Example #1
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port1 = of_ports[len(of_ports)-1]
        egr_port2 = of_ports[0]

        pkt = testutils.simple_tcp_packet(dl_src='99:33:11:11:11:55', dl_dst='33:33:11:11:77:66')
        pkt_metadata = {'metadata_val':0x99999999, 
                        'metadata_msk':0xFFFFFFFFFFFFFFFF}
        request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port1, table_id = table_id)
        testutils.flow_msg_install(self, request)

        #"mod it ,add outport 1"
        request_mod = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port2, table_id = table_id)
        request_mod.command = ofp.OFPFC_MODIFY
        testutils.ofmsg_send(self, request_mod)
        #print(flow_mod.show())

        #"read it back;"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
        self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats)))
        self.assertEqual(response.stats[0].instructions.items[0].actions.items[0].port,
                         request_mod.instructions.items[0].actions.items[0].port,
                         "action error:"+str(response.stats[0].instructions.items[0].actions.items[0].port))
Example #2
0
def Verify_FlowStats(self,match,byte_count=0,packet_count=0):
# Verify flow counters : byte_count and packet_count

        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE
        test_timeout = 10
        all_packets_received = 0
        for i in range(0,test_timeout):
            
            response, pkt = self.controller.transact(stat_req,
                                                     timeout=test_timeout)
            self.assertTrue(response is not None, 
                            "No response to stats request")
            for obj in response.stats:
                if ( obj.packet_count == packet_count and obj.byte_count == byte_count ) :
                    all_packets_received = 1

            if all_packets_received:
                break
            sleep(1)

        self.assertTrue(all_packets_received,
                        "Flow counters are incorrect")
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 verifyStats(self, match, out_port, test_timeout, packet_count):
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = out_port

        all_packets_received = 0
        for i in range(0, test_timeout):
            fs_logger.info("Sending stats request")
            response, pkt = self.controller.transact(stat_req,
                                                     timeout=test_timeout)
            self.assertTrue(response is not None,
                            "No response to stats request")
            self.assertTrue(
                len(response.stats) == 1, "Did not receive flow stats reply")
            for obj in response.stats:
                # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
                # for now, just clear them so the assert is simpler
                #obj.match.pad1 = 0
                #obj.match.pad2 = [0, 0]
                #self.assertEqual(match, obj.match,
                #                 "Matches do not match")
                fs_logger.info("Received " + str(obj.packet_count) +
                               " packets")
                if obj.packet_count == packet_count:
                    all_packets_received = 1

            if all_packets_received:
                break
            sleep(1)

        self.assertTrue(all_packets_received,
                        "Packet count does not match number sent")
Example #5
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[0]

        pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22', dl_dst='22:22:22:22:22:22')
        pkt_metadata = {'metadata_val':0x1122334455667788, 
                        'metadata_msk':0xFFFFFFFFFFFFFFFF}
        request = testutils.flow_msg_create(self, pkt, pkt_metadata, egr_port = egr_port, table_id = table_id)
        testutils.flow_msg_install(self, request)

        #"delete it"
        request_del = testutils.flow_msg_create(self, pkt, match_fields = request.match_fields, egr_port = egr_port, table_id = table_id)
        request_del.command = ofp.OFPFC_DELETE
        testutils.ofmsg_send(self, request_del)

        #'read it back , returns blank;'
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
        self.assertEqual(len(response.stats),0, "len of stats is:"+str(len(response.stats)))
Example #6
0
    def runTest(self):
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        table_id = testutils.EX_ACL_TABLE
        of_ports = exact_port_map.keys()
        port_in = of_ports[0]
        egr_port = of_ports[1]
        vlan_tags=[{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags=[{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]

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

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

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

        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.match_fields = match_ls
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPP_ANY
        
        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
        self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats)))
Example #7
0
    def verifyStats(self, match, out_port, test_timeout, packet_count):
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = out_port

        all_packets_received = 0
        for i in range(0,test_timeout):
            fs_logger.info("Sending stats request")
            # TODO: move REPLY_MORE handling to controller.transact?
            response, pkt = self.controller.transact(stat_req,
                                                     timeout=test_timeout)
            self.assertTrue(response is not None,
                            "No response to stats request")
            total_packets = self.sumStatsReplyCounts(response)

            while response.flags == ofp.OFPSF_REPLY_MORE:
               response, pkt = self.controller.poll(exp_msg=
                                                    ofp.OFPT_STATS_REPLY,
                                                    timeout=test_timeout)
               total_packets += self.sumStatsReplyCounts(response)

            if total_packets == packet_count:
                all_packets_received = 1
                break
            sleep(1)

        self.assertTrue(all_packets_received,
                        "Total stats packet count " + str(total_packets) +
                        " does not match number sent " + str(packet_count))
