dayi的大键盘
dayi的大键盘

SDN 作业1

SDN 作业1

任务:要求1、将代码上传作业 2、用python3运行代码,使用cli实现pingall、nodes、net、dump iperf h1 h2等命令

更好阅读:

可能仍然有BUG,请反馈。

打开虚拟机

我这里打开的是Ubuntu_20.04_sdn_ovs-2.17.8-LTS

这个虚拟机。具体的文件在群文件中

https://cmd.dayi.ink/uploads/upload_f2e8270a3e928c3d4a075039bfd203b7.png

打开miniedit.py

sudo python2 /opt/sdn/mininet/examples/miniedit.py

画图

照着图画一个,然后连起来即可。

https://cmd.dayi.ink/uploads/upload_c174a130145c4652677856f16725eeb4.png

设置IP

右键这个主机,然后选properties

https://cmd.dayi.ink/uploads/upload_24d721e3be975d11c0b28d5dfb9daf34.png

分别设置IP地址即可。

https://cmd.dayi.ink/uploads/upload_aeefd965b4533f4fb96d3e9463968c8c.png

设置链路速率

右键这个线,然后选properties

https://cmd.dayi.ink/uploads/upload_1996cb323545c208565a19f62487bb2a.png

然后参数这样设置:

100,5ms

https://cmd.dayi.ink/uploads/upload_4a20710cd4478c9c2f7d81cda0d70ad5.png

设置,进入CLI模式

Edit->Preferences->Start CLI

https://cmd.dayi.ink/uploads/upload_5c59c6483c57652f4e4ace619bb26af7.png

CLI:

https://cmd.dayi.ink/uploads/upload_3b0c720af5870c73c33a31febaf16944.png

保存文件

这里记得存两份,保存出的python文件是不能再变成图片的!

保存mn

File->Save

https://cmd.dayi.ink/uploads/upload_43529826eb674b8b040265904377ae4b.png
https://cmd.dayi.ink/uploads/upload_bb3cd94ac92aedf978a33d5063c15b39.png
https://cmd.dayi.ink/uploads/upload_e6437beb55cee4cd6811508346e65d57.png

导出python文件

导出Level 2 Script

https://cmd.dayi.ink/uploads/upload_3b6febc98a6cffa4fe3cff278868a3ca.png

另外,这里导出到过程不应该出现报错

https://cmd.dayi.ink/uploads/upload_594af51751f090c9e8dacd08b543c76f.png

这里不应该有python报错。

运行测试

进入导出文件的目录,我这里是/home/sdn

https://cmd.dayi.ink/uploads/upload_55bcfadfcdd9d2ed756e10d35d11312a.png

运行:

python3 ovo.py
https://cmd.dayi.ink/uploads/upload_da8ec733e2e6ae92cea2a72eb32007be.png

测试 PING(4,5交换机未连接控制器)

# 在mn的CLI下
net.pingall()

pingall()
https://cmd.dayi.ink/uploads/upload_8406f3665fdab6ebefd07f612b0a2646.png

因为那个没连接控制器,所以会ping不通,只有部分可以通。

https://cmd.dayi.ink/uploads/upload_f04d87a3d0ea4aa3b3740c4184b61a94.png

测试PING(4/5连接控制器)

https://cmd.dayi.ink/uploads/upload_870436623e909fef668eec412b0057e5.png
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
https://cmd.dayi.ink/uploads/upload_31e76bf6d2c4058139592c8a19d23dde.png
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
https://cmd.dayi.ink/uploads/upload_1dcf0a725ede399404a6a44204890cd2.png
mininet> dump














mininet>

iperf测速

iperf h1 h2
https://cmd.dayi.ink/uploads/upload_b2261c1d3b49953de2483eb4f439e958.png
*** 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>
https://cmd.dayi.ink/uploads/upload_66a9a647389e1de10cd23f2df65f14f9.png

调试过程

  • 发现pingall有不通的
https://cmd.dayi.ink/uploads/upload_35dad2ed78bc9f9838bdff18af4260cd.png

做了好久好久,换了内核,重装了好多查了好久,发现必须要连接那个controller才可以。

代码

https://cmd.dayi.ink/uploads/upload_f47eb93466c8fa7fb4edf2d7e14e258c.png
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)

发表回复

textsms
account_circle
email

dayi的大键盘

SDN 作业1
# SDN 作业1 > 任务:要求1、将代码上传作业 2、用python3运行代码,使用cli实现pingall、nodes、net、dump iperf h1 h2等命令 更好阅读: - https://type.dayiyi.top/index…
扫描二维码继续阅读
2023-11-28