Example #1
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)
Example #2
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)
Example #3
0
    def runTest(self):
        #async_logger.info("Running " + str(self))
        #step 0:clear switch
        of_ports = testutils.clear_switch(self, async_port_map.keys(), async_logger)
        
        (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2)
        (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2)
        (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2)
        #step 1:controller sends set_async_request msg
        async_logger.info("Sending set_async_request")
        mask = 0xffffffff ^ (1 << ofp.OFPPR_MODIFY)
        request_set = create_set_async(port_st_mstr = mask)
        testutils.ofmsg_send(self, request_set)
        #result 1: contrller sends msg successfully
    
        #step 2: set the first port's config to the other way
        async_logger.info("testcase executed on port: " + str(of_ports[0]))

        async_logger.debug("No flood bit port " + str(of_ports[0]) + " is now " + 
                           str(ofp.OFPPC_NO_PACKET_IN))                    
        rv = testutils.port_config_set(self.controller, of_ports[0],
                             ofp.OFPPC_NO_PACKET_IN, ofp.OFPPC_NO_PACKET_IN,
                             async_logger)
        #result 2:set the first port's config to the other way successfully
        self.assertTrue(rv != -1, "Error sending port mod")
        testutils.do_barrier(self.controller)

        #step 3: after the port's attribute changed, PORT_STATUS msg sended to controller
        (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2)
        #result 3: no packetin msg sended to controller
        self.assertTrue(response is None, 'PORT_STATUS message received unexpected')

        #step 4: Verify change took place with same feature request
        _,config,_ = testutils.port_config_get(self.controller, of_ports[0], async_logger)

        async_logger.debug("No packet_in bit port " + str(of_ports[0]) + " is now " + 
                           str(config & ofp.OFPPC_NO_PACKET_IN))
        self.assertTrue(config is not None, "Did not get port config")
        self.assertTrue(config & ofp.OFPPC_NO_PACKET_IN != 0, "Bit change did not take")

        #step 5: Set it back
        mask = 1 << ofp.OFPPR_MODIFY
        request_set = create_set_async(port_st_mstr = mask)
        testutils.ofmsg_send(self, request_set)

        rv = testutils.port_config_set(self.controller, of_ports[0], 0,
                                        ofp.OFPPC_NO_PACKET_IN, async_logger)
        self.assertTrue(rv != -1, "Error sending port mod")

        (response, _) = self.controller.poll(ofp.OFPT_PORT_STATUS, 2)
        #result 3: no packetin msg sended to controller
        self.assertTrue(response is not None, 'PORT_STATUS message not received')

        testutils.clear_switch(self, async_port_map, async_logger)
        msg = create_set_async()
        set_async_verify(self, msg)
Example #4
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")
Example #5
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')
Example #6
0
    def runTest(self):
        """
        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; do nothing // match but stop pipeline
        Fourth Table; Match IP Src A; send to 2  // not match, just a fake

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

        @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(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE)

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

        # Set up third match
        testutils.write_output(self, testutils.WC_SERV_TABLE, of_ports[1], of_ports[2])

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

        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        testutils.reply_check_dp(self, tcp_sport=1234,
                       ing_port = of_ports[2], egr_port = of_ports[1])
Example #7
0
    def scenario4(self, first_table = 0, second_table = 1, third_table = 2, fourth_table = 3):
        """
        Add five flow entries:
        First Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1
        Third Table; Match IP Src C; send to 1
        Fourth Table; Match IP Src D; send to 1

        Then send in 2 packets:
        IP F, TCP C; expect packet_in
        IP G, TCP B; expect packet_in

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

        # Set up matches
        write_output(self, first_table, of_ports[0], ip_src="192.168.1.10")
        write_output(self, second_table, of_ports[0], ip_src="192.168.1.20")
        write_output(self, third_table, of_ports[0], ip_src="192.168.1.30")
        write_output(self, fourth_table, of_ports[0], ip_src="192.168.1.40")

        # Generate a packet not matching to any flow, then packet_in
        reply_check_ctrl(self, ip_src='192.168.1.70', tcp_sport=10,
                         ing_port = of_ports[2])
Example #8
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, basic_port_map.keys(),
                                          basic_logger)

        for max_len in [
                0, 99, DEFAULT_MISS_SEND_LEN, ofp.OFPCML_MAX,
                ofp.OFPCML_NO_BUFFER
        ]:
            rc = testutils.delete_all_flows(self.controller, basic_logger)
            self.assertEqual(rc, 0, "Failed to delete all flows")
            testutils.set_config_verify(self,
                                        max_len=(max_len % ofp.OFPCML_MAX +
                                                 10))
            if max_len == ofp.OFPCML_NO_BUFFER:
                testutils.set_config_verify(self, max_len=max_len)
            testutils.set_flow_miss_entry(self,
                                          ofp.OFPTC_TABLE_MISS_CONTROLLER,
                                          max_len, 0)
            for of_port in basic_port_map.keys():
                basic_logger.info("PKT IN test, port " + str(of_port))
                pkt = testutils.simple_tcp_packet()
                self.dataplane.send(of_port, str(pkt))
                #@todo Check for unexpected messages?
                testutils.do_barrier(self.controller)
                testutils.packetin_verify(self, pkt, max_len)
                response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
                while response != None:
                    response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
        testutils.set_config_verify(self, max_len=DEFAULT_MISS_SEND_LEN)
