blob: 7e6f36b19c4535927341e56f1c658db8fcb90a32 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
ShreyaPandita66de26f2012-10-26 14:44:24 -040017"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
18 Refer Documentation -- Detailed testing methodology
19 <Some of test-cases are directly taken from oftest> """
20
21"Test Suite 5 --> Counters"
22
23import logging
24
25import unittest
26import random
27
28from oftest import config
29import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080030import ofp
ShreyaPandita66de26f2012-10-26 14:44:24 -040031import oftest.dataplane as dataplane
ShreyaPandita66de26f2012-10-26 14:44:24 -040032import oftest.parse as parse
33import oftest.base_tests as base_tests
34import time
35
36from oftest.testutils import *
37from time import sleep
38from FuncUtils import*
39
40
ShreyaPanditae807dfb2012-11-02 19:01:19 -040041def port_queues_get(self, queue_stats, port_num):
ShreyaPandita66de26f2012-10-26 14:44:24 -040042 result = []
Rich Lane5fd6faf2013-03-11 13:30:20 -070043 for qs in queue_stats.entries:
ShreyaPandita66de26f2012-10-26 14:44:24 -040044 if qs.port_no != port_num:
45 continue
46 result.append(qs.queue_id)
47 return result
48
49
ShreyaPanditae807dfb2012-11-02 19:01:19 -040050class PktPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -040051
ShreyaPanditae807dfb2012-11-02 19:01:19 -040052 """Verify Packet counters per flow are
53 incremented by no. of packets received for that flow"""
ShreyaPandita66de26f2012-10-26 14:44:24 -040054
55 def runTest(self):
56
ShreyaPanditae807dfb2012-11-02 19:01:19 -040057 logging.info("Running PktPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -040058
59 of_ports = config["port_map"].keys()
60 of_ports.sort()
61 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
62
63 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080064 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -040065
66 logging.info("Insert any flow")
67 logging.info("Sending N Packets matching the flow")
ShreyaPanditae807dfb2012-11-02 19:01:19 -040068 logging.info("Verify packet counters increment in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -040069
70 #Create a Match on Ingress flow
ShreyaPanditae807dfb2012-11-02 19:01:19 -040071 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
72
73 #Send Packets matching the flow
74 num_pkts = 5
75 for pkt_cnt in range(num_pkts):
76 self.dataplane.send(of_ports[0],str(pkt))
Rich Laneae3428c2013-03-07 14:37:42 -080077
78 # Verify the packet counter was updated
79 verify_flow_stats(self, match, pkts=num_pkts)
ShreyaPanditae807dfb2012-11-02 19:01:19 -040080
81
82class BytPerFlow(base_tests.SimpleDataPlane):
83
84 """Verify Byte counters per flow are
85 incremented by no. of bytes received for that flow"""
86
87 def runTest(self):
88
89 logging.info("Running BytPerFlow test")
90
91 of_ports = config["port_map"].keys()
92 of_ports.sort()
93 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
94
95 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080096 delete_all_flows(self.controller)
ShreyaPanditae807dfb2012-11-02 19:01:19 -040097
98 logging.info("Insert any flow")
99 logging.info("Sending N Packets matching the flow")
100 logging.info("Verify byte counters increment in accordance")
101
102 #Create a Match on Ingress flow
103 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400104
105 #Send Packets matching the flow
106 num_pkts = 5
107 byte_count = num_pkts*len(str(pkt))
108 for pkt_cnt in range(num_pkts):
109 self.dataplane.send(of_ports[0],str(pkt))
Rich Laneae3428c2013-03-07 14:37:42 -0800110
111 # Verify the byte counter was updated
112 verify_flow_stats(self, match, bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400113
114
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400115class DurationPerFlow(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400116
117 """Verify Duration_sec and Duration_nsec counters per flow varies in accordance with the amount of
118 time the flow was alive"""
119
120 def runTest(self):
121
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400122 logging.info("Running DurationPerFlow test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400123
124 of_ports = config["port_map"].keys()
125 of_ports.sort()
126 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
127
128 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800129 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400130
131 logging.info("Insert any flow")
132 logging.info("Send Flow_stats request after n sec intervals")
133 logging.info("Verify duration_sec and nsec counters are incrementing in accordance with the life of flow")
134
135 #Create a flow with match on ingress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400136 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
137
ShreyaPandita66de26f2012-10-26 14:44:24 -0400138 #Create flow_stats request
Rich Lane28fa9272013-03-08 16:00:25 -0800139 stat_req = ofp.message.flow_stats_request()
ShreyaPandita66de26f2012-10-26 14:44:24 -0400140 stat_req.match= match
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400141 stat_req.table_id = 0xff
142 stat_req.out_port = ofp.OFPP_NONE
Rich Lane0b04b6c2012-12-31 10:12:23 -0800143
144 expected_duration = 3
145 sleep(expected_duration)
146
147 response, pkt = self.controller.transact(stat_req)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400148
Rich Lane0b04b6c2012-12-31 10:12:23 -0800149 self.assertTrue(response is not None,"No response to stats request")
Rich Lane5fd6faf2013-03-11 13:30:20 -0700150 self.assertTrue(len(response.entries) == 1,"Did not receive flow stats reply")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400151
Rich Lane5fd6faf2013-03-11 13:30:20 -0700152 stat = response.entries[0]
Rich Lane0b04b6c2012-12-31 10:12:23 -0800153 logging.info("Duration of flow is %d s %d ns", stat.duration_sec, stat.duration_nsec)
154 self.assertTrue(stat.duration_sec == expected_duration, "Flow stats reply incorrect")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400155
156
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400157class RxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400158
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400159 """Verify that rx_packets counter in the Port_Stats reply
160 increments when packets are received on a port"""
ShreyaPandita66de26f2012-10-26 14:44:24 -0400161
162 def runTest(self):
163
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400164 logging.info("Running RxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400165
166 of_ports = config["port_map"].keys()
167 of_ports.sort()
168 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
169
170 # Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800171 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400172
173 logging.info("Insert a flow with match on ingress_port")
174 logging.info("Send N Packets on an ingress_port P ")
175 logging.info("Send Port_Stats Request for Port P , verify recieved packets counters are incrementing in accordance")
176
177 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400178 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400179
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400180 # Send Port_Stats request for the ingress port (retrieve old counter state)
Rich Lane968b6192013-03-07 15:34:43 -0800181 initial_stats = get_port_stats(self, of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400182
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400183 # Send packets matching the flow
184 num_pkts = 5
ShreyaPandita66de26f2012-10-26 14:44:24 -0400185 for pkt_cnt in range(num_pkts):
186 self.dataplane.send(of_ports[0],str(pkt))
Rich Lane47d0ec02012-10-26 14:28:19 -0700187
ShreyaPandita66de26f2012-10-26 14:44:24 -0400188 #Verify recieved packet counters
Rich Lane968b6192013-03-07 15:34:43 -0800189 verify_port_stats(self, of_ports[0], initial=initial_stats, rx_pkts=num_pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400190
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400191class TxPktPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400192
193 """Verify that tx_packets counter in the Port_Stats reply , increments when packets are transmitted by a port"""
194
195 def runTest(self):
196
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400197 logging.info("Running TxPktPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400198
199 of_ports = config["port_map"].keys()
200 of_ports.sort()
201 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
202
203 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800204 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400205
ShreyaPandita66de26f2012-10-26 14:44:24 -0400206 logging.info("Insert any flow matching on in_port=ingress_port, action output to egress_port T ")
207 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500208 logging.info("Send Port_Stats Request for Port T , verify transmitted packets counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400209
210 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400211 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400212
Rich Lane968b6192013-03-07 15:34:43 -0800213 # Send Port_Stats request for the egress port (retrieve old counter state)
214 initial_stats = get_port_stats(self, of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400215
216 #Send packets matching the flow
217 num_pkts = 5
218 for pkt_cnt in range(num_pkts):
219 self.dataplane.send(of_ports[0],str(pkt))
220
221 #Verify transmitted_packet counters
Rich Lane968b6192013-03-07 15:34:43 -0800222 verify_port_stats(self, of_ports[1], initial=initial_stats,
223 tx_pkts=num_pkts)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400224
225
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400226
227class RxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400228
229 """Verify that recieved bytes counter in the Port_Stats reply , increments in accordance with the bytes recieved on a port"""
230
231 def runTest(self):
232
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400233 logging.info("Running RxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400234
235 of_ports = config["port_map"].keys()
236 of_ports.sort()
237 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
238
239 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800240 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400241
242 logging.info("Insert any flow matching on in_port=ingress_port")
243 logging.info("Send N Packets matching the flow on ingress_port P ")
244 logging.info("Send Port_Stats Request for Port P , verify recieved bytes counters are incrementing in accordance")
245
246 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400247 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400248
249 # Send Port_Stats request for the ingress port (retrieve current counter state)
Rich Lane968b6192013-03-07 15:34:43 -0800250 initial_stats = get_port_stats(self, of_ports[0])
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400251
ShreyaPandita66de26f2012-10-26 14:44:24 -0400252 #Send packets matching the flow.
253 num_pkts = 5
254 byte_count = num_pkts*len(str(pkt))
255 for pkt_cnt in range(num_pkts):
256 self.dataplane.send(of_ports[0],str(pkt))
257
ShreyaPandita66de26f2012-10-26 14:44:24 -0400258 #Verify recieved_bytes counters
Rich Lane968b6192013-03-07 15:34:43 -0800259 verify_port_stats(self, of_ports[0], initial=initial_stats,
260 rx_bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400261
262
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400263class TxBytPerPort(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400264
265 """Verify that trasnsmitted bytes counter in the Port_Stats reply , increments in accordance with the bytes trasmitted by a port"""
266
267 def runTest(self):
268
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400269 logging.info("Running TxBytPerPort test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400270
271 of_ports = config["port_map"].keys()
272 of_ports.sort()
273 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
274
275 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800276 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400277
ShreyaPanditaed209962012-11-04 02:16:48 -0500278 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400279 logging.info("Send N Packets matching the flow on ingress_port P ")
ShreyaPanditaed209962012-11-04 02:16:48 -0500280 logging.info("Send Port_Stats Request for Port T , verify trasmitted bytes counters are incrementing in accordance")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400281
282 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400283 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400284
Rich Lane968b6192013-03-07 15:34:43 -0800285 # Send Port_Stats request for the egress port (retrieve current counter state)
286 initial_stats = get_port_stats(self, of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400287
288 #Send packets matching the flow.
289 num_pkts = 5
290 byte_count = num_pkts*len(str(pkt))
291 for pkt_cnt in range(num_pkts):
292 self.dataplane.send(of_ports[0],str(pkt))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400293
294 #Verify trasmitted_bytes counters
Rich Lane968b6192013-03-07 15:34:43 -0800295 verify_port_stats(self, of_ports[1], initial=initial_stats,
296 tx_bytes=byte_count)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400297
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400298class ActiveCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400299
300 """Verify that active_count counter in the Table_Stats reply , increments in accordance with the flows inserted in a table"""
301
302 def runTest(self):
303
304 logging.info("Running Table_Counter_1 test")
305
306 of_ports = config["port_map"].keys()
307 of_ports.sort()
308 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
309
310 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800311 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400312
ShreyaPanditaed209962012-11-04 02:16:48 -0500313 logging.info("Insert any flow matching on in_port=ingress_port,action = output to egress_port T ")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400314 logging.info("Send Table_Stats, verify active_count counter is incremented in accordance")
315
316 #Insert a flow with match on all ingress port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400317 (pkt, match ) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400318
319 #Generate Table_Stats
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400320 verify_tablestats(self,expect_active=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400321
322
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400323class LookupMatchedCount(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400324
325 """Verify that lookup_count and matched_count counter in the Table_Stats reply
326 increments in accordance with the packets looked up and matched with the flows in the table"""
327
328 def runTest(self):
329
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400330 logging.info("Running LookupMatchedCount test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400331
332 of_ports = config["port_map"].keys()
333 of_ports.sort()
334 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
335
336 #Clear Switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800337 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400338
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
Rich Lane32bf9482013-01-03 17:26:30 -0800388 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400389
390 # Get Queue stats for selected egress queue only
Rich Lane6a334922013-03-07 16:14:52 -0800391 initial_stats = get_queue_stats(self, egress_port, egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400392
393 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400394 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400395
396 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400397 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400398
Rich Lane6a334922013-03-07 16:14:52 -0800399 verify_queue_stats(self, egress_port, egress_queue_id,
400 initial=initial_stats, pkts=1)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400401
402
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400403class TxBytPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400404
405 """Verify that tx_bytes in the queue_stats reply increments in accordance with the number of transmitted bytes"""
406
407 def runTest(self):
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400408 logging.info("Running TxBytPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400409
410 of_ports = config["port_map"].keys()
411 of_ports.sort()
412 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
413
414 # Get queue stats from switch (retrieve current state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400415 (queue_stats,p) = get_queuestats(self,ofp.OFPP_ALL,ofp.OFPQ_ALL)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400416
417 for idx in range(len(of_ports)):
418 ingress_port = of_ports[idx]
419 egress_port = of_ports[(idx + 1) % len(of_ports)]
420
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400421 queue_id = port_queues_get(self,queue_stats,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400422
423 for egress_queue_id in queue_id:
424
425 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800426 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400427
428 # Get Queue stats for selected egress queue only
Rich Lane6a334922013-03-07 16:14:52 -0800429 initial_stats = get_queue_stats(self, egress_port, egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400430
431 #Insert a flow with enqueue action to queues configured on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400432 (pkt,match) = enqueue(self,ingress_port,egress_port,egress_queue_id)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400433
434 #Send packet on the ingress_port and verify its received on egress_port
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400435 send_packet(self,pkt,ingress_port,egress_port)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400436
Rich Lane6a334922013-03-07 16:14:52 -0800437 verify_queue_stats(self, egress_port, egress_queue_id,
438 initial=initial_stats,
439 bytes=len(str(pkt)))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400440
ShreyaPanditaed209962012-11-04 02:16:48 -0500441
ShreyaPandita66de26f2012-10-26 14:44:24 -0400442class RxDrops(base_tests.SimpleDataPlane):
443
444 """Verify that rx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by RX"""
445
446 def runTest(self):
447
448 logging.info("Running Rx_Drops test")
449
450 of_ports = config["port_map"].keys()
451 of_ports.sort()
452 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
453
454 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800455 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400456
457 logging.info("Send Port_Stats Request")
458 logging.info("Verify reply has rx_dropped count ")
459
460 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400461 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400462
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400463 rx_drp = counter[4]
464 logging.info("recieved dropped count is :" + str(rx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400465
466
467
468class TxDrops(base_tests.SimpleDataPlane):
469
470 """Verify that tx_dropped counters in the Port_Stats reply increments in accordance with the packets dropped by TX"""
471
472 def runTest(self):
473
474 logging.info("Running Tx_Drops test")
475
476 of_ports = config["port_map"].keys()
477 of_ports.sort()
478 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
479
480 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800481 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400482
483 logging.info("Send Port_Stats Request")
484 logging.info("Verify reply has tx_dropped count ")
485
486 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400487 (counter) = get_portstats(self,of_ports[1])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400488
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400489 tx_drp = counter[5]
490 logging.info("Transmitted dropped count is :" + str(tx_drp))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400491
492
493class RxErrors(base_tests.SimpleDataPlane):
494
495 """Verify that rx_errors counters in the Port_Stats reply increments in accordance with number of recieved error
496 This is a super-set of more specific receive errors and should be greater than or equal to the sum of all
497 rx_*_err values"""
498
499 def runTest(self):
500
501 logging.info("Running Rx_Errors test")
502
503 of_ports = config["port_map"].keys()
504 of_ports.sort()
505 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
506
507 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800508 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400509
510 logging.info("Send Port_Stats Request")
511 logging.info("Verify reply has rx_errors count ")
512
513 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400514 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400515
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400516 rx_err = counter[6]
517 logging.info("Recieve Errors count is :" + str(rx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400518
519
520class TxErrors(base_tests.SimpleDataPlane):
521
522 """Verify that Tx_errors counters in the Port_Stats reply increments in accordance with number of trasmit error"""
523
524 def runTest(self):
525
526 logging.info("Running Tx_Errors test")
527
528 of_ports = config["port_map"].keys()
529 of_ports.sort()
530 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
531
532 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800533 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400534
535 logging.info("Send Port_Stats Request")
536 logging.info("Verify reply has Tx_errors count ")
537
538 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400539 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400540
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400541 tx_err = counter[7]
542 logging.info("Trasmit Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400543
544
545class RxFrameErr(base_tests.SimpleDataPlane):
546
547 """Verify that rx_frm_err counters in the Port_Stats reply increments in accordance with the number of frame alignment errors"""
548
549 def runTest(self):
550
551 logging.info("Running Rx_Frame_Err test")
552
553 of_ports = config["port_map"].keys()
554 of_ports.sort()
555 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
556
557 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800558 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400559
560 logging.info("Send Port_Stats Request")
561 logging.info("Verify reply has rx_frame_err count ")
562
563 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400564 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400565
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400566 rx_fr_err = counter[8]
567 logging.info("Recieve Frame Errors count is :" + str(rx_fr_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400568
569
570
571class RxOErr(base_tests.SimpleDataPlane):
572
573 """Verify that rx_over_err counters in the Port_Stats reply increments in accordance with the number of with RX overrun"""
574
575 def runTest(self):
576
577 logging.info("Running Rx_O_Err test")
578
579 of_ports = config["port_map"].keys()
580 of_ports.sort()
581 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
582
583 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800584 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400585
586 logging.info("Send Port_Stats Request")
587 logging.info("Verify reply has rx_over_err count ")
588
589 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400590 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400591
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400592 rx_over_err = counter[9]
593 logging.info("Recieve Overrun Errors count is :" + str(rx_over_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400594
595
596
597
598class RxCrcErr(base_tests.SimpleDataPlane):
599
600 """Verify that rx_crc_err counters in the Port_Stats reply increments in accordance with the number of crc errors"""
601
602 def runTest(self):
603
604 logging.info("Running Port_Counter_9 test")
605
606 of_ports = config["port_map"].keys()
607 of_ports.sort()
608 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
609
610 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800611 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400612
613 logging.info("Send Port_Stats Request")
614 logging.info("Verify reply has rx_crc_err count ")
615
616 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400617 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400618
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400619 rx_crc_err = counter[10]
620 logging.info("Recieve CRC Errors count is :" + str(rx_crc_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400621
622
623
624class Collisions(base_tests.SimpleDataPlane):
625
626 """Verify that collisons counters in the Port_Stats reply increments in accordance with the collisions encountered by the switch """
627
628 def runTest(self):
629
630 logging.info("Running Collisions test")
631
632 of_ports = config["port_map"].keys()
633 of_ports.sort()
634 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
635
636 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800637 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400638
639 logging.info("Send Port_Stats Request")
640 logging.info("Verify reply has Collisions count ")
641
642 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400643 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400644
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400645 collisions = counter[11]
646 logging.info("collisions count is :" + str(collisions))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400647
648
649
650
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400651class TxErrorPerQueue(base_tests.SimpleDataPlane):
ShreyaPandita66de26f2012-10-26 14:44:24 -0400652
653 """Verify that tx_errors in the queue_stats reply increments in accordance with the number of packets dropped due to overrun """
654
655 def runTest(self):
656
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400657 logging.info("Running TxErrorPerQueue test")
ShreyaPandita66de26f2012-10-26 14:44:24 -0400658
659 of_ports = config["port_map"].keys()
660 of_ports.sort()
661 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
662
663 #Clear switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800664 delete_all_flows(self.controller)
ShreyaPandita66de26f2012-10-26 14:44:24 -0400665
666 logging.info("Send Queue_Stats Request")
667 logging.info("Verify reply has Tramitted Overrun errors count ")
668
669 # Send Port_Stats request for the ingress port (retrieve current counter state)
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400670 (counter) = get_portstats(self,of_ports[0])
ShreyaPandita66de26f2012-10-26 14:44:24 -0400671
ShreyaPanditae807dfb2012-11-02 19:01:19 -0400672 tx_err = counter[12]
673 logging.info("Transmit Overrun Error count is :" + str(tx_err))
ShreyaPandita66de26f2012-10-26 14:44:24 -0400674
ShreyaPandita66de26f2012-10-26 14:44:24 -0400675
676