Example #1
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port1)
     fm_new = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port2)
     fm_new.command = ofp.OFPFC_MODIFY_STRICT
     rv = self.controller.message_send(fm_orig)
     self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
     testutils.do_barrier(self.controller)
     rv = self.controller.message_send(fm_new)
     testutils.do_barrier(self.controller)
     self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
     flow_stats = testutils.flow_stats_get(self)
     self.assertEqual(len(flow_stats.stats),1, 
                      "Expected only one flow_mod")
     stat = flow_stats.stats[0]
     self.assertEqual(stat.match, fm_new.match)
     self.assertEqual(stat.instructions, fm_new.instructions)
Example #2
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 #3
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # make packet
        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99')
        match_ls = testutils.packet_to_exact_flow_match(pkt=pkt,
                                                        table_id=table_id,
                                                        ing_port=port_in)

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

        testutils.do_barrier(self.controller)

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

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        self.assertTrue(pkt_rec is not None, "rec none packet")
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #4
0
def setup_table_config(parent, table_id, table_config):
    request = message.table_mod()
    request.table_id = table_id
    request.config = table_config
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error configuring table")
    testutils.do_barrier(parent.controller)
Example #5
0
    def runTest(self):
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05',
                                          dl_dst='00:06:07:08:09:0a')

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

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

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        #print( str(pkt_rec).encode('hex'))
        self.assertTrue(pkt_rec is not None, "rec none packets")
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #6
0
 def runTest(self):
     basic_logger.info("Running TableStats")
     testutils.delete_all_flows(self.controller, self.logger)
     basic_logger.info("Sending table stats request")
     request = message.table_stats_request()
     response, _ = self.controller.transact(request, timeout=2)
 
     # delete everything, so there should be no entries
     self.assertEqual(self.get_first_table_active_entries(response), 0)
     # add two entries to first table
     m1 = testutils.match_all_generate()
     m1.dl_type = 0x800
     m1.wildcards ^= ofp.OFPFW_DL_TYPE
     fm1 = testutils.flow_msg_create(self, None, match=m1, egr_port=2)
     rv = self.controller.message_send(fm1)
     self.assertEqual(rv, 0)
     m2 = testutils.match_all_generate()
     m2.dl_type = 0x806
     m2.wildcards ^= ofp.OFPFW_DL_TYPE
     fm2 = testutils.flow_msg_create(self, None, match=m2, egr_port=2)
     rv = self.controller.message_send(fm2)
     self.assertEqual(rv, 0)
     testutils.do_barrier(self.controller)
     response, _ = self.controller.transact(request, timeout=2)
     self.assertEqual(self.get_first_table_active_entries(response), 2)
Example #7
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

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

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

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

        self.assertTrue(
            response is None,
            'OFPPC_NO_PACKET_IN flag is ignored on port (got a packet when we asked not to) '
            + str(of_port))
Example #8
0
def setup_table_config(parent, table_id, table_config):
    request = message.table_mod()
    request.table_id = table_id
    request.config = table_config
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error configuring table")
    testutils.do_barrier(parent.controller)
Example #9
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        #make packet;
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='00:06:07:08:09:0a')
        exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05', dl_dst='aa:aa:aa:aa:aa:aa')
        # get match list
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in)

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

        testutils.do_barrier(self.controller)

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

        self.assertTrue(pkt is not None,"rec none packets")
        self.assertEqual(str(exp_pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Example #10
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port1)
     fm_new = testutils.flow_msg_create(self, pkt, 
                                         ing_port=ing_port, 
                                         egr_port=out_port2)
     fm_new.command = ofp.OFPFC_MODIFY_STRICT
     rv = self.controller.message_send(fm_orig)
     self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
     testutils.do_barrier(self.controller)
     rv = self.controller.message_send(fm_new)
     testutils.do_barrier(self.controller)
     self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
     flow_stats = testutils.flow_stats_get(self)
     self.assertEqual(len(flow_stats.stats),1, 
                      "Expected only one flow_mod")
     stat = flow_stats.stats[0]
     self.assertEqual(stat.match, fm_new.match)
     self.assertEqual(stat.instructions, fm_new.instructions)
Example #11
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = ofp.OFPP_ALL
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)#flood
     inst = None
     inst = instruction.instruction_apply_actions()
     act = action.action_output()
     act.port = ofp.OFPP_IN_PORT #fwd to ingress
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
     self.assertTrue(response is None, 'Receive error message')
     #user sends packet
     self.dataplane.send(ing_port, str(pkt))
     testutils.do_barrier(self.controller)
     #verify pkt
     for of_port in flow_mods_port_map.keys():
         testutils.receive_pkt_verify(self, of_port, pkt)