Example #9
0
    def runTest(self):
        """
        Set the first table config as "Send to Controller" and the second
        table as "Drop", add flow entries:
        First Table; Match IP Src A; send to 1 // if not match, packet_in
        Second Table; Match IP Src B; send to 2 // if not match, drop

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

        # Set table config as "send to controller" and "drop"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTROLLER, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE,
                                   ofp.OFPTC_TABLE_MISS_DROP, True)

        # Set up matches
        testutils.write_output(self,
                               testutils.WC_ACL_TABLE,
                               of_ports[0],
                               ip_src="192.168.1.10")
        testutils.write_output(self,
                               testutils.WC_SERV_TABLE,
                               of_ports[1],
                               of_ports[2],
                               ip_src="192.168.1.70")

        # Generate a packet not matching to any flow entry in the first table
        testutils.reply_check_ctrl(self,
                                   ip_src='192.168.1.70',
                                   tcp_sport=1234,
                                   ing_port=of_ports[2])
Example #10
0
    def runTest(self):
        """
        Set table config as "Continue" and add flow entry:
        First Table; Match IP Src A; send to 1 // not match then continue
        Second Table; Match IP Src B; send to 2 // do execution

        Then send in 2 packets:
        IP B; expect out port 2
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set table config as "continue"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE,
                                   ofp.OFPTC_TABLE_MISS_CONTINUE, True)

        # Set up flow entries
        #write_output(self, testutils.EX_ACL_TABLE, of_ports[0], ip_src="192.168.1.10")
        testutils.write_output(self,
                               testutils.WC_ACL_TABLE,
                               of_ports[0],
                               ip_src="192.168.1.10")
        testutils.write_output(self,
                               testutils.WC_SERV_TABLE,
                               of_ports[1],
                               of_ports[2],
                               ip_src="192.168.1.70")
        testutils.do_barrier(self.controller)

        # Generate a packet not matching in the first table, but in the second
        testutils.reply_check_dp(self,
                                 ip_src='192.168.1.70',
                                 tcp_sport=1234,
                                 ing_port=of_ports[2],
                                 egr_port=of_ports[1])
Example #11
0
    def runTest(self):
        """
        ** Currently, same scenario with "NoGoto" **

        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; do nothing // match but stop pipeline
        Fourth Table; Match IP Src A; send to 2  // not match, just a fake

        Then send in 2 packets:
        IP A, TCP C; expect out port 1
        IP A, TCP B; expect out port 1
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE)

        # Set up second match
        testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE,
                                                                        of_ports[0], of_ports[2])

        # Set up third match, "Empty Instruction"
        pkt = testutils.simple_tcp_packet()
        request = testutils.flow_msg_create(self, pkt, ing_port = of_ports[2], table_id = testutils.EX_L2_TABLE)
        testutils.flow_msg_install(self, request)

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

        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        testutils.reply_check_dp(self, tcp_sport=1234,
                       ing_port = of_ports[2], egr_port = of_ports[0])
Example #12
0
    def runTest(self):
        """
        Add five flow entries:
        First Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1
        Third Table; Match IP Src C; send to 1
        Fourth Table; Match IP Src D; send to 1

        Then send in 2 packets:
        IP F, TCP C; expect packet_in
        IP G, TCP B; expect packet_in

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

        # Set up matches
        #write_output(self, testutils.EX_ACL_TABLE, 1, ip_src="192.168.1.10")
        #write_output(self, testutils.EX_ACL_TABLE, of_ports[0], ip_src="128.128.128.10")
        testutils.set_table_config(self, config = ofp.OFPTC_TABLE_MISS_CONTROLLER)
        testutils.write_output(self, testutils.WC_ACL_TABLE, of_ports[0], ip_src="192.168.1.10")
        testutils.write_output(self, testutils.WC_SERV_TABLE, of_ports[0],
                                                ing_port=of_ports[1], ip_src="192.168.1.20")
        testutils.write_output(self, testutils.EX_L2_TABLE, of_ports[0], ip_src="192.168.1.30")
        testutils.write_output(self, testutils.EX_L3_TABLE, of_ports[0], ip_src="192.168.1.40")

        # Generate a packet not matching to any flow, then packet_in
        testutils.reply_check_ctrl(self, ip_src='192.168.1.70', tcp_sport=1234,
                         ing_port = of_ports[2])
