2

I am retrieving flow statistics using a _flow_stats_reply_handler as demonstrated in the Ryu Traffic Monitor example.

I print using the following:

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))

Note the stat.packet_count.

How could I change this to count TCP packets? I understand there is an ip_proto field and a tcp_flags field but I don't know how to code the match/count.

Edit: I have further investigated this and added a flow match to my request flow stats function:

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)

This unfortunately still doesn't work, any ideas as to why not would be greatly appreciated.

HCF3301
  • 508
  • 1
  • 4
  • 14

1 Answers1

0

You should add more data to your match, like ip_proto in order to match with tcp, as you may know, IP protocol number of TCP is 6, for more information about IP Protocol numbers check Wikipedia.

Please use the code below, You don't need to settcp_flags in this case.

match = parser.OFPMatch(
    eth_type=0x0800, 
    ip_proto=6, 
    )
H. Qasemi
  • 164
  • 1
  • 10