Example #1
0
    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)
Example #2
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")
Example #3
0
    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")    
Example #4
0
    def runTest(self):
        
        of_ports = pa_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, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all
        flow_match = "wildcards=none,dl_src_mask=ff:ff:ff:ff:ff:ff,dl_dst_mask=ff:ff:ff:ff:ff:ff,nw_src_mask=255.255.255.255,nw_dst_mask=255.255.255.255,meta_mask=0xffffffffffffffff" #, -in_port,in_port=1,dl_type=2048in_port=0  wildcards=0xffff
        flow_acts = "apply:output=" + str(egr_port)
        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
        pkt = testutils.simple_tcp_packet()
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = testutils.simple_tcp_packet()
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        rc = nxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #5
0
    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")
Example #6
0
 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)
Example #7
0
    def runTest(self):
        
        of_ports = pa_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, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match 
        flow_match = "wildcards=none,nw_src_ipv6=fe80::2420:52ff:fe8f:5189,nw_dst_ipv6=fe80::2420:52ff:fe8f:5190"
        flow_acts = "apply:output=" + str(egr_port)
        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
        pkt = simple_ipv6_packet(EH = True)
        pa_logger.info("Sending IPv6 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = simple_ipv6_packet(EH = True)
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        rc = nxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #8
0
    def runTest(self):
        
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[3]
        
        # Remove all entries Add entry match all
        rc = dpctl.oxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all
        flow_match = "dl_type=0x0800,nw_src=192.168.0.1"
        flow_acts = "apply:output=" + str(egr_port)
        rc = dpctl.oxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
        pkt = testutils.simple_tcp_packet()
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = testutils.simple_tcp_packet()
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        dpctl.request_flow_stats()
        
        #Remove flows
        rc = dpctl.oxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #9
0
    def runTest(self):

        # Config
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port = of_ports[1]
        
        rc = dpctl.oxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")

        flow_match = "in_port=" + str(ing_port)
        flow_acts = "apply:output=" + str(egr_port)
        rc = dpctl.oxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")
        
        pkt = testutils.simple_tcp_packet()
        
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))

        pkt = testutils.simple_tcp_packet()
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        exp_pkt = testutils.simple_tcp_packet()
        
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        dpctl.request_flow_stats()
        
        rc = dpctl.oxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #10
0
    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)
Example #11
0
    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")
Example #12
0
    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)
Example #13
0
def reply_check_dp(parent, ip_src=MT_TEST_IP, tcp_sport=10,
                   exp_pkt=None, ing_port=0, egr_port=1):
    """
    Receiving and received packet check on dataplane
    """
    pkt = testutils.simple_tcp_packet(ip_src=ip_src, tcp_sport=tcp_sport)
    parent.dataplane.send(ing_port, str(pkt))
    if exp_pkt is None:
        exp_pkt = pkt
    testutils.receive_pkt_verify(parent, egr_port, exp_pkt)
Example #14
0
    def runTest(self):
        
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port =   of_ports[2]
        
        self.of_dir = os.path.normpath("../../of11softswitch")
        self.ofd = os.path.normpath(self.of_dir + "/udatapath/ofdatapath")
        self.dpctl = os.path.normpath(self.of_dir + "/utilities/dpctl")
        dpctl_switch = "unix:/tmp/ofd"

        # Remove all entries Add entry match all
        # sudo ./dpctl unix:/tmp/ofd flow-mod cmd=del,table=0
#        flow_cmd1 = "flow-mod"
#        flow_cmd2 = "cmd=del,table=0"
#        pcall = [self.dpctl, dpctl_switch, flow_cmd1, flow_cmd2]
#        subprocess.call(pcall)  

        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all
        flow_cmd1 = "flow-mod"
        flow_cmd2 = "cmd=add,table=0,idle=100"
        flow_match = "wildcards=+all,dl_src_mask=FF:FF:FF:FF:FF:FF,dl_dst_mask=FF:FF:FF:FF:FF:FF,nw_src_mask=255.255.255.255,nw_dst_mask=255.255.255.255" #, -in_port,in_port=1,dl_type=2048in_port=0  wildcards=0xffff
        flow_acts = "apply:output=" + str(egr_port)

        pcall = [self.dpctl, dpctl_switch, flow_cmd1, flow_cmd2, flow_match,  flow_acts]
        print pcall
        subprocess.call(pcall)

        #Send packet
        pkt = testutils.simple_tcp_packet()
        pa_logger.info("Sending IPv4 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        exp_pkt = testutils.simple_tcp_packet()
        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        pa_logger.debug("Request stats-flow")  
        pcall = [self.dpctl, dpctl_switch, "stats-flow"]  #  
        subprocess.call(pcall)
        
        #Remove flows
        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #15
0
    def runTest(self):
        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[1])

        # Set up third match
        testutils.write_output(self, testutils.EX_L2_TABLE, of_ports[2])
        
        # Generate a packet and receive 3 responses
        pkt = testutils.simple_tcp_packet(ip_src = testutils.MT_TEST_IP)
        self.dataplane.send(of_ports[1], str(pkt))

        testutils.receive_pkt_verify(self, of_ports[2], pkt)
