def exact_table_goto_table(parent=None, first_table=0, second_table=1, match_ls=None, actions=[]): """ exact table goto table """ if parent == None or match_ls == None: print("parent == None or match_ls == None") return if first_table >= second_table: print("first_table >= second_table") return request = message.flow_mod() request.table_id = first_table request.command = ofp.OFPFC_ADD request.match_fields = match_ls if (len(actions) != 0): inst = instruction.instruction_write_actions() inst.actions = actions request.instructions.add(inst) inst_goto = instruction.instruction_goto_table() inst_goto.table_id = second_table request.instructions.add(inst_goto) testutils.ofmsg_send(parent, request)
def scenario3(self, first_table = 0, second_table = 1, third_table = 2): """ Add three flow entries: First Table; Match IP Src A; send to 0 now, goto Second Table Second Table; Match IP Src A; send to 1 now, goto Third Table Third Table; Match IP src A; send to 2 now Then send a packet: IP A; expect out port 0, 1, and 2 @param self object instance @param first_table first table @param second_table second table @param third_table third table """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up matches inst = instruction.instruction_goto_table() inst.table_id = second_table self.set_apply_output(first_table, of_ports[0], inst) # Set up second match inst.table_id = third_table self.set_apply_output(second_table, of_ports[1], inst) # Set up third match self.set_apply_output(third_table, of_ports[2]) # Generate a packet and receive 3 responses pkt = testutils.simple_tcp_packet(ip_src=MT_TEST_IP, tcp_sport=10) self.dataplane.send(of_ports[3], str(pkt)) testutils.receive_pkt_verify(self, of_ports[0], pkt) testutils.receive_pkt_verify(self, of_ports[1], pkt) testutils.receive_pkt_verify(self, of_ports[2], pkt)
def exact_table_goto_table(parent = None, first_table = 0, second_table = 1, match_ls = None, actions = []): """ exact table goto table """ if parent == None or match_ls == None: print("parent == None or match_ls == None") return if first_table >= second_table : print( "first_table >= second_table") return request = message.flow_mod() request.table_id = first_table request.command = ofp.OFPFC_ADD request.match_fields = match_ls if(len(actions) != 0): inst = instruction.instruction_write_actions(); inst.actions = actions request.instructions.add(inst) inst_goto = instruction.instruction_goto_table(); inst_goto.table_id = second_table request.instructions.add(inst_goto) testutils.ofmsg_send(parent,request)
def scenario3(self, first_table=0, second_table=1, third_table=2): """ Add three flow entries: First Table; Match IP Src A; send to 0 now, goto Second Table Second Table; Match IP Src A; send to 1 now, goto Third Table Third Table; Match IP src A; send to 2 now Then send a packet: IP A; expect out port 0, 1, and 2 @param self object instance @param first_table first table @param second_table second table @param third_table third table """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up matches inst = instruction.instruction_goto_table() inst.table_id = second_table self.set_apply_output(first_table, of_ports[0], inst) # Set up second match inst.table_id = third_table self.set_apply_output(second_table, of_ports[1], inst) # Set up third match self.set_apply_output(third_table, of_ports[2]) # Generate a packet and receive 3 responses pkt = testutils.simple_tcp_packet(ip_src=MT_TEST_IP, tcp_sport=10) self.dataplane.send(of_ports[3], str(pkt)) testutils.receive_pkt_verify(self, of_ports[0], pkt) testutils.receive_pkt_verify(self, of_ports[1], pkt) testutils.receive_pkt_verify(self, of_ports[2], pkt)
def runTest(self): of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] check_expire_tbl0 = False check_expire_tbl1 = False # Build the ingress packet pkt = testutils.simple_tcp_packet(**self.base_pkt_params) # Set action for the first table for item_tbl0 in self.start_pkt_params: tbl0_pkt_params = self.base_pkt_params.copy() tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0] act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params) action_list = [act] inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(self, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list, check_expire=check_expire_tbl0, table_id=0) exp_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params) request1 = testutils.flow_msg_create(self, exp_pkt, ing_port=ing_port, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) # Insert two flows self.logger.debug("Inserting flows: Modify-field: " + item_tbl0) testutils.flow_msg_install(self, request0) testutils.flow_msg_install(self, request1) # Send pkt self.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) self.dataplane.send(ing_port, str(pkt)) #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if check_expire_tbl0: flow_removed_verify(self, request0, pkt_count=1, byte_count=pktlen) if check_expire_tbl1: flow_removed_verify(self, request1, pkt_count=1, byte_count=exp_pktlen) # Receive and verify pkt testutils.receive_pkt_verify(self, egr_port, exp_pkt)
def runTest(self): # instructions header is 8 bytes l = instruction_list() act = action.action_output() act.port = 7 inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act)) self.assertTrue(l.add(inst)) pkt = l.pack() # 24 == 8 (list header) + (apply header) 8 + (output action) 8 self.assertEqual(len(pkt), 24) l = instruction_list() self.assertTrue(l.add(instruction.instruction_goto_table()))
def runTest(self): # instructions header is 8 bytes l = instruction_list() act = action.action_output() act.port = 7 inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act)) self.assertTrue(l.add(inst)) pkt = l.pack() # 24 == 8 (list header) + (apply header) 8 + (output action) 8 self.assertEqual(len(pkt),24) l = instruction_list() self.assertTrue(l.add(instruction.instruction_goto_table()))
def write_goto(parent, set_id, next_id, ip_src=MT_TEST_IP, add_inst=None): """ Make flow_mod of Goto table instruction """ request = message.flow_mod() request.match = make_match(ip_src=ip_src) request.buffer_id = 0xffffffff request.table_id = set_id if add_inst is not None: parent.assertTrue(request.instructions.add(add_inst), "Can't add inst") inst = instruction.instruction_goto_table() inst.table_id = next_id parent.assertTrue(request.instructions.add(inst), "Can't add inst") pa_logger.info("Inserting flow") rv = parent.controller.message_send(request) parent.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(parent.controller)
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 flow_match_test_port_pair_vlan_two_tables( parent, ing_port, egr_port, wildcards=0, dl_vlan=-1, dl_vlan_pcp=0, dl_vlan_type=ETHERTYPE_VLAN, dl_vlan_int=-1, dl_vlan_pcp_int=0, vid_match_tbl0=ofp.OFPVID_NONE, pcp_match_tbl0=0, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, vid_match_tbl1=ofp.OFPVID_NONE, pcp_match_tbl1=0, action_list_tbl1=None, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, exp_vid=-1, exp_pcp=0, exp_vlan_type=ETHERTYPE_VLAN, add_tag_exp=False, pkt=None, exp_pkt=None): """ Flow match test for various vlan matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " vlan: " + str(dl_vlan) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) len = 100 len_w_vid = len + 4 if pkt is None: if dl_vlan >= 0: if dl_vlan_int >= 0: pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) pkt.push_vlan(dl_vlan_type) pkt.set_vlan_vid(dl_vlan) pkt.set_vlan_pcp(dl_vlan_pcp) else: pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=dl_vlan_type, dl_vlan=dl_vlan, dl_vlan_pcp=dl_vlan_pcp) else: pkt = testutils.simple_tcp_packet(pktlen=len, dl_vlan_enable=False) if exp_pkt is None: if exp_vid >= 0: if add_tag_exp: if dl_vlan >= 0: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) exp_pkt.push_vlan(dl_vlan_type) exp_pkt.set_vlan_vid(dl_vlan) exp_pkt.set_vlan_pcp(dl_vlan_pcp) else: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=dl_vlan_type, dl_vlan=dl_vlan, dl_vlan_pcp=dl_vlan_pcp) #Push one more tag in either case exp_pkt.push_vlan(exp_vlan_type) exp_pkt.set_vlan_vid(exp_vid) exp_pkt.set_vlan_pcp(exp_pcp) else: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=exp_vlan_type, dl_vlan=exp_vid, dl_vlan_pcp=exp_pcp) else: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) exp_pkt.push_vlan(exp_vlan_type) exp_pkt.set_vlan_vid(exp_vid) exp_pkt.set_vlan_pcp(exp_pcp) else: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=exp_vlan_type, dl_vlan=exp_vid, dl_vlan_pcp=exp_pcp) else: #subtract action if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) else: exp_pkt = testutils.simple_tcp_packet(pktlen=len, dl_vlan_enable=False) match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.wildcards = wildcards # Flow Mod for Table0 match.dl_vlan = vid_match_tbl0 match.dl_vlan_pcp = pcp_match_tbl0 inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, match=match, check_expire=check_expire_tbl0, table_id=0) testutils.flow_msg_install(parent, request0) # Flow Mod for Table1 match.dl_vlan = vid_match_tbl1 match.dl_vlan_pcp = pcp_match_tbl1 request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, action_list=action_list_tbl1, wildcards=wildcards, match=match, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) if match_exp_tbl0: if check_expire_tbl0: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request0, pkt_count=1, byte_count=pktlen) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request1, pkt_count=1, byte_count=exp_pktlen) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
def runTest(self): of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] check_expire_tbl0 = False check_expire_tbl1 = False # Build the ingress packet pkt = testutils.simple_tcp_packet(**self.base_pkt_params) # Set action for the first table for item_tbl0 in self.start_pkt_params: tbl0_pkt_params = self.base_pkt_params.copy() tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0] act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params) action_list = [act] inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create( self, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list, check_expire=check_expire_tbl0, table_id=0) mod_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params) for item_tbl1 in self.start_pkt_params: if item_tbl1 == item_tbl0: continue tbl1_pkt_params = tbl0_pkt_params.copy() tbl1_pkt_params[item_tbl1] = self.mod_pkt_params[item_tbl1] act = testutils.action_generate(self, item_tbl1, tbl1_pkt_params) self.assertTrue(act is not None, "Action not available") action_list = [act] request1 = testutils.flow_msg_create( self, mod_pkt, ing_port=ing_port, action_list=action_list, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) exp_pkt = testutils.simple_tcp_packet(**tbl1_pkt_params) # Insert two flows self.logger.debug("Inserting flows: Modify-fields: TBL0= " + item_tbl0 + ", TBL1= " + item_tbl1) testutils.flow_msg_install(self, request0) testutils.flow_msg_install(self, request1) # Send pkt self.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) self.dataplane.send(ing_port, str(pkt)) #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if check_expire_tbl0: flow_removed_verify(self, request0, pkt_count=1, byte_count=pktlen) if check_expire_tbl1: flow_removed_verify(self, request1, pkt_count=1, byte_count=exp_pktlen) # Receive and verify pkt testutils.receive_pkt_verify(self, egr_port, exp_pkt)
def runTest(self): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 2, "Not enough ports for test") # Clear flow table rv = testutils.initialize_table_config(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to initialize table config") rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") # Set up first match match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.nw_src_mask = 0 # Match nw_src match.dl_type = 0x800 match.nw_src = parse.parse_ip("192.168.1.10") act = action.action_output() act.port = of_ports[0] request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff request.table_id = 0 inst = instruction.instruction_write_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(request.instructions.add(inst), "Could not add inst1") inst = instruction.instruction_goto_table() inst.table_id = 1 self.assertTrue(request.instructions.add(inst), "Could not add inst2") pa_logger.info("Inserting flow 1") rv = self.controller.message_send(request) # pa_logger.debug(request.show()) self.assertTrue(rv != -1, "Error installing flow mod") # Set up second match match = ofp.ofp_match() match.length = ofp.OFPMT_STANDARD_LENGTH testutils.wildcard_all_set(match) match.wildcards -= ofp.OFPFW_DL_TYPE match.wildcards -= ofp.OFPFW_TP_SRC match.dl_type = 0x800 match.nw_proto = 6 # TCP match.tp_src = 80 act = action.action_output() act.port = of_ports[1] request = message.flow_mod() request.match = match request.buffer_id = 0xffffffff request.table_id = 1 inst = instruction.instruction_write_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(request.instructions.add(inst), "Could not add inst3") pa_logger.info("Inserting flow 2") # pa_logger.debug(request.show()) rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller) # Generate a packet matching only flow 1; rcv on port[0] pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=10) self.dataplane.send(of_ports[2], str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, of_ports[0], "Unexpected receive port") # Generate a packet matching both flow 1 and flow 2; rcv on port[1] pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=80) self.dataplane.send(of_ports[2], str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")
def flow_match_test_port_pair_vlan_two_tables( parent, ing_port, egr_port, wildcards=0, dl_vlan=-1, dl_vlan_pcp=0, dl_vlan_type=ETHERTYPE_VLAN, dl_vlan_int=-1, dl_vlan_pcp_int=0, vid_match_tbl0=ofp.OFPVID_NONE, pcp_match_tbl0=0, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, vid_match_tbl1=ofp.OFPVID_NONE, pcp_match_tbl1=0, action_list_tbl1=None, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, exp_vid=-1, exp_pcp=0, exp_vlan_type=ETHERTYPE_VLAN, add_tag_exp=False, pkt=None, exp_pkt=None): """ Flow match test for various vlan matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " vlan: " + str(dl_vlan) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) if pkt is None: if dl_vlan > 0: if dl_vlan_int > 0: pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp }, { 'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int }]) else: pkt = testutils.simple_tcp_packet(vlan_tags=[{ 'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp }]) else: pkt = testutils.simple_tcp_packet() if exp_pkt is None: if exp_vid > 0: if add_tag_exp: if dl_vlan > 0: if dl_vlan_int > 0: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp }, { 'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int }]) else: #Push one more tag in either case exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp }, { 'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp }]) else: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp }]) else: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp }, { 'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int }]) else: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp }]) else: #subtract action if dl_vlan_int > 0: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{ 'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int }]) else: exp_pkt = testutils.simple_tcp_packet() table_id0 = testutils.EX_ACL_TABLE if dl_vlan > 0: table_id0 = testutils.EX_VLAN_TABLE testutils.delete_all_flows(parent.controller, parent.logger) if table_id0 != testutils.EX_ACL_TABLE: testutils.set_table_config(parent, table_id0) match_ls = testutils.packet_to_exact_flow_match(pkt, None, table_id0, ing_port) parent.assertTrue(match_ls is not None, "Flow match from pkt failed") #match.wildcards = wildcards # Flow Mod for Table0 inst = instruction.instruction_goto_table() if table_id0 == testutils.EX_ACL_TABLE: table_id1 = testutils.EX_VLAN_TABLE else: table_id1 = testutils.WC_ALL_TABLE inst.table_id = table_id1 inst_list = [inst] request0 = testutils.flow_msg_create( parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, egr_port=ofp.OFPP_LOCAL, match_fields=match_ls, check_expire=check_expire_tbl0, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION, table_id=table_id0) testutils.flow_msg_install(parent, request0) if exp_msg_tbl0 is not ofp.OFPT_ERROR: response, _ = parent.controller.poll(ofp.OFPT_ERROR, 1) if response is not None: parent.assertTrue( response is None, "Rcv: Unexpected Error Message: type " + str(response.type) + ", code " + str(response.code)) # Flow Mod for Table1 pkt1 = testutils.simple_tcp_packet(vlan_tags=[{ 'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp }]) match_ls1 = testutils.packet_to_exact_flow_match(pkt1, None, table_id1, ing_port) for i in range(len(match_ls1.items)): if match_ls1.items[i].field == ofp.OFPXMT_OFB_VLAN_VID: if vid_match_tbl1 > ofp.OFPVID_NONE: match_ls1.items[i].value = vid_match_tbl1 + ofp.OFPVID_PRESENT break else: del match_ls1.items[i] break for i in range(len(match_ls1.items)): if match_ls1.items[i].field == ofp.OFPXMT_OFB_VLAN_PCP: if vid_match_tbl1 > ofp.OFPVID_NONE: match_ls1.items[i].value = pcp_match_tbl1 break else: del match_ls1.items[i] break request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, action_list=action_list_tbl1, wildcards=wildcards, match_fields=match_ls1, check_expire=check_expire_tbl1, table_id=table_id1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) if exp_msg_tbl1 is not ofp.OFPT_ERROR: response, _ = parent.controller.poll(ofp.OFPT_ERROR, 1) if response is not None: parent.assertTrue( response is None, "Rcv: Unexpected Error Message: type " + str(response.type) + ", code " + str(response.code)) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) if match_exp_tbl0: if check_expire_tbl0: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request0, pkt_count=1, byte_count=len(exp_pkt)) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request1, pkt_count=1, byte_count=len(exp_pkt)) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
def flow_match_test_port_pair_mpls_two_tables(parent, ing_port, egr_port, wildcards=0, mpls_type=ETHERTYPE_MPLS, mpls_label=-1, mpls_tc=0, mpls_ttl=64, mpls_label_int=-1, mpls_tc_int=0, mpls_ttl_int=32, ip_ttl=192, label_match_tbl0=0, tc_match_tbl0=0, dl_type_match_tbl0=ETHERTYPE_MPLS, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, label_match_tbl1=0, tc_match_tbl1=0, dl_type_match_tbl1=ETHERTYPE_MPLS, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, add_tag_exp=False, exp_mpls_type=ETHERTYPE_MPLS, exp_mpls_label=-1, exp_mpls_tc=0, exp_mpls_ttl=64, exp_mpls_ttl_int=32, exp_ip_ttl=192, pkt=None, exp_pkt=None): """ Flow match test for various mpls matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " mpls label: " + str(mpls_label) + " mpls tc: " + str(mpls_tc) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) # Check if the switch supports all the MPLS actions sup_act_dic = mplsact.mpls_action_support_check(parent) sup_act_elm = sup_act_dic.keys() for i in sup_act_elm: if sup_act_dic[i] == False: testutils.skip_message_emit(parent, "Switch doesn't support " + "one or more of MPLS actions : " + i) return pkt = testutils.simple_tcp_packet_w_mpls( mpls_type=mpls_type, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl, mpls_label_int=mpls_label_int, mpls_tc_int=mpls_tc_int, mpls_ttl_int=mpls_ttl_int, ip_ttl=ip_ttl) if exp_pkt is None: if add_tag_exp: exp_pkt = testutils.simple_tcp_packet_w_mpls( mpls_type=exp_mpls_type, mpls_label_ext=exp_mpls_label, mpls_tc_ext=exp_mpls_tc, mpls_ttl_ext=exp_mpls_ttl, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl, mpls_label_int=mpls_label_int, mpls_tc_int=mpls_tc_int, mpls_ttl_int=exp_mpls_ttl_int, ip_ttl=exp_ip_ttl) else: if (exp_mpls_label < 0) and (mpls_label_int >= 0): exp_pkt = testutils.simple_tcp_packet_w_mpls( mpls_type=mpls_type, mpls_label=mpls_label_int, mpls_tc=mpls_tc_int, mpls_ttl=exp_mpls_ttl_int, ip_ttl=exp_ip_ttl) else: exp_pkt = testutils.simple_tcp_packet_w_mpls( mpls_type=exp_mpls_type, mpls_label=exp_mpls_label, mpls_tc=exp_mpls_tc, mpls_ttl=exp_mpls_ttl, mpls_label_int=mpls_label_int, mpls_tc_int=mpls_tc_int, mpls_ttl_int=exp_mpls_ttl_int, ip_ttl=exp_ip_ttl) # Flow Mod for Table0 match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.mpls_label = label_match_tbl0 match.mpls_tc = tc_match_tbl0 match.dl_type = dl_type_match_tbl0 if ((dl_type_match_tbl0 == ETHERTYPE_MPLS) or (dl_type_match_tbl0 == ETHERTYPE_MPLS_MC)): match.nw_tos = 0 match.nw_proto = 0 match.nw_src = 0 match.nw_src_mask = 0 match.nw_dst = 0 match.nw_dst_mask = 0 match.tp_src = 0 match.tp_dst = 0 inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, match=match, check_expire=check_expire_tbl0, table_id=0) testutils.flow_msg_install(parent, request0) # Flow Mod for Table1 match = parse.packet_to_flow_match(exp_pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.mpls_label = label_match_tbl1 match.mpls_tc = tc_match_tbl1 match.dl_type = dl_type_match_tbl1 if ((dl_type_match_tbl1 == ETHERTYPE_MPLS) or (dl_type_match_tbl1 == ETHERTYPE_MPLS_MC)): match.nw_tos = 0 match.nw_proto = 0 match.nw_src = 0 match.nw_src_mask = 0 match.nw_dst = 0 match.nw_dst_mask = 0 match.tp_src = 0 match.tp_dst = 0 request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, wildcards=wildcards, match=match, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) # Check response from switch #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if match_exp_tbl0: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=1, byte_count=pktlen) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=1, byte_count=exp_pktlen) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) # Check pkt if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
def flow_match_test_port_pair_vlan_two_tables(parent, ing_port, egr_port, wildcards=0, dl_vlan=-1, dl_vlan_pcp=0, dl_vlan_type=ETHERTYPE_VLAN, dl_vlan_int=-1, dl_vlan_pcp_int=0, vid_match_tbl0=ofp.OFPVID_NONE, pcp_match_tbl0=0, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, vid_match_tbl1=ofp.OFPVID_NONE, pcp_match_tbl1=0, action_list_tbl1=None, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, exp_vid=-1, exp_pcp=0, exp_vlan_type=ETHERTYPE_VLAN, add_tag_exp=False, pkt=None, exp_pkt=None): """ Flow match test for various vlan matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " vlan: " + str(dl_vlan) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) if pkt is None: if dl_vlan > 0: if dl_vlan_int > 0: pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp}, {'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int}]) else: pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp}]) else: pkt = testutils.simple_tcp_packet() if exp_pkt is None: if exp_vid > 0: if add_tag_exp: if dl_vlan > 0: if dl_vlan_int > 0: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp}, {'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int}]) else: #Push one more tag in either case exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp}, {'type': dl_vlan_type, 'vid': dl_vlan, 'pcp': dl_vlan_pcp}]) else: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp}]) else: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp}, {'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int}]) else: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp}]) else: #subtract action if dl_vlan_int > 0: exp_pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': dl_vlan_type, 'vid': dl_vlan_int, 'pcp': dl_vlan_pcp_int}]) else: exp_pkt = testutils.simple_tcp_packet() table_id0 = testutils.EX_ACL_TABLE if dl_vlan > 0: table_id0 = testutils.EX_VLAN_TABLE testutils.delete_all_flows(parent.controller,parent.logger) if table_id0 != testutils.EX_ACL_TABLE: testutils.set_table_config(parent,table_id0) match_ls = testutils.packet_to_exact_flow_match(pkt,None,table_id0,ing_port) parent.assertTrue(match_ls is not None, "Flow match from pkt failed") #match.wildcards = wildcards # Flow Mod for Table0 inst = instruction.instruction_goto_table() if table_id0 == testutils.EX_ACL_TABLE: table_id1 = testutils.EX_VLAN_TABLE else: table_id1 = testutils.WC_ALL_TABLE inst.table_id = table_id1 inst_list = [inst] request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, egr_port = ofp.OFPP_LOCAL, match_fields=match_ls, check_expire=check_expire_tbl0, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION, table_id=table_id0) testutils.flow_msg_install(parent, request0) if exp_msg_tbl0 is not ofp.OFPT_ERROR: response,_ = parent.controller.poll(ofp.OFPT_ERROR, 1) if response is not None: parent.assertTrue(response is None, "Rcv: Unexpected Error Message: type " + str(response.type) + ", code " + str(response.code)) # Flow Mod for Table1 pkt1 = testutils.simple_tcp_packet( vlan_tags=[{'type': exp_vlan_type, 'vid': exp_vid, 'pcp': exp_pcp}]) match_ls1 = testutils.packet_to_exact_flow_match(pkt1,None,table_id1,ing_port) for i in range(len(match_ls1.items)): if match_ls1.items[i].field == ofp.OFPXMT_OFB_VLAN_VID: if vid_match_tbl1 > ofp.OFPVID_NONE: match_ls1.items[i].value = vid_match_tbl1 + ofp.OFPVID_PRESENT break else: del match_ls1.items[i] break for i in range(len(match_ls1.items)): if match_ls1.items[i].field == ofp.OFPXMT_OFB_VLAN_PCP: if vid_match_tbl1 > ofp.OFPVID_NONE: match_ls1.items[i].value = pcp_match_tbl1 break else: del match_ls1.items[i] break request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, action_list=action_list_tbl1, wildcards=wildcards, match_fields=match_ls1, check_expire=check_expire_tbl1, table_id=table_id1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) if exp_msg_tbl1 is not ofp.OFPT_ERROR: response,_ = parent.controller.poll(ofp.OFPT_ERROR, 1) if response is not None: parent.assertTrue(response is None, "Rcv: Unexpected Error Message: type " + str(response.type) + ", code " + str(response.code)) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) if match_exp_tbl0: if check_expire_tbl0: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request0, pkt_count=1, byte_count=len(exp_pkt)) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request1, pkt_count=1, byte_count=len(exp_pkt)) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
def flow_match_test_port_pair_vlan_two_tables(parent, ing_port, egr_port, wildcards=0, dl_vlan=-1, dl_vlan_pcp=0, dl_vlan_type=ETHERTYPE_VLAN, dl_vlan_int=-1, dl_vlan_pcp_int=0, vid_match_tbl0=ofp.OFPVID_NONE, pcp_match_tbl0=0, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, vid_match_tbl1=ofp.OFPVID_NONE, pcp_match_tbl1=0, action_list_tbl1=None, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, exp_vid=-1, exp_pcp=0, exp_vlan_type=ETHERTYPE_VLAN, add_tag_exp=False, pkt=None, exp_pkt=None): """ Flow match test for various vlan matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " vlan: " + str(dl_vlan) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) len = 100 len_w_vid = len + 4 if pkt is None: if dl_vlan >= 0: if dl_vlan_int >= 0: pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) pkt.push_vlan(dl_vlan_type) pkt.set_vlan_vid(dl_vlan) pkt.set_vlan_pcp(dl_vlan_pcp) else: pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=dl_vlan_type, dl_vlan=dl_vlan, dl_vlan_pcp=dl_vlan_pcp) else: pkt = testutils.simple_tcp_packet(pktlen=len, dl_vlan_enable=False) if exp_pkt is None: if exp_vid >= 0: if add_tag_exp: if dl_vlan >= 0: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) exp_pkt.push_vlan(dl_vlan_type) exp_pkt.set_vlan_vid(dl_vlan) exp_pkt.set_vlan_pcp(dl_vlan_pcp) else: exp_pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=dl_vlan_type, dl_vlan=dl_vlan, dl_vlan_pcp=dl_vlan_pcp) #Push one more tag in either case exp_pkt.push_vlan(exp_vlan_type) exp_pkt.set_vlan_vid(exp_vid) exp_pkt.set_vlan_pcp(exp_pcp) else: exp_pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=exp_vlan_type, dl_vlan=exp_vid, dl_vlan_pcp=exp_pcp) else: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) exp_pkt.push_vlan(exp_vlan_type) exp_pkt.set_vlan_vid(exp_vid) exp_pkt.set_vlan_pcp(exp_pcp) else: exp_pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=exp_vlan_type, dl_vlan=exp_vid, dl_vlan_pcp=exp_pcp) else: #subtract action if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) else: exp_pkt = testutils.simple_tcp_packet(pktlen=len, dl_vlan_enable=False) match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.wildcards = wildcards # Flow Mod for Table0 match.dl_vlan = vid_match_tbl0 match.dl_vlan_pcp = pcp_match_tbl0 inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, match=match, check_expire=check_expire_tbl0, table_id=0) testutils.flow_msg_install(parent, request0) # Flow Mod for Table1 match.dl_vlan = vid_match_tbl1 match.dl_vlan_pcp = pcp_match_tbl1 request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, action_list=action_list_tbl1, wildcards=wildcards, match=match, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) if match_exp_tbl0: if check_expire_tbl0: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request0, pkt_count=1, byte_count=pktlen) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request1, pkt_count=1, byte_count=exp_pktlen) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
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 flow_match_test_port_pair_mpls_two_tables( parent, ing_port, egr_port, wildcards=0, mpls_type=ETHERTYPE_MPLS, mpls_label=-1, mpls_tc=0, mpls_ttl=64, mpls_label_int=-1, mpls_tc_int=0, mpls_ttl_int=32, ip_ttl=192, label_match_tbl0=0, tc_match_tbl0=0, dl_type_match_tbl0=ETHERTYPE_MPLS, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, label_match_tbl1=0, tc_match_tbl1=0, dl_type_match_tbl1=ETHERTYPE_MPLS, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, add_tag_exp=False, exp_mpls_type=ETHERTYPE_MPLS, exp_mpls_label=-1, exp_mpls_tc=0, exp_mpls_ttl=64, exp_mpls_ttl_int=32, exp_ip_ttl=192, pkt=None, exp_pkt=None): """ Flow match test for various mpls matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " mpls label: " + str(mpls_label) + " mpls tc: " + str(mpls_tc) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) # Check if the switch supports all the MPLS actions sup_act_dic = mplsact.mpls_action_support_check(parent) sup_act_elm = sup_act_dic.keys() for i in sup_act_elm: if sup_act_dic[i] == False: testutils.skip_message_emit( parent, "Switch doesn't support " + "one or more of MPLS actions : " + i) return len = 100 len_w_shim = len + 4 len_w_2shim = len_w_shim + 4 len_w_3shim = len_w_2shim + 4 if pkt is None: if mpls_label >= 0: if mpls_label_int >= 0: pktlen = len_w_2shim else: pktlen = len_w_shim else: pktlen = len pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen, mpls_type=mpls_type, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl, mpls_label_int=mpls_label_int, mpls_tc_int=mpls_tc_int, mpls_ttl_int=mpls_ttl_int, ip_ttl=ip_ttl) if exp_pkt is None: if exp_mpls_label >= 0: if add_tag_exp: if mpls_label_int >= 0: exp_pktlen = len_w_3shim else: exp_pktlen = len_w_2shim else: if mpls_label_int >= 0: exp_pktlen = len_w_2shim else: exp_pktlen = len_w_shim else: #subtract action if mpls_label_int >= 0: exp_pktlen = len_w_shim else: exp_pktlen = len if add_tag_exp: exp_pkt = testutils.simple_tcp_packet_w_mpls( pktlen=exp_pktlen, mpls_type=exp_mpls_type, mpls_label_ext=exp_mpls_label, mpls_tc_ext=exp_mpls_tc, mpls_ttl_ext=exp_mpls_ttl, mpls_label=mpls_label, mpls_tc=mpls_tc, mpls_ttl=mpls_ttl, mpls_label_int=mpls_label_int, mpls_tc_int=mpls_tc_int, mpls_ttl_int=exp_mpls_ttl_int, ip_ttl=exp_ip_ttl) else: if (exp_mpls_label < 0) and (mpls_label_int >= 0): exp_pkt = testutils.simple_tcp_packet_w_mpls( pktlen=exp_pktlen, mpls_type=mpls_type, mpls_label=mpls_label_int, mpls_tc=mpls_tc_int, mpls_ttl=exp_mpls_ttl_int, ip_ttl=exp_ip_ttl) else: exp_pkt = testutils.simple_tcp_packet_w_mpls( pktlen=exp_pktlen, mpls_type=exp_mpls_type, mpls_label=exp_mpls_label, mpls_tc=exp_mpls_tc, mpls_ttl=exp_mpls_ttl, mpls_label_int=mpls_label_int, mpls_tc_int=mpls_tc_int, mpls_ttl_int=exp_mpls_ttl_int, ip_ttl=exp_ip_ttl) # Flow Mod for Table0 match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.mpls_label = label_match_tbl0 match.mpls_tc = tc_match_tbl0 match.dl_type = dl_type_match_tbl0 if ((dl_type_match_tbl0 == ETHERTYPE_MPLS) or (dl_type_match_tbl0 == ETHERTYPE_MPLS_MC)): match.nw_tos = 0 match.nw_proto = 0 match.nw_src = 0 match.nw_src_mask = 0 match.nw_dst = 0 match.nw_dst_mask = 0 match.tp_src = 0 match.tp_dst = 0 inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, match=match, check_expire=check_expire_tbl0, table_id=0) testutils.flow_msg_install(parent, request0) # Flow Mod for Table1 match = parse.packet_to_flow_match(exp_pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.mpls_label = label_match_tbl1 match.mpls_tc = tc_match_tbl1 match.dl_type = dl_type_match_tbl1 if ((dl_type_match_tbl1 == ETHERTYPE_MPLS) or (dl_type_match_tbl1 == ETHERTYPE_MPLS_MC)): match.nw_tos = 0 match.nw_proto = 0 match.nw_src = 0 match.nw_src_mask = 0 match.nw_dst = 0 match.nw_dst_mask = 0 match.tp_src = 0 match.tp_dst = 0 request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, wildcards=wildcards, match=match, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) # Check response from switch #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if match_exp_tbl0: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=1, byte_count=pktlen) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=1, byte_count=exp_pktlen) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) # Check pkt if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
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 write_action_test_multi_tables(parent, ing_port, egr_port, match = None, wildcards = 0, act_list = None, next_avail = None, chk_expire = None, pkt = None, exp_pkt = None): """ Testing framework for write_action tests with multiple tables @param parent Must implement controller, dataplane, assertTrue, assertEqual and logger @param ing_port Ingress OF port @param egr_port Egress OF port @match Match field in flow_mod commans for all the tables @param wildcard Match.wildcard filed in flow_mod commands for all the tables @param act_list Array of action list for each table @param next_avail Array. Indicate False for no more tables are used @param chk_expire Array. Indicate True if you want flow_removed msg @param pkt Pkt to be sent @param exp_pkt Expected pkt """ parent.assertTrue(match is not None, "Match param doesn't exist") parent.assertTrue(act_list is not None, "act_list param doesn't exist") parent.assertTrue(next_avail is not None, "next_avail param doesn't exist") parent.assertTrue(chk_expire is not None, "chk_expire param doesn't exist") wildcards = wildcards & 0xfffffffff # mask out anything out of range request_list = [] for table_id in range(MAX_TABLE): inst_list = [] inst = instruction.instruction_write_actions() inst_list.append(inst) action_list = act_list[table_id] check_expire = chk_expire[table_id] if next_avail[table_id]: inst = instruction.instruction_goto_table() inst.table_id = table_id + 1 inst_list.append(inst) else: pass request = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list, wildcards=wildcards, match=match, check_expire=check_expire, table_id=table_id) request_list.append(request) testutils.flow_msg_install(parent, request_list[table_id]) if next_avail[table_id]: pass else: num_table_used = table_id + 1 break parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) # Check response from switch #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. for table_id in range(num_table_used): if chk_expire[table_id]: flow_removed_verify(parent, request_list[table_id], pkt_count=1, byte_count=pktlen) testutils.receive_pkt_verify(parent, egr_port, exp_pkt)
def runTest(self): #testutils.skip_message_emit(self, 'action type set tc not support') #return of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] check_expire_tbl0 = False check_expire_tbl1 = False # Build the ingress packet pkt = testutils.simple_tcp_packet(**self.base_pkt_params) #print(pkt.show()) # Set action for the first table for item_tbl0 in self.start_pkt_params: tbl0_pkt_params = self.base_pkt_params.copy() tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0] act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params) action_list = [act] inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create( self, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list, check_expire=check_expire_tbl0, table_id=0, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) exp_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params) request1 = testutils.flow_msg_create( self, exp_pkt, ing_port=ing_port, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port, inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION) #print(request0.show()) #print(request1.show()) # Insert two flows self.logger.debug("Inserting flows: Modify-field: " + item_tbl0) testutils.flow_msg_install(self, request0) testutils.flow_msg_install(self, request1) # Send pkt self.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) self.dataplane.send(ing_port, str(pkt)) #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if check_expire_tbl0: flow_removed_verify(self, request0, pkt_count=1, byte_count=len(pkt)) if check_expire_tbl1: flow_removed_verify(self, request1, pkt_count=1, byte_count=len(exp_pkt))