def runTest(self): logging = get_logger() logging.info("Running Grp70No150 Vlan_Prio_2 test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test") logging.info("Insert a flow with action -- set vlan priority ") logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten") #Verify set_vlan_priority is a supported action sup_acts = sw_supported_actions(self,"true") if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): skip_message_emit(self, "modify_vlan_prio test skipped") return #Create a tagged packet , and an expected packet with vlan_priority set to specified value vid = 123 old_vlan_pcp = 2 new_vlan_pcp = 3 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) vid_act = action.action_set_vlan_pcp() vid_act.vlan_pcp = new_vlan_pcp #Insert flow with action -- set vLAN priority, Send tagged packet matching the flow, Verify recieved packet is expected packet flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, action_list=[vid_act])
def runTest(self): logging = get_logger() logging.info("Running vlan_Prio_1 test") of_ports = config["port_map"].keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #Clear switch state rv = delete_all_flows(self.controller) self.assertEqual(rv, 0, "Failed to delete all flows") logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test") logging.info("Insert a flow with action -- set vlan priority ") logging.info("Send untagged packet matching the flow , verify recieved packet has specified VLAN priority and has vid set tO 0 ") #Verify set_vlan_priority is a supported action sup_acts = sw_supported_actions(self) if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): skip_message_emit(self, "Set VLAN priority test skipped") return #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set. vlan_id = 0 vlan_pcp = 1 pkt = simple_tcp_packet(pktlen=60) exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=vlan_pcp, pktlen=64) act = action.action_set_vlan_pcp() act.vlan_pcp = vlan_pcp #Insert flow with action -- set vLAN priority, Send packet matching the flow, Verify recieved packet is expected packet flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, action_list=[act])
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(0, 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 action_list_tbl0.append(act) act = action.action_set_vlan_pcp() act.vlan_pcp = exp_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_set_two_tables_tests(parent, test_condition=0): """ @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ wildcards = 0 vid = random.randint(0, 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 act2 = action.action_set_vlan_pcp() act2.vlan_pcp = exp_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(0, 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 action_list_tbl0.append(act) act = action.action_set_vlan_pcp() act.vlan_pcp = exp_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_set_two_tables_tests(parent, test_condition=0): """ @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger """ wildcards = 0 vid = random.randint(0, 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 act2 = action.action_set_vlan_pcp() act2.vlan_pcp = exp_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 action_generate(parent, field_to_mod, mod_field_vals): """ Create an action to modify the field indicated in field_to_mod @param parent Must implement, assertTrue @param field_to_mod The field to modify as a string name @param mod_field_vals Hash of values to use for modified values """ act = None if field_to_mod in ['pktlen']: return None if field_to_mod == 'dl_dst': act = action.action_set_dl_dst() act.dl_addr = parse.parse_mac(mod_field_vals['dl_dst']) elif field_to_mod == 'dl_src': act = action.action_set_dl_src() act.dl_addr = parse.parse_mac(mod_field_vals['dl_src']) elif field_to_mod == 'dl_vlan_enable': if not mod_field_vals['dl_vlan_enable']: # Strip VLAN tag act = action.action_strip_vlan() # Add VLAN tag is handled by dl_vlan field # Will return None in this case elif field_to_mod == 'dl_vlan': act = action.action_set_vlan_vid() act.vlan_vid = mod_field_vals['dl_vlan'] elif field_to_mod == 'dl_vlan_pcp': act = action.action_set_vlan_pcp() act.vlan_pcp = mod_field_vals['dl_vlan_pcp'] elif field_to_mod == 'ip_src': act = action.action_set_nw_src() act.nw_addr = parse.parse_ip(mod_field_vals['ip_src']) elif field_to_mod == 'ip_dst': act = action.action_set_nw_dst() act.nw_addr = parse.parse_ip(mod_field_vals['ip_dst']) elif field_to_mod == 'ip_tos': act = action.action_set_nw_tos() act.nw_tos = mod_field_vals['ip_tos'] elif field_to_mod == 'tcp_sport': act = action.action_set_tp_src() act.tp_port = mod_field_vals['tcp_sport'] elif field_to_mod == 'tcp_dport': act = action.action_set_tp_dst() act.tp_port = mod_field_vals['tcp_dport'] elif field_to_mod == 'udp_sport': act = action.action_set_tp_src() act.tp_port = mod_field_vals['udp_sport'] elif field_to_mod == 'udp_dport': act = action.action_set_tp_dst() act.tp_port = mod_field_vals['udp_dport'] else: parent.assertTrue(0, "Unknown field to modify: " + str(field_to_mod)) return act
def action_generate(parent, field_to_mod, mod_field_vals): """ Create an action to modify the field indicated in field_to_mod @param parent Must implement, assertTrue @param field_to_mod The field to modify as a string name @param mod_field_vals Hash of values to use for modified values """ act = None if field_to_mod in ['pktlen']: return None if field_to_mod == 'dl_dst': act = action.action_set_dl_dst() act.dl_addr = parse.parse_mac(mod_field_vals['dl_dst']) elif field_to_mod == 'dl_src': act = action.action_set_dl_src() act.dl_addr = parse.parse_mac(mod_field_vals['dl_src']) elif field_to_mod == 'dl_vlan_enable': if not mod_field_vals['dl_vlan_enable']: # Strip VLAN tag act = action.action_strip_vlan() # Add VLAN tag is handled by dl_vlan field # Will return None in this case elif field_to_mod == 'dl_vlan': act = action.action_set_vlan_vid() act.vlan_vid = mod_field_vals['dl_vlan'] elif field_to_mod == 'dl_vlan_pcp': act = action.action_set_vlan_pcp() act.vlan_pcp = mod_field_vals['dl_vlan_pcp'] elif field_to_mod == 'ip_src': act = action.action_set_nw_src() act.nw_addr = parse.parse_ip(mod_field_vals['ip_src']) elif field_to_mod == 'ip_dst': act = action.action_set_nw_dst() act.nw_addr = parse.parse_ip(mod_field_vals['ip_dst']) elif field_to_mod == 'ip_tos': act = action.action_set_nw_tos() act.nw_tos = mod_field_vals['ip_tos'] elif field_to_mod == 'tcp_sport': act = action.action_set_tp_src() act.tp_port = mod_field_vals['tcp_sport'] elif field_to_mod == 'tcp_dport': act = action.action_set_tp_dst() act.tp_port = mod_field_vals['tcp_dport'] else: parent.assertTrue(0, "Unknown field to modify: " + str(field_to_mod)) return act
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(0, 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 else: # test_condition == 3 exp_vid = vid + 1 exp_pcp = pcp + 1 # 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 action_list_tbl0.append(act) elif (test_condition == 2): act = action.action_set_vlan_pcp() act.vlan_pcp = exp_pcp action_list_tbl0.append(act) elif (test_condition == 3): act = action.action_set_vlan_vid() act.vlan_vid = exp_vid action_list_tbl0.append(act) act = action.action_set_vlan_pcp() act.vlan_pcp = exp_pcp action_list_tbl0.append(act) else: if (test_condition == 0): act = action.action_set_vlan_vid() act.vlan_vid = vid + 1 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 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) = \ 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 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: 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 add_tag_exp = True exp_pcp = new_pcp exp_vlan_type = act.ethertype if parent.num_tags == 0: exp_vid = 0 else: exp_vid = parent.vid elif test_condition == 2: act2 = action.action_set_vlan_vid() act2.vlan_vid = new_vid act3 = action.action_set_vlan_pcp() act3.vlan_pcp = new_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 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) testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=0, 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, 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) = \ vlan_action_support_check(parent) new_vid = parent.vid + 2 new_pcp = parent.pcp + 2 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: 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: act = action.action_set_vlan_vid() act.vlan_vid = 4096 #OUT OF RANGE 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_ARGUMENT elif test_condition == 2: act = action.action_set_vlan_pcp() act.vlan_pcp = new_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 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_ARGUMENT else: return action_list = [act] testutils.flow_match_test_vlan(parent, pa_port_map, wildcards=0, 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 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) = 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 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: 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 add_tag_exp = True exp_pcp = new_pcp exp_vlan_type = act.ethertype if parent.num_tags == 0: exp_vid = 0 else: exp_vid = parent.vid elif test_condition == 2: act2 = action.action_set_vlan_vid() act2.vlan_vid = new_vid act3 = action.action_set_vlan_pcp() act3.vlan_pcp = new_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 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) testutils.flow_match_test_vlan( parent, pa_port_map, wildcards=0, 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, 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) = vlan_action_support_check(parent) new_vid = parent.vid + 2 new_pcp = parent.pcp + 2 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: 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: act = action.action_set_vlan_vid() act.vlan_vid = 4096 # OUT OF RANGE 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_ARGUMENT elif test_condition == 2: act = action.action_set_vlan_pcp() act.vlan_pcp = new_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 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_ARGUMENT else: return action_list = [act] testutils.flow_match_test_vlan( parent, pa_port_map, wildcards=0, 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 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(0, 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 else: # test_condition == 3 exp_vid = vid + 1 exp_pcp = pcp + 1 # 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 action_list_tbl0.append(act) elif (test_condition == 2): act = action.action_set_vlan_pcp() act.vlan_pcp = exp_pcp action_list_tbl0.append(act) elif (test_condition == 3): act = action.action_set_vlan_vid() act.vlan_vid = exp_vid action_list_tbl0.append(act) act = action.action_set_vlan_pcp() act.vlan_pcp = exp_pcp action_list_tbl0.append(act) else: if (test_condition == 0): act = action.action_set_vlan_vid() act.vlan_vid = vid + 1 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)