Example #8
0
    def runTest(self):
        table_id = testutils.EX_ACL_TABLE
        port_in = exact_port_map.keys()[0]
        egr_port = exact_port_map.keys()[1]
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        # make packet
        pkt = testutils.simple_tcp_packet(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 #9
0
    def verifyStats(self, match, out_port, test_timeout, packet_count):
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = out_port

        all_packets_received = 0
        for i in range(0, test_timeout):
            fs_logger.info("Sending stats request")
            # TODO: move REPLY_MORE handling to controller.transact?
            response, pkt = self.controller.transact(stat_req,
                                                     timeout=test_timeout)
            self.assertTrue(response is not None,
                            "No response to stats request")
            total_packets = self.sumStatsReplyCounts(response)

            while response.flags == ofp.OFPSF_REPLY_MORE:
                response, pkt = self.controller.poll(
                    exp_msg=ofp.OFPT_STATS_REPLY, timeout=test_timeout)
                total_packets += self.sumStatsReplyCounts(response)

            if total_packets == packet_count:
                all_packets_received = 1
                break
            sleep(1)

        self.assertTrue(
            all_packets_received,
            "Total stats packet count " + str(total_packets) +
            " does not match number sent " + str(packet_count))
Example #10
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[len(of_ports) - 1]

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

        testutils.flow_msg_install(self, request)
        #"get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 1,
                         "len of stats is:" + str(len(response.stats)))
Example #11
0
    def runTest(self):
        
        logging.info("Running DurationPerFlow test")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
        
        #Clear switch state
        delete_all_flows(self.controller)

        logging.info("Insert any flow")
        logging.info("Send Flow_stats request after n sec intervals")
        logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")

        #Create a flow with match on ingress_port
        (pkt,match) = wildcard_all_except_ingress(self,of_ports)
    
        #Create flow_stats request 
        stat_req = message.flow_stats_request()
        stat_req.match= match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE

        expected_duration = 3
        sleep(expected_duration)

        response, pkt = self.controller.transact(stat_req)
        
        self.assertTrue(response is not None,"No response to stats request")
        self.assertTrue(len(response.stats) == 1,"Did not receive flow stats reply")
        
        stat = response.stats[0]
        logging.info("Duration of flow is %d s %d ns", stat.duration_sec, stat.duration_nsec) 
        self.assertTrue(stat.duration_sec == expected_duration, "Flow stats reply incorrect")
Example #12
0
    def verifyStats(self, match, out_port, test_timeout, packet_count):
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = out_port

        all_packets_received = 0
        for i in range(0,test_timeout):
            fs_logger.info("Sending stats request")
            response, pkt = self.controller.transact(stat_req,
                                                     timeout=test_timeout)
            self.assertTrue(response is not None, 
                            "No response to stats request")
            self.assertTrue(len(response.stats) == 1,
                            "Did not receive flow stats reply")
            for obj in response.stats:
                # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
                # for now, just clear them so the assert is simpler
                #obj.match.pad1 = 0
                #obj.match.pad2 = [0, 0]
                #self.assertEqual(match, obj.match,
                #                 "Matches do not match")
                fs_logger.info("Received " + str(obj.packet_count) + " packets")
                if obj.packet_count == packet_count:
                    all_packets_received = 1

            if all_packets_received:
                break
            sleep(1)

        self.assertTrue(all_packets_received,
                        "Packet count does not match number sent")
Example #13
0
    def runTest(self):
        #"clear swtich;"
        testutils.delete_all_flows(self.controller, self.logger)
        table_id = testutils.EX_ACL_TABLE
        of_ports = exact_port_map.keys()
        port_in = of_ports[0]
        egr_port = of_ports[1]
        vlan_tags = [{'type': 0x8100, 'vid': 3, 'pcp': 1}]
        mpls_tags = [{'type': 0x8847, 'label': 22, 'tc': 2, 'ttl': 48}]

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

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

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

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

        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 1,
                         "len of stats is:" + str(len(response.stats)))
Example #14
0
 def runTest(self):
     basic_logger.info("Running StatsGet")
     basic_logger.info("Inserting trial flow")
     request = message.flow_mod()
     request.match.wildcards = ofp.OFPFW_ALL
     request.buffer_id = 0xffffffff
     for i in range(1, 5):
         request.priority = i * 1000
         basic_logger.debug("Adding flow %d" % i)
         rv = self.controller.message_send(request)
         self.assertTrue(rv != -1, "Failed to insert test flow %d" % i)
     basic_logger.info("Removing all flows")
     testutils.delete_all_flows(self.controller, basic_logger)
     basic_logger.info("Sending flow request")
     request = message.flow_stats_request()
     request.out_port = ofp.OFPP_ANY
     request.out_group = ofp.OFPG_ANY
     request.table_id = 0xff
     request.match.wildcards = 0  # ofp.OFPFW_ALL
     response, _ = self.controller.transact(request, timeout=2)
     self.assertTrue(response is not None, "Did not get response")
     self.assertTrue(isinstance(response, message.flow_stats_reply),
                     "Not a flow_stats_reply")
     self.assertEqual(len(response.stats), 0)
     basic_logger.debug(response.show())
