介绍
Mininet 作为一个轻量级软定义网络研发和测试平台,其主要特性包括:
- 支持 Openflow、OpenvSwitch 等软定义网络部件
- 方便多人协同开发
- 支持系统级的还原测试支持复杂拓扑、自定义拓扑
- 提供 Python API
- 很好的硬件移植性(Linux 兼容),结果有更好的说服力
- 高扩展性,支持超过 4096 台主机的网络结构
.如果想要对某个节点的虚拟机单独进行命令操作,也十分简单,命令格式为 node cmd
。例如查看交换机 s1 上的网络信息,我们只需要在执行的 ifconfig 命令前加上 s1 主机标志即可,即 s1 ifconfig
,同样,如果我们想用 ping 3 个包的方法来测试 h2 跟 h3 之间连通情况,只需要执行 h2 ping -c 3 h3
即可。
mininet> h2 ping -c 3 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=7.19 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.239 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.136 ms
— 10.0.0.3 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2006ms
rtt min/avg/max/mdev = 0.136/2.523/7.194/3.303 ms
自定义拓扑
Mininet 提供了 Python API,可以用来方便的自定义拓扑结构。
在 mininet/custom 目录下给出了几个例子。例如在 topo-2sw-2host.py 文件中定义了一个 mytopo,则可以通过 --topo
选项来指定使用这一拓扑,命令为 sudo mn --custom ~/mininet/custom/topo-2sw-2host.py --topo mytopo --test pingall
。
同样的,我们可以通过下面的 Python 脚本来完成对一个2 层 tree 拓扑网络的测试。
from mininet.net import Mininet
from mininet.topolib import TreeTopo
tree4 = TreeTopo(depth=2,fanout=2)
net = Mininet(topo=tree4)
net.start()
h1, h4 = net.hosts[0], net.hosts[3]
print h1.cmd('ping -c1 %s' % h4.IP())
net.stop()
链路操作
在 Mininet cli 中,使用 link
命令,禁用或启用某条链路,格式为
link node1 node2 up/down
例如临时禁用 s1 跟 h2 之间的链路,可以用
link s1 h2 down
<