最好的方法是在Controller类中定义一个集合,并在那里添加所有交换机的DPID。因此,每次在_handle_ConnectionUp中有事件时,您都可以获得交换机的DPID并相应地添加它。
在你的主控制器类init函数中
self.switches = set()
和_handle_ConnectionUp函数
def _handle_ConnectionUp(self, event): """ Fired up openflow connection with the switch save the switch dpid Args: event: openflow ConnectionUp event Returns: Nada """ self.switches.add(pox.lib.util.dpid_to_str(event.dpid))
因此,如果需要,您应该捕获Connection Down事件以删除开关。要获取POX控制器的Dart版本中当前可用的所有openflow事件列表,请转到 https://github.com/noxrepo/pox/blob/dart/pox/openflow/ 的 在里面 强> 的.py 事件mixins的第336行
_eventMixin_events = set([ ConnectionUp, ConnectionDown, FeaturesReceived, PortStatus, FlowRemoved, PacketIn, BarrierIn, ErrorIn, RawStatsReply, SwitchDescReceived, FlowStatsReceived, AggregateFlowStatsReceived, TableStatsReceived, PortStatsReceived, QueueStatsReceived, FlowRemoved, ])
如需进一步的帮助,您可以查看我为希腊塞萨洛尼基的Python Meetup编写的Dart POX功能齐全的SDN控制器的代码,可在以下位置找到 https://github.com/tsartsaris/pythess-SDN