blob: e543f5900c38e0e11dc384b77c85ce8007a0fd99 [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
ShreyaPandita66de26f2012-10-26 14:44:24 -0400203 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
204 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500205 logging.info("Send Port_Stats Request for Port T , verify transmitted packets counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400206
207 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400208 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400209
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400210 # Send Port_Stats request for the ingress port (retrieve old counter state)
211 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400212
213 #Send packets matching the flow
214 num_pkts = 5
215 for pkt_cnt in range(num_pkts):
216 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700217
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400218 pkts = num_pkts+counter[1]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400219
220 #Verify transmitted_packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400221 verify_portstats(self,of_ports[1],tx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400222
223
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400224
225class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400226
227 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
228
229 def runTest(self):
230
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400231 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400232
233 of_ports = config["port_map"].keys()
234 of_ports.sort()
235 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
236
237 #Clear switch State
238 rv = delete_all_flows(self.controller)
239 self.assertEqual(rv, 0, "Failed to delete all flows")
240
241 logging.info("Insert any flow matching on in_port=ingress_port")
242 logging.info("Send N Packets matching the flow on ingress_port P ")
243 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
244
245 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400246 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400247
248 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400249 (counter) = get_portstats(self,of_ports[0])
250
ShreyaPandita66de26f2012-10-26 14:44:24 -0400251 #Send packets matching the flow.
252 num_pkts = 5
253 byte_count = num_pkts*len(str(pkt))
254 for pkt_cnt in range(num_pkts):
255 self.dataplane.send(of_ports[0],str(pkt))
256
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400257 byt_count = byte_count+counter[2]
Rich Lane47d0ec02012-10-26 14:28:19 -0700258
ShreyaPandita66de26f2012-10-26 14:44:24 -0400259 #Verify recieved_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400260 verify_portstats(self,of_ports[0],rx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400261
262
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400263class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400264
265 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
266
267 def runTest(self):
268
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400269 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400270
271 of_ports = config["port_map"].keys()
272 of_ports.sort()
273 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
274
275 #Clear switch State
276 rv = delete_all_flows(self.controller)
277 self.assertEqual(rv, 0, "Failed to delete all flows")
278
ShreyaPanditaed209962012-11-04 02:16:48 -0500279 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400280 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500281 logging.info("Send Port_Stats Request for Port T , verify trasmitted bytes counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400282
283 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400284 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400285
286 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400287 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400288
289 #Send packets matching the flow.
290 num_pkts = 5
291 byte_count = num_pkts*len(str(pkt))
292 for pkt_cnt in range(num_pkts):
293 self.dataplane.send(of_ports[0],str(pkt))
294
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400295 byt_count = byte_count+counter[3]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400296
297 #Verify trasmitted_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400298 verify_portstats(self,of_ports[1],tx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400299
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400300class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400301
302 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
303
304 def runTest(self):
305
306 logging.info("Running Table_Counter_1 test")
307
308 of_ports = config["port_map"].keys()
309 of_ports.sort()
310 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
311
312 #Clear Switch state
313 rv = delete_all_flows(self.controller)
314 self.assertEqual(rv, 0, "Failed to delete all flows")
315
ShreyaPanditaed209962012-11-04 02:16:48 -0500316 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T ")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400317 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
318
319 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400320 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400321
322 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400323 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400324
325
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400326class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400327
328 """Verify that lookup_count and matched_count counter in the Table_Stats reply
329 increments in accordance with the packets looked up and matched with the flows in the table"""
330
331 def runTest(self):
332
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400333 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400334
335 of_ports = config["port_map"].keys()
336 of_ports.sort()
337 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
338
339 #Clear Switch state
340 rv = delete_all_flows(self.controller)
341 self.assertEqual(rv, 0, "Failed to delete all flows")
342
343 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
344 logging.info("Send N packets matching the flow, N' packets not matching the flow")
345 logging.info("Send Table_Stats, verify lookup_count = N+N' & matched_count=N ")
346
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400347 #Get Current Table Stats
348 (current_lookedup,current_matched,current_active) = get_tablestats(self)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400349
350 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400351 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400352
353 #send packet pkt N times (pkt matches the flow)
354 num_sends = 5
355 for pkt_cnt in range(num_sends):
356 self.dataplane.send(of_ports[0],str(pkt))
357
358 #send packet pkt N' (pkt does not match the flow)
359 num_sends2 = 5
360 for pkt_cnt in range(num_sends):
361 self.dataplane.send(of_ports[1],str(pkt))
362
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400363 new_lookup = num_sends+num_sends2+current_lookedup
364 new_matched = num_sends+current_matched
Rich Lane47d0ec02012-10-26 14:28:19 -0700365
ShreyaPandita66de26f2012-10-26 14:44:24 -0400366 #Verify lookup_count and matched_count counters.
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400367 verify_tablestats(self,expect_lookup=new_lookup,expect_match=new_matched)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400368
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400369class TxPktPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400370
371 """Verify that tx_packets in the queue_stats reply increments in accordance with the number of transmitted packets"""
372
373 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400374 logging.info("Running TxPktPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400375
376 of_ports = config["port_map"].keys()
377 of_ports.sort()
378 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
379
380 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400381 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400382
383 for idx in range(len(of_ports)):
384 ingress_port = of_ports[idx]
385 egress_port = of_ports[(idx + 1) % len(of_ports)]
386
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400387 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400388
389 for egress_queue_id in queue_id:
390
391 #Clear switch state
392 rv = delete_all_flows(self.controller)
393 self.assertEqual(rv, 0, "Failed to delete all flows")
394
395 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400396 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400397
398 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400399 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400400
401 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400402 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400403
ShreyaPanditaed209962012-11-04 02:16:48 -0500404 expected_packets = qs_before.stats[0].tx_packets+1
ShreyaPandita66de26f2012-10-26 14:44:24 -0400405
ShreyaPanditaed209962012-11-04 02:16:48 -0500406 verify_queuestats(self,egress_port,egress_queue_id,expect_packet=expected_packets)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400407
408
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400409class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400410
411 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
412
413 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400414 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400415
416 of_ports = config["port_map"].keys()
417 of_ports.sort()
418 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
419
420 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400421 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400422
423 for idx in range(len(of_ports)):
424 ingress_port = of_ports[idx]
425 egress_port = of_ports[(idx + 1) % len(of_ports)]
426
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400427 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400428
429 for egress_queue_id in queue_id:
430
431 #Clear switch state
432 rv = delete_all_flows(self.controller)
433 self.assertEqual(rv, 0, "Failed to delete all flows")
434
435 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400436 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400437
438 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400439 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400440
441 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400442 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400443
ShreyaPanditaed209962012-11-04 02:16:48 -0500444 expected_bytes = qs_before.stats[0].tx_bytes+len(str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400445
ShreyaPanditaed209962012-11-04 02:16:48 -0500446 verify_queuestats(self,egress_port,egress_queue_id,expect_packet=expected_bytes)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400447
ShreyaPanditaed209962012-11-04 02:16:48 -0500448
ShreyaPandita66de26f2012-10-26 14:44:24 -0400449class RxDrops(base_tests.SimpleDataPlane):
450
451 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
452
453 def runTest(self):
454
455 logging.info("Running Rx_Drops test")
456
457 of_ports = config["port_map"].keys()
458 of_ports.sort()
459 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
460
461 #Clear switch State
462 rv = delete_all_flows(self.controller)
463 self.assertEqual(rv, 0, "Failed to delete all flows")
464
465 logging.info("Send Port_Stats Request")
466 logging.info("Verify reply has rx_dropped count ")
467
468 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400469 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400470
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400471 rx_drp = counter[4]
472 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400473
474
475
476class TxDrops(base_tests.SimpleDataPlane):
477
478 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
479
480 def runTest(self):
481
482 logging.info("Running Tx_Drops test")
483
484 of_ports = config["port_map"].keys()
485 of_ports.sort()
486 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
487
488 #Clear switch State
489 rv = delete_all_flows(self.controller)
490 self.assertEqual(rv, 0, "Failed to delete all flows")
491
492 logging.info("Send Port_Stats Request")
493 logging.info("Verify reply has tx_dropped count ")
494
495 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400496 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400497
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400498 tx_drp = counter[5]
499 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400500
501
502class RxErrors(base_tests.SimpleDataPlane):
503
504 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
505 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
506 rx_*_err values"""
507
508 def runTest(self):
509
510 logging.info("Running Rx_Errors test")
511
512 of_ports = config["port_map"].keys()
513 of_ports.sort()
514 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
515
516 #Clear switch State
517 rv = delete_all_flows(self.controller)
518 self.assertEqual(rv, 0, "Failed to delete all flows")
519
520 logging.info("Send Port_Stats Request")
521 logging.info("Verify reply has rx_errors count ")
522
523 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400524 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400525
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400526 rx_err = counter[6]
527 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400528
529
530class TxErrors(base_tests.SimpleDataPlane):
531
532 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
533
534 def runTest(self):
535
536 logging.info("Running Tx_Errors test")
537
538 of_ports = config["port_map"].keys()
539 of_ports.sort()
540 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
541
542 #Clear switch State
543 rv = delete_all_flows(self.controller)
544 self.assertEqual(rv, 0, "Failed to delete all flows")
545
546 logging.info("Send Port_Stats Request")
547 logging.info("Verify reply has Tx_errors count ")
548
549 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400550 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400551
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400552 tx_err = counter[7]
553 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400554
555
556class RxFrameErr(base_tests.SimpleDataPlane):
557
558 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
559
560 def runTest(self):
561
562 logging.info("Running Rx_Frame_Err test")
563
564 of_ports = config["port_map"].keys()
565 of_ports.sort()
566 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
567
568 #Clear switch State
569 rv = delete_all_flows(self.controller)
570 self.assertEqual(rv, 0, "Failed to delete all flows")
571
572 logging.info("Send Port_Stats Request")
573 logging.info("Verify reply has rx_frame_err count ")
574
575 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400576 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400577
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400578 rx_fr_err = counter[8]
579 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400580
581
582
583class RxOErr(base_tests.SimpleDataPlane):
584
585 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
586
587 def runTest(self):
588
589 logging.info("Running Rx_O_Err test")
590
591 of_ports = config["port_map"].keys()
592 of_ports.sort()
593 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
594
595 #Clear switch State
596 rv = delete_all_flows(self.controller)
597 self.assertEqual(rv, 0, "Failed to delete all flows")
598
599 logging.info("Send Port_Stats Request")
600 logging.info("Verify reply has rx_over_err count ")
601
602 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400603 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400604
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400605 rx_over_err = counter[9]
606 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400607
608
609
610
611class RxCrcErr(base_tests.SimpleDataPlane):
612
613 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
614
615 def runTest(self):
616
617 logging.info("Running Port_Counter_9 test")
618
619 of_ports = config["port_map"].keys()
620 of_ports.sort()
621 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
622
623 #Clear switch State
624 rv = delete_all_flows(self.controller)
625 self.assertEqual(rv, 0, "Failed to delete all flows")
626
627 logging.info("Send Port_Stats Request")
628 logging.info("Verify reply has rx_crc_err count ")
629
630 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400631 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400632
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400633 rx_crc_err = counter[10]
634 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400635
636
637
638class Collisions(base_tests.SimpleDataPlane):
639
640 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
641
642 def runTest(self):
643
644 logging.info("Running Collisions test")
645
646 of_ports = config["port_map"].keys()
647 of_ports.sort()
648 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
649
650 #Clear switch State
651 rv = delete_all_flows(self.controller)
652 self.assertEqual(rv, 0, "Failed to delete all flows")
653
654 logging.info("Send Port_Stats Request")
655 logging.info("Verify reply has Collisions count ")
656
657 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400658 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400659
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400660 collisions = counter[11]
661 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400662
663
664
665
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400666class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400667
668 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
669
670 def runTest(self):
671
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400672 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400673
674 of_ports = config["port_map"].keys()
675 of_ports.sort()
676 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
677
678 #Clear switch State
679 rv = delete_all_flows(self.controller)
680 self.assertEqual(rv, 0, "Failed to delete all flows")
681
682 logging.info("Send Queue_Stats Request")
683 logging.info("Verify reply has Tramitted Overrun errors count ")
684
685 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400686 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400687
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400688 tx_err = counter[12]
689 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400690
ShreyaPandita66de26f2012-10-26 14:44:24 -0400691
692