本文主要介绍如果进入mininet终端的命名空间,调试网络、报文等。
首先,构造一个简单的二层网络,h1、h2分别连到s1交换机上。
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=3558>
<Host h2: h2-eth0:10.0.0.2 pid=3561>
<OVSBridge s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=3566>
在/var/run创建网络命名空间
mkdir /var/run/netns
将进程网络命名空间软链接到主机目录
ln -s /proc/3558/ns/net /var/run/netns/h1
ln -s /proc/3561/ns/net /var/run/netns/h2
展示所有位于/var/run/netns下的网络命名空间
root@nettraffic-vm:/home/nettraffic# ip netns list
h2
h1
进入h1的命名空间控制台,可以看到mininet创建的三次接口ip地址
root@nettraffic-vm:/home/nettraffic# ip netns exec h1 bash
root@nettraffic-vm:/home/nettraffic# ifconfig
h1-eth0 Link encap:Ethernet HWaddr 2a:78:52:42:33:06
inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::2878:52ff:fe42:3306/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:133 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25145 (25.1 KB) TX bytes:648 (648.0 B)lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
使用h1 ping h2
root@nettraffic-vm:/home/nettraffic# ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.478 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.068 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.032 ms
64 bytes from 10.0.0.2: icmp_seq=5 ttl=64 time=0.063 ms
64 bytes from 10.0.0.2: icmp_seq=6 ttl=64 time=0.032 ms
进入h2的命名空间,并使用tcpdump抓包
root@nettraffic-vm:/home/nettraffic# tcpdump -i h2-eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on h2-eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C00:18:42.911399 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 16, length 64
00:18:42.911412 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 16, length 64
00:18:43.911559 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 17, length 64
00:18:43.911572 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 17, length 64
00:18:44.911510 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 18, length 64
00:18:44.911523 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 18, length 64
00:18:45.910895 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 19, length 64
00:18:45.910913 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 19, length 64
00:18:46.910836 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 20, length 64
00:18:46.910849 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 20, length 64
00:18:47.911455 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 21, length 64
00:18:47.911465 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 21, length 64
00:18:48.911058 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 22, length 64
00:18:48.911071 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 22, length 64
00:18:49.910794 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 23, length 64
00:18:49.910808 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 23, length 64
00:18:50.910913 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 24, length 64
00:18:50.910926 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 24, length 64
00:18:51.911361 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 25, length 64
00:18:51.911371 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 25, length 64
00:18:52.911132 IP 10.0.0.1 > 10.0.0.2: ICMP echo request, id 4316, seq 26, length 64
00:18:52.911146 IP 10.0.0.2 > 10.0.0.1: ICMP echo reply, id 4316, seq 26, length 6422 packets captured
22 packets received by filter
0 packets dropped by kernel
参考: