最好的方法是在你的控制器类中定义一个集合,并在那里添加所有开关的 DPID。因此,每次您在 _handle_ConnectionUp 中有事件时,您都可以获得交换机的 DPID 并相应地添加它。
在你的主控制器类初始化函数中
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 事件 mixin 的列表,请转到 event mixins 处的https://github.com/noxrepo/pox/blob/dart/pox/openflow/init.py line 336
_eventMixin_events = set([
ConnectionUp,
ConnectionDown,
FeaturesReceived,
PortStatus,
FlowRemoved,
PacketIn,
BarrierIn,
ErrorIn,
RawStatsReply,
SwitchDescReceived,
FlowStatsReceived,
AggregateFlowStatsReceived,
TableStatsReceived,
PortStatsReceived,
QueueStatsReceived,
FlowRemoved,
])
如需进一步帮助,您可以使用 Dart POX 检查功能齐全的 SDN 控制器的代码,我为希腊塞萨洛尼基的 Python Meetup 编写,可以在https://github.com/tsartsaris/pythess-SDN找到。