linux mpls

 

 

ip netns add host1
ip netns add host2
ip link add veth0 type veth peer netns host1 name veth1
ip link add veth2 type veth peer netns host2  name veth3

sysctl -w net.mpls.platform_labels=65535
sysctl -w net.mpls.conf.veth0.input=1
sysctl -w net.mpls.conf.veth2.input=1

ip link set veth0 up
ip link set veth2 up
ip netns exec host1 ip link set lo up
ip netns exec host2 ip link set lo up
ip netns exec host1 ip link set veth1 up
ip netns exec host2 ip link set veth3 up

ip addr add 10.3.3.1/24 dev veth0
ip netns exec host1 ip addr add 10.3.3.2/24 dev veth1
ip addr add 10.4.4.1/24 dev veth2
ip netns exec host2 ip addr add 10.4.4.2/24 dev veth3

ip netns exec host1 ip addr add 10.10.10.1/32 dev lo
ip netns exec host2 ip addr add 10.10.10.2/32 dev lo

ip netns exec host1 ip route add 10.10.10.2/32 encap mpls 112 via inet 10.3.3.1
ip netns exec host2 ip route add 10.10.10.1/32 encap mpls 111 via inet 10.4.4.1       --------10.4.4.1 in host namespace


host namespace ip -f mpls route add 111 via inet 10.3.3.2 ip -f mpls route add 112 via inet 10.4.4.2

ip netns exec host2 ping 10.10.10.1 -I 10.10.10.2 -i 2
先encap mpls 111, 转发给10.4.4.4.1 在,host namespace 把label=111的路由给10.3.3.2




 

