blob: 4caae4fbd13ef76349304321804c29b337a8d371 [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))
63
64 #Verify Recieved Packets/Bytes Per Flow
65 verify_flowstats(self,match,packet_count=num_pkts)
66
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))
96
97 #Verify Recieved Packets/Bytes Per Flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -040098 verify_flowstats(self,match,byte_count=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)
167 (counter) = get_portstats(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
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400174 pkts = num_pkts+counter[0]
175
ShreyaPandita66de26f2012-10-26 14:44:24 -0400176 #Verify recieved packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400177 verify_portstats(self,of_ports[0],rx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400178
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400179class TxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400180
181 """Verify that tx_packets counter in the Port_Stats reply , increments when packets are transmitted by a port"""
182
183 def runTest(self):
184
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400185 logging.info("Running TxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400186
187 of_ports = config["port_map"].keys()
188 of_ports.sort()
189 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
190
191 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800192 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400193
ShreyaPandita66de26f2012-10-26 14:44:24 -0400194 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
195 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500196 logging.info("Send Port_Stats Request for Port T , verify transmitted packets counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400197
198 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400199 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400200
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400201 # Send Port_Stats request for the ingress port (retrieve old counter state)
202 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400203
204 #Send packets matching the flow
205 num_pkts = 5
206 for pkt_cnt in range(num_pkts):
207 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700208
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400209 pkts = num_pkts+counter[1]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400210
211 #Verify transmitted_packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400212 verify_portstats(self,of_ports[1],tx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400213
214
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400215
216class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400217
218 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
219
220 def runTest(self):
221
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400222 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400223
224 of_ports = config["port_map"].keys()
225 of_ports.sort()
226 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
227
228 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800229 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400230
231 logging.info("Insert any flow matching on in_port=ingress_port")
232 logging.info("Send N Packets matching the flow on ingress_port P ")
233 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
234
235 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400236 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400237
238 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400239 (counter) = get_portstats(self,of_ports[0])
240
ShreyaPandita66de26f2012-10-26 14:44:24 -0400241 #Send packets matching the flow.
242 num_pkts = 5
243 byte_count = num_pkts*len(str(pkt))
244 for pkt_cnt in range(num_pkts):
245 self.dataplane.send(of_ports[0],str(pkt))
246
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400247 byt_count = byte_count+counter[2]
Rich Lane47d0ec02012-10-26 14:28:19 -0700248
ShreyaPandita66de26f2012-10-26 14:44:24 -0400249 #Verify recieved_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400250 verify_portstats(self,of_ports[0],rx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400251
252
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400253class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400254
255 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
256
257 def runTest(self):
258
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400259 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400260
261 of_ports = config["port_map"].keys()
262 of_ports.sort()
263 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
264
265 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800266 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400267
ShreyaPanditaed209962012-11-04 02:16:48 -0500268 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400269 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500270 logging.info("Send Port_Stats Request for Port T , verify trasmitted bytes counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400271
272 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400273 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400274
275 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400276 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400277
278 #Send packets matching the flow.
279 num_pkts = 5
280 byte_count = num_pkts*len(str(pkt))
281 for pkt_cnt in range(num_pkts):
282 self.dataplane.send(of_ports[0],str(pkt))
283
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400284 byt_count = byte_count+counter[3]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400285
286 #Verify trasmitted_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400287 verify_portstats(self,of_ports[1],tx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400288
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400289class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400290
291 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
292
293 def runTest(self):
294
295 logging.info("Running Table_Counter_1 test")
296
297 of_ports = config["port_map"].keys()
298 of_ports.sort()
299 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
300
301 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800302 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400303
ShreyaPanditaed209962012-11-04 02:16:48 -0500304 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T ")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400305 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
306
307 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400308 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400309
310 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400311 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400312
313
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400314class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400315
316 """Verify that lookup_count and matched_count counter in the Table_Stats reply
317 increments in accordance with the packets looked up and matched with the flows in the table"""
318
319 def runTest(self):
320
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400321 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400322
323 of_ports = config["port_map"].keys()
324 of_ports.sort()
325 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
326
327 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800328 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400329
330 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
331 logging.info("Send N packets matching the flow, N' packets not matching the flow")
332 logging.info("Send Table_Stats, verify lookup_count = N+N' & matched_count=N ")
333
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400334 #Get Current Table Stats
335 (current_lookedup,current_matched,current_active) = get_tablestats(self)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400336
337 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400338 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400339
340 #send packet pkt N times (pkt matches the flow)
341 num_sends = 5
342 for pkt_cnt in range(num_sends):
343 self.dataplane.send(of_ports[0],str(pkt))
344
345 #send packet pkt N' (pkt does not match the flow)
346 num_sends2 = 5
347 for pkt_cnt in range(num_sends):
348 self.dataplane.send(of_ports[1],str(pkt))
349
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400350 new_lookup = num_sends+num_sends2+current_lookedup
351 new_matched = num_sends+current_matched
Rich Lane47d0ec02012-10-26 14:28:19 -0700352
ShreyaPandita66de26f2012-10-26 14:44:24 -0400353 #Verify lookup_count and matched_count counters.
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400354 verify_tablestats(self,expect_lookup=new_lookup,expect_match=new_matched)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400355
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400356class TxPktPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400357
358 """Verify that tx_packets in the queue_stats reply increments in accordance with the number of transmitted packets"""
359
360 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400361 logging.info("Running TxPktPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400362
363 of_ports = config["port_map"].keys()
364 of_ports.sort()
365 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
366
367 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400368 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400369
370 for idx in range(len(of_ports)):
371 ingress_port = of_ports[idx]
372 egress_port = of_ports[(idx + 1) % len(of_ports)]
373
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400374 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400375
376 for egress_queue_id in queue_id:
377
378 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800379 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400380
381 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400382 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400383
384 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400385 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400386
387 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400388 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400389
ShreyaPanditaed209962012-11-04 02:16:48 -0500390 expected_packets = qs_before.stats[0].tx_packets+1
ShreyaPandita66de26f2012-10-26 14:44:24 -0400391
ShreyaPanditaed209962012-11-04 02:16:48 -0500392 verify_queuestats(self,egress_port,egress_queue_id,expect_packet=expected_packets)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400393
394
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400395class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400396
397 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
398
399 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400400 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400401
402 of_ports = config["port_map"].keys()
403 of_ports.sort()
404 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
405
406 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400407 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400408
409 for idx in range(len(of_ports)):
410 ingress_port = of_ports[idx]
411 egress_port = of_ports[(idx + 1) % len(of_ports)]
412
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400413 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400414
415 for egress_queue_id in queue_id:
416
417 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800418 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400419
420 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400421 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400422
423 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400424 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400425
426 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400427 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400428
ShreyaPanditaed209962012-11-04 02:16:48 -0500429 expected_bytes = qs_before.stats[0].tx_bytes+len(str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400430
ShreyaPandita87932042012-11-05 18:48:39 -0500431 verify_queuestats(self,egress_port,egress_queue_id,expect_byte=expected_bytes)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400432
ShreyaPanditaed209962012-11-04 02:16:48 -0500433
ShreyaPandita66de26f2012-10-26 14:44:24 -0400434class RxDrops(base_tests.SimpleDataPlane):
435
436 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
437
438 def runTest(self):
439
440 logging.info("Running Rx_Drops test")
441
442 of_ports = config["port_map"].keys()
443 of_ports.sort()
444 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
445
446 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800447 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400448
449 logging.info("Send Port_Stats Request")
450 logging.info("Verify reply has rx_dropped count ")
451
452 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400453 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400454
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400455 rx_drp = counter[4]
456 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400457
458
459
460class TxDrops(base_tests.SimpleDataPlane):
461
462 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
463
464 def runTest(self):
465
466 logging.info("Running Tx_Drops test")
467
468 of_ports = config["port_map"].keys()
469 of_ports.sort()
470 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
471
472 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800473 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400474
475 logging.info("Send Port_Stats Request")
476 logging.info("Verify reply has tx_dropped count ")
477
478 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400479 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400480
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400481 tx_drp = counter[5]
482 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400483
484
485class RxErrors(base_tests.SimpleDataPlane):
486
487 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
488 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
489 rx_*_err values"""
490
491 def runTest(self):
492
493 logging.info("Running Rx_Errors test")
494
495 of_ports = config["port_map"].keys()
496 of_ports.sort()
497 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
498
499 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800500 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400501
502 logging.info("Send Port_Stats Request")
503 logging.info("Verify reply has rx_errors count ")
504
505 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400506 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400507
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400508 rx_err = counter[6]
509 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400510
511
512class TxErrors(base_tests.SimpleDataPlane):
513
514 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
515
516 def runTest(self):
517
518 logging.info("Running Tx_Errors test")
519
520 of_ports = config["port_map"].keys()
521 of_ports.sort()
522 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
523
524 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800525 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400526
527 logging.info("Send Port_Stats Request")
528 logging.info("Verify reply has Tx_errors count ")
529
530 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400531 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400532
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400533 tx_err = counter[7]
534 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400535
536
537class RxFrameErr(base_tests.SimpleDataPlane):
538
539 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
540
541 def runTest(self):
542
543 logging.info("Running Rx_Frame_Err test")
544
545 of_ports = config["port_map"].keys()
546 of_ports.sort()
547 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
548
549 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800550 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400551
552 logging.info("Send Port_Stats Request")
553 logging.info("Verify reply has rx_frame_err count ")
554
555 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400556 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400557
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400558 rx_fr_err = counter[8]
559 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400560
561
562
563class RxOErr(base_tests.SimpleDataPlane):
564
565 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
566
567 def runTest(self):
568
569 logging.info("Running Rx_O_Err test")
570
571 of_ports = config["port_map"].keys()
572 of_ports.sort()
573 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
574
575 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800576 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400577
578 logging.info("Send Port_Stats Request")
579 logging.info("Verify reply has rx_over_err count ")
580
581 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400582 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400583
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400584 rx_over_err = counter[9]
585 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400586
587
588
589
590class RxCrcErr(base_tests.SimpleDataPlane):
591
592 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
593
594 def runTest(self):
595
596 logging.info("Running Port_Counter_9 test")
597
598 of_ports = config["port_map"].keys()
599 of_ports.sort()
600 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
601
602 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800603 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400604
605 logging.info("Send Port_Stats Request")
606 logging.info("Verify reply has rx_crc_err count ")
607
608 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400609 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400610
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400611 rx_crc_err = counter[10]
612 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400613
614
615
616class Collisions(base_tests.SimpleDataPlane):
617
618 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
619
620 def runTest(self):
621
622 logging.info("Running Collisions test")
623
624 of_ports = config["port_map"].keys()
625 of_ports.sort()
626 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
627
628 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800629 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400630
631 logging.info("Send Port_Stats Request")
632 logging.info("Verify reply has Collisions count ")
633
634 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400635 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400636
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400637 collisions = counter[11]
638 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400639
640
641
642
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400643class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400644
645 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
646
647 def runTest(self):
648
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400649 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400650
651 of_ports = config["port_map"].keys()
652 of_ports.sort()
653 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
654
655 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800656 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400657
658 logging.info("Send Queue_Stats Request")
659 logging.info("Verify reply has Tramitted Overrun errors count ")
660
661 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400662 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400663
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400664 tx_err = counter[12]
665 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400666
ShreyaPandita66de26f2012-10-26 14:44:24 -0400667
668