SDN 作业1
任务:要求1、将代码上传作业 2、用python3运行代码,使用cli实现pingall、nodes、net、dump iperf h1 h2等命令
更好阅读:
可能仍然有BUG,请反馈。
打开虚拟机
我这里打开的是Ubuntu_20.04_sdn_ovs-2.17.8-LTS
这个虚拟机。具体的文件在群文件中
打开miniedit.py
sudo python2 /opt/sdn/mininet/examples/miniedit.py
画图
照着图画一个,然后连起来即可。
设置IP
右键这个主机,然后选properties
分别设置IP地址即可。
设置链路速率
右键这个线,然后选properties
然后参数这样设置:
100
,5ms
设置,进入CLI模式
Edit
->Preferences
->Start CLI
CLI:
保存文件
这里记得存两份,保存出的python文件是不能再变成图片的!
保存mn
File
->Save
导出python文件
导出Level 2 Script
另外,这里导出到过程不应该出现报错
这里不应该有python报错。
运行测试
进入导出文件的目录,我这里是/home/sdn
运行:
python3 ovo.py
测试 PING(4,5交换机未连接控制器)
# 在mn的CLI下
net.pingall()
pingall()
因为那个没连接控制器,所以会ping不通,只有部分可以通。
测试PING(4/5连接控制器)
mininet> pingall
*** Ping: testing ping reachability
h6 -> h8 h1 h5 h4 h2 h3 h7
h8 -> h6 h1 h5 h4 h2 h3 h7
h1 -> h6 h8 h5 h4 h2 h3 h7
h5 -> h6 h8 h1 h4 h2 h3 h7
h4 -> h6 h8 h1 h5 h2 h3 h7
h2 -> h6 h8 h1 h5 h4 h3 h7
h3 -> h6 h8 h1 h5 h4 h2 h7
h7 -> h6 h8 h1 h5 h4 h2 h3
*** Results: 0% dropped (56/56 received)
mininet>
测试延迟:
20ms(去5ms,回来5ms)
mininet> h1 ping h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=46.7 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=23.4 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=21.9 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=22.5 ms
64 bytes from 10.0.0.2: icmp_seq=5 ttl=64 time=23.1 ms
64 bytes from 10.0.0.2: icmp_seq=6 ttl=64 time=22.9 ms
64 bytes from 10.0.0.2: icmp_seq=7 ttl=64 time=23.8 ms
^C
--- 10.0.0.2 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6007ms
rtt min/avg/max/mdev = 21.987/26.393/46.792/8.345 ms
mininet>
nodes
nodes
结果:
mininet> nodes
available nodes are:
c0 h1 h2 h3 h4 h5 h6 h7 h8 s1 s2 s3 s4 s5
mininet>
net
net
mininet> net
h7 h7-eth0:s3-eth2
h3 h3-eth0:s4-eth2
h4 h4-eth0:s4-eth3
h5 h5-eth0:s5-eth2
h1 h1-eth0:s1-eth1
h8 h8-eth0:s3-eth3
h6 h6-eth0:s5-eth3
h2 h2-eth0:s1-eth2
s2 lo: s2-eth1:s1-eth3 s2-eth2:s3-eth1 s2-eth3:s4-eth1 s2-eth4:s5-eth1
s4 lo: s4-eth1:s2-eth3 s4-eth2:h3-eth0 s4-eth3:h4-eth0
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:s2-eth1
s3 lo: s3-eth1:s2-eth2 s3-eth2:h7-eth0 s3-eth3:h8-eth0
s5 lo: s5-eth1:s2-eth4 s5-eth2:h5-eth0 s5-eth3:h6-eth0
c0
mininet>
dump
dump
mininet> dump
mininet>
iperf测速
iperf h1 h2
*** Starting CLI:
mininet> iperf h1 h2
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['78.1 Mbits/sec', '79.7 Mbits/sec']
mininet> iperf h1 h2
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['81.0 Mbits/sec', '96.0 Mbits/sec']
mininet>
mininet> iperf h1 h2
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['74.6 Mbits/sec', '87.2 Mbits/sec']
mininet>
mininet> iperf h1 h2
*** Iperf: testing TCP bandwidth between h1 and h2
*** Results: ['78.1 Mbits/sec', '94.0 Mbits/sec']
mininet> iperfudp h1 h2
invalid number of args: iperfudp bw src dst
bw examples: 10M
mininet> iperfudp 100M h1 h2
*** Iperf: testing UDP bandwidth between h1 and h2
*** Results: ['100M', '23.7 Mbits/sec', '23.7 Mbits/sec']
mininet>
调试过程
- 发现pingall有不通的
做了好久好久,换了内核,重装了好多查了好久,发现必须要连接那个controller才可以。
代码
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')
s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3/24', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2/24', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='10.0.0.4/24', defaultRoute=None)
h5 = net.addHost('h5', cls=Host, ip='10.0.0.5/24', defaultRoute=None)
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1/24', defaultRoute=None)
h7 = net.addHost('h7', cls=Host, ip='10.0.0.7/24', defaultRoute=None)
h8 = net.addHost('h8', cls=Host, ip='10.0.0.8/24', defaultRoute=None)
h6 = net.addHost('h6', cls=Host, ip='10.0.0.6/24', defaultRoute=None)
info( '*** Add links\n')
s1h1 = {'bw':100,'delay':'5ms'}
net.addLink(s1, h1, cls=TCLink , **s1h1)
s1h2 = {'bw':100,'delay':'5ms'}
net.addLink(s1, h2, cls=TCLink , **s1h2)
s1s2 = {'bw':100,'delay':'5ms'}
net.addLink(s1, s2, cls=TCLink , **s1s2)
s2s3 = {'bw':100,'delay':'5ms'}
net.addLink(s2, s3, cls=TCLink , **s2s3)
s2s4 = {'bw':100,'delay':'5ms'}
net.addLink(s2, s4, cls=TCLink , **s2s4)
s2s5 = {'bw':100,'delay':'5ms'}
net.addLink(s2, s5, cls=TCLink , **s2s5)
s3h7 = {'bw':100,'delay':'5ms'}
net.addLink(s3, h7, cls=TCLink , **s3h7)
s3h8 = {'bw':100,'delay':'5ms'}
net.addLink(s3, h8, cls=TCLink , **s3h8)
s4h3 = {'bw':100,'delay':'5ms'}
net.addLink(s4, h3, cls=TCLink , **s4h3)
s4h4 = {'bw':100,'delay':'5ms'}
net.addLink(s4, h4, cls=TCLink , **s4h4)
s5h5 = {'bw':100,'delay':'5ms'}
net.addLink(s5, h5, cls=TCLink , **s5h5)
s5h6 = {'bw':100,'delay':'5ms'}
net.addLink(s5, h6, cls=TCLink , **s5h6)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s4').start([c0])
net.get('s3').start([c0])
net.get('s1').start([c0])
net.get('s2').start([c0])
net.get('s5').start([c0])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
root@ubuntu:/home/sdn# python3 wk3.py
*** Adding controller
*** Add switches
*** Add hosts
*** Add links
(100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) *** Starting network
*** Configuring hosts
h3 h2 h4 h5 h1 h7 h8 h6
*** Starting controllers
*** Starting switches
(100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) (100.00Mbit 5ms delay) *** Post configure switches and hosts
*** Starting CLI:
mininet> pingall
*** Ping: testing ping reachability
h3 -> h2 h4 h5 h1 h7 h8 h6
h2 -> h3 h4 h5 h1 h7 h8 h6
h4 -> h3 h2 h5 h1 h7 h8 h6
h5 -> h3 h2 h4 h1 h7 h8 h6
h1 -> h3 h2 h4 h5 h7 h8 h6
h7 -> h3 h2 h4 h5 h1 h8 h6
h8 -> h3 h2 h4 h5 h1 h7 h6
h6 -> h3 h2 h4 h5 h1 h7 h8
*** Results: 0% dropped (56/56 received)
发表回复