Example #12
0
    def runTest(self):
        basic_logger.info("Running TableStats")
        testutils.delete_all_flows(self.controller, self.logger)
        basic_logger.info("Sending table stats request")
        request = message.table_stats_request()
        response, _ = self.controller.transact(request, timeout=2)

        # delete everything, so there should be no entries
        self.assertEqual(self.get_first_table_active_entries(response), 0)
        # add two entries to first table
        m1 = testutils.match_all_generate()
        m1.dl_type = 0x800
        m1.wildcards ^= ofp.OFPFW_DL_TYPE
        fm1 = testutils.flow_msg_create(self, None, match=m1, egr_port=2)
        rv = self.controller.message_send(fm1)
        self.assertEqual(rv, 0)
        m2 = testutils.match_all_generate()
        m2.dl_type = 0x806
        m2.wildcards ^= ofp.OFPFW_DL_TYPE
        fm2 = testutils.flow_msg_create(self, None, match=m2, egr_port=2)
        rv = self.controller.message_send(fm2)
        self.assertEqual(rv, 0)
        testutils.do_barrier(self.controller)
        response, _ = self.controller.transact(request, timeout=2)
        self.assertEqual(self.get_first_table_active_entries(response), 2)
Example #13
0
    def send_ctrl_exp_error(self, msg, log='', type=0, code=0):
        group_logger.info('Sending message ' + log)
        group_logger.debug(msg.show())
        rv = self.controller.message_send(msg)
        self.assertTrue(rv != -1, 'Error sending!')

        group_logger.info('Waiting for error messages...')
        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 1)

        self.assertTrue(response is not None,
                        'Did not receive an error message')

        self.assertEqual(response.header.type, ofp.OFPT_ERROR,
                         'Did not receive an error message')

        if type != 0:
            self.assertEqual(
                response.type, type,
                'Did not receive a ' + str(type) + ' type error message')

        if code != 0:
            self.assertEqual(
                response.code, code,
                'Did not receive a ' + str(code) + ' code error message')

        testutils.do_barrier(self.controller)
Example #14
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

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

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

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

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

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

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

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

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

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            testutils.receive_pkt_check(self.dataplane, pkt, of_ports, [], self,
                              pa_logger)
Example #16
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = ofp.OFPP_ALL
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self,
                                         pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)  #flood
     inst = None
     inst = instruction.instruction_apply_actions()
     act = action.action_output()
     act.port = ofp.OFPP_IN_PORT  #fwd to ingress
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
     self.assertTrue(response is None, 'Receive error message')
     #user sends packet
     self.dataplane.send(ing_port, str(pkt))
     testutils.do_barrier(self.controller)
     #verify pkt
     for of_port in flow_mods_port_map.keys():
         testutils.receive_pkt_verify(self, of_port, pkt)
