blob: 46566cc609b7491a94182d7c59e08e152ddf7070 [file] [log] [blame]
ShreyaPandita66de26f2012-10-26 14:44:24 -04001"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
2 Refer Documentation -- Detailed testing methodology
3 <Some of test-cases are directly taken from oftest> """
4
5"Test Suite 5 --> Counters"
6
7import logging
8
9import unittest
10import random
11
12from oftest import config
13import oftest.controller as controller
14import oftest.cstruct as ofp
15import oftest.message as message
16import oftest.dataplane as dataplane
17import oftest.action as action
18import oftest.parse as parse
19import oftest.base_tests as base_tests
20import time
21
22from oftest.testutils import *
23from time import sleep
24from FuncUtils import*
25
26
ShreyaPanditae807dfb2012-11-02 19:01:19 -040027def port_queues_get(self, queue_stats, port_num):
ShreyaPandita66de26f2012-10-26 14:44:24 -040028 result = []
29 for qs in queue_stats.stats:
30 if qs.port_no != port_num:
31 continue
32 result.append(qs.queue_id)
33 return result
34
35
ShreyaPanditae807dfb2012-11-02 19:01:19 -040036class PktPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -040037
ShreyaPanditae807dfb2012-11-02 19:01:19 -040038 """Verify Packet counters per flow are
39 incremented by no. of packets received for that flow"""
ShreyaPandita66de26f2012-10-26 14:44:24 -040040
41 def runTest(self):
42
ShreyaPanditae807dfb2012-11-02 19:01:19 -040043 logging.info("Running PktPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -040044
45 of_ports = config["port_map"].keys()
46 of_ports.sort()
47 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
48
49 #Clear switch state
50 rv = delete_all_flows(self.controller)
51 self.assertEqual(rv, 0, "Failed to delete all flows")
52
53 logging.info("Insert any flow")
54 logging.info("Sending N Packets matching the flow")
ShreyaPanditae807dfb2012-11-02 19:01:19 -040055 logging.info("Verify packet counters increment in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -040056
57 #Create a Match on Ingress flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -040058 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
59
60 #Send Packets matching the flow
61 num_pkts = 5
62 for pkt_cnt in range(num_pkts):
63 self.dataplane.send(of_ports[0],str(pkt))
64
65 #Verify Recieved Packets/Bytes Per Flow
66 verify_flowstats(self,match,packet_count=num_pkts)
67
68
69class BytPerFlow(base_tests.SimpleDataPlane):
70
71 """Verify Byte counters per flow are
72 incremented by no. of bytes received for that flow"""
73
74 def runTest(self):
75
76 logging.info("Running BytPerFlow test")
77
78 of_ports = config["port_map"].keys()
79 of_ports.sort()
80 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
81
82 #Clear switch state
83 rv = delete_all_flows(self.controller)
84 self.assertEqual(rv, 0, "Failed to delete all flows")
85
86 logging.info("Insert any flow")
87 logging.info("Sending N Packets matching the flow")
88 logging.info("Verify byte counters increment in accordance")
89
90 #Create a Match on Ingress flow
91 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -040092
93 #Send Packets matching the flow
94 num_pkts = 5
95 byte_count = num_pkts*len(str(pkt))
96 for pkt_cnt in range(num_pkts):
97 self.dataplane.send(of_ports[0],str(pkt))
98
99 #Verify Recieved Packets/Bytes Per Flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400100 verify_flowstats(self,match,byte_count=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400101
102
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400103class DurationPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400104
105 """Verify Duration_sec and Duration_nsec counters per flow varies in accordance with the amount of
106 time the flow was alive"""
107
108 def runTest(self):
109
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400110 logging.info("Running DurationPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400111
112 of_ports = config["port_map"].keys()
113 of_ports.sort()
114 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
115
116 #Clear switch state
117 rc = delete_all_flows(self.controller)
118 self.assertEqual(rc, 0, "Failed to delete all flows")
119
120 logging.info("Insert any flow")
121 logging.info("Send Flow_stats request after n sec intervals")
122 logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")
123
124 #Create a flow with match on ingress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400125 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
126
ShreyaPandita66de26f2012-10-26 14:44:24 -0400127 #Create flow_stats request
ShreyaPandita66de26f2012-10-26 14:44:24 -0400128 stat_req = message.flow_stats_request()
129 stat_req.match= match
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400130 stat_req.table_id = 0xff
131 stat_req.out_port = ofp.OFPP_NONE
Rich Lane0b04b6c2012-12-31 10:12:23 -0800132
133 expected_duration = 3
134 sleep(expected_duration)
135
136 response, pkt = self.controller.transact(stat_req)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400137
Rich Lane0b04b6c2012-12-31 10:12:23 -0800138 self.assertTrue(response is not None,"No response to stats request")
139 self.assertTrue(len(response.stats) == 1,"Did not receive flow stats reply")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400140
Rich Lane0b04b6c2012-12-31 10:12:23 -0800141 stat = response.stats[0]
142 logging.info("Duration of flow is %d s %d ns", stat.duration_sec, stat.duration_nsec)
143 self.assertTrue(stat.duration_sec == expected_duration, "Flow stats reply incorrect")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400144
145
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400146class RxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400147
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400148 """Verify that rx_packets counter in the Port_Stats reply
149 increments when packets are received on a port"""
ShreyaPandita66de26f2012-10-26 14:44:24 -0400150
151 def runTest(self):
152
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400153 logging.info("Running RxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400154
155 of_ports = config["port_map"].keys()
156 of_ports.sort()
157 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
158
159 # Clear Switch State
160 rv = delete_all_flows(self.controller)
161 self.assertEqual(rv, 0, "Failed to delete all flows")
162
163 logging.info("Insert a flow with match on ingress_port")
164 logging.info("Send N Packets on an ingress_port P ")
165 logging.info("Send Port_Stats Request for Port P , verify recieved packets counters are incrementing in accordance")
166
167 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400168 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400169
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400170 # Send Port_Stats request for the ingress port (retrieve old counter state)
171 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400172
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400173 # Send packets matching the flow
174 num_pkts = 5
ShreyaPandita66de26f2012-10-26 14:44:24 -0400175 for pkt_cnt in range(num_pkts):
176 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700177
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400178 pkts = num_pkts+counter[0]
179
ShreyaPandita66de26f2012-10-26 14:44:24 -0400180 #Verify recieved packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400181 verify_portstats(self,of_ports[0],rx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400182
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400183class TxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400184
185 """Verify that tx_packets counter in the Port_Stats reply , increments when packets are transmitted by a port"""
186
187 def runTest(self):
188
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400189 logging.info("Running TxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400190
191 of_ports = config["port_map"].keys()
192 of_ports.sort()
193 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
194
195 #Clear switch state
196 rv = delete_all_flows(self.controller)
197 self.assertEqual(rv, 0, "Failed to delete all flows")
198
ShreyaPandita66de26f2012-10-26 14:44:24 -0400199 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
200 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500201 logging.info("Send Port_Stats Request for Port T , verify transmitted packets counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400202
203 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400204 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400205
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400206 # Send Port_Stats request for the ingress port (retrieve old counter state)
207 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400208
209 #Send packets matching the flow
210 num_pkts = 5
211 for pkt_cnt in range(num_pkts):
212 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700213
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400214 pkts = num_pkts+counter[1]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400215
216 #Verify transmitted_packet counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400217 verify_portstats(self,of_ports[1],tx_packets=pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400218
219
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400220
221class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400222
223 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
224
225 def runTest(self):
226
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400227 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400228
229 of_ports = config["port_map"].keys()
230 of_ports.sort()
231 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
232
233 #Clear switch State
234 rv = delete_all_flows(self.controller)
235 self.assertEqual(rv, 0, "Failed to delete all flows")
236
237 logging.info("Insert any flow matching on in_port=ingress_port")
238 logging.info("Send N Packets matching the flow on ingress_port P ")
239 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
240
241 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400242 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400243
244 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400245 (counter) = get_portstats(self,of_ports[0])
246
ShreyaPandita66de26f2012-10-26 14:44:24 -0400247 #Send packets matching the flow.
248 num_pkts = 5
249 byte_count = num_pkts*len(str(pkt))
250 for pkt_cnt in range(num_pkts):
251 self.dataplane.send(of_ports[0],str(pkt))
252
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400253 byt_count = byte_count+counter[2]
Rich Lane47d0ec02012-10-26 14:28:19 -0700254
ShreyaPandita66de26f2012-10-26 14:44:24 -0400255 #Verify recieved_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400256 verify_portstats(self,of_ports[0],rx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400257
258
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400259class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400260
261 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
262
263 def runTest(self):
264
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400265 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400266
267 of_ports = config["port_map"].keys()
268 of_ports.sort()
269 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
270
271 #Clear switch State
272 rv = delete_all_flows(self.controller)
273 self.assertEqual(rv, 0, "Failed to delete all flows")
274
ShreyaPanditaed209962012-11-04 02:16:48 -0500275 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400276 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500277 logging.info("Send Port_Stats Request for Port T , verify trasmitted bytes counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400278
279 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400280 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400281
282 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400283 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400284
285 #Send packets matching the flow.
286 num_pkts = 5
287 byte_count = num_pkts*len(str(pkt))
288 for pkt_cnt in range(num_pkts):
289 self.dataplane.send(of_ports[0],str(pkt))
290
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400291 byt_count = byte_count+counter[3]
ShreyaPandita66de26f2012-10-26 14:44:24 -0400292
293 #Verify trasmitted_bytes counters
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400294 verify_portstats(self,of_ports[1],tx_byte=byt_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400295
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400296class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400297
298 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
299
300 def runTest(self):
301
302 logging.info("Running Table_Counter_1 test")
303
304 of_ports = config["port_map"].keys()
305 of_ports.sort()
306 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
307
308 #Clear Switch state
309 rv = delete_all_flows(self.controller)
310 self.assertEqual(rv, 0, "Failed to delete all flows")
311
ShreyaPanditaed209962012-11-04 02:16:48 -0500312 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T ")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400313 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
314
315 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400316 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400317
318 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400319 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400320
321
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400322class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400323
324 """Verify that lookup_count and matched_count counter in the Table_Stats reply
325 increments in accordance with the packets looked up and matched with the flows in the table"""
326
327 def runTest(self):
328
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400329 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400330
331 of_ports = config["port_map"].keys()
332 of_ports.sort()
333 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
334
335 #Clear Switch state
336 rv = delete_all_flows(self.controller)
337 self.assertEqual(rv, 0, "Failed to delete all flows")
338
339 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port")
340 logging.info("Send N packets matching the flow, N' packets not matching the flow")
341 logging.info("Send Table_Stats, verify lookup_count = N+N' & matched_count=N ")
342
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400343 #Get Current Table Stats
344 (current_lookedup,current_matched,current_active) = get_tablestats(self)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400345
346 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400347 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400348
349 #send packet pkt N times (pkt matches the flow)
350 num_sends = 5
351 for pkt_cnt in range(num_sends):
352 self.dataplane.send(of_ports[0],str(pkt))
353
354 #send packet pkt N' (pkt does not match the flow)
355 num_sends2 = 5
356 for pkt_cnt in range(num_sends):
357 self.dataplane.send(of_ports[1],str(pkt))
358
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400359 new_lookup = num_sends+num_sends2+current_lookedup
360 new_matched = num_sends+current_matched
Rich Lane47d0ec02012-10-26 14:28:19 -0700361
ShreyaPandita66de26f2012-10-26 14:44:24 -0400362 #Verify lookup_count and matched_count counters.
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400363 verify_tablestats(self,expect_lookup=new_lookup,expect_match=new_matched)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400364
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400365class TxPktPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400366
367 """Verify that tx_packets in the queue_stats reply increments in accordance with the number of transmitted packets"""
368
369 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400370 logging.info("Running TxPktPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400371
372 of_ports = config["port_map"].keys()
373 of_ports.sort()
374 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
375
376 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400377 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400378
379 for idx in range(len(of_ports)):
380 ingress_port = of_ports[idx]
381 egress_port = of_ports[(idx + 1) % len(of_ports)]
382
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400383 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400384
385 for egress_queue_id in queue_id:
386
387 #Clear switch state
388 rv = delete_all_flows(self.controller)
389 self.assertEqual(rv, 0, "Failed to delete all flows")
390
391 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400392 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400393
394 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400395 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400396
397 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400398 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400399
ShreyaPanditaed209962012-11-04 02:16:48 -0500400 expected_packets = qs_before.stats[0].tx_packets+1
ShreyaPandita66de26f2012-10-26 14:44:24 -0400401
ShreyaPanditaed209962012-11-04 02:16:48 -0500402 verify_queuestats(self,egress_port,egress_queue_id,expect_packet=expected_packets)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400403
404
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400405class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400406
407 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
408
409 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400410 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400411
412 of_ports = config["port_map"].keys()
413 of_ports.sort()
414 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
415
416 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400417 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400418
419 for idx in range(len(of_ports)):
420 ingress_port = of_ports[idx]
421 egress_port = of_ports[(idx + 1) % len(of_ports)]
422
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400423 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400424
425 for egress_queue_id in queue_id:
426
427 #Clear switch state
428 rv = delete_all_flows(self.controller)
429 self.assertEqual(rv, 0, "Failed to delete all flows")
430
431 # Get Queue stats for selected egress queue only
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400432 (qs_before,p) = get_queuestats(self,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400433
434 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400435 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400436
437 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400438 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400439
ShreyaPanditaed209962012-11-04 02:16:48 -0500440 expected_bytes = qs_before.stats[0].tx_bytes+len(str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400441
ShreyaPandita87932042012-11-05 18:48:39 -0500442 verify_queuestats(self,egress_port,egress_queue_id,expect_byte=expected_bytes)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400443
ShreyaPanditaed209962012-11-04 02:16:48 -0500444
ShreyaPandita66de26f2012-10-26 14:44:24 -0400445class RxDrops(base_tests.SimpleDataPlane):
446
447 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
448
449 def runTest(self):
450
451 logging.info("Running Rx_Drops test")
452
453 of_ports = config["port_map"].keys()
454 of_ports.sort()
455 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
456
457 #Clear switch State
458 rv = delete_all_flows(self.controller)
459 self.assertEqual(rv, 0, "Failed to delete all flows")
460
461 logging.info("Send Port_Stats Request")
462 logging.info("Verify reply has rx_dropped count ")
463
464 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400465 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400466
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400467 rx_drp = counter[4]
468 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400469
470
471
472class TxDrops(base_tests.SimpleDataPlane):
473
474 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
475
476 def runTest(self):
477
478 logging.info("Running Tx_Drops test")
479
480 of_ports = config["port_map"].keys()
481 of_ports.sort()
482 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
483
484 #Clear switch State
485 rv = delete_all_flows(self.controller)
486 self.assertEqual(rv, 0, "Failed to delete all flows")
487
488 logging.info("Send Port_Stats Request")
489 logging.info("Verify reply has tx_dropped count ")
490
491 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400492 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400493
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400494 tx_drp = counter[5]
495 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400496
497
498class RxErrors(base_tests.SimpleDataPlane):
499
500 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
501 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
502 rx_*_err values"""
503
504 def runTest(self):
505
506 logging.info("Running Rx_Errors test")
507
508 of_ports = config["port_map"].keys()
509 of_ports.sort()
510 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
511
512 #Clear switch State
513 rv = delete_all_flows(self.controller)
514 self.assertEqual(rv, 0, "Failed to delete all flows")
515
516 logging.info("Send Port_Stats Request")
517 logging.info("Verify reply has rx_errors count ")
518
519 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400520 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400521
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400522 rx_err = counter[6]
523 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400524
525
526class TxErrors(base_tests.SimpleDataPlane):
527
528 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
529
530 def runTest(self):
531
532 logging.info("Running Tx_Errors test")
533
534 of_ports = config["port_map"].keys()
535 of_ports.sort()
536 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
537
538 #Clear switch State
539 rv = delete_all_flows(self.controller)
540 self.assertEqual(rv, 0, "Failed to delete all flows")
541
542 logging.info("Send Port_Stats Request")
543 logging.info("Verify reply has Tx_errors count ")
544
545 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400546 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400547
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400548 tx_err = counter[7]
549 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400550
551
552class RxFrameErr(base_tests.SimpleDataPlane):
553
554 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
555
556 def runTest(self):
557
558 logging.info("Running Rx_Frame_Err test")
559
560 of_ports = config["port_map"].keys()
561 of_ports.sort()
562 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
563
564 #Clear switch State
565 rv = delete_all_flows(self.controller)
566 self.assertEqual(rv, 0, "Failed to delete all flows")
567
568 logging.info("Send Port_Stats Request")
569 logging.info("Verify reply has rx_frame_err count ")
570
571 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400572 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400573
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400574 rx_fr_err = counter[8]
575 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400576
577
578
579class RxOErr(base_tests.SimpleDataPlane):
580
581 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
582
583 def runTest(self):
584
585 logging.info("Running Rx_O_Err test")
586
587 of_ports = config["port_map"].keys()
588 of_ports.sort()
589 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
590
591 #Clear switch State
592 rv = delete_all_flows(self.controller)
593 self.assertEqual(rv, 0, "Failed to delete all flows")
594
595 logging.info("Send Port_Stats Request")
596 logging.info("Verify reply has rx_over_err count ")
597
598 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400599 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400600
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400601 rx_over_err = counter[9]
602 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400603
604
605
606
607class RxCrcErr(base_tests.SimpleDataPlane):
608
609 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
610
611 def runTest(self):
612
613 logging.info("Running Port_Counter_9 test")
614
615 of_ports = config["port_map"].keys()
616 of_ports.sort()
617 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
618
619 #Clear switch State
620 rv = delete_all_flows(self.controller)
621 self.assertEqual(rv, 0, "Failed to delete all flows")
622
623 logging.info("Send Port_Stats Request")
624 logging.info("Verify reply has rx_crc_err 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 rx_crc_err = counter[10]
630 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400631
632
633
634class Collisions(base_tests.SimpleDataPlane):
635
636 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
637
638 def runTest(self):
639
640 logging.info("Running Collisions test")
641
642 of_ports = config["port_map"].keys()
643 of_ports.sort()
644 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
645
646 #Clear switch State
647 rv = delete_all_flows(self.controller)
648 self.assertEqual(rv, 0, "Failed to delete all flows")
649
650 logging.info("Send Port_Stats Request")
651 logging.info("Verify reply has Collisions 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 collisions = counter[11]
657 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400658
659
660
661
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400662class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400663
664 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
665
666 def runTest(self):
667
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400668 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400669
670 of_ports = config["port_map"].keys()
671 of_ports.sort()
672 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
673
674 #Clear switch State
675 rv = delete_all_flows(self.controller)
676 self.assertEqual(rv, 0, "Failed to delete all flows")
677
678 logging.info("Send Queue_Stats Request")
679 logging.info("Verify reply has Tramitted Overrun errors count ")
680
681 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400682 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400683
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400684 tx_err = counter[12]
685 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400686
ShreyaPandita66de26f2012-10-26 14:44:24 -0400687
688