blob: 77182b69259a512d1f7ba0ccb44af29c3438c118 [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.dataplane as dataplane
ShreyaPandita66de26f2012-10-26 14:44:24 -040016import oftest.parse as parse
17import oftest.base_tests as base_tests
18import time
19
20from oftest.testutils import *
21from time import sleep
22from FuncUtils import*
23
24
ShreyaPanditae807dfb2012-11-02 19:01:19 -040025def port_queues_get(self, queue_stats, port_num):
ShreyaPandita66de26f2012-10-26 14:44:24 -040026 result = []
Rich Lane5fd6faf2013-03-11 13:30:20 -070027 for qs in queue_stats.entries:
ShreyaPandita66de26f2012-10-26 14:44:24 -040028 if qs.port_no != port_num:
29 continue
30 result.append(qs.queue_id)
31 return result
32
33
ShreyaPanditae807dfb2012-11-02 19:01:19 -040034class PktPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -040035
ShreyaPanditae807dfb2012-11-02 19:01:19 -040036 """Verify Packet counters per flow are
37 incremented by no. of packets received for that flow"""
ShreyaPandita66de26f2012-10-26 14:44:24 -040038
39 def runTest(self):
40
ShreyaPanditae807dfb2012-11-02 19:01:19 -040041 logging.info("Running PktPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -040042
43 of_ports = config["port_map"].keys()
44 of_ports.sort()
45 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
46
47 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080048 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -040049
50 logging.info("Insert any flow")
51 logging.info("Sending N Packets matching the flow")
ShreyaPanditae807dfb2012-11-02 19:01:19 -040052 logging.info("Verify packet counters increment in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -040053
54 #Create a Match on Ingress flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -040055 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
56
57 #Send Packets matching the flow
58 num_pkts = 5
59 for pkt_cnt in range(num_pkts):
60 self.dataplane.send(of_ports[0],str(pkt))
Rich Laneae3428c2013-03-07 14:37:42 -080061
62 # Verify the packet counter was updated
63 verify_flow_stats(self, match, pkts=num_pkts)
ShreyaPanditae807dfb2012-11-02 19:01:19 -040064
65
66class BytPerFlow(base_tests.SimpleDataPlane):
67
68 """Verify Byte counters per flow are
69 incremented by no. of bytes received for that flow"""
70
71 def runTest(self):
72
73 logging.info("Running BytPerFlow test")
74
75 of_ports = config["port_map"].keys()
76 of_ports.sort()
77 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
78
79 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080080 delete_all_flows(self.controller)
ShreyaPanditae807dfb2012-11-02 19:01:19 -040081
82 logging.info("Insert any flow")
83 logging.info("Sending N Packets matching the flow")
84 logging.info("Verify byte counters increment in accordance")
85
86 #Create a Match on Ingress flow
87 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -040088
89 #Send Packets matching the flow
90 num_pkts = 5
91 byte_count = num_pkts*len(str(pkt))
92 for pkt_cnt in range(num_pkts):
93 self.dataplane.send(of_ports[0],str(pkt))
Rich Laneae3428c2013-03-07 14:37:42 -080094
95 # Verify the byte counter was updated
96 verify_flow_stats(self, match, bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -040097
98
ShreyaPanditae807dfb2012-11-02 19:01:19 -040099class DurationPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400100
101 """Verify Duration_sec and Duration_nsec counters per flow varies in accordance with the amount of
102 time the flow was alive"""
103
104 def runTest(self):
105
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400106 logging.info("Running DurationPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400107
108 of_ports = config["port_map"].keys()
109 of_ports.sort()
110 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
111
112 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800113 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400114
115 logging.info("Insert any flow")
116 logging.info("Send Flow_stats request after n sec intervals")
117 logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")
118
119 #Create a flow with match on ingress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400120 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
121
ShreyaPandita66de26f2012-10-26 14:44:24 -0400122 #Create flow_stats request
Rich Lane28fa9272013-03-08 16:00:25 -0800123 stat_req = ofp.message.flow_stats_request()
ShreyaPandita66de26f2012-10-26 14:44:24 -0400124 stat_req.match= match
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400125 stat_req.table_id = 0xff
126 stat_req.out_port = ofp.OFPP_NONE
Rich Lane0b04b6c2012-12-31 10:12:23 -0800127
128 expected_duration = 3
129 sleep(expected_duration)
130
131 response, pkt = self.controller.transact(stat_req)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400132
Rich Lane0b04b6c2012-12-31 10:12:23 -0800133 self.assertTrue(response is not None,"No response to stats request")
Rich Lane5fd6faf2013-03-11 13:30:20 -0700134 self.assertTrue(len(response.entries) == 1,"Did not receive flow stats reply")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400135
Rich Lane5fd6faf2013-03-11 13:30:20 -0700136 stat = response.entries[0]
Rich Lane0b04b6c2012-12-31 10:12:23 -0800137 logging.info("Duration of flow is %d s %d ns", stat.duration_sec, stat.duration_nsec)
138 self.assertTrue(stat.duration_sec == expected_duration, "Flow stats reply incorrect")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400139
140
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400141class RxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400142
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400143 """Verify that rx_packets counter in the Port_Stats reply
144 increments when packets are received on a port"""
ShreyaPandita66de26f2012-10-26 14:44:24 -0400145
146 def runTest(self):
147
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400148 logging.info("Running RxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400149
150 of_ports = config["port_map"].keys()
151 of_ports.sort()
152 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
153
154 # Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800155 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400156
157 logging.info("Insert a flow with match on ingress_port")
158 logging.info("Send N Packets on an ingress_port P ")
159 logging.info("Send Port_Stats Request for Port P , verify recieved packets counters are incrementing in accordance")
160
161 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400162 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400163
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400164 # Send Port_Stats request for the ingress port (retrieve old counter state)
Rich Lane968b6192013-03-07 15:34:43 -0800165 initial_stats = get_port_stats(self, of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400166
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400167 # Send packets matching the flow
168 num_pkts = 5
ShreyaPandita66de26f2012-10-26 14:44:24 -0400169 for pkt_cnt in range(num_pkts):
170 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700171
ShreyaPandita66de26f2012-10-26 14:44:24 -0400172 #Verify recieved packet counters
Rich Lane968b6192013-03-07 15:34:43 -0800173 verify_port_stats(self, of_ports[0], initial=initial_stats, rx_pkts=num_pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400174
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400175class TxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400176
177 """Verify that tx_packets counter in the Port_Stats reply , increments when packets are transmitted by a port"""
178
179 def runTest(self):
180
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400181 logging.info("Running TxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400182
183 of_ports = config["port_map"].keys()
184 of_ports.sort()
185 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
186
187 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800188 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400189
ShreyaPandita66de26f2012-10-26 14:44:24 -0400190 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
191 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500192 logging.info("Send Port_Stats Request for Port T , verify transmitted packets counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400193
194 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400195 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400196
Rich Lane968b6192013-03-07 15:34:43 -0800197 # Send Port_Stats request for the egress port (retrieve old counter state)
198 initial_stats = get_port_stats(self, of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400199
200 #Send packets matching the flow
201 num_pkts = 5
202 for pkt_cnt in range(num_pkts):
203 self.dataplane.send(of_ports[0],str(pkt))
204
205 #Verify transmitted_packet counters
Rich Lane968b6192013-03-07 15:34:43 -0800206 verify_port_stats(self, of_ports[1], initial=initial_stats,
207 tx_pkts=num_pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400208
209
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400210
211class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400212
213 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
214
215 def runTest(self):
216
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400217 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400218
219 of_ports = config["port_map"].keys()
220 of_ports.sort()
221 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
222
223 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800224 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400225
226 logging.info("Insert any flow matching on in_port=ingress_port")
227 logging.info("Send N Packets matching the flow on ingress_port P ")
228 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
229
230 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400231 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400232
233 # Send Port_Stats request for the ingress port (retrieve current counter state)
Rich Lane968b6192013-03-07 15:34:43 -0800234 initial_stats = get_port_stats(self, of_ports[0])
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400235
ShreyaPandita66de26f2012-10-26 14:44:24 -0400236 #Send packets matching the flow.
237 num_pkts = 5
238 byte_count = num_pkts*len(str(pkt))
239 for pkt_cnt in range(num_pkts):
240 self.dataplane.send(of_ports[0],str(pkt))
241
ShreyaPandita66de26f2012-10-26 14:44:24 -0400242 #Verify recieved_bytes counters
Rich Lane968b6192013-03-07 15:34:43 -0800243 verify_port_stats(self, of_ports[0], initial=initial_stats,
244 rx_bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400245
246
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400247class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400248
249 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
250
251 def runTest(self):
252
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400253 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400254
255 of_ports = config["port_map"].keys()
256 of_ports.sort()
257 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
258
259 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800260 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400261
ShreyaPanditaed209962012-11-04 02:16:48 -0500262 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400263 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500264 logging.info("Send Port_Stats Request for Port T , verify trasmitted bytes counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400265
266 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400267 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400268
Rich Lane968b6192013-03-07 15:34:43 -0800269 # Send Port_Stats request for the egress port (retrieve current counter state)
270 initial_stats = get_port_stats(self, of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400271
272 #Send packets matching the flow.
273 num_pkts = 5
274 byte_count = num_pkts*len(str(pkt))
275 for pkt_cnt in range(num_pkts):
276 self.dataplane.send(of_ports[0],str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400277
278 #Verify trasmitted_bytes counters
Rich Lane968b6192013-03-07 15:34:43 -0800279 verify_port_stats(self, of_ports[1], initial=initial_stats,
280 tx_bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400281
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400282class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400283
284 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
285
286 def runTest(self):
287
288 logging.info("Running Table_Counter_1 test")
289
290 of_ports = config["port_map"].keys()
291 of_ports.sort()
292 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
293
294 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800295 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400296
ShreyaPanditaed209962012-11-04 02:16:48 -0500297 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T ")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400298 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
299
300 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400301 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400302
303 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400304 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400305
306
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400307class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400308
309 """Verify that lookup_count and matched_count counter in the Table_Stats reply
310 increments in accordance with the packets looked up and matched with the flows in the table"""
311
312 def runTest(self):
313
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400314 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400315
316 of_ports = config["port_map"].keys()
317 of_ports.sort()
318 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
319
320 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800321 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400322
323 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
324 logging.info("Send N packets matching the flow, N' packets not matching the flow")
325 logging.info("Send Table_Stats, verify lookup_count = N+N' & matched_count=N ")
326
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400327 #Get Current Table Stats
328 (current_lookedup,current_matched,current_active) = get_tablestats(self)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400329
330 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400331 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400332
333 #send packet pkt N times (pkt matches the flow)
334 num_sends = 5
335 for pkt_cnt in range(num_sends):
336 self.dataplane.send(of_ports[0],str(pkt))
337
338 #send packet pkt N' (pkt does not match the flow)
339 num_sends2 = 5
340 for pkt_cnt in range(num_sends):
341 self.dataplane.send(of_ports[1],str(pkt))
342
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400343 new_lookup = num_sends+num_sends2+current_lookedup
344 new_matched = num_sends+current_matched
Rich Lane47d0ec02012-10-26 14:28:19 -0700345
ShreyaPandita66de26f2012-10-26 14:44:24 -0400346 #Verify lookup_count and matched_count counters.
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400347 verify_tablestats(self,expect_lookup=new_lookup,expect_match=new_matched)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400348
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400349class TxPktPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400350
351 """Verify that tx_packets in the queue_stats reply increments in accordance with the number of transmitted packets"""
352
353 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400354 logging.info("Running TxPktPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400355
356 of_ports = config["port_map"].keys()
357 of_ports.sort()
358 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
359
360 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400361 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400362
363 for idx in range(len(of_ports)):
364 ingress_port = of_ports[idx]
365 egress_port = of_ports[(idx + 1) % len(of_ports)]
366
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400367 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400368
369 for egress_queue_id in queue_id:
370
371 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800372 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400373
374 # Get Queue stats for selected egress queue only
Rich Lane6a334922013-03-07 16:14:52 -0800375 initial_stats = get_queue_stats(self, egress_port, egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400376
377 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400378 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400379
380 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400381 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400382
Rich Lane6a334922013-03-07 16:14:52 -0800383 verify_queue_stats(self, egress_port, egress_queue_id,
384 initial=initial_stats, pkts=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400385
386
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400387class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400388
389 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
390
391 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400392 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400393
394 of_ports = config["port_map"].keys()
395 of_ports.sort()
396 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
397
398 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400399 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400400
401 for idx in range(len(of_ports)):
402 ingress_port = of_ports[idx]
403 egress_port = of_ports[(idx + 1) % len(of_ports)]
404
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400405 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400406
407 for egress_queue_id in queue_id:
408
409 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800410 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400411
412 # Get Queue stats for selected egress queue only
Rich Lane6a334922013-03-07 16:14:52 -0800413 initial_stats = get_queue_stats(self, egress_port, egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400414
415 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400416 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400417
418 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400419 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400420
Rich Lane6a334922013-03-07 16:14:52 -0800421 verify_queue_stats(self, egress_port, egress_queue_id,
422 initial=initial_stats,
423 bytes=len(str(pkt)))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400424
ShreyaPanditaed209962012-11-04 02:16:48 -0500425
ShreyaPandita66de26f2012-10-26 14:44:24 -0400426class RxDrops(base_tests.SimpleDataPlane):
427
428 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
429
430 def runTest(self):
431
432 logging.info("Running Rx_Drops test")
433
434 of_ports = config["port_map"].keys()
435 of_ports.sort()
436 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
437
438 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800439 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400440
441 logging.info("Send Port_Stats Request")
442 logging.info("Verify reply has rx_dropped count ")
443
444 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400445 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400446
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400447 rx_drp = counter[4]
448 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400449
450
451
452class TxDrops(base_tests.SimpleDataPlane):
453
454 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
455
456 def runTest(self):
457
458 logging.info("Running Tx_Drops test")
459
460 of_ports = config["port_map"].keys()
461 of_ports.sort()
462 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
463
464 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800465 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400466
467 logging.info("Send Port_Stats Request")
468 logging.info("Verify reply has tx_dropped count ")
469
470 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400471 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400472
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400473 tx_drp = counter[5]
474 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400475
476
477class RxErrors(base_tests.SimpleDataPlane):
478
479 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
480 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
481 rx_*_err values"""
482
483 def runTest(self):
484
485 logging.info("Running Rx_Errors test")
486
487 of_ports = config["port_map"].keys()
488 of_ports.sort()
489 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
490
491 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800492 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400493
494 logging.info("Send Port_Stats Request")
495 logging.info("Verify reply has rx_errors count ")
496
497 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400498 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400499
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400500 rx_err = counter[6]
501 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400502
503
504class TxErrors(base_tests.SimpleDataPlane):
505
506 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
507
508 def runTest(self):
509
510 logging.info("Running Tx_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
Rich Lane32bf9482013-01-03 17:26:30 -0800517 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400518
519 logging.info("Send Port_Stats Request")
520 logging.info("Verify reply has Tx_errors count ")
521
522 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400523 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400524
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400525 tx_err = counter[7]
526 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400527
528
529class RxFrameErr(base_tests.SimpleDataPlane):
530
531 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
532
533 def runTest(self):
534
535 logging.info("Running Rx_Frame_Err test")
536
537 of_ports = config["port_map"].keys()
538 of_ports.sort()
539 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
540
541 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800542 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400543
544 logging.info("Send Port_Stats Request")
545 logging.info("Verify reply has rx_frame_err count ")
546
547 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400548 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400549
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400550 rx_fr_err = counter[8]
551 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400552
553
554
555class RxOErr(base_tests.SimpleDataPlane):
556
557 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
558
559 def runTest(self):
560
561 logging.info("Running Rx_O_Err test")
562
563 of_ports = config["port_map"].keys()
564 of_ports.sort()
565 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
566
567 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800568 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400569
570 logging.info("Send Port_Stats Request")
571 logging.info("Verify reply has rx_over_err count ")
572
573 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400574 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400575
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400576 rx_over_err = counter[9]
577 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400578
579
580
581
582class RxCrcErr(base_tests.SimpleDataPlane):
583
584 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
585
586 def runTest(self):
587
588 logging.info("Running Port_Counter_9 test")
589
590 of_ports = config["port_map"].keys()
591 of_ports.sort()
592 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
593
594 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800595 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400596
597 logging.info("Send Port_Stats Request")
598 logging.info("Verify reply has rx_crc_err count ")
599
600 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400601 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400602
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400603 rx_crc_err = counter[10]
604 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400605
606
607
608class Collisions(base_tests.SimpleDataPlane):
609
610 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
611
612 def runTest(self):
613
614 logging.info("Running Collisions test")
615
616 of_ports = config["port_map"].keys()
617 of_ports.sort()
618 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
619
620 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800621 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400622
623 logging.info("Send Port_Stats Request")
624 logging.info("Verify reply has Collisions count ")
625
626 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400627 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400628
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400629 collisions = counter[11]
630 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400631
632
633
634
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400635class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400636
637 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
638
639 def runTest(self):
640
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400641 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400642
643 of_ports = config["port_map"].keys()
644 of_ports.sort()
645 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
646
647 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800648 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400649
650 logging.info("Send Queue_Stats Request")
651 logging.info("Verify reply has Tramitted Overrun errors count ")
652
653 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400654 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400655
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400656 tx_err = counter[12]
657 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400658
ShreyaPandita66de26f2012-10-26 14:44:24 -0400659
660