其他分享
首页 > 其他分享> > 实验1:SDN拓扑实践

实验1:SDN拓扑实践

作者:互联网

实验1:SDN拓扑实践

一、实验目的

1.能够使用源码安装Mininet;
2.能够使用Mininet的可视化工具生成拓扑;
3.能够使用Mininet的命令行生成特定拓扑;
4.能够使用Mininet交互界面管理SDN拓扑;
5.能够使用Python脚本构建SDN拓扑。

二、实验环境

Ubuntu 20.04 Desktop amd64

三、实验要求

(一)基本要求

使用Mininet可视化工具,生成下图所示的拓扑,并保存拓扑文件名为学号.py

使用Mininet的命令行生成如下拓扑:

编辑(一)中第1步保存的Python脚本,添加如下网络性能限制,生成拓扑:

032002401.py(修改版)

#!/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, dpid='0000000000000001')
    s2 = net.addSwitch('s2', cls=OVSKernelSwitch, dpid='0000000000000002')

    info( '*** Add hosts\n')
    h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None,cpu=0.5)  #h1的cpu最高不超过50%
    h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
    h3 = net.addHost('h3', cls=Host, ip='10.0.1.1', defaultRoute=None)
    h4 = net.addHost('h4', cls=Host, ip='10.0.1.2', defaultRoute=None)

    info( '*** Add links\n')
    net.addLink(h1, s1,bw=10,delay='5ms',max_queue_size=1000,loss=50,use_htb=True)  #h1和s1之间的链路带宽为10,延迟为5ms,最大队列大小为1000,损耗率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('s1').start([c0])
    net.get('s2').start([c0])

    info( '*** Post configure switches and hosts\n')
    s1.cmd('ifconfig s1 10.0.0.56')
    s2.cmd('ifconfig s2 10.0.1.56')

    CLI(net)
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    myNetwork()

运行结果

(二)进阶要求

032002401_fattree.py

#!/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
        c = []
        a = []
        e = []
          
        # add core ovs  
        for i in range( L1 ):
                sw = self.addSwitch( 's{}'.format( i + 1 ) )
                c.append( sw )
    
        # add aggregation ovs
        for i in range( L2 ):
                sw = self.addSwitch( 's{}'.format( L1 + i + 1 ) )
                a.append( sw )
    
        # add edge ovs
        for i in range( L3 ):
                sw = self.addSwitch( 's{}'.format( L1 + L2 + i + 1 ) )
                e.append( sw )
 
        # add links between core and aggregation ovs
        for i in range( L1 ):
                sw1 = c[i]
                for sw2 in a[i//2::L1//2]:
        # self.addLink(sw2, sw1, bw=10, delay='5ms', loss=10, max_queue_size=1000, use_htb=True)
			                self.addLink( sw2, sw1 )
 
        # add links between aggregation and edge ovs
        for i in range( 0, L2, 2 ):
                for sw1 in c[i:i+2]:
	                for sw2 in e[i:i+2]:
			                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() ) }

运行结果

四、实验报告

本次实验对我来说还是比较有难度,主要是初次接触SDN和mininet的使用,有很多错误都需要一一百度尝试解决,耗费了比较多的时间。还有一些比较偏门的问题,百度也难以找到,好在同组的同学们有成功解决这些问题的,他们的经验在实验过程中给予了我很大的帮助,也说明我解决问题的能力还有待加强。
在实验过程中,我熟悉巩固了linux系统下的各种命令操作,也学习了mininet构建网络拓扑的相关基础知识,同时意识到自己的不足,这些对我来说都是学习和进步。在实验中有使用到python脚本,也涉及到一部分python编程的内容,我对这一块还不是很熟悉,希望在接下来能够不断充实加强自己,在之后的实验中赶上大家的步伐。继续加油!

标签:info,mininet,Mininet,拓扑,实践,self,import,SDN,net
来源: https://www.cnblogs.com/jjc-daydayup/p/16686033.html