Ejemplo n.º 1
0
    def runTest(self):
        testutils.clear_switch(self,config["port_map"],logging)
#        self.clear_switch()

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

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out)
Ejemplo n.º 2
0
    def runTest(self):
        testutils.clear_switch(self,config["port_map"],logging)
#        self.clear_switch()

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

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

        self.send_data(packet_in, 1)
        
        self.recv_data(2, packet_out)
Ejemplo n.º 3
0
    def runTest(self):
        testutils.clear_switch(self,config["port_map"],logging)
#        self.clear_switch()

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

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

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

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

        self.assertTrue(((recv1 is not None) and testutils.pkt_verify(self, recv1, packet_out1)) or \
                        ((recv2 is not None) and testutils.pkt_verify(self, recv2, packet_out2)) or \
                        ((recv3 is not None) and testutils.pkt_verify(self, recv3, packet_out3)),
                        "Received unexpected packet")
Ejemplo n.º 4
0
    def runTest(self):
        testutils.clear_switch(self,config["port_map"],logging)
#        self.clear_switch()

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

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

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

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

        self.assertTrue(((recv1 is not None) and testutils.pkt_verify(self, recv1, packet_out1)) or \
                        ((recv2 is not None) and testutils.pkt_verify(self, recv2, packet_out2)) or \
                        ((recv3 is not None) and testutils.pkt_verify(self, recv3, packet_out3)),
                        "Received unexpected packet")
Ejemplo n.º 5
0
    def runTest(self):
#        self.clear_switch()
        testutils.clear_switch(self,config["port_map"],logging)
        
        group_add_msg = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ]),
            create_bucket(0, 0, 0, [
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

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

        group_stats_req = \
        create_group_stats_req(10)

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

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

        self.assertEqual(len(response), exp_len,
                         'Received packet length does not equal expected length')
Ejemplo n.º 6
0
    def runTest(self):
#        self.clear_switch()
        testutils.clear_switch(self,config["port_map"],logging)
        
        group_add_msg = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
            create_bucket([
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ]),
            create_bucket([
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ])
        ])

        self.send_ctrl_exp_noerror(group_add_msg, 'group add')

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

        self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')

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

        group_stats_req = \
        create_group_stats_req(10)

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

        self.assertEqual(len(response.entries), 1, 'Incorrect number of groups')
        self.assertEqual(len(response.entries[0].bucket_stats), 2, 'Incorrect number of groups')
        self.assertEqual(response.entries[0].packet_count, 3, 'Incorrect group packet count')
        self.assertEqual(response.entries[0].byte_count, 300, 'Incorrect group byte count')
        for bucket_stat in response.entries[0].bucket_stats:
            self.assertEqual(bucket_stat.packet_count, 3, 'Incorrect bucket packet count')
            self.assertEqual(bucket_stat.byte_count, 300, 'Incorrect bucket byte count')
Ejemplo n.º 7
0
    def runTest(self):
#        self.clear_switch()
        testutils.clear_switch(self,config["port_map"],logging)

        group_add_msg1 = \
        create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
            create_bucket([
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 2)
            ]),
            create_bucket([
                create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
                create_action(action = ofp.OFPAT_OUTPUT, port = 3)
            ])
        ])

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

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

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

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

        self.send_ctrl_exp_noerror(flow_add_msg1, 'flow add 1')

        flow_add_msg2 = \
        testutils.flow_msg_create(self,packet_in,ing_port = 2,action_list = [
            create_action(action = ofp.OFPAT_GROUP, group_id = 20)
        ])

        self.send_ctrl_exp_noerror(flow_add_msg2, 'flow add 2')

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

        group_stats_req = \
        create_group_stats_req(ofp.OFPG_ALL)

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

        self.assertEqual(len(response.entries), 2)
        group10, group20 = sorted(response.entries, key=lambda x: x.group_id)

        # Check stats for group 10
        self.assertEqual(group10.group_id, 10)
        self.assertEqual(group10.ref_count, 1)
        self.assertEqual(group10.packet_count, 2)
        self.assertEqual(group10.byte_count, 200)
        self.assertEqual(len(group10.bucket_stats), 2)
        for bucket_stat in group10.bucket_stats:
            self.assertEqual(bucket_stat.packet_count, 2)
            self.assertEqual(bucket_stat.byte_count, 200)

        # Check stats for group 20
        self.assertEqual(group20.group_id, 20)
        self.assertEqual(group20.ref_count, 1)
        self.assertEqual(group20.packet_count, 3)
        self.assertEqual(group20.byte_count, 300)
        self.assertEqual(len(group20.bucket_stats), 2)
        for bucket_stat in group20.bucket_stats:
            self.assertEqual(bucket_stat.packet_count, 3)
            self.assertEqual(bucket_stat.byte_count, 300)