针对特定拓扑的命令行快速创建
- 最小拓扑,1 台交换机下挂 2 台主机
$ sudo mn --topo minimal
- 简单拓扑,1 台交换机下挂 n 台主机,此处 n=3,n=2 即为最小拓扑
$ sudo mn --topo single,3
- 线性拓扑,交换机连成一线,每台交换机下挂 1 台主机,此处有 3 台交换机 3 台主机
$ sudo mn --topo linear,3
- 树形拓扑,基于深度 depth 和扇出 fanout,此处均为 2
$ sudo mn --topo tree, fanout=2,depth=2
通用情形的 Python 脚本自定义创建
mytopo.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')
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()
IperfTest.py
# coding=UTF-8
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')
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((h1, h3))
net.iperf((h2, h3))
net.stop()
if __name__=='__main__':
setLogLevel('info')
#print the log when Configuring hosts, starting switches and controller
IperfTest()
另:主机和虚拟机共享文件夹设置
- 虚拟机->设置目录下
这个作业属于哪个课程 | https://edu.cnblogs.com/campus/fzu/FZUSDN2020/ |
---|---|
这个作业目录在哪里 | https://edu.cnblogs.com/campus/fzu/FZUSDN2020/homework/11179 |
这个作业的目标 | 掌握用命令行或python脚本方法构建拓扑网络 |
学号 | 031802244 |