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; 
}
相关推荐
码农学院35 分钟前
基于运维监控体系的网络品牌推广方案:从架构设计到技术实现
运维·网络
REDcker8 小时前
显示分辨率标准对照详解
前端·网络·分辨率·显示·屏幕
ANSIOT10 小时前
安朔科技蓝牙无感开锁方案,靠近自动解锁
网络·科技·物联网
晏宁科技YaningAI10 小时前
VoIP系统的工程实现模型:从信令控制到媒体传输的完整架构解析
网络·人工智能·架构·系统架构·信息与通信
神奇霸王龙13 小时前
Claude Code屠榜:MiMo与Grok紧追Codex
服务器·网络·人工智能·gpt·ai·ai编程
数智化管理手记15 小时前
账龄分析手工统计易遗漏?自动账龄分析工具怎么搭建
大数据·网络·数据库·人工智能·数据挖掘
LabVIEW开发15 小时前
NI Package Manager安装LabVIEW时InternalServerError错误
网络·数据库·labview·labview知识·labview功能·labview程序
RD_daoyi15 小时前
外链权重暴跌至13%,品牌提及反超传统链接——2026年不做Digital PR,你的独立站等于隐形
运维·网络·学习·机器学习·搜索引擎
张小姐的猫16 小时前
【Linux】网络编程 —— HTTP协议(上)
linux·运维·服务器·网络·http·单例模式·策略模式
国科安芯16 小时前
星间光链路:AS32S601型抗辐射MCU在空间激光通信终端控制中的技术实现
服务器·网络·单片机·嵌入式硬件·物联网·安全·信息与通信