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; 
}
相关推荐
笨手笨脚の2 分钟前
从一行 ip route 到容器跨主机通信
网络·网络协议·tcp/ip
mmsx6 分钟前
Android 模块化三件套:轻量组件化、宿主插件双形态、AIDL 隔离
android·网络·组件化·aidl
czt_java10 分钟前
网络基础入门:IPv4、IPv6、私网公网、MAC、以太网帧与 DNS 学习笔记
网络·学习·macos
是个西兰花14 分钟前
http讲解
网络·网络协议·http
tianbin91131 分钟前
中小团队大模型训练落地实战:如何借助API网关降低工程负担
网络·后端
2401_8685347841 分钟前
VXLAN虚拟可扩展局域网
服务器·网络
烟雨醉沉浮1 小时前
VLAN 网络划分与安全管控
网络·安全·智能路由器
企业解惑小能手-域智盾系统1 小时前
手机偷拍电脑屏幕怎么防范?光学泄密攻防实战与落地选型
网络·智能手机·域智盾
Escalating_xu1 小时前
【Linux 网络编程】UDP Socket 编程(上):从地址与字节序到完整回显服务器
linux·服务器·网络
凌云若寒1 小时前
BarTender官网下载打印机驱动
运维·服务器·前端·网络·产品经理