最良の方法は、コントローラー クラスでセットを定義し、そこにすべてのスイッチの 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))
したがって、必要に応じて、接続ダウンのイベントをキャッチしてスイッチを削除する必要があります。Dart バージョンの POX コントローラーで現在利用可能なすべての openflow イベント ミックスインのリストを取得するには、https://github.com/noxrepo/pox/blob/dart/pox/openflow/ init .py line 336 at event mixinsに移動します。
_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で見つけることができます。