mininet和ryu简单实现自定义topo

mininet和ryu简单实现自定义topo

设备名称 软件
ubuntu16.04 host1 mininet
ubuntu16.04 host1 ryu controller
远成连接xshell 开两个窗口 一个窗口开ryu 一个窗口使用 mininet

步骤1. 窗口1下 在/mininet/custom/ 下编写一个简单的topo python文件example.py

Last login: Thu Jan 28 15:18:39 2021 from 192.168.137.1
tian01@tian01-virtual-machine:~$ su
密码: 
root@tian01-virtual-machine:/home/tian01# 
root@tian01-virtual-machine:/home/tian01# ls
examples.desktop  openvswitch  VMwareTools-10.3.22-15902021.tar.gz  公共的  视频  文档  音乐
mininet           ryu          vmware-tools-distrib                 模板    图片  下载  桌面
root@tian01-virtual-machine:/home/tian01# cd ./mininet/custom/
root@tian01-virtual-machine:/home/tian01/mininet/custom# ls
example.py  README  topo-2sw-2host.py
	example.py 代码
#!/usr/bin/python

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.link import TCLink
from mininet.util import dumpNodeConnections

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize Topology
        Topo.__init__( self )

        # Add hosts and switches
        Host1 = self.addHost( 'h1' )
        Host2 = self.addHost( 'h2' )
        Host3 = self.addHost( 'h3' )
        Switch1 = self.addSwitch( 's1' )
        Switch2 = self.addSwitch( 's2' )

        # Add links
        self.addLink( Host1, Switch1 )
        self.addLink( Host2, Switch1 )
        self.addLink( Host3, Switch2 )
        self.addLink( Switch1, Switch2 )

topos = {
    
     'mytopo': ( lambda: MyTopo() ) }

步骤2. 窗口2下 启动ryu

Last login: Thu Jan 28 11:23:06 2021 from 192.168.137.1
tian01@tian01-virtual-machine:~$ 
tian01@tian01-virtual-machine:~$ su
密码: 
root@tian01-virtual-machine:/home/tian01# ls
examples.desktop  openvswitch  VMwareTools-10.3.22-15902021.tar.gz  公共的  视频  文档  音乐
mininet           ryu          vmware-tools-distrib                 模板    图片  下载  桌面
root@tian01-virtual-machine:/home/tian01# cd ./ryu/ryu/app
root@tian01-virtual-machine:/home/tian01/ryu/ryu/app# ryu-manager simple_switch.py
loading app simple_switch.py
loading app ryu.controller.ofp_handler
instantiating app simple_switch.py of SimpleSwitch
instantiating app ryu.controller.ofp_handler of OFPHandler
port added 2
port added 1

步骤3. 窗口1下 执行你的t自定义的网络topo结构

root@tian01-virtual-machine:/home/tian01/mininet/custom# mn --custom example.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 
*** Adding switches:
s1 s2 
*** Adding links:
(h1, s1) (h2, s1) (h3, s2) (s1, s2) 
*** Configuring hosts
h1 h2 h3 
*** Starting controller
c0 
*** Starting 2 switches
s1 s2 ...
*** Starting CLI:

*********************************
截至这就完成了,后面是我自己的实验命令
*********************************

mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
mininet> sh ovs-vsctl show
74e96470-5f45-49bf-83ea-9bbd36926607
    Bridge "s1"
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        Controller "ptcp:6654"
        fail_mode: secure
        Port "s1"
            Interface "s1"
                type: internal
        Port "s1-eth1"
            Interface "s1-eth1"
        Port "s1-eth2"
            Interface "s1-eth2"
        Port "s1-eth3"
            Interface "s1-eth3"
    Bridge "s2"
        Controller "ptcp:6655"
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        Port "s2-eth1"
            Interface "s2-eth1"
        Port "s2"
            Interface "s2"
                type: internal
        Port "s2-eth2"
            Interface "s2-eth2"
    ovs_version: "2.5.0"
