tian01@tian01-virtual-machine:~$ mn
*** Mininet must run as root.
tian01@tian01-virtual-machine:~$ sudo mn
[sudo] tian01 的密码:
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0
mininet> link
invalid number of args: link end1 end2 [up down]
mininet> links
h1-eth0<->s1-eth1 (OK OK)
h2-eth0<->s1-eth2 (OK OK)
mininet> nodes
available nodes are:
c0 h1 h2 s1
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2
h2 -> h1
*** Results: 0% dropped (2/2 received)
************************
从这里看,上面是联系内部命令
mininet> py net.addHost('h3')
<Host h3: pid=22976> pid 进程id
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0
mininet> py net.addLink(s1,net.get('h3'))
<mininet.link.Link object at 0x7f92e9033910>
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s1-eth3
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:h3-eth0
c0
mininet> py s1.attach('s1-eth3')
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 *** Error: could not parse ping output: ping: None: 域名解析暂时失败
X
h2 -> h1 *** Error: could not parse ping output: ping: None: 域名解析暂时失败
X
h3 -> *** Error: could not parse ping output: ping: connect: 网络不可达
X *** Error: could not parse ping output: ping: connect: 网络不可达
X
*** Results: 66% dropped (2/6 received)
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s1-eth3
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:h3-eth0
c0
mininet> py net.get('h3').cmd('ifconfig h3-eth0 10.3') #配置 h3 IP地址
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 *** Error: could not parse ping output: ping: None: 域名解析暂时失败
X
h2 -> h1 *** Error: could not parse ping output: ping: None: 域名解析暂时失败
X
h3 -> h1 h2
*** Results: 33% dropped (4/6 received)
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=22861>
<Host h2: h2-eth0:10.0.0.2 pid=22864>
<Host h3: h3-eth0:None pid=22976>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=22869>
<Controller c0: 127.0.0.1:6653 pid=22854>
mininet> h1 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=1.83 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=1.38 ms
......
--- 10.0.0.3 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8135ms
rtt min/avg/max/mdev = 0.084/0.482/1.826/0.622 ms
mininet> h2 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=3.87 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.585 ms
.......
--- 10.0.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.585/2.227/3.869/1.642 ms
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3
h2 -> h1 h3
h3 -> h1 h2
*** Results: 0% dropped (6/6 received)
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=22861>
<Host h2: h2-eth0:10.0.0.2 pid=22864>
<Host h3: h3-eth0:10.0.0.3 pid=22976>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=22869>
<Controller c0: 127.0.0.1:6653 pid=22854>
mininet> py help(h1)
mininet> py dir(s!)
invalid syntax (<string>, line 1)
mininet> py dir(s1)
省略....
mininet> py h1.setIP('10.0.0.5',24)
mininet> dump
<Host h1: h1-eth0:10.0.0.5 pid=22861>
<Host h2: h2-eth0:10.0.0.2 pid=22864>
<Host h3: h3-eth0:10.0.0.3 pid=22976>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=22869>
<Controller c0: 127.0.0.1:6653 pid=22854>
mininet>
Why can't I find the ip address in the first dump?
Because dump obtains the host ip address through an existing flow table, host3 has no corresponding flow table just now, so None
can ping each other, here through h1 ping h3; h2 ping h3 to build the flow table next time, you can set it in advance next time H3ip address