Esempio n. 1
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, exact_port_map.keys(), exact_logger)#zhaoxiuchu
        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_CONTROLLER, 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))
         # checks no response from controller and dataplane
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        # self.assertIsNone() is preferable for newer python
        self.assertTrue(response is not None, "PacketIn message is not received")
        (_, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertFalse(rcv_pkt is not None, "Packet on dataplane")
Esempio n. 2
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)
Esempio n. 3
0
    def runTest(self):
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05',
                                          dl_dst='00:06:07:08:09:0a')

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_ACL_TABLE, ing_port=port_in)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE,
                               testutils.EX_L2_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_L2_TABLE, ing_port=port_in)
        exact_table_output(self,
                           testutils.EX_L2_TABLE,
                           match_ls,
                           egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        #print( str(pkt_rec).encode('hex'))
        self.assertTrue(pkt_rec is not None, "rec none packets")
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Esempio n. 4
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_DROP, True)
        'table 4 output'
        match_ls = testutils.packet_to_exact_flow_match(
            pkt, None, testutils.EX_VLAN_TABLE, 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))
        # checks no response from controller and dataplane
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        # self.assertIsNone() is preferable for newer python
        self.assertFalse(response is not None, "PacketIn message is received")
        (_, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertFalse(rcv_pkt is not None, "Packet on dataplane")
Esempio n. 5
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 test packet;"
        pkt = testutils.simple_tcp_packet(vlan_tags=vlan_tags,
                                          mpls_tags=mpls_tags)

        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)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_L2_TABLE, ing_port=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=pkt, table_id=testutils.EX_VLAN_TABLE, ing_port=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=pkt, table_id=testutils.EX_MPLS_TABLE, ing_port=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=pkt, table_id=testutils.EX_L3_TABLE, ing_port=ing_port)
        exact_table_output(self,
                           testutils.EX_L3_TABLE,
                           match_ls,
                           egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        self.assertTrue(pkt_rec is not None, "rec none packets")
        #print("++++++++++++++++++++++rcv_pkt++++++++++++++++++++++")
        #if pkt_rec is None:
        #   print(str(pkt_rec))
        #else:
        #   print(str(pkt_rec).encode('hex'))
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Esempio n. 6
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)
Esempio n. 7
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = 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(ip_src='192.168.0.99')
        match_ls = testutils.packet_to_exact_flow_match(pkt=pkt,
                                                        table_id=table_id,
                                                        ing_port=port_in)

        exact_table_output(self, table_id, match_ls, egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        response, _ = self.controller.transact(stat_req, timeout=2)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        self.assertTrue(pkt_rec is not None, "rec none packet")
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Esempio n. 8
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = 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')
        exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='aa:aa:aa:aa:aa:aa')
        # get match list
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in)

        act = action.action_set_field()
        field = match.eth_dst(parse.parse_mac("aa:aa:aa:aa:aa:aa"))
        act.field.add(field)
        exact_table_output(self, table_id, match_ls, actions = [act], egr_port = egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)

        self.assertTrue(pkt is not None,"rec none packets")
        self.assertEqual(str(exp_pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Esempio n. 9
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = 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(ip_src='192.168.0.99')
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in)

        exact_table_output(self, table_id, match_ls, egr_port = egr_port)

        testutils.do_barrier(self.controller)

        "get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        response, _ = self.controller.transact(stat_req, timeout=2)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)
        self.assertTrue(pkt_rec is not None,"rec none packet")
        self.assertEqual(str(pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Esempio n. 10
0
    def runTest(self):
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        table_id = testutils.EX_ACL_TABLE
        of_ports = exact_port_map.keys()
        port_in = of_ports[0]
        egr_port = of_ports[1]
        vlan_tags=[{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]

        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99', dl_dst='00:06:07:08:09:aa', \
                                               vlan_tags = [], mpls_tags = [])

        match_ls = testutils.packet_to_exact_flow_match(pkt, None, testutils.EX_L2_TABLE, port_in)

        exact_table_output(self, table_id, match_ls, egr_port = egr_port)

        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPP_ANY
        
        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
        self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats)))
Esempio n. 11
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)
Esempio n. 12
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port = of_ports[2]

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.EX_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_VLAN_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_MPLS_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata();
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst = inst_write_metadata)

        pkt_metadata = {'metadata_val':inst_write_metadata.metadata, 
                        'metadata_msk':inst_write_metadata.metadata_mask}
        match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata, table_id = testutils.EX_L3_TABLE)
        testutils.write_output(self, testutils.EX_L3_TABLE, egr_port, match_fields=match_fields)

        testutils.reply_check_dp(self, tcp_sport=1234, ing_port = ing_port, egr_port = egr_port)
        
        testutils.set_table_config(self, testutils.EX_L3_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER)
