保留Datapath #port以保持兼容性

时间:2015-07-15 15:46:11

标签: python-2.7 ryu

我想让ryu运行,尤其是拓扑发现。

现在我在ryu/topology/dumper.py下运行演示应用程序,它应该转储所有拓扑事件。我在ryu/topology目录中并使用ryu-manager dumper.py运行它。 ryu-manager的版本是2.23.2。

启动后不久就给了我这个错误:

/usr/local/lib/python2.7/dist-packages/ryu/topology/switches.py:478: UserWarning:
 Datapath#ports is kept for compatibility with the previous openflow versions (< 1.3).
 This not be updated by EventOFPPortStatus message. If you want to be updated,
 you can use 'ryu.controller.dpset' or 'ryu.topology.switches'.
  for port in dp.ports.values():

对我来说真正奇怪的是,它建议使用ryu.topology.switches,但该错误是由该文件的第478行触发的!

有问题的功能是:

class Switches(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION, ofproto_v1_2.OFP_VERSION,
                    ofproto_v1_3.OFP_VERSION, ofproto_v1_4.OFP_VERSION]
    _EVENTS = [event.EventSwitchEnter, event.EventSwitchLeave,
               event.EventPortAdd, event.EventPortDelete,
               event.EventPortModify,
               event.EventLinkAdd, event.EventLinkDelete]

    DEFAULT_TTL = 120  # unused. ignored.
    LLDP_PACKET_LEN = len(LLDPPacket.lldp_packet(0, 0, DONTCARE_STR, 0))

    LLDP_SEND_GUARD = .05
    LLDP_SEND_PERIOD_PER_PORT = .9
    TIMEOUT_CHECK_PERIOD = 5.
    LINK_TIMEOUT = TIMEOUT_CHECK_PERIOD * 2
    LINK_LLDP_DROP = 5
#...
    def _register(self, dp):
        assert dp.id is not None

        self.dps[dp.id] = dp
        if dp.id not in self.port_state:
            self.port_state[dp.id] = PortState()
            for port in dp.ports.values():    # THIS LINE
                self.port_state[dp.id].add(port.port_no, port)

之前是否有其他人遇到此问题?我该如何解决?

2 个答案:

答案 0 :(得分:1)

之前我遇到过这个问题,但我忽略了它,到目前为止,每件事都按预期工作。

如果您正在尝试学习拓扑,我建议您使用ryu.topology.api。即

from ryu.topology.api import get_switch, get_link

tutorial。然而,有一些东西丢失了。

以下是我目前的情况:Controller.py

Controller.py中,两个函数get_switch(self, None)get_link(self, None)会为您提供链接和开关列表。

答案 1 :(得分:1)

我遇到了同样的问题(取决于你的应用程序,也许这不是问题,只是警告,你可以忽略)。这是我在find . -type f | xargs grep "ports is kept"

之后想出来的

ryu.topology.switches通过调用_get_ports()文件class Datapath中的ryu/controller/controller.py来触发此警告。

class Datapath(ofproto_protocol.ProtocolDesc):
    #......
    def _get_ports(self):
        if (self.ofproto_parser is not None and
                self.ofproto_parser.ofproto.OFP_VERSION >= 0x04):
            message = (
                'Datapath#ports is kept for compatibility with the previous '
                'openflow versions (< 1.3). '
                'This not be updated by EventOFPPortStatus message. '
                'If you want to be updated, you can use '
                '\'ryu.controller.dpset\' or \'ryu.topology.switches\'.'
            )
            warnings.warn(message, stacklevel=2)
        return self._ports

    def _set_ports(self, ports):
        self._ports = ports

    # To show warning when Datapath#ports is read
    ports = property(_get_ports, _set_ports)

我的理解是,如果警告来自ryu.topology.switchesryu.controller.dpset,您可以忽略它;因为这两个类为你处理事件。但是,如果直接使用Datapath,则端口状态不会自动更新。如果我错了,任何人都会纠正我。

class Switches(app_manager.RyuApp):
    #......
    @set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
    def port_status_handler(self, ev):
相关问题