def send_and_count(pkt_size, gap_ms): """ Sends 1500 flows, each of FLOW_LENGTH packets of size pkt_size, and with gap_ms in microseconds. Returns the number of rules in the TCAM and the software table. """ switch.reset_flow_table() tcpdump.sniff_and_send(pkt_count_arg=FLOW_COUNT, pkt_size_arg=pkt_size, gap_ns_arg=gap_ms*(10**6), flow_count_arg=FLOW_COUNT) time.sleep(5) flow_table = switch.dump_tables(filter='') return (len(filter(lambda x: x.find('table_id=0') >=0, flow_table)), len(filter(lambda x: x.find('table_id=2') >=0, flow_table)))
def run(): """ Main entry point. """ global _est_flow_length global _steady_slice_start_seq_num, _steady_slice_end_seq_num # Initialize global variables state.flow_stat = {} state.global_stat = {'recv_count': 0, 'recv_time': None, 'sent_count': None, 'sent_time': None, 'recv_start_time': None, 'recv_end_time': None, 'recv_bw_Mbps': None, 'sent_bw_Mbps': None} _est_flow_length = None _steady_slice_start_seq_num = None _steady_slice_end_seq_num = None # Start! Analyze packets. tcpdump.sniff_and_send() tcpdump.parse_pkt(_get_new_pkt) print '' # Analyze flows. for flow_id in sorted(state.flow_stat.keys()): _process_flow_stat(flow_id) # Analyze aggregate. g = state.global_stat g['sent_time'] = state.pktgen_run_time g['sent_count'] = state.pktgen_sent_pkt_count g['recv_time'] = g['recv_end_time'] - g['recv_start_time'] g['recv_bw_Mbps'] = g['recv_count'] * config.pkt_size * 8 / g['recv_time'] / 1000000 g['sent_bw_Mbps'] = g['sent_count'] * config.pkt_size * 8 / g['sent_time'] / 1000000