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; 
}
相关推荐
白帽黑客沐瑶17 小时前
【网络安全就业】信息安全专业的就业前景(非常详细)零基础入门到精通,收藏这篇就够了
网络·安全·web安全·计算机·程序员·编程·网络安全就业
树码小子17 小时前
Java网络编程:(socket API编程:TCP协议的 socket API -- 回显程序的服务器端程序的编写)
java·网络·tcp/ip
绿箭柠檬茶19 小时前
Ubuntu 服务器配置转发网络访问
服务器·网络·ubuntu
real 119 小时前
传输层协议UDP
网络·网络协议·udp
路由侠内网穿透20 小时前
本地部署 GPS 跟踪系统 Traccar 并实现外部访问
运维·服务器·网络·windows·tcp/ip
喵手1 天前
玩转Java网络编程:基于Socket的服务器和客户端开发!
java·服务器·网络
徐子元竟然被占了!!1 天前
实验-基本ACL
网络
ftpeak1 天前
从零开始使用 axum-server 构建 HTTP/HTTPS 服务
网络·http·https·rust·web·web app
LabVIEW开发1 天前
LabVIEW气体污染无线监测
网络·labview·labview知识·labview功能·labview程序
error:(1 天前
【从零到公网】本地电脑部署服务并实现公网访问(IPv4/IPv6/DDNS 全攻略)
网络·智能路由器