blob: c30ba51203aaaf48f1e3192299b64bb108c3f264 [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
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
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400377 (qs_before,p) = get_queuestats(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
ShreyaPanditaed209962012-11-04 02:16:48 -0500385 expected_packets = qs_before.stats[0].tx_packets+1
ShreyaPandita66de26f2012-10-26 14:44:24 -0400386
ShreyaPanditaed209962012-11-04 02:16:48 -0500387 verify_queuestats(self,egress_port,egress_queue_id,expect_packet=expected_packets)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400388
389
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400390class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400391
392 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
393
394 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400395 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400396
397 of_ports = config["port_map"].keys()
398 of_ports.sort()
399 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
400
401 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400402 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400403
404 for idx in range(len(of_ports)):
405 ingress_port = of_ports[idx]
406 egress_port = of_ports[(idx + 1) % len(of_ports)]
407
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400408 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400409
410 for egress_queue_id in queue_id:
411
412 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800413 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400414
415 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400416 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400417
418 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400419 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400420
421 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400422 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400423
ShreyaPanditaed209962012-11-04 02:16:48 -0500424 expected_bytes = qs_before.stats[0].tx_bytes+len(str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400425
ShreyaPandita87932042012-11-05 18:48:39 -0500426 verify_queuestats(self,egress_port,egress_queue_id,expect_byte=expected_bytes)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400427
ShreyaPanditaed209962012-11-04 02:16:48 -0500428
ShreyaPandita66de26f2012-10-26 14:44:24 -0400429class RxDrops(base_tests.SimpleDataPlane):
430
431 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
432
433 def runTest(self):
434
435 logging.info("Running Rx_Drops test")
436
437 of_ports = config["port_map"].keys()
438 of_ports.sort()
439 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
440
441 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800442 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400443
444 logging.info("Send Port_Stats Request")
445 logging.info("Verify reply has rx_dropped count ")
446
447 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400448 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400449
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400450 rx_drp = counter[4]
451 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400452
453
454
455class TxDrops(base_tests.SimpleDataPlane):
456
457 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
458
459 def runTest(self):
460
461 logging.info("Running Tx_Drops test")
462
463 of_ports = config["port_map"].keys()
464 of_ports.sort()
465 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
466
467 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800468 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400469
470 logging.info("Send Port_Stats Request")
471 logging.info("Verify reply has tx_dropped count ")
472
473 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400474 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400475
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400476 tx_drp = counter[5]
477 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400478
479
480class RxErrors(base_tests.SimpleDataPlane):
481
482 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
483 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
484 rx_*_err values"""
485
486 def runTest(self):
487
488 logging.info("Running Rx_Errors test")
489
490 of_ports = config["port_map"].keys()
491 of_ports.sort()
492 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
493
494 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800495 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400496
497 logging.info("Send Port_Stats Request")
498 logging.info("Verify reply has rx_errors count ")
499
500 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400501 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400502
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400503 rx_err = counter[6]
504 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400505
506
507class TxErrors(base_tests.SimpleDataPlane):
508
509 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
510
511 def runTest(self):
512
513 logging.info("Running Tx_Errors test")
514
515 of_ports = config["port_map"].keys()
516 of_ports.sort()
517 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
518
519 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800520 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400521
522 logging.info("Send Port_Stats Request")
523 logging.info("Verify reply has Tx_errors count ")
524
525 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400526 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400527
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400528 tx_err = counter[7]
529 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400530
531
532class RxFrameErr(base_tests.SimpleDataPlane):
533
534 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
535
536 def runTest(self):
537
538 logging.info("Running Rx_Frame_Err test")
539
540 of_ports = config["port_map"].keys()
541 of_ports.sort()
542 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
543
544 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800545 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400546
547 logging.info("Send Port_Stats Request")
548 logging.info("Verify reply has rx_frame_err count ")
549
550 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400551 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400552
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400553 rx_fr_err = counter[8]
554 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400555
556
557
558class RxOErr(base_tests.SimpleDataPlane):
559
560 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
561
562 def runTest(self):
563
564 logging.info("Running Rx_O_Err test")
565
566 of_ports = config["port_map"].keys()
567 of_ports.sort()
568 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
569
570 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800571 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400572
573 logging.info("Send Port_Stats Request")
574 logging.info("Verify reply has rx_over_err count ")
575
576 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400577 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400578
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400579 rx_over_err = counter[9]
580 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400581
582
583
584
585class RxCrcErr(base_tests.SimpleDataPlane):
586
587 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
588
589 def runTest(self):
590
591 logging.info("Running Port_Counter_9 test")
592
593 of_ports = config["port_map"].keys()
594 of_ports.sort()
595 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
596
597 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800598 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400599
600 logging.info("Send Port_Stats Request")
601 logging.info("Verify reply has rx_crc_err count ")
602
603 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400604 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400605
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400606 rx_crc_err = counter[10]
607 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400608
609
610
611class Collisions(base_tests.SimpleDataPlane):
612
613 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
614
615 def runTest(self):
616
617 logging.info("Running Collisions 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
Rich Lane32bf9482013-01-03 17:26:30 -0800624 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400625
626 logging.info("Send Port_Stats Request")
627 logging.info("Verify reply has Collisions count ")
628
629 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400630 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400631
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400632 collisions = counter[11]
633 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400634
635
636
637
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400638class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400639
640 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
641
642 def runTest(self):
643
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400644 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400645
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
Rich Lane32bf9482013-01-03 17:26:30 -0800651 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400652
653 logging.info("Send Queue_Stats Request")
654 logging.info("Verify reply has Tramitted Overrun errors count ")
655
656 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400657 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400658
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400659 tx_err = counter[12]
660 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400661
ShreyaPandita66de26f2012-10-26 14:44:24 -0400662
663