Add port_stats.MultiFlowStats
diff --git a/tests/port_stats.py b/tests/port_stats.py
index a22c267..facef3e 100644
--- a/tests/port_stats.py
+++ b/tests/port_stats.py
@@ -91,9 +91,9 @@
Verify flow stats are properly retrieved.
Generate a packet
- Generate and install a matching flow
+ Generate and install a flow from port 1 to 2
Send the packet
- Send a flow stats request to match the flow and retrieve stats
+ Send port stats request to port 1 & 2
Verify that the packet counter has incremented
"""
@@ -183,3 +183,110 @@
self.verifyStats(ingress_port, test_timeout, 0, num_sends)
self.verifyStats(egress_port, test_timeout, num_sends, 0)
+
+
+class MultiFlowStats(basic.SimpleDataPlane):
+ """
+ Verify flow stats are properly retrieved.
+
+ Generate two packets and install two matching flows
+ Send some number of packets
+ Send a port stats request to get packet count
+ Verify that the packet counter has incremented
+ """
+
+ def buildFlowModMsg(self, pkt, ingress_port, egress_port):
+ 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")
+ 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 = 0
+ flow_mod_msg.hard_timeout = 0
+ act = action.action_output()
+ act.port = egress_port
+ self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
+
+ fs_logger.info("Ingress " + str(ingress_port) +
+ " to egress " + str(egress_port))
+
+ return flow_mod_msg
+
+ def verifyStats(self, port, test_timeout, packet_sent, packet_recv):
+ stat_req = message.port_stats_request()
+ stat_req.port_no = port
+
+ all_packets_received = 0
+ all_packets_sent = 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 port stats reply")
+ for obj in response.stats:
+ fs_logger.info("Sent " + str(obj.tx_packets) + " packets")
+ if obj.tx_packets == packet_sent:
+ all_packets_sent = 1
+ fs_logger.info("Received " + str(obj.rx_packets) + " packets")
+ if obj.rx_packets == packet_recv:
+ all_packets_received = 1
+
+ if all_packets_received and all_packets_sent:
+ break
+ sleep(1)
+
+ self.assertTrue(all_packets_sent,
+ "Packet sent does not match number sent")
+ self.assertTrue(all_packets_received,
+ "Packet received does not match number sent")
+
+ def runTest(self):
+ global fs_port_map
+
+ # TODO: set from command-line parameter
+ test_timeout = 60
+
+ of_ports = fs_port_map.keys()
+ of_ports.sort()
+ self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
+ ingress_port = of_ports[0];
+ egress_port1 = of_ports[1];
+ egress_port2 = of_ports[2];
+
+ rc = delete_all_flows(self.controller, fs_logger)
+ self.assertEqual(rc, 0, "Failed to delete all flows")
+
+ pkt1 = simple_tcp_packet()
+ flow_mod_msg1 = self.buildFlowModMsg(pkt1, ingress_port, egress_port1)
+
+ pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
+ flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
+
+ fs_logger.info("Inserting flow1")
+ rv = self.controller.message_send(flow_mod_msg1)
+ self.assertTrue(rv != -1, "Error installing flow mod")
+ fs_logger.info("Inserting flow2")
+ rv = self.controller.message_send(flow_mod_msg2)
+ self.assertTrue(rv != -1, "Error installing flow mod")
+ self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
+
+ num_pkt1s = random.randint(10,30)
+ fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
+ num_pkt2s = random.randint(10,30)
+ fs_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
+ for i in range(0,num_pkt1s):
+ sendPacket(self, pkt1, ingress_port, egress_port1, test_timeout)
+ for i in range(0,num_pkt2s):
+ sendPacket(self, pkt2, ingress_port, egress_port2, test_timeout)
+
+ self.verifyStats(ingress_port, test_timeout, 0, num_pkt1s + num_pkt2s)
+ self.verifyStats(egress_port1, test_timeout, num_pkt1s, 0)
+ self.verifyStats(egress_port2, test_timeout, num_pkt2s, 0)