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])
import pickle """ Make rules that form a diamond of dependencies """ flows = [ # Table 0 parser.OFPFlowStats( table_id=0, priority=10, match=parser.OFPMatch(vlan_vid=(0x1000, 0x1FFE)), instructions=[ parser.OFPInstructionGotoTable(1) ] ), parser.OFPFlowStats( table_id=0, priority=10, match=parser.OFPMatch(vlan_vid=(0x1002, 0x1FFE)), instructions=[ parser.OFPInstructionGotoTable(1) ] ), parser.OFPFlowStats( table_id=0, priority=0, match=parser.OFPMatch(),
| | 3 L2 FWD | | | | +--^+ ETH_DST -> | | OUTPUT | | | | | | | | | +---------------+ """ flows = [ # Table 0 parser.OFPFlowStats(table_id=0, priority=1000, match=parser.OFPMatch(tcp_dst=80), instructions=[]), parser.OFPFlowStats(table_id=0, priority=1000, match=parser.OFPMatch(tcp_dst=443), instructions=[]), parser.OFPFlowStats(table_id=0, priority=0, match=parser.OFPMatch(), instructions=[parser.OFPInstructionGotoTable(1)]), # Table 1 parser.OFPFlowStats(table_id=1, priority=1000, match=parser.OFPMatch(eth_dst=1), instructions=[parser.OFPInstructionGotoTable(2)]),
+------------------+ +--------------------+ | | | | | 10 + TCP:10 | | 10 + IP:1 | | drop/empty | | Ouput:1 | | | | | | 0 + * | | 0 + * | | Goto:1 | | drop/empty | | | | | +------------------+ +--------------------+ """ flows = [ # Table 0, drop all traffic parser.OFPFlowStats(table_id=0, priority=10, match=parser.OFPMatch(tcp_dst=10), instructions=[]), parser.OFPFlowStats(table_id=0, priority=0, match=parser.OFPMatch(), instructions=[parser.OFPInstructionGotoTable(1)]), # Table 1, forward parser.OFPFlowStats(table_id=1, priority=10, match=parser.OFPMatch(ipv4_dst=1), instructions=[ parser.OFPInstructionActions( ofproto_v1_3.OFPIT_APPLY_ACTIONS, [parser.OFPActionOutput(1)]) ]), parser.OFPFlowStats(table_id=1,
| | | 0 - * | | 0 - * | | | | GOTO:2 | | OUTPUT:2 | +----------------+ +-------------------+ +-----------------+ When targeting a single table: A partial merge of ETH_DST:2 and table 3, only merging with (*) OUTPUT:2 will result in ETH_DST:2,IPV4_DST:1 traffic incorrectly output out 2. The correction to this is also merge with (IPV4_DST:1). """ flows = [ # Table 0 parser.OFPFlowStats(table_id=0, priority=0, match=parser.OFPMatch(), instructions=[parser.OFPInstructionGotoTable(1)]), parser.OFPFlowStats(table_id=1, priority=10, match=parser.OFPMatch(eth_dst=2), instructions=[parser.OFPInstructionGotoTable(2)]), parser.OFPFlowStats(table_id=1, priority=0, match=parser.OFPMatch(), instructions=[parser.OFPInstructionGotoTable(2)]), parser.OFPFlowStats(table_id=2, priority=10, match=parser.OFPMatch(ipv4_dst=1), instructions=[ parser.OFPInstructionActions( ofproto_v1_3.OFPIT_WRITE_ACTIONS,