Example #15
0
 def runTest(self):
     request = message.flow_stats_request()
     request.out_port = ofp.OFPP_ANY
     request.out_group = ofp.OFPG_ANY
     request.table_id = ofp.OFPTT_ALL
     response, _ = self.controller.transact(request, timeout=2)
     #print(response.show())
     self.logger.info(response.show())
Example #16
0
 def runTest(self):
     request = message.flow_stats_request()
     request.out_port = ofp.OFPP_ANY
     request.out_group = ofp.OFPG_ANY
     request.table_id = ofp.OFPTT_ALL
     response, _ = self.controller.transact(request, timeout=2)
     #print(response.show())
     self.logger.info(response.show())
Example #17
0
def get_flowstats(self, match):
    # Generate flow_stats request

    stat_req = message.flow_stats_request()
    stat_req.match = match
    stat_req.table_id = 0xff
    stat_req.out_port = ofp.OFPP_NONE

    logging.info("Sending stats request")
    response, pkt = self.controller.transact(stat_req, timeout=5)
    self.assertTrue(response is not None, "No response to stats request")
Example #18
0
def get_flowstats(self, match):
    # Generate flow_stats request

    stat_req = message.flow_stats_request()
    stat_req.match = match
    stat_req.table_id = 0xFF
    stat_req.out_port = ofp.OFPP_NONE

    logging.info("Sending stats request")
    response, pkt = self.controller.transact(stat_req, timeout=5)
    self.assertTrue(response is not None, "No response to stats request")
Example #19
0
    def runTest(self):
        delete_all_flows(self.controller)
        match = ofp.ofp_match()
        match.wildcards = 0
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE

        response, pkt = self.controller.transact(stat_req)
        self.assertTrue(response is not None,
                        "No response to stats request")
        self.assertEquals(len(response.stats), 0)
        self.assertEquals(response.flags, 0)
Example #20
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")
        ingress_port = of_ports[0]
        egress_port = of_ports[1]

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

        #controller send flow_mod to switch
        pkt = testutils.simple_tcp_packet()
        flow_mod_add = testutils.flow_msg_create(
            self,
            pkt,
            ing_port=ingress_port,
            egr_port=egress_port,
            table_id=testutils.EX_ACL_TABLE)
        testutils.flow_msg_install(self, flow_mod_add)

        #user send pkt to switch, switch transfer to eng_port
        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(egress_port, 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')

        #check the  stats msg
        stat_req = message.flow_stats_request()
        stat_req.match_fields = flow_mod_add.match_fields
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY

        pa_logger.info("Sending stats request")
        testutils.ofmsg_send(self, stat_req)

        (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_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 #21
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp100No20 BadRequestBadVersion Test")

        # Send a flow_stats request , with incorrect version
        logging.info("Sending flow_mod request.. ")
        request = message.flow_stats_request()
        request.header.version = 0
        rv = self.controller.message_send(request)

        logging.info("Waiting for OFPT_ERROR message..")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(response is not None, "Switch did not reply with error message")
        self.assertTrue(response.type == ofp.OFPET_BAD_REQUEST, "Error type is not OFPET_BAD_REQUEST")
        self.assertTrue(response.code == ofp.OFPBRC_BAD_VERSION, "Error code is not OFPBRC_BAD_VERSION")
Example #22
0
    def runTest(self):
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows")
        match = ofp.ofp_match()
        match.wildcards = 0
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE

        response, pkt = self.controller.transact(stat_req)
        self.assertTrue(response is not None,
                        "No response to stats request")
        self.assertEquals(len(response.stats), 0)
        self.assertEquals(response.flags, 0)
Example #23
0
 def runTest(self):
     basic_logger.info("Running StatsGet")
     basic_logger.info("Inserting trial flow")
     request = flow_mod_gen(basic_port_map, True)
     rv = self.controller.message_send(request)
     self.assertTrue(rv != -1, "Failed to insert test flow")
     
     basic_logger.info("Sending flow request")
     request = message.flow_stats_request()
     request.out_port = ofp.OFPP_NONE
     request.table_id = 0xff
     request.match.wildcards = 0 # ofp.OFPFW_ALL
     response, pkt = self.controller.transact(request)
     self.assertTrue(response is not None, "Did not get response")
     basic_logger.debug(response.show())
Example #24
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port1 = of_ports[len(of_ports) - 1]
        egr_port2 = of_ports[0]

        pkt = testutils.simple_tcp_packet(dl_src='99:33:11:11:11:55',
                                          dl_dst='33:33:11:11:77:66')
        pkt_metadata = {
            'metadata_val': 0x99999999,
            'metadata_msk': 0xFFFFFFFFFFFFFFFF
        }
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            pkt_metadata,
                                            egr_port=egr_port1,
                                            table_id=table_id)
        testutils.flow_msg_install(self, request)

        #"mod it ,add outport 1"
        request_mod = testutils.flow_msg_create(
            self,
            pkt,
            match_fields=request.match_fields,
            egr_port=egr_port2,
            table_id=table_id)
        request_mod.command = ofp.OFPFC_MODIFY
        testutils.ofmsg_send(self, request_mod)
        #print(flow_mod.show())

        #"read it back;"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        #print(response.show())
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 1,
                         "len of stats is:" + str(len(response.stats)))
        self.assertEqual(
            response.stats[0].instructions.items[0].actions.items[0].port,
            request_mod.instructions.items[0].actions.items[0].port,
            "action error:" +
            str(response.stats[0].instructions.items[0].actions.items[0].port))
