VPP学习

flowtable

cpp 复制代码
static uword flowtable_getinfo(struct vlib_main_t *vppMain,
                               struct vlib_node_runtime_t *nodeRuntime,
                               struct vlib_frame_t *inputFrame) {

    u32 remainingPackets, *packetIndices, *nextFrameIndices;
    u32 nextNodeIndex = nodeRuntime->cached_next_index;

    printf("flowtable_getinfo cached_next_index: %u\n", nextNodeIndex);

    packetIndices = vlib_frame_vector_args(inputFrame); // 获取指向帧向量数据的指针,即第一个数据包的地址
    remainingPackets = inputFrame->n_vectors; // 获取向量数量,即有多少个数据包

    while (remainingPackets > 0) {
        u32 spaceInNextFrame;
        // 获取下一个节点的帧和向量,然后vlib_put_next_frame将当前节点处理的数据包添加到这个帧中
        vlib_get_next_frame(vppMain, nodeRuntime, nextNodeIndex, nextFrameIndices, spaceInNextFrame);

        while (remainingPackets > 0 && spaceInNextFrame > 0) {
            vlib_buffer_t *currentBuffer;
            u32 currentBufferIndex, nextBufferIndex = 0;

            currentBufferIndex = nextFrameIndices[0] = packetIndices[0];
            packetIndices += 1;
            nextFrameIndices += 1;
            spaceInNextFrame -= 1;
            remainingPackets -= 1;

            // 它将 DPDK 的 rte_mbuf 转换为 VPP 的 vlib_buffer_t
            currentBuffer = vlib_get_buffer(vppMain, currentBufferIndex);
            // 取出当前需要处理的数据包
            ip4_header_t *currentIPHeader = vlib_buffer_get_current(currentBuffer);
            ip4_address_t srcIP = currentIPHeader->src_address;
            ip4_address_t dstIP = currentIPHeader->dst_address;
            // 获取处理的数据包所到达的接口的软件索引,并将其存储在变量 inputInterfaceIndex 中
            u32 inputInterfaceIndex = vnet_buffer(currentBuffer)->sw_if_index[VLIB_RX];
            // 对每个数据包打印其源ip及目的ip
            struct in_addr srcAddr;
            srcAddr.s_addr = srcIP.as_u32;
            printf("sw_if_index: %d, srcIP: %s ", inputInterfaceIndex, inet_ntoa(srcAddr));
            srcAddr.s_addr = dstIP.as_u32;
            printf("dstIP: %s\n", inet_ntoa(srcAddr));

            // 将当前处理的缓冲区传递到下一个节点
            vlib_validate_buffer_enqueue_x1(vppMain, nodeRuntime, nextNodeIndex,
                                              nextFrameIndices, spaceInNextFrame,
                                              currentBufferIndex, nextBufferIndex);
        }
        // 完成当前帧的处理,并将剩余的空间返回给VPP
        vlib_put_next_frame(vppMain, nodeRuntime, nextNodeIndex, spaceInNextFrame);
    }
    return inputFrame->n_vectors; 
}
相关推荐
DevSecOps选型指南2 小时前
2025软件供应链安全最佳实践︱证券DevSecOps下供应链与开源治理实践
网络·安全·web安全·开源·代码审计·软件供应链安全
国科安芯3 小时前
抗辐照MCU在卫星载荷电机控制器中的实践探索
网络·嵌入式硬件·硬件工程·智能硬件·空间计算
EasyDSS4 小时前
国标GB28181设备管理软件EasyGBS远程视频监控方案助力高效安全运营
网络·人工智能
玩转4G物联网4 小时前
零基础玩转物联网-串口转以太网模块如何快速实现与TCP服务器通信
服务器·网络·物联网·网络协议·tcp/ip·http·fs100p
派阿喵搞电子4 小时前
Ubuntu下有关UDP网络通信的指令
linux·服务器·网络
搬码临时工5 小时前
外网访问内网服务器常用的三种简单操作步骤方法,本地搭建网址轻松让公网连接
服务器·网络·智能路由器
Fortinet_CHINA6 小时前
引领AI安全新时代 Accelerate 2025北亚巡展·北京站成功举办
网络·安全
dustcell.6 小时前
Cisco Packer Tracer 综合实验
网络
量子-Alex8 小时前
【反无人机检测】C2FDrone:基于视觉Transformer网络的无人机间由粗到细检测
网络·transformer·无人机
Jeremy_Lee1239 小时前
grafana 批量视图备份及恢复(含数据源)
前端·网络·grafana