简体   繁体   中英

Can't establish a conection between two hosts in mininet using a Ryu REST controller

I create a custom topology in Mininet with the help of Mininets Python-API. The code to create the custom topology is:

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import setLogLevel, info

def myNet():


    #OpenDayLight controller
    #    ODL_CONTROLLER_IP='10.0.0.4'

    #Floodlight controller
    #    FL_CONTROLLER_IP='10.0.0.5'

    net = Mininet( topo=None, build=False, link=TCLink)

    # Create nodes
    h1 = net.addHost( 'h1' )
    h2 = net.addHost( 'h2' )

    # Create switches
    s1 = net.addSwitch( 's1' )

    print "*** Creating links"
    net.addLink(h1, s1, port1=1, port2=1, bw=100 )
    net.addLink(s1, h2, port1=2, port2=1, bw=100 )


    # Add Controllers
    ryu_ctrl_rest = net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6633)

    #    fl_ctrl = net.addController( 'c1', controller=RemoteController, ip=FL_CONTROLLER_IP, port=6633)


    net.build()

    # Connect each switch to the controller
    s1.start( [ryu_ctrl_rest] )

    s1.cmdPrint('ovs-vsctl show')

    CLI( net )
    #    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    myNet()

I start the topology with the following comand:

sudo python topo_small.py

I use the Ryu controller "ofctl_rest.py", which processes REST requests. The REST requests send to the controller contain information which the controller use to install flow entries in the switches. I start the controller with the following command:

cd /usr/local/lib/python2.7/dist-packages/ryu/app
PYTHONPATH=. ryu-manager --verbose ofctl_rest.py

I use the following commands to install flowentries in the switches:

curl -X POST -d '{
    "dpid": 1,
    "cookie": 1,
    "cookie_mask": 1,
    "table_id": 0,
    "idle_timeout": 300,
    "hard_timeout": 300,
    "priority": 11111,
    "flags": 1,
    "match":{
        "nw_dst": "10.0.0.2",
        "dl_type": "2048"
    },
    "actions":[
        {
            "type":"OUTPUT",
            "port": 2
        }
    ]
}' http://localhost:8080/stats/flowentry/add

curl -X POST -d '{
    "dpid": 1,
    "cookie": 1,
    "cookie_mask": 1,
    "table_id": 0,
    "idle_timeout": 300,
    "hard_timeout": 300,
    "priority": 11111,
    "flags": 1,
    "match":{
        "nw_dst": "10.0.0.1",
        "dl_type": "2048"
    },
    "actions":[
        {
            "type":"OUTPUT",
            "port": 1
        }
    ]
}' http://localhost:8080/stats/flowentry/add

The rules are installed in the switch:

mininet@mininet-vm:~$ sudo ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
cookie=0x1, duration=16.327s, table=0, n_packets=0, n_bytes=0, idle_timeout=300, hard_timeout=300, idle_age=16, priority=11111,ip,nw_dst=10.0.0.2 actions=output:2
cookie=0x1, duration=16.317s, table=0, n_packets=0, n_bytes=0, idle_timeout=300, hard_timeout=300, idle_age=16, priority=11111,ip,nw_dst=10.0.0.1 actions=output:1

But I can't establish a connection. If I issue the following comand in the mininet-CLI:

mininet> h1 ping h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
From 10.0.0.1 icmp_seq=2 Destination Host Unreachable
From 10.0.0.1 icmp_seq=3 Destination Host Unreachable
^C
--- 10.0.0.2 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3015ms
pipe 3

If I use switch-ports in the matching part of the REST-requests I can establish a connection. What do I wrong? Please help me.

You are missing what happens before hosts of a local network (I am assuming it us local because of the IP address you are showing on the flow match fields) are able to exchange IP packets. The fact that there is an OpenFlow switch connected to the hosts does not change the hosts network stack and the way address resolution is performed.

When you try to make h1 ping the IP address of h2, h1 needs to know the Ethernet address (ie: MAC) of h2. It will then broadcast in the network ARP requests frames with the following question: "Who has the hardware address of h2?".

The ARP frame , as seen in the TCP/IP guide , does not include the IP header. It means the match you specified will never match an ARP packet, since it only looks for the packet's destination IP. For this reason you cannot ping between the hosts, once the ARP request will be dropped or sent to the controller (I do not know what is the default action of your switch) which means it h1 will never get an ARP reply from h2.

Here is a good resource to understand how ARP works. Also, i would recommend this good OpenFlow Tutorial . Going through this tutorial is important to understand SDN and OpenFlow. Moreover, it is likely that you will understand in practice why your were not able to ping between the hosts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM