blob: 0a01419ec11284cd12dd6e03fa681a84dac0688e [file] [log] [blame]
ShreyaPandita66de26f2012-10-26 14:44:24 -04001"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
2 Refer Documentation -- Detailed testing methodology
3 <Some of test-cases are directly taken from oftest> """
4
5"Test Suite 5 --> Counters"
6
7import logging
8
9import unittest
10import random
11
12from oftest import config
13import oftest.controller as controller
14import oftest.cstruct as ofp
15import oftest.message as message
16import oftest.dataplane as dataplane
17import oftest.action as action
18import oftest.parse as parse
19import oftest.base_tests as base_tests
20import time
21
22from oftest.testutils import *
23from time import sleep
24from FuncUtils import*
25
26
ShreyaPanditae807dfb2012-11-02 19:01:19 -040027def port_queues_get(self, queue_stats, port_num):
ShreyaPandita66de26f2012-10-26 14:44:24 -040028 result = []
29 for qs in queue_stats.stats:
30 if qs.port_no != port_num:
31 continue
32 result.append(qs.queue_id)
33 return result
34
35
ShreyaPanditae807dfb2012-11-02 19:01:19 -040036class PktPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -040037
ShreyaPanditae807dfb2012-11-02 19:01:19 -040038 """Verify Packet counters per flow are
39 incremented by no. of packets received for that flow"""
ShreyaPandita66de26f2012-10-26 14:44:24 -040040
41 def runTest(self):
42
ShreyaPanditae807dfb2012-11-02 19:01:19 -040043 logging.info("Running PktPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -040044
45 of_ports = config["port_map"].keys()
46 of_ports.sort()
47 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
48
49 #Clear switch state
50 rv = delete_all_flows(self.controller)
51 self.assertEqual(rv, 0, "Failed to delete all flows")
52
53 logging.info("Insert any flow")
54 logging.info("Sending N Packets matching the flow")
ShreyaPanditae807dfb2012-11-02 19:01:19 -040055 logging.info("Verify packet counters increment in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -040056
57 #Create a Match on Ingress flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -040058 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
59
60 #Send Packets matching the flow
61 num_pkts = 5
62 for pkt_cnt in range(num_pkts):
63 self.dataplane.send(of_ports[0],str(pkt))
64
65 #Verify Recieved Packets/Bytes Per Flow
66 verify_flowstats(self,match,packet_count=num_pkts)
67
68
69class BytPerFlow(base_tests.SimpleDataPlane):
70
71 """Verify Byte counters per flow are
72 incremented by no. of bytes received for that flow"""
73
74 def runTest(self):
75
76 logging.info("Running BytPerFlow test")
77
78 of_ports = config["port_map"].keys()
79 of_ports.sort()
80 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
81
82 #Clear switch state
83 rv = delete_all_flows(self.controller)
84 self.assertEqual(rv, 0, "Failed to delete all flows")
85
86 logging.info("Insert any flow")
87 logging.info("Sending N Packets matching the flow")
88 logging.info("Verify byte counters increment in accordance")
89
90 #Create a Match on Ingress flow
91 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -040092
93 #Send Packets matching the flow
94 num_pkts = 5
95 byte_count = num_pkts*len(str(pkt))
96 for pkt_cnt in range(num_pkts):
97 self.dataplane.send(of_ports[0],str(pkt))
98
99 #Verify Recieved Packets/Bytes Per Flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400100 verify_flowstats(self,match,byte_count=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400101
102
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400103class DurationPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400104
105 """Verify Duration_sec and Duration_nsec counters per flow varies in accordance with the amount of
106 time the flow was alive"""
107
108 def runTest(self):
109
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400110 logging.info("Running DurationPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400111
112 of_ports = config["port_map"].keys()
113 of_ports.sort()
114 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
115
116 #Clear switch state
117 rc = delete_all_flows(self.controller)
118 self.assertEqual(rc, 0, "Failed to delete all flows")
119
120 logging.info("Insert any flow")
121 logging.info("Send Flow_stats request after n sec intervals")
122 logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")
123
124 #Create a flow with match on ingress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400125 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
126
ShreyaPandita66de26f2012-10-26 14:44:24 -0400127 #Create flow_stats request
128 test_timeout = 30
129 stat_req = message.flow_stats_request()
130 stat_req.match= match
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400131 stat_req.table_id = 0xff
132 stat_req.out_port = ofp.OFPP_NONE
ShreyaPandita66de26f2012-10-26 14:44:24 -0400133
134 flow_stats_gen_ts = range (10,test_timeout,10)
135
136 for ts in range(0,test_timeout):
137 if ts in flow_stats_gen_ts:
138 response, pkt = self.controller.transact(stat_req)
139
140 self.assertTrue(response is not None,"No response to stats request")
141 self.assertTrue(len(response.stats) == 1,"Did not receive flow stats reply")
142
143 stat = response.stats[0]
144 self.assertTrue(stat.duration_sec == ts,"Flow stats reply incorrect")
145 logging.info("Duration of flow is " + str(stat.duration_sec) + str(stat.duration_nsec))
146
147 sleep(1)
148
149
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400150class RxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400151
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400152 """Verify that rx_packets counter in the Port_Stats reply
153 increments when packets are received on a port"""
ShreyaPandita66de26f2012-10-26 14:44:24 -0400154
155 def runTest(self):
156
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400157 logging.info("Running RxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400158
159 of_ports = config["port_map"].keys()
160 of_ports.sort()
161 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
162
163 # Clear Switch State
164 rv = delete_all_flows(self.controller)
165 self.assertEqual(rv, 0, "Failed to delete all flows")
166
167 logging.info("Insert a flow with match on ingress_port")
168 logging.info("Send N Packets on an ingress_port P ")
169 logging.info("Send Port_Stats Request for Port P , verify recieved packets counters are incrementing in accordance")
170
171 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400172 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400173
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400174 # Send Port_Stats request for the ingress port (retrieve old counter state)
175 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400176
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400177 # Send packets matching the flow
178 num_pkts = 5
ShreyaPandita66de26f2012-10-26 14:44:24 -0400179 for pkt_cnt in range(num_pkts):
180 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700181
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400182 pkts = num_pkts+counter[0]
183
ShreyaPandita66de26f2012-10-26 14:44:24 -0400184 #Verify recieved packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400185 verify_portstats(self,of_ports[0],rx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400186
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400187class TxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400188
189 """Verify that tx_packets counter in the Port_Stats reply , increments when packets are transmitted by a port"""
190
191 def runTest(self):
192
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400193 logging.info("Running TxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400194
195 of_ports = config["port_map"].keys()
196 of_ports.sort()
197 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
198
199 #Clear switch state
200 rv = delete_all_flows(self.controller)
201 self.assertEqual(rv, 0, "Failed to delete all flows")
202
203
204 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
205 logging.info("Send N Packets matching the flow on ingress_port P ")
206 logging.info("Send Port_Stats Request for Port P , verify transmitted packets counters are incrementing in accordance")
207
208 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400209 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400210
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400211 # Send Port_Stats request for the ingress port (retrieve old counter state)
212 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400213
214 #Send packets matching the flow
215 num_pkts = 5
216 for pkt_cnt in range(num_pkts):
217 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700218
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400219 pkts = num_pkts+counter[1]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400220
221 #Verify transmitted_packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400222 verify_portstats(self,of_ports[1],tx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400223
224
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400225
226class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400227
228 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
229
230 def runTest(self):
231
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400232 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400233
234 of_ports = config["port_map"].keys()
235 of_ports.sort()
236 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
237
238 #Clear switch State
239 rv = delete_all_flows(self.controller)
240 self.assertEqual(rv, 0, "Failed to delete all flows")
241
242 logging.info("Insert any flow matching on in_port=ingress_port")
243 logging.info("Send N Packets matching the flow on ingress_port P ")
244 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
245
246 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400247 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400248
249 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400250 (counter) = get_portstats(self,of_ports[0])
251
ShreyaPandita66de26f2012-10-26 14:44:24 -0400252 #Send packets matching the flow.
253 num_pkts = 5
254 byte_count = num_pkts*len(str(pkt))
255 for pkt_cnt in range(num_pkts):
256 self.dataplane.send(of_ports[0],str(pkt))
257
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400258 byt_count = byte_count+counter[2]
Rich Lane47d0ec02012-10-26 14:28:19 -0700259
ShreyaPandita66de26f2012-10-26 14:44:24 -0400260 #Verify recieved_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400261 verify_portstats(self,of_ports[0],rx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400262
263
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400264class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400265
266 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
267
268 def runTest(self):
269
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400270 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400271
272 of_ports = config["port_map"].keys()
273 of_ports.sort()
274 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
275
276 #Clear switch State
277 rv = delete_all_flows(self.controller)
278 self.assertEqual(rv, 0, "Failed to delete all flows")
279
280 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
281 logging.info("Send N Packets matching the flow on ingress_port P ")
282 logging.info("Send Port_Stats Request for Port P , verify trasmitted bytes counters are incrementing in accordance")
283
284 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400285 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400286
287 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400288 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400289
290 #Send packets matching the flow.
291 num_pkts = 5
292 byte_count = num_pkts*len(str(pkt))
293 for pkt_cnt in range(num_pkts):
294 self.dataplane.send(of_ports[0],str(pkt))
295
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400296 byt_count = byte_count+counter[3]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400297
298 #Verify trasmitted_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400299 verify_portstats(self,of_ports[1],tx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400300
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400301class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400302
303 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
304
305 def runTest(self):
306
307 logging.info("Running Table_Counter_1 test")
308
309 of_ports = config["port_map"].keys()
310 of_ports.sort()
311 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
312
313 #Clear Switch state
314 rv = delete_all_flows(self.controller)
315 self.assertEqual(rv, 0, "Failed to delete all flows")
316
317 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
318 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
319
320 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400321 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400322
323 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400324 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400325
326
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400327class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400328
329 """Verify that lookup_count and matched_count counter in the Table_Stats reply
330 increments in accordance with the packets looked up and matched with the flows in the table"""
331
332 def runTest(self):
333
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400334 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400335
336 of_ports = config["port_map"].keys()
337 of_ports.sort()
338 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
339
340 #Clear Switch state
341 rv = delete_all_flows(self.controller)
342 self.assertEqual(rv, 0, "Failed to delete all flows")
343
344 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
345 logging.info("Send N packets matching the flow, N' packets not matching the flow")
346 logging.info("Send Table_Stats, verify lookup_count = N+N' & matched_count=N ")
347
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400348 #Get Current Table Stats
349 (current_lookedup,current_matched,current_active) = get_tablestats(self)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400350
351 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400352 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400353
354 #send packet pkt N times (pkt matches the flow)
355 num_sends = 5
356 for pkt_cnt in range(num_sends):
357 self.dataplane.send(of_ports[0],str(pkt))
358
359 #send packet pkt N' (pkt does not match the flow)
360 num_sends2 = 5
361 for pkt_cnt in range(num_sends):
362 self.dataplane.send(of_ports[1],str(pkt))
363
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400364 new_lookup = num_sends+num_sends2+current_lookedup
365 new_matched = num_sends+current_matched
Rich Lane47d0ec02012-10-26 14:28:19 -0700366
ShreyaPandita66de26f2012-10-26 14:44:24 -0400367 #Verify lookup_count and matched_count counters.
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400368 verify_tablestats(self,expect_lookup=new_lookup,expect_match=new_matched)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400369
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400370class TxPktPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400371
372 """Verify that tx_packets in the queue_stats reply increments in accordance with the number of transmitted packets"""
373
374 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400375 logging.info("Running TxPktPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400376
377 of_ports = config["port_map"].keys()
378 of_ports.sort()
379 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
380
381 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400382 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400383
384 for idx in range(len(of_ports)):
385 ingress_port = of_ports[idx]
386 egress_port = of_ports[(idx + 1) % len(of_ports)]
387
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400388 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400389
390 for egress_queue_id in queue_id:
391
392 #Clear switch state
393 rv = delete_all_flows(self.controller)
394 self.assertEqual(rv, 0, "Failed to delete all flows")
395
396 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400397 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400398
399 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400400 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400401
402 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400403 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400404
405 # FIXME: instead of sleeping, keep requesting queue stats until
406 # the expected queue counter increases or some large timeout is
407 # reached
408 time.sleep(2)
409
410 # Get Queue Stats for selected egress queue after packets have been sent
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400411 (qs_after,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400412
413 #Verify transmitted packets counter is incremented in accordance
414 self.assertEqual(qs_after.stats[0].tx_packets,qs_before.stats[0].tx_packets + 1,"tx_packet count incorrect")
415
416
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400417class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400418
419 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
420
421 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400422 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400423
424 of_ports = config["port_map"].keys()
425 of_ports.sort()
426 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
427
428 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400429 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400430
431 for idx in range(len(of_ports)):
432 ingress_port = of_ports[idx]
433 egress_port = of_ports[(idx + 1) % len(of_ports)]
434
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400435 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400436
437 for egress_queue_id in queue_id:
438
439 #Clear switch state
440 rv = delete_all_flows(self.controller)
441 self.assertEqual(rv, 0, "Failed to delete all flows")
442
443 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400444 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400445
446 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400447 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400448
449 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400450 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400451
452 # FIXME: instead of sleeping, keep requesting queue stats until
453 # the expected queue counter increases or some large timeout is
454 # reached
455 time.sleep(2)
456
457 # Get Queue Stats for selected egress queue after packets have been sent
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400458 (qs_after,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400459
460 #Verify transmitted packets counter is incremented in accordance
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400461 self.assertEqual(qs_after.stats[0].tx_bytes,qs_before.stats[0].tx_bytes + 1,"tx_bytes count incorrect")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400462
463
464
465class RxDrops(base_tests.SimpleDataPlane):
466
467 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
468
469 def runTest(self):
470
471 logging.info("Running Rx_Drops test")
472
473 of_ports = config["port_map"].keys()
474 of_ports.sort()
475 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
476
477 #Clear switch State
478 rv = delete_all_flows(self.controller)
479 self.assertEqual(rv, 0, "Failed to delete all flows")
480
481 logging.info("Send Port_Stats Request")
482 logging.info("Verify reply has rx_dropped count ")
483
484 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400485 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400486
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400487 rx_drp = counter[4]
488 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400489
490
491
492class TxDrops(base_tests.SimpleDataPlane):
493
494 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
495
496 def runTest(self):
497
498 logging.info("Running Tx_Drops test")
499
500 of_ports = config["port_map"].keys()
501 of_ports.sort()
502 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
503
504 #Clear switch State
505 rv = delete_all_flows(self.controller)
506 self.assertEqual(rv, 0, "Failed to delete all flows")
507
508 logging.info("Send Port_Stats Request")
509 logging.info("Verify reply has tx_dropped count ")
510
511 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400512 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400513
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400514 tx_drp = counter[5]
515 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400516
517
518class RxErrors(base_tests.SimpleDataPlane):
519
520 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
521 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
522 rx_*_err values"""
523
524 def runTest(self):
525
526 logging.info("Running Rx_Errors test")
527
528 of_ports = config["port_map"].keys()
529 of_ports.sort()
530 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
531
532 #Clear switch State
533 rv = delete_all_flows(self.controller)
534 self.assertEqual(rv, 0, "Failed to delete all flows")
535
536 logging.info("Send Port_Stats Request")
537 logging.info("Verify reply has rx_errors count ")
538
539 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400540 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400541
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400542 rx_err = counter[6]
543 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400544
545
546class TxErrors(base_tests.SimpleDataPlane):
547
548 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
549
550 def runTest(self):
551
552 logging.info("Running Tx_Errors test")
553
554 of_ports = config["port_map"].keys()
555 of_ports.sort()
556 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
557
558 #Clear switch State
559 rv = delete_all_flows(self.controller)
560 self.assertEqual(rv, 0, "Failed to delete all flows")
561
562 logging.info("Send Port_Stats Request")
563 logging.info("Verify reply has Tx_errors count ")
564
565 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400566 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400567
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400568 tx_err = counter[7]
569 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400570
571
572class RxFrameErr(base_tests.SimpleDataPlane):
573
574 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
575
576 def runTest(self):
577
578 logging.info("Running Rx_Frame_Err test")
579
580 of_ports = config["port_map"].keys()
581 of_ports.sort()
582 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
583
584 #Clear switch State
585 rv = delete_all_flows(self.controller)
586 self.assertEqual(rv, 0, "Failed to delete all flows")
587
588 logging.info("Send Port_Stats Request")
589 logging.info("Verify reply has rx_frame_err count ")
590
591 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400592 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400593
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400594 rx_fr_err = counter[8]
595 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400596
597
598
599class RxOErr(base_tests.SimpleDataPlane):
600
601 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
602
603 def runTest(self):
604
605 logging.info("Running Rx_O_Err test")
606
607 of_ports = config["port_map"].keys()
608 of_ports.sort()
609 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
610
611 #Clear switch State
612 rv = delete_all_flows(self.controller)
613 self.assertEqual(rv, 0, "Failed to delete all flows")
614
615 logging.info("Send Port_Stats Request")
616 logging.info("Verify reply has rx_over_err count ")
617
618 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400619 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400620
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400621 rx_over_err = counter[9]
622 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400623
624
625
626
627class RxCrcErr(base_tests.SimpleDataPlane):
628
629 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
630
631 def runTest(self):
632
633 logging.info("Running Port_Counter_9 test")
634
635 of_ports = config["port_map"].keys()
636 of_ports.sort()
637 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
638
639 #Clear switch State
640 rv = delete_all_flows(self.controller)
641 self.assertEqual(rv, 0, "Failed to delete all flows")
642
643 logging.info("Send Port_Stats Request")
644 logging.info("Verify reply has rx_crc_err count ")
645
646 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400647 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400648
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400649 rx_crc_err = counter[10]
650 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400651
652
653
654class Collisions(base_tests.SimpleDataPlane):
655
656 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
657
658 def runTest(self):
659
660 logging.info("Running Collisions test")
661
662 of_ports = config["port_map"].keys()
663 of_ports.sort()
664 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
665
666 #Clear switch State
667 rv = delete_all_flows(self.controller)
668 self.assertEqual(rv, 0, "Failed to delete all flows")
669
670 logging.info("Send Port_Stats Request")
671 logging.info("Verify reply has Collisions count ")
672
673 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400674 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400675
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400676 collisions = counter[11]
677 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400678
679
680
681
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400682class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400683
684 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
685
686 def runTest(self):
687
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400688 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400689
690 of_ports = config["port_map"].keys()
691 of_ports.sort()
692 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
693
694 #Clear switch State
695 rv = delete_all_flows(self.controller)
696 self.assertEqual(rv, 0, "Failed to delete all flows")
697
698 logging.info("Send Queue_Stats Request")
699 logging.info("Verify reply has Tramitted Overrun errors count ")
700
701 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400702 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400703
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400704 tx_err = counter[12]
705 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400706
ShreyaPandita66de26f2012-10-26 14:44:24 -0400707
708