DPDK L2 fwd代码走读报告(代码流程分析)

2026/1/27 7:35:20

216 *((uint64_t *)tmp) = 0x002 + ((uint64_t)dst_port <<40); 217 218/* src addr 修改进入包的目的mac地址为转发包的源mac地址 */ 219 ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], ð->s_addr); 220 221 l2fwd_send_packet(m, (uint8_t) dst_port); //在dst_port上发送数据包 } 223 224/* main processing loop */ 225staticvoid//线程的主处理循环 226 l2fwd_main_loop(void) 227 { 228struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; 229struct rte_mbuf *m; 230 unsigned lcore_id; 231 uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc; 232 unsigned i, j, portid, nb_rx; 233struct lcore_queue_conf *qconf; 234const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; 235 236 prev_tsc = 0; 237 timer_tsc = 0; 238 239 lcore_id = rte_lcore_id(); //获取当期lcore的编号 240 qconf = &lcore_queue_conf[lcore_id]; //读取此lcore上的配置信息 241 242if (qconf->n_rx_port == 0) { //如果此lcore上的用于接收的物理端口数量为0 243 RTE_LOG(INFO, L2FWD, \, lcore_id); 244return; //那么结束该线程 245 } 246 247 RTE_LOG(INFO, L2FWD, \, lcore_id); 248 249for (i = 0; i < qconf->n_rx_port; i++) { //遍历所有的用于接收数据包的物理端口 250 251 portid = qconf->rx_port_list[i];//一个lcore可能负责多个接收用的物理端口 252 RTE_LOG(INFO, L2FWD, \, lcore_id, 253 portid); 254 } 255 256while (1) { //死循环 257 258 cur_tsc = rte_rdtsc(); 259 260/* 261 * TX burst queue drain 262*/ 263 diff_tsc = cur_tsc - prev_tsc; 264if (unlikely(diff_tsc > drain_tsc)) { 265 266for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 267if (qconf->tx_mbufs[portid].len == 0) 268continue; 269 l2fwd_send_burst(&lcore_queue_conf[lcore_id], 270 qconf->tx_mbufs[portid].len, 271 (uint8_t) portid); 272 qconf->tx_mbufs[portid].len = 0; 273 } 274 275/* if timer is enabled */ 276if (timer_period >0) { //如果定时器启动 277 278/* advance the timer */ 279 timer_tsc += diff_tsc; 280 281/* if timer has reached its timeout */ 282if (unlikely(timer_tsc >= (uint64_t) timer_period)) { 283 284/* do this only on master core */ 285if (lcore_id == rte_get_master_lcore()) { 286 print_stats(); //十秒钟打印一次收包统计信息 287/* reset the timer */ 288 timer_tsc = 0; 289 } 290 } 291 } 292 293 prev_tsc = cur_tsc; 294 } 295 296/* 297 * Read packet from RX queues 298*/ 299for (i = 0; i < qconf->n_rx_port; i++) { //遍历所有的用于接收数据包的物理端口 300 301 portid = qconf->rx_port_list[i]; //第i个物理端口 302 nb_rx = rte_eth_rx_burst((uint8_t) portid, 0, //接收数据包,返回实际个数 303 pkts_burst, MAX_PKT_BURST); 304 305 port_statistics[portid].rx += nb_rx; //记录物理端口上收包数量 306 307for (j = 0; j < nb_rx; j++) { //遍历实际接收到的所有的数据包 308 m = pkts_burst[j]; 309 rte_prefetch0(rte_pktmbuf_mtod(m, void *)); //预取 310 l2fwd_simple_forward(m, portid);//简单的二层转发数据包 311 } 312 } 313 } 314 } 315 316staticint 317 l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy) 318 { 319 l2fwd_main_loop();//线程执行函数 320return0; 321 } 322 323/* display usage */ 324staticvoid 325 l2fwd_usage(constchar *prgname) 326 { 327 printf(\ 328\ 329\


DPDK L2 fwd代码走读报告(代码流程分析).doc 将本文的Word文档下载到电脑
搜索更多关于: DPDK L2 fwd代码走读报告(代码流程分析) 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219