1、基础版
a) 第1步Mininet运行结果截图
b) 第2步的执行结果截图
c) 第3步提交修改过的“学号.py”代码、Mininet运行结果
#!/usr/bin/env 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')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None,cpu=0.5)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', 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)
info( '*** Add links\n')
net.addLink(h1, s1, bw=10, delay='5ms',max_queue_size=1000, loss=50, use_htb=True)
net.addLink(h2, s1)
net.addLink(s1, s2)
net.addLink(h3, s2)
net.addLink(h4, s2)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
2、进阶版
#!/usr/bin/python
"""Custom topology example
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
from mininet.node import RemoteController,CPULimitedHost
from mininet.util import dumpNodeConnections
from mininet.link import TCLink
from mininet.net import Mininet
class MyTopo( Topo ):
def __init__( self ):
# Initialize topology
Topo.__init__( self )
L1 = 2
L2 = L1 * 2
L3 = L2 * 2
s1 = []
s2 = []
s3 = []
# add core ovs
for i in range( L1 ):
switch = self.addSwitch( 's{}'.format( i + 1 ) )
s1.append( switch )
# add aggregation ovs
for i in range( L2 ):
switch = self.addSwitch( 's{}'.format( L1 + i + 1 ) )
s2.append( switch )
# add edge ovs
for i in range( L3 ):
switch = self.addSwitch( 's{}'.format( L1 + L2 + i + 1 ) )
s3.append( switch )
# add links core aggregation ovs
for i in range( L1 ):
sw1 = s1[i]
for sw2 in s2[i//2::L1//2]:
self.addLink( sw2, sw1 )
# add links aggregation edge ovs
for i in range( 0, L2, 2 ):
for sw1 in s2[i:i+2]:
for sw2 in s3[i*2:i*2+4]:
self.addLink( sw2, sw1 )
#add hosts edge
count = 1
for sw1 in s3:
for i in range(2):
host = self.addHost( 'h{}'.format( count ) ,ip='10.0.0.{}'.format( count ),defaultRoute=None)
self.addLink( sw1, host )
count += 1
topos = { 'mytopo': ( lambda: MyTopo() ) }
3、感想
本次实验一开启了我对SDN的认识!基本实验呢,还是比较好上手的,做起来还挺有趣的!但是,我一看到进阶版要我用python写脚本,我就比较害怕,毕竟编程真的很差!参考资料里面提供了大部分代码,所以还是比较好处理的,经过分析代码,稍微改动一些参数就可以满足题意。同时经过查阅资料、请教同学等等各种各样的方式,磕磕绊绊勉勉强强做完了,虽然过程曲折,但收获颇多,期间解决了很多细节问题。以下列举几个我期间遇到的问题及解决方法:
1)
问题:打不开图形化界面
解决:用root账户登陆图形化界面
结果依旧出现问题:打不开图形化界面
分析原因:python版本不对
解决:修改python版本为python3
结果:可以打开图形化界面
2)
问题:使用Mininet的命令行生成拓扑时出错
解决:重启虚拟机就解决了哈哈哈
3)
问题:进阶版拓扑ping不通
解决:因拓扑出现环路而产生广播风暴,故开启生成树协议
4)
问题:在Mininet交互界面上新增1台主机并且连接到交换机上,再测试新拓扑的连通性发现出错
解决:
5)修改python代码时,为方便编写以及查看,下载了vscode,并通过该软件修改代码