blob: 9c7170e638ea431af02d70cf14899e53698d578a [file] [log] [blame]
Dan Talayco89d57342010-06-07 16:24:59 -07001"""
2Flow stats test case.
3Similar to Flow stats test case in the perl test harness.
4
5"""
6
7import logging
8
9import unittest
10import random
11
12import oftest.controller as controller
13import oftest.cstruct as ofp
14import oftest.message as message
15import oftest.dataplane as dataplane
16import oftest.action as action
17import oftest.parse as parse
18import basic
19
20from testutils import *
21from time import sleep
22
Ken Chiangfb593e72012-03-28 17:19:13 -070023#@var fs_port_map Local copy of the configuration map from OF port
Dan Talayco89d57342010-06-07 16:24:59 -070024# numbers to OS interfaces
Ken Chiangfb593e72012-03-28 17:19:13 -070025fs_port_map = None
26#@var fs_logger Local logger object
27fs_logger = None
28#@var fs_config Local copy of global configuration data
29fs_config = None
Dan Talayco89d57342010-06-07 16:24:59 -070030
Ken Chiang620bdcc2012-03-23 12:52:07 -070031# TODO: ovs has problems with VLAN id?
32WILDCARD_VALUES = [ofp.OFPFW_IN_PORT,
Dan Talayco488fbc52012-04-09 16:30:41 -070033 # (ofp.OFPFW_DL_VLAN | ofp.OFPFW_DL_VLAN_PCP),
Ken Chiang620bdcc2012-03-23 12:52:07 -070034 ofp.OFPFW_DL_SRC,
35 ofp.OFPFW_DL_DST,
Dan Talayco488fbc52012-04-09 16:30:41 -070036 (ofp.OFPFW_DL_TYPE | ofp.OFPFW_NW_SRC_ALL |
37 ofp.OFPFW_NW_DST_ALL | ofp.OFPFW_NW_TOS | ofp.OFPFW_NW_PROTO |
38 ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST),
39 (ofp.OFPFW_NW_PROTO | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST),
Ken Chiang620bdcc2012-03-23 12:52:07 -070040 ofp.OFPFW_TP_SRC,
41 ofp.OFPFW_TP_DST,
Dan Talayco488fbc52012-04-09 16:30:41 -070042 ofp.OFPFW_NW_SRC_MASK,
43 ofp.OFPFW_NW_DST_MASK,
Ken Chiang620bdcc2012-03-23 12:52:07 -070044 ofp.OFPFW_DL_VLAN_PCP,
45 ofp.OFPFW_NW_TOS]
46
Dan Talayco89d57342010-06-07 16:24:59 -070047def test_set_init(config):
48 """
49 Set up function for packet action test classes
50
51 @param config The configuration dictionary; see oft
52 """
53
Ed Swierk89f78352012-03-29 12:32:32 -070054 basic.test_set_init(config)
55
Ken Chiangfb593e72012-03-28 17:19:13 -070056 global fs_port_map
57 global fs_logger
58 global fs_config
Dan Talayco89d57342010-06-07 16:24:59 -070059
Ken Chiangfb593e72012-03-28 17:19:13 -070060 fs_logger = logging.getLogger("flow_stats")
61 fs_logger.info("Initializing test set")
62 fs_port_map = config["port_map"]
63 fs_config = config
Dan Talayco89d57342010-06-07 16:24:59 -070064
Ken Chiangaa5bc062012-03-31 14:03:28 -070065def sendPacket(obj, pkt, ingress_port, egress_port, test_timeout):
66
67 fs_logger.info("Sending packet to dp port " + str(ingress_port) +
68 ", expecting output on " + str(egress_port))
69 obj.dataplane.send(ingress_port, str(pkt))
70
71 exp_pkt_arg = None
72 exp_port = None
73 if fs_config["relax"]:
74 exp_pkt_arg = pkt
75 exp_port = egress_port
76
Rich Lanec8aaa3e2012-07-26 19:28:02 -070077 (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(port_number=exp_port,
Ken Chiangaa5bc062012-03-31 14:03:28 -070078 exp_pkt=exp_pkt_arg)
79 obj.assertTrue(rcv_pkt is not None,
80 "Packet not received on port " + str(egress_port))
81 fs_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
82 str(rcv_port))
83 obj.assertEqual(rcv_port, egress_port,
84 "Packet received on port " + str(rcv_port) +
85 ", expected port " + str(egress_port))
86 obj.assertEqual(str(pkt), str(rcv_pkt),
87 'Response packet does not match send packet')
88
Ken Chiang620bdcc2012-03-23 12:52:07 -070089class SingleFlowStats(basic.SimpleDataPlane):
Dan Talayco89d57342010-06-07 16:24:59 -070090 """
91 Verify flow stats are properly retrieved.
92
93 Generate a packet
Ken Chiang620bdcc2012-03-23 12:52:07 -070094 Generate and install a matching flow
95 Send the packet
96 Send a flow stats request to match the flow and retrieve stats
97 Verify that the packet counter has incremented
Dan Talayco89d57342010-06-07 16:24:59 -070098 """
Ken Chiang620bdcc2012-03-23 12:52:07 -070099
100 def verifyStats(self, match, out_port, test_timeout, packet_count):
101 stat_req = message.flow_stats_request()
102 stat_req.match = match
103 stat_req.table_id = 0xff
104 stat_req.out_port = out_port
105
106 all_packets_received = 0
107 for i in range(0,test_timeout):
Ken Chiangfb593e72012-03-28 17:19:13 -0700108 fs_logger.info("Sending stats request")
109 response, pkt = self.controller.transact(stat_req,
110 timeout=test_timeout)
111 self.assertTrue(response is not None,
112 "No response to stats request")
113 self.assertTrue(len(response.stats) == 1,
114 "Did not receive flow stats reply")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700115 for obj in response.stats:
116 # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
117 # for now, just clear them so the assert is simpler
118 #obj.match.pad1 = 0
119 #obj.match.pad2 = [0, 0]
120 #self.assertEqual(match, obj.match,
121 # "Matches do not match")
Ken Chiangfb593e72012-03-28 17:19:13 -0700122 fs_logger.info("Received " + str(obj.packet_count) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700123 if obj.packet_count == packet_count:
124 all_packets_received = 1
125
126 if all_packets_received:
127 break
128 sleep(1)
129
130 self.assertTrue(all_packets_received,
131 "Packet count does not match number sent")
132
Dan Talayco89d57342010-06-07 16:24:59 -0700133 def runTest(self):
Ken Chiangfb593e72012-03-28 17:19:13 -0700134 global fs_port_map
Dan Talayco89d57342010-06-07 16:24:59 -0700135
Ken Chiang620bdcc2012-03-23 12:52:07 -0700136 # TODO: set from command-line parameter
137 test_timeout = 60
138
Ken Chiangfb593e72012-03-28 17:19:13 -0700139 of_ports = fs_port_map.keys()
Dan Talayco89d57342010-06-07 16:24:59 -0700140 of_ports.sort()
141 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
142
Ken Chiangfb593e72012-03-28 17:19:13 -0700143 rc = delete_all_flows(self.controller, fs_logger)
Dan Talayco89d57342010-06-07 16:24:59 -0700144 self.assertEqual(rc, 0, "Failed to delete all flows")
145
Ken Chiang620bdcc2012-03-23 12:52:07 -0700146 # build packet
Dan Talayco89d57342010-06-07 16:24:59 -0700147 pkt = simple_tcp_packet()
Ed Swierk99a74de2012-08-22 06:40:54 -0700148 match = packet_to_flow_match(self, pkt)
Dan Talayco89d57342010-06-07 16:24:59 -0700149 match.wildcards &= ~ofp.OFPFW_IN_PORT
150 self.assertTrue(match is not None,
151 "Could not generate flow match from pkt")
152 act = action.action_output()
153
Ken Chiang620bdcc2012-03-23 12:52:07 -0700154 # build flow
Dan Talayco39bf6912010-07-08 14:17:52 -0700155 ingress_port = of_ports[0];
156 egress_port = of_ports[1];
Ken Chiangfb593e72012-03-28 17:19:13 -0700157 fs_logger.info("Ingress " + str(ingress_port) +
Dan Talayco89d57342010-06-07 16:24:59 -0700158 " to egress " + str(egress_port))
Ken Chiang620bdcc2012-03-23 12:52:07 -0700159 match.in_port = ingress_port
160 flow_mod_msg = message.flow_mod()
161 flow_mod_msg.match = match
162 flow_mod_msg.cookie = random.randint(0,9007199254740992)
163 flow_mod_msg.buffer_id = 0xffffffff
164 flow_mod_msg.idle_timeout = 0
165 flow_mod_msg.hard_timeout = 0
166 act.port = egress_port
167 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
168
169 # send flow
Ken Chiangfb593e72012-03-28 17:19:13 -0700170 fs_logger.info("Inserting flow")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700171 rv = self.controller.message_send(flow_mod_msg)
172 self.assertTrue(rv != -1, "Error installing flow mod")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700173 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700174
175 # no packets sent, so zero packet count
176 self.verifyStats(match, ofp.OFPP_NONE, test_timeout, 0)
177
178 # send packet N times
179 num_sends = random.randint(10,20)
Ken Chiangfb593e72012-03-28 17:19:13 -0700180 fs_logger.info("Sending " + str(num_sends) + " test packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700181 for i in range(0,num_sends):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700182 sendPacket(self, pkt, ingress_port, egress_port,
183 test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700184
185 self.verifyStats(match, ofp.OFPP_NONE, test_timeout, num_sends)
186 self.verifyStats(match, egress_port, test_timeout, num_sends)
187 for wc in WILDCARD_VALUES:
Ed Swierk99a74de2012-08-22 06:40:54 -0700188 match.wildcards = required_wildcards(self) | wc
Ken Chiang620bdcc2012-03-23 12:52:07 -0700189 self.verifyStats(match, egress_port, test_timeout, num_sends)
190
191
192class TwoFlowStats(basic.SimpleDataPlane):
193 """
194 Verify flow stats are properly retrieved.
195
196 Generate two packets and install two matching flows
197 Send some number of packets
198 Send a flow stats request to match the flows and retrieve stats
199 Verify that the packet counter has incremented
200
201 TODO: add a third flow, and then configure the match to exclude
202 that flow?
203 """
204
205 def buildFlowModMsg(self, pkt, ingress_port, egress_port):
Ed Swierk99a74de2012-08-22 06:40:54 -0700206 match = packet_to_flow_match(self, pkt)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700207 match.wildcards &= ~ofp.OFPFW_IN_PORT
208 self.assertTrue(match is not None,
209 "Could not generate flow match from pkt")
Dan Talayco89d57342010-06-07 16:24:59 -0700210 match.in_port = ingress_port
211
212 flow_mod_msg = message.flow_mod()
213 flow_mod_msg.match = match
214 flow_mod_msg.cookie = random.randint(0,9007199254740992)
215 flow_mod_msg.buffer_id = 0xffffffff
Ken Chiang620bdcc2012-03-23 12:52:07 -0700216 flow_mod_msg.idle_timeout = 0
217 flow_mod_msg.hard_timeout = 0
218 act = action.action_output()
Dan Talayco89d57342010-06-07 16:24:59 -0700219 act.port = egress_port
220 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
Dan Talayco89d57342010-06-07 16:24:59 -0700221
Ken Chiangfb593e72012-03-28 17:19:13 -0700222 fs_logger.info("Ingress " + str(ingress_port) +
Ken Chiang620bdcc2012-03-23 12:52:07 -0700223 " to egress " + str(egress_port))
Dan Talayco89d57342010-06-07 16:24:59 -0700224
Ken Chiang620bdcc2012-03-23 12:52:07 -0700225 return flow_mod_msg
Dan Talayco89d57342010-06-07 16:24:59 -0700226
Ken Chiangaa5bc062012-03-31 14:03:28 -0700227 def sumStatsReplyCounts(self, response):
228 total_packets = 0
229 for obj in response.stats:
230 # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
231 # for now, just clear them so the assert is simpler
232 #obj.match.pad1 = 0
233 #obj.match.pad2 = [0, 0]
234 #self.assertEqual(match, obj.match,
235 # "Matches do not match")
236 fs_logger.info("Received " + str(obj.packet_count)
237 + " packets")
238 total_packets += obj.packet_count
239 return total_packets
Ken Chiang620bdcc2012-03-23 12:52:07 -0700240
241 def verifyStats(self, match, out_port, test_timeout, packet_count):
242 stat_req = message.flow_stats_request()
243 stat_req.match = match
244 stat_req.table_id = 0xff
245 stat_req.out_port = out_port
246
247 all_packets_received = 0
248 for i in range(0,test_timeout):
Ken Chiangfb593e72012-03-28 17:19:13 -0700249 fs_logger.info("Sending stats request")
Ken Chiangaa5bc062012-03-31 14:03:28 -0700250 # TODO: move REPLY_MORE handling to controller.transact?
Ken Chiangfb593e72012-03-28 17:19:13 -0700251 response, pkt = self.controller.transact(stat_req,
252 timeout=test_timeout)
253 self.assertTrue(response is not None,
254 "No response to stats request")
Ken Chiangaa5bc062012-03-31 14:03:28 -0700255 total_packets = self.sumStatsReplyCounts(response)
256
257 while response.flags == ofp.OFPSF_REPLY_MORE:
258 response, pkt = self.controller.poll(exp_msg=
259 ofp.OFPT_STATS_REPLY,
260 timeout=test_timeout)
261 total_packets += self.sumStatsReplyCounts(response)
262
Ken Chiang620bdcc2012-03-23 12:52:07 -0700263 if total_packets == packet_count:
264 all_packets_received = 1
265 break
266 sleep(1)
267
268 self.assertTrue(all_packets_received,
Ken Chiangaa5bc062012-03-31 14:03:28 -0700269 "Total stats packet count " + str(total_packets) +
270 " does not match number sent " + str(packet_count))
Ken Chiang620bdcc2012-03-23 12:52:07 -0700271
272 def runTest(self):
Ken Chiangfb593e72012-03-28 17:19:13 -0700273 global fs_port_map
Ken Chiang620bdcc2012-03-23 12:52:07 -0700274
275 # TODO: set from command-line parameter
276 test_timeout = 60
277
Ken Chiangfb593e72012-03-28 17:19:13 -0700278 of_ports = fs_port_map.keys()
Ken Chiang620bdcc2012-03-23 12:52:07 -0700279 of_ports.sort()
280 self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
281 ingress_port = of_ports[0];
282 egress_port1 = of_ports[1];
283 egress_port2 = of_ports[2];
284
Ken Chiangfb593e72012-03-28 17:19:13 -0700285 rc = delete_all_flows(self.controller, fs_logger)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700286 self.assertEqual(rc, 0, "Failed to delete all flows")
287
288 pkt1 = simple_tcp_packet()
289 flow_mod_msg1 = self.buildFlowModMsg(pkt1, ingress_port, egress_port1)
290
291 pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
292 flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
293
Ken Chiangfb593e72012-03-28 17:19:13 -0700294 fs_logger.info("Inserting flow1")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700295 rv = self.controller.message_send(flow_mod_msg1)
296 self.assertTrue(rv != -1, "Error installing flow mod")
Ken Chiangfb593e72012-03-28 17:19:13 -0700297 fs_logger.info("Inserting flow2")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700298 rv = self.controller.message_send(flow_mod_msg2)
299 self.assertTrue(rv != -1, "Error installing flow mod")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700300 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Dan Talayco89d57342010-06-07 16:24:59 -0700301
Ken Chiang620bdcc2012-03-23 12:52:07 -0700302 num_pkt1s = random.randint(10,30)
Ken Chiangfb593e72012-03-28 17:19:13 -0700303 fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700304 num_pkt2s = random.randint(10,30)
Ken Chiangfb593e72012-03-28 17:19:13 -0700305 fs_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700306 for i in range(0,num_pkt1s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700307 sendPacket(self, pkt1, ingress_port, egress_port1, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700308 for i in range(0,num_pkt2s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700309 sendPacket(self, pkt2, ingress_port, egress_port2, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700310
Ed Swierk99a74de2012-08-22 06:40:54 -0700311 match1 = packet_to_flow_match(self, pkt1)
Ken Chiangaa5bc062012-03-31 14:03:28 -0700312 fs_logger.info("Verifying flow1's " + str(num_pkt1s) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700313 self.verifyStats(match1, ofp.OFPP_NONE, test_timeout, num_pkt1s)
Ed Swierk99a74de2012-08-22 06:40:54 -0700314 match2 = packet_to_flow_match(self, pkt2)
Ken Chiangaa5bc062012-03-31 14:03:28 -0700315 fs_logger.info("Verifying flow2's " + str(num_pkt2s) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700316 self.verifyStats(match2, ofp.OFPP_NONE, test_timeout, num_pkt2s)
317 match1.wildcards |= ofp.OFPFW_DL_SRC
Ken Chiangaa5bc062012-03-31 14:03:28 -0700318 fs_logger.info("Verifying combined " + str(num_pkt1s+num_pkt2s) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700319 self.verifyStats(match1, ofp.OFPP_NONE, test_timeout,
320 num_pkt1s+num_pkt2s)
321 # TODO: sweep through the wildcards to verify matching?
322
323
324class AggregateStats(basic.SimpleDataPlane):
325 """
326 Verify aggregate flow stats are properly retrieved.
327
328 Generate two packets
329 Generate and install two matching flows
330 Send an aggregate stats request
331 Verify that aggregate stats are correct
332 Also verify out_port filtering
333 """
334
335 def buildFlowModMsg(self, pkt, ingress_port, egress_port):
Ed Swierk99a74de2012-08-22 06:40:54 -0700336 match = packet_to_flow_match(self, pkt)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700337 match.wildcards &= ~ofp.OFPFW_IN_PORT
338 self.assertTrue(match is not None,
339 "Could not generate flow match from pkt")
340 match.in_port = ingress_port
341
342 flow_mod_msg = message.flow_mod()
343 flow_mod_msg.match = match
344 flow_mod_msg.cookie = random.randint(0,9007199254740992)
345 flow_mod_msg.buffer_id = 0xffffffff
346 flow_mod_msg.idle_timeout = 0
347 flow_mod_msg.hard_timeout = 0
348 act = action.action_output()
349 act.port = egress_port
350 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
351
Ken Chiangfb593e72012-03-28 17:19:13 -0700352 fs_logger.info("Ingress " + str(ingress_port) +
Ken Chiang620bdcc2012-03-23 12:52:07 -0700353 " to egress " + str(egress_port))
354
355 return flow_mod_msg
356
Ken Chiang620bdcc2012-03-23 12:52:07 -0700357 def verifyAggFlowStats(self, match, out_port, test_timeout,
358 flow_count, packet_count):
359 stat_req = message.aggregate_stats_request()
360 stat_req.match = match
361 stat_req.table_id = 0xff
362 stat_req.out_port = out_port
363
364 all_packets_received = 0
365 for i in range(0,test_timeout):
Ken Chiangfb593e72012-03-28 17:19:13 -0700366 fs_logger.info("Sending stats request")
367 response, pkt = self.controller.transact(stat_req,
368 timeout=test_timeout)
369 self.assertTrue(response is not None,
370 "No response to stats request")
Dan Talaycoaff26c82012-03-25 15:06:26 -0700371 self.assertTrue(len(response.stats) == 1,
372 "Did not receive flow stats reply")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700373 for obj in response.stats:
374 self.assertTrue(obj.flow_count == flow_count,
375 "Flow count " + str(obj.flow_count) +
376 " does not match expected " + str(flow_count))
Ken Chiangfb593e72012-03-28 17:19:13 -0700377 fs_logger.info("Received " + str(obj.packet_count) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700378 if obj.packet_count == packet_count:
379 all_packets_received = 1
380
381 if all_packets_received:
382 break
383 sleep(1)
384
385 self.assertTrue(all_packets_received,
386 "Packet count does not match number sent")
387
388 def runTest(self):
Ken Chiangfb593e72012-03-28 17:19:13 -0700389 global fs_port_map
Ken Chiang620bdcc2012-03-23 12:52:07 -0700390
391 # TODO: set from command-line parameter
392 test_timeout = 60
393
Ken Chiangfb593e72012-03-28 17:19:13 -0700394 of_ports = fs_port_map.keys()
Ken Chiang620bdcc2012-03-23 12:52:07 -0700395 of_ports.sort()
396 self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
397 ingress_port = of_ports[0];
398 egress_port1 = of_ports[1];
399 egress_port2 = of_ports[2];
400
Ken Chiangfb593e72012-03-28 17:19:13 -0700401 rc = delete_all_flows(self.controller, fs_logger)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700402 self.assertEqual(rc, 0, "Failed to delete all flows")
403
404 pkt1 = simple_tcp_packet()
405 flow_mod_msg1 = self.buildFlowModMsg(pkt1, ingress_port, egress_port1)
406
407 pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
408 flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
409
Ken Chiangfb593e72012-03-28 17:19:13 -0700410 fs_logger.info("Inserting flow1")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700411 rv = self.controller.message_send(flow_mod_msg1)
412 self.assertTrue(rv != -1, "Error installing flow mod")
Ken Chiangfb593e72012-03-28 17:19:13 -0700413 fs_logger.info("Inserting flow2")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700414 rv = self.controller.message_send(flow_mod_msg2)
415 self.assertTrue(rv != -1, "Error installing flow mod")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700416 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700417
418 num_pkt1s = random.randint(10,30)
Ken Chiangfb593e72012-03-28 17:19:13 -0700419 fs_logger.info("Sending " + str(num_pkt1s) + " pkt1s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700420 num_pkt2s = random.randint(10,30)
Ken Chiangfb593e72012-03-28 17:19:13 -0700421 fs_logger.info("Sending " + str(num_pkt2s) + " pkt2s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700422 for i in range(0,num_pkt1s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700423 sendPacket(self, pkt1, ingress_port, egress_port1, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700424 for i in range(0,num_pkt2s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700425 sendPacket(self, pkt2, ingress_port, egress_port2, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700426
427 # loop on flow stats request until timeout
Ed Swierk99a74de2012-08-22 06:40:54 -0700428 match = packet_to_flow_match(self, pkt1)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700429 match.wildcards |= ofp.OFPFW_DL_SRC
430 self.verifyAggFlowStats(match, ofp.OFPP_NONE, test_timeout,
431 2, num_pkt1s+num_pkt2s)
432
433 # out_port filter for egress_port1
434 self.verifyAggFlowStats(match, egress_port1, test_timeout,
435 1, num_pkt1s)
436
437 # out_port filter for egress_port1
438 self.verifyAggFlowStats(match, egress_port2, test_timeout,
439 1, num_pkt2s)