首页 文章

使用pox控制器显示SDN中所有连接的交换机

提问于
浏览
1

我的环境是mininet . 我试图实现的是,每次开关连接或断开与痘控制器,控制器应打印所有连接的开关(他们的DPID) .

def _handle_ConnectionUp (self, event):

print "Switch %s has come up." % event.dpid

那是我可以合作的东西吗?在我可以使用_handle_ConnectionUp之前我需要实现什么?

提前致谢 .

1 回答

  • 1

    最好的方法是在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事件列表,请转到事件mixins的https://github.com/noxrepo/pox/blob/dart/pox/openflow/init.py第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找到

相关问题