Example #17
0
    def runTest(self):
        for of_port in sdn_port_map.keys():
            ing_port = of_port
            for egr_port in sdn_port_map.keys():
                if egr_port != of_port:
                    break
            #egr_port = (i+1) %4 + 1
            #print("\ncount: " + str(ing_port))
            #print("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            self.logger.info("\ncount: " + str(ing_port))
            self.logger.info("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            pkt = testutils.simple_tcp_packet()
            testutils.delete_all_flows(self.controller, self.logger)

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

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

            self.dataplane.send(ing_port, str(pkt))
            (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=1)
            #print("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            #print("\n")
            self.logger.info("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            self.logger.info("\n")
            self.assertTrue(rcv_pkt is not None, "Did not receive packet")
Example #18
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # make packet
        pkt = testutils.simple_tcp_packet(ip_src='192.168.0.99')
        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = table_id, ing_port = port_in)

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

        testutils.do_barrier(self.controller)

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

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)
        self.assertTrue(pkt_rec is not None,"rec none packet")
        self.assertEqual(str(pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Example #19
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 #20
0
    def runTest(self):
        # Construct packet to send to dataplane
        # Send packet to dataplane, once to each port
        # Poll controller with expect message type packet in

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

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

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


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

        self.assertTrue(response is None, 
                        'OFPPC_NO_PACKET_IN flag is ignored on port (got a packet when we asked not to) ' + 
                        str(of_port))
Example #21
0
    def runTest(self):
        #testutils.clear_switch(self,pa_port_map,pa_logger)
        testutils.delete_all_flows(self.controller, pa_logger)
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0])
        match_ls = parse.packet_to_flow_match(pkt)

        request = message.flow_mod()
        request.match_fields = match_ls
        request.flags = 0x18  #set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS

        action_list = []
        act = action.action_output()
        act.port = of_ports[1]
        action_list.append(act)

        inst = None
        instruction_list = []

        if len(instruction_list) == 0:
            inst = instruction.instruction_apply_actions()
            instruction_list.append(inst)

        for act in action_list:
            rv = inst.actions.add(act)
            self.assertTrue(rv, "Could not add action" + act.show())

        for i in instruction_list:
            rv = request.instructions.add(i)
            self.assertTrue(rv, "Could not add instruction " + i.show())

        #testutils.message_send(self, request)
        rv0 = self.controller.message_send(request)
        self.assertTrue(rv0 != -1, "Error sending flow mod")
        testutils.do_barrier(self.controller)

        #self.send_data(pkt, of_ports[0])
        self.dataplane.send(of_ports[0], str(pkt))

        aggregate_stats_req = message.aggregate_stats_request()
        aggregate_stats_req.match_fields = match_ls

        rv = self.controller.message_send(aggregate_stats_req)
        self.assertTrue(rv != -1, "Error sending flow stat req")
        #testutils.message_send(self, aggregate_stats_req)

        (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2)
        #print(response.show())
        self.assertTrue(response is not None, "No aggregate_stats reply")
        self.assertEqual(len(response.stats), 1,
                         "Did not receive aggregate stats reply")
        self.assertEqual(response.stats[0].packet_count, 0)  #1)
        self.assertEqual(response.stats[0].byte_count, 0)  #len(packet_in))
Example #22
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 #23
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 #24
0
    def runTest(self):
        #testutils.clear_switch(self,pa_port_map,pa_logger)
        testutils.delete_all_flows(self.controller, pa_logger)
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt  = testutils.simple_tcp_packet()
        #match_ls = packet_to_exact_flow_match(pkt = pkt, table_id = 0, in_port = of_ports[0])
        match_ls = parse.packet_to_flow_match(pkt)

        request = message.flow_mod()
        request.match_fields = match_ls
        request.flags = 0x18#set flags OFPFF_NO_PKT_COUNTS and OFPFF_NO_BYT_COUNTS
        
        action_list = []        
        act = action.action_output()
        act.port = of_ports[1]
        action_list.append(act)
        
        inst = None
        instruction_list = []
        
        if len(instruction_list) == 0: 
              inst = instruction.instruction_apply_actions()
              instruction_list.append(inst)
        
        for act in action_list:
              rv = inst.actions.add(act)
              self.assertTrue(rv, "Could not add action" + act.show())

        for i in instruction_list: 
              rv = request.instructions.add(i)
              self.assertTrue(rv, "Could not add instruction " + i.show())

        #testutils.message_send(self, request)
        rv0 = self.controller.message_send(request)
        self.assertTrue( rv0 != -1, "Error sending flow mod")
        testutils.do_barrier(self.controller)

        #self.send_data(pkt, of_ports[0])
        self.dataplane.send(of_ports[0],str(pkt))

        aggregate_stats_req = message.aggregate_stats_request()
        aggregate_stats_req.match_fields = match_ls
        
        rv = self.controller.message_send(aggregate_stats_req)
        self.assertTrue( rv != -1, "Error sending flow stat req")
        #testutils.message_send(self, aggregate_stats_req)

        (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_REPLY, 2)
        #print(response.show())
        self.assertTrue(response is not None, "No aggregate_stats reply")
        self.assertEqual(len(response.stats), 1, "Did not receive aggregate stats reply")
        self.assertEqual(response.stats[0].packet_count,0)#1)
        self.assertEqual(response.stats[0].byte_count,0)#len(packet_in))
