Exemplo n.º 1
0
    def runTest(self):
        self.clear_switch()

        group_add_msg2 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_TP_SRC, tp_port = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg2, 'group add')

        group_add_msg1 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_GROUP, group_id = 2),
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg1, 'group add')

        packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out = testutils.simple_tcp_packet(tcp_sport=2000)

        flow_add_msg = \
        create_flow_msg(packet = packet_in, in_port = 1, apply_action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1)
        ])

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)

        self.recv_data(2, packet_out)
Exemplo n.º 2
0
    def runTest(self):
        self.clear_switch()

        group_add_msg = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_INDIRECT, group_id = 1, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_TP_SRC, tp_port = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

        packet_in  = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
        
        flow_add_msg = \
        create_flow_msg(packet = packet_in, in_port = 1, apply_action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1)
        ])

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out)
Exemplo n.º 3
0
    def runTest(self):
        self.clear_switch()

        group_add_msg2 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg2, 'group add')

        group_add_msg1 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_GROUP, group_id = 2),
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg1, 'group add')

        packet_in  = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
        
        flow_add_msg = \
        testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1)
        ])
        
        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out)
Exemplo n.º 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")
Exemplo n.º 5
0
    def runTest(self):
        testutils.clear_switch(self,group_port_map,group_logger)
