实验 2:Mininet 实验——拓扑的命令脚本生成

一、实验目的

掌握 Mininet 的自定义拓扑生成方法:命令行创建、Python 脚本编写。

二、实验任务

通过使用命令行创建、Python 脚本编写生成拓扑,熟悉 Mininet 的基本功能。

三 、实验要求
1. 在创建的个人目录下, 修改上述 Mininet , 脚本, 使之变成一个 线性拓扑(交换
为 机和主机数均为 3) )。
2. 各类性能限制保持不变。
3. 使用 iperf 完成拓扑内 3 台主机相互之间的简单性能测试。
4. 在博客园发表一篇博客,记录代码和主要步骤。

四、实验步骤

1. 实验环境

安装了 Ubuntu 18.04.5 Desktop amd64 的虚拟机

2. 实验过程

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

// 线性拓扑,交换机连成一线,每台交换机下挂 1 台主机,此处有 3 台交换机 3 台主机

$ sudo mn --topo linear,3 

 

(2)通用情形的 n Python 脚本 自定义创建

此种方法需要具备 Python 的编程能力。

 

执行命令:

 

$ nano mytopo.py // 复制 Python 代码到 py 文件中

#coding=UTF-8
from mininet.net import Mininet
from mininet.node import CPULimitedHost
from mininet.link import TCLink
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',cpu=0.5)
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=10, use_htb=True)
net.addLink(h2, s2, bw=10, delay='5ms',max_queue_size=1000, loss=10, use_htb=True)
net.addLink(h3, s3,bw=10, delay='5ms',max_queue_size=1000, loss=10, use_htb=True)
net.addLink(s1, s2)
net.addLink(s2, s3)
# 配置主机ip
h1.setIP('10.0.0.1', 24)
h2.setIP('10.0.0.2', 24)
h3.setIP('10.0.0.3', 24)

net.start()
net.pingAll()
net.stop()

 

 

$ sudo python mytopo.py // 执行 py 文件

 

修改之前的 Python 程序,使之可用 iPerf 测试网络拓扑中的指定主机之间的带宽。

执行命令:
$ nano IperfTest.py
 
#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',cpu=0.5)
    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=10, use_htb=True)
    net.addLink(h2, s2, bw=10, delay='5ms',max_queue_size=1000, loss=10, use_htb=True)
    net.addLink(h3, s3, bw=10, delay='5ms',max_queue_size=1000, loss=10, use_htb=True)
    net.addLink(s1, s2)
    net.addLink(s2, s3)
    # 配置主机ip
    h1.setIP('10.0.0.1', 24)
    h2.setIP('10.0.0.2', 24)
    h3.setIP('10.0.0.3', 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((h1,h2))
    net.iperf((h2,h3))
    net.iperf((h1,h3))
    net.pingAll()
    net.stop()
if __name__=='__main__':
    setLogLevel('info') #print the log when Configuring hosts, starting switches and cont$
    IperfTest()

  

 
 
$ sudo python IperfTest.py
 
 
 
 
五、实验小结
1.oracle上虚拟机剪贴板无法共享,索性换用VMware之后解决了这个问题
2.按步骤正常操作,实验总体顺利

 

posted @ 2020-09-16 13:46  难得随遇而安  阅读(370)  评论(0)    收藏  举报