Mininet中文使用教程.docx
《Mininet中文使用教程.docx》由会员分享,可在线阅读,更多相关《Mininet中文使用教程.docx(25页珍藏版)》请在冰点文库上搜索。
Mininet中文使用教程
Mininet中文使用教程
译者注:
这篇Blog是在学习SDN过程中翻译的Mininet官方的文档。
文档主要是介绍了Mininet的简单用法。
会分成几个局部放出来,原文。
下面是正文
第1局部:
EverydayMininetUsage
首先是是命令语法
∙$这个符号代表现在处于Linu*的shell交互下,需要使用的是Linu*命令
∙mininet>这个符号表示现在处于Mininet交互下,需要使用的是Mininet的命令
∙#这个符号表示的是现在处于Linu*的root权限下。
以上相应的状态下下属于对应的命令,就能够得到正常的输出。
需要注意的是mininet>的情况比拟特殊,需要使用minient的命令来进展交互。
DisplayStartupOptions
我们首先来启动Mininet。
键入以下命令来显示Mininet的帮助信息:
$sudomn-h
Usage:
mn[options]
(typemn-hfordetails)
ThemnutilitycreatesMininetnetworkfromthemandline.Itcancreate
parametrizedtopologies,invoketheMininetCLI,andruntests.
Options:
-h,--helpshowthishelpmessageande*it
--switch=SWITCHivs|ovsk|ovsl|user[,param=value...]
--host=HOSTcfs|proc|rt[,param=value...]
--controller=CONTROLLER
none|no*|ovsc|ref|remote[,param=value...]
--link=LINKdefault|tc[,param=value...]
--topo=TOPOlinear|minimal|reversed|single|tree[,param=value...]
-c,--cleancleanande*it
--custom=CUSTOMreadcustomtopoandnodeparamsfrom.pyfile
--test=TESTcli|build|pingall|pingpair|iperf|all|iperfudp|none
-*,--*termsspawn*termsforeachnode
-iIPBASE,--ipbase=IPBASE
baseIPaddressforhosts
--macautomaticallysethostMACs
--arpsetall-pairsARPentries
-vVERBOSITY,--verbosity=VERBOSITY
info|warning|critical|error|debug|output
--innamespaceswandctrlinnamespace"
--listenport=LISTENPORT
baseportforpassiveswitchlistening
--nolistenportdon'tusepassivelisteningport
--pre=PRECLIscripttorunbeforetests
--post=POSTCLIscripttorunaftertests
--pinpinhoststoCPUcores(requires--hostcfsor--host
rt)
--version
如上所示,输出了mn的帮助信息。
StartWireshark
为了使用Wireshark来查看OpenFlow的控制信息,我们先翻开Wireshark并让他在后台运行。
$sudowireshark&
在Wireshark的过滤选项中,输入of,然后选择Apply。
InWireshark,clickCapture,thenInterfaces,thenselectStartontheloopbackinterface(lo).
现在窗口上暂时应该没有任何OpenFlow的数据包。
注:
在MininetVM镜像中Wireshark是默认已经安装的。
如果你的系统中没有Wireshark的和OpenFlow,您可以使用Mininet的install.sh脚本,按以下步骤安装:
$cd~
$gitclones:
//github./mininet/mininet#如果它尚不存在
$mininet/util/install.sh-w
如果已经安装了Wireshark,但是运行不了〔e.g.你得到一个类似$DISPLAYnotset之类的错误信息,可以参考FAQ,:
s:
//github./mininet/mininet/wiki/FAQ*wiki-*11-forwarding〕
设置好*11就可以正常运行GUI程序,并且使用*term之类的终端仿真器了,后面的演示中可以用到。
InteractwithHostsandSwitches
StartaminimaltopologyandentertheCLI:
$sudomn
默认的最小拓扑构造包含有两台主机〔h1,h2〕,还有一个OpenFlow的交换机,一个OpenFlow的控制器四台设备。
这种拓扑接口也可以使用--topo=minimal来指定。
当然我们也可以使用其他的拓扑构造,具体信息可以看--topo的信息。
现在四个实体〔h1,h2,c0,s1〕都在运行着。
c0作为控制器,是可以放在虚拟机外部的。
如果没有具体的测试作为参数传递时,我们可以使用Mininet交互。
在Wireshark的窗口中,你会看到核交换机连接到控制器。
显示MininetCLI命令:
mininet>help
Documentedmands(typehelp):
========================================
EOFe*itintfslinknoechopingpairpysource*term
dpctlgtermiperfnetpingallpingpairfullquittime
dumphelpiperfudpnodespingallfullp*sh*
Youmayalsosendamandtoanodeusing:
mand{args}
Fore*ample:
mininet>h1ifconfig
TheinterpreterautomaticallysubstitutesIPaddresses
fornodenameswhenanodeisthefirstarg,somands
like
mininet>h2pingh3
shouldwork.
Somecharacter-orientedinteractivemandsrequire
noecho:
mininet>noechoh2vifoo.py
However,startingupan*term/gtermisgenerallybetter:
mininet>*termh2
显示节点:
mininet>nodes
availablenodesare:
c0h1h2s1
显示网络:
mininet>net
h1h1-eth0:
s1-eth1
h2h2-eth0:
s1-eth2
s1lo:
s1-eth1:
h1-eth0s1-eth2:
h2-eth0
c0
输出所有节点的信息:
mininet>dump
h1-eth0:
10.0.0.1pid=3278>
h2-eth0:
10.0.0.2pid=3279>
lo:
127.0.0.1,s1-eth1:
None,s1-eth2:
Nonepid=3282>
127.0.0.1:
6633pid=3268>
从上面的输出中,你可以看到有一台交换机和两台主机。
在Mininet的CLI中第一个字符串是设备名,那后面的命令就在该设备上执行。
例如我们想在h1设备上执行ifconfig则输入如下命令:
mininet>h1ifconfig-a
h1-eth0Linkencap:
EthernetHWaddr3e:
94:
43:
b1:
ad:
48
inetaddr:
10.0.0.1Bcast:
10.255.255.255Mask:
255.0.0.0
inet6addr:
fe80:
:
3c94:
43ff:
feb1:
ad48/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
22errors:
0dropped:
0overruns:
0frame:
0
T*packets:
8errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
1764(1.7KB)T*bytes:
648(648.0B)
loLinkencap:
LocalLoopback
inetaddr:
127.0.0.1Mask:
255.0.0.0
inet6addr:
:
:
1/128Scope:
Host
UPLOOPBACKRUNNINGMTU:
65536Metric:
1
R*packets:
0errors:
0dropped:
0overruns:
0frame:
0
T*packets:
0errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
0
R*bytes:
0(0.0B)T*bytes:
0(0.0B)
上面的输出中,可以看见h1-eth0跟lo两个接口,需要注意的是,在Linu*系统的shell中运行ifconfig是看不到h1-eth0。
与h1-eth0相反的是,switch默认是跑在root的网络namespace上面,所以在switch上执行命令与在Linu*下的shell中是一样的。
mininet>s1ifconfig-a
eth0Linkencap:
EthernetHWaddr08:
00:
27:
98:
dc:
aa
inetaddr:
10.0.2.15Bcast:
10.0.2.255Mask:
255.255.255.0
inet6addr:
fe80:
:
a00:
27ff:
fe98:
dcaa/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
46716errors:
0dropped:
0overruns:
0frame:
0
T*packets:
40265errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
10804203(10.8MB)T*bytes:
40122199(40.1MB)
loLinkencap:
LocalLoopback
inetaddr:
127.0.0.1Mask:
255.0.0.0
inet6addr:
:
:
1/128Scope:
Host
UPLOOPBACKRUNNINGMTU:
65536Metric:
1
R*packets:
43654errors:
0dropped:
0overruns:
0frame:
0
T*packets:
43654errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
0
R*bytes:
37264504(37.2MB)T*bytes:
37264504(37.2MB)
l*cbr0Linkencap:
EthernetHWaddrfe:
5e:
f0:
f7:
a6:
f3
inetaddr:
10.0.3.1Bcast:
10.0.3.255Mask:
255.255.255.0
inet6addr:
fe80:
:
a8c4:
b5ff:
fea6:
2809/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
52errors:
0dropped:
0overruns:
0frame:
0
T*packets:
20errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
0
R*bytes:
4759(4.7KB)T*bytes:
2952(2.9KB)
ovs-systemLinkencap:
EthernetHWaddr3e:
79:
59:
3d:
d9:
bb
BROADCASTMULTICASTMTU:
1500Metric:
1
R*packets:
0errors:
0dropped:
0overruns:
0frame:
0
T*packets:
0errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
0
R*bytes:
0(0.0B)T*bytes:
0(0.0B)
s1Linkencap:
EthernetHWaddr6e:
8c:
5d:
91:
d5:
44
inet6addr:
fe80:
:
fc47:
8aff:
fe6a:
4155/64Scope:
Link
UPBROADCASTRUNNINGMTU:
1500Metric:
1
R*packets:
13errors:
0dropped:
0overruns:
0frame:
0
T*packets:
8errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
0
R*bytes:
1026(1.0KB)T*bytes:
648(648.0B)
s1-eth1Linkencap:
EthernetHWaddr5e:
a2:
f7:
86:
f3:
b1
inet6addr:
fe80:
:
5ca2:
f7ff:
fe86:
f3b1/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
8errors:
0dropped:
0overruns:
0frame:
0
T*packets:
22errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
648(648.0B)T*bytes:
1764(1.7KB)
s1-eth2Linkencap:
EthernetHWaddrb2:
c6:
37:
e0:
d9:
61
inet6addr:
fe80:
:
b0c6:
37ff:
fee0:
d961/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
8errors:
0dropped:
0overruns:
0frame:
0
T*packets:
21errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
648(648.0B)T*bytes:
1674(1.6KB)
veth14524JLinkencap:
EthernetHWaddrfe:
ca:
13:
f5:
dd:
b4
inet6addr:
fe80:
:
fcca:
13ff:
fef5:
ddb4/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
8errors:
0dropped:
0overruns:
0frame:
0
T*packets:
40errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
648(648.0B)T*bytes:
4190(4.1KB)
veth2K19CELinkencap:
EthernetHWaddrfe:
f1:
f7:
e8:
49:
45
inet6addr:
fe80:
:
fcf1:
f7ff:
fee8:
4945/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
8errors:
0dropped:
0overruns:
0frame:
0
T*packets:
42errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
648(648.0B)T*bytes:
4370(4.3KB)
veth9WSHRKLinkencap:
EthernetHWaddrfe:
87:
1d:
33:
f6:
41
inet6addr:
fe80:
:
fc87:
1dff:
fe33:
f641/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
8errors:
0dropped:
0overruns:
0frame:
0
T*packets:
43errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
648(648.0B)T*bytes:
4460(4.4KB)
vethH2K7R5Linkencap:
EthernetHWaddrfe:
5e:
f0:
f7:
a6:
f3
inet6addr:
fe80:
:
fc5e:
f0ff:
fef7:
a6f3/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
14errors:
0dropped:
0overruns:
0frame:
0
T*packets:
48errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
1776(1.7KB)T*bytes:
5030(5.0KB)
vethO99MI2Linkencap:
EthernetHWaddrfe:
cf:
ee:
97:
fb:
7f
inet6addr:
fe80:
:
fccf:
eeff:
fe97:
fb7f/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
R*packets:
14errors:
0dropped:
0overruns:
0frame:
0
T*packets:
51errors:
0dropped:
0overruns:
0carrier:
0
collisions:
0t*queuelen:
1000
R*bytes:
1767(1.7KB)T*bytes:
5294(5.2KB)
上面的输出中包含交换机的虚拟网卡s1,以及主机的eth0。
为了区别显示host主机的网络是隔离的,我们可以通过arp与route命令来做演示,分别在s1与h1上面演示如下:
mininet>s1arp
AddressHWtypeHWaddressFlagsMaskIface
localhostether00:
16:
3e:
54:
9c:
03Cl*cbr0
localhostether52:
54:
00:
12:
35:
02Ceth0
localhostether52:
54:
00:
12:
35:
03Ceth0
localhostether00:
16:
3e:
51:
24:
a7Cl*cbr0
mininet>s1route
KernelIProutingtable
DestinationGatewayGenmaskFlagsMetricRefUseIface
defaultlocalhost0.0.0.0UG000eth0
10.0.2.0*255.255.255.0U000eth0
10.0.3.0*255.255.255.0U000l*cbr0
172.17.0.0*255.255.0.0U000docker0
mininet>h1arp
mininet>h1route
KernelIProutingtable
DestinationGatewayGenmaskFlagsMetricRefUseIface
10.0.0.0*255.0.0.0U000h1-eth0
这样可以做到将每一个主机,交换机,以及控制器都放到他自己的标准的networknamespace中,但是这种做法并没有什么特别的优势,除非你想复制一个非常复杂的网络。
Mininet不支持这种做法,你可以通过--innamespace参数来查看更多的信息。
译者注:
感觉有点像L*C或者说想最近比拟火的Docker
注意:
只有网络是虚拟出来的,每一个主机里面的进程使用的都是同一套目录,可以看到一样的进程集合,我们打印不同主机下面的进程列表看看:
mininet>h1ps-a
PIDTTYTIMECMD
3899pts/300:
00:
0