Example #13
0
    def runTest(self):
        """
        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"
        testutils.set_table_config(self, testutils.WC_ACL_TABLE, ofp.OFPTC_TABLE_MISS_DROP, True)
        testutils.set_table_config(self, testutils.WC_SERV_TABLE, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)

        # Set up first match
        testutils.write_output(self, testutils.WC_ACL_TABLE, of_ports[0], ip_src="192.168.1.10")
        testutils.write_output(self, testutils.WC_SERV_TABLE, of_ports[1], of_ports[2], 
                                                                        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")
Example #14
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')
Example #15
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")
Example #16
0
    def scenario3(self, first_table=0, second_table=1, third_table=2):
        """
        Add three flow entries:
        First Table; Match IP Src A; send to 0 now, goto Second Table
        Second Table; Match IP Src A; send to 1 now, goto Third Table
        Third Table; Match IP src A; send to 2 now

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

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

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

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

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

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

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

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

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

        testutils.receive_pkt_verify(self, of_ports[0], pkt)
        testutils.receive_pkt_verify(self, of_ports[1], pkt)
        testutils.receive_pkt_verify(self, of_ports[2], pkt)
Example #18
0
    def scenario4(self,
                  first_table=0,
                  second_table=1,
                  third_table=2,
                  fourth_table=3):
        """
        Add five flow entries:
        First Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1
        Third Table; Match IP Src C; send to 1
        Fourth Table; Match IP Src D; send to 1

        Then send in 2 packets:
        IP F, TCP C; expect packet_in
        IP G, TCP B; expect packet_in

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

        # Set up matches
        write_output(self, first_table, of_ports[0], ip_src="192.168.1.10")
        write_output(self, second_table, of_ports[0], ip_src="192.168.1.20")
        write_output(self, third_table, of_ports[0], ip_src="192.168.1.30")
        write_output(self, fourth_table, of_ports[0], ip_src="192.168.1.40")

        # Generate a packet not matching to any flow, then packet_in
        reply_check_ctrl(self,
                         ip_src='192.168.1.70',
                         tcp_sport=10,
                         ing_port=of_ports[2])
Example #19
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')
Example #20
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")
Example #21
0
    def scenario2(self, first_table=0, second_table=1):
        """
        Set the first table config as "Send to Controller" and the second
        table as "Drop", add flow entries:
        First Table; Match IP Src A; send to 1 // if not match, packet_in
        Second Table; Match IP Src B; send to 2 // if not match, drop

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

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

        # Set up matches
        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 entry in the first table
        reply_check_ctrl(self,
                         ip_src='192.168.1.70',
                         tcp_sport=10,
                         ing_port=of_ports[2])
Example #22
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])
Example #23
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]
        check_expire_tbl0 = False
        check_expire_tbl1 = False

        # Build the ingress packet
        pkt = testutils.simple_tcp_packet(**self.base_pkt_params)

        # Set action for the first table
        for item_tbl0 in self.start_pkt_params:
            tbl0_pkt_params = self.base_pkt_params.copy()
            tbl0_pkt_params[item_tbl0] = self.mod_pkt_params[item_tbl0]
            act = testutils.action_generate(self, item_tbl0, tbl0_pkt_params)
            action_list = [act]

            inst_1 = instruction.instruction_apply_actions()
            inst_2 = instruction.instruction_goto_table()
            inst_2.table_id = 1
            inst_list = [inst_1, inst_2]
            request0 = testutils.flow_msg_create(self, pkt,
                              ing_port=ing_port,
                              instruction_list=inst_list,
                              action_list=action_list,
                              check_expire=check_expire_tbl0,
                              table_id=0)

            exp_pkt = testutils.simple_tcp_packet(**tbl0_pkt_params)

            request1 = testutils.flow_msg_create(self, exp_pkt,
                              ing_port=ing_port,
                              check_expire=check_expire_tbl1,
                              table_id=1,
                              egr_port=egr_port)

            # Insert two flows
            self.logger.debug("Inserting flows: Modify-field: " + item_tbl0)
            testutils.flow_msg_install(self, request0)
            testutils.flow_msg_install(self, request1)

            # Send pkt
            self.logger.debug("Send packet: " + str(ing_port) +
                              " to " + str(egr_port))
            self.dataplane.send(ing_port, str(pkt))

            #@todo Not all HW supports both pkt and byte counters
            #@todo We shouldn't expect the order of coming response..
            if check_expire_tbl0:
                flow_removed_verify(self, request0, pkt_count=1,
                                    byte_count=pktlen)
            if check_expire_tbl1:
                flow_removed_verify(self, request1, pkt_count=1,
                                    byte_count=exp_pktlen)
            # Receive and verify pkt
            testutils.receive_pkt_verify(self, egr_port, exp_pkt)
Example #24
0
    def runTest(self):
#        self.clear_switch()
        testutils.clear_switch(self,group_port_map,group_logger)
        
        group_add_msg = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ]),
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        self.send_data(packet_in, 1)
        self.send_data(packet_in, 1)

        group_stats_req = \
        create_group_stats_req(10)

        response = \
        self.send_ctrl_exp_reply(group_stats_req,
                                 ofp.OFPT_STATS_REPLY, 'group stat')

        exp_len = ofp.OFP_HEADER_BYTES + \
                  ofp.OFP_STATS_REPLY_BYTES + \
                  ofp.OFP_GROUP_STATS_BYTES + \
                  ofp.OFP_BUCKET_COUNTER_BYTES * 2

        self.assertEqual(len(response), exp_len,
                         'Received packet length does not equal expected length')
