python-2.7 - 保留 Datapath#ports 以保持兼容性

标签 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)

有没有人遇到过这个问题?我该如何解决?

最佳答案

我遇到了同样的问题(取决于你的应用程序,也许这不是问题,只是一个你可以忽略的警告)。这是我在 find 之后发现的。 -类型f | xargs grep “保留端口”

此警告在 ryu.topology.switches 中触发,通过调用文件 class Datapath 中的 _get_ports() 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.switches或者ryu.controller.dpset,可以忽略;因为这两个类会为您处理事件。但是如果你直接使用Datapath,端口状态不会自动更新。如果我错了,有人会纠正我。

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

关于python-2.7 - 保留 Datapath#ports 以保持兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31435099/

相关文章:

python - CeleryBeat 进程消耗所有操作系统内存

python - 如何识别字符串中的单个数字以插入前导零?

python - 如何识别从 Ryu Controller 到 OF 交换机的数据包?

python - 如何获取TCP数据包的数据包数量?

python-2.7 - 在 Windows 中更新/安装 Python scikit 学习最新的开发版本

python - 使用 SymPy codegen 为方程组生成 Fortran 子程序

python - 在 python 中使用正则表达式解析 IP