Esempio n. 13
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port =ofp.OFPP_CONTROLLER

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_DROP, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata();
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, ing_port, add_inst = inst_write_metadata)

        pkt_metadata = {'metadata_val':inst_write_metadata.metadata, 'metadata_msk':inst_write_metadata.metadata_mask}
        match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata, table_id = testutils.EX_L2_TABLE)
        testutils.write_output(self, testutils.EX_L2_TABLE, egr_port, match_fields=match_fields)
        
        self.dataplane.send(ing_port, str(pkt))
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        self.assertTrue(response is not None, 'Packet in message not received on port ' + str(egr_port))
        if str(pkt) != response.data:
               pa_logger.debug("pkt  len " + str(len(str(pkt))) +": " + str(pkt))
               pa_logger.debug("resp len " + str(len(str(response.data))) + ": " + str(response.data))
Esempio n. 14
0
    def runTest(self):
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        table_id = testutils.EX_ACL_TABLE
        of_ports = exact_port_map.keys()
        port_in = of_ports[0]
        egr_port = of_ports[1]
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]

        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99', dl_dst='00:06:07:08:09:aa', \
                                               vlan_tags = [], mpls_tags = [])

        match_ls = testutils.packet_to_exact_flow_match(
            pkt, None, testutils.EX_L2_TABLE, port_in)

        exact_table_output(self, table_id, match_ls, egr_port=egr_port)

        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPP_ANY

        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 1,
                         "len of stats is:" + str(len(response.stats)))
