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; 
}
相关推荐
怣疯knight42 分钟前
几个好用的ip纯净度检测网站
网络·ip
全栈工程师修炼指南1 小时前
Nginx | HTTP 反向代理:对上游服务端返回响应处理实践
运维·网络·nginx·安全·http
沧澜sincerely1 小时前
WebSocket 实时聊天功能
网络·websocket·vue·springboot
专业开发者1 小时前
思科以终端产品解决方案提供商的身份实现效能提升
运维·服务器·网络
培培说证1 小时前
2026大专前端开发工程师入门证书推荐?
网络·web安全
管理大亨1 小时前
企业级ELK:从日志收集到业务驱动
java·大数据·网络·数据库·elk·elasticsearch
网络小白不怕黑2 小时前
SRv6技术完全指南(1):下一代网络的核心引擎
网络
乾元2 小时前
网络遥测(Telemetry/gNMI)的结构化建模与特征化体系—— 从“采集指标”到“可被 AI 推理的状态向量”
运维·服务器·网络·人工智能·网络协议·华为·ansible
网硕互联的小客服2 小时前
CC攻击对服务器正常运行会有什么影响?如何预防和解决CC攻击?
运维·服务器·网络·windows·安全
大白的编程日记.2 小时前
【计算网络学习笔记】TCP套接字介绍和使用
网络·笔记·学习