zoukankan      html  css  js  c++  java
  • 2020 SDN实验 2:Mininet 实验——拓扑的命令脚本生成

    1.针对特定拓扑的命令行快速创建

    $ sudo mn --topo tree, fanout=2,depth=2
    

    2.使用Python 脚本自定义创建线性拓扑

    使用python代码搭建一个交换机和主机数均为3的线性拓扑结构,该线性拓扑结构如下图:

    检测代码如下:

    # coding=UTF-8
    #!/usr/bin/python
    from mininet.net import Mininet
    from mininet.node import CPULimitedHost
    from mininet.link import TCLink
    from mininet.util import dumpNodeConnections
    from mininet.log import setLogLevel
    def IperfTest():
    	net = Mininet(host=CPULimitedHost, link=TCLink) 
    	c0 = net.addController()
    	h1 = net.addHost('h1' , cpu=0.5)
    	h2 = net.addHost('h2', cpu=0.5)
    	h3 = net.addHost('h3')
    	#h4 = net.addHost('h4')
    	s1 = net.addSwitch('s1')
    	s2 = net.addSwitch('s2')
    	s3 = net.addSwitch('s3')
    	net.addLink(h1, s1, bw=10, delay='5ms',max_queue_size=1000, loss=0, use_htb=True)
    	net.addLink(h2, s2, bw=10, delay='5ms',max_queue_size=1000, loss=0, use_htb=True)
    	net.addLink(h3, s3, bw=10, delay='5ms',max_queue_size=1000, loss=0, 	use_htb=True)
    	net.addLink(s1, s2, bw=10, delay='5ms',max_queue_size=1000, loss=0, use_htb=True)
    	net.addLink(s2, s3, bw=10, delay='5ms',max_queue_size=1000, loss=0, use_htb=True)
    	#net.addLink(h4, s2, bw=10, delay='5ms',max_queue_size=1000, loss=0, use_htb=True)
    	h1.setIP('10.0.0.1', 24)
    	h2.setIP('10.0.0.2', 24)
    	h3.setIP('10.0.0.3', 24)
    	#h4.setIP('10.0.0.4', 24)
    	net.start()
    	print "Dumping host connections"
    	dumpNodeConnections(net.hosts)
    	print "Testing network connectivity"
    	net.pingAll()
    	print "Testing bandwidth"
    	h1, h2, h3 = net.get('h1', 'h2', 'h3')
    	#net.iperf((s1, s3))
    	net.iperf((h2, h1))
    	net.iperf((h3, h1))
    	net.iperf((h3, h1))
    	net.stop()
    if __name__=='__main__':
     setLogLevel('info') #print the log when Configuring hosts, starting switches and controller
     IperfTest()
    

    3. 实验中遇到的坑

    (1)PDF中代码存在着空格,将空格去除,运行指令则可以正常建立拓扑。

    $ sudo mn --topo tree, fanout=2,depth=2
    

    (2)出现如下图报错

    Caught exception. Cleaning up...
    
    Exception: Please shut down the controller which is running on port 6653:
    激活Internet连接 (服务器和已建立连接的)
    tcp        0      0 0.0.0.0:6653            0.0.0.0:*               LISTEN      4519/controller 
    tcp        0      0 127.0.0.1:43514         127.0.0.1:6653          ESTABLISHED 1112/ovs-vswitchd
    tcp        0      0 127.0.0.1:6653          127.0.0.1:43514         ESTABLISHED 4519/controller 
    tcp        0      0 127.0.0.1:43512         127.0.0.1:6653          ESTABLISHED 1112/ovs-vswitchd
    tcp        0      0 127.0.0.1:6653          127.0.0.1:43516         ESTABLISHED 4519/controller 
    tcp        0      0 127.0.0.1:43516         127.0.0.1:6653          ESTABLISHED 1112/ovs-vswitchd
    tcp        0      0 127.0.0.1:43518         127.0.0.1:6653          TIME_WAIT   -               
    tcp        0      0 127.0.0.1:6653          127.0.0.1:43512         ESTABLISHED 4519/controller 
    
    

    原因是构建了拓扑之后,没有清除,直接建立拓扑会出现错误,所以若在.py文件中构建拓扑图时需要运行以下指令先清除掉先前的拓扑结构避免出现意外情况。

    $ sudo mn -c
    

    (3) 建立拓扑结构需要在python文件中建立交换机与交换机之间的链路,交换机与主机之间的链路,才能正确得出结果。

  • 相关阅读:
    Lock接口、AbstractQueuedSynchronizer队列同步器、重入锁、读写锁
    SpringMVC一点简单地源码解析
    MyBatis源码部分简单地解析
    笔记本外接显示器不显示
    WPF查找指定类型的父/子控件
    java.io.EOFException: HttpConnectionOverHTTP
    Spark读取HDFS某个路径下的子文件夹中的所有文件
    utf-8 BOM前导3个字节头
    org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService:spark_shuffle does not exist
    org.apache.spark.sql.AnalysisException: Table or view not found解决办法
  • 原文地址:https://www.cnblogs.com/031802220lkq/p/13641433.html
Copyright © 2011-2022 走看看