上一篇文章中我们安装了Mininet,那么下一步我们需要熟悉Mininet的使用并准备使用Mininet对实际网络进行仿真,一般来说对于网络分析需要抓包和拓扑结构。我们暂时使用命令行显示拓扑,以后安装了SDN 控制器之后可以使用控制器的UI界面显示拓扑,,至于抓包软件,可以用使用老牌抓包软件Wireshark。
上一篇文章结尾我们在安装完成Mininet之后,启动Mininet之后随即自动创建了一个最简单网络拓扑结构:
sudo mn
*** No default OpenFlow controller found for default switch!
*** Falling back to OVS Bridge
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet>
其拓扑结构如图所示:
S:交换机 H:主机
在mininet>之后我们可以输入pingall来测试主机的连通性;
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2
h2 -> h1
*** Results: 0% dropped (2/2 received)
可以看到H1 H2之间是联通的,那么下面可以按照linux系统的习惯输入help 查看对应的命令行,得到下
mininet> help
Documented commands (type help ):
========================================
EOF gterm iperfudp nodes pingpair py switch
dpctl help link noecho pingpairfull quit time
dump intfs links pingall ports sh x
exit iperf net pingallfull px source xterm
You may also send a command to a node using:
command {args}
For example:
mininet> h1 ifconfig
The interpreter automatically substitutes IP addresses
for node names when a node is the first arg, so commands
like
mininet> h2 ping h3
should work.
Some character-oriented interactive commands require
noecho:
mininet> noecho h2 vi foo.py
However, starting up an xterm/gterm is generally better:
mininet> xterm h2
命令行基本可以分为三类:
第一类查看网络状态
第二类进行现有网络拓扑配置
第三类是创建网络
net 查看网络链路情况
nodes 查看节点情况
links 查看链路情况
pingpair/pingparifull 主机连通性测试
dump 查看网络链路详细信息
ports 查看端口连接
pingallpingallfull 网络节点链路联通性测试
iperf/iperfudp
py 执行Python的命令行,增加或者删除网络设备。比如我们要在S1交换机下增加一台主机H3,并连接到拓扑中:
mininet> py net.addHost('h3') #加入新主机H3
mininet> py net.addLink(h3,s1) #加入S1 H3的链路
mininet> py s1.attach('s1-eth3') #S1加入端口eth3
mininet> py h3.cmd('ifconfig h3-eth0 10.3') #H3配置IP地址
mininet> h1 ping h3 #H1-H3ARP协议
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=0.985 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.341 ms
mininet> pingall #测试主机连通性
*** Ping: testing ping reachability
h1 -> h2 h3
h2 -> h1 h3
h3 -> h1 h2
*** Results: 0% dropped (6/6 received)
link 用来关闭链路
mininet> link h3 s2 down
mininet可以通过--topo 的命令创建网络拓扑,也可通过--custom参数的形式使用自定义Python文件,在examples的目录下有多个写好的网络拓扑文件
mininet@mininet-vm:~/mininet$ sudo mn --topo single,3 #创建一个单交换机简单网络,主机数为3
mininet@mininet-vm:~/mininet$ sudo mn --topo single,3
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet>
mininet@mininet-vm:~/mininet$ sudo mn --topo tree,depth=2,fanout=3 #创建一个树形简单网络,深度2,扇出3
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4 h5 h6 h7 h8 h9
*** Adding switches:
s1 s2 s3 s4
*** Adding links:
(s1, s2) (s1, s3) (s1, s4) (s2, h1) (s2, h2) (s2, h3) (s3, h4) (s3, h5) (s3, h6) (s4, h7) (s4, h8) (s4, h9)
*** Configuring hosts
h1 h2 h3 h4 h5 h6 h7 h8 h9
*** Starting controller
c0
*** Starting 4 switches
s1 s2 s3 s4 ...
*** Starting CL
使用examples目录下的nat.py建立一个nat网络
mininet@mininet-vm:~/mininet$ sudo mn --custom examples/nat.py
*** 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>
当然你可以直接运行
sudo ./nat.py
由此可以根据需要直接使用自定义Python语句建立复杂网络,另外还有一种方法是使用MininetUI可视化修改,由于我的环境都是Server环境,这个相对简单就不进行介绍了。