def runTest(self): of_ports = pa_port_map.keys() ing_port = of_ports[1] egr_port =ofp.OFPP_CONTROLLER "clear swtich;" testutils.delete_all_flows(self.controller, self.logger) # Set table config as "continue" testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_DROP, True) testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True) #"make test packet;" pkt = testutils.simple_icmp_packet() inst_write_metadata = instruction.instruction_write_metadata(); inst_write_metadata.metadata = 0x20000000 inst_write_metadata.metadata_mask = 0xf0000000 testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst = inst_write_metadata) pkt_metadata = {'metadata_val':inst_write_metadata.metadata, 'metadata_msk':inst_write_metadata.metadata_mask} match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata, table_id = testutils.EX_L2_TABLE) testutils.write_output(self, testutils.EX_L2_TABLE, egr_port, match_fields=match_fields) self.dataplane.send(ing_port, str(pkt)) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue(response is not None, 'Packet in message not received on port ' + str(egr_port)) if str(pkt) != response.data: pa_logger.debug("pkt len " + str(len(str(pkt))) +": " + str(pkt)) pa_logger.debug("resp len " + str(len(str(response.data))) + ": " + str(response.data))
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 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): of_ports = pa_port_map.keys() ing_port = of_ports[1] egr_port = of_ports[2] "clear swtich;" testutils.delete_all_flows(self.controller, self.logger) # Set table config as "continue" testutils.set_table_config(self, testutils.EX_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True) testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.EX_VLAN_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.EX_MPLS_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True) #"make test packet;" pkt = testutils.simple_icmp_packet() inst_write_metadata = instruction.instruction_write_metadata(); inst_write_metadata.metadata = 0x20000000 inst_write_metadata.metadata_mask = 0xf0000000 testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst = inst_write_metadata) pkt_metadata = {'metadata_val':inst_write_metadata.metadata, 'metadata_msk':inst_write_metadata.metadata_mask} match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata, table_id = testutils.EX_L3_TABLE) testutils.write_output(self, testutils.EX_L3_TABLE, egr_port, match_fields=match_fields) testutils.reply_check_dp(self, tcp_sport=1234, ing_port = ing_port, egr_port = egr_port) testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER)
def runTest(self): vlan_tags=[{'type': 0x8100, 'vid': 1, 'pcp': 1}] #mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}] pkt = testutils.simple_icmp_packet( dl_dst='00:01:02:03:04:05', dl_src='00:06:07:08:09:0a', vlan_tags=vlan_tags, mpls_tags=[], ip_src='192.168.0.55', ip_dst='192.168.3.254', ip_tos=5, ip_ttl=47, icmp_type=8, icmp_code=0, payload_len=100) of_ports = exact_port_map.keys() for dp_port1 in of_ports: ing_port = dp_port1 for dp_port2 in of_ports: if dp_port2 != dp_port1: egr_port = dp_port2 #match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_ACL_TABLE, ing_port) #exact_table_goto_table(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.WC_ACL_TABLE, ing_port) exact_table_goto_table(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.WC_SERV_TABLE, ing_port) exact_table_goto_table(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_L2_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_L2_TABLE, testutils.EX_VLAN_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_VLAN_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_VLAN_TABLE, testutils.EX_MPLS_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_MPLS_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_MPLS_TABLE, testutils.EX_L3_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_L3_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_L3_TABLE, testutils.WC_L3_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.WC_L3_TABLE, ing_port) exact_table_goto_table(self, testutils.WC_L3_TABLE, testutils.EX_ICMP_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_ICMP_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_ICMP_TABLE, testutils.WC_ALL_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.WC_ALL_TABLE, ing_port) exact_table_output(self, testutils.WC_ALL_TABLE, match_ls, egr_port = egr_port) self.dataplane.send(ing_port, str(pkt)) testutils.receive_pkt_verify(self, egr_port, pkt)
def runTest(self): of_ports = pa_port_map.keys() ing_port = of_ports[1] egr_port = of_ports[2] "clear swtich;" testutils.delete_all_flows(self.controller, self.logger) # Set table config as "continue" testutils.set_table_config(self, testutils.EX_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True) testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.EX_VLAN_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.EX_MPLS_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True) #"make test packet;" pkt = testutils.simple_icmp_packet() inst_write_metadata = instruction.instruction_write_metadata() inst_write_metadata.metadata = 0x20000000 inst_write_metadata.metadata_mask = 0xf0000000 testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst=inst_write_metadata) pkt_metadata = { 'metadata_val': inst_write_metadata.metadata, 'metadata_msk': inst_write_metadata.metadata_mask } match_fields = testutils.packet_to_exact_flow_match( pkt_metadata=pkt_metadata, table_id=testutils.EX_L3_TABLE) testutils.write_output(self, testutils.EX_L3_TABLE, egr_port, match_fields=match_fields) testutils.reply_check_dp(self, tcp_sport=1234, ing_port=ing_port, egr_port=egr_port) testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER)
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() else: pkt = testutils.simple_tcp_packet() match = parse.packet_to_flow_match(pkt) self.assertTrue(match is not None, "Could not generate flow match from pkt") match.wildcards &= ~ofp.OFPFW_IN_PORT act = action.action_output() 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") 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)) match.in_port = ingress_port request = message.flow_mod() request.command = ofp.OFPFC_ADD request.match = match request.buffer_id = 0xffffffff inst = instruction.instruction_apply_actions() act.port = egress_port self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(request.instructions.add(inst), "Could not add instruction") pa_logger.info("Inserting flow") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller) 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(timeout=1) self.assertTrue(rcv_pkt is not None, "Did not receive packet") pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + str(rcv_port)) self.assertEqual(rcv_port, egress_port, "Unexpected receive port") self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet')
def runTest(self): of_ports = pa_port_map.keys() ing_port = of_ports[1] egr_port = ofp.OFPP_CONTROLLER "clear swtich;" testutils.delete_all_flows(self.controller, self.logger) # Set table config as "continue" testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True) testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_DROP, True) testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True) #"make test packet;" pkt = testutils.simple_icmp_packet() inst_write_metadata = instruction.instruction_write_metadata() inst_write_metadata.metadata = 0x20000000 inst_write_metadata.metadata_mask = 0xf0000000 testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst=inst_write_metadata) pkt_metadata = { 'metadata_val': inst_write_metadata.metadata, 'metadata_msk': inst_write_metadata.metadata_mask } match_fields = testutils.packet_to_exact_flow_match( pkt_metadata=pkt_metadata, table_id=testutils.EX_L2_TABLE) testutils.write_output(self, testutils.EX_L2_TABLE, egr_port, match_fields=match_fields) self.dataplane.send(ing_port, str(pkt)) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) self.assertTrue( response is not None, 'Packet in message not received on port ' + str(egr_port)) if str(pkt) != response.data: pa_logger.debug("pkt len " + str(len(str(pkt))) + ": " + str(pkt)) pa_logger.debug("resp len " + str(len(str(response.data))) + ": " + str(response.data))
def runTest(self): vlan_tags = [{'type': 0x8100, 'vid': 1, 'pcp': 1}] #mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}] pkt = testutils.simple_icmp_packet(dl_dst='00:01:02:03:04:05', dl_src='00:06:07:08:09:0a', vlan_tags=vlan_tags, mpls_tags=[], ip_src='192.168.0.55', ip_dst='192.168.3.254', ip_tos=5, ip_ttl=47, icmp_type=8, icmp_code=0, payload_len=100) of_ports = exact_port_map.keys() for dp_port1 in of_ports: ing_port = dp_port1 for dp_port2 in of_ports: if dp_port2 != dp_port1: egr_port = dp_port2 #match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_ACL_TABLE, ing_port) #exact_table_goto_table(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.WC_ACL_TABLE, ing_port) exact_table_goto_table(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.WC_SERV_TABLE, ing_port) exact_table_goto_table(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.EX_L2_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_L2_TABLE, testutils.EX_VLAN_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.EX_VLAN_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_VLAN_TABLE, testutils.EX_MPLS_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.EX_MPLS_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_MPLS_TABLE, testutils.EX_L3_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.EX_L3_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_L3_TABLE, testutils.WC_L3_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.WC_L3_TABLE, ing_port) exact_table_goto_table(self, testutils.WC_L3_TABLE, testutils.EX_ICMP_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.EX_ICMP_TABLE, ing_port) exact_table_goto_table(self, testutils.EX_ICMP_TABLE, testutils.WC_ALL_TABLE, match_ls) match_ls = testutils.packet_to_exact_flow_match( pkt, None, testutils.WC_ALL_TABLE, ing_port) exact_table_output(self, testutils.WC_ALL_TABLE, match_ls, egr_port=egr_port) self.dataplane.send(ing_port, str(pkt)) testutils.receive_pkt_verify(self, egr_port, pkt)
def runTest(self): #async_logger.info("Running Action_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_ACTION 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 match flow entry ,action=packetin; testutils.set_table_config(self) pkt = testutils.simple_icmp_packet() flow_add = testutils.flow_msg_create(self, pkt, egr_port = ofp.OFPP_CONTROLLER, table_id = testutils.EX_ICMP_TABLE) testutils.flow_msg_install(self, flow_add) #send data 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, 'Packet in message not received') (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_ACTION) 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 match flow entry ,action=packetin; testutils.set_table_config(self) pkt = testutils.simple_icmp_packet() flow_add = testutils.flow_msg_create(self, pkt, egr_port = ofp.OFPP_CONTROLLER, table_id = testutils.EX_ICMP_TABLE) testutils.flow_msg_install(self, flow_add) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #send data 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) #print(response) self.assertTrue(response is None, 'Packet in message received unexpected') msg = create_set_async() set_async_verify(self, msg)
def runTest(self): #async_logger.info("Running Action_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_ACTION 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 match flow entry ,action=packetin; testutils.set_table_config(self) pkt = testutils.simple_icmp_packet() flow_add = testutils.flow_msg_create(self, pkt, egr_port=ofp.OFPP_CONTROLLER, table_id=testutils.EX_ICMP_TABLE) testutils.flow_msg_install(self, flow_add) #send data 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, 'Packet in message not received') (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_ACTION) 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 match flow entry ,action=packetin; testutils.set_table_config(self) pkt = testutils.simple_icmp_packet() flow_add = testutils.flow_msg_create(self, pkt, egr_port=ofp.OFPP_CONTROLLER, table_id=testutils.EX_ICMP_TABLE) testutils.flow_msg_install(self, flow_add) (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) #send data 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) #print(response) self.assertTrue(response is None, 'Packet in message received unexpected') msg = create_set_async() set_async_verify(self, msg)