blob: df060b476265a909c70f7d2b1bc746687e735ca2 [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
ShreyaPandita9306c772012-09-28 12:21:40 -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 3 --> Detailed Controller to switch messages"
22
23import logging
24
25import unittest
26import random
27
Rich Lane477f4812012-10-04 22:49:00 -070028from oftest import config
ShreyaPandita9306c772012-09-28 12:21:40 -040029import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080030import ofp
ShreyaPandita9306c772012-09-28 12:21:40 -040031import oftest.dataplane as dataplane
ShreyaPandita9306c772012-09-28 12:21:40 -040032import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070033import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040034
Rich Laneda3b5ad2012-10-03 09:05:32 -070035from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040036from time import sleep
37from FuncUtils import *
38
Rich Laneb90a1c42012-10-05 09:16:05 -070039class OverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040040
41 """Verify that if overlap check flag is set in the flow entry and an overlapping flow is inserted then an error
42 is generated and switch refuses flow entry"""
43
44 def runTest(self):
45
Rich Lane9a003812012-10-04 17:17:59 -070046 logging.info("Running Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040047
Rich Lane477f4812012-10-04 22:49:00 -070048 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040049 of_ports.sort()
50 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
51
52 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080053 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040054
Rich Lane9a003812012-10-04 17:17:59 -070055 logging.info("Inserting two overlapping flows")
56 logging.info("Expecting switch to return an error")
ShreyaPandita9306c772012-09-28 12:21:40 -040057
58 #Insert a flow F with wildcarded all fields
ShreyaPandita8dab4662012-11-02 13:40:14 -040059 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -040060
61 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -040062 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040063
64 # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set
ShreyaPandita8dab4662012-11-02 13:40:14 -040065 pkt_matchingress = simple_tcp_packet()
66 match3 = parse.packet_to_flow_match(pkt_matchingress)
ShreyaPandita9306c772012-09-28 12:21:40 -040067 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
68 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
69 match3.in_port = of_ports[0]
70
Rich Laneba3f0e22013-03-11 16:43:57 -070071 msg3 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -040072 msg3.match = match3
73 msg3.flags |= ofp.OFPFF_CHECK_OVERLAP
74 msg3.cookie = random.randint(0,9007199254740992)
75 msg3.buffer_id = 0xffffffff
76
Rich Lane9d3cc6b2013-03-08 16:33:08 -080077 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -040078 act3.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -080079 msg3.actions.append(act3)
Rich Lane5c3151c2013-01-03 17:15:41 -080080 self.controller.message_send(msg3)
Rich Lane3a261d52013-01-03 17:45:08 -080081 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040082
83 # Verify Flow does not get inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -040084 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040085
86 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
87 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
88 timeout=5)
89 self.assertTrue(response is not None,
90 'Switch did not reply with error message')
Rich Lane4e361bb2013-03-11 13:57:31 -070091 self.assertTrue(response.err_type==ofp.OFPET_FLOW_MOD_FAILED,
ShreyaPandita9306c772012-09-28 12:21:40 -040092 'Error message type is not flow mod failed ')
93 self.assertTrue(response.code==ofp.OFPFMFC_OVERLAP,
94 'Error Message code is not overlap')
95
96
Rich Laneb90a1c42012-10-05 09:16:05 -070097class NoOverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040098
99 """Verify that without overlap check flag set, overlapping flows can be created."""
100
101 def runTest(self):
102
Rich Lane9a003812012-10-04 17:17:59 -0700103 logging.info("Running No_Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400104
Rich Lane477f4812012-10-04 22:49:00 -0700105 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400106 of_ports.sort()
107 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
108
109 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800110 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400111
Rich Lane9a003812012-10-04 17:17:59 -0700112 logging.info("Inserting two overlapping flows")
113 logging.info("Expecting switch to insert the flows without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400114
115 #Build a flow F with wildcarded all fields.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400116 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400117
118 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400119 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400120
121 # Build a overlapping flow F' without check overlap bit set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400122 wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400123
124 # Verify Flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400125 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400126
127
Rich Laneb90a1c42012-10-05 09:16:05 -0700128class IdenticalFlows(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400129
130 """Verify that adding two identical flows overwrites the existing one and clears counters"""
131
132 def runTest(self):
133
Rich Lane9a003812012-10-04 17:17:59 -0700134 logging.info("Running Identical_Flows test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400135
Rich Lane477f4812012-10-04 22:49:00 -0700136 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400137 of_ports.sort()
138 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
139
140 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800141 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400142
Rich Lane9a003812012-10-04 17:17:59 -0700143 logging.info("Inserting two identical flows one by one")
144 logging.info("Expecting switch to overwrite the first flow and clear the counters associated with it ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400145
146 # Create and add flow-1, check on dataplane it is active.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400147 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400148
149 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400150 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400151
152 # Send Packet (to increment counters like byte_count and packet_count)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400153 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400154
155 # Verify Flow counters have incremented
Rich Laneae3428c2013-03-07 14:37:42 -0800156 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400157
158 #Send Identical flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400159 (pkt1,match1) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400160
161 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400162 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400163
164 # Verify Flow counters reset
Rich Laneae3428c2013-03-07 14:37:42 -0800165 verify_flow_stats(self, match, pkts=0, bytes=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400166
167
Rich Laneb90a1c42012-10-05 09:16:05 -0700168class EmerFlowTimeout(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400169
170 """Timeout values are not allowed for emergency flows"""
171
172 def runTest(self):
173
Rich Lane9a003812012-10-04 17:17:59 -0700174 logging.info("Running Emergency_Flow_Timeout test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400175
Rich Lane477f4812012-10-04 22:49:00 -0700176 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400177 of_ports.sort()
178 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
179
180 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800181 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400182
Rich Lane9a003812012-10-04 17:17:59 -0700183 logging.info("Inserting an emergency flow with timeout values")
184 logging.info("Expecting switch to generate error ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400185
186 #Insert an emergency flow
187 pkt = simple_tcp_packet()
188 match = parse.packet_to_flow_match(pkt)
189 match.in_port = of_ports[0]
190
Rich Laneba3f0e22013-03-11 16:43:57 -0700191 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400192 request.match = match
ShreyaPandita9306c772012-09-28 12:21:40 -0400193 request.flags = request.flags|ofp.OFPFF_EMERG
194 request.hard_timeout =9
195 request.idle_timeout =9
196
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800197 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400198 act.port = of_ports[1]
199
Rich Lanec495d9e2013-03-08 17:43:36 -0800200 request.actions.append(act)
Rich Lane9a003812012-10-04 17:17:59 -0700201 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800202 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400203
Rich Lane3a261d52013-01-03 17:45:08 -0800204 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400205
206 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
207 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
208 timeout=5)
209 self.assertTrue(response is not None,
210 'Switch did not reply with error message')
Rich Lane4e361bb2013-03-11 13:57:31 -0700211 self.assertTrue(response.err_type==ofp.OFPET_FLOW_MOD_FAILED,
ShreyaPandita9306c772012-09-28 12:21:40 -0400212 'Error message type is not flow mod failed ')
213 self.assertTrue(response.code==ofp.OFPFMFC_BAD_EMERG_TIMEOUT,
214 'Error Message code is not bad emergency timeout')
215
216
Rich Laneb90a1c42012-10-05 09:16:05 -0700217class MissingModifyAdd(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400218
219 """If a modify does not match an existing flow, the flow gets added """
220
221 def runTest(self):
222
Rich Lane9a003812012-10-04 17:17:59 -0700223 logging.info("Running Missing_Modify_Add test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400224
Rich Lane477f4812012-10-04 22:49:00 -0700225 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400226 of_ports.sort()
227 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
228
Rich Lane9a003812012-10-04 17:17:59 -0700229 logging.info("Inserting a flow-modify that does not match an existing flow")
230 logging.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400231
232 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800233 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400234
235 #Generate a flow-mod,command OFPC_MODIFY
236
Rich Laneba3f0e22013-03-11 16:43:57 -0700237 request = ofp.message.flow_modify()
ShreyaPandita9306c772012-09-28 12:21:40 -0400238 request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
239 request.match.in_port = of_ports[0]
240 request.cookie = random.randint(0,9007199254740992)
241 request.buffer_id = 0xffffffff
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800242 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400243 act3.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -0800244 request.actions.append(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400245
Rich Lane9a003812012-10-04 17:17:59 -0700246 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800247 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800248 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400249
250 #Verify the flow gets added i.e. active_count= 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400251 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400252
253
Rich Laneb90a1c42012-10-05 09:16:05 -0700254class ModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400255
256 """A modified flow preserves counters"""
257
258 def runTest(self):
259
Rich Lane9a003812012-10-04 17:17:59 -0700260 logging.info("Running Modify_Action test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400261
Rich Lane477f4812012-10-04 22:49:00 -0700262 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400263 of_ports.sort()
264 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
265
266 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800267 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400268
Rich Lane9a003812012-10-04 17:17:59 -0700269 logging.info("Inserting a Flow and incrementing flow counters. Modifying the flow action")
270 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400271
272 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A , output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400273 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400274
275 #Send Packet matching the flow thus incrementing counters like packet_count,byte_count
ShreyaPandita8dab4662012-11-02 13:40:14 -0400276 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400277
278 #Verify flow counters
Rich Laneae3428c2013-03-07 14:37:42 -0800279 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400280
281 #Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400282 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400283
284 # Send Packet matching the flow-1 i.e ingress_port=port[0] and verify it is recieved on corret dataplane port i.e port[2]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400285 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400286
287 #Verify flow counters are preserved
Rich Laneae3428c2013-03-07 14:37:42 -0800288 verify_flow_stats(self, match, pkts=2, bytes=len(str(pkt))*2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400289
290
Rich Laneb90a1c42012-10-05 09:16:05 -0700291class StrictModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400292
293 """Strict Modify Flow also changes action preserves counters"""
294
295 def runTest(self):
296
Rich Lane9a003812012-10-04 17:17:59 -0700297 logging.info("Running Strict_Modify_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400298
Rich Lane477f4812012-10-04 22:49:00 -0700299 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400300 of_ports.sort()
301 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
302
303 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800304 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400305
Rich Lane9a003812012-10-04 17:17:59 -0700306 logging.info("Inserting Flows and incrementing flow counters. Strict Modify the flow action ")
307 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400308
309 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400310 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400311
312 #Create and add flow-2 , Match on ingress_port only, Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400313 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=10)
ShreyaPandita9306c772012-09-28 12:21:40 -0400314
315 # Verify both the flows are active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400316 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400317
318 #Send a packet matching the flows, thus incrementing flow-counters (packet matches the flow F-1 with higher priority)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400319 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400320
321 # Verify flow counters of the flow-1
Rich Laneae3428c2013-03-07 14:37:42 -0800322 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400323
324 # Strict-Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400325 strict_modify_flow_action(self,of_ports[2],match,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400326
327 # Send Packet matching the flow-1 i.e ingress_port=port[0] and verify it is recieved on corret dataplane port i.e port[2]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400328 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400329
330 # Verify flow counters are preserved
Rich Laneae3428c2013-03-07 14:37:42 -0800331 verify_flow_stats(self, match, pkts=2, bytes=2*len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400332
333
Rich Laneb90a1c42012-10-05 09:16:05 -0700334class DeleteNonexistingFlow(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400335
336 """Request deletion of non-existing flow"""
337
338 def runTest(self):
339
Rich Lane9a003812012-10-04 17:17:59 -0700340 logging.info("Delete_NonExisting_Flow test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400341
Rich Lane477f4812012-10-04 22:49:00 -0700342 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400343 of_ports.sort()
344 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
345
346 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800347 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400348
Rich Lane9a003812012-10-04 17:17:59 -0700349 logging.info("Deleting a non-existing flow")
350 logging.info("Expecting switch to ignore the command , without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400351
352 # Issue a delete command
Rich Laneba3f0e22013-03-11 16:43:57 -0700353 msg = ofp.message.flow_delete()
ShreyaPandita9306c772012-09-28 12:21:40 -0400354 msg.match.wildcards = ofp.OFPFW_ALL
355 msg.out_port = ofp.OFPP_NONE
ShreyaPandita9306c772012-09-28 12:21:40 -0400356 msg.buffer_id = 0xffffffff
357
358 # Verify no message or error is generated by polling the the control plane
359 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
360 timeout=2)
361 self.assertTrue(response is None,
362 'Recieved Error for deleting non-exiting flow ')
363
364
365
Rich Laneb90a1c42012-10-05 09:16:05 -0700366class SendFlowRem(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400367
368 """Check deletion of flows happens and generates messages as configured.
369 If Send Flow removed message Flag is set in the flow entry, the flow deletion of that respective flow should generate the flow removed message,
370 vice versa also exists """
371
372 def runTest(self):
373
Rich Lane9a003812012-10-04 17:17:59 -0700374 logging.info("Running Send_Flow_Rem test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400375
Rich Lane477f4812012-10-04 22:49:00 -0700376 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400377 of_ports.sort()
378 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
379
380 #Clear swicth state
Rich Lane32bf9482013-01-03 17:26:30 -0800381 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400382
Rich Lane9a003812012-10-04 17:17:59 -0700383 logging.info("Inserting flows F1 and F2 without and with send_flow_removed_message flag set ")
384 logging.info("Deleting the flows")
385 logging.info("Expecting flow removed message only for F2")
ShreyaPandita9306c772012-09-28 12:21:40 -0400386
387 # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400388 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400389
390 # Verify flow is inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400391 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400392
393 #Delete the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400394 nonstrict_delete(self,match,priority=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400395
396 # Verify no flow removed message is generated for the FLOW-1
397
398 (response1, pkt1) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
399 timeout=2)
400 self.assertTrue(response1 is None,
401 'Received flow removed message for the flow with flow_rem flag not set')
402
403 # Insert another flow F' with OFPFF_SEND_FLOW_REM flag set.
Rich Laneba3f0e22013-03-11 16:43:57 -0700404 msg9 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400405 msg9.match.wildcards = ofp.OFPFW_ALL
406 msg9.cookie = random.randint(0,9007199254740992)
407 msg9.buffer_id = 0xffffffff
408 msg9.idle_timeout = 1
409 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
410 rv1 = self.controller.message_send(msg9)
411 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800412 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400413
414 # Delete the flow-2
Rich Lane32bf9482013-01-03 17:26:30 -0800415 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400416
417 # Verify flow removed message is generated for the FLOW-2
418
419 (response2, pkt2) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
420 timeout=2)
421 self.assertTrue(response2 is not None,
422 'Did not receive flow removed message for this flow')
423
424
Rich Laneb90a1c42012-10-05 09:16:05 -0700425class DeleteEmerFlow(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400426
427 """Delete emergency flow and verify no message is generated.An emergency flow deletion will not generate flow-removed messages even if
428 Send Flow removed message flag was set during the emergency flow entry"""
429
430 def runTest(self):
431
Rich Lane9a003812012-10-04 17:17:59 -0700432 logging.info("Running Delete_Emer_Flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400433
Rich Lane477f4812012-10-04 22:49:00 -0700434 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400435 of_ports.sort()
436
437 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800438 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400439
Rich Lane9a003812012-10-04 17:17:59 -0700440 logging.info("Inserting a emergency flow with send_flow_removed flag set")
441 logging.info("Expecting no flow_removed_message on the deletion of the emergency flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400442
443 # Insert a flow with emergency bit set.
444 pkt = simple_tcp_packet()
445 match = parse.packet_to_flow_match(pkt)
446 match.in_port = of_ports[0]
Rich Laneba3f0e22013-03-11 16:43:57 -0700447 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400448 request.match = match
ShreyaPandita9306c772012-09-28 12:21:40 -0400449 request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800450 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400451 act.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -0800452 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400453
Rich Lane5c3151c2013-01-03 17:15:41 -0800454 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400455
456 # Delete the emergency flow
457
ShreyaPandita8dab4662012-11-02 13:40:14 -0400458 nonstrict_delete(self,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400459 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM ,
460 timeout=2)
461 self.assertTrue(response is None,
462 'Test Failed ')
463
464
Rich Laneb90a1c42012-10-05 09:16:05 -0700465class StrictVsNonstrict(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400466
467 """Delete and verify strict and non-strict behaviors
468 This test compares the behavior of delete strict and non-strict"""
469
470 def runTest(self):
471
Rich Lane9a003812012-10-04 17:17:59 -0700472 logging.info("Strict_Vs_Nonstrict test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400473
Rich Lane477f4812012-10-04 22:49:00 -0700474 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400475 of_ports.sort()
476 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
477
478 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800479 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400480
Rich Lane9a003812012-10-04 17:17:59 -0700481 logging.info("Inserting a flow with exact match")
482 logging.info("Issue Strict Delete command , verify it gets deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400483
484 #Insert F with an exact Match
ShreyaPandita8dab4662012-11-02 13:40:14 -0400485 (pkt,match) = exact_match(self,of_ports)
486 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400487
488 #Issue Strict Delete Command , verify F gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400489 strict_delete(self,match)
490 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400491
Rich Lane9a003812012-10-04 17:17:59 -0700492 logging.info("Inserting two overlapping flows")
493 logging.info("Issue Strict Delete command ")
494 logging.info("Expecting only one flow gets deleted , because Strict Delete matches on wildcards as well")
ShreyaPandita9306c772012-09-28 12:21:40 -0400495
496 #Insert Flow T with match on all , except one wildcarded ( say src adddress ).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400497 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400498
499 #Insert another flow T' with match on ingress_port , wildcarded rest.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400500 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
501 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400502
503 #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400504 strict_delete(self,match1)
505 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400506
Rich Lane9a003812012-10-04 17:17:59 -0700507 logging.info("Inserting two overlapping flows")
508 logging.info("Issue Non-Strict Delete command ")
509 logging.info("Expecting both the flow gets deleted , because wildcards are active")
ShreyaPandita9306c772012-09-28 12:21:40 -0400510
511 #Insert T and T' again .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400512 (pkt,match) = match_all_except_source_address(self,of_ports)
513 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
514 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400515
516 #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400517 nonstrict_delete(self,match1)
518 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400519
Rich Lane9a003812012-10-04 17:17:59 -0700520 logging.info("Inserting three overlapping flows with different priorities")
521 logging.info("Issue Non-Strict Delete command ")
522 logging.info("Expecting all the flows to get deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400523
524 #Insert T , add Priority P (say 100 )
ShreyaPandita8dab4662012-11-02 13:40:14 -0400525 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400526
527 #Insert T' add priority (200).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400528 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
ShreyaPandita9306c772012-09-28 12:21:40 -0400529
530 #Insert T' again add priority 300 --> T" .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400531 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
532 verify_tablestats(self,expect_active=3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400533
534 #Issue Non-Strict Delete and verify all getting deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400535 nonstrict_delete(self,match1,priority=200)
536 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400537
Rich Lane9a003812012-10-04 17:17:59 -0700538 logging.info("Inserting three overlapping flows with different priorities")
539 logging.info("Issue Strict Delete command ")
540 logging.info("Expecting only one to get deleted because here priorities & wildcards are being matched")
ShreyaPandita9306c772012-09-28 12:21:40 -0400541
542 #Issue Strict-Delete and verify only T'' gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400543 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
544 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
545 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
546 strict_delete(self,match1,priority=200)
547 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400548
549
550
Rich Laneb90a1c42012-10-05 09:16:05 -0700551class Outport1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400552
553 """Delete flows filtered by action outport.If the out_port field in the delete command contains a value other than OFPP_NONE,
554 it introduces a constraint when matching. This constraint is that the rule must contain an output action directed at that port."""
555
556 def runTest(self):
557
Rich Lane9a003812012-10-04 17:17:59 -0700558 logging.info("Outport1 test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400559
Rich Lane477f4812012-10-04 22:49:00 -0700560 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400561 of_ports.sort()
562 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
563
564 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800565 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400566
Rich Lane9a003812012-10-04 17:17:59 -0700567 logging.info("Inserting a flow with output action --> of_port[1]")
568 logging.info("Deleting the flow but with out_port set to of_port[2]")
569 logging.info("Expecting switch to filter the delete command")
ShreyaPandita9306c772012-09-28 12:21:40 -0400570
571 #Build and send Flow-1 with action output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400572 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400573
574 # Verify active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400575 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400576
577 #Send delete command matching the flow-1 but with contraint out_port = of_port[2]
Rich Laneba3f0e22013-03-11 16:43:57 -0700578 msg7 = ofp.message.flow_delete()
ShreyaPandita9306c772012-09-28 12:21:40 -0400579 msg7.out_port = of_ports[2]
ShreyaPandita9306c772012-09-28 12:21:40 -0400580 msg7.buffer_id = 0xffffffff
581 msg7.match = match
582
Rich Lane5c3151c2013-01-03 17:15:41 -0800583 self.controller.message_send(msg7)
Rich Lane3a261d52013-01-03 17:45:08 -0800584 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400585
586 # Verify flow will not get deleted, active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400587 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400588
Rich Lane9a003812012-10-04 17:17:59 -0700589 logging.info("Deleting the flow with out_port set to of_port[1]")
590 logging.info("Expecting switch to delete the flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400591
592 #Send Delete command with contraint out_port = of_ports[1]
Rich Laneba3f0e22013-03-11 16:43:57 -0700593 msg7 = ofp.message.flow_delete()
ShreyaPandita9306c772012-09-28 12:21:40 -0400594 msg7.out_port = of_ports[1]
ShreyaPandita9306c772012-09-28 12:21:40 -0400595 msg7.buffer_id = 0xffffffff
596 msg7.match = match
597
Rich Lane5c3151c2013-01-03 17:15:41 -0800598 self.controller.message_send(msg7)
Rich Lane3a261d52013-01-03 17:45:08 -0800599 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400600
601 #Verify flow gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400602 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400603
604
Rich Laneb90a1c42012-10-05 09:16:05 -0700605class IdleTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400606
607 """ Verify that idle timeout is implemented"""
608
609 def runTest(self):
610
Rich Lane9a003812012-10-04 17:17:59 -0700611 logging.info("Running Idle_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400612
Rich Lane477f4812012-10-04 22:49:00 -0700613 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400614 of_ports.sort()
615 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
616
617 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800618 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400619
Rich Lane9a003812012-10-04 17:17:59 -0700620 logging.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set")
621 logging.info("Expecting the flow entry to delete with given idle_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400622
623 #Insert a flow entry with idle_timeout=1.Send_Flow_Rem flag set
Rich Laneba3f0e22013-03-11 16:43:57 -0700624 msg9 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400625 msg9.match.wildcards = ofp.OFPFW_ALL
626 msg9.cookie = random.randint(0,9007199254740992)
627 msg9.buffer_id = 0xffffffff
628 msg9.idle_timeout = 1
629 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
630 rv1 = self.controller.message_send(msg9)
631 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800632 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400633
634 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400635 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400636
637 # Verify flow removed message is recieved.
638 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
639 timeout=5)
640 self.assertTrue(response is not None,
641 'Did not receive flow removed message ')
642 self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
643 'Flow table entry removal reason is not idle_timeout')
644 self.assertEqual(1, response.duration_sec,
645 'Flow was not alive for 1 sec')
646
Rich Lane2617eb62015-05-05 14:19:59 -0700647 sleep(1)
648
ShreyaPandita9306c772012-09-28 12:21:40 -0400649
Rich Laneb90a1c42012-10-05 09:16:05 -0700650class Outport2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400651
652 """Add, modify flows with outport set. This field is ignored by ADD, MODIFY, and MODIFY STRICT messages."""
653
654 def runTest(self):
655
Rich Lane9a003812012-10-04 17:17:59 -0700656 logging.info("Running Outport2 test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400657
Rich Lane477f4812012-10-04 22:49:00 -0700658 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400659 of_ports.sort()
660 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
661
662 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800663 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400664
Rich Lane9a003812012-10-04 17:17:59 -0700665 logging.info("Adding and modifying flow with out_port fields set")
666 logging.info("Expecting switch to ignore out_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400667
668 # Create and add flow-1,Action A ,output to port of_port[1], out_port set to of_ports[2]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400669 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400670
671 # Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400672 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400673
674 # Send Packet matching the flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400675 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400676
677 # Insert Flow-Modify matching flow F-1 ,action A', output to port[2], out_port set to port[3]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400678 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400679
680 # Again verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400681 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400682
683 #Verify action is modified
ShreyaPandita8dab4662012-11-02 13:40:14 -0400684 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400685
686
687
688
Rich Laneb90a1c42012-10-05 09:16:05 -0700689class HardTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400690
691 """ Verify that hard timeout is implemented """
692
693 def runTest(self):
694
Rich Lane9a003812012-10-04 17:17:59 -0700695 logging.info("Running Hard_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400696
Rich Lane477f4812012-10-04 22:49:00 -0700697 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400698 of_ports.sort()
699 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
700
701 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800702 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400703
Rich Lane9a003812012-10-04 17:17:59 -0700704 logging.info("Inserting flow entry with hard_timeout set. Also send_flow_removed_message flag set")
705 logging.info("Expecting the flow entry to delete with given hard_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400706
707 # Insert a flow entry with hardtimeout=1 and send_flow_removed flag set
Rich Laneba3f0e22013-03-11 16:43:57 -0700708 msg9 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400709 msg9.match.wildcards = ofp.OFPFW_ALL
710 msg9.cookie = random.randint(0,9007199254740992)
711 msg9.buffer_id = 0xffffffff
712 msg9.hard_timeout = 1
713 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
714 rv1 = self.controller.message_send(msg9)
715 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800716 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400717
718 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400719 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400720
721 # Verify flow removed message is recieved.
722 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
723 timeout=5)
724 self.assertTrue(response is not None,
725 'Did not receive flow removed message ')
726 self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
727 'Flow table entry removal reason is not hard_timeout')
728 self.assertEqual(1, response.duration_sec,
729 'Flow was not alive for 1 sec')
730
Rich Lane2617eb62015-05-05 14:19:59 -0700731 sleep(1)
732
ShreyaPandita9306c772012-09-28 12:21:40 -0400733
Rich Laneb90a1c42012-10-05 09:16:05 -0700734class FlowTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400735
736 """Verify that Flow removed messages are generated as expected
737 Flow removed messages being generated when flag is set, is already tested in the above tests
738 So here, we test the vice-versa condition"""
739
740
741 def runTest(self):
742
Rich Lane9a003812012-10-04 17:17:59 -0700743 logging.info("Running Flow_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400744
Rich Lane477f4812012-10-04 22:49:00 -0700745 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400746 of_ports.sort()
747 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
748
749 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800750 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400751
Rich Lane9a003812012-10-04 17:17:59 -0700752 logging.info("Inserting flow entry with hard_timeout set and send_flow_removed_message flag not set")
753 logging.info("Expecting the flow entry to delete, but no flow removed message")
ShreyaPandita9306c772012-09-28 12:21:40 -0400754
755 # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set
756 pkt = simple_tcp_packet()
757 match3 = parse.packet_to_flow_match(pkt)
758 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
759 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
760 match3.in_port = of_ports[0]
Rich Laneba3f0e22013-03-11 16:43:57 -0700761 msg3 = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400762 msg3.out_port = of_ports[2] # ignored by flow add,flow modify
ShreyaPandita9306c772012-09-28 12:21:40 -0400763 msg3.cookie = random.randint(0,9007199254740992)
764 msg3.buffer_id = 0xffffffff
765 msg3.hard_timeout = 1
766 msg3.buffer_id = 0xffffffff
767 msg3.match = match3
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800768 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400769 act3.port = of_ports[1]
Rich Lanec495d9e2013-03-08 17:43:36 -0800770 msg3.actions.append(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400771
Rich Lane5c3151c2013-01-03 17:15:41 -0800772 self.controller.message_send(msg3)
Rich Lane3a261d52013-01-03 17:45:08 -0800773 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400774
775 #Verify no flow removed message is generated
776 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
777 timeout=3)
778 self.assertTrue(response is None,
779 'Recieved flow removed message ')
780
781 # Verify no entries in the table
ShreyaPandita8dab4662012-11-02 13:40:14 -0400782 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400783
Rich Lane2617eb62015-05-05 14:19:59 -0700784 sleep(1)
785
ShreyaPandita9306c772012-09-28 12:21:40 -0400786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807