def run(pkt_size, gap_ms): util.ping_test() switch = Switch(config.active_config) switch.reset_flow_table() control_client = ExpControlClient('mumu.ucsd.edu') control_client.execute('RESET') control_client.execute('SET learning False') pktgen = Pktgen(config.active_config) pktgen.low_level_start(pkt_count=50000, flow_count=50000, pkt_size=pkt_size, gap_ns=1000000*gap_ms) try: time.sleep(20) except KeyboardInterrupt: pktgen.stop_and_get_result() sys.exit(1) pktgen_result = pktgen.stop_and_get_result() pkt_in_count = control_client.execute('GET pkt_in_count') pktgen_rate = pktgen_result.sent_pkt_count / pktgen_result.running_time pkt_in_rate = pkt_in_count / pktgen_result.running_time control_client.execute('RESET') return (pktgen_rate, pkt_in_rate)
def main(): conf = config.active_config switch = Switch(conf) switch.reset_flow_table() #new_wildcard_rules() start_processes(200, 50, TOTAL_CLIENT_COUNT, 10.0, 10*1000*1000, REDIS_HOST_OF)
def run(flow_mod_gap_ms): util.ping_test() switch = Switch(config.active_config) switch.reset_flow_table() control_client = ExpControlClient('mumu.ucsd.edu') control_client.execute('RESET') control_client.execute('SET auto_install_rules False') control_client.execute('SET manual_install_gap_ms %s' % flow_mod_gap_ms) control_client.execute('SET manual_install_active True') # Send a starter packet to trigger packet-in. Doesn't matter what port it # goes to, as long as it has the IP address of what would have been the # pktgen host. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.sendto('Hi', (config.active_config.source_ip, 12345)) # Let the whole system run for a while. We cannot check for TCAM status; # that'd sometimes take forever when the switch is busily processing flow- # mods, and it'd probably affect the flow-mods. We check the TCAM # afterwards. util.verbose_sleep(60) control_client.execute('SET manual_install_active False') # Gather stats about flow-mod. The flow-mod gap may not be accurate. flow_mod_count = control_client.execute('GET flow_mod_count') flow_mod_start_time = control_client.execute('GET flow_mod_start_time') flow_mod_end_time = control_client.execute('GET flow_mod_end_time') flow_mod_rate = flow_mod_count / (flow_mod_end_time - flow_mod_start_time) # Wait for the switch to stabilize before asking it for stats. util.verbose_sleep(80) print 'Dumping table...' # Parse flow tables. Search up to the last point of a TCAM-write, which # signifies a full TCAM. Up to that point, we count the total number of # rules added. rule_list = switch.dump_tables(filter_str='') tcam_rule_count = 0 total_rule_count = 0 print 'Parsing', len(rule_list), 'rules...' for rule in rule_list: total_rule_count += 1 if 'table_id=0' in rule: tcam_rule_count += 1 if tcam_rule_count == 1500: break control_client.execute('RESET') switch.reset_flow_table() util.verbose_sleep(5) return (tcam_rule_count, total_rule_count, flow_mod_rate)
def new_exact_match_rules(wait_and_verify=True, reset_flow_table=True, rule_count=CLIENT_COUNT, flow_table_filter=FLOW_TABLE_FILTER, client_base_port=CLIENT_BASE_PORT): conf = config.active_config switch = Switch(conf) if reset_flow_table: switch.reset_flow_table() # From client to redis server. new_tcp_rule1 = lambda client_id: \ 'cookie=0,idle_timeout=0,hard_timeout=0,tcp,nw_tos=0x00,' + \ 'dl_vlan=0xffff,dl_vlan_pcp=0x00,dl_src=' + \ conf.dest_mac + ',dl_dst=' + conf.source_mac + ',nw_src=' + \ conf.dest_ip + ',nw_dst=' + conf.source_ip + \ ',tp_src=' + str(client_id + client_base_port) + \ ',tp_dst=' + str(REDIS_PORT) + \ ',actions=output:' + conf.source_of_port # From server back to client. new_tcp_rule2 = lambda client_id: \ 'cookie=0,idle_timeout=0,hard_timeout=0,tcp,nw_tos=0x00,' + \ 'dl_vlan=0xffff,dl_vlan_pcp=0x00,dl_src=' + \ conf.source_mac + ',dl_dst=' + conf.dest_mac + ',nw_src=' + \ conf.source_ip + ',nw_dst=' + conf.dest_ip + \ ',tp_dst=' + str(client_id + client_base_port) + \ ',tp_src=' + str(REDIS_PORT) + \ ',actions=output:' + conf.dest_of_port initial_rule_count = len(switch.dump_tables(filter_str=flow_table_filter)) for client_id in range(rule_count): # Add the rules first. for rule_f in [new_tcp_rule1, new_tcp_rule2]: proc = util.run_ssh(conf.add_rule_cmd(rule_f(client_id)), hostname=conf.ofctl_ip, verbose=True, stdout=subprocess.PIPE) if wait_and_verify or (client_id % 5 == 0): proc.wait() # Then verify if the correct number of rules have been added. if wait_and_verify and (client_id % 5 == 0 or client_id + 1 == rule_count): current_rule_count = len(switch.dump_tables(filter_str=flow_table_filter)) try: assert current_rule_count - initial_rule_count == (client_id + 1) * 2 except: print current_rule_count, initial_rule_count, client_id raise
def new_wildcard_rules(): conf = config.active_config switch = Switch(conf) switch.reset_flow_table() new_tcp_rule1 = 'cookie=0, priority=32768, idle_timeout=3600,hard_timeout=3600,tcp,in_port=' + \ conf.source_of_port + ',dl_src=' + \ conf.source_mac + ',dl_dst=' + conf.dest_mac + ',nw_src=' + \ conf.source_ip + ',nw_dst=' + conf.dest_ip + \ ',actions=output:' + conf.dest_of_port new_tcp_rule2 = 'cookie=0, priority=32768, idle_timeout=3600,hard_timeout=3600,tcp,in_port=' + \ conf.dest_of_port + ',dl_src=' + \ conf.dest_mac + ',dl_dst=' + conf.source_mac + ',nw_src=' + \ conf.dest_ip + ',nw_dst=' + conf.source_ip + \ ',actions=output:' + conf.source_of_port for rule in [new_tcp_rule1, new_tcp_rule2]: add_rule_cmd = conf.add_rule_cmd(rule) util.run_ssh(add_rule_cmd, hostname=conf.ofctl_ip, verbose=True)
def run(packet_per_second=100, pkt_size=1500, run_time=220): """ Returns (pktgen_pps, pkt_in_pps, flow_mod_pps, flow_mod_pps_stdev, pkt_out_pps), where pps_in is the actual number of packets/sec of pktgen, and flow_mod_pps and flow_mod_pps_stdev are the mean and stdev pps of successful flow installations at steady state. """ util.ping_test() switch = Switch(config.active_config) switch.reset_flow_table() # Initialize the experimental controller so that POX would have the # necessary settings. control_client = ExpControlClient('mumu.ucsd.edu') control_client.execute(['RESET']) control_client.execute(['SET', 'flow_stat_interval', 20]) control_client.execute(['SET', 'install_bogus_rules', True]) control_client.execute(['SET', 'emulate_hp_switch', True]) # Start capturing packets. tcpdump = Tcpdump(config.active_config) tcpdump.start() tcpdump_start_time = time.time() # Start firing packets. pktgen = Pktgen(config.active_config) gap = 1.0 / packet_per_second pkt_count = int(run_time * packet_per_second) pktgen.low_level_start(pkt_count=pkt_count, pkt_size=pkt_size, gap_ns=gap*1000*1000*1000, flow_count=1) pktgen_start_time = time.time() flow_mod_pps_list = [] # How fast were rules successfully written into the hardware table? We take # statistics at steady state. Also display flow statistics once in a while. last_stat_time = [0] def callback(t_left): flow_stat_dict = control_client.execute(['GET', 'flow_count_dict']) for stat_time in sorted(flow_stat_dict.keys()): if stat_time > last_stat_time[0]: last_stat_time[0] = stat_time flow_count = flow_stat_dict[stat_time] print t_left, 'seconds left, with flows', flow_count if pktgen_start_time + 60 <= time.time() <= pktgen_start_time + 180: flow_mod_pps_list.append(flow_count / 10.0) # Check the stat every 20 seconds. util.callback_sleep(run_time, callback, interval=20) # How fast were packets actually generated? pktgen_result = pktgen.stop_and_get_result() pktgen_pps = pktgen_result.sent_pkt_count / pktgen_result.running_time # How fast were pkt_out events? tcpdump_end_time = time.time() tcpdump_result = tcpdump.stop_and_get_result() pkt_out_pps = (tcpdump_result.dropped_pkt_count + tcpdump_result.recvd_pkt_count) / \ (tcpdump_end_time - tcpdump_start_time) # Calculate the mean and stdev of successful flow_mod pps. (flow_mod_pps, flow_mod_pps_stdev) = util.get_mean_and_stdev(flow_mod_pps_list) # How fast were pkt_in events arriving? pkt_in_count = control_client.execute(['GET', 'pkt_in_count']) pkt_in_start_time = control_client.execute(['GET', 'pkt_in_start_time']) pkt_in_end_time = control_client.execute(['GET', 'pkt_in_end_time']) pkt_in_pps = pkt_in_count / (pkt_in_end_time - pkt_in_start_time) return (pktgen_pps, pkt_in_pps, flow_mod_pps, flow_mod_pps_stdev, pkt_out_pps)