Python 如何获取TCP数据包的数据包计数?
我正在使用_flow_stats_reply_处理程序检索流统计信息,如Ryu Traffic Monitor示例中所示 我使用以下方式打印:Python 如何获取TCP数据包的数据包计数?,python,openflow,ryu,Python,Openflow,Ryu,我正在使用_flow_stats_reply_处理程序检索流统计信息,如Ryu Traffic Monitor示例中所示 我使用以下方式打印: file.write("\n{},{},{},{},{},{},{},{},{}" .format(ev.msg.datapath.id, stat.match['in_port'], stat.match['eth_src'], stat.match['eth_
file.write("\n{},{},{},{},{},{},{},{},{}"
.format(ev.msg.datapath.id,
stat.match['in_port'], stat.match['eth_src'], stat.match['eth_dst'],
stat.instructions[0].actions[0].port,
stat.packet_count, stat.byte_count,
stat.duration_sec, stat.duration_nsec))
注意stat.packet\u计数
如何更改此设置以计算TCP数据包?我知道有一个ip_proto
字段和一个tcp_flags
字段,但我不知道如何对匹配/计数进行编码
编辑:
我进一步研究了这一点,并在我的请求流统计功能中添加了一个流匹配:
def _request_stats(self, datapath):
self.logger.debug('send stats request: %016x', datapath.id)
ofp = datapath.ofproto
parser = datapath.ofproto_parser
cookie = cookie_mask = 0
match = parser.OFPMatch(eth_type=0x0800)
req = parser.OFPFlowStatsRequest(datapath, 0, ofp.OFPTT_ALL, ofp.OFPP_ANY, ofp.OFPG_ANY,
cookie, cookie_mask, match)
datapath.send_msg(req)
不幸的是,这仍然不起作用,任何关于为什么不这样做的想法都将不胜感激。您应该在匹配中添加更多数据,如
ip_proto
,以便与tcp匹配,您可能知道,tcp的ip协议号为6,有关ip协议号的更多信息,请检查
请使用下面的代码,在这种情况下不需要设置tcp\u标志
match = parser.OFPMatch(
eth_type=0x0800,
ip_proto=6,
)