def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = ofp.OFPP_ALL pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1) #flood inst = None inst = instruction.instruction_apply_actions() act = action.action_output() act.port = ofp.OFPP_IN_PORT #fwd to ingress rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) fm_orig.instructions.add(inst) #print(fm_orig.show()) testutils.ofmsg_send(self, fm_orig) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is None, 'Receive error message') #user sends packet self.dataplane.send(ing_port, str(pkt)) testutils.do_barrier(self.controller) #verify pkt for of_port in flow_mods_port_map.keys(): testutils.receive_pkt_verify(self, of_port, pkt)
def create_flow_msg(packet = None, in_port = None, match = None, apply_action_list = []): apply_inst = instruction.instruction_apply_actions() if apply_action_list is not None: for act in apply_action_list: apply_inst.actions.add(act) request = message.flow_mod() request.match.type = ofp.OFPMT_OXM if match is None: match = parse.packet_to_flow_match(packet) request.match_fields = match if in_port != None: match_port = testutils.oxm_field.in_port(in_port) request.match_fields.tlvs.append(match_port) request.buffer_id = 0xffffffff request.priority = 1000 request.instructions.add(apply_inst) return request
def runTest(self): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) field_2b_set = match.ipv6_dst(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD')) act_setfield = action.action_set_field() act_setfield.field = field_2b_set # TODO: insert action set field properly act_out = action.action_output() act_out.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act_setfield) inst.actions.add(act_out) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") #Send packet pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189',ip_dst='fe80::2420:52ff:fe8f:5190') ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet(ip_dst='fe80::2420:52ff:fe8f:DDDD') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def runTest(self): ing_port = flow_mods_port_map.keys()[0] out_port1 = ofp.OFPP_ALL pkt = testutils.simple_tcp_packet() testutils.delete_all_flows(self.controller, self.logger) fm_orig = testutils.flow_msg_create(self, pkt, ing_port=ing_port, egr_port=out_port1)#flood inst = None inst = instruction.instruction_apply_actions() act = action.action_output() act.port = ofp.OFPP_IN_PORT #fwd to ingress rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) fm_orig.instructions.add(inst) #print(fm_orig.show()) testutils.ofmsg_send(self, fm_orig) (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2) self.assertTrue(response is None, 'Receive error message') #user sends packet self.dataplane.send(ing_port, str(pkt)) testutils.do_barrier(self.controller) #verify pkt for of_port in flow_mods_port_map.keys(): testutils.receive_pkt_verify(self, of_port, pkt)
def runTest(self): of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] check_expire_tbl0 = False check_expire_tbl1 = False # Build the ingress packet pkt = testutils.simple_tcp_packet(**self.base_pkt_params) # Set action for the first table for item_tbl0 in self.start_pkt_params: tbl0_pkt_params = self.base_pkt_params.copy() tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0] act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params) action_list = [act] inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(self, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list, check_expire=check_expire_tbl0, table_id=0) exp_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params) request1 = testutils.flow_msg_create(self, exp_pkt, ing_port=ing_port, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) # Insert two flows self.logger.debug("Inserting flows: Modify-field: " + item_tbl0) testutils.flow_msg_install(self, request0) testutils.flow_msg_install(self, request1) # Send pkt self.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) self.dataplane.send(ing_port, str(pkt)) #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if check_expire_tbl0: flow_removed_verify(self, request0, pkt_count=1, byte_count=pktlen) if check_expire_tbl1: flow_removed_verify(self, request1, pkt_count=1, byte_count=exp_pktlen) # Receive and verify pkt testutils.receive_pkt_verify(self, egr_port, exp_pkt)
def runTest(self): #testutils.clear_switch(self,pa_port_map,pa_logger) testutils.delete_all_flows(self.controller, pa_logger) of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0]) match_ls = parse.packet_to_flow_match(pkt) request = message.flow_mod() request.match_fields = match_ls request.flags = 0x18 #set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS action_list = [] act = action.action_output() act.port = of_ports[1] action_list.append(act) inst = None instruction_list = [] if len(instruction_list) == 0: inst = instruction.instruction_apply_actions() instruction_list.append(inst) for act in action_list: rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) for i in instruction_list: rv = request.instructions.add(i) self.assertTrue(rv, "Could not add instruction " + i.show()) #testutils.message_send(self, request) rv0 = self.controller.message_send(request) self.assertTrue(rv0 != -1, "Error sending flow mod") testutils.do_barrier(self.controller) #self.send_data(pkt, of_ports[0]) self.dataplane.send(of_ports[0], str(pkt)) aggregate_stats_req = message.aggregate_stats_request() aggregate_stats_req.match_fields = match_ls rv = self.controller.message_send(aggregate_stats_req) self.assertTrue(rv != -1, "Error sending flow stat req") #testutils.message_send(self, aggregate_stats_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) #print(response.show()) self.assertTrue(response is not None, "No aggregate_stats reply") self.assertEqual(len(response.stats), 1, "Did not receive aggregate stats reply") self.assertEqual(response.stats[0].packet_count, 0) #1) self.assertEqual(response.stats[0].byte_count, 0) #len(packet_in))
def runTest(self): # Config of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src( ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) ip_proto = match.ip_proto(TCP_PROTOCOL) tcp_port = match.tcp_src(80) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) request.match_fields.tlvs.append(ip_proto) request.match_fields.tlvs.append(tcp_port) act = action.action_output() act.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to send test flow") #Send packet pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 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): # Config of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src(ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) ip_proto = match.ip_proto(TCP_PROTOCOL) tcp_port = match.tcp_src(80) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) request.match_fields.tlvs.append(ip_proto) request.match_fields.tlvs.append(tcp_port) act = action.action_output() act.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to send test flow") #Send packet pkt = testutils.simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 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): #testutils.clear_switch(self,pa_port_map,pa_logger) testutils.delete_all_flows(self.controller, pa_logger) of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") pkt = testutils.simple_tcp_packet() #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0]) match_ls = parse.packet_to_flow_match(pkt) request = message.flow_mod() request.match_fields = match_ls request.flags = 0x18#set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS action_list = [] act = action.action_output() act.port = of_ports[1] action_list.append(act) inst = None instruction_list = [] if len(instruction_list) == 0: inst = instruction.instruction_apply_actions() instruction_list.append(inst) for act in action_list: rv = inst.actions.add(act) self.assertTrue(rv, "Could not add action" + act.show()) for i in instruction_list: rv = request.instructions.add(i) self.assertTrue(rv, "Could not add instruction " + i.show()) #testutils.message_send(self, request) rv0 = self.controller.message_send(request) self.assertTrue( rv0 != -1, "Error sending flow mod") testutils.do_barrier(self.controller) #self.send_data(pkt, of_ports[0]) self.dataplane.send(of_ports[0],str(pkt)) aggregate_stats_req = message.aggregate_stats_request() aggregate_stats_req.match_fields = match_ls rv = self.controller.message_send(aggregate_stats_req) self.assertTrue( rv != -1, "Error sending flow stat req") #testutils.message_send(self, aggregate_stats_req) (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2) #print(response.show()) self.assertTrue(response is not None, "No aggregate_stats reply") self.assertEqual(len(response.stats), 1, "Did not receive aggregate stats reply") self.assertEqual(response.stats[0].packet_count,0)#1) self.assertEqual(response.stats[0].byte_count,0)#len(packet_in))
def runTest(self): # instructions header is 8 bytes l = instruction_list() act = action.action_output() act.port = 7 inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act)) self.assertTrue(l.add(inst)) pkt = l.pack() # 24 == 8 (list header) + (apply header) 8 + (output action) 8 self.assertEqual(len(pkt),24) l = instruction_list() self.assertTrue(l.add(instruction.instruction_goto_table()))
def runTest(self): # instructions header is 8 bytes l = instruction_list() act = action.action_output() act.port = 7 inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act)) self.assertTrue(l.add(inst)) pkt = l.pack() # 24 == 8 (list header) + (apply header) 8 + (output action) 8 self.assertEqual(len(pkt), 24) l = instruction_list() self.assertTrue(l.add(instruction.instruction_goto_table()))
def 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 set_apply_output(self, table_id, outport, add_inst=None): act = action.action_output() act.port = outport request = message.flow_mod() request.match = make_match() request.buffer_id = 0xffffffff request.table_id = table_id inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act), "Can't add action") self.assertTrue(request.instructions.add(inst), "Can't add inst") if add_inst is not None: self.assertTrue(request.instructions.add(add_inst), "Can't add inst") pa_logger.info("Inserting flow") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller)
def set_apply_output(self, table_id, outport, add_inst=None): act = action.action_output() act.port = outport request = message.flow_mod() request.match = make_match() request.buffer_id = 0xffffffff request.table_id = table_id inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act), "Can't add action") self.assertTrue(request.instructions.add(inst), "Can't add inst") if add_inst is not None: self.assertTrue(request.instructions.add(add_inst), "Can't add inst") pa_logger.info("Inserting flow") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Error installing flow mod") testutils.do_barrier(self.controller)
def runTest(self): of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger) for max_len in [ 0, 99, DEFAULT_MISS_SEND_LEN, ofp.OFPCML_MAX, ofp.OFPCML_NO_BUFFER ]: rc = testutils.delete_all_flows(self.controller, basic_logger) self.assertEqual(rc, 0, "Failed to delete all flows") testutils.set_config_verify(self, max_len=(max_len % ofp.OFPCML_MAX + 10)) if max_len == ofp.OFPCML_NO_BUFFER: testutils.set_config_verify(self, max_len=max_len) request = message.flow_mod() request.table_id = 0 request.priority = 0 request.cookie = 123456 act = action.action_output() act.max_len = max_len act.port = ofp.OFPP_CONTROLLER inst_packet_in = instruction.instruction_apply_actions() #apply inst_packet_in.actions.add(act) request.instructions.add(inst_packet_in) rv = self.controller.message_send(request) for of_port in basic_port_map.keys(): basic_logger.info("PKT IN test, port " + str(of_port)) pkt = testutils.simple_tcp_packet() self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? testutils.do_barrier(self.controller) #testutils.packetin_verify(self, pkt, max_len) response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) self.assertEqual(response.cookie, request.cookie, "cookie is not equal") #print(response.cookie) #print(request.cookie) #clear the msg response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) while response != None: response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
def runTest(self): msg = message.flow_stats_entry() match = ofp.ofp_match() match.wildcards &= ~ofp.OFPFW_IN_PORT act = action.action_output() act.port = 3 msg.match = match pkt = msg.pack() self.assertEqual(len(pkt), 136) inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(msg.instructions.add(inst), "Could not add instructions") #self.assertTrue(msg.actions.add(act), "Could not add action") pkt = msg.pack() # 160 = 136 for flow_stats_entry and 24 for instruction_list self.assertEqual(len(pkt), 160) rep = message.flow_stats_reply() self.assertEqual(len(rep.pack()),12) rep.stats.append(msg) self.assertEqual(len(rep.pack()),172)
def create_flow_msg(packet = None, in_port = None, match = None, apply_action_list = []): apply_inst = instruction.instruction_apply_actions() if apply_action_list is not None: for act in apply_action_list: apply_inst.actions.add(act) request = message.flow_mod() if packet != None: match = parse.packet_to_flow_match(packet) match.wildcards = 0 match.in_port = in_port request.match = match request.buffer_id = 0xffffffff request.instructions.add(apply_inst) return request
def runTest(self): of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger) for max_len in [0, 99, DEFAULT_MISS_SEND_LEN, ofp.OFPCML_MAX, ofp.OFPCML_NO_BUFFER]: rc = testutils.delete_all_flows(self.controller, basic_logger) self.assertEqual(rc, 0, "Failed to delete all flows") testutils.set_config_verify(self, max_len = (max_len % ofp.OFPCML_MAX + 10)) if max_len == ofp.OFPCML_NO_BUFFER: testutils.set_config_verify(self, max_len = max_len) request = message.flow_mod() request.table_id = 0 request.priority = 0 request.cookie = 123456 act = action.action_output() act.max_len = max_len act.port = ofp.OFPP_CONTROLLER inst_packet_in = instruction.instruction_apply_actions()#apply inst_packet_in.actions.add(act) request.instructions.add(inst_packet_in) rv = self.controller.message_send(request) for of_port in basic_port_map.keys(): basic_logger.info("PKT IN test, port " + str(of_port)) pkt = testutils.simple_tcp_packet() self.dataplane.send(of_port, str(pkt)) #@todo Check for unexpected messages? testutils.do_barrier(self.controller) #testutils.packetin_verify(self, pkt, max_len) response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) self.assertEqual(response.cookie, request.cookie, "cookie is not equal") #print(response.cookie) #print(request.cookie) #clear the msg response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1) while response != None: response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
def create_flow_msg(packet=None, in_port=None, match=None, apply_action_list=[]): apply_inst = instruction.instruction_apply_actions() if apply_action_list is not None: for act in apply_action_list: apply_inst.actions.add(act) request = message.flow_mod() if packet != None: match = parse.packet_to_flow_match(packet) match.wildcards = 0 match.in_port = in_port request.match = match request.buffer_id = 0xffffffff request.instructions.add(apply_inst) return request
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_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): global pa_port_map of_ports = pa_port_map.keys() of_ports.sort() self.assertTrue(len(of_ports) > 1, "Not enough ports for test") rc = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") pkt = testutils.simple_tcp_packet() match = parse.packet_to_flow_match(pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") act = action.action_output() ingress_port = of_ports[0]; egress_port = of_ports[1]; pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) match.in_port = ingress_port flow_mod_msg = message.flow_mod() flow_mod_msg.match = match flow_mod_msg.command = ofp.OFPFC_ADD flow_mod_msg.cookie = random.randint(0,9007199254740992) flow_mod_msg.buffer_id = 0xffffffff flow_mod_msg.idle_timeout = 1 act.port = egress_port #pdb.set_trace() inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(flow_mod_msg.instructions.add(inst), "Could not add action") stat_req = message.flow_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_ANY; stat_req.out_group = ofp.OFPG_ANY; testutils.do_barrier(self.controller) pa_logger.info("Sending stats request (before flow_mod insert)") rv = self.controller.message_send(stat_req) self.assertTrue(rv != -1, "Error sending flow stat req") testutils.do_barrier(self.controller) (empty_response, _) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2) self.assertTrue(empty_response, "No flow_stats reply (expected empty flow_stats)") self.assertEqual(len(empty_response.stats),0) pa_logger.info("Inserting flow") rv = self.controller.message_send(flow_mod_msg) 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=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') pa_logger.info("Sending stats request") rv = self.controller.message_send(stat_req) self.assertTrue(rv != -1, "Error sending flow stat req") testutils.do_barrier(self.controller) (response, _) = self.controller.poll(ofp.OFPT_STATS_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 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 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") rc = testutils.delete_all_flows(self.controller, pa_logger) self.assertEqual(rc, 0, "Failed to delete all flows") pkt = testutils.simple_tcp_packet() match = parse.packet_to_flow_match(pkt) match.wildcards &= ~ofp.OFPFW_IN_PORT self.assertTrue(match is not None, "Could not generate flow match from pkt") act = action.action_output() ingress_port = of_ports[0] egress_port = of_ports[1] pa_logger.info("Ingress " + str(ingress_port) + " to egress " + str(egress_port)) match.in_port = ingress_port flow_mod_msg = message.flow_mod() flow_mod_msg.match = match flow_mod_msg.command = ofp.OFPFC_ADD flow_mod_msg.cookie = random.randint(0, 9007199254740992) flow_mod_msg.buffer_id = 0xffffffff flow_mod_msg.idle_timeout = 1 act.port = egress_port #pdb.set_trace() inst = instruction.instruction_apply_actions() self.assertTrue(inst.actions.add(act), "Could not add action") self.assertTrue(flow_mod_msg.instructions.add(inst), "Could not add action") stat_req = message.flow_stats_request() stat_req.match = match stat_req.table_id = 0xff stat_req.out_port = ofp.OFPP_ANY stat_req.out_group = ofp.OFPG_ANY testutils.do_barrier(self.controller) pa_logger.info("Sending stats request (before flow_mod insert)") rv = self.controller.message_send(stat_req) self.assertTrue(rv != -1, "Error sending flow stat req") testutils.do_barrier(self.controller) (empty_response, _) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2) self.assertTrue(empty_response, "No flow_stats reply (expected empty flow_stats)") self.assertEqual(len(empty_response.stats), 0) pa_logger.info("Inserting flow") rv = self.controller.message_send(flow_mod_msg) 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=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') pa_logger.info("Sending stats request") rv = self.controller.message_send(stat_req) self.assertTrue(rv != -1, "Error sending flow stat req") testutils.do_barrier(self.controller) (response, _) = self.controller.poll(ofp.OFPT_STATS_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): of_ports = ipv6_port_map.keys() of_ports.sort() ing_port = of_ports[0] egr_port = of_ports[3] # Remove all entries Add entry match all rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows") # Add entry match request = message.flow_mod() request.match.type = ofp.OFPMT_OXM port = match.in_port(of_ports[0]) eth_type = match.eth_type(IPV6_ETHERTYPE) ipv6_src = match.ipv6_src( ipaddr.IPv6Address('fe80::2420:52ff:fe8f:5189')) request.match_fields.tlvs.append(port) request.match_fields.tlvs.append(eth_type) request.match_fields.tlvs.append(ipv6_src) field_2b_set = match.ipv6_dst( ipaddr.IPv6Address('fe80::2420:52ff:fe8f:DDDD')) act_setfield = action.action_set_field() act_setfield.field = field_2b_set # TODO: insert action set field properly act_out = action.action_output() act_out.port = of_ports[3] inst = instruction.instruction_apply_actions() inst.actions.add(act_setfield) inst.actions.add(act_out) request.instructions.add(inst) request.buffer_id = 0xffffffff request.priority = 1000 ipv6_logger.debug("Adding flow ") rv = self.controller.message_send(request) self.assertTrue(rv != -1, "Failed to insert test flow") #Send packet pkt = testutils.simple_ipv6_packet(ip_src='fe80::2420:52ff:fe8f:5189', ip_dst='fe80::2420:52ff:fe8f:5190') ipv6_logger.info("Sending IPv6 packet to " + str(ing_port)) ipv6_logger.debug("Data: " + str(pkt).encode('hex')) self.dataplane.send(ing_port, str(pkt)) #Receive packet exp_pkt = testutils.simple_ipv6_packet( ip_dst='fe80::2420:52ff:fe8f:DDDD') testutils.receive_pkt_verify(self, egr_port, exp_pkt) #See flow match response = testutils.flow_stats_get(self) ipv6_logger.debug("Response" + response.show()) #Remove flows rc = testutils.delete_all_flows(self.controller, ipv6_logger) self.assertEqual(rc, 0, "Failed to delete all flows")
def flow_match_test_port_pair_vlan_two_tables( parent, ing_port, egr_port, wildcards=0, dl_vlan=-1, dl_vlan_pcp=0, dl_vlan_type=ETHERTYPE_VLAN, dl_vlan_int=-1, dl_vlan_pcp_int=0, vid_match_tbl0=ofp.OFPVID_NONE, pcp_match_tbl0=0, action_list_tbl0=None, check_expire_tbl0=False, match_exp_tbl0=True, exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl0=0, exp_msg_code_tbl0=0, vid_match_tbl1=ofp.OFPVID_NONE, pcp_match_tbl1=0, action_list_tbl1=None, check_expire_tbl1=False, match_exp_tbl1=True, exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED, exp_msg_type_tbl1=0, exp_msg_code_tbl1=0, exp_vid=-1, exp_pcp=0, exp_vlan_type=ETHERTYPE_VLAN, add_tag_exp=False, pkt=None, exp_pkt=None): """ Flow match test for various vlan matching patterns on single TCP packet Run test with packet through switch from ing_port to egr_port See flow_match_test for parameter descriptions """ parent.logger.info("Pkt match test: " + str(ing_port) + " to " + str(egr_port)) parent.logger.debug(" WC: " + hex(wildcards) + " vlan: " + str(dl_vlan) + " expire_table0: " + str(check_expire_tbl0) + " expire_table1: " + str(check_expire_tbl1)) len = 100 len_w_vid = len + 4 if pkt is None: if dl_vlan >= 0: if dl_vlan_int >= 0: pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) pkt.push_vlan(dl_vlan_type) pkt.set_vlan_vid(dl_vlan) pkt.set_vlan_pcp(dl_vlan_pcp) else: pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=dl_vlan_type, dl_vlan=dl_vlan, dl_vlan_pcp=dl_vlan_pcp) else: pkt = testutils.simple_tcp_packet(pktlen=len, dl_vlan_enable=False) if exp_pkt is None: if exp_vid >= 0: if add_tag_exp: if dl_vlan >= 0: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) exp_pkt.push_vlan(dl_vlan_type) exp_pkt.set_vlan_vid(dl_vlan) exp_pkt.set_vlan_pcp(dl_vlan_pcp) else: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=dl_vlan_type, dl_vlan=dl_vlan, dl_vlan_pcp=dl_vlan_pcp) #Push one more tag in either case exp_pkt.push_vlan(exp_vlan_type) exp_pkt.set_vlan_vid(exp_vid) exp_pkt.set_vlan_pcp(exp_pcp) else: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=exp_vlan_type, dl_vlan=exp_vid, dl_vlan_pcp=exp_pcp) else: if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) exp_pkt.push_vlan(exp_vlan_type) exp_pkt.set_vlan_vid(exp_vid) exp_pkt.set_vlan_pcp(exp_pcp) else: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan_type=exp_vlan_type, dl_vlan=exp_vid, dl_vlan_pcp=exp_pcp) else: #subtract action if dl_vlan_int >= 0: exp_pkt = testutils.simple_tcp_packet( pktlen=len_w_vid, dl_vlan_enable=True, dl_vlan=dl_vlan_int, dl_vlan_pcp=dl_vlan_pcp_int) else: exp_pkt = testutils.simple_tcp_packet(pktlen=len, dl_vlan_enable=False) match = parse.packet_to_flow_match(pkt) parent.assertTrue(match is not None, "Flow match from pkt failed") match.wildcards = wildcards # Flow Mod for Table0 match.dl_vlan = vid_match_tbl0 match.dl_vlan_pcp = pcp_match_tbl0 inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list_tbl0, wildcards=wildcards, match=match, check_expire=check_expire_tbl0, table_id=0) testutils.flow_msg_install(parent, request0) # Flow Mod for Table1 match.dl_vlan = vid_match_tbl1 match.dl_vlan_pcp = pcp_match_tbl1 request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port, action_list=action_list_tbl1, wildcards=wildcards, match=match, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) testutils.flow_msg_install(parent, request1) parent.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) parent.dataplane.send(ing_port, str(pkt)) if match_exp_tbl0: if check_expire_tbl0: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request0, pkt_count=1, byte_count=pktlen) else: if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl0: flow_removed_verify(parent, request0, pkt_count=0, byte_count=0) elif exp_msg_tbl0 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl0)) if match_exp_tbl1: if check_expire_tbl1: #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. flow_removed_verify(parent, request1, pkt_count=1, byte_count=exp_pktlen) else: if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED: if check_expire_tbl1: flow_removed_verify(parent, request1, pkt_count=0, byte_count=0) elif exp_msg_tbl1 is ofp.OFPT_ERROR: error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1) else: parent.assertTrue(0, "Rcv: Unexpected Message: " + str(exp_msg_tbl1)) if match_exp_tbl0 and match_exp_tbl1: testutils.receive_pkt_verify(parent, egr_port, exp_pkt) else: (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1) parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
def runTest(self): of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # For making the test simpler... ing_port = of_ports[0] egr_port = of_ports[1] check_expire_tbl0 = False check_expire_tbl1 = False # Build the ingress packet pkt = testutils.simple_tcp_packet(**self.base_pkt_params) # Set action for the first table for item_tbl0 in self.start_pkt_params: tbl0_pkt_params = self.base_pkt_params.copy() tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0] act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params) action_list = [act] inst_1 = instruction.instruction_apply_actions() inst_2 = instruction.instruction_goto_table() inst_2.table_id = 1 inst_list = [inst_1, inst_2] request0 = testutils.flow_msg_create( self, pkt, ing_port=ing_port, instruction_list=inst_list, action_list=action_list, check_expire=check_expire_tbl0, table_id=0) mod_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params) for item_tbl1 in self.start_pkt_params: if item_tbl1 == item_tbl0: continue tbl1_pkt_params = tbl0_pkt_params.copy() tbl1_pkt_params[item_tbl1] = self.mod_pkt_params[item_tbl1] act = testutils.action_generate(self, item_tbl1, tbl1_pkt_params) self.assertTrue(act is not None, "Action not available") action_list = [act] request1 = testutils.flow_msg_create( self, mod_pkt, ing_port=ing_port, action_list=action_list, check_expire=check_expire_tbl1, table_id=1, egr_port=egr_port) exp_pkt = testutils.simple_tcp_packet(**tbl1_pkt_params) # Insert two flows self.logger.debug("Inserting flows: Modify-fields: TBL0= " + item_tbl0 + ", TBL1= " + item_tbl1) testutils.flow_msg_install(self, request0) testutils.flow_msg_install(self, request1) # Send pkt self.logger.debug("Send packet: " + str(ing_port) + " to " + str(egr_port)) self.dataplane.send(ing_port, str(pkt)) #@todo Not all HW supports both pkt and byte counters #@todo We shouldn't expect the order of coming response.. if check_expire_tbl0: flow_removed_verify(self, request0, pkt_count=1, byte_count=pktlen) if check_expire_tbl1: flow_removed_verify(self, request1, pkt_count=1, byte_count=exp_pktlen) # Receive and verify pkt testutils.receive_pkt_verify(self, egr_port, exp_pkt)
def runTest(self): #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))