Beispiel #1
0
    def test_flow_stats(self):
        """Check the update method of the GaugeFlowTableInfluxDBLogger class"""

        conf = self.create_config_obj(create_mock_datapath(0))
        db_logger = gauge_influx.GaugeFlowTableInfluxDBLogger(
            conf, '__name__', mock.Mock())
        db_logger._running = True

        rcv_time = int(time.time())
        instructions = [parser.OFPInstructionGotoTable(1)]
        msg = flow_stats_msg(conf.dp, instructions)
        db_logger.update(rcv_time, msg)

        other_fields = {
            'dp_name': conf.dp.name,
            'dp_id': hex(conf.dp.dp_id),
            'timestamp': rcv_time,
            'priority': msg.body[0].priority,
            'table_id': msg.body[0].table_id,
            'inst_count': len(msg.body[0].instructions),
            'vlan': msg.body[0].match.get('vlan_vid') ^ ofproto.OFPVID_PRESENT,
            'cookie': msg.body[0].cookie,
        }

        with open(self.server.output_file, 'r', encoding='utf-8') as log:
            output = log.readlines()

        for line in output:
            measurement, influx_data = self.parse_influx_output(line)

            for stat_name, stat_val in influx_data.items():
                if stat_name == 'value':
                    if measurement == 'flow_packet_count':
                        self.assertEqual(msg.body[0].packet_count, stat_val)
                    elif measurement == 'flow_byte_count':
                        self.assertEqual(msg.body[0].byte_count, stat_val)
                    else:
                        self.fail("Unknown measurement")

                elif stat_name in other_fields:
                    self.assertEqual(other_fields[stat_name], stat_val)

                elif stat_name in msg.body[0].match:
                    self.assertEqual(msg.body[0].match.get(stat_name),
                                     stat_val)

                else:
                    self.fail("Unknown key: {} and value: {}".format(
                        stat_name, stat_val))
Beispiel #2
0
    def test_flow_stats(self):
        """Check the update method of the GaugeFlowTableInfluxDBLogger class"""

        conf = self.create_config_obj(create_mock_datapath(0))
        db_logger = gauge_influx.GaugeFlowTableInfluxDBLogger(
            conf, '__name__', mock.Mock())

        rcv_time = int(time.time())
        matches = self.generate_all_matches()
        instructions = [parser.OFPInstructionGotoTable(1)]
        flow_stats = [
            parser.OFPFlowStats(0, 0, 0, 1, 0, 0, 0, 0, 1, 1, matches,
                                instructions)
        ]
        message = parser.OFPFlowStatsReply(conf.dp, body=flow_stats)
        db_logger.update(rcv_time, conf.dp.id, message)

        other_fields = {
            'dp_name': conf.dp.name,
            'timestamp': rcv_time,
            'priority': flow_stats[0].priority,
            'table_id': flow_stats[0].table_id,
            'inst_count': len(flow_stats[0].instructions),
            'vlan': matches.get('vlan_vid') ^ ofproto.OFPVID_PRESENT
        }

        self.server.output_file.seek(0)
        for line in self.server.output_file.readlines():
            measurement, influx_data = self.parse_influx_output(line)

            for stat_name, stat_val in influx_data.items():
                if stat_name == 'value':
                    if measurement == 'flow_packet_count':
                        self.assertEqual(flow_stats[0].packet_count, stat_val)
                    elif measurement == 'flow_byte_count':
                        self.assertEqual(flow_stats[0].byte_count, stat_val)
                    else:
                        self.fail("Unknown measurement")

                elif stat_name in other_fields:
                    self.assertEqual(other_fields[stat_name], stat_val)

                elif stat_name in matches:
                    self.assertEqual(matches.get(stat_name), stat_val)

                else:
                    self.fail("Unknown key: {} and value: {}".format(
                        stat_name, stat_val))