Esempio n. 15
0
    def runTest(self):
        """
        Add four flow entries:
        First Table; Match IP Src A; send to 1, goto Second Table
        Second Table; Match IP Src A; write metadata, goto Third Table
        Third Table; Match IP Src A and metadata; send to 2 // stop, do action
        Fourth Table; Match IP Src A; send to 1 // not match, just a trap

        Then send in 2 packets:
        IP A, TCP C; expect out port 2
        IP A, TCP B; expect out port 2

        @param self object instance
        @param EX_ACL_TABLE first table
        @param WC_ACL_TABLE second table
        @param WC_SERV_TABLE third table
        @param EX_VLAN_TABLE fourth table
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto_output(self, testutils.WC_ACL_TABLE,
                                    testutils.WC_SERV_TABLE, of_ports[0])

        # Set up second match
        inst = instruction.instruction_write_metadata()
        inst.metadata = 0xfedcba9876543210
        inst.metadata_mask = 0xffffffffffffffff
        testutils.write_goto(self,
                             testutils.WC_SERV_TABLE,
                             testutils.EX_L2_TABLE,
                             of_ports[2],
                             add_inst=inst)

        # Set up third match
        pkt_metadata = {
            'metadata_val': inst.metadata,
            'metadata_msk': inst.metadata_mask
        }
        match_fields = testutils.packet_to_exact_flow_match(
            pkt_metadata=pkt_metadata, table_id=testutils.EX_L2_TABLE)

        testutils.write_output(self,
                               testutils.EX_L2_TABLE,
                               of_ports[1],
                               match_fields=match_fields)

        # Set up fourth match
        #write_output(self, testutils.EX_VLAN_TABLE, of_ports[0])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        testutils.reply_check_dp(self,
                                 tcp_sport=1234,
                                 ing_port=of_ports[2],
                                 egr_port=of_ports[1])
Esempio n. 16
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port = of_ports[2]

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.EX_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_VLAN_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_MPLS_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.EX_L3_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata()
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self,
                             testutils.WC_SERV_TABLE,
                             testutils.EX_L2_TABLE,
                             ing_port,
                             add_inst=inst_write_metadata)

        pkt_metadata = {
            'metadata_val': inst_write_metadata.metadata,
            'metadata_msk': inst_write_metadata.metadata_mask
        }
        match_fields = testutils.packet_to_exact_flow_match(
            pkt_metadata=pkt_metadata, table_id=testutils.EX_L3_TABLE)
        testutils.write_output(self,
                               testutils.EX_L3_TABLE,
                               egr_port,
                               match_fields=match_fields)

        testutils.reply_check_dp(self,
                                 tcp_sport=1234,
                                 ing_port=ing_port,
                                 egr_port=egr_port)

        testutils.set_table_config(self, testutils.EX_L3_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER)
Esempio n. 17
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 test packet;"
        pkt = testutils.simple_tcp_packet(vlan_tags = vlan_tags, mpls_tags = mpls_tags)

        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)

        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_L2_TABLE, ing_port = 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 = pkt, table_id = testutils.EX_VLAN_TABLE, ing_port = 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 = pkt, table_id = testutils.EX_MPLS_TABLE, ing_port = 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 = pkt, table_id = testutils.EX_L3_TABLE, ing_port = ing_port)
        exact_table_output(self, testutils.EX_L3_TABLE, match_ls, egr_port = egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)
        self.assertTrue(pkt_rec is not None,"rec none packets")
        #print("++++++++++++++++++++++rcv_pkt++++++++++++++++++++++")
        #if pkt_rec is None:
        #   print(str(pkt_rec))
        #else:
        #   print(str(pkt_rec).encode('hex'))
        self.assertEqual(str(pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Esempio n. 18
0
    def runTest(self):
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a')

        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_ACL_TABLE, ing_port = port_in)
        exact_table_goto_table(self, testutils.EX_ACL_TABLE, testutils.EX_L2_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_L2_TABLE, ing_port = port_in)
        exact_table_output(self, testutils.EX_L2_TABLE, match_ls, egr_port = egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)
        #print( str(pkt_rec).encode('hex'))
        self.assertTrue(pkt_rec is not None,"rec none packets")
        self.assertEqual(str(pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Esempio n. 19
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)
Esempio n. 20
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        ing_port = of_ports[1]
        egr_port = ofp.OFPP_CONTROLLER

        "clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # Set table config as "continue"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE,
                                   ofp.OFPTC_TABLE_MISS_DROP, True)
        testutils.set_table_config(self, testutils.EX_L2_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        #"make test packet;"
        pkt = testutils.simple_icmp_packet()

        inst_write_metadata = instruction.instruction_write_metadata()
        inst_write_metadata.metadata = 0x20000000
        inst_write_metadata.metadata_mask = 0xf0000000

        testutils.write_goto(self,
                             testutils.WC_SERV_TABLE,
                             testutils.EX_L2_TABLE,
                             ing_port,
                             add_inst=inst_write_metadata)

        pkt_metadata = {
            'metadata_val': inst_write_metadata.metadata,
            'metadata_msk': inst_write_metadata.metadata_mask
        }
        match_fields = testutils.packet_to_exact_flow_match(
            pkt_metadata=pkt_metadata, table_id=testutils.EX_L2_TABLE)
        testutils.write_output(self,
                               testutils.EX_L2_TABLE,
                               egr_port,
                               match_fields=match_fields)

        self.dataplane.send(ing_port, str(pkt))
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        self.assertTrue(
            response is not None,
            'Packet in message not received on port ' + str(egr_port))
        if str(pkt) != response.data:
            pa_logger.debug("pkt  len " + str(len(str(pkt))) + ": " + str(pkt))
            pa_logger.debug("resp len " + str(len(str(response.data))) + ": " +
                            str(response.data))
Esempio n. 21
0
    def runTest(self):
        """
        Add four flow entries:
        First Table; Match IP Src A; send to 1, goto Second Table
        Second Table; Match IP Src A; write metadata, goto Third Table
        Third Table; Match IP Src A and metadata; send to 2 // stop, do action
        Fourth Table; Match IP Src A; send to 1 // not match, just a trap

        Then send in 2 packets:
        IP A, TCP C; expect out port 2
        IP A, TCP B; expect out port 2

        @param self object instance
        @param EX_ACL_TABLE first table
        @param WC_ACL_TABLE second table
        @param WC_SERV_TABLE third table
        @param EX_VLAN_TABLE fourth table
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto_output(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE, of_ports[0])

        # Set up second match
        inst = instruction.instruction_write_metadata()
        inst.metadata = 0xfedcba9876543210
        inst.metadata_mask = 0xffffffffffffffff
        testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, of_ports[2], add_inst=inst)

        # Set up third match
        pkt_metadata = {'metadata_val':inst.metadata, 'metadata_msk':inst.metadata_mask}
        match_fields = testutils.packet_to_exact_flow_match(pkt_metadata = pkt_metadata,
                                                            table_id = testutils.EX_L2_TABLE)

        testutils.write_output(self, testutils.EX_L2_TABLE, of_ports[1], match_fields=match_fields)

        # Set up fourth match
        #write_output(self, testutils.EX_VLAN_TABLE, of_ports[0])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        testutils.reply_check_dp(self, tcp_sport=1234,
                       ing_port = of_ports[2], egr_port = of_ports[1])