Example #16
0
    def runTest(self):
               
	# Config
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port =   of_ports[3]
        
        # Remove flows
        rc = nxm_delete_all_flows()
#        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all 
	#sudo dpctl unix:/tmp/ofd -F nxm flow-mod cmd=add,table=0,idle=100 wildcards=none,in_port=1,hbh_ipv6 apply:output=4

        flow_match = "wildcards=none,in_port=1,rh_ipv6"
        flow_acts = "apply:output=" + str(egr_port)

        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
	pkt = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrRouting()) 

 	print "Sending IPv6 packet to " + str(ing_port)
        pa_logger.info("Sending IPv6 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        
	self.dataplane.send(ing_port, str(pkt))


        #Receive packet
        exp_pkt = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrRouting()) 

        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        rc = nxm_delete_all_flows()
#        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #17
0
    def runTest(self):

        # Config
        of_ports = pa_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, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

	# Add Entry wich matches packets with hbh_code = 0

        flow_match = "wildcards=none,dl_type=0x86DD,rh_ipv6,rh_add_ipv6=ff01::0001"
        flow_acts = "apply:output=" + str(egr_port)

        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

	#Send IPv6 packet with Routing Header

        pkt = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrRouting(addresses=['ff01::0001','ff02::0000']))

        pa_logger.info("Sending IPv6 RH packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #See flow match
        request_flow_stats()
	
	#Receive packet
        exp_pktv6 = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrRouting(addresses=['ff01::0001','ff02::0000'])) 

        testutils.receive_pkt_verify(self, egr_port, exp_pktv6)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        rc = nxm_delete_all_flows()
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #18
0
    def runTest(self):
        	# Config
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port =   of_ports[3]
        
        # Remove flows
        rc = nxm_delete_all_flows()
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all 
        flow_match = "wildcards=none,in_port=1,tp_src=80,tp_dst=8080"
        flow_acts = "apply:output=" + str(egr_port)

        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

        #Send packet
        pkt = simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 

        print "Sending IPv6 packet to " + str(ing_port)
        pa_logger.info("Sending IPv6 packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        
        self.dataplane.send(ing_port, str(pkt))

        #Receive packet
        #exp_pkt = simple_ipv6_packet()
        exp_pkt = simple_ipv6_packet(tcp_sport=80, tcp_dport=8080) 

        testutils.receive_pkt_verify(self, egr_port, exp_pkt)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        #rc = testutils.delete_all_flows(self.controller, pa_logger)
        rc = nxm_delete_all_flows()        
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #19
0
    def scenario3(self, first_table = 0, second_table = 1, third_table = 2):
        """
        Add three flow entries:
        First Table; Match IP Src A; send to 0 now, goto Second Table
        Second Table; Match IP Src A; send to 1 now, goto Third Table
        Third Table; Match IP src A; send to 2 now

        Then send a packet:
        IP A;  expect out port 0, 1, and 2

        @param self object instance
        @param first_table first table
        @param second_table second table
        @param third_table third table
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up matches
        inst = instruction.instruction_goto_table()
        inst.table_id = second_table
        self.set_apply_output(first_table, of_ports[0], inst)
        # Set up second match
        inst.table_id = third_table
        self.set_apply_output(second_table, of_ports[1], inst)
        # Set up third match
        self.set_apply_output(third_table, of_ports[2])

        # Generate a packet and receive 3 responses
        pkt = testutils.simple_tcp_packet(ip_src=MT_TEST_IP, tcp_sport=10)
        self.dataplane.send(of_ports[3], str(pkt))

        testutils.receive_pkt_verify(self, of_ports[0], pkt)
        testutils.receive_pkt_verify(self, of_ports[1], pkt)
        testutils.receive_pkt_verify(self, of_ports[2], pkt)
Example #20
0
    def scenario3(self, first_table=0, second_table=1, third_table=2):
        """
        Add three flow entries:
        First Table; Match IP Src A; send to 0 now, goto Second Table
        Second Table; Match IP Src A; send to 1 now, goto Third Table
        Third Table; Match IP src A; send to 2 now

        Then send a packet:
        IP A;  expect out port 0, 1, and 2

        @param self object instance
        @param first_table first table
        @param second_table second table
        @param third_table third table
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up matches
        inst = instruction.instruction_goto_table()
        inst.table_id = second_table
        self.set_apply_output(first_table, of_ports[0], inst)
        # Set up second match
        inst.table_id = third_table
        self.set_apply_output(second_table, of_ports[1], inst)
        # Set up third match
        self.set_apply_output(third_table, of_ports[2])

        # Generate a packet and receive 3 responses
        pkt = testutils.simple_tcp_packet(ip_src=MT_TEST_IP, tcp_sport=10)
        self.dataplane.send(of_ports[3], str(pkt))

        testutils.receive_pkt_verify(self, of_ports[0], pkt)
        testutils.receive_pkt_verify(self, of_ports[1], pkt)
        testutils.receive_pkt_verify(self, of_ports[2], pkt)
Example #21
0
    def runTest(self):
        vlan_tags=[{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        'make packet'
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a', \
                                            vlan_tags = vlan_tags, mpls_tags = mpls_tags)
        'table 0 goto table3'
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_ACL_TABLE, ing_port = ing_port)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE, testutils.EX_L2_TABLE, match_ls)
        "set table 3 not match, continue"
        testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        'table 4 output'
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_VLAN_TABLE, ing_port = ing_port)
        exact_table_output(self, testutils.EX_VLAN_TABLE, match_ls, egr_port = egr_port)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        'verify the rec data'
        testutils.receive_pkt_verify(self, egr_port, pkt)
