实验1:SDN拓扑实践
作者:互联网
一、基本要求
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')
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None, cpu=0.5)
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, bw=10, delay='5ms', max_queue_size=1000, loss=50)
net.addLink(h2, s1)
net.addLink(s1, s2)
net.addLink(s2, h3)
net.addLink(s2, h4)
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()
二、进阶要求
#!/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.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
L1 = 2
L2 = L1 * 2
L3 = L2 * 2
s = []
# add core ovs
for i in range( L1 ):
sw = self.addSwitch( 's{}'.format( i + 1 ) )
s.append( sw )
# add aggregation ovs
for i in range( L2 ):
sw = self.addSwitch( 's{}'.format( L1 + i + 1 ) )
s.append( sw )
# add edge ovs
for i in range( L3 ):
sw = self.addSwitch( 's{}'.format( L1 + L2 + i + 1 ) )
s.append( sw )
# add links between core and aggregation ovs
for i in range( L1 ):
sw1 = s[i]
for sw2 in s[L1:L1+L2]:
# self.addLink(sw2, sw1, bw=10, delay='5ms', loss=10, max_queue_size=1000, use_htb=True)
self.addLink( sw1, sw2 )
# add links between aggregation and edge ovs
for i in range( L2 ):
sw1=s[L1+i]
j=i/2
for sw2 in s[L1+L2+4*j:L1+L2+(j+1)*4]:
self.addLink( sw1, sw2 )
#add hosts and its links with edge ovs
count = 1
for sw1 in s[L1+L2:L1+L2+L3]:
for i in range(2):
host = self.addHost( 'h{}'.format( count ) )
self.addLink( sw1, host )
count += 1
三、个人总结
此次实验按照要求一步一步可以顺利完成,难度不是很大。我对于计算机几乎可以算是零基础,但是通过文档中较为全面的内容以及相关链接,还是可以较为顺利的完成这次实践。不过对于一些不大明白的地方还需要自己消化理解才行。在基础要求部分,出现的一些包括python版本的一些问题,基本可以通过百度找到答案并解决。进阶部分因为我并没有什么基础,只能去模仿链接中的案例,并且通过请教同学来完成。此次实践让我明白作为二学位的学生要更努力地去补一些基础,才能更快跟上身边同学的脚步。
标签:mininet,拓扑,实践,self,L2,L1,import,SDN,net 来源: https://www.cnblogs.com/hjc13112580/p/16694255.html