Example #25
0
    def send_ctrl_exp_noerror(self, msg, log = ''):
        group_logger.info('Sending message ' + log)
#        group_logger.debug(msg.show())
        rv = self.controller.message_send(msg)
        self.assertTrue(rv != -1, 'Error sending!')

        group_logger.info('Waiting for error messages...')
        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 1)

        self.assertTrue(response is None, 'Unexpected error message received')

        testutils.do_barrier(self.controller);
Example #26
0
    def runTest(self):
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(vlan_tags=vlan_tags,
                                          mpls_tags=mpls_tags)

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

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

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_VLAN_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_VLAN_TABLE,
                               testutils.EX_MPLS_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(
            pkt=pkt, table_id=testutils.EX_MPLS_TABLE, ing_port=ing_port)
        exact_table_goto_table(self, testutils.EX_MPLS_TABLE,
                               testutils.EX_L3_TABLE, match_ls)

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

        testutils.do_barrier(self.controller)

        "send a packet from ing_port "
        self.dataplane.send(ing_port, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port,
                                                     timeout=1)
        self.assertTrue(pkt_rec is not None, "rec none packets")
        #print("++++++++++++++++++++++rcv_pkt++++++++++++++++++++++")
        #if pkt_rec is None:
        #   print(str(pkt_rec))
        #else:
        #   print(str(pkt_rec).encode('hex'))
        self.assertEqual(str(pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #27
0
    def send_ctrl_exp_noerror(self, msg, log = ''):
        group_logger.info('Sending message ' + log)
        group_logger.debug(msg.show())
        rv = self.controller.message_send(msg)
        self.assertTrue(rv != -1, 'Error sending!')

        group_logger.info('Waiting for error messages...')
        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 1)

        self.assertTrue(response is None, 'Unexpected error message received')

        testutils.do_barrier(self.controller);
Example #28
0
    def handleFlow(self, pkttype='TCP'):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        if (pkttype == 'ICMP'):
            pkt = testutils.simple_icmp_packet()
        else:
            pkt = testutils.simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        self.assertTrue(match is not None, 
                        "Could not generate flow match from pkt")
        match.wildcards &= ~ofp.OFPFW_IN_PORT
        act = action.action_output()

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

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

            match.in_port = ingress_port

            request = message.flow_mod()
            request.command = ofp.OFPFC_ADD
            request.match = match
            request.buffer_id = 0xffffffff
            inst = instruction.instruction_apply_actions()
            act.port = egress_port
            self.assertTrue(inst.actions.add(act), "Could not add action")
            self.assertTrue(request.instructions.add(inst),
                            "Could not add instruction")
            pa_logger.info("Inserting flow")
            rv = self.controller.message_send(request)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

            pa_logger.info("Sending packet to dp port " + 
                           str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=1)
            self.assertTrue(rcv_pkt is not None, "Did not receive packet")
            pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + 
                         str(rcv_port))
            self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
            self.assertEqual(str(pkt), str(rcv_pkt),
                             'Response packet does not match send packet')
Example #29
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 #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 set_apply_output(self, table_id, outport, add_inst=None):
     act = action.action_output()
     act.port = outport
     request = message.flow_mod()
     request.match = make_match()
     request.buffer_id = 0xffffffff
     request.table_id = table_id
     inst = instruction.instruction_apply_actions()
     self.assertTrue(inst.actions.add(act), "Can't add action")
     self.assertTrue(request.instructions.add(inst), "Can't add inst")
     if add_inst is not None:
         self.assertTrue(request.instructions.add(add_inst),
                         "Can't add inst")
     pa_logger.info("Inserting flow")
     rv = self.controller.message_send(request)
     self.assertTrue(rv != -1, "Error installing flow mod")
     testutils.do_barrier(self.controller)
