Ryu Controller中处理EventOFPFlowStatsReply消息时的Keyerror

Keyerror when handling the EventOFPFlowStatsReply message in the Ryu Controller

我试图在 Simple_monitor_13(Ryu SDN 控制器)中获取请求的 FlowStat 信息,但是当 运行 使用简单的 mininet 拓扑和“pingall”时,应用程序不断报告 Keyerrors coming来自非常基本的匹配字段,例如 Ipv4_src、eth_type。我是不是误解了这个活动的运作方式?以及如何实现这个要求?

for stat in sorted([flow for flow in body if (flow.priority == 1)], key=lambda flow: 
            (flow.match['in_port'], flow.match['eth_dst'],flow.match['ipv4_src'],flow.match['ipv4_dst'],flow.match['ip_proto'])):
            flow_stat['table_id']= stat.table_id
            flow_stat['priority'] = stat.priority
            flow_stat['in_port'] = stat.match['in_port']
            flow_stat['ip_proto'] = stat.match['ip_proto']
            flow_stat['ipv4_src'] = stat.match['ipv4_src']
            flow_stat['ipv4_dst'] = stat.match['ipv4_dst']
     File "c:\users\acer\appdata\local\programs\python\python38-32\lib\site-packages\ryu\base\app_manager.py", line 290, in _event_loop
        handler(ev)
      File "E:\SDN_ML_Anaconda\ryu\ryu\app\simple_monitor_13_fetch.py", line 91, in _flow_stats_reply_handler
        for stat in sorted([flow for flow in body if (flow.priority == 1)], key=lambda flow:
      File "E:\SDN_ML_Anaconda\ryu\ryu\app\simple_monitor_13_fetch.py", line 92, in <lambda>
        (flow.match['in_port'], flow.match['eth_dst'],flow.match['ipv4_src'],flow.match['ipv4_dst'],flow.match['ip_proto'])):
      File "c:\users\acer\appdata\local\programs\python\python38-32\lib\site-packages\ryu\ofproto\ofproto_v1_3_parser.py", line 904, in __getitem__
        return dict(self._fields2)[key]
    KeyError: 'ipv4_src'

FlowStatsReply

FlowStatsReply 包含交换机上安装的每个流的统计信息。由于流没有专用的唯一标识符,因此它们由它们的匹配字段标识。如果流规则在某个头字段上不匹配,则其在 FlowStatsReply 中的相应流条目也不会包含该字段。

SimpleMonitor13 中的匹配项

如果您查看继承自 SimpleMonitor13 的 SimpleSwitch13,您会发现控制器在其 _packet_in_handler 中安装流,匹配如下:

 match = parser.OFPMatch(in_port=in_port, eth_dst=dst, eth_src=src)

因此,SimpleMonitor13 中的 FlowStatsReply 将仅包含字段 in_porteth_dsteth_src,而不包含 ipv4_srceth_type