cuili@cuili-OptiPlex-3020:~$ cd /home/cuili/mininet
cuili@cuili-OptiPlex-3020:~/mininet$ ls
bin custom doc LICENSE mininet.egg-info mnexec.1 setup.py
build debian examples Makefile mn.1 mnexec.c util
CONTRIBUTORS dist INSTALL mininet mnexec README.md
cuili@cuili-OptiPlex-3020:~/mininet$ cd custom
cuili@cuili-OptiPlex-3020:~/mininet/custom$ ls
README topo-2sw-2host.py
cuili@cuili-OptiPlex-3020:~/mininet/custom$ vi topo-2sw-2host.py
""Custom topology example
Two directly connected switches plus a host for each switch:
host --- switch --- switch --- host
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
# Add hosts and switches
leftHost = self.addHost( 'h1' )
rightHost = self.addHost( 'h2' )
(在文档中有提示,执行以下命令启动Mininet,生成测试拓扑结构:)
(cuili@cuili-OptiPlex-3020:~/mininet/custom$ sudo apt-get install screen 此步骤也许会存在)
(切记:容易错误原因在于topo-2sw_2host.py --topo mytopo )
cuili@cuili-OptiPlex-3020:~/mininet/custom$ sudo screen mn --custom /home/cuili/mininet/custom/topo-2sw-2host.py --topo mytopo --controller=remote,ip=172.16.75.117,port=6633 --switch ovsk,protocols=OpenFlow10
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s3 s4
*** Adding links:
(h1, s3) (s3, s4) (s4, h2)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 2 switches
s3 s4 ...
*** Starting CLI:
mininet>
执行ctrl+a+d命令切换到系统命令行。
输入ovs-vsctl show命令查看Mininet是否与OpenDaylight连通。
[detached from 26530.pts-7.cuili-OptiPlex-3020]cuili@cuili-OptiPlex-3020:~/mininet/custom$ ovs-vsctl show
ovs-vsctl: unix:/usr/local/var/run/openvswitch/db.sock: database connection failed (Permission denied)
抓包验证
步骤1.在OpenDaylight虚拟机上执行以下命令开始抓包。(在老大电脑上重新开一个虚拟机)
1
|
tcpdump
-
i
any
port
6633
-
s0
-
w
206.pcap
|
步骤2.在Mininet命令行中查看当前已生成2个交换机和4个主机。
如果当前是在系统命令行,则执行screen –r命令切换到mininet命令行。执行以下命
令查看交换机和主机
cuili@cuili-OptiPlex-3020:~/mininet/custom$ screen -rThere is no screen to be resumed.
cuili@cuili-OptiPlex-3020:~/mininet/custom$ sudo screen mn --custom /home/cuili/mininet/custom/topo-2sw-2host.py --topo mytopo --controller=remote,ip=172.16.75.117,port=6633 --switch ovsk,protocols=OpenFlow10
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s3 s4
*** Adding links:
(h1, s3) (s3, s4) (s4, h2)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 2 switches
s3 s4 ...
*** Starting CLI:
mininet> nodes
available nodes are:
c0 h1 h2 s3 s4
mininet> h1 ping h2
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.507 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.434 ms
^C
--- 10.0.0.2 ping statistics ---
22 packets transmitted, 22 received, 0% packet loss, time 21001ms
rtt min/avg/max/mdev = 0.156/0.411/0.560/0.137 ms
mininet>
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 2 switches
s3 s4 ...
*** Starting CLI:
mininet> nodes
available nodes are:
c0 h1 h2 s3 s4
mininet> h1 ping h2
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.507 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.434 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.440 ms
^C
--- 10.0.0.2 ping statistics ---
22 packets transmitted, 22 received, 0% packet loss, time 21001ms
rtt min/avg/max/mdev = 0.156/0.411/0.560/0.137 ms
mininet>