Example #32
0
def write_goto(parent, set_id, next_id, ip_src=MT_TEST_IP, add_inst=None):
    """
    Make flow_mod of Goto table instruction
    """
    request = message.flow_mod()
    request.match = make_match(ip_src=ip_src)
    request.buffer_id = 0xffffffff
    request.table_id = set_id
    if add_inst is not None:
        parent.assertTrue(request.instructions.add(add_inst), "Can't add inst")
    inst = instruction.instruction_goto_table()
    inst.table_id = next_id
    parent.assertTrue(request.instructions.add(inst), "Can't add inst")
    pa_logger.info("Inserting flow")
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error installing flow mod")
    testutils.do_barrier(parent.controller)
Example #33
0
 def set_apply_output(self, table_id, outport, add_inst=None):
     act = action.action_output()
     act.port = outport
     request = message.flow_mod()
     request.match = make_match()
     request.buffer_id = 0xffffffff
     request.table_id = table_id
     inst = instruction.instruction_apply_actions()
     self.assertTrue(inst.actions.add(act), "Can't add action")
     self.assertTrue(request.instructions.add(inst), "Can't add inst")
     if add_inst is not None:
         self.assertTrue(request.instructions.add(add_inst),
                         "Can't add inst")
     pa_logger.info("Inserting flow")
     rv = self.controller.message_send(request)
     self.assertTrue(rv != -1, "Error installing flow mod")
     testutils.do_barrier(self.controller)
Example #34
0
def write_goto(parent, set_id, next_id, ip_src=MT_TEST_IP, add_inst=None):
    """
    Make flow_mod of Goto table instruction
    """
    request = message.flow_mod()
    request.match = make_match(ip_src=ip_src)
    request.buffer_id = 0xffffffff
    request.table_id = set_id
    if add_inst is not None:
        parent.assertTrue(request.instructions.add(add_inst), "Can't add inst")
    inst = instruction.instruction_goto_table()
    inst.table_id = next_id
    parent.assertTrue(request.instructions.add(inst), "Can't add inst")
    pa_logger.info("Inserting flow")
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error installing flow mod")
    testutils.do_barrier(parent.controller)
Example #35
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.wildcards &= ~ofp.OFPFW_IN_PORT
        self.assertTrue(match is not None, 
                        "Could not generate flow match from pkt")
        act1 = action.action_output()
        act2 = action.action_output()

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

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

            match.in_port = ingress_port

            act1.port = egress_port1
            act2.port = egress_port2
            
            request = testutils.flow_msg_create(self, pkt, ingress_port, action_list=[act1, act2])
            request.buffer_id = 0xffffffff
            
            pa_logger.info("Inserting flow")
            rv = self.controller.message_send(request)
            self.assertTrue(rv != -1, "Error installing flow mod")
            testutils.do_barrier(self.controller)

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

            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports,
                              self, pa_logger)
Example #36
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 #37
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 #38
0
def write_output(parent, set_id, outport, ip_src=MT_TEST_IP, match=None):
    """
    Make flow_mod of Write_action instruction of Output
    """
    act = action.action_output()
    act.port = outport
    request = message.flow_mod()
    if match is None:
        request.match = make_match(ip_src=ip_src)
    else:
        request.match = match
    request.buffer_id = 0xffffffff
    request.table_id = set_id
    inst = instruction.instruction_write_actions()
    parent.assertTrue(inst.actions.add(act), "Can't add action")
    parent.assertTrue(request.instructions.add(inst), "Can't add inst")
    pa_logger.info("Inserting flow")
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error installing flow mod")
    testutils.do_barrier(parent.controller)
Example #39
0
def write_output(parent, set_id, outport, ip_src=MT_TEST_IP, match=None):
    """
    Make flow_mod of Write_action instruction of Output
    """
    act = action.action_output()
    act.port = outport
    request = message.flow_mod()
    if match is None:
        request.match = make_match(ip_src=ip_src)
    else:
        request.match = match
    request.buffer_id = 0xffffffff
    request.table_id = set_id
    inst = instruction.instruction_write_actions()
    parent.assertTrue(inst.actions.add(act), "Can't add action")
    parent.assertTrue(request.instructions.add(inst), "Can't add inst")
    pa_logger.info("Inserting flow")
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error installing flow mod")
    testutils.do_barrier(parent.controller)