Example #25
0
    def runTest(self):
        logging.info("Running StatsGet")
        logging.info("Inserting trial flow")
        request = flow_mod_gen(config["port_map"], True)
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Failed to insert test flow")

        logging.info("Sending flow request")
        request = message.flow_stats_request()
        request.out_port = ofp.OFPP_NONE
        request.table_id = 0xff
        request.match.wildcards = 0  # ofp.OFPFW_ALL
        response, pkt = self.controller.transact(request)
        self.assertTrue(response is not None,
                        "Did not get response for flow stats")
        logging.debug(response.show())
Example #26
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")
        ingress_port = of_ports[0];
        egress_port = of_ports[1];

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

        #controller send flow_mod to switch
        pkt = testutils.simple_tcp_packet()
        flow_mod_add = testutils.flow_msg_create(self, pkt, ing_port=ingress_port, egr_port=egress_port, table_id=testutils.EX_ACL_TABLE)
        testutils.flow_msg_install(self, flow_mod_add)

        #user send pkt to switch, switch transfer to eng_port
        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(egress_port, 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')

        #check the  stats msg
        stat_req = message.flow_stats_request()
        stat_req.match_fields = flow_mod_add.match_fields
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_ANY;
        stat_req.out_group = ofp.OFPG_ANY;
        
        pa_logger.info("Sending stats request")
        testutils.ofmsg_send(self,  stat_req)

        (response, _) = self.controller.poll(ofp.OFPT_MULTIPART_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 #27
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp100No20 BadRequestBadVersion Test") 

        #Send a flow_stats request , with incorrect version
        logging.info("Sending flow_mod request.. ")
        request=message.flow_stats_request();
        request.header.version=0        
        rv = self.controller.message_send(request)
        
        logging.info("Waiting for OFPT_ERROR message..")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                               timeout=5)
        self.assertTrue(response is not None, 
                               'Switch did not reply with error message')
        self.assertTrue(response.type==ofp.OFPET_BAD_REQUEST, 
                               'Error type is not OFPET_BAD_REQUEST') 
        self.assertTrue(response.code==ofp.OFPBRC_BAD_VERSION, 
                               'Error code is not OFPBRC_BAD_VERSION')
Example #28
0
def verify_flowstats(self, match, byte_count=None, packet_count=None):
    '''
    Ensures that packet_count packets and byte_count bytes have
    been recorded and are advertised by dut.
    '''
    stat_req = message.flow_stats_request()
    stat_req.match = match
    stat_req.table_id = 0xff
    stat_req.out_port = ofp.OFPP_NONE

    for i in range(0, 60):
        logging.info("Sending stats request")
        # TODO: move REPLY_MORE handling to controller.transact?
        response, pkt = self.controller.transact(stat_req, timeout=5)
        self.assertTrue(response is not None, "No response to stats request")

        packet_counter = 0
        byte_counter = 0

        sleep(1)

        for item in response.stats:
            packet_counter += item.packet_count
            byte_counter += item.byte_count
            logging.info("packet_counter " + str(item.packet_count) +
                         " packets")
            logging.info("byte_counter " + str(item.byte_count) + " bytes")

        if packet_count != None and packet_count != packet_counter: continue
        if byte_count != None and byte_count != byte_counter: continue
        break
    counter = [byte_counter, byte_counter + 20]
    if packet_count != None:
        self.assertEqual(
            packet_count, packet_counter,
            "Expected packet count of {0} recived {1} instead.".format(
                packet_count, packet_counter))

    if byte_count != None:
        self.assertIn(
            byte_count, counter,
            "Expected byte count of {0} received {1} instead.".format(
                byte_count, counter))
Example #29
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp60No30 DurationPerFlow test")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        #Clear switch state
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        logging.info("Installing a flow entry")
        #Create a flow with match on ingress_port
        (pkt, match) = wildcard_all_except_ingress(self, of_ports)

        #Create flow_stats request
        test_timeout = 30
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE

        flow_stats_gen_ts = range(10, test_timeout, 10)

        for ts in range(0, test_timeout):
            if ts in flow_stats_gen_ts:
                logging.info("Sending a flow stats request")
                response, pkt = self.controller.transact(stat_req)

                self.assertTrue(response is not None,
                                "No response to stats request")
                self.assertTrue(
                    len(response.stats) == 1,
                    "Did not receive flow stats reply")

                stat = response.stats[0]
                self.assertTrue(stat.duration_sec == ts,
                                "Flow stats reply incorrect")
                logging.info("Duration of flow is " + str(stat.duration_sec) +
                             str(stat.duration_nsec))

            sleep(1)
Example #30
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp60No40 Duration (nsecs).")
        dataplane_ports = config["port_map"].keys()
        dataplane_ports.sort()
        self.assertTrue(len(dataplane_ports) > 1, "Not enough ports for test.")
        
        logging.info("Clearing switch state...")
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows.")

        logging.info("Installing flow entry that matches on in_port.")
        (pkt,match) = wildcard_all_except_ingress(self, dataplane_ports)

        req = message.flow_stats_request()
        req.match= match
        req.table_id = 0xff
        req.out_port = ofp.OFPP_NONE

        duration_verifications = 5
        previous_duration = (-1, -1)
        for v in range(0, duration_verifications):
            logging.info("Sending ofp_stats_request of type ofp.OFPST_FLOW")
            res, pkt = self.controller.transact(req)
            self.assertTrue(res is not None, "No ofp_stats_reply message received in response to ofp_stats_request.")
            self.assertTrue(res.type == ofp.OFPST_FLOW, "Expected ofp_stats_reply of type ofp.OFPST_FLOW, got {0}".format(res.type))
            self.assertTrue(len(res.stats) == 1, "Received {0} ofp_flow_stats in the ofp_stats_reply message, but expected exactly 1".format(len(res.stats)))

            logging.info("Comparing duration in nsecs from ofp_flow_stats to previous duration in nsecs.")
            duration = (res.stats[0].duration_sec, res.stats[0].duration_nsec)
            if duration[1] < previous_duration[1]:
                self.assertGreater(duration[0], previous_duration[0], "Duration in nsecs was less than previous duration in nsecs, but the duration in secs was not greater than the previous duration in secs.")
            else:
                # In the case that a switch can't report in
                # millisecond granularity, we expect
                # duration_nsec to be reported as 0xffffffff.
                if duration[1] == previous_duration[1] and duration[1] == 4294967295:
                    logging.info("Duration in nsec is not supported. Reported as -1 or 0xffffffff")
                    return
                self.assertNotEqual(duration[1], previous_duration[1], "ofp_flow_stats.duration_nsec {0} was the same as the previous duration_nsec {1}.".format(duration, previous_duration))
            previous_duration = duration
            time.sleep(1.5)
Example #31
0
def Verify_FlowStats(self,match,stats_byte_count=0,stats_packet_count=0):
# Verify Flow_Stats

        # Send Flow_Stats_Request       
        request = message.flow_stats_request()
        request.out_port = ofp.OFPP_NONE
        request.table_id = 0xff
        request.match = match
        response, pkt = self.controller.transact(request, timeout=1)
        self.assertTrue(response is not None, "Did not get response")
        byte_count = 0 
        packet_count = 0

        #Verify byte_count and packet_count in the reply
        for stat in response.stats:
            byte_count += stat.byte_count
            packet_count += stat.packet_count
            self.assertEqual(stats_byte_count,byte_count,
                        "Byte counter is incorrect")
            self.assertEqual(stats_packet_count,packet_count,
                        "Packet counter is incorrect")
Example #32
0
    def runTest(self):
        
        logging.info("Running DurationPerFlow test")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
        
        #Clear switch state
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        logging.info("Insert any flow")
        logging.info("Send Flow_stats request after n sec intervals")
        logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")

        #Create a flow with match on ingress_port
        (pkt,match) = wildcard_all_except_ingress(self,of_ports)
    
        #Create flow_stats request 
        test_timeout = 30
        stat_req = message.flow_stats_request()
        stat_req.match= match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE
        
        flow_stats_gen_ts =  range (10,test_timeout,10)
        
        for ts in range(0,test_timeout):
            if ts in flow_stats_gen_ts:
                response, pkt = self.controller.transact(stat_req)
                
                self.assertTrue(response is not None,"No response to stats request")
                self.assertTrue(len(response.stats) == 1,"Did not receive flow stats reply")
                
                stat = response.stats[0]
                self.assertTrue(stat.duration_sec == ts,"Flow stats reply incorrect")
                logging.info("Duration of flow is " + str(stat.duration_sec) + str(stat.duration_nsec)) 
            
            sleep(1)
Example #33
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[0]

        pkt = testutils.simple_tcp_packet(dl_src='22:22:22:22:22:22',
                                          dl_dst='22:22:22:22:22:22')
        pkt_metadata = {
            'metadata_val': 0x1122334455667788,
            'metadata_msk': 0xFFFFFFFFFFFFFFFF
        }
        request = testutils.flow_msg_create(self,
                                            pkt,
                                            pkt_metadata,
                                            egr_port=egr_port,
                                            table_id=table_id)
        testutils.flow_msg_install(self, request)

        #"delete it"
        request_del = testutils.flow_msg_create(
            self,
            pkt,
            match_fields=request.match_fields,
            egr_port=egr_port,
            table_id=table_id)
        request_del.command = ofp.OFPFC_DELETE
        testutils.ofmsg_send(self, request_del)

        #'read it back , returns blank;'
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        self.assertTrue(isinstance(response, message.flow_stats_reply),
                        "Not a flow_stats_reply")
        self.assertEqual(len(response.stats), 0,
                         "len of stats is:" + str(len(response.stats)))
Example #34
0
def verify_flowstats(self,match,byte_count=None,packet_count=None):
    # Verify flow counters : byte_count and packet_count

    stat_req = message.flow_stats_request()
    stat_req.match = match
    stat_req.table_id = 0xff
    stat_req.out_port = ofp.OFPP_NONE
    
    for i in range(0,60):
        logging.info("Sending stats request")
        # TODO: move REPLY_MORE handling to controller.transact?
        response, pkt = self.controller.transact(stat_req,
                                                     timeout=5)
        self.assertTrue(response is not None,"No response to stats request")

        packet_counter = 0
        byte_counter = 0 

        sleep(1)

        for item in response.stats:
            packet_counter += item.packet_count
            byte_counter += item.byte_count

            logging.info("Recieved" + str(item.packet_count) + " packets")
           
            logging.info("Received " + str(item.byte_count) + "bytes")
           
        if packet_count != None  and  packet_count != packet_counter: continue
        if byte_count != None  and  byte_count != byte_counter: continue
        break

        
    
    if packet_count != None :
        self.assertEqual(packet_count,item.packet_count,"packet_count counter is not incremented correctly")

    if byte_count != None :   
        self.assertEqual(byte_count,item.byte_count,"byte_count counter is not incremented correctly")
Example #35
0
 def runTest(self):
     basic_logger.info("Running StatsGet")
     basic_logger.info("Inserting trial flow")
     request = message.flow_mod()
     request.buffer_id = 0xffffffff
     for i in range(1,5):
         request.priority = i*1000
         basic_logger.debug("Adding flow %d" % i)
         rv = self.controller.message_send(request)
         self.assertTrue(rv != -1, "Failed to insert test flow %d" % i)
     basic_logger.info("Removing all flows")
     testutils.delete_all_flows(self.controller, basic_logger)
     basic_logger.info("Sending flow request")
     request = message.flow_stats_request()
     request.out_port = ofp.OFPP_ANY
     request.out_group = ofp.OFPG_ANY
     request.table_id = 0xff
     response, _ = self.controller.transact(request, timeout=2)
     self.assertTrue(response is not None, "Did not get response")
     self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
     self.assertEqual(len(response.stats),0)
     basic_logger.debug(response.show())
Example #36
0
def verify_flowstats(self,match,byte_count=None,packet_count=None):
    '''
    Ensures that packet_count packets and byte_count bytes have
    been recorded and are advertised by dut.
    '''
    stat_req = message.flow_stats_request()
    stat_req.match = match
    stat_req.table_id = 0xff
    stat_req.out_port = ofp.OFPP_NONE
    
    for i in range(0,60):
        logging.info("Sending stats request")
        # TODO: move REPLY_MORE handling to controller.transact?
        response, pkt = self.controller.transact(stat_req,
                                                     timeout=5)
        self.assertTrue(response is not None,"No response to stats request")

        packet_counter = 0
        byte_counter = 0 

        sleep(1)

        for item in response.stats:
            packet_counter += item.packet_count
            byte_counter += item.byte_count

            logging.info("packet_counter " + str(item.packet_count) + " packets")
            logging.info("byte_counter " + str(item.byte_count) + " bytes")
           
        if packet_count != None  and  packet_count != packet_counter: continue
        if byte_count != None  and  byte_count != byte_counter: continue
        break

    if packet_count != None :
        self.assertEqual(packet_count, packet_counter, "Expected packet count of {0} recived {1} instead.".format(packet_count, packet_counter))

    if byte_count != None :   
        self.assertEqual(byte_count, byte_counter, "Expected byte count of {0} received {1} instead.".format(byte_count, byte_counter))
Example #37
0
    def runTest(self):
        table_id = testutils.EX_L2_TABLE
        of_ports = exact_port_map.keys()
        egr_port = of_ports[len(of_ports)-1]

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

        testutils.flow_msg_install(self, request)
        #"get flow stats"
        stat_req = message.flow_stats_request()
        stat_req.buffer_id = 0xffffffff
        stat_req.table_id = table_id
        stat_req.out_port = ofp.OFPP_ANY
        stat_req.out_group = ofp.OFPG_ANY
        stat_req.match_fields = request.match_fields
        response, _ = self.controller.transact(stat_req, timeout=2)
        self.assertTrue(isinstance(response,message.flow_stats_reply),"Not a flow_stats_reply")
        self.assertEqual(len(response.stats),1, "len of stats is:"+str(len(response.stats)))
Example #38
0
def Verify_FlowStats(self, match, byte_count=0, packet_count=0):
    # Verify flow counters : byte_count and packet_count

    stat_req = message.flow_stats_request()
    stat_req.match = match
    stat_req.table_id = 0xff
    stat_req.out_port = ofp.OFPP_NONE
    test_timeout = 10
    all_packets_received = 0
    for i in range(0, test_timeout):

        response, pkt = self.controller.transact(stat_req,
                                                 timeout=test_timeout)
        self.assertTrue(response is not None, "No response to stats request")
        for obj in response.stats:
            if (obj.packet_count == packet_count
                    and obj.byte_count == byte_count):
                all_packets_received = 1

        if all_packets_received:
            break
        sleep(1)

    self.assertTrue(all_packets_received, "Flow counters are incorrect")
Example #39
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 #40
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 #41
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp40No30 Identical_Flows test ")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        #Clear switch state
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        logging.info("Installing an all wildcarded flow")

        # Create and add flow-1, check on dataplane it is active.
        (pkt, match) = wildcard_all(self, of_ports)

        # Verify active_entries in table_stats_request =1
        #verify_tablestats(self,expect_active=1)

        # Send Packet (to increment counters like byte_count and packet_count)
        logging.info("Sending a matching packet to increase the counters")
        send_packet(self, pkt, of_ports[0], of_ports[1])

        # Verify Flow counters have incremented
        logging.info("Verifying whether the flow counters have increased")
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE

        for i in range(0, 60):
            logging.info("Sending stats request")
            response, pkt = self.controller.transact(stat_req, timeout=5)
            self.assertTrue(response is not None,
                            "No response to stats request")
            packet_counter = 0
            byte_counter = 0
            sleep(1)

            for item in response.stats:
                packet_counter += item.packet_count
                byte_counter += item.byte_count
                logging.info("Recieved" + str(item.packet_count) + " packets")
                logging.info("Received " + str(item.byte_count) + "bytes")

            if packet_counter == None: continue
            if byte_counter == None: continue
            break

        if packet_counter == None:
            self.assertEqual(packet_count, item.packet_count,
                             "packet_count counter did not increment")
        if byte_counter == None:
            self.assertEqual(byte_count, item.byte_count,
                             "byte_count counter did not increment")

        #Send Identical flow
        logging.info("Installing an identical flow")
        (pkt1, match1) = wildcard_all(self, of_ports)

        # Verify active_entries in table_stats_request =1
        #verify_tablestats(self,expect_active=1)

        # Verify Flow counters reset
        logging.info("Verifying whether the flow counter have reset")
        verify_flowstats(self, match, byte_count=0, packet_count=0)
Example #42
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp40No30 Identical_Flows test ")

        of_ports = config["port_map"].keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 1, "Not enough ports for test")

        #Clear switch state
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        logging.info("Installing an all wildcarded flow")
        
        
        # Create and add flow-1, check on dataplane it is active.
        (pkt,match) = wildcard_all(self,of_ports)

        # Verify active_entries in table_stats_request =1 
        #verify_tablestats(self,expect_active=1)
        
        # Send Packet (to increment counters like byte_count and packet_count)
        logging.info("Sending a matching packet to increase the counters")
        send_packet(self,pkt,of_ports[0],of_ports[1])

        # Verify Flow counters have incremented 
        logging.info("Verifying whether the flow counters have increased")
        stat_req = message.flow_stats_request()
        stat_req.match = match
        stat_req.table_id = 0xff
        stat_req.out_port = ofp.OFPP_NONE
    
        for i in range(0,60):
            logging.info("Sending stats request")
            response, pkt = self.controller.transact(stat_req,
                                                     timeout=5)
            self.assertTrue(response is not None,"No response to stats request")
            packet_counter = 0
            byte_counter = 0 
            sleep(1)
            
            for item in response.stats:
                packet_counter += item.packet_count
                byte_counter += item.byte_count
                logging.info("Recieved" + str(item.packet_count) + " packets")
                logging.info("Received " + str(item.byte_count) + "bytes")
            
            if packet_counter == None : continue
            if byte_counter == None : continue
            break

        if packet_counter == None :
            self.assertEqual(packet_count,item.packet_count,"packet_count counter did not increment")
        if byte_counter == None :   
            self.assertEqual(byte_count,item.byte_count,"byte_count counter did not increment")
        
        #Send Identical flow 
        logging.info("Installing an identical flow")
        (pkt1,match1) = wildcard_all(self,of_ports)

        # Verify active_entries in table_stats_request =1 
        #verify_tablestats(self,expect_active=1)

        # Verify Flow counters reset
        logging.info("Verifying whether the flow counter have reset")
        verify_flowstats(self,match,byte_count=0,packet_count=0)