mininet> sh ovs-ofctl dump-flows
ovs-ofctl: 'dump-flows' command requires at least 1 arguments
mininet> sh ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3 
h2 -> h1 h3 
h3 -> h1 h2 
*** Results: 0% dropped (6/6 received)
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=14.909s, table=0, n_packets=3, n_bytes=238, idle_age=9, in_port=2,dl_src=f6:cd:5a:25:6a:22,dl_dst=ce:48:3d:04:3a:e9 actions=output:1
 cookie=0x0, duration=14.906s, table=0, n_packets=2, n_bytes=140, idle_age=9, in_port=1,dl_src=ce:48:3d:04:3a:e9,dl_dst=f6:cd:5a:25:6a:22 actions=output:2
 cookie=0x0, duration=14.894s, table=0, n_packets=3, n_bytes=238, idle_age=9, in_port=3,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=ce:48:3d:04:3a:e9 actions=output:1
 cookie=0x0, duration=14.893s, table=0, n_packets=2, n_bytes=140, idle_age=9, in_port=1,dl_src=ce:48:3d:04:3a:e9,dl_dst=c6:c6:4a:7c:b2:ff actions=output:3
 cookie=0x0, duration=14.877s, table=0, n_packets=3, n_bytes=238, idle_age=9, in_port=3,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=f6:cd:5a:25:6a:22 actions=output:2
 cookie=0x0, duration=14.874s, table=0, n_packets=2, n_bytes=140, idle_age=9, in_port=2,dl_src=f6:cd:5a:25:6a:22,dl_dst=c6:c6:4a:7c:b2:ff actions=output:3
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=14.905s, table=0, n_packets=3, n_bytes=238, idle_age=9, in_port=1,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=ce:48:3d:04:3a:e9 actions=output:2
 cookie=0x0, duration=14.901s, table=0, n_packets=2, n_bytes=140, idle_age=9, in_port=2,dl_src=ce:48:3d:04:3a:e9,dl_dst=c6:c6:4a:7c:b2:ff actions=output:1
 cookie=0x0, duration=14.889s, table=0, n_packets=3, n_bytes=238, idle_age=9, in_port=1,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=f6:cd:5a:25:6a:22 actions=output:2
 cookie=0x0, duration=14.882s, table=0, n_packets=2, n_bytes=140, idle_age=9, in_port=2,dl_src=f6:cd:5a:25:6a:22,dl_dst=c6:c6:4a:7c:b2:ff actions=output:1
mininet> node
*** Unknown command: node
mininet> nodes
available nodes are: 
c0 h1 h2 h3 s1 s2
mininet>   show
*** Unknown command: show
mininet> sh show
/bin/sh: 1: show: not found
mininet> sh s1 show
/bin/sh: 1: s1: not found
mininet> sh ovs-odctl show s1
/bin/sh: 1: ovs-odctl: not found
mininet> sh ovs-ofctl show s1
OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000001
n_tables:254, n_buffers:256
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
 1(s1-eth1): addr:76:f2:98:e3:1d:1b
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(s1-eth2): addr:52:09:30:cb:f5:aa
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 3(s1-eth3): addr:ea:8e:78:7d:4a:3e
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(s1): addr:92:01:80:c7:58:43
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max
OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
mininet> sh ovs-ofctl dump-ports
ovs-ofctl: 'dump-ports' command requires at least 1 arguments
mininet> sh ovs-ofctl dump-ports s1
OFPST_PORT reply (xid=0x2): 4 ports
  port  1: rx pkts=23, bytes=1706, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=107, bytes=10662, drop=0, errs=0, coll=0
  port LOCAL: rx pkts=0, bytes=0, drop=80, errs=0, frame=0, over=0, crc=0
           tx pkts=0, bytes=0, drop=0, errs=0, coll=0
  port  2: rx pkts=23, bytes=1706, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=107, bytes=10662, drop=0, errs=0, coll=0
  port  3: rx pkts=57, bytes=5590, drop=0, errs=0, frame=0, over=0, crc=0
           tx pkts=72, bytes=6688, drop=0, errs=0, coll=0