Example #40
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 #41
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        pkt = testutils.simple_tcp_packet()
#        match = parse.packet_to_flow_match(pkt)
#        match.wildcards &= ~ofp.OFPFW_IN_PORT
#        self.assertTrue(match is not None, 
#                        "Could not generate flow match from pkt")
#        act = action.action_output()

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

            pa_logger.info("Ingress " + str(ingress_port) + " to all ports")
#            match.in_port = ingress_port
#
#            request = message.flow_mod()
#            request.match = match
#            request.buffer_id = 0xffffffff
#            act.port = ofp.OFPP_ALL
#            self.assertTrue(request.actions.add(act), 
#                            "Could not add ALL port action")
            request = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, 
                                                egr_port=ofp.OFPP_ALL)
            # already done in flow_msg_create
            #pa_logger.info(request.show())

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

            pa_logger.info("Sending packet to dp port " + str(ingress_port))
            self.dataplane.send(ingress_port, str(pkt))
            yes_ports = set(of_ports).difference([ingress_port])
            testutils.receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
                              self, pa_logger)
Example #42
0
    def runTest(self):
        vlan_tags=[{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]
        ing_port = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        "make test packet;"
        pkt = testutils.simple_tcp_packet(vlan_tags = vlan_tags, mpls_tags = mpls_tags)

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

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

        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_VLAN_TABLE, ing_port = ing_port)
        exact_table_goto_table(self, testutils.EX_VLAN_TABLE, testutils.EX_MPLS_TABLE, match_ls)

        match_ls = testutils.packet_to_exact_flow_match(pkt = pkt, table_id = testutils.EX_MPLS_TABLE, ing_port = ing_port)
        exact_table_goto_table(self, testutils.EX_MPLS_TABLE, testutils.EX_L3_TABLE, match_ls)

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

        testutils.do_barrier(self.controller)

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

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

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

        testutils.do_barrier(self.controller)

        "send a packet from port_in "
        self.dataplane.send(port_in, str(pkt))
        "poll from the egr_port port"
        (port_rec, pkt_rec, _) = self.dataplane.poll(port_number=egr_port, timeout=1)
        #print( str(pkt_rec).encode('hex'))
        self.assertTrue(pkt_rec is not None,"rec none packets")
        self.assertEqual(str(pkt), str(pkt_rec), 'retruned pkt not equal to the original pkt')
Example #44
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 #45
0
    def runTest(self):
        for of_port in sdn_port_map.keys():
            ing_port = of_port
            for egr_port in sdn_port_map.keys():
                if egr_port != of_port:
                    break
            #egr_port = (i+1) %4 + 1
            #print("\ncount: " + str(ing_port))
            #print("erg_port : " + str(egr_port) + " ing_port: " + str(ing_port))
            self.logger.info("\ncount: " + str(ing_port))
            self.logger.info("erg_port : " + str(egr_port) + " ing_port: " +
                             str(ing_port))
            pkt = testutils.simple_tcp_packet()
            testutils.delete_all_flows(self.controller, self.logger)

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

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

            self.dataplane.send(ing_port, str(pkt))
            (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=1)
            #print("erg_port : " + str(rcv_port) + " pkt: %s" % str(rcv_pkt).encode("hex") )
            #print("\n")
            self.logger.info("erg_port : " + str(rcv_port) +
                             " pkt: %s" % str(rcv_pkt).encode("hex"))
            self.logger.info("\n")
            self.assertTrue(rcv_pkt is not None, "Did not receive packet")
Example #46
0
    def send_ctrl_exp_error(self, msg, log = '', type = 0, code = 0):
        group_logger.info('Sending message ' + log)
        group_logger.debug(msg.show())
        rv = self.controller.message_send(msg)
        self.assertTrue(rv != -1, 'Error sending!')

        group_logger.info('Waiting for error messages...')
        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 1)

        self.assertTrue(response is not None, 
                        'Did not receive an error message')

        self.assertEqual(response.header.type, ofp.OFPT_ERROR,
                         'Did not receive an error message')

        if type != 0:
            self.assertEqual(response.type, type,
                             'Did not receive a ' + str(type) + ' type error message')

        if code != 0:
            self.assertEqual(response.code, code,
                             'Did not receive a ' + str(code) + ' code error message')
        
        testutils.do_barrier(self.controller);
