2019 SDN上机第1次作业
1. 安装轻量级网络仿真工具Mininet
安装步骤
-
sudo git clone http://www.github.com/mininet/mininet
-
sudo ./install.sh -a
2. 用字符命令搭建拓扑
线性拓扑
命令:sudo mn --topo linear,3
树形拓扑
命令:sudo mn --topo tree,fanout=3,depth=2
利用可视化工具搭建拓扑
-
拓扑搭建
-
net命令查看
-
运行
Xterm h1,h2,h3
,分别使用ifconfig
利用Python脚本完成Fat-tree型的拓扑
-
运行结果
-
代码
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
class MyTopo( Topo ):
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
L1 = 2
L2 = 4
c = []
e = []
# add core ovs
for i in range( L1 ):
sw = self.addSwitch( 's{}'.format( i + 1 ) )
c.append( sw )
# add edge ovs
for i in range( L2 ):
sw = self.addSwitch( 's{}'.format( L1 + i + 1 ) )
e.append( sw )
# add links between core and edge ovs
for i in range( L1 ):
sw1 = c[i]
for sw2 in e:
self.addLink( sw2, sw1 )
#add hosts and its links with edge ovs
count = 1
for sw1 in e:
for i in range(2):
host = self.addHost( 'h{}'.format( count ) )
self.addLink( sw1, host )
count += 1
topos = { 'mytopo': ( lambda: MyTopo() ) }