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!
參見: