def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) field_2b_set = match.ipv6_dst(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD')) act_setfield = action.action_set_field() act_setfield.field = field_2b_set # TODO: insert action set field properly act_out = action.action_output() act_out.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act_setfield) inst.actions.add(act_out) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") #Send packet pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190') ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): table_id = testutils.EX_ACL_TABLE port_in = exact_port_map.keys()[0] egr_port = exact_port_map.keys()[1] #"clear swtich;" testutils.delete_all_flows(self.controller, self.logger) #make packet; pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a') exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='aa:aa:aa:aa:aa:aa') # get match list match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in) act = action.action_set_field() field = match.eth_dst(parse.parse_mac("aa:aa:aa:aa:aa:aa")) act.field.add(field) exact_table_output(self, table_id, match_ls, actions = [act], egr_port = egr_port) testutils.do_barrier(self.controller) "send a packet from port_in " self.dataplane.send(port_in, str(pkt)) "poll from the egr_port port" (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1) self.assertTrue(pkt is not None,"rec none packets") self.assertEqual(str(exp_pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] dl_vlan = random.randint(1,0x7ff) dl_vlan_pcp = random.randint(0,7) pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': dl_vlan, 'pcp': dl_vlan_pcp}]) match_ls = parse.packet_to_flow_match(pkt) wildcards = 0 new_dl_vlan = random.randint(0x800,0xfff) exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'type': ETHERTYPE_VLAN, 'vid': new_dl_vlan, 'pcp': dl_vlan_pcp}, {'vid': dl_vlan, 'pcp': dl_vlan_pcp}]) # Create parameters for each table act_list = [] next_avail = [] chk_expire = [] #Table 0 act = action.action_output() act.port = egr_port act_list.append([act]) next_avail.append(True) chk_expire.append(False) #Table 1 #act = action.action_set_vlan_vid() #act.vlan_vid = new_dl_vlan act = action.action_set_field() act.field = match.vlan_vid(new_dl_vlan + ofp.OFPVID_PRESENT) act_list.append([act]) next_avail.append(True) chk_expire.append(False) #Table 2 act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN act_list.append([act]) next_avail.append(False) chk_expire.append(False) write_action_test_multi_tables(self, ing_port, egr_port, match_fields = match_ls, wildcards = wildcards, act_list = act_list, next_avail = next_avail, chk_expire = chk_expire, pkt = pkt, exp_pkt = exp_pkt)
def runTest(self): old_vid = 2 new_vid = 3 # sup_acts = supported_actions_get(self) # if not (sup_acts & 1 << ofp.OFPXMT_OFB_VLAN_VID): # testutils.skip_message_emit(self, "Modify VLAN tag test") # return pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}]) exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': new_vid}]) vid_act = action.action_set_field() vid_act.field = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, apply_action_list=[vid_act])
def runTest(self): """ Add four flow entries: First Table; Match IP Src A; goto Second Table Second Table; Match IP Src A; send to 1, goto Third Table Third Table; Match IP Src A; clear action, goto Fourth Table Fourth Table; Match IP Src A; send to 2 Then send in 2 packets: IP A, TCP C; expect out port 1 IP A, TCP B; expect out port 1 @param self object instance @param EX_ACL_TABLE first table @param WC_ACL_TABLE second table @param WC_SERV_TABLE third table @param EX_L2_TABLE fourth table """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up first match #write_goto(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE) act = action.action_set_field() field = match.eth_src(parse.parse_mac("aa:aa:aa:aa:aa:aa")) act.field.add(field) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE, act=act) # Set up second match testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L3_TABLE, of_ports[0], of_ports[2]) # Set up third match, "Clear Action" inst = instruction.instruction_clear_actions() testutils.write_goto(self, testutils.EX_L3_TABLE, testutils.WC_L3_TABLE, of_ports[2], add_inst=inst) # Set up fourth match testutils.write_output(self, testutils.WC_L3_TABLE, of_ports[1]) #write_output(self, testutils.EX_L2_TABLE, 4) # Generate a packet matching flow 1, 2, and 3; rcv on port[1] testutils.reply_check_dp(self, tcp_sport=1234, ing_port=of_ports[2], egr_port=of_ports[1])
def create_action(**kwargs): a = kwargs.get('action') if a == ofp.OFPAT_OUTPUT: act = action.action_output() act.port = kwargs.get('port', 1) return act if a == ofp.OFPAT_GROUP: act = action.action_group() act.group_id = kwargs.get('group_id', 0) return act if a == ofp.OFPAT_SET_FIELD: port = kwargs.get('tcp_sport', 0) field_2b_set = match.tcp_src(port) act = action.action_set_field() act.field = field_2b_set return act;
def runTest(self): new_vid = 4002 # sup_acts = supported_actions_get(self) # if not(sup_acts & 1<<ofp.OFPXMT_OFB_VLAN_VID): # testutils.skip_message_emit(self, "Add VLAN tag test") # return pkt = testutils.simple_tcp_packet() exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'vid': new_vid}]) push_act = action.action_push_vlan() push_act.ethertype = 0x8100 vid_act = action.action_set_field() vid_act.field=match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) #vid_act = action.action_set_vlan_vid() #vid_act.vlan_vid = new_vid testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, apply_action_list=[push_act, vid_act])
def runTest(self): """ Add flow entries: First Table; Match IP Src A; set ToS = tos1, goto Second Table First Table; Match IP Src B; set ToS = tos2, goto Second Table Second Table; Match IP Src A; send to 1 Second Table; Match IP Src B; send to 1 Then send packets: IP A; expect port 1 with DSCP = dscp1 IP B; expect port 1 with DSCP = dscp2 @param self object instance @param EX_ACL_TABLE first table @param WC_ACL_TABLE second table @param dscp1 DSCP value to be set for first flow @param dscp2 DSCP value to be set for second flow """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up flow match in table A: set ToS #t_act = action.action_set_nw_tos() #t_act.nw_tos = tos1 dscp1 = 4 dscp2 = 8 t_act = action.action_set_field() t_act.field = match.ip_dscp(dscp1) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.10') t_act.field = match.ip_dscp(dscp2) #t_act.field = match.ip_ecn(3) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.30',clear_tag=False) # Set up flow matches in table B: routing testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.10") testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.30") # Generate packets and check them exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=1234, ip_dscp=dscp1) testutils.reply_check_dp(self, ip_src='192.168.1.10', tcp_sport=1234, exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])
def runTest(self): new_vid = 4002 # sup_acts = supported_actions_get(self) # if not(sup_acts & 1<<ofp.OFPXMT_OFB_VLAN_VID): # testutils.skip_message_emit(self, "Add VLAN tag test") # return pkt = testutils.simple_tcp_packet() exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': new_vid}]) push_act = action.action_push_vlan() push_act.ethertype = 0x8100 vid_act = action.action_set_field() vid_act.field = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) #vid_act = action.action_set_vlan_vid() #vid_act.vlan_vid = new_vid testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, apply_action_list=[push_act, vid_act])
def runTest(self): #testutils.skip_message_emit(self, 'skip!') #return #'instruction goto' inst_goto = instruction.instruction_goto_table() #'instruction table 0' inst = instruction.instruction_write_actions() #"action setfield" act = action.action_set_field() inst.actions.add(act) #"action output" act = action.action_output() act.port = 1 inst.actions.add(act) #"table 0 instructions" request = message.flow_mod() request.table_id = 0 request.instructions.add(inst) inst_goto.table_id = 1; request.instructions.add(inst_goto)
def runTest(self): #testutils.skip_message_emit(self, 'skip!') #return #'instruction goto' inst_goto = instruction.instruction_goto_table() #'instruction table 0' inst = instruction.instruction_write_actions() #"action setfield" act = action.action_set_field() inst.actions.add(act) #"action output" act = action.action_output() act.port = 1 inst.actions.add(act) #"table 0 instructions" request = message.flow_mod() request.table_id = 0 request.instructions.add(inst) inst_goto.table_id = 1 request.instructions.add(inst_goto)
def runTest(self): """ Add four flow entries: First Table; Match IP Src A; goto Second Table Second Table; Match IP Src A; send to 1, goto Third Table Third Table; Match IP Src A; clear action, goto Fourth Table Fourth Table; Match IP Src A; send to 2 Then send in 2 packets: IP A, TCP C; expect out port 1 IP A, TCP B; expect out port 1 @param self object instance @param EX_ACL_TABLE first table @param WC_ACL_TABLE second table @param WC_SERV_TABLE third table @param EX_L2_TABLE fourth table """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up first match #write_goto(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE) act = action.action_set_field() field = match.eth_src(parse.parse_mac("aa:aa:aa:aa:aa:aa")) act.field.add(field) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE ,act = act) # Set up second match testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L3_TABLE, of_ports[0], of_ports[2]) # Set up third match, "Clear Action" inst = instruction.instruction_clear_actions() testutils.write_goto(self, testutils.EX_L3_TABLE, testutils.WC_L3_TABLE, of_ports[2], add_inst=inst) # Set up fourth match testutils.write_output(self, testutils.WC_L3_TABLE, of_ports[1]) #write_output(self, testutils.EX_L2_TABLE, 4) # Generate a packet matching flow 1, 2, and 3; rcv on port[1] testutils.reply_check_dp(self, tcp_sport=1234, ing_port = of_ports[2], egr_port = of_ports[1])
def runTest(self): table_id = testutils.EX_ACL_TABLE port_in = exact_port_map.keys()[0] egr_port = exact_port_map.keys()[1] #"clear swtich;" testutils.delete_all_flows(self.controller, self.logger) #make packet; pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a') exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='aa:aa:aa:aa:aa:aa') # get match list match_ls = testutils.packet_to_exact_flow_match(pkt=pkt, table_id=table_id, ing_port=port_in) act = action.action_set_field() field = match.eth_dst(parse.parse_mac("aa:aa:aa:aa:aa:aa")) act.field.add(field) exact_table_output(self, table_id, match_ls, actions=[act], egr_port=egr_port) testutils.do_barrier(self.controller) "send a packet from port_in " self.dataplane.send(port_in, str(pkt)) "poll from the egr_port port" (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1) self.assertTrue(pkt is not None, "rec none packets") self.assertEqual(str(exp_pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
def vlan_multipush_act_tests(parent, test_condition=0): """ Test vlan push action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param test_condition Value between 0 and 3 """ parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)), "Parameter num_tags not within an acceptable range") (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True) # vlan_action_support_check(parent) if sup_push_vlan == False: testutils.skip_message_emit( parent, "Vlan multiple push action test. PUSH not supported") return if sup_pop_vlan == False: testutils.skip_message_emit( parent, "Vlan multiple push action test. POP not supported") return if sup_set_vlan_vid == False: testutils.skip_message_emit( parent, "Vlan multiple push action test. SET VLAN VID not supported") return if sup_set_vlan_pcp == False: testutils.skip_message_emit( parent, "Vlan multiple push action test. SET VLAN PCP not supported") return inst_app_flag = testutils.WRITE_ACTIONS_INSTRUCTION new_vid = parent.vid + 2 new_pcp = parent.pcp + 2 act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN act3 = None if test_condition == 0: vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = new_vid add_tag_exp = True exp_vid = new_vid exp_vlan_type = act.ethertype if parent.num_tags == 0: exp_pcp = 0 else: exp_pcp = parent.pcp elif test_condition == 1: #act2 = action.action_set_vlan_pcp() #act2.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act2 = action.action_set_field() act2.field = vlan_pcp add_tag_exp = True exp_pcp = new_pcp exp_vlan_type = act.ethertype #exp_vid = 0 if parent.num_tags == 0: exp_vid = 0 else: exp_vid = parent.vid elif test_condition == 2: vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = new_vid #act3 = action.action_set_vlan_pcp() #act3.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act3 = action.action_set_field() act3.field = vlan_pcp add_tag_exp = True exp_vid = new_vid exp_pcp = new_pcp exp_vlan_type = act.ethertype elif test_condition == 3: act2 = action.action_pop_vlan() add_tag_exp = False exp_vid = parent.vid exp_pcp = parent.pcp exp_vlan_type = parent.vlan_type inst_app_flag = testutils.APPLY_ACTIONS_INSTRUCTION elif test_condition == 4: vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act3 = action.action_set_field() act3.field = vlan_vid #act2 = action.action_set_vlan_pcp() #act2.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act2 = action.action_set_field() act2.field = vlan_pcp add_tag_exp = True exp_pcp = new_pcp exp_vlan_type = act.ethertype #exp_vid = 0 if parent.num_tags == 0: exp_vid = 1 else: exp_vid = parent.vid else: return match_exp = True exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED action_list = [act, act2] if act3 is not None: action_list.append(act3) wildcards = 0 if parent.num_tags == 0: wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_VID wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_PCP testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=wildcards, dl_vlan=parent.vid, dl_vlan_pcp=parent.pcp, dl_vlan_type=parent.vlan_type, dl_vlan_int=parent.vid_2nd, dl_vlan_pcp_int=parent.pcp_2nd, vid_match=parent.vid_match, pcp_match=parent.pcp_match, exp_vid=exp_vid, exp_pcp=exp_pcp, exp_vlan_type=exp_vlan_type, match_exp=match_exp, add_tag_exp=add_tag_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, inst_app_flag=inst_app_flag, max_test=1)
def vlan_set_two_tables_tests(parent, test_condition=0): """ @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ wildcards = 0 vid = random.randint(1, 4094) pcp = random.randint(0, 6) vid_int = -1 pcp_int = 0 exp_vid = vid + 1 exp_pcp = pcp + 1 # Match condition on TBL0 (match) vid_match_tbl0 = vid pcp_match_tbl0 = pcp # Expect modified pkt on TBL1 (match) if (test_condition == 0): vid_match_tbl1 = exp_vid pcp_match_tbl1 = exp_pcp match_exp_tbl1 = True # Expect the same pkt on TBL1 (Unmatch) else: #test_condition == 1 vid_match_tbl1 = vid pcp_match_tbl1 = pcp match_exp_tbl1 = False # Create action_list for TBL0 #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid #act2 = action.action_set_vlan_pcp() #act2.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act2 = action.action_set_field() act2.field = vlan_pcp action_list_tbl0 = [act, act2] # Output action for table1 will be set in the framework action_list_tbl1 = None flow_match_test_vlan_two_tables(parent, pa_port_map, wildcards=wildcards, dl_vlan=vid, dl_vlan_pcp=pcp, dl_vlan_int=vid_int, dl_vlan_pcp_int=pcp_int, vid_match_tbl0=vid_match_tbl0, pcp_match_tbl0=pcp_match_tbl0, action_list_tbl0=action_list_tbl0, match_exp_tbl0=True, vid_match_tbl1=vid_match_tbl1, pcp_match_tbl1=pcp_match_tbl1, action_list_tbl1=action_list_tbl1, match_exp_tbl1=match_exp_tbl1, exp_vid=exp_vid, exp_pcp=exp_pcp, max_test=1)
def vlan_multipush_act_tests(parent, test_condition=0): """ Test vlan push action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param test_condition Value between 0 and 3 """ parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)), "Parameter num_tags not within an acceptable range") (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True) # vlan_action_support_check(parent) if sup_push_vlan == False: testutils.skip_message_emit(parent, "Vlan multiple push action test. PUSH not supported") return if sup_pop_vlan == False: testutils.skip_message_emit(parent, "Vlan multiple push action test. POP not supported") return if sup_set_vlan_vid == False: testutils.skip_message_emit(parent, "Vlan multiple push action test. SET VLAN VID not supported") return if sup_set_vlan_pcp == False: testutils.skip_message_emit(parent, "Vlan multiple push action test. SET VLAN PCP not supported") return inst_app_flag = testutils.WRITE_ACTIONS_INSTRUCTION new_vid = parent.vid + 2; new_pcp = parent.pcp + 2; act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN act3 = None if test_condition == 0: vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = new_vid add_tag_exp = True exp_vid = new_vid exp_vlan_type = act.ethertype if parent.num_tags == 0: exp_pcp = 0 else: exp_pcp = parent.pcp elif test_condition == 1: #act2 = action.action_set_vlan_pcp() #act2.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act2 = action.action_set_field() act2.field = vlan_pcp add_tag_exp = True exp_pcp = new_pcp exp_vlan_type = act.ethertype #exp_vid = 0 if parent.num_tags == 0: exp_vid = 0 else: exp_vid = parent.vid elif test_condition == 2: vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = new_vid #act3 = action.action_set_vlan_pcp() #act3.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act3 = action.action_set_field() act3.field = vlan_pcp add_tag_exp = True exp_vid = new_vid exp_pcp = new_pcp exp_vlan_type = act.ethertype elif test_condition == 3: act2 = action.action_pop_vlan() add_tag_exp = False exp_vid = parent.vid exp_pcp = parent.pcp exp_vlan_type = parent.vlan_type inst_app_flag = testutils.APPLY_ACTIONS_INSTRUCTION elif test_condition == 4: vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act3 = action.action_set_field() act3.field = vlan_vid #act2 = action.action_set_vlan_pcp() #act2.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act2 = action.action_set_field() act2.field = vlan_pcp add_tag_exp = True exp_pcp = new_pcp exp_vlan_type = act.ethertype #exp_vid = 0 if parent.num_tags == 0: exp_vid = 1 else: exp_vid = parent.vid else: return match_exp = True exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED action_list=[act, act2] if act3 is not None: action_list.append(act3) wildcards = 0 if parent.num_tags == 0: wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_VID wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_PCP testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=wildcards, dl_vlan=parent.vid, dl_vlan_pcp=parent.pcp, dl_vlan_type=parent.vlan_type, dl_vlan_int=parent.vid_2nd, dl_vlan_pcp_int=parent.pcp_2nd, vid_match=parent.vid_match, pcp_match=parent.pcp_match, exp_vid=exp_vid, exp_pcp=exp_pcp, exp_vlan_type=exp_vlan_type, match_exp=match_exp, add_tag_exp=add_tag_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, inst_app_flag=inst_app_flag, max_test=1)
def mpls_multipush3_act_tests(parent, test_condition=0): """ Test mpls push and set with out-of-range value actions for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)), "Parameter num_tags not within an acceptable range") sup_mpls_act = mpls_action_support_check(parent) if sup_mpls_act.has_key('sup_push_mpls') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. PUSH not supported") return if sup_mpls_act.has_key('sup_set_mpls_label') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. SET_LABEL not supported") return if sup_mpls_act.has_key('sup_set_mpls_tc') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. SET_TC not supported") return act = action.action_push_mpls() act.ethertype = 0x8847 if test_condition == 0: #act2 = action.action_set_mpls_label() #act2.mpls_label = 1048576 #exp_label = act2.mpls_label act2 = action.action_set_field() act2.field = match.mpls_label(1048576) exp_label = 1048576 exp_tc = 0 exp_ttl = 0 # Not expected elif test_condition == 1: #act2 = action.action_set_mpls_tc() #act2.mpls_tc = 8 #exp_tc = act2.mpls_tc act2 = action.action_set_field() act2.field = match.mpls_tc(8) exp_tc = 8 exp_label = 0 exp_ttl = 0 # Not expected else: return match_exp = False exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT action_list=[act, act2] testutils.flow_match_test_mpls(parent, pa_port_map, wildcards=0, mpls_label=parent.label, mpls_tc=parent.tc, mpls_label_int=parent.label_int, mpls_tc_int=parent.tc_int, label_match=parent.label_match, tc_match=parent.tc_match, dl_type_match=parent.dl_type_match, exp_mpls_label=exp_label, exp_mpls_tc=exp_tc, exp_mpls_ttl=exp_ttl, match_exp=match_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def vlan_set_act_tests(parent, test_condition=0): """ Test vlan set_vid and set_pcp action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param test_condition Value between 0 and 3 """ parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)), "Parameter num_tags not within an acceptable range") (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True) # vlan_action_support_check(parent) new_vid = parent.vid + 2 new_pcp = parent.pcp + 2 #print(str(new_vid)) #print(str(new_pcp)) if sup_set_vlan_vid == False: testutils.skip_message_emit( parent, "Vlan set action test. SET VLAN VID not supported") return if sup_set_vlan_pcp == False: testutils.skip_message_emit( parent, "Vlan set action test. SET VLAN PCP not supported") return exp_vlan_type = parent.vlan_type if test_condition == 0: vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid #act = action.action_set_vlan_vid() #act.vlan_vid = new_vid if parent.num_tags == 0: match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT else: match_exp = True exp_vid = new_vid exp_pcp = parent.pcp exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 1: vlan_vid = match.vlan_vid(4096 + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid #act = action.action_set_vlan_vid() #act.vlan_vid = 4096 match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT elif test_condition == 2: #act = action.action_set_vlan_pcp() #act.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act = action.action_set_field() act.field = vlan_pcp if parent.num_tags == 0: match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT else: match_exp = True exp_vid = parent.vid exp_pcp = new_pcp exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 3: #act = action.action_set_vlan_pcp() #act.vlan_pcp = 8 #OUT OF RANGE vlan_pcp = match.vlan_pcp(8) #OUT OF RANGE act = action.action_set_field() act.field = vlan_pcp match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT else: return action_list = [act] wildcards = 0 if parent.num_tags == 0: wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_VID wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_PCP testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=wildcards, dl_vlan=parent.vid, dl_vlan_pcp=parent.pcp, dl_vlan_type=parent.vlan_type, dl_vlan_int=parent.vid_2nd, dl_vlan_pcp_int=parent.pcp_2nd, vid_match=parent.vid_match, pcp_match=parent.pcp_match, exp_vid=exp_vid, exp_pcp=exp_pcp, exp_vlan_type=exp_vlan_type, match_exp=match_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def mpls_multipush3_act_tests(parent, test_condition=0): """ Test mpls push and set with out-of-range value actions for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)), "Parameter num_tags not within an acceptable range") sup_mpls_act = mpls_action_support_check(parent) if sup_mpls_act.has_key('sup_push_mpls') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. PUSH not supported") return if sup_mpls_act.has_key('sup_set_mpls_label') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. SET_LABEL not supported") return if sup_mpls_act.has_key('sup_set_mpls_tc') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. SET_TC not supported") return act = action.action_push_mpls() act.ethertype = 0x8847 if test_condition == 0: #act2 = action.action_set_mpls_label() #act2.mpls_label = 1048576 #exp_label = act2.mpls_label act2 = action.action_set_field() act2.field = match.mpls_label(1048576) exp_label = 1048576 exp_tc = 0 exp_ttl = 0 # Not expected elif test_condition == 1: #act2 = action.action_set_mpls_tc() #act2.mpls_tc = 8 #exp_tc = act2.mpls_tc act2 = action.action_set_field() act2.field = match.mpls_tc(8) exp_tc = 8 exp_label = 0 exp_ttl = 0 # Not expected else: return match_exp = False exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT action_list = [act, act2] testutils.flow_match_test_mpls(parent, pa_port_map, wildcards=0, mpls_label=parent.label, mpls_tc=parent.tc, mpls_label_int=parent.label_int, mpls_tc_int=parent.tc_int, label_match=parent.label_match, tc_match=parent.tc_match, dl_type_match=parent.dl_type_match, exp_mpls_label=exp_label, exp_mpls_tc=exp_tc, exp_mpls_ttl=exp_ttl, match_exp=match_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[2] table_id1 = testutils.EX_L3_TABLE table_id2 = testutils.WC_ALL_TABLE # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") rv = testutils.set_table_config(self, table_id = table_id1) self.assertEqual(rv, 0, "Failed to set table config") # Add entry match pkt = testutils.simple_ipv6_packet(ip_dst='fe80::1:0:1234') pkt_metadata = {'metadata_val':0xabcdef0123456789, 'metadata_msk':0xffffffffffffffff} inst_ls1 = [] inst1_write = instruction.instruction_write_metadata() inst1_write.metadata = pkt_metadata['metadata_val'] inst1_write.metadata_mask = pkt_metadata['metadata_msk'] inst1_goto = instruction.instruction_goto_table() inst1_goto.table_id = table_id2 inst_ls1.append(inst1_write) inst_ls1.append(inst1_goto) request1 = testutils.flow_msg_create(self, pkt, ing_port = ing_port, instruction_list = inst_ls1, table_id = table_id1) testutils.flow_msg_install(self, request1) act_ls2 = [] act2_setfld = action.action_set_field() act2_setfld.field = match.ipv6_dst(ipaddr.IPv6Address('fe80::1:6554:3e7f:1')) act2_out = action.action_output() act2_out.port = egr_port act_ls2.append(act2_setfld) act_ls2.append(act2_out) pkt_metadata = {'metadata_val':0xabcdef0100000000, 'metadata_msk':0xffffffff00000000} request2 = testutils.flow_msg_create(self, pkt, pkt_metadata, ing_port, action_list = act_ls2, table_id = table_id2) testutils.flow_msg_install(self, request2) #Send packet ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::1:6554:3e7f:1') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def vlan_set_two_tables_tests(parent, test_condition=0): """ @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ wildcards = 0 vid = random.randint(1, 4094) pcp = random.randint(0, 6) vid_int = -1 pcp_int = 0 exp_vid = vid + 1 exp_pcp = pcp + 1 # Match condition on TBL0 (match) vid_match_tbl0 = vid pcp_match_tbl0 = pcp # Expect modified pkt on TBL1 (match) if (test_condition == 0): vid_match_tbl1 = exp_vid pcp_match_tbl1 = exp_pcp match_exp_tbl1 = True # Expect the same pkt on TBL1 (Unmatch) else: #test_condition == 1 vid_match_tbl1 = vid pcp_match_tbl1 = pcp match_exp_tbl1 = False # Create action_list for TBL0 #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid #act2 = action.action_set_vlan_pcp() #act2.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act2 = action.action_set_field() act2.field = vlan_pcp action_list_tbl0 = [act, act2] # Output action for table1 will be set in the framework action_list_tbl1 = None flow_match_test_vlan_two_tables(parent, pa_port_map, wildcards=wildcards, dl_vlan=vid, dl_vlan_pcp=pcp, dl_vlan_int=vid_int, dl_vlan_pcp_int=pcp_int, vid_match_tbl0=vid_match_tbl0, pcp_match_tbl0=pcp_match_tbl0, action_list_tbl0 = action_list_tbl0, match_exp_tbl0=True, vid_match_tbl1=vid_match_tbl1, pcp_match_tbl1=pcp_match_tbl1, action_list_tbl1 = action_list_tbl1, match_exp_tbl1=match_exp_tbl1, exp_vid=exp_vid, exp_pcp=exp_pcp, max_test=1)
def novlan_push_two_tables_tests(parent): """ @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ wildcards = 0 vid = -1 pcp = 0 vid_int = -1 pcp_int = 0 exp_vid = random.randint(1, 4094) exp_pcp = random.randint(0, 6) # Match condition on TBL0 (match) vid_match_tbl0 = ofp.OFPVID_NONE pcp_match_tbl0 = 0 # Create action_list for TBL0 action_list_tbl0 = [] act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN action_list_tbl0.append(act) #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) #act = action.action_set_vlan_pcp() #act.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act = action.action_set_field() act.field = vlan_pcp action_list_tbl0.append(act) # create action_list for tbl1 vid_match_tbl1 = exp_vid pcp_match_tbl1 = exp_pcp # output action for table1 will be set in the framework action_list_tbl1 = None flow_match_test_vlan_two_tables(parent, pa_port_map, dl_vlan=vid, dl_vlan_pcp=pcp, dl_vlan_int=vid_int, dl_vlan_pcp_int=pcp_int, vid_match_tbl0=vid_match_tbl0, pcp_match_tbl0=pcp_match_tbl0, action_list_tbl0=action_list_tbl0, match_exp_tbl0=True, vid_match_tbl1=vid_match_tbl1, pcp_match_tbl1=pcp_match_tbl1, action_list_tbl1=action_list_tbl1, match_exp_tbl1=True, exp_vid=exp_vid, exp_pcp=exp_pcp, add_tag_exp=True, wildcards=wildcards, max_test=1)
def vlan_push_two_tables_tests(parent, test_condition=0, match_exp=True): """ @param parent must implement controller, dataplane, asserttrue, assertequal and logger """ wildcards = 0 vid = random.randint(1, 4094) pcp = random.randint(0, 6) vid_int = -1 pcp_int = 0 if (test_condition == 0): exp_vid = vid exp_pcp = pcp elif (test_condition == 1): exp_vid = vid + 1 exp_pcp = pcp elif (test_condition == 2): exp_vid = vid exp_pcp = pcp + 1 elif (test_condition == 3): exp_vid = vid + 1 exp_pcp = pcp + 1 else: return # match condition on tbl0 (match) vid_match_tbl0 = vid pcp_match_tbl0 = pcp # create action_list for tbl0 action_list_tbl0 = [] act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN action_list_tbl0.append(act) if (match_exp): # push-only for test0 if (test_condition == 1): #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) elif (test_condition == 2): #act = action.action_set_vlan_pcp() #act.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act = action.action_set_field() act.field = vlan_pcp action_list_tbl0.append(act) elif (test_condition == 3): #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) #act = action.action_set_vlan_pcp() #act.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act = action.action_set_field() act.field = vlan_pcp action_list_tbl0.append(act) else: if (test_condition == 0): #act = action.action_set_vlan_vid() #act.vlan_vid = vid + 1 vlan_vid = match.vlan_vid(vid + 1 + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) # Create action_list for TBL1 vid_match_tbl1 = exp_vid pcp_match_tbl1 = exp_pcp # Output action for table1 will be set in the framework action_list_tbl1 = None flow_match_test_vlan_two_tables(parent, pa_port_map, dl_vlan=vid, dl_vlan_pcp=pcp, dl_vlan_int=vid_int, dl_vlan_pcp_int=pcp_int, vid_match_tbl0=vid_match_tbl0, pcp_match_tbl0=pcp_match_tbl0, action_list_tbl0=action_list_tbl0, match_exp_tbl0=True, vid_match_tbl1=vid_match_tbl1, pcp_match_tbl1=pcp_match_tbl1, action_list_tbl1=action_list_tbl1, match_exp_tbl1=match_exp, exp_vid=exp_vid, exp_pcp=exp_pcp, add_tag_exp=True, wildcards=wildcards, max_test=1)
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] mpls_label = 0xa5f05 # no specific meaning mpls_tc = 5 mpls_ttl = 129 pkt = testutils.simple_tcp_packet_w_mpls(mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl) match_ls = parse.packet_to_flow_match(pkt) wildcards = 0 new_mpls_label = 0x5a0fa exp_pkt = testutils.simple_tcp_packet_w_mpls( mpls_label_ext=new_mpls_label, mpls_tc_ext=mpls_tc, mpls_ttl_ext=mpls_ttl, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl) # Create parameters for each table act_list = [] next_avail = [] chk_expire = [] #Table 0 act = action.action_output() act.port = egr_port act_list.append([act]) next_avail.append(True) chk_expire.append(False) #Table 1 #act = action.action_set_mpls_label() #act.mpls_label = new_mpls_label act = action.action_set_field() act.field = match.mpls_label(new_mpls_label) act_list.append([act]) next_avail.append(True) chk_expire.append(False) #Table 2 act = action.action_push_mpls() act.ethertype = ETHERTYPE_MPLS act_list.append([act]) next_avail.append(False) chk_expire.append(False) write_action_test_multi_tables(self, ing_port, egr_port, match_fields = match_ls, wildcards = wildcards, act_list = act_list, next_avail = next_avail, chk_expire = chk_expire, pkt = pkt, exp_pkt = exp_pkt)
def mpls_multipush2_act_tests(parent, test_condition=0): """ Test mpls push and set actions for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)), "Parameter num_tags not within an acceptable range") sup_mpls_act = mpls_action_support_check(parent) if sup_mpls_act.has_key('sup_push_mpls') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. PUSH not supported") return if sup_mpls_act.has_key('sup_set_mpls_label') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. SET_LABEL not supported") return if sup_mpls_act.has_key('sup_set_mpls_tc') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. SET_TC not supported") return if sup_mpls_act.has_key('sup_set_mpls_ttl') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. SET_TTL not supported") return if sup_mpls_act.has_key('sup_dec_mpls_ttl') == False: testutils.skip_message_emit(parent, "MPLS multipush action test. DEC_TTL not supported") return act = action.action_push_mpls() act.ethertype = 0x8847 if test_condition == 0: #act2 = action.action_set_mpls_label() #act2.mpls_label = parent.label + 2 act2 = action.action_set_field() act2.field = match.mpls_label(parent.label + 2) exp_label = parent.label + 2 if parent.num_tags == 0: exp_tc = 0 exp_ttl = parent.ip_ttl else: exp_tc = parent.tc exp_ttl = parent.ttl elif test_condition == 1: #act2 = action.action_set_mpls_tc() #act2.mpls_tc = parent.tc + 2 #exp_tc = act2.mpls_tc act2 = action.action_set_field() act2.field = match.mpls_tc(parent.tc + 2) exp_tc = parent.tc + 2 if parent.num_tags == 0: exp_label = 0 exp_ttl = parent.ip_ttl else: exp_label = parent.label exp_ttl = parent.ttl elif test_condition == 2: act2 = action.action_set_mpls_ttl() act2.mpls_ttl = parent.ttl + 2 exp_ttl = act2.mpls_ttl if parent.num_tags == 0: exp_label = 0 exp_tc = 0 else: exp_label = parent.label exp_tc = parent.tc elif test_condition == 3: act2 = action.action_dec_mpls_ttl() if parent.num_tags == 0: exp_ttl = parent.ip_ttl - 1 exp_label = 0 exp_tc = 0 else: exp_ttl = parent.ttl - 1 exp_label = parent.label exp_tc = parent.tc else: return match_exp = True add_tag_exp = parent.num_tags > 0 exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED action_list=[act, act2] testutils.flow_match_test_mpls(parent, pa_port_map, wildcards=0, mpls_label=parent.label, mpls_tc=parent.tc, mpls_label_int=parent.label_int, mpls_tc_int=parent.tc_int, label_match=parent.label_match, tc_match=parent.tc_match, dl_type_match=parent.dl_type_match, exp_mpls_label=exp_label, exp_mpls_tc=exp_tc, exp_mpls_ttl=exp_ttl, match_exp=match_exp, add_tag_exp=add_tag_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[2] table_id1 = testutils.EX_L3_TABLE table_id2 = testutils.WC_ALL_TABLE # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") rv = testutils.set_table_config(self, table_id=table_id1) self.assertEqual(rv, 0, "Failed to set table config") # Add entry match pkt = testutils.simple_ipv6_packet(ip_dst='fe80::1:0:1234') pkt_metadata = { 'metadata_val': 0xabcdef0123456789, 'metadata_msk': 0xffffffffffffffff } inst_ls1 = [] inst1_write = instruction.instruction_write_metadata() inst1_write.metadata = pkt_metadata['metadata_val'] inst1_write.metadata_mask = pkt_metadata['metadata_msk'] inst1_goto = instruction.instruction_goto_table() inst1_goto.table_id = table_id2 inst_ls1.append(inst1_write) inst_ls1.append(inst1_goto) request1 = testutils.flow_msg_create(self, pkt, ing_port=ing_port, instruction_list=inst_ls1, table_id=table_id1) testutils.flow_msg_install(self, request1) act_ls2 = [] act2_setfld = action.action_set_field() act2_setfld.field = match.ipv6_dst( ipaddr.IPv6Address('fe80::1:6554:3e7f:1')) act2_out = action.action_output() act2_out.port = egr_port act_ls2.append(act2_setfld) act_ls2.append(act2_out) pkt_metadata = { 'metadata_val': 0xabcdef0100000000, 'metadata_msk': 0xffffffff00000000 } request2 = testutils.flow_msg_create(self, pkt, pkt_metadata, ing_port, action_list=act_ls2, table_id=table_id2) testutils.flow_msg_install(self, request2) #Send packet ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::1:6554:3e7f:1') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src( ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) field_2b_set = match.ipv6_dst( ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD')) act_setfield = action.action_set_field() act_setfield.field = field_2b_set # TODO: insert action set field properly act_out = action.action_output() act_out.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act_setfield) inst.actions.add(act_out) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") #Send packet pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189', ip_dst='fe80::2420:52ff:fe8f:5190') ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet( ip_dst='fe80::2420:52ff:fe8f:DDDD') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def novlan_push_two_tables_tests(parent): """ @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ wildcards = 0 vid = -1 pcp = 0 vid_int = -1 pcp_int = 0 exp_vid = random.randint(1, 4094) exp_pcp = random.randint(0, 6) # Match condition on TBL0 (match) vid_match_tbl0 = ofp.OFPVID_NONE pcp_match_tbl0 = 0 # Create action_list for TBL0 action_list_tbl0 = [] act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN action_list_tbl0.append(act) #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) #act = action.action_set_vlan_pcp() #act.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act = action.action_set_field() act.field = vlan_pcp action_list_tbl0.append(act) # create action_list for tbl1 vid_match_tbl1 = exp_vid pcp_match_tbl1 = exp_pcp # output action for table1 will be set in the framework action_list_tbl1 = None flow_match_test_vlan_two_tables(parent, pa_port_map, dl_vlan=vid, dl_vlan_pcp=pcp, dl_vlan_int=vid_int, dl_vlan_pcp_int=pcp_int, vid_match_tbl0=vid_match_tbl0, pcp_match_tbl0=pcp_match_tbl0, action_list_tbl0 = action_list_tbl0, match_exp_tbl0 = True, vid_match_tbl1=vid_match_tbl1, pcp_match_tbl1=pcp_match_tbl1, action_list_tbl1 = action_list_tbl1, match_exp_tbl1 = True, exp_vid=exp_vid, exp_pcp=exp_pcp, add_tag_exp=True, wildcards=wildcards, max_test=1)
def vlan_singlepush_act_tests(parent, test_condition=0): """ Test vlan push action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param test_condition Value between 0 and 2 """ parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)), "Parameter num_tags not within an acceptable range") #print("parent vid="+str(parent.vid)) #print("parent pcp="+str(parent.pcp)) (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True) # vlan_action_support_check(parent) if sup_push_vlan == False: testutils.skip_message_emit( parent, "Vlan single push action test. SET VLAN VID not supported") return if test_condition == 0: act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN match_exp = True add_tag_exp = True if parent.num_tags == 0: exp_vid = 1 exp_pcp = 0 vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = 1 else: exp_vid = parent.vid exp_pcp = parent.pcp vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = parent.vid exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 1: act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN_PBB match_exp = True add_tag_exp = True if parent.num_tags == 0: exp_vid = 1 exp_pcp = 0 vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = 1 else: exp_vid = parent.vid exp_pcp = parent.pcp vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = parent.vid # parent.vid_2nd = parent.vid # parent.pcp_2nd = parent.pcp exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 2: act = action.action_push_vlan() act.ethertype = 0xaaa #Other than 0x8100 and 0x88a8 match_exp = False add_tag_exp = False exp_vid = 1 exp_pcp = 0 vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = 1 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT else: return #NOTE need to set a VLAN vid value, as vid=0 is stripped by the system action_list = [act, act2] wildcards = 0 if parent.num_tags == 0: wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_VID wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_PCP testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=wildcards, dl_vlan=parent.vid, dl_vlan_pcp=parent.pcp, dl_vlan_type=parent.vlan_type, dl_vlan_int=parent.vid_2nd, dl_vlan_pcp_int=parent.pcp_2nd, vid_match=parent.vid_match, pcp_match=parent.pcp_match, exp_vid=exp_vid, exp_pcp=exp_pcp, exp_vlan_type=act.ethertype, match_exp=match_exp, add_tag_exp=add_tag_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def vlan_push_two_tables_tests(parent, test_condition=0, match_exp = True): """ @param parent must implement controller, dataplane, asserttrue, assertequal and logger """ wildcards = 0 vid = random.randint(1, 4094) pcp = random.randint(0, 6) vid_int = -1 pcp_int = 0 if (test_condition == 0): exp_vid = vid exp_pcp = pcp elif (test_condition == 1): exp_vid = vid + 1 exp_pcp = pcp elif (test_condition == 2): exp_vid = vid exp_pcp = pcp + 1 elif (test_condition == 3): exp_vid = vid + 1 exp_pcp = pcp + 1 else: return # match condition on tbl0 (match) vid_match_tbl0 = vid pcp_match_tbl0 = pcp # create action_list for tbl0 action_list_tbl0 = [] act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN action_list_tbl0.append(act) if (match_exp): # push-only for test0 if (test_condition == 1): #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) elif (test_condition == 2): #act = action.action_set_vlan_pcp() #act.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act = action.action_set_field() act.field = vlan_pcp action_list_tbl0.append(act) elif (test_condition == 3): #act = action.action_set_vlan_vid() #act.vlan_vid = exp_vid vlan_vid = match.vlan_vid(exp_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) #act = action.action_set_vlan_pcp() #act.vlan_pcp = exp_pcp vlan_pcp = match.vlan_pcp(exp_pcp) act = action.action_set_field() act.field = vlan_pcp action_list_tbl0.append(act) else: if (test_condition == 0): #act = action.action_set_vlan_vid() #act.vlan_vid = vid + 1 vlan_vid = match.vlan_vid(vid + 1 + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid action_list_tbl0.append(act) # Create action_list for TBL1 vid_match_tbl1 = exp_vid pcp_match_tbl1 = exp_pcp # Output action for table1 will be set in the framework action_list_tbl1 = None flow_match_test_vlan_two_tables(parent, pa_port_map, dl_vlan=vid, dl_vlan_pcp=pcp, dl_vlan_int=vid_int, dl_vlan_pcp_int=pcp_int, vid_match_tbl0=vid_match_tbl0, pcp_match_tbl0=pcp_match_tbl0, action_list_tbl0 = action_list_tbl0, match_exp_tbl0 = True, vid_match_tbl1=vid_match_tbl1, pcp_match_tbl1=pcp_match_tbl1, action_list_tbl1 = action_list_tbl1, match_exp_tbl1 = match_exp, exp_vid=exp_vid, exp_pcp=exp_pcp, add_tag_exp=True, wildcards=wildcards, max_test=1)
def mpls_multipush2_act_tests(parent, test_condition=0): """ Test mpls push and set actions for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)), "Parameter num_tags not within an acceptable range") sup_mpls_act = mpls_action_support_check(parent) if sup_mpls_act.has_key('sup_push_mpls') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. PUSH not supported") return if sup_mpls_act.has_key('sup_set_mpls_label') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. SET_LABEL not supported") return if sup_mpls_act.has_key('sup_set_mpls_tc') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. SET_TC not supported") return if sup_mpls_act.has_key('sup_set_mpls_ttl') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. SET_TTL not supported") return if sup_mpls_act.has_key('sup_dec_mpls_ttl') == False: testutils.skip_message_emit( parent, "MPLS multipush action test. DEC_TTL not supported") return act = action.action_push_mpls() act.ethertype = 0x8847 if test_condition == 0: #act2 = action.action_set_mpls_label() #act2.mpls_label = parent.label + 2 act2 = action.action_set_field() act2.field = match.mpls_label(parent.label + 2) exp_label = parent.label + 2 if parent.num_tags == 0: exp_tc = 0 exp_ttl = parent.ip_ttl else: exp_tc = parent.tc exp_ttl = parent.ttl elif test_condition == 1: #act2 = action.action_set_mpls_tc() #act2.mpls_tc = parent.tc + 2 #exp_tc = act2.mpls_tc act2 = action.action_set_field() act2.field = match.mpls_tc(parent.tc + 2) exp_tc = parent.tc + 2 if parent.num_tags == 0: exp_label = 0 exp_ttl = parent.ip_ttl else: exp_label = parent.label exp_ttl = parent.ttl elif test_condition == 2: act2 = action.action_set_mpls_ttl() act2.mpls_ttl = parent.ttl + 2 exp_ttl = act2.mpls_ttl if parent.num_tags == 0: exp_label = 0 exp_tc = 0 else: exp_label = parent.label exp_tc = parent.tc elif test_condition == 3: act2 = action.action_dec_mpls_ttl() if parent.num_tags == 0: exp_ttl = parent.ip_ttl - 1 exp_label = 0 exp_tc = 0 else: exp_ttl = parent.ttl - 1 exp_label = parent.label exp_tc = parent.tc else: return match_exp = True add_tag_exp = parent.num_tags > 0 exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED action_list = [act, act2] testutils.flow_match_test_mpls(parent, pa_port_map, wildcards=0, mpls_label=parent.label, mpls_tc=parent.tc, mpls_label_int=parent.label_int, mpls_tc_int=parent.tc_int, label_match=parent.label_match, tc_match=parent.tc_match, dl_type_match=parent.dl_type_match, exp_mpls_label=exp_label, exp_mpls_tc=exp_tc, exp_mpls_ttl=exp_ttl, match_exp=match_exp, add_tag_exp=add_tag_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def vlan_set_act_tests(parent, test_condition=0): """ Test vlan set_vid and set_pcp action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param test_condition Value between 0 and 3 """ parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)), "Parameter num_tags not within an acceptable range") (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True) # vlan_action_support_check(parent) new_vid = parent.vid + 2; new_pcp = parent.pcp + 2; #print(str(new_vid)) #print(str(new_pcp)) if sup_set_vlan_vid == False: testutils.skip_message_emit(parent, "Vlan set action test. SET VLAN VID not supported") return if sup_set_vlan_pcp == False: testutils.skip_message_emit(parent, "Vlan set action test. SET VLAN PCP not supported") return exp_vlan_type = parent.vlan_type if test_condition == 0: vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid #act = action.action_set_vlan_vid() #act.vlan_vid = new_vid if parent.num_tags == 0: match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT else: match_exp = True exp_vid = new_vid exp_pcp = parent.pcp exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 1: vlan_vid = match.vlan_vid(4096 + ofp.OFPVID_PRESENT) act = action.action_set_field() act.field = vlan_vid #act = action.action_set_vlan_vid() #act.vlan_vid = 4096 match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT elif test_condition == 2: #act = action.action_set_vlan_pcp() #act.vlan_pcp = new_pcp vlan_pcp = match.vlan_pcp(new_pcp) act = action.action_set_field() act.field = vlan_pcp if parent.num_tags == 0: match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT else: match_exp = True exp_vid = parent.vid exp_pcp = new_pcp exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 3: #act = action.action_set_vlan_pcp() #act.vlan_pcp = 8 #OUT OF RANGE vlan_pcp = match.vlan_pcp(8) #OUT OF RANGE act = action.action_set_field() act.field = vlan_pcp match_exp = False exp_vid = -1 exp_pcp = 0 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT else: return action_list=[act] wildcards = 0 if parent.num_tags == 0: wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_VID wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_PCP testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=wildcards, dl_vlan=parent.vid, dl_vlan_pcp=parent.pcp, dl_vlan_type=parent.vlan_type, dl_vlan_int=parent.vid_2nd, dl_vlan_pcp_int=parent.pcp_2nd, vid_match=parent.vid_match, pcp_match=parent.pcp_match, exp_vid=exp_vid, exp_pcp=exp_pcp, exp_vlan_type=exp_vlan_type, match_exp=match_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def mpls_set_tc_act_tests(parent, test_condition=0): """ Test mpls set_tc action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)), "Parameter num_tags not within an acceptable range") sup_mpls_act = mpls_action_support_check(parent) if sup_mpls_act.has_key('sup_set_mpls_tc') == False: testutils.skip_message_emit( parent, "MPLS set_tc action test. SET_TC not supported") return #act = action.action_set_mpls_tc() act = action.action_set_field() exp_label = parent.label exp_ttl = parent.ttl if test_condition == 0: #act.mpls_tc = parent.tc + 2 act.field = match.mpls_tc(parent.tc + 2) if parent.num_tags == 0: match_exp = False exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT exp_tc = parent.tc else: match_exp = True exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED exp_tc = parent.tc + 2 action_list = [act] elif test_condition == 1: #act.mpls_tc = 8 act.field = match.mpls_tc(8) match_exp = False if parent.num_tags == 0: exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT exp_tc = parent.tc else: exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT exp_tc = 8 action_list = [act] else: return testutils.flow_match_test_mpls(parent, pa_port_map, wildcards=0, mpls_label=parent.label, mpls_tc=parent.tc, mpls_ttl=parent.ttl, mpls_label_int=parent.label_int, mpls_tc_int=parent.tc_int, mpls_ttl_int=parent.ttl_int, ip_ttl=parent.ip_ttl, label_match=parent.label_match, tc_match=parent.tc_match, dl_type_match=parent.dl_type_match, exp_mpls_label=exp_label, exp_mpls_tc=exp_tc, exp_mpls_ttl=exp_ttl, match_exp=match_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def vlan_singlepush_act_tests(parent, test_condition=0): """ Test vlan push action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param test_condition Value between 0 and 2 """ parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)), "Parameter num_tags not within an acceptable range") #print("parent vid="+str(parent.vid)) #print("parent pcp="+str(parent.pcp)) (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True) # vlan_action_support_check(parent) if sup_push_vlan == False: testutils.skip_message_emit(parent, "Vlan single push action test. SET VLAN VID not supported") return if test_condition == 0: act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN match_exp = True add_tag_exp = True if parent.num_tags == 0: exp_vid = 1 exp_pcp = 0 vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = 1 else: exp_vid = parent.vid exp_pcp = parent.pcp vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = parent.vid exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 1: act = action.action_push_vlan() act.ethertype = ETHERTYPE_VLAN_PBB match_exp = True add_tag_exp = True if parent.num_tags == 0: exp_vid = 1 exp_pcp = 0 vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = 1 else: exp_vid = parent.vid exp_pcp = parent.pcp vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = parent.vid # parent.vid_2nd = parent.vid # parent.pcp_2nd = parent.pcp exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED elif test_condition == 2: act = action.action_push_vlan() act.ethertype = 0xaaa #Other than 0x8100 and 0x88a8 match_exp = False add_tag_exp = False exp_vid = 1 exp_pcp = 0 vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT) act2 = action.action_set_field() act2.field = vlan_vid #act2 = action.action_set_vlan_vid() #act2.vlan_vid = 1 exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT else: return #NOTE need to set a VLAN vid value, as vid=0 is stripped by the system action_list=[act, act2] wildcards = 0 if parent.num_tags == 0: wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_VID wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_PCP testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=wildcards, dl_vlan=parent.vid, dl_vlan_pcp=parent.pcp, dl_vlan_type=parent.vlan_type, dl_vlan_int=parent.vid_2nd, dl_vlan_pcp_int=parent.pcp_2nd, vid_match=parent.vid_match, pcp_match=parent.pcp_match, exp_vid=exp_vid, exp_pcp=exp_pcp, exp_vlan_type=act.ethertype, match_exp=match_exp, add_tag_exp=add_tag_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)
def runTest(self): """ Add flow entries: First Table; Match IP Src A; set ToS = tos1, goto Second Table First Table; Match IP Src B; set ToS = tos2, goto Second Table Second Table; Match IP Src A; send to 1 Second Table; Match IP Src B; send to 1 Then send packets: IP A; expect port 1 with DSCP = dscp1 IP B; expect port 1 with DSCP = dscp2 @param self object instance @param EX_ACL_TABLE first table @param WC_ACL_TABLE second table @param dscp1 DSCP value to be set for first flow @param dscp2 DSCP value to be set for second flow """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up flow match in table A: set ToS #t_act = action.action_set_nw_tos() #t_act.nw_tos = tos1 dscp1 = 4 dscp2 = 8 t_act = action.action_set_field() t_act.field = match.ip_dscp(dscp1) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.10') t_act.field = match.ip_dscp(dscp2) #t_act.field = match.ip_ecn(3) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.30', clear_tag=False) # Set up flow matches in table B: routing testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.10") testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.30") # Generate packets and check them exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=1234, ip_dscp=dscp1) testutils.reply_check_dp(self, ip_src='192.168.1.10', tcp_sport=1234, exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])
def mpls_set_tc_act_tests(parent, test_condition=0): """ Test mpls set_tc action for the packets with/without tags @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)), "Parameter num_tags not within an acceptable range") sup_mpls_act = mpls_action_support_check(parent) if sup_mpls_act.has_key('sup_set_mpls_tc') == False: testutils.skip_message_emit(parent, "MPLS set_tc action test. SET_TC not supported") return #act = action.action_set_mpls_tc() act = action.action_set_field() exp_label = parent.label exp_ttl = parent.ttl if test_condition == 0: #act.mpls_tc = parent.tc + 2 act.field = match.mpls_tc(parent.tc + 2) if parent.num_tags == 0: match_exp = False exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT exp_tc = parent.tc else: match_exp = True exp_msg = ofp.OFPT_FLOW_REMOVED exp_msg_type = 0 #NOT_EXPECTED exp_msg_code = 0 #NOT_EXPECTED exp_tc = parent.tc + 2 action_list=[act] elif test_condition == 1: #act.mpls_tc = 8 act.field = match.mpls_tc(8) match_exp = False if parent.num_tags == 0: exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT exp_tc = parent.tc else: exp_msg = ofp.OFPT_ERROR exp_msg_type = ofp.OFPET_BAD_ACTION exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT exp_tc = 8 action_list=[act] else: return testutils.flow_match_test_mpls(parent, pa_port_map, wildcards=0, mpls_label=parent.label, mpls_tc=parent.tc, mpls_ttl=parent.ttl, mpls_label_int=parent.label_int, mpls_tc_int=parent.tc_int, mpls_ttl_int=parent.ttl_int, ip_ttl=parent.ip_ttl, label_match=parent.label_match, tc_match=parent.tc_match, dl_type_match=parent.dl_type_match, exp_mpls_label=exp_label, exp_mpls_tc=exp_tc, exp_mpls_ttl=exp_ttl, match_exp=match_exp, exp_msg=exp_msg, exp_msg_type=exp_msg_type, exp_msg_code=exp_msg_code, action_list=action_list, max_test=1)