Mininet 是一个虚拟网络工具,使用它创建一个真实的虚拟网络,在一台机器(虚拟机、云或本机)上运行真实的内核、交换机和应用程序代码。它支持 OpenFlow、OpenvSwith 等各种协议。
特性
- 支持 OpenFlow、OpenvSwitch 等软定义网路
- 支持系统级的还原测试
- 支持复杂拓扑,自定义拓扑
- 提供 Python API,方便多人协作开发
- 硬件移植性好
- 高扩展性
- 支持上千台主机的网络结构
安装
源码安装
- 下载源码
git clone git://github.com/mininet/mininet- 安装
cd mininet/util/
sudo ./install.sh- 使用
sudo mn --test pingall测试
help
选项:
--topo:自定义拓扑,如 linear|minimal|reversed|single|torus|tree[,param=value…] minimal=MinimalTopo linear=LinearTopo--link:自定义网络参数,如 default|ovs|tc|tcu--switch:自定义虚拟交换机,如 default|ivs|lxbr|ovs|ovsbr|ovsk|user--controller:自定义控制器,如 default|none|nox|ovsc|ref|remote|ryu--nat:自动设置 NAT--cluster:集群模式,将网络拓扑运行在多台机器上--mac:自动设置主机 MAC--arp:自动设置 ARP 表项
使用
基础使用
- 使用
OpenFlow1.3协议,连接 ovs 交换机
$ sudo mn --controller=remote,ip=127.0.0.1 --mac --switch=ovs,protocols=OpenFlow13- 测试
> pingall- 交互模式,直接输入
mn命令查看:
$ mn
*** 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>- help
mininet> help
Documented commands (type help <topic>):
========================================
EOF gterm iperfudp nodes pingpair py switch xterm
dpctl help link noecho pingpairfull quit time
dump intfs links pingall ports sh wait
exit iperf net pingallfull px source x
You may also send a command to a node using:
<node> 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
mininet>部分解释:
-
nodes:查看所有节点 -
dump:查看各节点的信息 -
net:查看链路信息 -
links:查看网络接口连接拓扑 -
link:开启或关闭网络接口,如link s1 h1 up -
xterm:开启终端 -
dpctl:查看 OpenFlow 相关信息,如 ports,流表等 -
pingall:自动ping测试 -
py:执行python命令,如py h1.IP()获取 h1 的 ip 地址 -
查看节点信息
mininet> nodes
available nodes are:
c0 h1 h2 s1
mininet>- dump 设备信息
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=30667>
<Host h2: h2-eth0:10.0.0.2 pid=30669>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=30674>
<Controller c0: 127.0.0.1:6653 pid=30660>
mininet>- 查看链路信息
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0- 查看交换机 s1 的 ports 信息
mininet> dpctl dump-ports s1
*** s1 ------------------------------------------------------------------------
OFPST_PORT reply (xid=0x4): 1 ports
port LOCAL: rx pkts=0, bytes=0, drop=16, errs=0, frame=0, over=0, crc=0
tx pkts=0, bytes=0, drop=0, errs=0, coll=0
mininet>- 查看 h1 的网卡
mininet> h1 ifconfig -a
h1-eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.1 netmask 255.0.0.0 broadcast 10.255.255.255
inet6 fe80::3cc0:4aff:fe33:cf98 prefixlen 64 scopeid 0x20<link>
ether 3e:c0:4a:33:cf:98 txqueuelen 1000 (Ethernet)
RX packets 37 bytes 3934 (3.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11 bytes 866 (866.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
mininet>- 由 h1 ping 一次 h2
mininet> h1 ping -c1 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=9.03 ms
--- 10.0.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 1ms
rtt min/avg/max/mdev = 9.031/9.031/9.031/0.000 ms
mininet>自定义网络拓扑
$ mn --topo tree,3
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4 h5 h6 h7 h8
*** Adding switches:
s1 s2 s3 s4 s5 s6 s7
*** Adding links:
(s1, s2) (s1, s5) (s2, s3) (s2, s4) (s3, h1) (s3, h2) (s4, h3) (s4, h4) (s5, s6) (s5, s7) (s6, h5) (s6, h6) (s7, h7) (s7, h8)
*** Configuring hosts
h1 h2 h3 h4 h5 h6 h7 h8
*** Starting controller
c0
*** Starting 7 switches
s1 s2 s3 s4 s5 s6 s7 ...
*** Starting CLI:
mininet> nodes
available nodes are:
c0 h1 h2 h3 h4 h5 h6 h7 h8 s1 s2 s3 s4 s5 s6 s7
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=32448>
<Host h2: h2-eth0:10.0.0.2 pid=32450>
<Host h3: h3-eth0:10.0.0.3 pid=32452>
<Host h4: h4-eth0:10.0.0.4 pid=32454>
<Host h5: h5-eth0:10.0.0.5 pid=32456>
<Host h6: h6-eth0:10.0.0.6 pid=32458>
<Host h7: h7-eth0:10.0.0.7 pid=32460>
<Host h8: h8-eth0:10.0.0.8 pid=32462>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=32467>
<OVSSwitch s2: lo:127.0.0.1,s2-eth1:None,s2-eth2:None,s2-eth3:None pid=32470>
<OVSSwitch s3: lo:127.0.0.1,s3-eth1:None,s3-eth2:None,s3-eth3:None pid=32473>
<OVSSwitch s4: lo:127.0.0.1,s4-eth1:None,s4-eth2:None,s4-eth3:None pid=32476>
<OVSSwitch s5: lo:127.0.0.1,s5-eth1:None,s5-eth2:None,s5-eth3:None pid=32479>
<OVSSwitch s6: lo:127.0.0.1,s6-eth1:None,s6-eth2:None,s6-eth3:None pid=32482>
<OVSSwitch s7: lo:127.0.0.1,s7-eth1:None,s7-eth2:None,s7-eth3:None pid=32485>
<Controller c0: 127.0.0.1:6653 pid=32441>
mininet>自定义网络参数
$ mn --link tc,bw=10,delay=10ms
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(10.00Mbit 10ms delay) (10.00Mbit 10ms delay) (h1, s1) (10.00Mbit 10ms delay) (10.00Mbit 10ms delay) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 1 switches
s1 ...(10.00Mbit 10ms delay) (10.00Mbit 10ms delay)
*** Starting CLI:
mininet> iperf
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['9.50 Mbits/sec', '12.0 Mbits/sec']
mininet>使用 python api
- API 参考:http://mininet.org/api/annotated.html
- example 代码:https://github.com/mininet/mininet/tree/master/examples