blob: ecc8157e6635ab35403ca437182065b5bb939be5 [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
Rich Laneda3b5ad2012-10-03 09:05:32 -070020from oftest.testutils import *
Dan Talayco89d57342010-06-07 16:24:59 -070021from 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
Ken Chiangfb593e72012-03-28 17:19:13 -070026#@var fs_config Local copy of global configuration data
27fs_config = None
Dan Talayco89d57342010-06-07 16:24:59 -070028
Ken Chiang620bdcc2012-03-23 12:52:07 -070029# TODO: ovs has problems with VLAN id?
30WILDCARD_VALUES = [ofp.OFPFW_IN_PORT,
Dan Talayco488fbc52012-04-09 16:30:41 -070031 # (ofp.OFPFW_DL_VLAN | ofp.OFPFW_DL_VLAN_PCP),
Ken Chiang620bdcc2012-03-23 12:52:07 -070032 ofp.OFPFW_DL_SRC,
33 ofp.OFPFW_DL_DST,
Dan Talayco488fbc52012-04-09 16:30:41 -070034 (ofp.OFPFW_DL_TYPE | ofp.OFPFW_NW_SRC_ALL |
35 ofp.OFPFW_NW_DST_ALL | ofp.OFPFW_NW_TOS | ofp.OFPFW_NW_PROTO |
36 ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST),
37 (ofp.OFPFW_NW_PROTO | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST),
Ken Chiang620bdcc2012-03-23 12:52:07 -070038 ofp.OFPFW_TP_SRC,
39 ofp.OFPFW_TP_DST,
Dan Talayco488fbc52012-04-09 16:30:41 -070040 ofp.OFPFW_NW_SRC_MASK,
41 ofp.OFPFW_NW_DST_MASK,
Ken Chiang620bdcc2012-03-23 12:52:07 -070042 ofp.OFPFW_DL_VLAN_PCP,
43 ofp.OFPFW_NW_TOS]
44
Dan Talayco89d57342010-06-07 16:24:59 -070045def test_set_init(config):
46 """
47 Set up function for packet action test classes
48
49 @param config The configuration dictionary; see oft
50 """
51
Ed Swierk89f78352012-03-29 12:32:32 -070052 basic.test_set_init(config)
53
Ken Chiangfb593e72012-03-28 17:19:13 -070054 global fs_port_map
Ken Chiangfb593e72012-03-28 17:19:13 -070055 global fs_config
Dan Talayco89d57342010-06-07 16:24:59 -070056
Ken Chiangfb593e72012-03-28 17:19:13 -070057 fs_port_map = config["port_map"]
58 fs_config = config
Dan Talayco89d57342010-06-07 16:24:59 -070059
Ken Chiangaa5bc062012-03-31 14:03:28 -070060def sendPacket(obj, pkt, ingress_port, egress_port, test_timeout):
61
Rich Lane9a003812012-10-04 17:17:59 -070062 logging.info("Sending packet to dp port " + str(ingress_port) +
Ken Chiangaa5bc062012-03-31 14:03:28 -070063 ", expecting output on " + str(egress_port))
64 obj.dataplane.send(ingress_port, str(pkt))
65
66 exp_pkt_arg = None
67 exp_port = None
68 if fs_config["relax"]:
69 exp_pkt_arg = pkt
70 exp_port = egress_port
71
Rich Lanec8aaa3e2012-07-26 19:28:02 -070072 (rcv_port, rcv_pkt, pkt_time) = obj.dataplane.poll(port_number=exp_port,
Ken Chiangaa5bc062012-03-31 14:03:28 -070073 exp_pkt=exp_pkt_arg)
74 obj.assertTrue(rcv_pkt is not None,
75 "Packet not received on port " + str(egress_port))
Rich Lane9a003812012-10-04 17:17:59 -070076 logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
Ken Chiangaa5bc062012-03-31 14:03:28 -070077 str(rcv_port))
78 obj.assertEqual(rcv_port, egress_port,
79 "Packet received on port " + str(rcv_port) +
80 ", expected port " + str(egress_port))
81 obj.assertEqual(str(pkt), str(rcv_pkt),
82 'Response packet does not match send packet')
83
Ken Chiang620bdcc2012-03-23 12:52:07 -070084class SingleFlowStats(basic.SimpleDataPlane):
Dan Talayco89d57342010-06-07 16:24:59 -070085 """
86 Verify flow stats are properly retrieved.
87
88 Generate a packet
Ken Chiang620bdcc2012-03-23 12:52:07 -070089 Generate and install a matching flow
90 Send the packet
91 Send a flow stats request to match the flow and retrieve stats
92 Verify that the packet counter has incremented
Dan Talayco89d57342010-06-07 16:24:59 -070093 """
Ken Chiang620bdcc2012-03-23 12:52:07 -070094
95 def verifyStats(self, match, out_port, test_timeout, packet_count):
96 stat_req = message.flow_stats_request()
97 stat_req.match = match
98 stat_req.table_id = 0xff
99 stat_req.out_port = out_port
100
101 all_packets_received = 0
102 for i in range(0,test_timeout):
Rich Lane9a003812012-10-04 17:17:59 -0700103 logging.info("Sending stats request")
Ken Chiangfb593e72012-03-28 17:19:13 -0700104 response, pkt = self.controller.transact(stat_req,
105 timeout=test_timeout)
106 self.assertTrue(response is not None,
107 "No response to stats request")
108 self.assertTrue(len(response.stats) == 1,
109 "Did not receive flow stats reply")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700110 for obj in response.stats:
111 # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
112 # for now, just clear them so the assert is simpler
113 #obj.match.pad1 = 0
114 #obj.match.pad2 = [0, 0]
115 #self.assertEqual(match, obj.match,
116 # "Matches do not match")
Rich Lane9a003812012-10-04 17:17:59 -0700117 logging.info("Received " + str(obj.packet_count) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700118 if obj.packet_count == packet_count:
119 all_packets_received = 1
120
121 if all_packets_received:
122 break
123 sleep(1)
124
125 self.assertTrue(all_packets_received,
126 "Packet count does not match number sent")
127
Dan Talayco89d57342010-06-07 16:24:59 -0700128 def runTest(self):
Ken Chiangfb593e72012-03-28 17:19:13 -0700129 global fs_port_map
Dan Talayco89d57342010-06-07 16:24:59 -0700130
Ken Chiang620bdcc2012-03-23 12:52:07 -0700131 # TODO: set from command-line parameter
132 test_timeout = 60
133
Ken Chiangfb593e72012-03-28 17:19:13 -0700134 of_ports = fs_port_map.keys()
Dan Talayco89d57342010-06-07 16:24:59 -0700135 of_ports.sort()
136 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
137
Rich Lane9a003812012-10-04 17:17:59 -0700138 rc = delete_all_flows(self.controller)
Dan Talayco89d57342010-06-07 16:24:59 -0700139 self.assertEqual(rc, 0, "Failed to delete all flows")
140
Ken Chiang620bdcc2012-03-23 12:52:07 -0700141 # build packet
Dan Talayco89d57342010-06-07 16:24:59 -0700142 pkt = simple_tcp_packet()
Ed Swierk99a74de2012-08-22 06:40:54 -0700143 match = packet_to_flow_match(self, pkt)
Dan Talayco89d57342010-06-07 16:24:59 -0700144 match.wildcards &= ~ofp.OFPFW_IN_PORT
145 self.assertTrue(match is not None,
146 "Could not generate flow match from pkt")
147 act = action.action_output()
148
Ken Chiang620bdcc2012-03-23 12:52:07 -0700149 # build flow
Dan Talayco39bf6912010-07-08 14:17:52 -0700150 ingress_port = of_ports[0];
151 egress_port = of_ports[1];
Rich Lane9a003812012-10-04 17:17:59 -0700152 logging.info("Ingress " + str(ingress_port) +
Dan Talayco89d57342010-06-07 16:24:59 -0700153 " to egress " + str(egress_port))
Ken Chiang620bdcc2012-03-23 12:52:07 -0700154 match.in_port = ingress_port
155 flow_mod_msg = message.flow_mod()
156 flow_mod_msg.match = match
157 flow_mod_msg.cookie = random.randint(0,9007199254740992)
158 flow_mod_msg.buffer_id = 0xffffffff
159 flow_mod_msg.idle_timeout = 0
160 flow_mod_msg.hard_timeout = 0
161 act.port = egress_port
162 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
163
164 # send flow
Rich Lane9a003812012-10-04 17:17:59 -0700165 logging.info("Inserting flow")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700166 rv = self.controller.message_send(flow_mod_msg)
167 self.assertTrue(rv != -1, "Error installing flow mod")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700168 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700169
170 # no packets sent, so zero packet count
171 self.verifyStats(match, ofp.OFPP_NONE, test_timeout, 0)
172
173 # send packet N times
174 num_sends = random.randint(10,20)
Rich Lane9a003812012-10-04 17:17:59 -0700175 logging.info("Sending " + str(num_sends) + " test packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700176 for i in range(0,num_sends):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700177 sendPacket(self, pkt, ingress_port, egress_port,
178 test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700179
180 self.verifyStats(match, ofp.OFPP_NONE, test_timeout, num_sends)
181 self.verifyStats(match, egress_port, test_timeout, num_sends)
182 for wc in WILDCARD_VALUES:
Ed Swierk99a74de2012-08-22 06:40:54 -0700183 match.wildcards = required_wildcards(self) | wc
Ken Chiang620bdcc2012-03-23 12:52:07 -0700184 self.verifyStats(match, egress_port, test_timeout, num_sends)
185
186
187class TwoFlowStats(basic.SimpleDataPlane):
188 """
189 Verify flow stats are properly retrieved.
190
191 Generate two packets and install two matching flows
192 Send some number of packets
193 Send a flow stats request to match the flows and retrieve stats
194 Verify that the packet counter has incremented
195
196 TODO: add a third flow, and then configure the match to exclude
197 that flow?
198 """
199
200 def buildFlowModMsg(self, pkt, ingress_port, egress_port):
Ed Swierk99a74de2012-08-22 06:40:54 -0700201 match = packet_to_flow_match(self, pkt)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700202 match.wildcards &= ~ofp.OFPFW_IN_PORT
203 self.assertTrue(match is not None,
204 "Could not generate flow match from pkt")
Dan Talayco89d57342010-06-07 16:24:59 -0700205 match.in_port = ingress_port
206
207 flow_mod_msg = message.flow_mod()
208 flow_mod_msg.match = match
209 flow_mod_msg.cookie = random.randint(0,9007199254740992)
210 flow_mod_msg.buffer_id = 0xffffffff
Ken Chiang620bdcc2012-03-23 12:52:07 -0700211 flow_mod_msg.idle_timeout = 0
212 flow_mod_msg.hard_timeout = 0
213 act = action.action_output()
Dan Talayco89d57342010-06-07 16:24:59 -0700214 act.port = egress_port
215 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
Dan Talayco89d57342010-06-07 16:24:59 -0700216
Rich Lane9a003812012-10-04 17:17:59 -0700217 logging.info("Ingress " + str(ingress_port) +
Ken Chiang620bdcc2012-03-23 12:52:07 -0700218 " to egress " + str(egress_port))
Dan Talayco89d57342010-06-07 16:24:59 -0700219
Ken Chiang620bdcc2012-03-23 12:52:07 -0700220 return flow_mod_msg
Dan Talayco89d57342010-06-07 16:24:59 -0700221
Ken Chiangaa5bc062012-03-31 14:03:28 -0700222 def sumStatsReplyCounts(self, response):
223 total_packets = 0
224 for obj in response.stats:
225 # TODO: pad1 and pad2 fields may be nonzero, is this a bug?
226 # for now, just clear them so the assert is simpler
227 #obj.match.pad1 = 0
228 #obj.match.pad2 = [0, 0]
229 #self.assertEqual(match, obj.match,
230 # "Matches do not match")
Rich Lane9a003812012-10-04 17:17:59 -0700231 logging.info("Received " + str(obj.packet_count)
Ken Chiangaa5bc062012-03-31 14:03:28 -0700232 + " packets")
233 total_packets += obj.packet_count
234 return total_packets
Ken Chiang620bdcc2012-03-23 12:52:07 -0700235
236 def verifyStats(self, match, out_port, test_timeout, packet_count):
237 stat_req = message.flow_stats_request()
238 stat_req.match = match
239 stat_req.table_id = 0xff
240 stat_req.out_port = out_port
241
242 all_packets_received = 0
243 for i in range(0,test_timeout):
Rich Lane9a003812012-10-04 17:17:59 -0700244 logging.info("Sending stats request")
Ken Chiangaa5bc062012-03-31 14:03:28 -0700245 # TODO: move REPLY_MORE handling to controller.transact?
Ken Chiangfb593e72012-03-28 17:19:13 -0700246 response, pkt = self.controller.transact(stat_req,
247 timeout=test_timeout)
248 self.assertTrue(response is not None,
249 "No response to stats request")
Ken Chiangaa5bc062012-03-31 14:03:28 -0700250 total_packets = self.sumStatsReplyCounts(response)
251
252 while response.flags == ofp.OFPSF_REPLY_MORE:
253 response, pkt = self.controller.poll(exp_msg=
254 ofp.OFPT_STATS_REPLY,
255 timeout=test_timeout)
256 total_packets += self.sumStatsReplyCounts(response)
257
Ken Chiang620bdcc2012-03-23 12:52:07 -0700258 if total_packets == packet_count:
259 all_packets_received = 1
260 break
261 sleep(1)
262
263 self.assertTrue(all_packets_received,
Ken Chiangaa5bc062012-03-31 14:03:28 -0700264 "Total stats packet count " + str(total_packets) +
265 " does not match number sent " + str(packet_count))
Ken Chiang620bdcc2012-03-23 12:52:07 -0700266
267 def runTest(self):
Ken Chiangfb593e72012-03-28 17:19:13 -0700268 global fs_port_map
Ken Chiang620bdcc2012-03-23 12:52:07 -0700269
270 # TODO: set from command-line parameter
271 test_timeout = 60
272
Ken Chiangfb593e72012-03-28 17:19:13 -0700273 of_ports = fs_port_map.keys()
Ken Chiang620bdcc2012-03-23 12:52:07 -0700274 of_ports.sort()
275 self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
276 ingress_port = of_ports[0];
277 egress_port1 = of_ports[1];
278 egress_port2 = of_ports[2];
279
Rich Lane9a003812012-10-04 17:17:59 -0700280 rc = delete_all_flows(self.controller)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700281 self.assertEqual(rc, 0, "Failed to delete all flows")
282
283 pkt1 = simple_tcp_packet()
284 flow_mod_msg1 = self.buildFlowModMsg(pkt1, ingress_port, egress_port1)
285
286 pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
287 flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
288
Rich Lane9a003812012-10-04 17:17:59 -0700289 logging.info("Inserting flow1")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700290 rv = self.controller.message_send(flow_mod_msg1)
291 self.assertTrue(rv != -1, "Error installing flow mod")
Rich Lane9a003812012-10-04 17:17:59 -0700292 logging.info("Inserting flow2")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700293 rv = self.controller.message_send(flow_mod_msg2)
294 self.assertTrue(rv != -1, "Error installing flow mod")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700295 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Dan Talayco89d57342010-06-07 16:24:59 -0700296
Ken Chiang620bdcc2012-03-23 12:52:07 -0700297 num_pkt1s = random.randint(10,30)
Rich Lane9a003812012-10-04 17:17:59 -0700298 logging.info("Sending " + str(num_pkt1s) + " pkt1s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700299 num_pkt2s = random.randint(10,30)
Rich Lane9a003812012-10-04 17:17:59 -0700300 logging.info("Sending " + str(num_pkt2s) + " pkt2s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700301 for i in range(0,num_pkt1s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700302 sendPacket(self, pkt1, ingress_port, egress_port1, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700303 for i in range(0,num_pkt2s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700304 sendPacket(self, pkt2, ingress_port, egress_port2, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700305
Ed Swierk99a74de2012-08-22 06:40:54 -0700306 match1 = packet_to_flow_match(self, pkt1)
Rich Lane9a003812012-10-04 17:17:59 -0700307 logging.info("Verifying flow1's " + str(num_pkt1s) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700308 self.verifyStats(match1, ofp.OFPP_NONE, test_timeout, num_pkt1s)
Ed Swierk99a74de2012-08-22 06:40:54 -0700309 match2 = packet_to_flow_match(self, pkt2)
Rich Lane9a003812012-10-04 17:17:59 -0700310 logging.info("Verifying flow2's " + str(num_pkt2s) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700311 self.verifyStats(match2, ofp.OFPP_NONE, test_timeout, num_pkt2s)
312 match1.wildcards |= ofp.OFPFW_DL_SRC
Rich Lane9a003812012-10-04 17:17:59 -0700313 logging.info("Verifying combined " + str(num_pkt1s+num_pkt2s) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700314 self.verifyStats(match1, ofp.OFPP_NONE, test_timeout,
315 num_pkt1s+num_pkt2s)
316 # TODO: sweep through the wildcards to verify matching?
317
318
319class AggregateStats(basic.SimpleDataPlane):
320 """
321 Verify aggregate flow stats are properly retrieved.
322
323 Generate two packets
324 Generate and install two matching flows
325 Send an aggregate stats request
326 Verify that aggregate stats are correct
327 Also verify out_port filtering
328 """
329
330 def buildFlowModMsg(self, pkt, ingress_port, egress_port):
Ed Swierk99a74de2012-08-22 06:40:54 -0700331 match = packet_to_flow_match(self, pkt)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700332 match.wildcards &= ~ofp.OFPFW_IN_PORT
333 self.assertTrue(match is not None,
334 "Could not generate flow match from pkt")
335 match.in_port = ingress_port
336
337 flow_mod_msg = message.flow_mod()
338 flow_mod_msg.match = match
339 flow_mod_msg.cookie = random.randint(0,9007199254740992)
340 flow_mod_msg.buffer_id = 0xffffffff
341 flow_mod_msg.idle_timeout = 0
342 flow_mod_msg.hard_timeout = 0
343 act = action.action_output()
344 act.port = egress_port
345 self.assertTrue(flow_mod_msg.actions.add(act), "Could not add action")
346
Rich Lane9a003812012-10-04 17:17:59 -0700347 logging.info("Ingress " + str(ingress_port) +
Ken Chiang620bdcc2012-03-23 12:52:07 -0700348 " to egress " + str(egress_port))
349
350 return flow_mod_msg
351
Ken Chiang620bdcc2012-03-23 12:52:07 -0700352 def verifyAggFlowStats(self, match, out_port, test_timeout,
353 flow_count, packet_count):
354 stat_req = message.aggregate_stats_request()
355 stat_req.match = match
356 stat_req.table_id = 0xff
357 stat_req.out_port = out_port
358
359 all_packets_received = 0
360 for i in range(0,test_timeout):
Rich Lane9a003812012-10-04 17:17:59 -0700361 logging.info("Sending stats request")
Ken Chiangfb593e72012-03-28 17:19:13 -0700362 response, pkt = self.controller.transact(stat_req,
363 timeout=test_timeout)
364 self.assertTrue(response is not None,
365 "No response to stats request")
Dan Talaycoaff26c82012-03-25 15:06:26 -0700366 self.assertTrue(len(response.stats) == 1,
367 "Did not receive flow stats reply")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700368 for obj in response.stats:
369 self.assertTrue(obj.flow_count == flow_count,
370 "Flow count " + str(obj.flow_count) +
371 " does not match expected " + str(flow_count))
Rich Lane9a003812012-10-04 17:17:59 -0700372 logging.info("Received " + str(obj.packet_count) + " packets")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700373 if obj.packet_count == packet_count:
374 all_packets_received = 1
375
376 if all_packets_received:
377 break
378 sleep(1)
379
380 self.assertTrue(all_packets_received,
381 "Packet count does not match number sent")
382
383 def runTest(self):
Ken Chiangfb593e72012-03-28 17:19:13 -0700384 global fs_port_map
Ken Chiang620bdcc2012-03-23 12:52:07 -0700385
386 # TODO: set from command-line parameter
387 test_timeout = 60
388
Ken Chiangfb593e72012-03-28 17:19:13 -0700389 of_ports = fs_port_map.keys()
Ken Chiang620bdcc2012-03-23 12:52:07 -0700390 of_ports.sort()
391 self.assertTrue(len(of_ports) >= 3, "Not enough ports for test")
392 ingress_port = of_ports[0];
393 egress_port1 = of_ports[1];
394 egress_port2 = of_ports[2];
395
Rich Lane9a003812012-10-04 17:17:59 -0700396 rc = delete_all_flows(self.controller)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700397 self.assertEqual(rc, 0, "Failed to delete all flows")
398
399 pkt1 = simple_tcp_packet()
400 flow_mod_msg1 = self.buildFlowModMsg(pkt1, ingress_port, egress_port1)
401
402 pkt2 = simple_tcp_packet(dl_src='0:7:7:7:7:7')
403 flow_mod_msg2 = self.buildFlowModMsg(pkt2, ingress_port, egress_port2)
404
Rich Lane9a003812012-10-04 17:17:59 -0700405 logging.info("Inserting flow1")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700406 rv = self.controller.message_send(flow_mod_msg1)
407 self.assertTrue(rv != -1, "Error installing flow mod")
Rich Lane9a003812012-10-04 17:17:59 -0700408 logging.info("Inserting flow2")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700409 rv = self.controller.message_send(flow_mod_msg2)
410 self.assertTrue(rv != -1, "Error installing flow mod")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700411 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700412
413 num_pkt1s = random.randint(10,30)
Rich Lane9a003812012-10-04 17:17:59 -0700414 logging.info("Sending " + str(num_pkt1s) + " pkt1s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700415 num_pkt2s = random.randint(10,30)
Rich Lane9a003812012-10-04 17:17:59 -0700416 logging.info("Sending " + str(num_pkt2s) + " pkt2s")
Ken Chiang620bdcc2012-03-23 12:52:07 -0700417 for i in range(0,num_pkt1s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700418 sendPacket(self, pkt1, ingress_port, egress_port1, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700419 for i in range(0,num_pkt2s):
Ken Chiangaa5bc062012-03-31 14:03:28 -0700420 sendPacket(self, pkt2, ingress_port, egress_port2, test_timeout)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700421
422 # loop on flow stats request until timeout
Ed Swierk99a74de2012-08-22 06:40:54 -0700423 match = packet_to_flow_match(self, pkt1)
Ken Chiang620bdcc2012-03-23 12:52:07 -0700424 match.wildcards |= ofp.OFPFW_DL_SRC
425 self.verifyAggFlowStats(match, ofp.OFPP_NONE, test_timeout,
426 2, num_pkt1s+num_pkt2s)
427
428 # out_port filter for egress_port1
429 self.verifyAggFlowStats(match, egress_port1, test_timeout,
430 1, num_pkt1s)
431
432 # out_port filter for egress_port1
433 self.verifyAggFlowStats(match, egress_port2, test_timeout,
434 1, num_pkt2s)