简体   繁体   English

无法使用 Ryu REST 控制器在 mininet 中的两台主机之间建立连接

[英]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.我在 Mininets Python-API 的帮助下在 Mininet 中创建了一个自定义拓扑。 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.我使用 Ryu 控制器“ofctl_rest.py”,它处理 REST 请求。 The REST requests send to the controller contain information which the controller use to install flow entries in the switches.发送到控制器的 REST 请求包含控制器用于在交换机中安装流条目的信息。 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:我使用以下命令在交换机中安装 flowentries:

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-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.如果我在 REST 请求的匹配部分使用交换机端口,我可以建立连接。 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.您错过了在本地网络的主机(我假设它是本地网络,因为您在流匹配字段中显示的 IP 地址)能够交换 IP 数据包之前发生的事情。 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.存在连接到主机的 OpenFlow 交换机这一事实不会改变主机网络堆栈和地址解析的执行方式。

When you try to make h1 ping the IP address of h2, h1 needs to know the Ethernet address (ie: MAC) of h2.当你试图让 h1 ping h2 的 IP 地址时,h1 需要知道 h2 的以太网地址(即:MAC)。 It will then broadcast in the network ARP requests frames with the following question: "Who has the hardware address of h2?".然后它将在网络中广播 ARP 请求帧,其中包含以下问题:“谁拥有 h2 的硬件地址?”。

The ARP frame , as seen in the TCP/IP guide , does not include the IP header. ARP 帧,如TCP/IP 指南中所见,不包括 IP 标头。 It means the match you specified will never match an ARP packet, since it only looks for the packet's destination IP.这意味着您指定的匹配项永远不会匹配 ARP 数据包,因为它只查找数据包的目标 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.出于这个原因,您无法在主机之间 ping,一旦 ARP 请求将被丢弃或发送到控制器(我不知道您的交换机的默认操作是什么),这意味着 h1 将永远不会从 h2 获得 ARP 回复。

Here is a good resource to understand how ARP works. 是了解 ARP 工作原理的好资源。 Also, i would recommend this good OpenFlow Tutorial .另外,我会推荐这个好的OpenFlow 教程 Going through this tutorial is important to understand SDN and OpenFlow.阅读本教程对于理解 SDN 和 OpenFlow 很重要。 Moreover, it is likely that you will understand in practice why your were not able to ping between the hosts.此外,您可能会在实践中理解为什么无法在主机之间进行 ping 操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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