mininet> sh ovs-ofctl dump-ports-desc s1
OFPST_PORT_DESC reply (xid=0x2):
 1(s1-eth1): addr:76:f2:98:e3:1d:1b
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(s1-eth2): addr:52:09:30:cb:f5:aa
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 3(s1-eth3): addr:ea:8e:78:7d:4a:3e
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(s1): addr:92:01:80:c7:58:43
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=2505.648s, table=0, n_packets=3, n_bytes=238, idle_age=2500, in_port=2,dl_src=f6:cd:5a:25:6a:22,dl_dst=ce:48:3d:04:3a:e9 actions=output:1
 cookie=0x0, duration=2505.645s, table=0, n_packets=2, n_bytes=140, idle_age=2500, in_port=1,dl_src=ce:48:3d:04:3a:e9,dl_dst=f6:cd:5a:25:6a:22 actions=output:2
 cookie=0x0, duration=2505.633s, table=0, n_packets=3, n_bytes=238, idle_age=2500, in_port=3,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=ce:48:3d:04:3a:e9 actions=output:1
 cookie=0x0, duration=2505.632s, table=0, n_packets=2, n_bytes=140, idle_age=2500, in_port=1,dl_src=ce:48:3d:04:3a:e9,dl_dst=c6:c6:4a:7c:b2:ff actions=output:3
 cookie=0x0, duration=2505.616s, table=0, n_packets=3, n_bytes=238, idle_age=2500, in_port=3,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=f6:cd:5a:25:6a:22 actions=output:2
 cookie=0x0, duration=2505.613s, table=0, n_packets=2, n_bytes=140, idle_age=2500, in_port=2,dl_src=f6:cd:5a:25:6a:22,dl_dst=c6:c6:4a:7c:b2:ff actions=output:3
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=2505.642s, table=0, n_packets=3, n_bytes=238, idle_age=2500, in_port=1,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=ce:48:3d:04:3a:e9 actions=output:2
 cookie=0x0, duration=2505.638s, table=0, n_packets=2, n_bytes=140, idle_age=2500, in_port=2,dl_src=ce:48:3d:04:3a:e9,dl_dst=c6:c6:4a:7c:b2:ff actions=output:1
 cookie=0x0, duration=2505.626s, table=0, n_packets=3, n_bytes=238, idle_age=2500, in_port=1,dl_src=c6:c6:4a:7c:b2:ff,dl_dst=f6:cd:5a:25:6a:22 actions=output:2
 cookie=0x0, duration=2505.619s, table=0, n_packets=2, n_bytes=140, idle_age=2500, in_port=2,dl_src=f6:cd:5a:25:6a:22,dl_dst=c6:c6:4a:7c:b2:ff actions=output:1