Example #22
0
    def runTest(self):
        of_ports = exact_port_map.keys()
        ing_port = of_ports[0]
        egr_port = of_ports[1]
        table_id = testutils.EX_ACL_TABLE

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet()
        "construct flow entry"
        match_ls = testutils.packet_to_exact_flow_match(pkt, None, table_id, ing_port)
        flow_add = testutils.flow_msg_create(self, pkt, match_fields = match_ls, egr_port = egr_port, table_id = table_id)

        testutils.ofmsg_send(self, flow_add)

        "read flow back;"
        response = testutils.flow_stats_get(self, match_ls, table_id)
        self.assertTrue(len(response.stats) != 0, "stats len is 0")

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        "poll from the egr_port port"
        testutils.receive_pkt_verify(self, egr_port, pkt)
Example #23
0
    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)
Example #24
0
    def runTest(self):

        # Config
        of_ports = pa_port_map.keys()
        of_ports.sort()
        ing_port = of_ports[0]
        egr_port =   of_ports[3]
        
        # Remove flows
        rc = nxm_delete_all_flows()
#        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        # Add entry match all 
	#sudo dpctl unix:/tmp/ofd -F nxm flow-mod cmd=add,table=0,idle=100 wildcards=none,in_port=1,hbh_ipv6 apply:output=4

        flow_match = "wildcards=none,hbh_ipv6,rh_ipv6"
        flow_acts = "apply:output=" + str(egr_port)

        rc = nxm_send_flow_mod_add(flow_match,flow_acts,pa_logger)
        self.assertEqual(rc, 0, "Failed to add flow entry")

	#Send IPv6 packet with Routing Header

        pkt = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrRouting())

        pa_logger.info("Sending IPv6 RH packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        self.dataplane.send(ing_port, str(pkt))
        
        #Receive packet
        #exp_pkt = testutils.simple_tcp_packet()
	testutils.receive_pkt_check(self.dataplane, pkt, [], of_ports, self,
                              pa_logger)

        #See flow match
        request_flow_stats()
	
	#Send IPv6 packet with both Headers
        #pkt = simple_ipv6_packet()        
	pktv6 = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrHopByHop()/scapy.IPv6ExtHdrRouting()) 
        print "Sending IPv6 HBH+RH packet to " + str(ing_port)
        pa_logger.info("Sending IPv6 HBH+RH packet to " + str(ing_port))
        pa_logger.debug("Data: " + str(pkt).encode('hex'))
        
	self.dataplane.send(ing_port, str(pktv6))


        #Receive packet
        #exp_pkt = simple_ipv6_packet()
        exp_pktv6 = simple_ipv6_packet(EH = True,  EHpkt = scapy.IPv6ExtHdrHopByHop()/scapy.IPv6ExtHdrRouting()) 

        testutils.receive_pkt_verify(self, egr_port, exp_pktv6)

        #See flow match
        request_flow_stats()
        
        #Remove flows
        rc = nxm_delete_all_flows()
#        rc = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")
Example #25
0
 def recv_data(self, port, expected = None):
     pkt = testutils.receive_pkt_verify(self, port, expected)
     return pkt
Example #26
0
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")
Example #27
0
    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")
Example #28
0
    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)
Example #29
0
    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")
Example #30
0
 def recv_data(self, port, expected = None):
     pkt = testutils.receive_pkt_verify(self, port, expected)
     return pkt
Example #31
0
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")
Example #32
0
    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")
Example #33
0
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")
Example #34
0
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")
Example #35
0
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")
Example #36
0
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)
Example #37
0
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")