Example #25
0
    def scenario4(self,
                  first_table=0,
                  second_table=1,
                  third_table=2,
                  fourth_table=3):
        """
        ** Currently, same scenario with "NoGoto" **

        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; do nothing // match but stop pipeline
        Fourth Table; Match IP Src A; send to 2  // not match, just a fake

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

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

        # Set up first match
        write_goto(self, first_table, second_table)

        # Set up second match
        write_goto_output(self, second_table, third_table, of_ports[0])

        # Set up third match, "Empty Instruction"
        request = message.flow_mod()
        request.match = make_match()
        request.buffer_id = 0xffffffff
        request.table_id = third_table
        pa_logger.info("Inserting flow 3")
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")

        testutils.do_barrier(self.controller)

        # Set up fourth match
        write_output(self, fourth_table, of_ports[1])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        reply_check_dp(self,
                       tcp_sport=10,
                       ing_port=of_ports[2],
                       egr_port=of_ports[0])
        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        reply_check_dp(self,
                       tcp_sport=80,
                       ing_port=of_ports[2],
                       egr_port=of_ports[0])
Example #26
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])
Example #27
0
    def scenario4(self,
                  first_table=0,
                  second_table=1,
                  third_table=2,
                  fourth_table=3):
        """
        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 first_table first table
        @param second_table second table
        @param third_table third table
        @param fourth_table fourth table
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        write_goto_output(self, first_table, second_table, of_ports[0])

        # Set up second match
        inst = instruction.instruction_write_metadata()
        inst.metadata = 0xfedcba9876543210
        inst.metadata_mask = 0xffffffffffffffff
        write_goto(self, second_table, third_table, add_inst=inst)

        # Set up third match
        match = make_match()
        match.metadata = 0xfedcba9876543210
        match.metadata_mask = 0xffffffffffffffff
        write_output(self, third_table, of_ports[1], match=match)

        # Set up fourth match
        write_output(self, fourth_table, of_ports[0])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        reply_check_dp(self,
                       tcp_sport=10,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        reply_check_dp(self,
                       tcp_sport=80,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
Example #28
0
    def runTest(self):
        """
        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; clear action, goto Fourth Table
        Fourth Table; Match IP Src A; send to 2

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

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

        # Set up first match
        #write_goto(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE)
        act = action.action_set_field()
        field = match.eth_src(parse.parse_mac("aa:aa:aa:aa:aa:aa"))
        act.field.add(field)
        testutils.write_goto_action(self,
                                    testutils.WC_ACL_TABLE,
                                    testutils.WC_SERV_TABLE,
                                    act=act)
        # Set up second match
        testutils.write_goto_output(self, testutils.WC_SERV_TABLE,
                                    testutils.EX_L3_TABLE, of_ports[0],
                                    of_ports[2])
        # Set up third match, "Clear Action"
        inst = instruction.instruction_clear_actions()
        testutils.write_goto(self,
                             testutils.EX_L3_TABLE,
                             testutils.WC_L3_TABLE,
                             of_ports[2],
                             add_inst=inst)
        # Set up fourth match
        testutils.write_output(self, testutils.WC_L3_TABLE, of_ports[1])
        #write_output(self, testutils.EX_L2_TABLE, 4)

        # 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])
Example #29
0
    def runTest(self):
        """
        Add five flow entries:
        First Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1
        Third Table; Match IP Src C; send to 1
        Fourth Table; Match IP Src D; send to 1

        Then send in 2 packets:
        IP F, TCP C; expect packet_in
        IP G, TCP B; expect packet_in

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

        # Set up matches
        #write_output(self, testutils.EX_ACL_TABLE, 1, ip_src="192.168.1.10")
        #write_output(self, testutils.EX_ACL_TABLE, of_ports[0], ip_src="128.128.128.10")
        testutils.set_table_config(self,
                                   config=ofp.OFPTC_TABLE_MISS_CONTROLLER)
        testutils.write_output(self,
                               testutils.WC_ACL_TABLE,
                               of_ports[0],
                               ip_src="192.168.1.10")
        testutils.write_output(self,
                               testutils.WC_SERV_TABLE,
                               of_ports[0],
                               ing_port=of_ports[1],
                               ip_src="192.168.1.20")
        testutils.write_output(self,
                               testutils.EX_L2_TABLE,
                               of_ports[0],
                               ip_src="192.168.1.30")
        testutils.write_output(self,
                               testutils.EX_L3_TABLE,
                               of_ports[0],
                               ip_src="192.168.1.40")

        # Generate a packet not matching to any flow, then packet_in
        testutils.reply_check_ctrl(self,
                                   ip_src='192.168.1.70',
                                   tcp_sport=1234,
                                   ing_port=of_ports[2])
Example #30
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)

        max_len = 40
        testutils.set_flow_miss_entry(self, ofp.OFPTC_TABLE_MISS_CONTROLLER,
                                      max_len, 0)
        # These will get put into function
        outpkt = testutils.simple_tcp_packet()
        of_ports = basic_port_map.keys()
        of_ports.sort()
        #_,miss_send_len = testutils.get_config_reply_verify(self)
        #testutils.set_config_verify(self, max_len = 40)

        for dp_port in of_ports:
            (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
            for egr_port in of_ports:
                if egr_port != dp_port:
                    break
            #_,max_len = testutils.get_config_reply_verify(self)
            self.dataplane.send(egr_port, str(outpkt))
            testutils.do_barrier(self.controller)
            buffer_id = testutils.packetin_verify(self, outpkt, max_len)
            response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
            while response != None:
                response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
            msg = message.packet_out()
            msg.in_port = ofp.OFPP_CONTROLLER
            msg.buffer_id = buffer_id
            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=3)

            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')
Example #31
0
    def scenario4(self, first_table = 0, second_table = 1, third_table = 2, fourth_table = 3):
        """
        ** Currently, same scenario with "NoGoto" **

        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; do nothing // match but stop pipeline
        Fourth Table; Match IP Src A; send to 2  // not match, just a fake

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

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

        # Set up first match
        write_goto(self, first_table, second_table)

        # Set up second match
        write_goto_output(self, second_table, third_table, of_ports[0])

        # Set up third match, "Empty Instruction"
        request = message.flow_mod()
        request.match = make_match()
        request.buffer_id = 0xffffffff
        request.table_id = third_table
        pa_logger.info("Inserting flow 3")
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")

        testutils.do_barrier(self.controller)

        # Set up fourth match
        write_output(self, fourth_table, of_ports[1])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        reply_check_dp(self, tcp_sport=10,
                       ing_port = of_ports[2], egr_port = of_ports[0])
        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        reply_check_dp(self, tcp_sport=80,
                       ing_port = of_ports[2], egr_port = of_ports[0])
Example #32
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE)

        # Set up second match
        testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, of_ports[0], of_ports[1])

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

        testutils.receive_pkt_verify(self, of_ports[2], pkt)
Example #33
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)
        
        max_len = 40
        testutils.set_flow_miss_entry(self, ofp.OFPTC_TABLE_MISS_CONTROLLER, max_len, 0)
        # These will get put into function
        outpkt = testutils.simple_tcp_packet()
        of_ports = basic_port_map.keys()
        of_ports.sort()
        #_,miss_send_len = testutils.get_config_reply_verify(self)
        #testutils.set_config_verify(self, max_len = 40)
        
        for dp_port in of_ports:
            (response, _) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
            for egr_port in of_ports:
                if egr_port != dp_port:
                    break
            #_,max_len = testutils.get_config_reply_verify(self)
            self.dataplane.send(egr_port, str(outpkt))
            testutils.do_barrier(self.controller)
            buffer_id = testutils.packetin_verify(self, outpkt, max_len)
            response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
            while response != None:
                  response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
            msg = message.packet_out()
            msg.in_port = ofp.OFPP_CONTROLLER
            msg.buffer_id = buffer_id
            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=3)

            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')
Example #34
0
    def scenario3(self, first_table=0, second_table=1, third_table=2):
        """
        Add three flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match TCP port B; send to 2

        Then send in 2 packets:
        IP A, TCP C; expect out port 1
        IP A, TCP B; expect out port 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 first match
        write_goto(self, first_table, second_table)

        # Set up second match
        write_goto_output(self, second_table, third_table, of_ports[0])

        # Set up third match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.wildcards -= ofp.OFPFW_TP_SRC
        match.dl_type = MT_TEST_DL_TYPE
        match.nw_proto = 6  #TCP
        match.tp_src = 80
        write_output(self, third_table, of_ports[1], match=match)

        # Generate a packet matching only flow 1 and 2; rcv on port[0]
        reply_check_dp(self,
                       tcp_sport=10,
                       ing_port=of_ports[2],
                       egr_port=of_ports[0])
        # Generate a packet matching both flow 1, 2 and 3; rcv on port[1]
        reply_check_dp(self,
                       tcp_sport=80,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
Example #35
0
     def runTest(self):
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto(self, testutils.WC_ACL_TABLE, testutils.EX_L3_TABLE)

        # Set up second match
        testutils.write_goto(self, testutils.WC_SERV_TABLE, testutils.EX_L2_TABLE, of_ports[2])

        # Set up third match
        testutils.write_goto(self, testutils.EX_L2_TABLE, testutils.EX_L3_TABLE)
        
        # Set up fourth match
        testutils.write_output(self, testutils.EX_L3_TABLE, of_ports[1])

        # 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])
Example #36
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, basic_port_map.keys(),
                                          basic_logger)

        for max_len in [
                0, 99, DEFAULT_MISS_SEND_LEN, ofp.OFPCML_MAX,
                ofp.OFPCML_NO_BUFFER
        ]:
            rc = testutils.delete_all_flows(self.controller, basic_logger)
            self.assertEqual(rc, 0, "Failed to delete all flows")
            testutils.set_config_verify(self,
                                        max_len=(max_len % ofp.OFPCML_MAX +
                                                 10))
            if max_len == ofp.OFPCML_NO_BUFFER:
                testutils.set_config_verify(self, max_len=max_len)

            request = message.flow_mod()
            request.table_id = 0
            request.priority = 0
            request.cookie = 123456
            act = action.action_output()
            act.max_len = max_len
            act.port = ofp.OFPP_CONTROLLER
            inst_packet_in = instruction.instruction_apply_actions()  #apply
            inst_packet_in.actions.add(act)
            request.instructions.add(inst_packet_in)
            rv = self.controller.message_send(request)

            for of_port in basic_port_map.keys():
                basic_logger.info("PKT IN test, port " + str(of_port))
                pkt = testutils.simple_tcp_packet()
                self.dataplane.send(of_port, str(pkt))
                #@todo Check for unexpected messages?
                testutils.do_barrier(self.controller)
                #testutils.packetin_verify(self, pkt, max_len)
                response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
                self.assertEqual(response.cookie, request.cookie,
                                 "cookie is not equal")
                #print(response.cookie)
                #print(request.cookie)
                #clear the msg
                response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
                while response != None:
                    response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
Example #37
0
    def scenario4(self,
                  first_table=0,
                  second_table=1,
                  third_table=2,
                  fourth_table=3):
        """
        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; clear action, goto Fourth Table
        Fourth Table; Match IP Src A; send to 2

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

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

        # Set up first match
        write_goto(self, first_table, second_table)
        # Set up second match
        write_goto_output(self, second_table, third_table, of_ports[0])
        # Set up third match, "Clear Action"
        inst = instruction.instruction_clear_actions()
        write_goto(self, third_table, fourth_table, add_inst=inst)
        # Set up fourth match
        write_output(self, fourth_table, of_ports[1])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        reply_check_dp(self,
                       tcp_sport=10,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        reply_check_dp(self,
                       tcp_sport=80,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
Example #38
0
    def scenario4(self, first_table = 0, second_table = 1, third_table = 2, fourth_table = 3):
        """
        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 first_table first table
        @param second_table second table
        @param third_table third table
        @param fourth_table fourth table
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        write_goto_output(self, first_table, second_table, of_ports[0])

        # Set up second match
        inst = instruction.instruction_write_metadata()
        inst.metadata =      0xfedcba9876543210
        inst.metadata_mask = 0xffffffffffffffff
        write_goto(self, second_table, third_table, add_inst=inst)

        # Set up third match
        match = make_match()
        match.metadata =      0xfedcba9876543210
        match.metadata_mask = 0xffffffffffffffff
        write_output(self, third_table, of_ports[1], match=match)

        # Set up fourth match
        write_output(self, fourth_table, of_ports[0])

        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        reply_check_dp(self, tcp_sport=10,
                       ing_port = of_ports[2], egr_port = of_ports[1])
        # Generate a packet matching flow 1, 2, and 3; rcv on port[1]
        reply_check_dp(self, tcp_sport=80,
                       ing_port = of_ports[2], egr_port = of_ports[1])
Example #39
0
    def runTest(self):
        """
        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 DSCP = dscp1
        IP B;  expect port 1 with DSCP = dscp2

        @param self object instance
        @param EX_ACL_TABLE first table
        @param WC_ACL_TABLE second table
        @param dscp1 DSCP value to be set for first flow
        @param dscp2 DSCP 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
        dscp1 = 4
        dscp2 = 8
        t_act = action.action_set_field()
        t_act.field = match.ip_dscp(dscp1)
        testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act,
                          ip_src='192.168.1.10')
        t_act.field = match.ip_dscp(dscp2)
        #t_act.field = match.ip_ecn(3)
        testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act,
                          ip_src='192.168.1.30',clear_tag=False)

        # Set up flow matches in table B: routing
        testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.10")
        testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], 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=1234, ip_dscp=dscp1)
        testutils.reply_check_dp(self, ip_src='192.168.1.10', tcp_sport=1234,
                 exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])
Example #40
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])
Example #41
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
        of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger)

        testutils.set_table_config(self, 0, ofp.OFPTC_TABLE_MISS_CONTROLLER, True)
        #_,miss_send_len = testutils.get_config_reply_verify(self)
        testutils.set_config_verify(self, max_len = ofp.OFPCML_NO_BUFFER)
        for of_port in basic_port_map.keys():
            basic_logger.info("PKT IN test, port " + str(of_port))
            pkt = testutils.simple_tcp_packet()
            self.dataplane.send(of_port, str(pkt))
            #@todo Check for unexpected messages?
            testutils.packetin_verify(self, pkt, ofp.OFPCML_NO_BUFFER)
            response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
            while response != None:
                  response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
        testutils.set_config_verify(self, max_len = DEFAULT_MISS_SEND_LEN)
Example #42
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])
Example #43
0
    def scenario3(self, first_table = 0, second_table = 1, third_table = 2):
        """
        Add three flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match TCP port B; send to 2

        Then send in 2 packets:
        IP A, TCP C; expect out port 1
        IP A, TCP B; expect out port 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 first match
        write_goto(self, first_table, second_table)

        # Set up second match
        write_goto_output(self, second_table, third_table, of_ports[0])

        # Set up third match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.wildcards -= ofp.OFPFW_NW_PROTO
        match.wildcards -= ofp.OFPFW_TP_SRC
        match.dl_type = MT_TEST_DL_TYPE
        match.nw_proto = 6 #TCP
        match.tp_src = 80
        write_output(self, third_table, of_ports[1], match=match)

        # Generate a packet matching only flow 1 and 2; rcv on port[0]
        reply_check_dp(self, tcp_sport=10,
                       ing_port = of_ports[2], egr_port = of_ports[0])
        # Generate a packet matching both flow 1, 2 and 3; rcv on port[1]
        reply_check_dp(self, tcp_sport=80,
                       ing_port = of_ports[2], egr_port = of_ports[1])
Example #44
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')
Example #45
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto(self, testutils.WC_ACL_TABLE,
                             testutils.WC_SERV_TABLE)

        # Set up second match
        testutils.write_goto_output(self, testutils.WC_SERV_TABLE,
                                    testutils.EX_L2_TABLE, of_ports[0],
                                    of_ports[1])

        # Set up third match
        testutils.write_output(self, testutils.EX_L2_TABLE, of_ports[2])

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

        testutils.receive_pkt_verify(self, of_ports[2], pkt)
Example #46
0
    def runTest(self):
        """
        ** Currently, same scenario with "NoGoto" **

        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; do nothing // match but stop pipeline
        Fourth Table; Match IP Src A; send to 2  // not match, just a fake

        Then send in 2 packets:
        IP A, TCP C; expect out port 1
        IP A, TCP B; expect out port 1
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto(self, testutils.WC_ACL_TABLE,
                             testutils.WC_SERV_TABLE)

        # Set up second match
        testutils.write_goto_output(self, testutils.WC_SERV_TABLE,
                                    testutils.EX_L2_TABLE, of_ports[0],
                                    of_ports[2])

        # Set up third match, "Empty Instruction"
        pkt = testutils.simple_tcp_packet()
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            ing_port=of_ports[2],
                                            table_id=testutils.EX_L2_TABLE)
        testutils.flow_msg_install(self, request)

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

        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        testutils.reply_check_dp(self,
                                 tcp_sport=1234,
                                 ing_port=of_ports[2],
                                 egr_port=of_ports[0])
Example #47
0
 def runTest(self):
     of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger)
     
     for max_len in [0, 99, DEFAULT_MISS_SEND_LEN, ofp.OFPCML_MAX, ofp.OFPCML_NO_BUFFER]:
         rc = testutils.delete_all_flows(self.controller, basic_logger)
         self.assertEqual(rc, 0, "Failed to delete all flows")
         testutils.set_config_verify(self, max_len = (max_len % ofp.OFPCML_MAX + 10))
         if max_len == ofp.OFPCML_NO_BUFFER:
             testutils.set_config_verify(self, max_len = max_len)
         testutils.set_flow_miss_entry(self, ofp.OFPTC_TABLE_MISS_CONTROLLER, max_len, 0)
         for of_port in basic_port_map.keys():
             basic_logger.info("PKT IN test, port " + str(of_port))
             pkt = testutils.simple_tcp_packet()
             self.dataplane.send(of_port, str(pkt))
             #@todo Check for unexpected messages?
             testutils.do_barrier(self.controller)
             testutils.packetin_verify(self, pkt, max_len)
             response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
             while response != None:
                   response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
     testutils.set_config_verify(self, max_len = DEFAULT_MISS_SEND_LEN)
Example #48
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
        of_ports = testutils.clear_switch(self, basic_port_map.keys(),
                                          basic_logger)

        testutils.set_table_config(self, 0, ofp.OFPTC_TABLE_MISS_CONTROLLER,
                                   True)
        #_,miss_send_len = testutils.get_config_reply_verify(self)
        testutils.set_config_verify(self, max_len=ofp.OFPCML_NO_BUFFER)
        for of_port in basic_port_map.keys():
            basic_logger.info("PKT IN test, port " + str(of_port))
            pkt = testutils.simple_tcp_packet()
            self.dataplane.send(of_port, str(pkt))
            #@todo Check for unexpected messages?
            testutils.packetin_verify(self, pkt, ofp.OFPCML_NO_BUFFER)
            response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
            while response != None:
                response, _ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
        testutils.set_config_verify(self, max_len=DEFAULT_MISS_SEND_LEN)
Example #49
0
    def scenario2(self, first_table = 0, second_table = 1):
        """
        Set table config as "Continue" and add flow entry:
        First Table; Match IP Src A; send to 1 // not match then continue
        Second Table; Match IP Src B; send to 2 // do execution

        Then send in 2 packets:
        IP B; expect out port 2
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set table config as "continue"
        setup_table_config(self, first_table, ofp.OFPTC_TABLE_MISS_CONTINUE)

        # Set up flow entries
        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 in the first table, but in the second
        reply_check_dp(self, ip_src='192.168.1.70', tcp_sport=10,
                       ing_port = of_ports[2], egr_port = of_ports[1])
Example #50
0
    def runTest(self):
        """
        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; do nothing // match but stop pipeline
        Fourth Table; Match IP Src A; send to 2  // not match, just a fake

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

        @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(self, testutils.EX_ACL_TABLE,
                             testutils.WC_ACL_TABLE)

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

        # Set up third match
        testutils.write_output(self, testutils.WC_SERV_TABLE, of_ports[1],
                               of_ports[2])

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

        # Generate a packet matching flow 1, 2, and 3; rcv on port[0]
        testutils.reply_check_dp(self,
                                 tcp_sport=1234,
                                 ing_port=of_ports[2],
                                 egr_port=of_ports[1])
Example #51
0
    def runTest(self):
        """
        Add four flow entries:
        First Table; Match IP Src A; goto Second Table
        Second Table; Match IP Src A; send to 1, goto Third Table
        Third Table; Match IP Src A; clear action, goto Fourth Table
        Fourth Table; Match IP Src A; send to 2

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

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

        # Set up first match
        #write_goto(self, testutils.EX_ACL_TABLE, testutils.WC_ACL_TABLE)
        act = action.action_set_field()
        field = match.eth_src(parse.parse_mac("aa:aa:aa:aa:aa:aa"))
        act.field.add(field)
        testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_SERV_TABLE ,act = act)
        # Set up second match
        testutils.write_goto_output(self, testutils.WC_SERV_TABLE, testutils.EX_L3_TABLE, of_ports[0], of_ports[2])
        # Set up third match, "Clear Action"
        inst = instruction.instruction_clear_actions()
        testutils.write_goto(self, testutils.EX_L3_TABLE, testutils.WC_L3_TABLE, of_ports[2], add_inst=inst)
        # Set up fourth match
        testutils.write_output(self, testutils.WC_L3_TABLE, of_ports[1])
        #write_output(self, testutils.EX_L2_TABLE, 4)

        # 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])
