前面有一篇文章中《Flexiwan 架构及功能说明》介绍了Flexiwan公司lte模组使用方式。因为LTE 接口是不支持直接被 DPDK 接管的,LTE 设备是由 Linux 系统拥有和管理的,我们创建一个 tap 接口连接到 VPP 以执行路由和服务。在Linix系统中通过默认路由从LTE接口进行NAT转换后送到公网。如下图所示:
下面介绍一下VPP AF_PACKET插件,它可以将DPDK无法直接纳管的接口通过AF_PACKET插件直接映射到VPP中。Linux 中的 AF_PACKET 套接字允许应用程序接收和发送原始数据包。我们可以将接口绑定到一个 AF_PACKET 套接字,并允许 DPDK&VPP 应用程序通过内核发送和接收原始数据包。为了提高Rx 和Tx 性能,我们使用 PACKET_MMAP,它提供了一个映射环形缓冲区,在用户空间和内核之间共享,用于发送和接收数据包。这有助于减少系统调用以及用户空间和内核之间频繁切换带来性能损耗。
这样LTE模组理论上可以通过AF_PACKET插件映射到VPP中,通过接口配置dhcp clinet来申请IP地址及默认路由,从而可以实现访问公网(由于目前没有LTE模组,就使用物理网卡来实现)。
#查询ens39接口mac地址为:00:0c:29:8d:8f:1f
root@jinsh:~# ifconfig ens39
ens39: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 2409:8a00:7980:9080:20c:29ff:fe8d:8f1f prefixlen 64 scopeid 0x0<global>
inet6 fe80::20c:29ff:fe8d:8f1f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:8d:8f:1f txqueuelen 1000 (Ethernet)
RX packets 2626 bytes 180824 (180.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 579 bytes 52408 (52.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#指定ens39 在vpp上创建af_packet接口
create host-interface name ens39 hw-addr 00:0c:29:8d:8f:1f
#查询接口信息
vpp# show hardware-interfaces host-ens39
Name Idx Link Hardware
host-ens39 2 up host-ens39
Link speed: unknown
RX Queues:
queue thread mode
0 main (0) interrupt
TX Queues:
TX Hash: [name: hash-eth-l34 priority: 50 description: Hash ethernet L34 headers]
queue shared thread(s)
0 no 0
Ethernet address 00:0c:29:8d:8f:1f
Linux PACKET socket interface v3
FEATURES:
qdisc-bpass-enabled
cksum-gso-enabled
RX Queue 0:
block size:65536 nr:160 frame size:2048 nr:5120 next block:5
TX Queue 0:
block size:69206016 nr:1 frame size:67584 nr:1024 next frame:33
available:1024 request:0 sending:0 wrong:0 total:1024
set interface state host-ens39 up
set dhcp clinet intfc host-ens39
配置完上述命令之后,我们可以看到接口host-ens39已经获取到ip地址,并且默认会配置默认路由指向网关192.168.1.1。
vpp# show interface addr
GigabitEthernet2/6/0 (up):
host-ens39 (up):
L3 192.168.1.21/24
local0 (dn):
vpp# show dhc
dhcp dhcp6 dhcpv6
vpp# show dhcp client
[0] host-ens39 state DHCP_BOUND installed 1 addr 192.168.1.21/24 gw 192.168.1.1 server 192.168.1.1 dns 192.168.1.1
vpp# show ip fib 0.0.0.0/0
ipv4-VRF:0, fib_index:0, flow hash:[src dst sport dport proto flowlabel ] epoch:0 flags:none locks:[adjacency:1, default-route:1, ]
0.0.0.0/0 fib:0 index:0 locks:3
DHCP refs:1 src-flags:added,contributing,active,
path-list:[16] locks:2 flags:shared, uPRF-list:15 len:1 itfs:[2, ]
path:[18] pl-index:16 ip4 weight=1 pref=0 attached-nexthop: oper-flags:resolved,
192.168.1.1 host-ens39
[@0]: ipv4 via 192.168.1.1 host-ens39: mtu:9000 next:3 flags:[] f4de0cf81280000c298d8f1f0800
default-route refs:1 entry-flags:drop, src-flags:added,
path-list:[0] locks:1 flags:drop, uPRF-list:0 len:0 itfs:[]
path:[0] pl-index:0 ip4 weight=1 pref=0 special: cfg-flags:drop,
[@0]: dpo-drop ip4
forwarding: unicast-ip4-chain
[@0]: dpo-load-balance: [proto:ip4 index:1 buckets:1 uRPF:15 to:[12:1152]]
[0] [@5]: ipv4 via 192.168.1.1 host-ens39: mtu:9000 next:3 flags:[] f4de0cf81280000c298d8f1f0800
接下来我们就可以在vpp中ping通阿里云dns server 223.5.5.5,并抓取trace流程如下:
#vpp 中ping 223.5.5.5
vpp# ping 223.5.5.5
116 bytes from 223.5.5.5: icmp_seq=1 ttl=117 time=13.3016 ms
116 bytes from 223.5.5.5: icmp_seq=2 ttl=117 time=21.3266 ms
#trace 记录如下
00:52:44:621730: af-packet-input
af_packet: hw_if_index 2 rx-queue 0 next-index 4
block 11:
:/icmp
vnet-hdr:
flags 0x00 gso_type 0x00 hdr_len 0
gso_size 0 csum_start 0 csum_offset 0
00:53:03:007169: ethernet-input
IP4: f4:de:0c:f8:12:80 -> 00:0c:29:8d:8f:1f
00:53:03:007176: ip4-input
ICMP: 223.5.5.5 -> 192.168.1.21
tos 0x04, ttl 117, length 96, checksum 0x9fd1 dscp unknown ecn NON_ECN
fragment id 0x0000
ICMP echo_reply checksum 0xca6d id 31627
00:53:03:007179: ip4-lookup
fib 0 dpo-idx 7 flow hash: 0x00000000
ICMP: 223.5.5.5 -> 192.168.1.21
tos 0x04, ttl 117, length 96, checksum 0x9fd1 dscp unknown ecn NON_ECN
fragment id 0x0000
ICMP echo_reply checksum 0xca6d id 31627
00:53:03:007188: ip4-receive
ICMP: 223.5.5.5 -> 192.168.1.21
tos 0x04, ttl 117, length 96, checksum 0x9fd1 dscp unknown ecn NON_ECN
fragment id 0x0000
ICMP echo_reply checksum 0xca6d id 31627
00:53:03:007190: ip4-icmp-input
ICMP: 223.5.5.5 -> 192.168.1.21
tos 0x04, ttl 117, length 96, checksum 0x9fd1 dscp unknown ecn NON_ECN
fragment id 0x0000
ICMP echo_reply checksum 0xca6d id 31627
00:53:03:007191: ip4-icmp-echo-reply
ICMP4 echo id 31627 seq 1 send to cli node 725
本文只是简单介绍使用VPP AF_PACKET插件实现将LTE模组直接映射到VPP中实现访问公网。对AF_PACKET具体实现细节在后续文章中深入研究。
参考资料: 1、内核packet_mmap文档 https://www.kernel.org/doc/Documentation/networking/packet_mmap.txt 2、dpdk AF_PACKET说明: https://doc.dpdk.org/guides/nics/af_packet.html 3、VPP使用心得(十五)AF_PACKET https://blog.csdn.net/xingyeping/article/details/104988559?spm=1001.2014.3001.5502 4、packet_mmap实现原理(内恶化packet mmmap文档翻译) http://blog.chinaunix.net/uid-20357359-id-1963684.html 5、packet socket linux手册 https://man7.org/linux/man-pages/man7/packet.7.htm
本文分享自 DPDK VPP源码分析 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!