如下创建物理接口GigabitEthernet7/0/0的对等接口e7。
vpp# show interface GigabitEthernet7/0/0
Name Idx State MTU (L3/IP4/IP6/MPLS) Counter Count
GigabitEthernet7/0/0 10 down 9000/0/0/0
vpp#
vpp# lcp create GigabitEthernet7/0/0 host-if e7
vpp#
vpp# show tap
Interface: tap10 (ifindex 17)
name "e7"
host-mtu-size "9000"
host-mac-addr: 00:60:e0:6f:5a:f0
创建物理接口GigabitEthernet8/0/0的对等接口e8,并且接口状态设置为UP,MTU设置为1500(默认情况为9000)。对等接口的MAC地址与实际的物理接口的MAC地址相同。
vpp# show interface GigabitEthernet8/0/0
Name Idx State MTU (L3/IP4/IP6/MPLS) Counter Count
GigabitEthernet8/0/0 11 down 9000/0/0/0
vpp#
vpp#
vpp# set interface state GigabitEthernet8/0/0 up
vpp# set interface mtu packet 1500 GigabitEthernet8/0/0
vpp#
vpp# lcp create GigabitEthernet8/0/0 host-if e8
vpp#
vpp# show tap
Interface: tap11 (ifindex 18)
name "e8"
host-mtu-size "1500"
host-mac-addr: 00:60:e0:6f:5a:f1
LCP命令查看接口对。
vpp# show lcp
lcp default netns '<unset>'
lcp lcp-auto-subint off
lcp lcp-sync off
itf-pair: [0] GigabitEthernet7/0/0 tap10 e7 18 type tap
itf-pair: [1] GigabitEthernet8/0/0 tap11 e8 19 type tap
退出VPP命令行,在Linux shell中查看创建的两个tap接口,e7的mtu为9000,状态为down。接口e8的mtu为1500,状态为up。并且,接口e7和e8的MAC地址与VPP中的接口GigabitEthernet7/0/0和GigabitEthernet8/0/0的MAC地址相同。
$ ip link show type tun
18: e7: <BROADCAST,MULTICAST> mtu 9000 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:60:e0:6f:5a:f0 brd ff:ff:ff:ff:ff:ff
19: e8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 00:60:e0:6f:5a:f1 brd ff:ff:ff:ff:ff:ff
LCP接口管理状态同步开关。
vpp# lcp lcp-sync on
vpp#
vpp# show lcp
lcp lcp-sync on
如下在VPP中将GigabitEthernet7/0/0接口状态设置为UP,linux中的对等接口e7状态也同步为UP。
vpp# set interface state GigabitEthernet7/0/0 up
vpp# quit
#
#
# ip link show type tun
18: e7: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:60:e0:6f:5a:f0 brd ff:ff:ff:ff:ff:ff
接口链路状态不受以上开关的限制。断开物理接口GigabitEthernet8/0/0的网线,VPP和linux中的e8接口的链路状态都是DOWN。
# ip link show type tun
19: e8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 00:60:e0:6f:5a:f1 brd ff:ff:ff:ff:ff:ff
#
#
# vppctl
vpp#
vpp# show hardware-interfaces GigabitEthernet8/0/0
Name Idx Link Hardware
GigabitEthernet8/0/0 11 down GigabitEthernet8/0/0
vpp#
vpp# quit
#
# ip link show type tun
19: e8: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:60:e0:6f:5a:f1 brd ff:ff:ff:ff:ff:ff
VPP中物理接口和linux中对等接口e8设置完全相同的IP地址。
vpp# set interface ip address GigabitEthernet8/0/0 10.0.1.1/24
vpp# quit
vpp#
#
# ip addr add dev e8 10.0.1.1/24
在linux中ping外部主机10.0.1.2。
# ping 10.0.1.2
PING 10.0.1.2 (10.0.1.2) 56(84) bytes of data.
64 bytes from 10.0.1.2: icmp_seq=1 ttl=64 time=0.290 ms
在VPP中trace回复的ICMP报文,如下:
vpp# trace add dpdk-input 100
vpp#
vpp# show trace
Packet 3
00:40:13:066975: dpdk-input
GigabitEthernet7/0/0 rx queue 0
buffer 0x82ca6: current data 0, length 98, buffer-pool 0, ref-count 1, trace handle 0x2000002
ext-hdr-valid
PKT MBUF: port 9, nb_segs 1, pkt_len 98
buf_len 2176, data_len 98, ol_flags 0x180, data_off 128, phys_addr 0x92cb2a00
packet_type 0x11 l2_len 0 l3_len 0 outer_l2_len 0 outer_l3_len 0
rss 0x0 fdir.hi 0x0 fdir.lo 0x0
Packet Offload Flags
PKT_RX_IP_CKSUM_GOOD (0x0080) IP cksum of RX pkt. is valid
PKT_RX_IP_CKSUM_NONE (0x0090) no IP cksum of RX pkt.
PKT_RX_L4_CKSUM_GOOD (0x0100) L4 cksum of RX pkt. is valid
PKT_RX_L4_CKSUM_NONE (0x0108) no L4 cksum of RX pkt.
Packet Types
RTE_PTYPE_L2_ETHER (0x0001) Ethernet packet
RTE_PTYPE_L3_IPV4 (0x0010) IPv4 packet without extension headers
IP4: 54:e1:ad:3f:11:f4 -> 00:60:e0:6f:5a:f0
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066978: ethernet-input
frame: flags 0x3, hw-if-index 10, sw-if-index 10
IP4: 54:e1:ad:3f:11:f4 -> 00:60:e0:6f:5a:f0
00:40:13:066980: ip4-input-no-checksum
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066980: ip4-lookup
fib 0 dpo-idx 7 flow hash: 0x00000000
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066984: ip4-receive
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066985: ip4-icmp-input
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066985: ip4-icmp-echo-reply
ICMP4 echo id 3 seq 1 (unknown)
00:40:13:066988: ip4-punt
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066988: ip4-punt-redirect
via redirect:0
00:40:13:066989: ip4-dvr-dpo
sw_if_index:17
00:40:13:066990: ip4-dvr-reinject
sw_if_index:17
00:40:13:066992: tap11-output
tap11
IP4: 54:e1:ad:3f:11:f4 -> 00:60:e0:6f:5a:f0
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
00:40:13:066993: tap11-tx
buffer 0x82ca6: current data 0, length 98, buffer-pool 0, ref-count 1, trace handle 0x2000002
ext-hdr-valid
local dvr l2-hdr-offset 0 l3-hdr-offset 14
hdr-sz 0 l2-hdr-offset 0 l3-hdr-offset 14 l4-hdr-offset 0 l4-hdr-sz 0
IP4: 54:e1:ad:3f:11:f4 -> 00:60:e0:6f:5a:f0
ICMP: 10.0.1.2 -> 10.0.1.1
tos 0x00, ttl 128, length 84, checksum 0xd71b dscp CS0 ecn NON_ECN
fragment id 0x4d8b
ICMP echo_reply checksum 0xecf9 id 3
在接收到ICMP回复报文后,依次经过以下node节点:
ip4-icmp-echo-reply -> ip4-punt -> ip4-punt-redirect -> ip4-dvr-dpo -> ip4-dvr-reinject ->tap11-output -> tap11-tx
通过tap11-tx将报文送至linux中对等体接口。