blob: 1c35dd7a23a3e9f53d25c91f96daaa34476a804a [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
Rich Laned7b0ffa2013-03-08 15:53:42 -080014import ofp
ShreyaPandita66de26f2012-10-26 14:44:24 -040015import 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
Rich Lane32bf9482013-01-03 17:26:30 -080050 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -040051
52 logging.info("Insert any flow")
53 logging.info("Sending N Packets matching the flow")
ShreyaPanditae807dfb2012-11-02 19:01:19 -040054 logging.info("Verify packet counters increment in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -040055
56 #Create a Match on Ingress flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -040057 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
58
59 #Send Packets matching the flow
60 num_pkts = 5
61 for pkt_cnt in range(num_pkts):
62 self.dataplane.send(of_ports[0],str(pkt))
Rich Laneae3428c2013-03-07 14:37:42 -080063
64 # Verify the packet counter was updated
65 verify_flow_stats(self, match, pkts=num_pkts)
ShreyaPanditae807dfb2012-11-02 19:01:19 -040066
67
68class BytPerFlow(base_tests.SimpleDataPlane):
69
70 """Verify Byte counters per flow are
71 incremented by no. of bytes received for that flow"""
72
73 def runTest(self):
74
75 logging.info("Running BytPerFlow test")
76
77 of_ports = config["port_map"].keys()
78 of_ports.sort()
79 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
80
81 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080082 delete_all_flows(self.controller)
ShreyaPanditae807dfb2012-11-02 19:01:19 -040083
84 logging.info("Insert any flow")
85 logging.info("Sending N Packets matching the flow")
86 logging.info("Verify byte counters increment in accordance")
87
88 #Create a Match on Ingress flow
89 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -040090
91 #Send Packets matching the flow
92 num_pkts = 5
93 byte_count = num_pkts*len(str(pkt))
94 for pkt_cnt in range(num_pkts):
95 self.dataplane.send(of_ports[0],str(pkt))
Rich Laneae3428c2013-03-07 14:37:42 -080096
97 # Verify the byte counter was updated
98 verify_flow_stats(self, match, bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -040099
100
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400101class DurationPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400102
103 """Verify Duration_sec and Duration_nsec counters per flow varies in accordance with the amount of
104 time the flow was alive"""
105
106 def runTest(self):
107
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400108 logging.info("Running DurationPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400109
110 of_ports = config["port_map"].keys()
111 of_ports.sort()
112 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
113
114 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800115 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400116
117 logging.info("Insert any flow")
118 logging.info("Send Flow_stats request after n sec intervals")
119 logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")
120
121 #Create a flow with match on ingress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400122 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
123
ShreyaPandita66de26f2012-10-26 14:44:24 -0400124 #Create flow_stats request
ShreyaPandita66de26f2012-10-26 14:44:24 -0400125 stat_req = message.flow_stats_request()
126 stat_req.match= match
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400127 stat_req.table_id = 0xff
128 stat_req.out_port = ofp.OFPP_NONE
Rich Lane0b04b6c2012-12-31 10:12:23 -0800129
130 expected_duration = 3
131 sleep(expected_duration)
132
133 response, pkt = self.controller.transact(stat_req)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400134
Rich Lane0b04b6c2012-12-31 10:12:23 -0800135 self.assertTrue(response is not None,"No response to stats request")
136 self.assertTrue(len(response.stats) == 1,"Did not receive flow stats reply")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400137
Rich Lane0b04b6c2012-12-31 10:12:23 -0800138 stat = response.stats[0]
139 logging.info("Duration of flow is %d s %d ns", stat.duration_sec, stat.duration_nsec)
140 self.assertTrue(stat.duration_sec == expected_duration, "Flow stats reply incorrect")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400141
142
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400143class RxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400144
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400145 """Verify that rx_packets counter in the Port_Stats reply
146 increments when packets are received on a port"""
ShreyaPandita66de26f2012-10-26 14:44:24 -0400147
148 def runTest(self):
149
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400150 logging.info("Running RxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400151
152 of_ports = config["port_map"].keys()
153 of_ports.sort()
154 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
155
156 # Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800157 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400158
159 logging.info("Insert a flow with match on ingress_port")
160 logging.info("Send N Packets on an ingress_port P ")
161 logging.info("Send Port_Stats Request for Port P , verify recieved packets counters are incrementing in accordance")
162
163 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400164 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400165
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400166 # Send Port_Stats request for the ingress port (retrieve old counter state)
Rich Lane968b6192013-03-07 15:34:43 -0800167 initial_stats = get_port_stats(self, of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400168
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400169 # Send packets matching the flow
170 num_pkts = 5
ShreyaPandita66de26f2012-10-26 14:44:24 -0400171 for pkt_cnt in range(num_pkts):
172 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700173
ShreyaPandita66de26f2012-10-26 14:44:24 -0400174 #Verify recieved packet counters
Rich Lane968b6192013-03-07 15:34:43 -0800175 verify_port_stats(self, of_ports[0], initial=initial_stats, rx_pkts=num_pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400176
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400177class TxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400178
179 """Verify that tx_packets counter in the Port_Stats reply , increments when packets are transmitted by a port"""
180
181 def runTest(self):
182
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400183 logging.info("Running TxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400184
185 of_ports = config["port_map"].keys()
186 of_ports.sort()
187 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
188
189 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800190 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400191
ShreyaPandita66de26f2012-10-26 14:44:24 -0400192 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
193 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500194 logging.info("Send Port_Stats Request for Port T , verify transmitted packets counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400195
196 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400197 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400198
Rich Lane968b6192013-03-07 15:34:43 -0800199 # Send Port_Stats request for the egress port (retrieve old counter state)
200 initial_stats = get_port_stats(self, of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400201
202 #Send packets matching the flow
203 num_pkts = 5
204 for pkt_cnt in range(num_pkts):
205 self.dataplane.send(of_ports[0],str(pkt))
206
207 #Verify transmitted_packet counters
Rich Lane968b6192013-03-07 15:34:43 -0800208 verify_port_stats(self, of_ports[1], initial=initial_stats,
209 tx_pkts=num_pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400210
211
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400212
213class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400214
215 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
216
217 def runTest(self):
218
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400219 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400220
221 of_ports = config["port_map"].keys()
222 of_ports.sort()
223 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
224
225 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800226 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400227
228 logging.info("Insert any flow matching on in_port=ingress_port")
229 logging.info("Send N Packets matching the flow on ingress_port P ")
230 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
231
232 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400233 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400234
235 # Send Port_Stats request for the ingress port (retrieve current counter state)
Rich Lane968b6192013-03-07 15:34:43 -0800236 initial_stats = get_port_stats(self, of_ports[0])
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400237
ShreyaPandita66de26f2012-10-26 14:44:24 -0400238 #Send packets matching the flow.
239 num_pkts = 5
240 byte_count = num_pkts*len(str(pkt))
241 for pkt_cnt in range(num_pkts):
242 self.dataplane.send(of_ports[0],str(pkt))
243
ShreyaPandita66de26f2012-10-26 14:44:24 -0400244 #Verify recieved_bytes counters
Rich Lane968b6192013-03-07 15:34:43 -0800245 verify_port_stats(self, of_ports[0], initial=initial_stats,
246 rx_bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400247
248
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400249class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400250
251 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
252
253 def runTest(self):
254
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400255 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400256
257 of_ports = config["port_map"].keys()
258 of_ports.sort()
259 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
260
261 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800262 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400263
ShreyaPanditaed209962012-11-04 02:16:48 -0500264 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400265 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500266 logging.info("Send Port_Stats Request for Port T , verify trasmitted bytes counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400267
268 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400269 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400270
Rich Lane968b6192013-03-07 15:34:43 -0800271 # Send Port_Stats request for the egress port (retrieve current counter state)
272 initial_stats = get_port_stats(self, of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400273
274 #Send packets matching the flow.
275 num_pkts = 5
276 byte_count = num_pkts*len(str(pkt))
277 for pkt_cnt in range(num_pkts):
278 self.dataplane.send(of_ports[0],str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400279
280 #Verify trasmitted_bytes counters
Rich Lane968b6192013-03-07 15:34:43 -0800281 verify_port_stats(self, of_ports[1], initial=initial_stats,
282 tx_bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400283
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400284class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400285
286 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
287
288 def runTest(self):
289
290 logging.info("Running Table_Counter_1 test")
291
292 of_ports = config["port_map"].keys()
293 of_ports.sort()
294 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
295
296 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800297 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400298
ShreyaPanditaed209962012-11-04 02:16:48 -0500299 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T ")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400300 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
301
302 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400303 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400304
305 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400306 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400307
308
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400309class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400310
311 """Verify that lookup_count and matched_count counter in the Table_Stats reply
312 increments in accordance with the packets looked up and matched with the flows in the table"""
313
314 def runTest(self):
315
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400316 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400317
318 of_ports = config["port_map"].keys()
319 of_ports.sort()
320 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
321
322 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800323 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400324
325 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
326 logging.info("Send N packets matching the flow, N' packets not matching the flow")
327 logging.info("Send Table_Stats, verify lookup_count = N+N' & matched_count=N ")
328
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400329 #Get Current Table Stats
330 (current_lookedup,current_matched,current_active) = get_tablestats(self)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400331
332 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400333 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400334
335 #send packet pkt N times (pkt matches the flow)
336 num_sends = 5
337 for pkt_cnt in range(num_sends):
338 self.dataplane.send(of_ports[0],str(pkt))
339
340 #send packet pkt N' (pkt does not match the flow)
341 num_sends2 = 5
342 for pkt_cnt in range(num_sends):
343 self.dataplane.send(of_ports[1],str(pkt))
344
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400345 new_lookup = num_sends+num_sends2+current_lookedup
346 new_matched = num_sends+current_matched
Rich Lane47d0ec02012-10-26 14:28:19 -0700347
ShreyaPandita66de26f2012-10-26 14:44:24 -0400348 #Verify lookup_count and matched_count counters.
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400349 verify_tablestats(self,expect_lookup=new_lookup,expect_match=new_matched)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400350
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400351class TxPktPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400352
353 """Verify that tx_packets in the queue_stats reply increments in accordance with the number of transmitted packets"""
354
355 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400356 logging.info("Running TxPktPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400357
358 of_ports = config["port_map"].keys()
359 of_ports.sort()
360 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
361
362 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400363 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400364
365 for idx in range(len(of_ports)):
366 ingress_port = of_ports[idx]
367 egress_port = of_ports[(idx + 1) % len(of_ports)]
368
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400369 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400370
371 for egress_queue_id in queue_id:
372
373 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800374 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400375
376 # Get Queue stats for selected egress queue only
Rich Lane6a334922013-03-07 16:14:52 -0800377 initial_stats = get_queue_stats(self, egress_port, egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400378
379 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400380 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400381
382 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400383 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400384
Rich Lane6a334922013-03-07 16:14:52 -0800385 verify_queue_stats(self, egress_port, egress_queue_id,
386 initial=initial_stats, pkts=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400387
388
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400389class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400390
391 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
392
393 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400394 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400395
396 of_ports = config["port_map"].keys()
397 of_ports.sort()
398 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
399
400 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400401 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400402
403 for idx in range(len(of_ports)):
404 ingress_port = of_ports[idx]
405 egress_port = of_ports[(idx + 1) % len(of_ports)]
406
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400407 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400408
409 for egress_queue_id in queue_id:
410
411 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800412 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400413
414 # Get Queue stats for selected egress queue only
Rich Lane6a334922013-03-07 16:14:52 -0800415 initial_stats = get_queue_stats(self, egress_port, egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400416
417 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400418 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400419
420 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400421 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400422
Rich Lane6a334922013-03-07 16:14:52 -0800423 verify_queue_stats(self, egress_port, egress_queue_id,
424 initial=initial_stats,
425 bytes=len(str(pkt)))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400426
ShreyaPanditaed209962012-11-04 02:16:48 -0500427
ShreyaPandita66de26f2012-10-26 14:44:24 -0400428class RxDrops(base_tests.SimpleDataPlane):
429
430 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
431
432 def runTest(self):
433
434 logging.info("Running Rx_Drops test")
435
436 of_ports = config["port_map"].keys()
437 of_ports.sort()
438 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
439
440 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800441 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400442
443 logging.info("Send Port_Stats Request")
444 logging.info("Verify reply has rx_dropped count ")
445
446 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400447 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400448
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400449 rx_drp = counter[4]
450 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400451
452
453
454class TxDrops(base_tests.SimpleDataPlane):
455
456 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
457
458 def runTest(self):
459
460 logging.info("Running Tx_Drops test")
461
462 of_ports = config["port_map"].keys()
463 of_ports.sort()
464 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
465
466 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800467 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400468
469 logging.info("Send Port_Stats Request")
470 logging.info("Verify reply has tx_dropped count ")
471
472 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400473 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400474
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400475 tx_drp = counter[5]
476 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400477
478
479class RxErrors(base_tests.SimpleDataPlane):
480
481 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
482 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
483 rx_*_err values"""
484
485 def runTest(self):
486
487 logging.info("Running Rx_Errors test")
488
489 of_ports = config["port_map"].keys()
490 of_ports.sort()
491 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
492
493 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800494 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400495
496 logging.info("Send Port_Stats Request")
497 logging.info("Verify reply has rx_errors count ")
498
499 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400500 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400501
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400502 rx_err = counter[6]
503 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400504
505
506class TxErrors(base_tests.SimpleDataPlane):
507
508 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
509
510 def runTest(self):
511
512 logging.info("Running Tx_Errors test")
513
514 of_ports = config["port_map"].keys()
515 of_ports.sort()
516 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
517
518 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800519 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400520
521 logging.info("Send Port_Stats Request")
522 logging.info("Verify reply has Tx_errors count ")
523
524 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400525 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400526
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400527 tx_err = counter[7]
528 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400529
530
531class RxFrameErr(base_tests.SimpleDataPlane):
532
533 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
534
535 def runTest(self):
536
537 logging.info("Running Rx_Frame_Err test")
538
539 of_ports = config["port_map"].keys()
540 of_ports.sort()
541 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
542
543 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800544 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400545
546 logging.info("Send Port_Stats Request")
547 logging.info("Verify reply has rx_frame_err 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 rx_fr_err = counter[8]
553 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400554
555
556
557class RxOErr(base_tests.SimpleDataPlane):
558
559 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
560
561 def runTest(self):
562
563 logging.info("Running Rx_O_Err test")
564
565 of_ports = config["port_map"].keys()
566 of_ports.sort()
567 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
568
569 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800570 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400571
572 logging.info("Send Port_Stats Request")
573 logging.info("Verify reply has rx_over_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_over_err = counter[9]
579 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400580
581
582
583
584class RxCrcErr(base_tests.SimpleDataPlane):
585
586 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
587
588 def runTest(self):
589
590 logging.info("Running Port_Counter_9 test")
591
592 of_ports = config["port_map"].keys()
593 of_ports.sort()
594 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
595
596 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800597 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400598
599 logging.info("Send Port_Stats Request")
600 logging.info("Verify reply has rx_crc_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_crc_err = counter[10]
606 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400607
608
609
610class Collisions(base_tests.SimpleDataPlane):
611
612 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
613
614 def runTest(self):
615
616 logging.info("Running Collisions test")
617
618 of_ports = config["port_map"].keys()
619 of_ports.sort()
620 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
621
622 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800623 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400624
625 logging.info("Send Port_Stats Request")
626 logging.info("Verify reply has Collisions count ")
627
628 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400629 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400630
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400631 collisions = counter[11]
632 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400633
634
635
636
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400637class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400638
639 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
640
641 def runTest(self):
642
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400643 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400644
645 of_ports = config["port_map"].keys()
646 of_ports.sort()
647 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
648
649 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800650 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400651
652 logging.info("Send Queue_Stats Request")
653 logging.info("Verify reply has Tramitted Overrun errors count ")
654
655 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400656 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400657
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400658 tx_err = counter[12]
659 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400660
ShreyaPandita66de26f2012-10-26 14:44:24 -0400661
662