Example #43
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp60No40 Duration (nsecs).")
        dataplane_ports = config["port_map"].keys()
        dataplane_ports.sort()
        self.assertTrue(len(dataplane_ports) > 1, "Not enough ports for test.")

        logging.info("Clearing switch state...")
        rc = delete_all_flows(self.controller)
        self.assertEqual(rc, 0, "Failed to delete all flows.")

        logging.info("Installing flow entry that matches on in_port.")
        (pkt, match) = wildcard_all_except_ingress(self, dataplane_ports)

        req = message.flow_stats_request()
        req.match = match
        req.table_id = 0xff
        req.out_port = ofp.OFPP_NONE

        duration_verifications = 5
        previous_duration = (-1, -1)
        for v in range(0, duration_verifications):
            logging.info("Sending ofp_stats_request of type ofp.OFPST_FLOW")
            res, pkt = self.controller.transact(req)
            self.assertTrue(
                res is not None,
                "No ofp_stats_reply message received in response to ofp_stats_request."
            )
            self.assertTrue(
                res.type == ofp.OFPST_FLOW,
                "Expected ofp_stats_reply of type ofp.OFPST_FLOW, got {0}".
                format(res.type))
            self.assertTrue(
                len(res.stats) == 1,
                "Received {0} ofp_flow_stats in the ofp_stats_reply message, but expected exactly 1"
                .format(len(res.stats)))

            logging.info(
                "Comparing duration in nsecs from ofp_flow_stats to previous duration in nsecs."
            )
            duration = (res.stats[0].duration_sec, res.stats[0].duration_nsec)
            if duration[1] < previous_duration[1]:
                self.assertGreater(
                    duration[0], previous_duration[0],
                    "Duration in nsecs was less than previous duration in nsecs, but the duration in secs was not greater than the previous duration in secs."
                )
            else:
                # In the case that a switch can't report in
                # millisecond granularity, we expect
                # duration_nsec to be reported as 0xffffffff.
                if duration[1] == previous_duration[1] and duration[
                        1] == 4294967295:
                    logging.info(
                        "Duration in nsec is not supported. Reported as -1 or 0xffffffff"
                    )
                    return
                self.assertNotEqual(
                    duration[1], previous_duration[1],
                    "ofp_flow_stats.duration_nsec {0} was the same as the previous duration_nsec {1}."
                    .format(duration, previous_duration))
            previous_duration = duration
            time.sleep(1.5)
Example #44
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 = delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rc, 0, "Failed to delete all flows")

        pkt = 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.cookie = random.randint(0, 9007199254740992)
        flow_mod_msg.buffer_id = 0xFFFFFFFF
        flow_mod_msg.idle_timeout = 1
        act.port = egress_port
        self.assertTrue(flow_mod_msg.actions.add(act), "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_NONE

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

        (response, raw) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)

        pa_logger.info("Inserting flow")
        rv = self.controller.message_send(flow_mod_msg)
        self.assertTrue(rv != -1, "Error installing flow mod")
        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, pkt_time) = 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")
        do_barrier(self.controller)

        (response, raw) = self.controller.poll(ofp.OFPT_STATS_REPLY, 2)
        # print "YYY: Stats reply is \n%s" % (response.show())
        self.assertTrue(len(response.stats) == 1, "Did not receive flow stats reply")