MiniNet安装:执行如下指令html
$sudo apt install mininetnode
但运行时会出现python
$ sudo mn
*** No default OpenFlow controller found for default switch!
*** Falling back to OVS Bridgegit
OpenFlow模块没有安装。github
$git clone git://github.com/mininet/mininet
web
$cd mininet/util/
ajax
$ sudo ./install.sh -a
shell
测试安装cookie
$ sudo mn --test pingall *** 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 ... *** Waiting for switches to connect s1 *** Ping: testing ping reachability h1 -> h2 h2 -> h1 *** Results: 0% dropped (2/2 received) *** Stopping 1 controllers c0 *** Stopping 2 links .. *** Stopping 1 switches s1 *** Stopping 2 hosts h1 h2 *** Done completed in 5.292 seconds
使用很简单,下面以界面截图为例,简单讲述常见的几个命令便可:网络
$sudo mn --help Usage: mn [options] (type mn -h for details) The mn utility creates Mininet network from the command line. It can create parametrized topologies, invoke the Mininet CLI, and run tests. Options: -h, --help show this help message and exit --switch=SWITCH default|ivs|lxbr|ovs|ovsbr|ovsk|user[,param=value...] ovs=OVSSwitch default=OVSSwitch ovsk=OVSSwitch lxbr=LinuxBridge user=UserSwitch ivs=IVSSwitch ovsbr=OVSBridge --host=HOST cfs|proc|rt[,param=value...] rt=CPULimitedHost{'sched': 'rt'} proc=Host cfs=CPULimitedHost{'sched': 'cfs'} --controller=CONTROLLER default|none|nox|ovsc|ref|remote|ryu[,param=value...] ovsc=OVSController none=NullController remote=RemoteController default=DefaultController nox=NOX ryu=Ryu ref=Controller --link=LINK default|ovs|tc|tcu[,param=value...] default=Link ovs=OVSLink tcu=TCULink tc=TCLink --topo=TOPO linear|minimal|reversed|single|torus|tree[,param=value ...] linear=LinearTopo torus=TorusTopo tree=TreeTopo single=SingleSwitchTopo reversed=SingleSwitchReversedTopo minimal=MinimalTopo -c, --clean clean and exit --custom=CUSTOM read custom classes or params from .py file(s) --test=TEST none|build|all|iperf|pingpair|iperfudp|pingall -x, --xterms spawn xterms for each node -i IPBASE, --ipbase=IPBASE base IP address for hosts --mac automatically set host MACs --arp set all-pairs ARP entries -v VERBOSITY, --verbosity=VERBOSITY info|warning|critical|error|debug|output --innamespace sw and ctrl in namespace? --listenport=LISTENPORT base port for passive switch listening --nolistenport don't use passive listening port --pre=PRE CLI script to run before tests --post=POST CLI script to run after tests --pin pin hosts to CPU cores (requires --host cfs or --host rt) --nat [option=val...] adds a NAT to the topology that connects Mininet hosts to the physical network. Warning: This may route any traffic on the machine that uses Mininet's IP subnet into the Mininet network. If you need to change Mininet's IP subnet, see the --ipbase option. --version prints the version and exits --cluster=server1,server2... run on multiple servers (experimental!) --placement=block|random node placement for --cluster (experimental!)
sudo mn用于启动MiniNet(必须root权限)。
~$ sudo 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>
(1)MiniNet已经为大多数应用实现了四种类型的openflow网络拓扑:tree,single,linear和minimal。缺省状况下,建立的是minimal拓扑包括四个元素:one OpenFlow kernel switch connected to two hosts, plus the OpenFlowreference controller(交换机+两个节点+控制器)
(2)--topo 用于创建拓扑的参数,能够创建各类不一样的拓扑:
如指定一台交换机,三台主机
$ 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> net h1 h1-eth0:s1-eth1 h2 h2-eth0:s1-eth2 h3 h3-eth0:s1-eth3 s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:h3-eth0 c0
二层八叉树,即九台交换机加上64台主机
$ sudo mn --switch ovsk --controller ref --topo tree,depth=2,fanout=8 *** Creating network *** Adding controller *** Adding hosts: h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23 h24 h25 h26 h27 h28 h29 h30 h31 h32 h33 h34 h35 h36 h37 h38 h39 h40 h41 h42 h43 h44 h45 h46 h47 h48 h49 h50 h51 h52 h53 h54 h55 h56 h57 h58 h59 h60 h61 h62 h63 h64 *** Adding switches: s1 s2 s3 s4 s5 s6 s7 s8 s9 *** Adding links: (s1, s2) (s1, s3) (s1, s4) (s1, s5) (s1, s6) (s1, s7) (s1, s8) (s1, s9) (s2, h1) (s2, h2) (s2, h3) (s2, h4) (s2, h5) (s2, h6) (s2, h7) (s2, h8) (s3, h9) (s3, h10) (s3, h11) (s3, h12) (s3, h13) (s3, h14) (s3, h15) (s3, h16) (s4, h17) (s4, h18) (s4, h19) (s4, h20) (s4, h21) (s4, h22) (s4, h23) (s4, h24) (s5, h25) (s5, h26) (s5, h27) (s5, h28) (s5, h29) (s5, h30) (s5, h31) (s5, h32) (s6, h33) (s6, h34) (s6, h35) (s6, h36) (s6, h37) (s6, h38) (s6, h39) (s6, h40) (s7, h41) (s7, h42) (s7, h43) (s7, h44) (s7, h45) (s7, h46) (s7, h47) (s7, h48) (s8, h49) (s8, h50) (s8, h51) (s8, h52) (s8, h53) (s8, h54) (s8, h55) (s8, h56) (s9, h57) (s9, h58) (s9, h59) (s9, h60) (s9, h61) (s9, h62) (s9, h63) (s9, h64) *** Configuring hosts h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20 h21 h22 h23 h24 h25 h26 h27 h28 h29 h30 h31 h32 h33 h34 h35 h36 h37 h38 h39 h40 h41 h42 h43 h44 h45 h46 h47 h48 h49 h50 h51 h52 h53 h54 h55 h56 h57 h58 h59 h60 h61 h62 h63 h64 *** Starting controller c0 *** Starting 9 switches s1 s2 s3 s4 s5 s6 s7 s8 s9 ... *** Starting CLI:
1. minimal——最简单的,设置一个交换机和两个主机的简单拓扑,默认无--topo参数的状况下就是这样。其内部实现就是调用了single,2对应的函数
2. single,n——设置一个交换机,n个主机与之相连的拓扑
3. tree,depth=x,fanout=y——设置深度为x,每层树枝为y的树形拓扑。这样造成的拓扑的交换机个数就是(y的x次方-1)/(y-1),造成的主机的个数就是y的x次方。4. linear,x,y——设置线性拓扑,交换机线性相连,有x台交换机,每台交换机上连有y台主机
5. reversed,n——设置一个交换机,n个主机与之相连的拓扑,可是主机端口号大小与交换机端口号大小正好相反,即最小端口号对应交换机最大端口号
6. torus,x,y——设置双向环形拓扑,启动比较麻烦。
2-D Torus topology
WARNING: this topology has LOOPS and WILL NOT WORK
with the default controller or any Ethernet bridge
without STP turned on! It can be used with STP, e.g.:
# mn --topo torus,3,3 --switch lxbr,stp=1 --test pingall
能够用--custom参数使用一个Python 脚本,例如--custom ~/mytopo.py --topo mytopo用于指定open加载Python文件创建自定义拓扑必须在mytopo.py文件中以dictionary的形式定义:topos = { 'mytopo': ( lambda: MyTopo() ) }
$ sudo mn --custom ~/mininet/custom/topo-2sw-2host.py --topo mytopo *** 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> mininet> nodes available nodes are: c0 h1 h2 s3 s4 mininet> dump <Host h1: h1-eth0:10.0.0.1 pid=6725> <Host h2: h2-eth0:10.0.0.2 pid=6727> <OVSSwitch s3: lo:127.0.0.1,s3-eth1:None,s3-eth2:None pid=6732> <OVSSwitch s4: lo:127.0.0.1,s4-eth1:None,s4-eth2:None pid=6735> <Controller c0: 127.0.0.1:6653 pid=6718> mininet> net h1 h1-eth0:s3-eth1 h2 h2-eth0:s4-eth2 s3 lo: s3-eth1:h1-eth0 s3-eth2:s4-eth1 s4 lo: s4-eth1:s3-eth2 s4-eth2:h2-eth0 c0 mininet> s3 ifconfig enp6s0 Link encap:以太网 硬件地址 20:47:47:72:19:04 UP BROADCAST MULTICAST MTU:1500 跃点数:1 接收数据包:0 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:0 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:0 (0.0 B) 发送字节:0 (0.0 B) lo Link encap:本地环回 inet 地址:127.0.0.1 掩码:255.0.0.0 inet6 地址: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 跃点数:1 接收数据包:36142 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:36142 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1 接收字节:10517695 (10.5 MB) 发送字节:10517695 (10.5 MB) s3-eth1 Link encap:以太网 硬件地址 62:77:b4:ad:32:cf inet6 地址: fe80::6077:b4ff:fead:32cf/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:8 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:62 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:648 (648.0 B) 发送字节:8488 (8.4 KB) s3-eth2 Link encap:以太网 硬件地址 12:76:df:23:4d:d1 inet6 地址: fe80::1076:dfff:fe23:4dd1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:35 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:34 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:4568 (4.5 KB) 发送字节:4478 (4.4 KB) s4-eth1 Link encap:以太网 硬件地址 2a:a5:41:38:f1:45 inet6 地址: fe80::28a5:41ff:fe38:f145/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:34 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:35 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:4478 (4.4 KB) 发送字节:4568 (4.5 KB) s4-eth2 Link encap:以太网 硬件地址 9a:ec:f4:dd:be:85 inet6 地址: fe80::98ec:f4ff:fedd:be85/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:8 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:61 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:648 (648.0 B) 发送字节:8398 (8.3 KB) wlp7s0 Link encap:以太网 硬件地址 4c:34:88:a6:13:a0 inet 地址:192.168.0.104 广播:192.168.0.255 掩码:255.255.255.0 inet6 地址: fe80::351c:c1e9:50ec:91bb/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:996508 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:988661 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:1001980929 (1.0 GB) 发送字节:588414728 (588.4 MB)
详见(http://yuba.stanford.edu/foswiki/bin/view/OpenFlow/MininetWalkthrough)。
在用户主目录下执行了 git clone https://github.com/mininet/mininet,即mininet源码已经克隆到用户主目录,~/mininet/custom/topo-2sw-2host.py文件才存在,该文件定义了两个节点(h1,h2)+两个交换机(s3,s4)+一个转发控制(c0)的网络拓扑。
经过对文件 mininet/custom/topo-2sw-2host.py的修改来自定义拓扑结构
为了避免影响原来的内容,把配置模板拷贝到用户主目录
~$ cp ~/mininet/custom/topo-2sw-2host.py mytopo.py
修改mytopo.py增长主机h3,并增长h3到s4的链路,修改后的内容以下:
$ cat mytopo.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' ) rightHost1 = self.addHost( 'h3' ) leftSwitch = self.addSwitch( 's3' ) rightSwitch = self.addSwitch( 's4' ) # Add links self.addLink( leftHost, leftSwitch ) self.addLink( leftSwitch, rightSwitch ) self.addLink( rightSwitch, rightHost ) self.addLink( rightSwitch, rightHost1 ) topos = { 'mytopo': ( lambda: MyTopo() ) }
运行:
~$ sudo mn --custom mytopo.py --topo mytopo --mac *** Creating network *** Adding controller *** Adding hosts: h1 h2 h3 *** Adding switches: s3 s4 *** Adding links: (h1, s3) (s3, s4) (s4, h2) (s4, h3) *** Configuring hosts h1 h2 h3 *** Starting controller c0 *** Starting 2 switches s3 s4 ... *** Starting CLI:
因为 Mininet 也支持参数化拓扑,经过 Python 代码也能够建立一个灵活的拓扑结构,也可根据自定义传递进去的参数进行配置,而且可重用到多个环境中,下面简短列出其代码的大体结构及含义(不须要mn 直接运行py脚本。)
#!/usr/bin/python #coding=utf-8 from mininet.topo import Topo from mininet.net import Mininet from mininet.util import dumpNodeConnections from mininet.log import setLogLevel from mininet.cli import CLI class SingleSwitchTopo(Topo): def __init__(self, n=2, **opts): Topo.__init__(self, **opts) switch = self.addSwitch('s1') #添加一个交换机在拓扑中 for h in range(n): host = self.addHost('h%s' % (h + 1)) #添加主机到拓扑中 self.addLink(host, switch) #添加双向链接拓扑 def simpleTest(): topo = SingleSwitchTopo(n=4) net = Mininet(topo) #主要类来建立和管理网络 net.start() #启动您的拓扑网络 print "Dumping host connections" dumpNodeConnections(net.hosts) #转存文件链接 print "Testing network connectivity" net.pingAll() #全部节点彼此测试互连 CLI(net) #进入mininet>提示符 net.stop() #中止您的网络 if __name__ == '__main__': setLogLevel('info') # 设置 Mininet 默认输出级别,设置 info 它将提供一些有用的信息 simpleTest()
运行结果以下:
~$ chmod a+x simpleTest.py ~$ sudo ./simpleTest.py *** Creating network *** Adding controller *** Adding hosts: h1 h2 h3 h4 *** Adding switches: s1 *** Adding links: (h1, s1) (h2, s1) (h3, s1) (h4, s1) *** Configuring hosts h1 h2 h3 h4 *** Starting controller c0 *** Starting 1 switches s1 ... Dumping host connections h1 h1-eth0:s1-eth1 h2 h2-eth0:s1-eth2 h3 h3-eth0:s1-eth3 h4 h4-eth0:s1-eth4 Testing network connectivity *** Ping: testing ping reachability h1 -> h2 h3 h4 h2 -> h1 h3 h4 h3 -> h1 h2 h4 h4 -> h1 h2 h3 *** Results: 0% dropped (12/12 received) *** Starting CLI: mininet>
$sudo mininet/examples/miniedit.py
使用图形界面设置好拓扑后
,能够将其保存为python脚本mytopo1.py(选择File-Export Level 2 Script),之后直接运行python脚本(须要增长执行权限)便可重现拓扑。
python脚本代码mytopo1.py
#!/usr/bin/python from mininet.net import Mininet from mininet.node import Controller, RemoteController, OVSController from mininet.node import CPULimitedHost, Host, Node from mininet.node import OVSKernelSwitch, UserSwitch from mininet.node import IVSSwitch from mininet.cli import CLI from mininet.log import setLogLevel, info from mininet.link import TCLink, Intf from subprocess import call def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) c0=net.addController(name='c0', controller=Controller, protocol='tcp', port=6633) info( '*** Add switches\n') s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s1 = net.addSwitch('s1', cls=OVSKernelSwitch) info( '*** Add hosts\n') h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) info( '*** Add links\n') net.addLink(h1, s1) net.addLink(h2, s1) net.addLink(h3, s1) net.addLink(h4, s2) net.addLink(h5, s2) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s2').start([c0]) net.get('s1').start([c0]) info( '*** Post configure switches and hosts\n') CLI(net) net.stop() if __name__ == '__main__': setLogLevel( 'info' ) myNetwork()
运行:
~$ sudo chmod a+x mytopo1.py ~$ sudo ./mytopo1.py *** Adding controller *** Add switches *** Add hosts *** Add links *** Starting network *** Configuring hosts h5 h3 h4 h2 h1 *** Starting controllers *** Starting switches *** Post configure switches and hosts *** Starting CLI: mininet> dump <Host h5: h5-eth0:10.0.0.5 pid=12407> <Host h3: h3-eth0:10.0.0.3 pid=12409> <Host h4: h4-eth0:10.0.0.4 pid=12411> <Host h2: h2-eth0:10.0.0.2 pid=12413> <Host h1: h1-eth0:10.0.0.1 pid=12415> <OVSSwitch s2: lo:127.0.0.1,s2-eth1:None,s2-eth2:None pid=12399> <OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None,s1-eth3:None pid=12402> <Controller c0: 127.0.0.1:6633 pid=12391>
(3)--switch 用于选择交换机的种类,有如下交换机可供选择:
1. user——UserSwitch, 顾名思义,运行于用户空间的交换机。这种交换机的带宽比较小,ping的延迟也会比较大
2. ovs——OVSSwitch
3. ovsbr——OVSBridge ,就是处在桥接模式(stand-alone/bridge mode)的OVSSwitch
4. ovsk——也是OVSSwitch ,为了和mininet 2.0兼容而保留的参数
5. ovsl——OVSLegacyKernelSwitch,是传统的工做在内核空间的OVSSwitch,当前只能工做在root的命名空间中
6. ivs——IVSSwitch,即Indigo Virtual Switch
7. lxbr,stp=1——LinuxBridge,其中stp=1表示开启生成树协议,避免环形拓扑形成的广播风暴。
8. default——默认无--switch参数的时候,就是OVSSwitch,也可使用--switch default来指定。
例如sudomn --switchuser使用用户态的交换
sudo mn --switch ovs,protocols=openflow13
(4)--controller 用于选择控制器的种类,有如下控制器可供选择:
能够是参考控制器,NOX或者虚拟机以外的远端控制器,一个指定远端控制器的方法:
sudo mn --controller=remote --ip=[controller IP] --port=[controllerlistening port]
实例(POX做为控制器):
$ sudo ./install.sh -a执行后会在用户主目录下安装pox,进入该子目录cd $~/pox
也能够用git克隆一个pox
git clone http://github.com/noxrepo/pox
启动pox控制器(无需超级用户权限),一开始是这样的。
~/pox$ ./pox.py openflow.of_01 --address=127.0.0.1 --port=6666
POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al.
INFO:core:POX 0.2.0 (carp) is up.
在另外一终端启动mininet
$ sudo mn --controller=remote,ip=127.0.0.1,port=6666 *** 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> dpctl dump-flows *** s1 ------------------------------------------------------------------------ NXST_FLOW reply (xid=0x4): mininet> h1 ping -c2 h2 PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. From 10.0.0.1 icmp_seq=1 Destination Host Unreachable From 10.0.0.1 icmp_seq=2 Destination Host Unreachable --- 10.0.0.2 ping statistics --- 2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1019ms pipe 2 mininet> dump <Host h1: h1-eth0:10.0.0.1 pid=8928> <Host h2: h2-eth0:10.0.0.2 pid=8930> <OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=8935> <RemoteController{'ip': '127.0.0.1', 'port': 6666} c0: 127.0.0.1:6666 pid=8922> mininet>
说明该虚拟网络已经使用了pox控制器,这时候回到pox那个终端,就变成这样了
~/pox$ ./pox.py openflow.of_01 --address=127.0.0.1 --port=6666 POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al. INFO:core:POX 0.2.0 (carp) is up. INFO:openflow.of_01:[None 1] closed INFO:openflow.of_01:[00-00-00-00-00-01 2] connected
上面咱们能够看到主机h1和h2是ping不通的,由于控制器没有定义h1到h2的转发规则,加上pox.forwarding.l2_pairs就能够了:
$ ./pox.py openflow.of_01 --address=127.0.0.1 --port=6666 pox.forwarding.l2_pairs POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al. INFO:forwarding.l2_pairs:Pair-Learning switch running. INFO:core:POX 0.2.0 (carp) is up. INFO:openflow.of_01:[None 1] closed INFO:openflow.of_01:[00-00-00-00-00-01 2] connected
$ sudo mn --controller=remote,ip=127.0.0.1,port=6666 *** 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> h1 ping -c2 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=53.3 ms 64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.042 ms --- 10.0.0.2 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 0.042/26.694/53.346/26.652 ms
不制定port默认端口号为6633
流表测试:
启动pox
$ ./pox.py openflow.of_01 --address=127.0.0.1 --port=6633 py
启动mininet
$ sudo mn --controller=remote,ip=127.0.0.1
mininet> dpctl dump-flows //数据流表空 *** s1 ------------------------------------------------------------------------ NXST_FLOW reply (xid=0x4): mininet> pingall //不能够ping通 *** Ping: testing ping reachability h1 -> X h2 -> X *** Results: 100% dropped (0/2 received) mininet> dump <Host h1: h1-eth0:10.0.0.1 pid=8730> <Host h2: h2-eth0:10.0.0.2 pid=8732> <OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=8737> <RemoteController{'ip': '127.0.0.1'} c0: 127.0.0.1:6633 pid=8722>
不通。
pox配置流表
POX> from pox.lib.addresses import IPAddr POX> from pox.lib.addresses import EthAddr POX> import pox.openflow.libopenflow_01 as of //导出核心模块,并命名为of POX> core.openflow.connections.keys() //获取链接控制端的openflow switch的key [1] POX> msg=of.ofp_flow_mod() //编辑消息 POX> msg.priority=3 POX> msg.match.in_port=1 POX> msg.actions.append(of.ofp_action_output(port=2)) POX> core.openflow.connections[1].send(msg) POX> msg.match.in_port=2 POX> msg.actions.append(of.ofp_action_output(port=1)) POX> core.openflow.connections[1].send(msg) POX>
mininet端
mininet> dump <Host h1: h1-eth0:10.0.0.1 pid=8730> <Host h2: h2-eth0:10.0.0.2 pid=8732> <OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=8737> <RemoteController{'ip': '127.0.0.1'} c0: 127.0.0.1:6633 pid=8722> mininet> dpctl dump-flows //显示已添加流表 *** s1 ------------------------------------------------------------------------ NXST_FLOW reply (xid=0x4): cookie=0x0, duration=53.468s, table=0, n_packets=0, n_bytes=0, idle_age=53, priority=3,in_port=1 actions=output:2 cookie=0x0, duration=19.214s, table=0, n_packets=0, n_bytes=0, idle_age=19, priority=3,in_port=2 actions=output:2,output:1 mininet> pingall //能够ping通 *** Ping: testing ping reachability
POXDESK实现拓扑的显示
今天实习次日,开始深刻逐渐玩POX跟mininet!以前只是会基本的操做,慢慢的要更加了解!今天早上就实现了一下poxdesk的功能!
操做步骤以下:
git clone https://github.com/noxrepo/pox cd pox git checkout betta cd ext git clone https://github.com/MurphyMc/poxdesk cd poxdesk wget http://downloads.sourceforge.net/qooxdoo/qooxdoo-2.0.2-sdk.zip unar qooxdoo-2.0.2-sdk.zip mv qooxdoo-2.0.2-sdk qx cd poxdesk ./generate.py cd ../../.. ./pox.py samples.pretty_log web messenger messenger.log_service messenger.ajax_transport openflow.of_service poxdesk
(5)--host 用于选择主机的种类,有如下主机可供选择:
1. proc——就是简单的主机,在没有--host参数的时候,它就是默认选项
2. rt—— # BL: Setting the correct period/quota is tricky, particularly
3. # for RT. RT allows very small quotas, but the overhead
4. # seems to be high. CFS has a mininimum quota of 1 ms, but
5. # still does better with larger period values.
6. cfs——、
(6)--mac: 做用是让MAC地址易读,即 setsthe switch MAC and host MAC and IP addrs to small, unique, easy-to-read IDs。默认状况下,主机跟交换机启动后分配的MAC地址是随机的,这在某些状况下不方便查找问题。可使用–mac选项,这样主机跟交换机分配到的MAC地址跟他们的ID是一致的,容易经过MAC地址较快找到对应的节点。使用XTerm
经过使用-x参数,mn在启动后会在每一个节点上自动打开一个XTerm,方便某些状况下的对多个节点分别进行操做。命令为
sudo mn -x
在进入mn cli以后,也可使用 xterm node 命令指定启动某些节点上的xterm,例如分别启用s1跟h2上的xterm,能够用
xterm s1 h2
在mn cli中,使用link命令,禁用或启用某条链路,格式为 link node1 node2 up/down,例如临时禁用s1跟h2之间的链路,能够用
link s1 h2 down
默认状况下,主机节点有用独立的名字空间(namespace),而控制节点跟交换节点都在根名字空间(root namespace)中。若是想要让全部节点拥有各自的名字空间,须要添加 –innamespace 参数,即启动方式为 sudo mn –innamespace
执行
$ sudo mn -c
会进行清理配置操做,适合故障后恢复。
其余一些调试可能用到的命令:Nodes,Net,H2 ping h3,S1 ifconfig等
表 1.Mininet 经常使用指令
名称 | 做用 |
---|---|
nodes | 查看所有节点 |
net | 查看链路信息 |
dump | 输出各节点的信息 |
h1 ping -c 4 h2 | 测试主机之间的连通性 |
iperf | 两个节点之间用指定简单的 TCP 测试 |
iperfudp | 两个节点之间用指定款单 udp 进行测试 |
noecho | 运行交互窗口,关闭回应 |
pingpair | 两个主机将互 ping |
help | 列出命令文档,查看命令帮助: help command |
dpctl | 在全部交换机 |
exit/quit | 退出 mininet 命令行 |
hX ifconfig | 查看当前那主机的 ip 地址,如: h1 ifconfig |
py/sh | 执行 python 表达式或运行外部 shell 程序 |
参数使用部分例子:
下面的指令表明发h3个包ping 3个包的方法来测试主机h3跟主机h1之间连通状况
mininet> h3 ping -c 3 h1 PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data. 64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.287 ms 64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.044 ms 64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.047 ms --- 10.0.0.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2047ms rtt min/avg/max/mdev = 0.044/0.126/0.287/0.113 ms
wireshark捕捉状况
dpctl
mininet> dpctl show *** s3 ------------------------------------------------------------------------ OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000003 n_tables:254, n_buffers:256 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst 1(s3-eth1): addr:1e:f9:ca:69:45:88 config: 0 state: 0 current: 10GB-FD COPPER speed: 10000 Mbps now, 0 Mbps max 2(s3-eth2): addr:8a:92:49:2a:34:a1 config: 0 state: 0 current: 10GB-FD COPPER speed: 10000 Mbps now, 0 Mbps max LOCAL(s3): addr:82:d9:53:79:1d:42 config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0 *** s4 ------------------------------------------------------------------------ OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000004 n_tables:254, n_buffers:256 capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst 1(s4-eth1): addr:82:73:74:93:93:10 config: 0 state: 0 current: 10GB-FD COPPER speed: 10000 Mbps now, 0 Mbps max 2(s4-eth2): addr:ee:87:7a:4b:55:de config: 0 state: 0 current: 10GB-FD COPPER speed: 10000 Mbps now, 0 Mbps max LOCAL(s4): addr:1a:3c:80:17:7f:4f config: PORT_DOWN state: LINK_DOWN speed: 0 Mbps now, 0 Mbps max OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
from mininet.topo import Topo class Router_Topo(Topo): def __init__(self): "Create P2P topology." # Initialize topology Topo.__init__(self) # Add hosts and switches H1 = self.addHost('h1') H2 = self.addHost('h2') H3 = self.addHost('h3') S1 = self.addSwitch('s1') S2 = self.addSwitch('s2') # Add links self.addLink(H1, S1) self.addLink(H2, S1) self.addLink(H2, S2) self.addLink(H3, S2) topos = { 'router': (lambda: Router_Topo()) }
运行
$ sudo mn --custom Router.py --topo router --mac *** Creating network *** Adding controller *** Adding hosts: h1 h2 h3 *** Adding switches: s1 s2 *** Adding links: (h1, s1) (h2, s1) (h2, s2) (h3, s2) *** Configuring hosts h1 h2 h3 *** Starting controller c0 *** Starting 2 switches s1 s2 ... *** Starting CLI: mininet> net h1 h1-eth0:s1-eth1 h2 h2-eth0:s1-eth2 h2-eth1:s2-eth1 h3 h3-eth0:s2-eth2 s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s2 lo: s2-eth1:h2-eth1 s2-eth2:h3-eth0 c0 mininet> h1 ping -c 3 h3 PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data. From 10.0.0.1 icmp_seq=1 Destination Host Unreachable From 10.0.0.1 icmp_seq=2 Destination Host Unreachable From 10.0.0.1 icmp_seq=3 Destination Host Unreachable --- 10.0.0.3 ping statistics --- 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2033ms pipe 3 mininet> h1 ifconfig h1-eth0 192.168.12.1 netmask 255.255.255.0 mininet> h2 ifconfig h2-eth0 192.168.12.2 netmask 255.255.255.0 mininet> h2 ifconfig h2-eth1 192.168.23.2 netmask 255.255.255.0 mininet> h3 ifconfig h3-eth0 192.168.23.3 netmask 255.255.255.0 mininet> h1 route add default gw 192.168.12.2 mininet> h3 route add default gw 192.168.23.2 mininet> h2 sysctl net.ipv4.ip_forward=1 net.ipv4.ip_forward = 1 mininet> h1 ping -c 3 h3 PING 192.168.23.3 (192.168.23.3) 56(84) bytes of data. 64 bytes from 192.168.23.3: icmp_seq=1 ttl=63 time=3.33 ms 64 bytes from 192.168.23.3: icmp_seq=2 ttl=63 time=0.584 ms 64 bytes from 192.168.23.3: icmp_seq=3 ttl=63 time=0.046 ms --- 192.168.23.3 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 0.046/1.321/3.335/1.441 ms
这里能够看到一开始主机h1和h3是ping不一样的,执行了一下命令配置了路由就能够ping通:
mininet> sudo mn --custom Router.py --topo router
mininet> h1 ifconfig h1-eth0 192.168.12.1 netmask 255.255.255.0
mininet> h2 ifconfig h2-eth0 192.168.12.2 netmask 255.255.255.0
mininet> h2 ifconfig h2-eth1 192.168.23.2 netmask 255.255.255.0
mininet> h3 ifconfig h3-eth0 192.168.23.3 netmask 255.255.255.0
mininet> h1 route add default gw 192.168.12.2
mininet> h3 route add default gw 192.168.23.2
mininet> h2 sysctl net.ipv4.ip_forward=1
Enough for MiniNet!
参见: