实验1:SDN拓扑实践

实验1:SDN拓扑实践

(一)基本要求

  1. Mininet运行结果截图

  2. 使用Mininet的命令行生成如下拓扑:
    a) 3台交换机,每个交换机连接1台主机,3台交换机连接成一条线。

    b) 3台主机,每个主机都连接到同1台交换机上。

  3. 在2 b)的基础上,在Mininet交互界面上新增1台主机并且连接到交换机上,再测试新拓扑的连通性。

  4. 编辑(一)中第1步保存的Python脚本,添加如下网络性能限制,生成拓扑:
    a) h1的cpu最高不超过50%;
    b) h1和s1之间的链路带宽为10,延迟为5ms,最大队列大小为1000,损耗率50。

(二)进阶要求

  • 代码
#!/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:   
                # 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( L2 ):
        	sw1 = a[i]
        	for j in range(L2):
                    sw2 = e[int(i/2)*L2+j]  
                    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() ) }



  • 截图

(三)个人总结

实验中遇到的问题及解决办法

  1. 一开始打开miniedit的时候报错ImportError: No module named mininet.log,通过搜索报错信息,找到了这篇这篇博文,对照自己的情况,成功解决了问题并打开了miniedit
  2. 修改03200212.py文件时,发现文件read-only。于是我查看了该文件的属性,发现是仅有根用户拥有读写权限,而普通用户只可读文件,便启动根用户模式,编辑py文件,成功解决问题。
  3. fattree在复制实验指导pdf中提供的链接博文并将py代码进行编辑修改后创建py文件并保存后,报错TabError: inconsistent use of tabs and spaces in indentation ,发现是复制博文后缩进出现错误,于是删除报错行前的空格重新键入正确次数的tab后,问题解决。

个人感想

这次实验乍一看很简单,但一开始就遇到了miniedit报错问题,虽然顺利解决了,但也觉得不能掉以轻心了。接下来的实验过程大体上都很顺利,偶尔出现报错也可以通过阅读报错信息很快地理解问题产生原因并解决问题。不过在进阶部分,理解链接博文的代码含义与对应职能并将其改编为题目所要求的拓扑结构比我想象中的困难了一些,但可能也正因如此,做出来的时候才会更有收获

posted @ 2022-09-12 14:29  IEChis  阅读(58)  评论(0编辑  收藏  举报