Esempio n. 22
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        match_fields = testutils.packet_to_exact_flow_match(pkt)
        self.assertTrue(match_fields is not None,
                        "Could not generate flow match from pkt")
        act1 = action.action_output()
        act2 = action.action_output()

        for idx in range(len(of_ports)):
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            ingress_port = of_ports[idx]
            egress_port1 = of_ports[(idx + 1) % len(of_ports)]
            egress_port2 = of_ports[(idx + 2) % len(of_ports)]
            pa_logger.info("Ingress " + str(ingress_port) + " to egress " +
                           str(egress_port1) + " and " + str(egress_port2))

            act1.port = egress_port1
            act2.port = egress_port2
            request = testutils.flow_msg_create(
                self,
                pkt,
                ing_port=ingress_port,
                action_list=[act1, act2],
                inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION)

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, request)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            yes_ports = set([egress_port1, egress_port2])
            no_ports = set(of_ports).difference(yes_ports)

            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports,
                                        no_ports, self, pa_logger)
Esempio n. 23
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        match_fields = testutils.packet_to_exact_flow_match(pkt)
        self.assertTrue(match_fields is not None,
                        "Could not generate flow match from pkt")
        act1 = action.action_output()
        act2 = action.action_output()

        for idx in range(len(of_ports)):
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            ingress_port = of_ports[idx]
            egress_port1 = of_ports[(idx + 1) % len(of_ports)]
            egress_port2 = of_ports[(idx + 2) % len(of_ports)]
            pa_logger.info("Ingress " + str(ingress_port) +
                           " to egress " + str(egress_port1) + " and " +
                           str(egress_port2))

            act1.port = egress_port1
            act2.port = egress_port2
            request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port,
                            action_list=[act1, act2], inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION)

            pa_logger.info("Inserting flow")
            testutils.ofmsg_send(self, request)

            pa_logger.info("Sending packet to dp port " +
                           str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            yes_ports = set([egress_port1, egress_port2])
            no_ports = set(of_ports).difference(yes_ports)

            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports,
                              self, pa_logger)
Esempio n. 24
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = 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')
        exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05',
                                              dl_dst='aa:aa:aa:aa:aa:aa')
        # get match list
        match_ls = testutils.packet_to_exact_flow_match(pkt=pkt,
                                                        table_id=table_id,
                                                        ing_port=port_in)

        act = action.action_set_field()
        field = match.eth_dst(parse.parse_mac("aa:aa:aa:aa:aa:aa"))
        act.field.add(field)
        exact_table_output(self,
                           table_id,
                           match_ls,
                           actions=[act],
                           egr_port=egr_port)

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)

        self.assertTrue(pkt is not None, "rec none packets")
        self.assertEqual(str(exp_pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Esempio n. 25
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)
Esempio n. 26
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")
Esempio n. 27
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")
Esempio n. 28
0
def write_action_test_multi_tables(parent, ing_port, egr_port,
        match_fields = 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_fields 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]
        match_fields = testutils.packet_to_exact_flow_match(pkt,None,table_id,ing_port)
        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_fields=match_fields,
                              check_expire=check_expire,
                              table_id=table_id)
        request_list.append(request)
        #print("request::\n%s" % request_list[table_id].show())
        testutils.flow_msg_install(parent, request_list[table_id], True)

        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=len(pkt))

    testutils.receive_pkt_verify(parent, egr_port, exp_pkt)
Esempio n. 29
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)