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))
def flow_stats_msg(datapath, instructions): """ Create an OFPFlowStatsReply with random values. """ matches = generate_all_matches() flow_stats = parser.OFPFlowStats(random.randint(0, 9), random.randint(1, 10000), random.randint(0, 10000), random.randint(1, 10000), random.randint(1, 10000), random.randint(1, 10000), 0, random.randint(1, 10000), random.randint(1, 10000), random.randint(1, 10000), matches, instructions) return parser.OFPFlowStatsReply(datapath, body=[flow_stats])