[root@mpls ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether fa:16:3e:eb:f3:29 brd ff:ff:ff:ff:ff:ff
    inet 10.10.18.142/24 brd 10.10.18.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feeb:f329/64 scope link 
       valid_lft forever preferred_lft forever
3: veth0@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 0e:fa:cc:13:6e:cd brd ff:ff:ff:ff:ff:ff link-netns host1
    inet 10.3.3.1/24 scope global veth0
       valid_lft forever preferred_lft forever
    inet6 fe80::cfa:ccff:fe13:6ecd/64 scope link 
       valid_lft forever preferred_lft forever
4: veth2@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 42:53:16:2a:61:48 brd ff:ff:ff:ff:ff:ff link-netns host2
    inet 10.4.4.1/24 scope global veth2
       valid_lft forever preferred_lft forever
    inet6 fe80::4053:16ff:fe2a:6148/64 scope link 
       valid_lft forever preferred_lft forever
[root@mpls ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.10.18.254    0.0.0.0         UG    100    0        0 eth0
10.3.3.0        0.0.0.0         255.255.255.0   U     0      0        0 veth0
10.4.4.0        0.0.0.0         255.255.255.0   U     0      0        0 veth2
10.10.18.0      0.0.0.0         255.255.255.0   U     100    0        0 eth0
[root@mpls ~]# ip netns list
host2 (id: 1)
host1 (id: 0)
[root@mpls ~]# ip netns exec host1 route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.3.3.0        0.0.0.0         255.255.255.0   U     0      0        0 veth1
10.10.10.2      10.3.3.1        255.255.255.255 UGH   0      0        0 veth1
[root@mpls ~]# ip netns exec host2  route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.4.4.0        0.0.0.0         255.255.255.0   U     0      0        0 veth3
10.10.10.1      10.4.4.1        255.255.255.255 UGH   0      0        0 veth3
[root@mpls ~]#
[root@mpls ~]# ip netns exec host2  ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.10.10.2/32 scope global lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: veth3@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 5a:82:1f:1f:5a:13 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.4.4.2/24 scope global veth3
       valid_lft forever preferred_lft forever
    inet6 fe80::5882:1fff:fe1f:5a13/64 scope link 
       valid_lft forever preferred_lft forever
[root@mpls ~]# ip netns exec host1  ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.10.10.1/32 scope global lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: veth1@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether b6:15:29:2f:82:98 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.3.3.2/24 scope global veth1
       valid_lft forever preferred_lft forever
    inet6 fe80::b415:29ff:fe2f:8298/64 scope link 
       valid_lft forever preferred_lft forever
[root@mpls ~]# 

 

 

[root@mpls ~]# ping 10.4.4.1 -I 10.3.3.1
PING 10.4.4.1 (10.4.4.1) from 10.3.3.1 : 56(84) bytes of data.
64 bytes from 10.4.4.1: icmp_seq=1 ttl=64 time=0.785 ms
64 bytes from 10.4.4.1: icmp_seq=2 ttl=64 time=0.066 ms
64 bytes from 10.4.4.1: icmp_seq=3 ttl=64 time=0.079 ms
^C
--- 10.4.4.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 29ms
rtt min/avg/max/mdev = 0.066/0.310/0.785/0.335 ms
[root@mpls ~]#
[root@mpls ~]# ip netns exec host2 ping 10.10.10.1 -I 10.10.10.2 -i 2
PING 10.10.10.1 (10.10.10.1) from 10.10.10.2 : 56(84) bytes of data.
64 bytes from 10.10.10.1: icmp_seq=1 ttl=63 time=0.242 ms
64 bytes from 10.10.10.1: icmp_seq=2 ttl=63 time=0.101 ms
64 bytes from 10.10.10.1: icmp_seq=3 ttl=63 time=0.084 ms
64 bytes from 10.10.10.1: icmp_seq=4 ttl=63 time=0.079 ms
64 bytes from 10.10.10.1: icmp_seq=5 ttl=63 time=0.133 ms
64 bytes from 10.10.10.1: icmp_seq=6 ttl=63 time=0.088 ms
64 bytes from 10.10.10.1: icmp_seq=7 ttl=63 time=0.082 ms
64 bytes from 10.10.10.1: icmp_seq=8 ttl=63 time=0.062 ms
64 bytes from 10.10.10.1: icmp_seq=9 ttl=63 time=0.083 ms
[root@mpls ~]# tcpdump -i veth0 -nn -l
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on veth0, link-type EN10MB (Ethernet), capture size 262144 bytes
06:00:28.356896 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 4, length 64
06:00:28.356922 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 4, length 64
06:00:30.404970 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 5, length 64
06:00:30.405013 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 5, length 64
06:00:32.452929 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 6, length 64
06:00:32.452960 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 6, length 64
^C
6 packets captured
6 packets received by filter
0 packets dropped by kernel

label 112 [root@mpls ~]# ip netns exec host2 tcpdump -i veth3 -nn -l tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on veth3, link-type EN10MB (Ethernet), capture size 262144 bytes 06:01:37.988896 MPLS (label 111, exp 0, [S], ttl 64) IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 38, length 64 06:01:37.988942 IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 38, length 64 06:01:40.036922 MPLS (label 111, exp 0, [S], ttl 64) IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 39, length 64 06:01:40.036970 IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 39, length 64 06:01:42.084932 MPLS (label 111, exp 0, [S], ttl 64) IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 40, length 64 06:01:42.084985 IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 40, length 64 ^C 6 packets captured 6 packets received by filter 0 packets dropped by kernel [root@mpls ~]# ip netns exec host1 tcpdump -i veth1 -nn -l tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on veth1, link-type EN10MB (Ethernet), capture size 262144 bytes 06:02:06.660895 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 52, length 64 06:02:06.660920 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 52, length 64 06:02:07.940818 ARP, Request who-has 10.3.3.2 tell 10.3.3.1, length 28 06:02:07.941006 ARP, Reply 10.3.3.2 is-at b6:15:29:2f:82:98, length 28 06:02:08.709304 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 53, length 64 06:02:08.709331 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 53, length 64 06:02:10.756886 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17785, seq 54, length 64 06:02:10.756908 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17785, seq 54, length 64 ^C 8 packets captured 8 packets received by filter 0 packets dropped by kernel [root@mpls ~]# tcpdump -i veth2 -nn -l tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on veth2, link-type EN10MB (Ethernet), capture size 262144 bytes 06:04:10.703365 MPLS (label 111, exp 0, [S], ttl 64) IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17802, seq 1, length 64 06:04:10.703512 IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17802, seq 1, length 64 06:04:12.740911 MPLS (label 111, exp 0, [S], ttl 64) IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17802, seq 2, length 64 06:04:12.740953 IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17802, seq 2, length 64 06:04:15.940844 ARP, Request who-has 10.4.4.2 tell 10.4.4.1, length 28 06:04:15.941005 ARP, Request who-has 10.4.4.1 tell 10.4.4.2, length 28 06:04:15.941012 ARP, Reply 10.4.4.1 is-at 42:53:16:2a:61:48, length 28 06:04:15.941013 ARP, Reply 10.4.4.2 is-at 5a:82:1f:1f:5a:13, length 28 ^C 8 packets captured 8 packets received by filter 0 packets dropped by kernel [root@mpls ~]#

 

 

[root@mpls ~]# ip netns exec host2 ping 10.10.10.1 -I 10.10.10.2 -i 3
PING 10.10.10.1 (10.10.10.1) from 10.10.10.2 : 56(84) bytes of data.
64 bytes from 10.10.10.1: icmp_seq=1 ttl=63 time=0.267 ms
64 bytes from 10.10.10.1: icmp_seq=2 ttl=63 time=0.074 ms
64 bytes from 10.10.10.1: icmp_seq=3 ttl=63 time=0.064 ms
64 bytes from 10.10.10.1: icmp_seq=4 ttl=63 time=0.111 ms
64 bytes from 10.10.10.1: icmp_seq=5 ttl=63 time=0.203 ms
64 bytes from 10.10.10.1: icmp_seq=6 ttl=63 time=0.127 ms
64 bytes from 10.10.10.1: icmp_seq=7 ttl=63 time=0.135 ms
64 bytes from 10.10.10.1: icmp_seq=8 ttl=63 time=0.104 ms
64 bytes from 10.10.10.1: icmp_seq=9 ttl=63 time=0.103 ms

[root@mpls ~]# ip netns exec host1  tcpdump -i veth1 -nn -l
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on veth1, link-type EN10MB (Ethernet), capture size 262144 bytes
06:16:54.212990 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 4, length 64 ---剥掉mpls
06:16:54.213034 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 4, length 64

06:16:57.221013 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 5, length 64

06:16:57.221058 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 5, length 64

06:17:00.228954 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 6, length 64

06:17:00.228998 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 6, length 64

06:17:03.236955 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 7, length 64

06:17:03.237006 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 7, length 64
06:17:06.246247 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 8, length 64

06:17:06.246286 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 8, length 64 06:17:09.252898 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 9, length 64 06:17:09.252942 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 9, length 64 06:17:12.260995 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 10, length 64 06:17:12.261041 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 10, length 64 06:17:13.156862 ARP, Request who-has 10.3.3.2 tell 10.3.3.1, length 28 06:17:13.157139 ARP, Reply 10.3.3.2 is-at b6:15:29:2f:82:98, length 28 06:17:15.268927 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 11, length 64 06:17:15.269043 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 11, length 64 06:17:18.276943 IP 10.10.10.2 > 10.10.10.1: ICMP echo request, id 17825, seq 12, length 64 06:17:18.276981 MPLS (label 112, exp 0, [S], ttl 64) IP 10.10.10.1 > 10.10.10.2: ICMP echo reply, id 17825, seq 12, length 64 ^C 20 packets captured 20 packets received by filter 0 packets dropped by kernel [root@mpls ~]#

 

 

[root@mpls ~]# uname -a
Linux mpls.novalocal 4.18.0-147.3.1.el8_1.x86_64 #1 SMP Fri Jan 3 23:55:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@mpls ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

[root@mpls ~]# 

 

posted on 2020-07-21 14:22  tycoon3  阅读(508)  评论(0编辑  收藏  举报

导航