Example #52
0
    def scenario2(self, first_table = 0, second_table = 1):
        """
        Set the first table config as "Send to Controller" and the second
        table as "Drop", add flow entries:
        First Table; Match IP Src A; send to 1 // if not match, packet_in
        Second Table; Match IP Src B; send to 2 // if not match, drop

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

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

        # Set up matches
        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 entry in the first table
        reply_check_ctrl(self, ip_src='192.168.1.70', tcp_sport=10,
                         ing_port = of_ports[2])
Example #53
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up first match
        testutils.write_goto(self, testutils.WC_ACL_TABLE,
                             testutils.EX_L3_TABLE)

        # Set up second match
        testutils.write_goto(self, testutils.WC_SERV_TABLE,
                             testutils.EX_L2_TABLE, of_ports[2])

        # Set up third match
        testutils.write_goto(self, testutils.EX_L2_TABLE,
                             testutils.EX_L3_TABLE)

        # Set up fourth match
        testutils.write_output(self, testutils.EX_L3_TABLE, of_ports[1])

        # 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])
Example #54
0
    def runTest(self):
        of_ports = testutils.clear_switch(self, basic_port_map.keys(), basic_logger)

        for max_len in [0, 99, DEFAULT_MISS_SEND_LEN, ofp.OFPCML_MAX, ofp.OFPCML_NO_BUFFER]:
            rc = testutils.delete_all_flows(self.controller, basic_logger)
            self.assertEqual(rc, 0, "Failed to delete all flows")
            testutils.set_config_verify(self, max_len = (max_len % ofp.OFPCML_MAX + 10))
            if max_len == ofp.OFPCML_NO_BUFFER:
                testutils.set_config_verify(self, max_len = max_len)
            
            request = message.flow_mod()
            request.table_id = 0
            request.priority = 0
            request.cookie = 123456
            act = action.action_output()
            act.max_len = max_len
            act.port = ofp.OFPP_CONTROLLER
            inst_packet_in = instruction.instruction_apply_actions()#apply
            inst_packet_in.actions.add(act)
            request.instructions.add(inst_packet_in)
            rv = self.controller.message_send(request)
             
            for of_port in basic_port_map.keys():
                basic_logger.info("PKT IN test, port " + str(of_port))
                pkt = testutils.simple_tcp_packet()
                self.dataplane.send(of_port, str(pkt))
                #@todo Check for unexpected messages?
                testutils.do_barrier(self.controller)
                #testutils.packetin_verify(self, pkt, max_len)
                response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
                self.assertEqual(response.cookie, request.cookie, "cookie is not equal")
                #print(response.cookie)
                #print(request.cookie)
                #clear the msg
                response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
                while response != None:
                      response,_ = self.controller.poll(ofp.OFPT_PACKET_IN, 1)
Example #55
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")
Example #56
0
    def scenario2(self, first_table=0, second_table=1):
        """
        Set table config as "Continue" and add flow entry:
        First Table; Match IP Src A; send to 1 // not match then continue
        Second Table; Match IP Src B; send to 2 // do execution

        Then send in 2 packets:
        IP B; expect out port 2
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set table config as "continue"
        setup_table_config(self, first_table, ofp.OFPTC_TABLE_MISS_CONTINUE)

        # Set up flow entries
        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 in the first table, but in the second
        reply_check_dp(self,
                       ip_src='192.168.1.70',
                       tcp_sport=10,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
Example #57
0
 def runTest(self):
     of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)
     mpls_multipush2_act_tests(self, test_condition=3)