Example #47
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        #make packet;
        pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05',
                                          dl_dst='00:06:07:08:09:0a')
        exp_pkt = testutils.simple_tcp_packet(dl_src='00:01:02:03:04:05',
                                              dl_dst='aa:aa:aa:aa:aa:aa')
        # get match list
        match_ls = testutils.packet_to_exact_flow_match(pkt=pkt,
                                                        table_id=table_id,
                                                        ing_port=port_in)

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

        testutils.do_barrier(self.controller)

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

        self.assertTrue(pkt is not None, "rec none packets")
        self.assertEqual(str(exp_pkt), str(pkt_rec),
                         'retruned pkt not equal to the original pkt')
Example #48
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 #49
0
    def runTest(self):
        global pa_port_map

        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

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

        pkt = testutils.simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.wildcards &= ~ofp.OFPFW_IN_PORT
        self.assertTrue(match is not None, 
                        "Could not generate flow match from pkt")
        act = action.action_output()

        ingress_port = of_ports[0];
        egress_port = of_ports[1];
        pa_logger.info("Ingress " + str(ingress_port) + 
                       " to egress " + str(egress_port))
        
        match.in_port = ingress_port
        
        flow_mod_msg = message.flow_mod()
        flow_mod_msg.match = match
        flow_mod_msg.command = ofp.OFPFC_ADD
        flow_mod_msg.cookie = random.randint(0,9007199254740992)
        flow_mod_msg.buffer_id = 0xffffffff
        flow_mod_msg.idle_timeout = 1
        act.port = egress_port
        #pdb.set_trace()
        inst = instruction.instruction_apply_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(flow_mod_msg.instructions.add(inst), "Could not add action")
        
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_ANY;
        stat_req.out_group = ofp.OFPG_ANY;

        testutils.do_barrier(self.controller)
        pa_logger.info("Sending stats request (before flow_mod insert)")
        rv = self.controller.message_send(stat_req)
        self.assertTrue(rv != -1, "Error sending flow stat req")
        testutils.do_barrier(self.controller)

        (empty_response, _) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
        self.assertTrue(empty_response, "No flow_stats reply (expected empty flow_stats)")
        self.assertEqual(len(empty_response.stats),0)

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

        pa_logger.info("Sending packet to dp port " + 
                       str(ingress_port))
        self.dataplane.send(ingress_port, str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=2)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(pkt)) + " in on " + 
                        str(rcv_port))
        self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
        self.assertEqual(str(pkt), str(rcv_pkt),
                         'Response packet does not match send packet')
            
        pa_logger.info("Sending stats request")
        rv = self.controller.message_send(stat_req)
        self.assertTrue(rv != -1, "Error sending flow stat req")
        testutils.do_barrier(self.controller)

        (response, _) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
        self.assertTrue(response, "No Flow_stats reply")
        #print "YYY: Stats reply is \n%s" % (response.show())
        self.assertEqual(len(response.stats), 1, "Did not receive flow stats reply")
        self.assertEqual(response.stats[0].packet_count,1)
        self.assertEqual(response.stats[0].byte_count,len(rcv_pkt))
