Pox启动及事件产生、监听分析

1    ./pox/pox.py , Pox入口 ,调用 pox/boot.py.boot()

 

2       实例化core=pox.core.initialize(),即为实例化POXCore类(该类是所有组件的交接点,提供组件注册功能),监听core即可监听以下事件

2.1       声明事件

  _eventMixin_events = set([
    UpEvent,
    DownEvent,
    GoingUpEvent,
    GoingDownEvent,
    ComponentRegistered
  ])

 

 

3       _do__launch(argv)

3.1       分析传入参数

3.2       _pre_startup(), 调用pox.openflow.launch() 加载 openflow 组件,处理openflow连接

3.2.1   注册OpenFlowConnectionArbiter,为连接建立nexus关系

3.2.2   OpenFlowNexus注册为openflow组件,申明了openflow事件,监听core.openflow 即可监听以下事件

  _eventMixin_events = set([
    ConnectionUp,
    ConnectionDown,
    FeaturesReceived,
    PortStatus,
    FlowRemoved,
    PacketIn,
    BarrierIn,
    ErrorIn,
    RawStatsReply,
    SwitchDescReceived,
    FlowStatsReceived,
    AggregateFlowStatsReceived,
    TableStatsReceived,
    PortStatsReceived,
    QueueStatsReceived,
    FlowRemoved,
  ])

3.3       从参数中加载组件,调用各组件中的launch函数

 

 

4       _post_startup()

4.1       调用pox.openflow.of_01.launch(),注册openflow.of_01 组件

4.1.1   实例化日志接口 core.getLogger('libopenflow_01')

4.1.2   实例化OpenFlow_01_Task

4.1.2.1  监听pox.core.GoingUpEvent,处理函数为_handle_GoingUpEvent

4.1.3   Core中注册of_01组件,组件任务为OpenFlow_01_Task

 

5       core.goUp(),执行POXCore.goUp()代码,

5.1       产生GoingUpEvent事件,执行of_01._handle_GoingUpEvent(),创建SOCK_STREAM监听TCP数据包

         当有连接请求时,实例化of_01.Connection,声明事件

_eventMixin_events = set([
    ConnectionUp,
    ConnectionDown,
    PortStatus,
    FlowRemoved,
    PacketIn,
    ErrorIn,
    BarrierIn,
    RawStatsReply,
    SwitchDescReceived,
    FlowStatsReceived,
    AggregateFlowStatsReceived,
    TableStatsReceived,
    PortStatsReceived,
    QueueStatsReceived,
    FlowRemoved,
  ])

5.2       产生UpEvent事件,执行


openflow以及 of_01.connection事件的产生:

of_01.Connection.read() 调用handlerMap类别的handle,raise全局事件触发其他监听组件

handlerMap = {
  of.OFPT_HELLO : handle_HELLO,
  of.OFPT_ECHO_REQUEST : handle_ECHO_REQUEST,
  of.OFPT_ECHO_REPLY : handle_ECHO_REPLY,
  of.OFPT_PACKET_IN : handle_PACKET_IN,
  of.OFPT_FEATURES_REPLY : handle_FEATURES_REPLY,
  of.OFPT_PORT_STATUS : handle_PORT_STATUS,
  of.OFPT_ERROR : handle_ERROR_MSG,
  of.OFPT_BARRIER_REPLY : handle_BARRIER,
  of.OFPT_STATS_REPLY : handle_STATS_REPLY,
  of.OFPT_FLOW_REMOVED : handle_FLOW_REMOVED,
  of.OFPT_VENDOR : handle_VENDOR,
}

of_01.Connection._incoming_stats_reply()调用statsHandlerMap类别的handle,raise全局事件触发其他监听组件

statsHandlerMap = {
  of.OFPST_DESC : handle_OFPST_DESC,
  of.OFPST_FLOW : handle_OFPST_FLOW,
  of.OFPST_AGGREGATE : handle_OFPST_AGGREGATE,
  of.OFPST_TABLE : handle_OFPST_TABLE,
  of.OFPST_PORT : handle_OFPST_PORT,
  of.OFPST_QUEUE : handle_OFPST_QUEUE,
}

上述的of_01.Connection.read()和_incomming_stats_reply()zai产生事件时均raise两次,首先raise Openflow事件,再raise of_01事件(Thx Lidemin)。

具体raise的细节为:

con.ofnexus产生openflow事件。如

con.ofnexus.raiseEventNoErrors(PacketIn, con, msg)

通过

 core.openflow.addListeners( self)

或者

core.openflow.addListenerByName("PacketIn", __handle__PacketIn)

将能监听到ofnexus产生的事件

con直接产生的of_01事件(即和connection有关事件),如

con.raiseEventNoErrors(PacketIn, con, msg)

监听该事件时必须指定connection,如

connection.addListeners(self)

 

 

强烈推荐lidemin “Pox的框架及启动过程分析“,分析的更到位!

posted @ 2014-01-26 11:35  YJunZhang  阅读(1057)  评论(0编辑  收藏  举报