上一篇將Mininet基礎環境的安裝好了,
先說說上次的mn --test pingall 為甚麼會有那些回應,初始mininet啟用的拓樸圖如下,所以pingall有那些資訊。
有關mininet的參數先不說,我們直接建構一個屬於我們的拓樸圖。
touch mytopo.py
from mininet.topo import Topo
2
3 class MyTopo( Topo ):
4 "Simple topology example."
5
6 def __init__( self,enable_all=True):
7 "Create custom topo."
8 # Initialize topology
9 super(MyTopo,self).__init__()
10
11 leftHost1=1
12 leftHost2=2
13 leftSwitch=3
14 rightSwitc=4
15 rightHost1=5
16 rightHost2=6
17 # Add hosts and switches
18 leftHost1 = self.addHost( 'h1' )
19 leftHost2 = self.addHost( 'h2' )
20 rightHost1 = self.addHost( 'h5' )
21 rightHost2 = self.addHost( 'h6' )
22 leftSwitch = self.addSwitch( 's3' )
23 rightSwitch = self.addSwitch( 's4' )
24
25 # Add links
26 self.addLink( leftHost1, leftSwitch )
27 self.addLink( leftHost2, leftSwitch )
28 self.addLink( leftSwitch, rightSwitch )
29 self.addLink( rightSwitch, rightHost1 )
30 self.addLink( rightSwitch, rightHost2 )
31
32 topos = { 'mytopo': ( lambda: MyTopo() ) }
mn --custom ~/mininet/custom/mytopo.py --topo mytopo
如果成功會直接進入mininet 可以用nodes、net等指令看節點和連接方式。
我將會用這個拓樸來完成之後的SDN學習。