Example #50
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        # Clear flow table
        rv = testutils.initialize_table_config(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to initialize table config")
        rv = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        # Set up first match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.nw_src_mask = 0 # Match nw_src
        match.dl_type = 0x800
        match.nw_src = parse.parse_ip("192.168.1.10")
        act = action.action_output()
        act.port = of_ports[0]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 0
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst1")
        inst = instruction.instruction_goto_table()
        inst.table_id = 1
        self.assertTrue(request.instructions.add(inst), "Could not add inst2")
        pa_logger.info("Inserting flow 1")
        rv = self.controller.message_send(request)
        # pa_logger.debug(request.show())
        self.assertTrue(rv != -1, "Error installing flow mod")

        # Set up second 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 = 0x800
        match.nw_proto = 6 # TCP
        match.tp_src = 80
        act = action.action_output()
        act.port = of_ports[1]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 1
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst3")
        pa_logger.info("Inserting flow 2")
        # pa_logger.debug(request.show())
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")
        testutils.do_barrier(self.controller)

        # Generate a packet matching only flow 1; rcv on port[0]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=10)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + 
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[0], "Unexpected receive port")
        
        # Generate a packet matching both flow 1 and flow 2; rcv on port[1]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=80)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + 
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")
Example #51
0
    def runTest(self):
        global pa_port_map

        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

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

        pkt = testutils.simple_tcp_packet()
        match = parse.packet_to_flow_match(pkt)
        match.wildcards &= ~ofp.OFPFW_IN_PORT
        self.assertTrue(match is not None,
                        "Could not generate flow match from pkt")
        act = action.action_output()

        ingress_port = of_ports[0]
        egress_port = of_ports[1]
        pa_logger.info("Ingress " + str(ingress_port) + " to egress " +
                       str(egress_port))

        match.in_port = ingress_port

        flow_mod_msg = message.flow_mod()
        flow_mod_msg.match = match
        flow_mod_msg.command = ofp.OFPFC_ADD
        flow_mod_msg.cookie = random.randint(0, 9007199254740992)
        flow_mod_msg.buffer_id = 0xffffffff
        flow_mod_msg.idle_timeout = 1
        act.port = egress_port
        #pdb.set_trace()
        inst = instruction.instruction_apply_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(flow_mod_msg.instructions.add(inst),
                        "Could not add action")

        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY

        testutils.do_barrier(self.controller)
        pa_logger.info("Sending stats request (before flow_mod insert)")
        rv = self.controller.message_send(stat_req)
        self.assertTrue(rv != -1, "Error sending flow stat req")
        testutils.do_barrier(self.controller)

        (empty_response, _) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
        self.assertTrue(empty_response,
                        "No flow_stats reply (expected empty flow_stats)")
        self.assertEqual(len(empty_response.stats), 0)

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

        pa_logger.info("Sending packet to dp port " + str(ingress_port))
        self.dataplane.send(ingress_port, str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=2)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(pkt)) + " in on " +
                        str(rcv_port))
        self.assertEqual(rcv_port, egress_port, "Unexpected receive port")
        self.assertEqual(str(pkt), str(rcv_pkt),
                         'Response packet does not match send packet')

        pa_logger.info("Sending stats request")
        rv = self.controller.message_send(stat_req)
        self.assertTrue(rv != -1, "Error sending flow stat req")
        testutils.do_barrier(self.controller)

        (response, _) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
        self.assertTrue(response, "No Flow_stats reply")
        #print "YYY: Stats reply is \n%s" % (response.show())
        self.assertEqual(len(response.stats), 1,
                         "Did not receive flow stats reply")
        self.assertEqual(response.stats[0].packet_count, 1)
        self.assertEqual(response.stats[0].byte_count, len(rcv_pkt))
Example #52
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 #53
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        # Clear flow table
        rv = testutils.initialize_table_config(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to initialize table config")
        rv = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        # Set up first match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.nw_src_mask = 0  # Match nw_src
        match.dl_type = 0x800
        match.nw_src = parse.parse_ip("192.168.1.10")
        act = action.action_output()
        act.port = of_ports[0]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 0
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst1")
        inst = instruction.instruction_goto_table()
        inst.table_id = 1
        self.assertTrue(request.instructions.add(inst), "Could not add inst2")
        pa_logger.info("Inserting flow 1")
        rv = self.controller.message_send(request)
        # pa_logger.debug(request.show())
        self.assertTrue(rv != -1, "Error installing flow mod")

        # Set up second 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 = 0x800
        match.nw_proto = 6  # TCP
        match.tp_src = 80
        act = action.action_output()
        act.port = of_ports[1]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 1
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst3")
        pa_logger.info("Inserting flow 2")
        # pa_logger.debug(request.show())
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")
        testutils.do_barrier(self.controller)

        # Generate a packet matching only flow 1; rcv on port[0]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=10)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[0], "Unexpected receive port")

        # Generate a packet matching both flow 1 and flow 2; rcv on port[1]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=80)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")