#        self.clear_switch()

        group_add_msg = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_INDIRECT, group_id = 1, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

        packet_in  = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
        
        flow_add_msg = \
        testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1)
        ])

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out)
Exemplo n.º 6
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')
Exemplo n.º 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 = 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")
Exemplo n.º 8
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")
Exemplo n.º 9
0
    def scenario2(self, first_table=0, second_table=1, tos1=4, tos2=8):
        """
        Add flow entries:
        First Table; Match IP Src A; set ToS = tos1, goto Second Table
        First Table; Match IP Src B; set ToS = tos2, goto Second Table
        Second Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1

        Then send packets:
        IP A;  expect port 1 with ToS = tos1
        IP B;  expect port 1 with ToS = tos2

        @param self object instance
        @param first_table first table
        @param second_table second table
        @param tos1 ToS value to be set for first flow
        @param tos2 ToS value to be set for second flow
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up flow match in table A: set ToS
        t_act = action.action_set_nw_tos()
        t_act.nw_tos = tos1
        write_goto_action(self,
                          first_table,
                          second_table,
                          t_act,
                          ip_src='192.168.1.10')
        t_act.nw_tos = tos2
        write_goto_action(self,
                          first_table,
                          second_table,
                          t_act,
                          ip_src='192.168.1.30')

        # Set up flow matches in table B: routing
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.10")
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.30")

        # Generate packets and check them
        exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10',
                                              tcp_sport=10,
                                              ip_tos=tos1)
        reply_check_dp(self,
                       ip_src='192.168.1.10',
                       tcp_sport=10,
                       exp_pkt=exp_pkt,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])

        exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.30',
                                              tcp_sport=10,
                                              ip_tos=tos2)
        reply_check_dp(self,
                       ip_src='192.168.1.30',
                       tcp_sport=10,
                       exp_pkt=exp_pkt,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
Exemplo n.º 10
0
    def runTest(self):
        #async_logger.info("Running Async_NoPacketIn")

        #verifying without set_async_request, switch will packet in
        #step 1-1:clear all flow entries for unmatching
        of_ports = testutils.clear_switch(self, async_port_map.keys(), async_logger)

        #step 2-1:controller sends set_async_request msg
        async_logger.info("Sending set_async_request")
        mask = 1 << ofp.OFPR_NO_MATCH
        request_set = create_set_async(pkt_in_mstr = mask)
        #print(request_set.show())
        set_async_verify(self, request_set)

        #result 2-1: contrller sends msg successfully
        
        #no match default deal:drop; add flow entry to packet_in
        #step 3-1: install default mismatch flow entry ,action=packetin;
        testutils.set_table_config(self, config = ofp.OFPTC_TABLE_MISS_CONTROLLER)

        #send data to port
        for of_port in of_ports:
            async_logger.info("PKT IN test, port " + str(of_port))
            pkt = testutils.simple_tcp_packet()
            self.dataplane.send(of_port, str(pkt))
            #@todo Check for unexpected messages?
            testutils.packetin_verify(self, pkt)
            #print(response)

        #"verifying with set_async_request, switch will packet in"
        #step 1-2:clear all flow entries for unmatching
        rc = testutils.clear_switch(self, async_port_map.keys(), async_logger)

        #step 2-2:controller sends set_async_request msg
        async_logger.info("Sending set_async_request")
        mask = 0xffffffff ^ (1 << ofp.OFPR_NO_MATCH)
        request_set = create_set_async(pkt_in_mstr = mask)
        set_async_verify(self, request_set)
        #print("2-2 request_set"+request_set.show())
        #result 2-2: contrller sends msg successfully
        
        #no match default deal:drop; add flow entry to packet_in
        #step 3-2: install default mismatch flow entry ,action=packetin;
        testutils.set_table_config(self, config = ofp.OFPTC_TABLE_MISS_CONTROLLER)

        #(response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
        #send data to port
        for of_port in async_port_map.keys():
            async_logger.info("PKT IN test, port " + str(of_port))
            pkt = testutils.simple_tcp_packet()
            self.dataplane.send(of_port, str(pkt))
            #@todo Check for unexpected messages?
            (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
            #print(response)
            self.assertTrue(response is None, 'Packet in message received unexpected')

        msg = create_set_async()
        set_async_verify(self, msg)
Exemplo n.º 11
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)
Exemplo n.º 12
0
    def runTest(self):
        self.clear_switch()

        group_add_msg2 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')

        group_add_msg3 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 3, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ]),
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 4000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 4)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg3, 'group add 3')

        group_add_msg1 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_GROUP, group_id = 2),
            ]),
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_GROUP, group_id = 3),
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')

        packet_in  = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out1 = testutils.simple_tcp_packet(tcp_sport=2000)
        packet_out2 = testutils.simple_tcp_packet(tcp_sport=3000)
        packet_out3 = testutils.simple_tcp_packet(tcp_sport=4000)
        
        flow_add_msg = \
        testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1)
        ])

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out1)
        self.recv_data(3, packet_out2)
        self.recv_data(4, packet_out3)
Exemplo n.º 13
0
    def runTest(self):
        self.clear_switch()

        group_add_msg2 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_TP_SRC, tp_port = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')

        group_add_msg3 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 3, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_TP_SRC, tp_port = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ]),
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_TP_SRC, tp_port = 4000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 4)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg3, 'group add 3')

        group_add_msg1 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_GROUP, group_id = 2),
            ]),
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_GROUP, group_id = 3),
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')

        packet_in  = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out1 = testutils.simple_tcp_packet(tcp_sport=2000)
        packet_out2 = testutils.simple_tcp_packet(tcp_sport=3000)
        packet_out3 = testutils.simple_tcp_packet(tcp_sport=4000)
        
        flow_add_msg = \
        create_flow_msg(packet = packet_in, in_port = 1, apply_action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1),
        ])

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out1)
        self.recv_data(3, packet_out2)
        self.recv_data(4, packet_out3)
Exemplo n.º 14
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]

        pktlen = 104
        dl_vlan = 0xa5a # no specific meaning
        dl_vlan_pcp=3
        pkt = testutils.simple_tcp_packet(pktlen=pktlen,
                                          dl_vlan_enable=True,
                                          dl_vlan=dl_vlan,
                                          dl_vlan_pcp=dl_vlan_pcp)

        match = parse.packet_to_flow_match(pkt)
        wildcards = 0

        exp_pkt = testutils.simple_tcp_packet(pktlen=pktlen,
                                              dl_vlan_enable=True)

        # Create parameters for each table
        act_list = []
        next_avail = []
        chk_expire = []

        #Table 0
        act = action.action_output()
        act.port = egr_port
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 1
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_pop_vlan()
        act_list.append([act])
        next_avail.append(False)
        chk_expire.append(False)

        write_action_test_multi_tables(self, ing_port, egr_port,
            match = match,
            wildcards = wildcards,
            act_list = act_list,
            next_avail = next_avail,
            chk_expire = chk_expire,
            pkt = pkt,
            exp_pkt = exp_pkt)
Exemplo n.º 15
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]

        dl_vlan = random.randint(1,0x7ff)
        dl_vlan_pcp = random.randint(0,7)
        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': dl_vlan, 'pcp': dl_vlan_pcp}])

        match_ls = parse.packet_to_flow_match(pkt)
        wildcards = 0

        new_dl_vlan = random.randint(0x800,0xfff)
        exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'type': ETHERTYPE_VLAN, 'vid': new_dl_vlan, 'pcp': dl_vlan_pcp},
                                                         {'vid': dl_vlan, 'pcp': dl_vlan_pcp}])

        # Create parameters for each table
        act_list = []
        next_avail = []
        chk_expire = []

        #Table 0
        act = action.action_output()
        act.port = egr_port
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 1
        #act = action.action_set_vlan_vid()
        #act.vlan_vid = new_dl_vlan
        act = action.action_set_field()
        act.field = match.vlan_vid(new_dl_vlan + ofp.OFPVID_PRESENT)
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN
        act_list.append([act])
        next_avail.append(False)
        chk_expire.append(False)

        write_action_test_multi_tables(self, ing_port, egr_port,
            match_fields = match_ls,
            wildcards = wildcards,
            act_list = act_list,
            next_avail = next_avail,
            chk_expire = chk_expire,
            pkt = pkt,
            exp_pkt = exp_pkt)
Exemplo n.º 16
0
    def runTest(self):
        old_vid = 2
        #sup_acts = supported_actions_get(self)
        #if not (sup_acts & 1 << ofp.OFPAT_POP_VLAN):
            #testutils.skip_message_emit(self, "Strip VLAN tag test")
            #return
        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}])
        exp_pkt = testutils.simple_tcp_packet()
        vid_act = action.action_pop_vlan()

        testutils.flow_match_test(self, pa_port_map,pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act] , max_test = 10)
Exemplo n.º 17
0
    def runTest(self):
        testutils.clear_switch(self,group_port_map,group_logger)
#        self.clear_switch()

        group_add_msg = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_SELECT, group_id = 1, buckets = [
            create_bucket(1, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ]),
            create_bucket(1, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ]),
            create_bucket(1, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 4000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 4)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

        packet_in  = testutils.simple_tcp_packet(tcp_sport=1000)
        packet_out1 = testutils.simple_tcp_packet(tcp_sport=2000)
        packet_out2 = testutils.simple_tcp_packet(tcp_sport=3000)
        packet_out3 = testutils.simple_tcp_packet(tcp_sport=4000)
        
        flow_add_msg = \
        testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 1)
        ])

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        recv1 = self.recv_data(2)
        recv2 = self.recv_data(3)
        recv3 = self.recv_data(4)

        self.assertTrue(((recv1 is not None) or (recv2 is not None) or (recv3 is not None)),
                        "Did not receive a packet")
        
        self.assertTrue(((recv1 is not None) and (recv2 is None) and (recv3 is None)) or \
                        ((recv1 is None) and (recv2 is not None) and (recv3 is None)) or \
                        ((recv1 is None) and (recv2 is None) and (recv3 is not None)),
                        "Received too many packets")

        self.assertTrue(((recv1 is not None) and testutils.pkt_verify(self, recv1, packet_out1)) or \
                        ((recv2 is not None) and testutils.pkt_verify(self, recv2, packet_out2)) or \
                        ((recv3 is not None) and testutils.pkt_verify(self, recv3, packet_out3)),
                        "Received unexpected packet")
Exemplo n.º 18
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]

        dl_vlan = 0xa5a # no specific meaning
        dl_vlan_pcp=3
        outer_dl_vlan = 0x18F
        pkt = testutils.simple_tcp_packet(vlan_tags=[{'type' : ETHERTYPE_VLAN, 'vid': outer_dl_vlan},
                                                     {'vid': dl_vlan, 'pcp': dl_vlan_pcp}])
        match = parse.packet_to_flow_match(pkt)
        wildcards = 0

        new_dl_vlan = 0xfed
        exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': new_dl_vlan, 'pcp': dl_vlan_pcp}])

        # Create parameters for each table
        act_list = []
        next_avail = []
        chk_expire = []

        #Table 0
        act = action.action_output()
        act.port = egr_port
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 1
        act = action.action_set_vlan_vid()
        act.vlan_vid = new_dl_vlan
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_pop_vlan()
        act_list.append([act])
        next_avail.append(False)
        chk_expire.append(False)

        write_action_test_multi_tables(self, ing_port, egr_port,
            match = match,
            wildcards = wildcards,
            act_list = act_list,
            next_avail = next_avail,
            chk_expire = chk_expire,
            pkt = pkt,
            exp_pkt = exp_pkt)
Exemplo n.º 19
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")
Exemplo n.º 20
0
    def runTest(self):
        old_vid = 2
        new_vid = 3
        # sup_acts = supported_actions_get(self)
        # if not (sup_acts & 1 << ofp.OFPXMT_OFB_VLAN_VID):
            # testutils.skip_message_emit(self, "Modify VLAN tag test")
            # return
        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}])
        exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': new_vid}])
        vid_act = action.action_set_field()
        vid_act.field = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT)

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act])
Exemplo n.º 21
0
    def runTest(self):
        old_vid = 2
        new_vid = 3
        sup_acts = supported_actions_get(self)
        if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
            testutils.skip_message_emit(self, "Modify VLAN tag test")
            return

        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}])
        exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': new_vid}])
        vid_act = action.action_set_vlan_vid()
        vid_act.vlan_vid = new_vid

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act])
Exemplo n.º 22
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

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

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")

            request = testutils.flow_msg_create(self,
                                                pkt,
                                                ing_port=ingress_port,
                                                egr_port=ofp.OFPP_ALL)

            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(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports,
                                        [ingress_port], self, pa_logger)
Exemplo n.º 23
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     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)
     fm_new = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port2)
     fm_new.command = ofp.OFPFC_MODIFY_STRICT
     rv = self.controller.message_send(fm_orig)
     self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
     testutils.do_barrier(self.controller)
     rv = self.controller.message_send(fm_new)
     testutils.do_barrier(self.controller)
     self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
     flow_stats = testutils.flow_stats_get(self)
     self.assertEqual(len(flow_stats.stats),1, 
                      "Expected only one flow_mod")
     stat = flow_stats.stats[0]
     self.assertEqual(stat.match, fm_new.match)
     self.assertEqual(stat.instructions, fm_new.instructions)
Exemplo n.º 24
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()
        
        for ingress_port in of_ports:
            rv = testutils.delete_all_flows(self.controller, pa_logger)
            self.assertEqual(rv, 0, "Failed to delete all flows")

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")    
            actions = []
            for egress_port in of_ports:
                act = action.action_output()
                if egress_port == ingress_port:
                    act.port = ofp.OFPP_IN_PORT
                else:
                    act.port = egress_port
                actions.append(act)
            request = testutils.flow_msg_create(self, pkt, ingress_port, action_list=actions)
            request.buffer_id = 0xffffffff
            # pa_logger.info(request.show())

            pa_logger.info("Inserting flow")
            rv = self.controller.message_send(request)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Exemplo n.º 25
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[1]

        pkt = testutils.simple_tcp_packet(dl_src='08:02:ff:34:88:99',
                                          dl_dst='22:22:ed:22:5f:1a')
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            egr_port=egr_port,
                                            table_id=table_id)
        for obj in request.match_fields.tlvs:
            if obj.field == ofp.OFPXMT_OFB_METADATA:
                obj.value = 0x9922334455667788
        request.idle_timeout = 1
        request.flags |= ofp.OFPFF_SEND_FLOW_REM
        testutils.flow_msg_install(self, request)
        #print(request.show())

        (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 3)
        self.assertTrue(response is not None,
                        'Did not receive flow removed message ')
        self.assertEqual(request.cookie, response.cookie,
                         'Cookies do not match')
        self.assertEqual(
            ofp.OFPRR_IDLE_TIMEOUT, response.reason,
            'Flow table entry removal reason is not idle_timeout')
Exemplo n.º 26
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)
Exemplo n.º 27
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)
Exemplo n.º 28
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]
        out_port2 = flow_mods_port_map.keys()[2]
        pkt = testutils.simple_tcp_packet()
        testutils.delete_all_flows(self.controller, self.logger)
        fm_orig = testutils.flow_msg_create(self,
                                            pkt,
                                            ing_port=ofp.OFPP_ANY,
                                            egr_port=out_port1,
                                            table_id=2)
        fm_new = testutils.flow_msg_create(self,
                                           pkt,
                                           ing_port=ing_port,
                                           egr_port=out_port2,
                                           table_id=2)
        fm_new.command = ofp.OFPFC_MODIFY_STRICT
        testutils.ofmsg_send(self, fm_orig)

        testutils.ofmsg_send(self, fm_new)

        flow_stats = testutils.flow_stats_get(self)
        #print(flow_stats.show())
        self.assertEqual(len(flow_stats.stats), 1,
                         "Expected only one flow_mod")

        #fail to modify and instruction will remain the same
        stat = flow_stats.stats[0]
        self.assertEqual(stat.match, fm_orig.match)
        self.assertEqual(stat.instructions, fm_orig.instructions)
Exemplo n.º 29
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)
Exemplo n.º 30
0
    def runTest(self):
        for of_port in sdn_port_map.keys():
            ing_port = of_port
            for egr_port in sdn_port_map.keys():
                if egr_port != of_port:
                    break
            #egr_port = (i+1) %4 + 1
            #print("\ncount: " + str(ing_port))
            #print("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            self.logger.info("\ncount: " + str(ing_port))
            self.logger.info("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            pkt = testutils.simple_tcp_packet()
            testutils.delete_all_flows(self.controller, self.logger)

            request = testutils.flow_msg_create(self, pkt, ing_port = ing_port, egr_port = egr_port,check_expire=True)
            request.cookie = random.randint(0,9007199254740992)
            request.buffer_id = 0xffffffff
            request.hard_timeout = 1000
            request.idle_timeout = 1000

            rv = self.controller.message_send(request)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            self.dataplane.send(ing_port, str(pkt))
            (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=1)
            #print("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            #print("\n")
            self.logger.info("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            self.logger.info("\n")
            self.assertTrue(rcv_pkt is not None, "Did not receive packet")
Exemplo n.º 31
0
 def runTest(self):
     ing_port = sdn_port_map.keys()[0]
     for i in range(1, 1024*1000 + 1):
         #print("packet count:", i)
         self.logger.info("packet count:", i)
         pkt_send = testutils.simple_tcp_packet(dl_dst='11:22:33:44:55:66',tcp_sport = i % 5000 + 1000)
         num = self.dataplane.send(ing_port, str(pkt_send))
Exemplo n.º 32
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)
Exemplo n.º 33
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")
Exemplo n.º 34
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[len(of_ports) - 1]

        pkt = testutils.simple_tcp_packet(dl_src='00:22:44:62:9b:1c',
                                          dl_dst='00:13:07:5f:61:ab')
        pkt_metadata = {
            'metadata_val': 0xaa22334455667788,
            'metadata_msk': 0xFFFFFFFFFFFFFFFF
        }
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            pkt_metadata,
                                            egr_port=egr_port,
                                            table_id=table_id)
        request.hard_timeout = 8
        request.idle_timeout = 8

        testutils.flow_msg_install(self, request)
        #"get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 1,
                         "len of stats is:" + str(len(response.stats)))
Exemplo n.º 35
0
    def runTest(self):
        old_vid = 2
        #sup_acts = supported_actions_get(self)
        #if not (sup_acts & 1 << ofp.OFPAT_POP_VLAN):
        #testutils.skip_message_emit(self, "Strip VLAN tag test")
        #return
        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}])
        exp_pkt = testutils.simple_tcp_packet()
        vid_act = action.action_pop_vlan()

        testutils.flow_match_test(self,
                                  pa_port_map,
                                  pkt=pkt,
                                  exp_pkt=exp_pkt,
                                  apply_action_list=[vid_act],
                                  max_test=10)
Exemplo n.º 36
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     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)
     inst = None
     inst = instruction.instruction_write_actions(
     )  #instruct is the same, action is different
     act = action.action_output()
     act.port = out_port2
     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, 5)
     self.assertTrue(response is not None, 'No error message received')
     self.assertEqual(
         ofp.OFPET_BAD_INSTRUCTION, response.type,
         'Error message type mismatch: ' +
         str(ofp.OFPET_BAD_INSTRUCTION, ) + " != " + str(response.type))
     self.assertEqual(
         ofp.OFPBIC_UNKNOWN_INST, response.code,
         'Error message code mismatch: ' + str(ofp.OFPBIC_UNKNOWN_INST) +
         " != " + str(response.code))
Exemplo n.º 37
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')
Exemplo n.º 38
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     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)
     inst = None
     inst = instruction.instruction_write_actions()#instruct is the same, action is different
     act = action.action_output()
     act.port = out_port2
     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, 5)
     self.assertTrue(response is not None, 'No error message received')
     self.assertEqual(ofp.OFPET_BAD_INSTRUCTION, response.type,
                    'Error message type mismatch: ' +
                    str(ofp.OFPET_BAD_INSTRUCTION,) + " != " +
                    str(response.type))
     self.assertEqual(ofp.OFPBIC_UNKNOWN_INST, response.code,
                    'Error message code mismatch: ' +
                    str(ofp.OFPBIC_UNKNOWN_INST) + " != " +
                    str(response.code))
Exemplo n.º 39
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

        for of_port in basic_port_map.keys():
            basic_logger.info("PKT IN test, port " + str(of_port))
            pkt = testutils.simple_tcp_packet()
            self.dataplane.send(of_port, str(pkt))
            #@todo Check for unexpected messages?
            (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)

            self.assertTrue(
                response is not None,
                'Packet in message not received on port ' + str(of_port))
            if str(pkt) != response.data:
                basic_logger.debug("pkt  len " + str(len(str(pkt))) + ": " +
                                   str(pkt))
                basic_logger.debug("resp len " + str(len(str(response.data))) +
                                   ": " + str(response.data))

            self.assertEqual(
                str(pkt), response.data,
                'Response packet does not match send packet' + ' for port ' +
                str(of_port))
Exemplo n.º 40
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]
        out_port2 = flow_mods_port_map.keys()[2]
        pkt = testutils.simple_tcp_packet()
        testutils.delete_all_flows(self.controller, self.logger)
        fm_orig = testutils.flow_msg_create(self, pkt,
                                            ing_port=ofp.OFPP_ANY,
                                            egr_port=out_port1,
                                            table_id=2)
        fm_new = testutils.flow_msg_create(self, pkt,
                                            ing_port=ing_port,
                                            egr_port=out_port2,
                                            table_id=2)
        fm_new.command = ofp.OFPFC_MODIFY_STRICT
        testutils.ofmsg_send(self, fm_orig)

        testutils.ofmsg_send(self, fm_new)

        flow_stats = testutils.flow_stats_get(self)
        #print(flow_stats.show())
        self.assertEqual(len(flow_stats.stats),1,
                         "Expected only one flow_mod")
                         
        #fail to modify and instruction will remain the same
        stat = flow_stats.stats[0]
        self.assertEqual(stat.match, fm_orig.match)                  
        self.assertEqual(stat.instructions, fm_orig.instructions)  
Exemplo n.º 41
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane
        # Poll controller with expect message type packet in

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

        # These will get put into function
        outpkt = testutils.simple_tcp_packet()
        of_ports = basic_port_map.keys()
        of_ports.sort()
        for dp_port in of_ports:
            msg = message.packet_out()
            msg.in_port = ofp.OFPP_CONTROLLER
            msg.data = str(outpkt)
            act = action.action_output()
            act.port = dp_port
            self.assertTrue(msg.actions.add(act),
                            'Could not add action to msg')

            basic_logger.info("PacketOut to: " + str(dp_port))
            rv = self.controller.message_send(msg)
            self.assertTrue(rv == 0, "Error sending out message")

            (of_port, pkt, _) = self.dataplane.poll(timeout=1)

            self.assertTrue(pkt is not None, 'Packet not received')
            basic_logger.info("PacketOut: got pkt from " + str(of_port))
            if of_port is not None:
                self.assertEqual(of_port, dp_port, "Unexpected receive port")
            self.assertEqual(str(outpkt), str(pkt),
                             'Response packet does not match send packet')
Exemplo n.º 42
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, exact_port_map.keys(),
                                          exact_logger)  #zhaoxiuchu
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[1]

        pkt = testutils.simple_tcp_packet(dl_src='08:02:03:04:88:99',
                                          dl_dst='22:22:22:22:22:22')
        pkt_metadata = {
            'metadata_val': 0xad22332e6f667588,
            'metadata_msk': 0xFFFFFFFFFFFFFFFF
        }
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            pkt_metadata,
                                            egr_port=egr_port,
                                            table_id=table_id)
        request.hard_timeout = 1
        request.flags |= ofp.OFPFF_SEND_FLOW_REM
        testutils.flow_msg_install(self, request)
        #print(request.show())

        (response, _) = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 3)

        self.assertTrue(response is not None,
                        'Did not receive flow removed message ')
        self.assertEqual(request.cookie, response.cookie,
                         'Cookies do not match')
        self.assertEqual(
            ofp.OFPRR_HARD_TIMEOUT, response.reason,
            'Flow table entry removal reason is not idle_timeout')
Exemplo n.º 43
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()

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

            pa_logger.info("Ingress " + str(ingress_port) +
                           " all non-ingress ports")
            actions = []
            for egress_port in of_ports:
                act = action.action_output()
                if egress_port == ingress_port:
                    continue
                act.port = egress_port
                actions.append(act)
            request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port,
                                action_list=actions, 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(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
                              self, pa_logger)
Exemplo n.º 44
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        
        act_all = action.action_output()
        act_all.port = ofp.OFPP_ALL
        act_ing = action.action_output()
        act_ing.port = ofp.OFPP_IN_PORT
        actions = [ act_all, act_ing]

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

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")
        
            flow_mod = testutils.flow_msg_create(self, pkt, 
                                                 ing_port=ingress_port, 
                                                 action_list=actions, 
                                                 wildcards=~ofp.OFPFW_IN_PORT)
            flow_mod.buffer_id = 0xffffffff
            pa_logger.info(flow_mod.show())

            pa_logger.info("Inserting flow")
            rv = self.controller.message_send(flow_mod)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Exemplo n.º 45
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        act_all = action.action_output()
        act_all.port = ofp.OFPP_ALL
        act_ing = action.action_output()
        act_ing.port = ofp.OFPP_IN_PORT
        actions = [ act_all, act_ing]

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

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")

            flow_mod = testutils.flow_msg_create(self, pkt,
                                                 ing_port=ingress_port,
                                                 action_list=actions,
                                                 inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION
                                                 )
            pa_logger.info(flow_mod.show())

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

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Exemplo n.º 46
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

        of_port = config_port_map.keys()[0]
        rv = testutils.port_config_set(self.controller, of_port,
                                       ofp.OFPPC_NO_PACKET_IN,
                                       ofp.OFPPC_NO_PACKET_IN, config_logger)
        self.assertTrue(rv != -1, "Error sending port mod")
        config_logger.info("NO PKT IN test, port " + str(of_port))

        # make sure config is changed before sending the packet
        testutils.do_barrier(self.controller)

        pkt = testutils.simple_tcp_packet()
        self.dataplane.send(of_port, str(pkt))
        #@todo Check for unexpected messages?
        (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)

        self.assertTrue(
            response is None,
            'OFPPC_NO_PACKET_IN flag is ignored on port (got a packet when we asked not to) '
            + str(of_port))
Exemplo n.º 47
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')
Exemplo n.º 48
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()

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

            pa_logger.info("Ingress " + str(ingress_port) +
                           " all non-ingress ports")
            actions = []
            for egress_port in of_ports:
                act = action.action_output()
                if egress_port == ingress_port:
                    continue
                act.port = egress_port
                actions.append(act)
            request = testutils.flow_msg_create(
                self,
                pkt,
                ing_port=ingress_port,
                action_list=actions,
                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(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports,
                                        [ingress_port], self, pa_logger)
Exemplo n.º 49
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)
Exemplo n.º 50
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()

        act_all = action.action_output()
        act_all.port = ofp.OFPP_ALL
        act_ing = action.action_output()
        act_ing.port = ofp.OFPP_IN_PORT
        actions = [act_all, act_ing]

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

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")

            flow_mod = testutils.flow_msg_create(
                self,
                pkt,
                ing_port=ingress_port,
                action_list=actions,
                inst_app_flag=testutils.APPLY_ACTIONS_INSTRUCTION)
            pa_logger.info(flow_mod.show())

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

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [],
                                        self, pa_logger)
Exemplo n.º 51
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane
        # Poll controller with expect message type packet in

        of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger)

        # These will get put into function
        outpkt = testutils.simple_tcp_packet()
        of_ports = basic_port_map.keys()
        of_ports.sort()
        for dp_port in of_ports:
            msg = message.packet_out()
            msg.in_port = ofp.OFPP_CONTROLLER
            msg.data = str(outpkt)
            act = action.action_output()
            act.port = dp_port
            self.assertTrue(msg.actions.add(act), 'Could not add action to msg')

            basic_logger.info("PacketOut to: " + str(dp_port))
            testutils.ofmsg_send(self, msg)

            (of_port, pkt, _) = self.dataplane.poll(timeout=1)

            self.assertTrue(pkt is not None, 'Packet not received')
            basic_logger.info("PacketOut: got pkt from " + str(of_port))
            if of_port is not None:
                self.assertEqual(of_port, dp_port, "Unexpected receive port")
            self.assertEqual(str(outpkt), str(pkt),
                             'Response packet does not match send packet')
Exemplo n.º 52
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)
Exemplo n.º 53
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)))
Exemplo n.º 54
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)
Exemplo n.º 55
0
    def runTest(self):
        old_vid = 2
        sup_acts = supported_actions_get(self)
        if not (sup_acts & 1 << ofp.OFPAT_POP_VLAN):
            testutils.skip_message_emit(self, "Strip VLAN tag test")
            return

        len_w_vid = 104
        len = 100
        pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, 
                                dl_vlan=old_vid)
        exp_pkt = testutils.simple_tcp_packet(pktlen=len)
        vid_act = action.action_pop_vlan()

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act])
Exemplo n.º 56
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     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)
     fm_new = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port2)
     fm_new.command = ofp.OFPFC_MODIFY_STRICT
     rv = self.controller.message_send(fm_orig)
     self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
     testutils.do_barrier(self.controller)
     rv = self.controller.message_send(fm_new)
     testutils.do_barrier(self.controller)
     self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
     flow_stats = testutils.flow_stats_get(self)
     self.assertEqual(len(flow_stats.stats),1, 
                      "Expected only one flow_mod")
     stat = flow_stats.stats[0]
     self.assertEqual(stat.match, fm_new.match)
     self.assertEqual(stat.instructions, fm_new.instructions)
Exemplo n.º 57
0
    def scenario2(self, first_table=0, second_table=1):
        """
        Set the first table config as "Drop" and second table as "Controller"
        add flow entry:
        First Table; Match IP Src A; send to 1 // if not match, then drop
        Second Table; Match IP Src B; send to 2 // if not match, controller

        Then send in a packet:
        IP B; expect drop
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set table config as "drop" and "send to controller"
        setup_table_config(self, first_table, ofp.OFPTC_TABLE_MISS_DROP)
        setup_table_config(self, second_table, ofp.OFPTC_TABLE_MISS_CONTROLLER)

        # Set up first match
        write_output(self, first_table, of_ports[0], ip_src="192.168.1.10")
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.70")

        # Generate a packet not matching to any flow, then drop
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.70', tcp_sport=10)
        self.dataplane.send(of_ports[2], 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")