def runTest(self): of_ports = testutils.clear_switch(self, exact_port_map.keys(), exact_logger) #zhaoxiuchu table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[1] pkt = testutils.simple_tcp_packet(dl_src='08:02:03:04:88:99', dl_dst='22:22:22:22:22:22') pkt_metadata = { 'metadata_val': 0xad22332e6f667588, 'metadata_msk': 0xFFFFFFFFFFFFFFFF } request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port=egr_port, table_id=table_id) request.hard_timeout = 1 request.flags |= ofp.OFPFF_SEND_FLOW_REM testutils.flow_msg_install(self, request) #print(request.show()) (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 3) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie, 'Cookies do not match') self.assertEqual( ofp.OFPRR_HARD_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout')
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22', dl_dst='22:22:22:22:22:22') pkt_metadata = {'metadata_val':0x1122334455667788, 'metadata_msk':0xFFFFFFFFFFFFFFFF} request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port, table_id = table_id) testutils.flow_msg_install(self, request) #"delete it" request_del = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port, table_id = table_id) request_del.command = ofp.OFPFC_DELETE testutils.ofmsg_send(self, request_del) #'read it back , returns blank;' stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats)))
def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[2] table_id = testutils.WC_L3_TABLE # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, self.logger) self.assertEqual(rc, 0, "Failed to delete all flows") rv = testutils.set_table_config(self, table_id) self.assertEqual(rv, 0, "Failed to set table config") # Add entry match pkt = testutils.simple_ipv6_packet() request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id=table_id) testutils.flow_msg_install(self, request) #Send packet self.logger.info("Sending IPv6 packet to " + str(ing_port)) self.logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet testutils.receive_pkt_verify(self, egr_port, pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, self.logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[len(of_ports) - 1] pkt = testutils.simple_tcp_packet(dl_src='00:22:44:62:9b:1c', dl_dst='00:13:07:5f:61:ab') pkt_metadata = { 'metadata_val': 0xaa22334455667788, 'metadata_msk': 0xFFFFFFFFFFFFFFFF } request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port=egr_port, table_id=table_id) request.hard_timeout = 8 request.idle_timeout = 8 testutils.flow_msg_install(self, request) #"get flow stats" stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) self.assertTrue(isinstance(response, message.flow_stats_reply), "Not a flow_stats_reply") self.assertEqual(len(response.stats), 1, "len of stats is:" + str(len(response.stats)))
def runTest(self): # Config of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[2] table_id = testutils.WC_ACL_TABLE # Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id=table_id) testutils.flow_msg_install(self, request) #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(tcp_sport=80, tcp_dport=8080) testutils.receive_pkt_verify(self, egr_port, exp_pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def handleFlow(self, pkttype='TCP'): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") if (pkttype == 'ICMP'): pkt = testutils.simple_icmp_packet() table_id = testutils.EX_ICMP_TABLE else: pkt = testutils.simple_tcp_packet() table_id = testutils.WC_ACL_TABLE for idx in range(len(of_ports)): rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") testutils.set_table_config(self, table_id, ofp.OFPTC_TABLE_MISS_CONTINUE) ingress_port = of_ports[idx] egress_port = of_ports[(idx + 1) % len(of_ports)] pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) #controller send flow mod to switch request = testutils.flow_msg_create(self,pkt, ing_port=ingress_port, egr_port=egress_port, table_id=table_id) testutils.flow_msg_install(self, request) #user send pkt to switch pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) testutils.receive_pkt_verify(self, egress_port, pkt)
def runTest(self): """ ** Currently, same scenario with "NoGoto" ** 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; do nothing // match but stop pipeline Fourth Table; Match IP Src A; send to 2 // not match, just a fake Then send in 2 packets: IP A, TCP C; expect out port 1 IP A, TCP B; expect out port 1 """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up first match testutils.write_goto(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE) # Set up second match testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, of_ports[0], of_ports[2]) # Set up third match, "Empty Instruction" pkt = testutils.simple_tcp_packet() request = testutils.flow_msg_create(self, pkt, ing_port = of_ports[2], table_id = testutils.EX_L2_TABLE) testutils.flow_msg_install(self, request) # Set up fourth match testutils.write_output(self, testutils.EX_VLAN_TABLE, of_ports[1]) # Generate a packet matching flow 1, 2, and 3; rcv on port[0] testutils.reply_check_dp(self, tcp_sport=1234, ing_port = of_ports[2], egr_port = of_ports[0])
def runTest(self): # Config of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[2] table_id = testutils.WC_ACL_TABLE # Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port, table_id = table_id) testutils.flow_msg_install(self, request) #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(tcp_sport=80, tcp_dport=8080) testutils.receive_pkt_verify(self, egr_port, exp_pkt) #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[2] table_id = testutils.WC_L3_TABLE # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, self.logger) self.assertEqual(rc, 0, "Failed to delete all flows") rv = testutils.set_table_config(self, table_id) self.assertEqual(rv, 0, "Failed to set table config") # Add entry match pkt = testutils.simple_ipv6_packet() request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port, table_id = table_id) testutils.flow_msg_install(self, request) #Send packet self.logger.info("Sending IPv6 packet to " + str(ing_port)) self.logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet testutils.receive_pkt_verify(self, egr_port, pkt) #Remove flows rc = testutils.delete_all_flows(self.controller, self.logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def handleFlow(self, pkttype='TCP'): of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") if (pkttype == 'ICMP'): pkt = testutils.simple_icmp_packet() table_id = testutils.EX_ICMP_TABLE else: pkt = testutils.simple_tcp_packet() table_id = testutils.WC_ACL_TABLE for idx in range(len(of_ports)): rv = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rv, 0, "Failed to delete all flows") testutils.set_table_config(self, table_id, ofp.OFPTC_TABLE_MISS_CONTINUE) ingress_port = of_ports[idx] egress_port = of_ports[(idx + 1) % len(of_ports)] pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) #controller send flow mod to switch request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=table_id) testutils.flow_msg_install(self, request) #user send pkt to switch pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) testutils.receive_pkt_verify(self, egress_port, pkt)
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port1 = of_ports[len(of_ports)-1] egr_port2 = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='99:33:11:11:11:55', dl_dst='33:33:11:11:77:66') pkt_metadata = {'metadata_val':0x99999999, 'metadata_msk':0xFFFFFFFFFFFFFFFF} request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port1, table_id = table_id) testutils.flow_msg_install(self, request) #"mod it ,add outport 1" request_mod = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port2, table_id = table_id) request_mod.command = ofp.OFPFC_MODIFY testutils.ofmsg_send(self, request_mod) #print(flow_mod.show()) #"read it back;" stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) #print(response.show()) self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats))) self.assertEqual(response.stats[0].instructions.items[0].actions.items[0].port, request_mod.instructions.items[0].actions.items[0].port, "action error:"+str(response.stats[0].instructions.items[0].actions.items[0].port))
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[1] pkt = testutils.simple_tcp_packet(dl_src='08:02:ff:34:88:99', dl_dst='22:22:ed:22:5f:1a') request = testutils.flow_msg_create(self, pkt, egr_port=egr_port, table_id=table_id) for obj in request.match_fields.tlvs: if obj.field == ofp.OFPXMT_OFB_METADATA: obj.value = 0x9922334455667788 request.idle_timeout = 1 request.flags |= ofp.OFPFF_SEND_FLOW_REM testutils.flow_msg_install(self, request) #print(request.show()) (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 3) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie, 'Cookies do not match') self.assertEqual( ofp.OFPRR_IDLE_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout')
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): ing_port = flow_mods_port_map.keys()[0] egr_port = flow_mods_port_map.keys()[1] table_id = testutils.EX_L3_TABLE flow_count = 10 testutils.delete_all_flows_one_table(self.controller, self.logger, table_id) match_fields_ls = [] ipv6_src_addr = 'fe80::2420:52ff:fe8f:5188' metadata_val = 0xaa22334455667788 for i in range(flow_count): match_fields_ls.append(match_list()) match_fields_ls[i].add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields_ls[i].add( match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) ipv6_dst_addr = 'fe80::2420:52ff:fe8f:' + str(5190 + i) match_fields_ls[i].add( match.ipv6_dst(ipaddr.IPv6Address(ipv6_dst_addr))) match_fields_ls[i].add(match.metadata(metadata_val)) request = testutils.flow_msg_create( self, None, ing_port=ing_port, match_fields=match_fields_ls[i], egr_port=egr_port, table_id=table_id) testutils.flow_msg_install(self, request, False) match_fields = match_list() match_fields.add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields.add(match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) response = testutils.flow_stats_get(self, table_id=table_id) self.assertTrue( len(response.stats) == flow_count, 'Did not add all flows successfully! Get table entry num is %d' % len(response.stats)) request = testutils.flow_msg_create(self, None, None, ing_port, match_fields, table_id=table_id) request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request, False) response = testutils.flow_stats_get(self, table_id=table_id) self.assertTrue( len(response.stats) == 0, 'Switch did not del the flow entry! Current table entry num is %d' % len(response.stats))
def runTest(self): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") ingress_port = of_ports[0] egress_port = of_ports[1] rc = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #controller send flow_mod to switch pkt = testutils.simple_tcp_packet() flow_mod_add = testutils.flow_msg_create( self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=testutils.EX_ACL_TABLE) testutils.flow_msg_install(self, flow_mod_add) #user send pkt to switch, switch transfer to eng_port pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(egress_port, timeout=2) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, egress_port, "Unexpected receive port") self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') #check the stats msg stat_req = message.flow_stats_request() stat_req.match_fields = flow_mod_add.match_fields stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY pa_logger.info("Sending stats request") testutils.ofmsg_send(self, stat_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) self.assertTrue(response, "No Flow_stats reply") #print "YYY: Stats reply is \n%s" % (response.show()) self.assertEqual(len(response.stats), 1, "Did not receive flow stats reply") self.assertEqual(response.stats[0].packet_count, 1) self.assertEqual(response.stats[0].byte_count, len(rcv_pkt))
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port1 = of_ports[len(of_ports) - 1] egr_port2 = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='99:33:11:11:11:55', dl_dst='33:33:11:11:77:66') pkt_metadata = { 'metadata_val': 0x99999999, 'metadata_msk': 0xFFFFFFFFFFFFFFFF } request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port=egr_port1, table_id=table_id) testutils.flow_msg_install(self, request) #"mod it ,add outport 1" request_mod = testutils.flow_msg_create( self, pkt, match_fields=request.match_fields, egr_port=egr_port2, table_id=table_id) request_mod.command = ofp.OFPFC_MODIFY testutils.ofmsg_send(self, request_mod) #print(flow_mod.show()) #"read it back;" stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) #print(response.show()) self.assertTrue(isinstance(response, message.flow_stats_reply), "Not a flow_stats_reply") self.assertEqual(len(response.stats), 1, "len of stats is:" + str(len(response.stats))) self.assertEqual( response.stats[0].instructions.items[0].actions.items[0].port, request_mod.instructions.items[0].actions.items[0].port, "action error:" + str(response.stats[0].instructions.items[0].actions.items[0].port))
def runTest(self): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") ingress_port = of_ports[0]; egress_port = of_ports[1]; rc = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #controller send flow_mod to switch pkt = testutils.simple_tcp_packet() flow_mod_add = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=testutils.EX_ACL_TABLE) testutils.flow_msg_install(self, flow_mod_add) #user send pkt to switch, switch transfer to eng_port pa_logger.info("Sending packet to dp port " + str(ingress_port)) self.dataplane.send(ingress_port, str(pkt)) (rcv_port, rcv_pkt, _) = self.dataplane.poll(egress_port, timeout=2) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, egress_port, "Unexpected receive port") self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') #check the stats msg stat_req = message.flow_stats_request() stat_req.match_fields = flow_mod_add.match_fields stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_ANY; stat_req.out_group = ofp.OFPG_ANY; pa_logger.info("Sending stats request") testutils.ofmsg_send(self, stat_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) self.assertTrue(response, "No Flow_stats reply") #print "YYY: Stats reply is \n%s" % (response.show()) self.assertEqual(len(response.stats), 1, "Did not receive flow stats reply") self.assertEqual(response.stats[0].packet_count,1) self.assertEqual(response.stats[0].byte_count,len(rcv_pkt))
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[1] pkt = testutils.simple_tcp_packet(dl_src='08:02:ff:34:88:99', dl_dst='22:22:ed:22:5f:1a') request = testutils.flow_msg_create(self, pkt, egr_port = egr_port, table_id = table_id) for obj in request.match_fields.tlvs: if obj.field == ofp.OFPXMT_OFB_METADATA: obj.value = 0x9922334455667788 request.idle_timeout = 1 request.flags |= ofp.OFPFF_SEND_FLOW_REM testutils.flow_msg_install(self, request) #print(request.show()) (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 3) self.assertTrue(response is not None, 'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie, 'Cookies do not match') self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout')
def runTest(self): of_ports = testutils.clear_switch(self, exact_port_map.keys(), exact_logger)#zhaoxiuchu table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[1] pkt = testutils.simple_tcp_packet(dl_src='08:02:03:04:88:99', dl_dst='22:22:22:22:22:22') pkt_metadata = {'metadata_val':0xad22332e6f667588, 'metadata_msk':0xFFFFFFFFFFFFFFFF} request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port, table_id = table_id) request.hard_timeout = 1 request.flags |= ofp.OFPFF_SEND_FLOW_REM testutils.flow_msg_install(self, request) #print(request.show()) (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 3) self.assertTrue(response is not None,'Did not receive flow removed message ') self.assertEqual(request.cookie, response.cookie,'Cookies do not match') self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason, 'Flow table entry removal reason is not idle_timeout')
def runTest(self): """ ** Currently, same scenario with "NoGoto" ** 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; do nothing // match but stop pipeline Fourth Table; Match IP Src A; send to 2 // not match, just a fake Then send in 2 packets: IP A, TCP C; expect out port 1 IP A, TCP B; expect out port 1 """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up first match testutils.write_goto(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE) # Set up second match testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, of_ports[0], of_ports[2]) # Set up third match, "Empty Instruction" pkt = testutils.simple_tcp_packet() request = testutils.flow_msg_create(self, pkt, ing_port=of_ports[2], table_id=testutils.EX_L2_TABLE) testutils.flow_msg_install(self, request) # Set up fourth match testutils.write_output(self, testutils.EX_VLAN_TABLE, of_ports[1]) # Generate a packet matching flow 1, 2, and 3; rcv on port[0] testutils.reply_check_dp(self, tcp_sport=1234, ing_port=of_ports[2], egr_port=of_ports[0])
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[0] pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22', dl_dst='22:22:22:22:22:22') pkt_metadata = { 'metadata_val': 0x1122334455667788, 'metadata_msk': 0xFFFFFFFFFFFFFFFF } request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port=egr_port, table_id=table_id) testutils.flow_msg_install(self, request) #"delete it" request_del = testutils.flow_msg_create( self, pkt, match_fields=request.match_fields, egr_port=egr_port, table_id=table_id) request_del.command = ofp.OFPFC_DELETE testutils.ofmsg_send(self, request_del) #'read it back , returns blank;' stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) self.assertTrue(isinstance(response, message.flow_stats_reply), "Not a flow_stats_reply") self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats)))
def runTest(self): ing_port = flow_mods_port_map.keys()[0] egr_port = flow_mods_port_map.keys()[1] table_id = testutils.EX_L3_TABLE flow_count = 10 testutils.delete_all_flows_one_table(self.controller, self.logger, table_id) match_fields_ls = [] ipv6_src_addr = 'fe80::2420:52ff:fe8f:5188' metadata_val = 0xaa22334455667788 for i in range(flow_count): match_fields_ls.append(match_list()) match_fields_ls[i].add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields_ls[i].add(match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) ipv6_dst_addr = 'fe80::2420:52ff:fe8f:' + str(5190+i) match_fields_ls[i].add(match.ipv6_dst(ipaddr.IPv6Address(ipv6_dst_addr))) match_fields_ls[i].add(match.metadata(metadata_val)) request = testutils.flow_msg_create(self, None, ing_port=ing_port, match_fields = match_fields_ls[i], egr_port = egr_port, table_id = table_id) testutils.flow_msg_install(self, request, False) match_fields = match_list() match_fields.add(match.eth_type(testutils.IPV6_ETHERTYPE)) match_fields.add(match.ipv6_src(ipaddr.IPv6Address(ipv6_src_addr))) response = testutils.flow_stats_get(self, table_id = table_id) self.assertTrue(len(response.stats) == flow_count, 'Did not add all flows successfully! Get table entry num is %d' %len(response.stats)) request = testutils.flow_msg_create(self, None, None, ing_port, match_fields, table_id = table_id) request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request, False) response = testutils.flow_stats_get(self, table_id = table_id) self.assertTrue(len(response.stats) == 0, 'Switch did not del the flow entry! Current table entry num is %d' %len(response.stats))
def runTest(self): table_id = testutils.EX_L2_TABLE of_ports = exact_port_map.keys() egr_port = of_ports[len(of_ports)-1] pkt = testutils.simple_tcp_packet(dl_src='00:22:44:62:9b:1c', dl_dst='00:13:07:5f:61:ab') pkt_metadata = {'metadata_val':0xaa22334455667788, 'metadata_msk':0xFFFFFFFFFFFFFFFF} request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port, table_id = table_id) request.hard_timeout = 8 request.idle_timeout = 8 testutils.flow_msg_install(self, request) #"get flow stats" stat_req = message.flow_stats_request() stat_req.buffer_id = 0xffffffff stat_req.table_id = table_id stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY stat_req.match_fields = request.match_fields response, _ = self.controller.transact(stat_req, timeout=2) self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply") self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats)))
def runTest(self): of_ports = async_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #"verifying without set_async_request, switch will send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPRR_HARD_TIMEOUT request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #step 2-1:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-1:insert a flow entry: idle_timeout=1 pkt = testutils.simple_tcp_packet() ing_port = of_ports[0] egr_port = of_ports[1] async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id=testutils.WC_ALL_TABLE, check_expire=True) request.cookie = random.randint(0, 0xffffffffffffffff) testutils.flow_msg_install(self, request) #step 4-1: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is not None, 'Not receive flow removed message') self.assertTrue(response.reason == ofp.OFPRR_HARD_TIMEOUT, 'Not OFPRR_HARD_TIMEOUT reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #step 5-1: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self, request.match_fields, request.table_id) async_logger.debug(response.show()) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) #"verifying with set_async_request, switch will not send flow removed" #step 1-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_HARD_TIMEOUT) request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-2: contrller sends msg successfully #step 2-2:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-2:insert a flow entry: idle_timeout=1 async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) testutils.flow_msg_install(self, request) #step 4-2: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is None, 'Receive flow removed message ') #step 5-2: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self) async_logger.debug(response.show()) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) msg = create_set_async() set_async_verify(self, msg)
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): #"verifying with set_async_request, switch will not send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") of_ports = async_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[1] mask = 1 << ofp.OFPRR_DELETE request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #"step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) pkt = testutils.simple_tcp_packet(vlan_tags=[{ 'type': 0x8100, 'vid': 5, 'pcp': 1 }]) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id=testutils.EX_VLAN_TABLE, check_expire=True) request.cookie = random.randint(0, 0xffffffffffffffff) testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) #"receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Not receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) #print(response.show()) #"verifying with set_async_request, switch will not send flow removed" "step 1-2:controller sends set_async_request msg" async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_DELETE) request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #table_id = 3 "add a flow entry" request.command = ofp.OFPFC_ADD testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) "receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') 'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats), 0, "len of stats is:" + str(len(response.stats))) #print(response.show()) msg = create_set_async() set_async_verify(self, msg)
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))
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): #self.clean_switch() #print("AsyncGroupDelNoFlowRemoved") #"verifying without set_async, switch will send flow removed" #step 1-1:controller sends set_async msg async_logger.info("Sending set_async") mask = 1 << ofp.OFPRR_GROUP_DELETE request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully "step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-1:add goup entry" group_add_msg = \ groups.create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [ groups.create_bucket(0, 0, 0, [ groups.create_action(action= ofp.OFPAT_OUTPUT, port= 1) ]) ]) testutils.ofmsg_send(self, group_add_msg) "step 4-1: add an flow entry ,install default mismatch flow entry;" pkt = testutils.simple_tcp_packet() act = groups.create_action(action=ofp.OFPAT_GROUP, group_id=10) request = testutils.flow_msg_create(self, pkt, action_list=[act], table_id=testutils.WC_L3_TABLE, check_expire=True) request.cookie = random.randint(0, 0xffffffffffffffff) testutils.flow_msg_install(self, request) "step 5-1: delete goup entry" group_del_msg = \ groups.create_group_mod_msg(ofp.OFPGC_DELETE, ofp.OFPGT_ALL, group_id = 10, buckets = [ ]) testutils.ofmsg_send(self, group_del_msg) "step 5-1:receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_GROUP_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #"verifying with set_async, switch will not send flow removed" "step 1-2:controller sends set_async msg" async_logger.info("Sending set_async") mask = 0xffffffff ^ (1 << ofp.OFPRR_GROUP_DELETE) request_set = create_set_async(flow_rm_mstr=mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response, _ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-2:add goup entry" testutils.ofmsg_send(self, group_add_msg) "step 4-2: add an flow entry ,install default mismatch flow entry;" testutils.flow_msg_install(self, request) "step 5-2: delete goup entry" testutils.ofmsg_send(self, group_del_msg) "step 6-2: receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #async_logger.info("Running InvalidTTL_NoPacketIn") #"verifying without set_async_request, switch will packet in" #step 1-1:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPR_INVALID_TTL request_set = create_set_async(pkt_in_mstr = mask) testutils.ofmsg_send(self, request_set) #result 2-1: contrller sends msg successfully #step 3-1: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port = ofp.OFPP_CONTROLLER, table_id = testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is not None, 'Can not receive packet in message') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port,1) self.assertTrue(pkt_rec is None, "dataplane not receive packet") (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #"verifying with set_async_request, switch will not packet in" #step 1-2:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPR_INVALID_TTL) request_set = create_set_async(pkt_in_mstr = mask) testutils.ofmsg_send(self, request_set) #result 2-2: contrller sends msg successfully #step 3-2: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port = ofp.OFPP_CONTROLLER, table_id = testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #(response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is None, 'Packet in message received unexpected') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port,1) self.assertTrue(pkt_rec is None, "dataplane rec packet") msg = create_set_async() set_async_verify(self, msg)
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 = async_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") #"verifying without set_async_request, switch will send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPRR_HARD_TIMEOUT request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #step 2-1:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-1:insert a flow entry: idle_timeout=1 pkt = testutils.simple_tcp_packet() ing_port = of_ports[0] egr_port = of_ports[1] async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id = testutils.WC_ALL_TABLE, check_expire=True) request.cookie = random.randint(0,0xffffffffffffffff) testutils.flow_msg_install(self, request) #step 4-1: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is not None, 'Not receive flow removed message') self.assertTrue(response.reason == ofp.OFPRR_HARD_TIMEOUT, 'Not OFPRR_HARD_TIMEOUT reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #step 5-1: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self, request.match_fields, request.table_id) async_logger.debug(response.show()) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) #"verifying with set_async_request, switch will not send flow removed" #step 1-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_HARD_TIMEOUT) request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-2: contrller sends msg successfully #step 2-2:clear all flow entry testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #step 3-2:insert a flow entry: idle_timeout=1 async_logger.info("Ingress " + str(ing_port) + " to egress " + str(egr_port)) testutils.flow_msg_install(self, request) #step 4-2: wait for 2sec, make sure no ofp_flow_removed msg (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 5) self.assertTrue(response is None, 'Receive flow removed message ') #step 5-2: verify there is no flow entry async_logger.info("Sending flow request") response = testutils.flow_stats_get(self) async_logger.debug(response.show()) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #"verifying with set_async_request, switch will not send flow removed" #step 1-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") of_ports = async_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[1] mask = 1 << ofp.OFPRR_DELETE request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully #"step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) pkt = testutils.simple_tcp_packet( vlan_tags=[{'type': 0x8100, 'vid': 5, 'pcp': 1}]) request = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=egr_port, table_id = testutils.EX_VLAN_TABLE, check_expire=True) request.cookie = random.randint(0,0xffffffffffffffff) testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) #"receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Not receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) #print(response.show()) #"verifying with set_async_request, switch will not send flow removed" "step 1-2:controller sends set_async_request msg" async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPRR_DELETE) request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) #table_id = 3 "add a flow entry" request.command = ofp.OFPFC_ADD testutils.flow_msg_install(self, request) "delete it" request.command = ofp.OFPFC_DELETE testutils.flow_msg_install(self, request) "receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') 'read it back , returns blank;' response = testutils.flow_stats_get(self, request.match_fields, request.table_id) self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats))) #print(response.show()) msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #async_logger.info("Running InvalidTTL_NoPacketIn") #"verifying without set_async_request, switch will packet in" #step 1-1:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-1:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 1 << ofp.OFPR_INVALID_TTL request_set = create_set_async(pkt_in_mstr=mask) testutils.ofmsg_send(self, request_set) #result 2-1: contrller sends msg successfully #step 3-1: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port=ofp.OFPP_CONTROLLER, table_id=testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is not None, 'Can not receive packet in message') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port, 1) self.assertTrue(pkt_rec is None, "dataplane not receive packet") (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #"verifying with set_async_request, switch will not packet in" #step 1-2:clear all flow entries for unmatching rc = testutils.delete_all_flows(self.controller, async_logger) self.assertEqual(rc, 0, "Failed to delete all flows") #step 2-2:controller sends set_async_request msg async_logger.info("Sending set_async_request") mask = 0xffffffff ^ (1 << ofp.OFPR_INVALID_TTL) request_set = create_set_async(pkt_in_mstr=mask) testutils.ofmsg_send(self, request_set) #result 2-2: contrller sends msg successfully #step 3-2: install default mismatch flow entry ,action=output; testutils.set_table_config(self) pkt = testutils.simple_tcp_packet(ip_ttl=0) flow_add = testutils.flow_msg_create(self, pkt, egr_port=ofp.OFPP_CONTROLLER, table_id=testutils.WC_L3_TABLE) testutils.flow_msg_install(self, flow_add) #(response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #send data(invalid ttl) to port for of_port in async_port_map.keys(): async_logger.info("PKT IN test, port " + str(of_port)) self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is None, 'Packet in message received unexpected') #dataplane receive nothing (port_rec, pkt_rec, _) = self.dataplane.poll(of_port, 1) self.assertTrue(pkt_rec is None, "dataplane rec packet") msg = create_set_async() set_async_verify(self, msg)
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_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 = 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 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 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 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 runTest(self): #self.clean_switch() #print("AsyncGroupDelNoFlowRemoved") #"verifying without set_async, switch will send flow removed" #step 1-1:controller sends set_async msg async_logger.info("Sending set_async") mask = 1 << ofp.OFPRR_GROUP_DELETE request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) #result 1-1: contrller sends msg successfully "step 2-1:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-1:add goup entry" group_add_msg = \ groups.create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [ groups.create_bucket(0, 0, 0, [ groups.create_action(action= ofp.OFPAT_OUTPUT, port= 1) ]) ]) testutils.ofmsg_send(self, group_add_msg) "step 4-1: add an flow entry ,install default mismatch flow entry;" pkt = testutils.simple_tcp_packet() act = groups.create_action(action= ofp.OFPAT_GROUP, group_id = 10) request = testutils.flow_msg_create(self, pkt, action_list = [act], table_id = testutils.WC_L3_TABLE, check_expire=True) request.cookie = random.randint(0,0xffffffffffffffff) testutils.flow_msg_install(self, request) "step 5-1: delete goup entry" group_del_msg = \ groups.create_group_mod_msg(ofp.OFPGC_DELETE, ofp.OFPGT_ALL, group_id = 10, buckets = [ ]) testutils.ofmsg_send(self, group_del_msg) "step 5-1:receive flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is not None, 'Receive flow removed message ') self.assertTrue(response.reason == ofp.OFPRR_GROUP_DELETE, 'Not OFPRR_DELETE reason') self.assertTrue(response.cookie == request.cookie, 'Cookie is not equal') #self.assertTrue(response.match_fields == request.match_fields, # 'Match_fields is not equal') #"verifying with set_async, switch will not send flow removed" "step 1-2:controller sends set_async msg" async_logger.info("Sending set_async") mask = 0xffffffff ^ (1 << ofp.OFPRR_GROUP_DELETE) request_set = create_set_async(flow_rm_mstr = mask) testutils.ofmsg_send(self, request_set) "result 1-2: contrller sends msg successfully" "step 2-2:clear all flow entry" testutils.delete_all_flows(self.controller, async_logger) response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) while response != None: response,_ = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 1) "step 3-2:add goup entry" testutils.ofmsg_send(self, group_add_msg) "step 4-2: add an flow entry ,install default mismatch flow entry;" testutils.flow_msg_install(self, request) "step 5-2: delete goup entry" testutils.ofmsg_send(self, group_del_msg) "step 6-2: receive no flow removed msg" (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) self.assertTrue(response is None, 'Receive flow removed message ') msg = create_set_async() set_async_verify(self, msg)