實驗拓撲
控制器:RYU
交換機:s1,s2
主機:h1,h2,h3,h3
聯通性(直連):
h1<->s1;h2<->s1
h3<->s2;h4<->s2
s1<->s2
拓撲代碼如下:
#!/user/bin/env python from mininet.topo import Topo class MyTopo(Topo): def build(self): left=[] left.append(self.addHost("h1")) left.append(self.addHost("h2")) right=[] right.append(self.addHost("h3")) right.append(self.addHost("h4")) switchs=[] switchs.append(self.addSwitch("s1")) switchs.append(self.addSwitch("s2")) self.addLink(left[0],switchs[0]) self.addLink(left[1],switchs[0]) self.addLink(right[0],switchs[1]) self.addLink(right[1],switchs[1]) self.addLink(switchs[0],switchs[1]) topos={'mytopo':(lambda : MyTopo())}
在 mininet/custom
中有一個示例文件topo-2sw-2host.py
.。可以按照該文件的內容進行相應地修改,定義自己的拓撲結構。
將自定義的網絡拓撲寫好后放到該custom目錄下即可。
啟動RYU
cd RYUPATH/ryu/app/ #首先進入到RYU的安裝目錄的app目錄下,里面有相應的模塊 sudo ryu-manager ofctl_rest.py simple_switch.py # 啟動ofctl_rest.py模塊以及simple_switch.py交換機,這個是openflow1.0的交換機
啟動mininet
sudo mn --controller=remote,ip=127.0.0.1,port=6653 --custom ~/Desktop/mininet/custom/1.py --topo mytopo
在這里ryu和mininet是在一台機器上的,所以ip地址為127.0.0.1,也可以寫成controller=remote預設是在本機的ip 若是controller在其他機器的話則在后面加上ip=xxx.xxx.xx.xx
例如 --controller=remote,ip=192.168.10.11
其中 1.py是剛剛定義的拓撲python文件, mytopo是 最后兩行
topos={'mytopo':(lambda : MyTopo())} 中指定的拓撲名
實驗細節
1. 在mininet 檢查網絡聯通性
mininet> pingall
*** 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)1234567
*** 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)1234567
結論:4台主機 兩兩互通
得到指定交換機的所有flow的狀態信息
{ "1": [ { "actions": [ "OUTPUT:3" ],(動作,轉發到3 號端口) "idle_timeout": 0,(空閑后存活時間) "cookie": 0, "packet_count": 2,(包計數) "hard_timeout": 0,(存活時間) "byte_count": 140,(比特計數) "duration_nsec": 111000000, "priority": 32768,(優先級) "duration_sec": 985,(已經存活時間) "table_id": 0,(在流表1) "match": (匹配字段) { "dl_dst": "02:28:7c:93:27:af",(主機h3的地址)(過濾目的地址為02:28:7c:93:27:af的包,就是去主機3的包) "in_port": 2(從2號口子來的) } (作用:從2號口子來的,要到h3的報文都從3號口子出去哈) }, { "actions": [ "OUTPUT:2" ], "idle_timeout": 0, "cookie": 0, "packet_count": 7, "hard_timeout": 0, "byte_count": 518, "duration_nsec": 113000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "d2:3e:55:89:f3:a1", "in_port": 3 } (作用:從3號口子來的,發往h2的包都從2號口子出去哈) }, { "actions": [ "OUTPUT:3" ], "idle_timeout": 0, "cookie": 0, "packet_count": 2, "hard_timeout": 0, "byte_count": 140, "duration_nsec": 155000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "02:28:7c:93:27:af", "in_port": 1 } (作用:從1號口子來的,發往h3的的包都從3號口子出去哈 }, { "actions": [ "OUTPUT:1" ], "idle_timeout": 0, "cookie": 0, "packet_count": 3, "hard_timeout": 0, "byte_count": 238, "duration_nsec": 171000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "fe:3b:25:cc:04:97", "in_port": 2 } (作用:從2號口子來的,發往h1的包都從1號口子出去哈) }, { "actions": [ "OUTPUT:2" ], "idle_timeout": 0, "cookie": 0, "packet_count": 2, "hard_timeout": 0, "byte_count": 140, "duration_nsec": 169000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "d2:3e:55:89:f3:a1", "in_port": 1 } (從1號口子來的,發給h2的包都從2號口子出去哈 }, { "actions": [ "OUTPUT:3" ], "idle_timeout": 0, "cookie": 0, "packet_count": 2, "hard_timeout": 0, "byte_count": 140, "duration_nsec": 137000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "ba:94:88:a1:55:63", "in_port": 1 } (從1號口子來的,發往h4的,從3號口子出去哈) }, { "actions": [ "OUTPUT:1" ], "idle_timeout": 0, "cookie": 0, "packet_count": 7, "hard_timeout": 0, "byte_count": 518, "duration_nsec": 157000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "fe:3b:25:cc:04:97", "in_port": 3 } (作用:從3號口子來的,發給h1的包都從1號口子出去哈) }, { "actions": [ "OUTPUT:3" ], "idle_timeout": 0, "cookie": 0, "packet_count": 2, "hard_timeout": 0, "byte_count": 140, "duration_nsec": 92000000, "priority": 32768, "duration_sec": 985, "table_id": 0, "match": { "dl_dst": "ba:94:88:a1:55:63", "in_port": 2 } (從2號口子來的,發給h4的都從3號口子出去哈) } ] }
由上面,我們可以分析出:
第一個交換機一個有3個端口
端口1與h1直連
端口2與h2直連
端口3負責與另外一個交換機直連
另一個交換機也是類似的作法