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

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

 

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

2.1       声明事件

1
2
3
4
5
6
7
_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 即可监听以下事件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
_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,声明事件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
_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全局事件触发其他监听组件

1
2
3
4
5
6
7
8
9
10
11
12
13
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全局事件触发其他监听组件

1
2
3
4
5
6
7
8
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事件。如

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

通过

1
core.openflow.addListeners( self)

或者

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

将能监听到ofnexus产生的事件

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

1
con.raiseEventNoErrors(PacketIn, con, msg)

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

1
connection.addListeners(self)

 

 

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

posted @   YJunZhang  阅读(1062)  评论(0编辑  收藏  举报
编辑推荐:
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
阅读排行:
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单
· C# 13 中的新增功能实操
· Supergateway:MCP服务器的远程调试与集成工具
点击右上角即可分享
微信分享提示