mininet> dpctl del-flows
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl add-flow in_port=1,actions=output:2
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl del-flows
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl add-flow in_port=1,actions=output:2
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=6.137s, table=0, n_packets=0, n_bytes=0, idle_age=6, in_port=1 actions=output:2
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=6.136s, table=0, n_packets=0, n_bytes=0, idle_age=6, in_port=1 actions=output:2
mininet> dpctl add-flows inport_2,actions=output:1
*** s1 ------------------------------------------------------------------------
ovs-ofctl: inport_2,actions=output:1: open failed (No such file or directory)
*** s2 ------------------------------------------------------------------------
ovs-ofctl: inport_2,actions=output:1: open failed (No such file or directory)
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=49.831s, table=0, n_packets=0, n_bytes=0, idle_age=49, in_port=1 actions=output:2
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=49.829s, table=0, n_packets=0, n_bytes=0, idle_age=49, in_port=1 actions=output:2
mininet> dpctl add-flow inport_2,actions=output:1
*** s1 ------------------------------------------------------------------------
ovs-ofctl: field inport_2 missing value
*** s2 ------------------------------------------------------------------------
ovs-ofctl: field inport_2 missing value
mininet> dpctl add-flow in_port=2,actions=output:1
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=83.174s, table=0, n_packets=0, n_bytes=0, idle_age=83, in_port=1 actions=output:2
 cookie=0x0, duration=4.210s, table=0, n_packets=0, n_bytes=0, idle_age=4, in_port=2 actions=output:1
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=83.174s, table=0, n_packets=0, n_bytes=0, idle_age=83, in_port=1 actions=output:2
 cookie=0x0, duration=4.210s, table=0, n_packets=0, n_bytes=0, idle_age=4, in_port=2 actions=output:1
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=0.523 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.078 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.082 ms
^C
--- 10.0.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2053ms
rtt min/avg/max/mdev = 0.078/0.227/0.523/0.209 ms
mininet> sh ovs-ofctl show s1
OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000001
n_tables:254, n_buffers:256
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
 1(s1-eth1): addr:76:f2:98:e3:1d:1b
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 2(s1-eth2): addr:52:09:30:cb:f5:aa
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 3(s1-eth3): addr:ea:8e:78:7d:4a:3e
     config:     0
     state:      0
     current:    10GB-FD COPPER
     speed: 10000 Mbps now, 0 Mbps max
 LOCAL(s1): addr:92:01:80:c7:58:43
     config:     PORT_DOWN
     state:      LINK_DOWN
     speed: 0 Mbps now, 0 Mbps max
OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
mininet> sh ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=441.431s, table=0, n_packets=4, n_bytes=336, idle_age=301, in_port=1 actions=output:2
 cookie=0x0, duration=362.467s, table=0, n_packets=4, n_bytes=336, idle_age=301, in_port=2 actions=output:1
mininet> sh ovs-ofctl del-flows in_port=1
ovs-ofctl: in_port=1 is not a bridge or a socket
mininet> sh ovs-vsctl del-flows in_port=1
ovs-vsctl: unknown command 'del-flows'; use --help for help
mininet> sh ovs-ofctl del-flows s1 in_port=1
mininet> sh ovs-ofctl dump-flows
ovs-ofctl: 'dump-flows' command requires at least 1 arguments
mininet> sh ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=462.040s, table=0, n_packets=4, n_bytes=336, idle_age=401, in_port=2 actions=output:1
mininet> dpctl del-flows in_port=1
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl del-flows in_port=2
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
mininet> dpctl add-flows in_port=2,actions=drop
*** s1 ------------------------------------------------------------------------
ovs-ofctl: in_port=2,actions=drop: open failed (No such file or directory)
*** s2 ------------------------------------------------------------------------
ovs-ofctl: in_port=2,actions=drop: open failed (No such file or directory)
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
mininet> dpctl add-flow in_port=2,actions=drop
*** s1 ------------------------------------------------------------------------
*** s2 ------------------------------------------------------------------------
mininet> dpctl dump-flows
*** s1 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=2.200s, table=0, n_packets=0, n_bytes=0, idle_age=2, in_port=2 actions=drop
*** s2 ------------------------------------------------------------------------
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=2.203s, table=0, n_packets=0, n_bytes=0, idle_age=2, in_port=2 actions=drop
mininet> h2 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
^C
--- 10.0.0.3 ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 6138ms

mininet> pingall
*** Ping: testing ping reachability
h1 -> X X 
h2 -> X X 
h3 -> X X 
*** Results: 100% dropped (0/6 received)
mininet> 
谢谢观看!有什么问题可以评论区见,欢迎点赞收藏

猜你喜欢

转载自blog.csdn.net/weixin_46239293/article/details/113348599