blob: 9fc83593a11844695d9d645ac365b2f43201de74 [file] [log] [blame]
ShreyaPandita9306c772012-09-28 12:21:40 -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 3 --> Detailed Controller to switch messages"
6
7import logging
8
9import unittest
10import random
11
Rich Lane477f4812012-10-04 22:49:00 -070012from oftest import config
ShreyaPandita9306c772012-09-28 12:21:40 -040013import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080014import ofp
ShreyaPandita9306c772012-09-28 12:21:40 -040015import oftest.dataplane as dataplane
ShreyaPandita9306c772012-09-28 12:21:40 -040016import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070017import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040018
Rich Laneda3b5ad2012-10-03 09:05:32 -070019from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040020from time import sleep
21from FuncUtils import *
22
Rich Laneb90a1c42012-10-05 09:16:05 -070023class OverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040024
25 """Verify that if overlap check flag is set in the flow entry and an overlapping flow is inserted then an error
26 is generated and switch refuses flow entry"""
27
28 def runTest(self):
29
Rich Lane9a003812012-10-04 17:17:59 -070030 logging.info("Running Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040031
Rich Lane477f4812012-10-04 22:49:00 -070032 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040033 of_ports.sort()
34 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
35
36 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080037 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040038
Rich Lane9a003812012-10-04 17:17:59 -070039 logging.info("Inserting two overlapping flows")
40 logging.info("Expecting switch to return an error")
ShreyaPandita9306c772012-09-28 12:21:40 -040041
42 #Insert a flow F with wildcarded all fields
ShreyaPandita8dab4662012-11-02 13:40:14 -040043 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -040044
45 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -040046 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040047
48 # Build a overlapping flow F'-- Wildcard All except ingress with check overlap bit set
ShreyaPandita8dab4662012-11-02 13:40:14 -040049 pkt_matchingress = simple_tcp_packet()
50 match3 = parse.packet_to_flow_match(pkt_matchingress)
ShreyaPandita9306c772012-09-28 12:21:40 -040051 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
52 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
53 match3.in_port = of_ports[0]
54
Rich Lane28fa9272013-03-08 16:00:25 -080055 msg3 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -040056 msg3.command = ofp.OFPFC_ADD
57 msg3.match = match3
58 msg3.flags |= ofp.OFPFF_CHECK_OVERLAP
59 msg3.cookie = random.randint(0,9007199254740992)
60 msg3.buffer_id = 0xffffffff
61
Rich Lane9d3cc6b2013-03-08 16:33:08 -080062 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -040063 act3.port = of_ports[1]
Rich Lanee30455b2013-01-03 16:24:44 -080064 msg3.actions.add(act3)
Rich Lane5c3151c2013-01-03 17:15:41 -080065 self.controller.message_send(msg3)
Rich Lane3a261d52013-01-03 17:45:08 -080066 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040067
68 # Verify Flow does not get inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -040069 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -040070
71 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
72 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
73 timeout=5)
74 self.assertTrue(response is not None,
75 'Switch did not reply with error message')
76 self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED,
77 'Error message type is not flow mod failed ')
78 self.assertTrue(response.code==ofp.OFPFMFC_OVERLAP,
79 'Error Message code is not overlap')
80
81
Rich Laneb90a1c42012-10-05 09:16:05 -070082class NoOverlapChecking(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040083
84 """Verify that without overlap check flag set, overlapping flows can be created."""
85
86 def runTest(self):
87
Rich Lane9a003812012-10-04 17:17:59 -070088 logging.info("Running No_Overlap_Checking test")
ShreyaPandita9306c772012-09-28 12:21:40 -040089
Rich Lane477f4812012-10-04 22:49:00 -070090 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040091 of_ports.sort()
92 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
93
94 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -080095 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040096
Rich Lane9a003812012-10-04 17:17:59 -070097 logging.info("Inserting two overlapping flows")
98 logging.info("Expecting switch to insert the flows without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -040099
100 #Build a flow F with wildcarded all fields.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400101 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400102
103 #Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400104 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400105
106 # Build a overlapping flow F' without check overlap bit set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400107 wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400108
109 # Verify Flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400110 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400111
112
Rich Laneb90a1c42012-10-05 09:16:05 -0700113class IdenticalFlows(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400114
115 """Verify that adding two identical flows overwrites the existing one and clears counters"""
116
117 def runTest(self):
118
Rich Lane9a003812012-10-04 17:17:59 -0700119 logging.info("Running Identical_Flows test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400120
Rich Lane477f4812012-10-04 22:49:00 -0700121 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400122 of_ports.sort()
123 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
124
125 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800126 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400127
Rich Lane9a003812012-10-04 17:17:59 -0700128 logging.info("Inserting two identical flows one by one")
129 logging.info("Expecting switch to overwrite the first flow and clear the counters associated with it ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400130
131 # Create and add flow-1, check on dataplane it is active.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400132 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400133
134 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400135 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400136
137 # Send Packet (to increment counters like byte_count and packet_count)
ShreyaPandita8dab4662012-11-02 13:40:14 -0400138 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400139
140 # Verify Flow counters have incremented
Rich Laneae3428c2013-03-07 14:37:42 -0800141 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400142
143 #Send Identical flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400144 (pkt1,match1) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400145
146 # Verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400147 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400148
149 # Verify Flow counters reset
Rich Laneae3428c2013-03-07 14:37:42 -0800150 verify_flow_stats(self, match, pkts=0, bytes=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400151
152
Rich Laneb90a1c42012-10-05 09:16:05 -0700153class EmerFlowTimeout(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400154
155 """Timeout values are not allowed for emergency flows"""
156
157 def runTest(self):
158
Rich Lane9a003812012-10-04 17:17:59 -0700159 logging.info("Running Emergency_Flow_Timeout test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400160
Rich Lane477f4812012-10-04 22:49:00 -0700161 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400162 of_ports.sort()
163 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
164
165 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800166 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400167
Rich Lane9a003812012-10-04 17:17:59 -0700168 logging.info("Inserting an emergency flow with timeout values")
169 logging.info("Expecting switch to generate error ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400170
171 #Insert an emergency flow
172 pkt = simple_tcp_packet()
173 match = parse.packet_to_flow_match(pkt)
174 match.in_port = of_ports[0]
175
Rich Lane28fa9272013-03-08 16:00:25 -0800176 request = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400177 request.match = match
178 request.command = ofp.OFPFC_ADD
179 request.flags = request.flags|ofp.OFPFF_EMERG
180 request.hard_timeout =9
181 request.idle_timeout =9
182
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800183 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400184 act.port = of_ports[1]
185
186 request.actions.add(act)
Rich Lane9a003812012-10-04 17:17:59 -0700187 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800188 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400189
Rich Lane3a261d52013-01-03 17:45:08 -0800190 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400191
192 #Verify OFPET_FLOW_MOD_FAILED/OFPFMFC_OVERLAP error is recieved on the control plane
193 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
194 timeout=5)
195 self.assertTrue(response is not None,
196 'Switch did not reply with error message')
197 self.assertTrue(response.type==ofp.OFPET_FLOW_MOD_FAILED,
198 'Error message type is not flow mod failed ')
199 self.assertTrue(response.code==ofp.OFPFMFC_BAD_EMERG_TIMEOUT,
200 'Error Message code is not bad emergency timeout')
201
202
Rich Laneb90a1c42012-10-05 09:16:05 -0700203class MissingModifyAdd(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400204
205 """If a modify does not match an existing flow, the flow gets added """
206
207 def runTest(self):
208
Rich Lane9a003812012-10-04 17:17:59 -0700209 logging.info("Running Missing_Modify_Add test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400210
Rich Lane477f4812012-10-04 22:49:00 -0700211 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400212 of_ports.sort()
213 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
214
Rich Lane9a003812012-10-04 17:17:59 -0700215 logging.info("Inserting a flow-modify that does not match an existing flow")
216 logging.info("Expecting flow to get added i.e OFPFC_MODIFY command should be taken as OFPFC_ADD ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400217
218 #Clear Switch State
Rich Lane32bf9482013-01-03 17:26:30 -0800219 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400220
221 #Generate a flow-mod,command OFPC_MODIFY
222
Rich Lane28fa9272013-03-08 16:00:25 -0800223 request = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400224 request.command = ofp.OFPFC_MODIFY
225 request.match.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
226 request.match.in_port = of_ports[0]
227 request.cookie = random.randint(0,9007199254740992)
228 request.buffer_id = 0xffffffff
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800229 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400230 act3.port = of_ports[1]
Rich Lanee30455b2013-01-03 16:24:44 -0800231 request.actions.add(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400232
Rich Lane9a003812012-10-04 17:17:59 -0700233 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800234 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800235 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400236
237 #Verify the flow gets added i.e. active_count= 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400238 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400239
240
Rich Laneb90a1c42012-10-05 09:16:05 -0700241class ModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400242
243 """A modified flow preserves counters"""
244
245 def runTest(self):
246
Rich Lane9a003812012-10-04 17:17:59 -0700247 logging.info("Running Modify_Action test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400248
Rich Lane477f4812012-10-04 22:49:00 -0700249 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400250 of_ports.sort()
251 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
252
253 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800254 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400255
Rich Lane9a003812012-10-04 17:17:59 -0700256 logging.info("Inserting a Flow and incrementing flow counters. Modifying the flow action")
257 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400258
259 #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 -0400260 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400261
262 #Send Packet matching the flow thus incrementing counters like packet_count,byte_count
ShreyaPandita8dab4662012-11-02 13:40:14 -0400263 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400264
265 #Verify flow counters
Rich Laneae3428c2013-03-07 14:37:42 -0800266 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400267
268 #Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400269 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400270
271 # 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 -0400272 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400273
274 #Verify flow counters are preserved
Rich Laneae3428c2013-03-07 14:37:42 -0800275 verify_flow_stats(self, match, pkts=2, bytes=len(str(pkt))*2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400276
277
Rich Laneb90a1c42012-10-05 09:16:05 -0700278class StrictModifyAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400279
280 """Strict Modify Flow also changes action preserves counters"""
281
282 def runTest(self):
283
Rich Lane9a003812012-10-04 17:17:59 -0700284 logging.info("Running Strict_Modify_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400285
Rich Lane477f4812012-10-04 22:49:00 -0700286 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400287 of_ports.sort()
288 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
289
290 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800291 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400292
Rich Lane9a003812012-10-04 17:17:59 -0700293 logging.info("Inserting Flows and incrementing flow counters. Strict Modify the flow action ")
294 logging.info("Expecting the flow action to be modified , but the flow-counters should be preserved")
ShreyaPandita9306c772012-09-28 12:21:40 -0400295
296 #Create and add flow-1 Match on all, except one wildcarded (src adddress).Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400297 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400298
299 #Create and add flow-2 , Match on ingress_port only, Action A
ShreyaPandita8dab4662012-11-02 13:40:14 -0400300 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=10)
ShreyaPandita9306c772012-09-28 12:21:40 -0400301
302 # Verify both the flows are active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400303 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400304
305 #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 -0400306 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400307
308 # Verify flow counters of the flow-1
Rich Laneae3428c2013-03-07 14:37:42 -0800309 verify_flow_stats(self, match, pkts=1, bytes=len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400310
311 # Strict-Modify flow- 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400312 strict_modify_flow_action(self,of_ports[2],match,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400313
314 # 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 -0400315 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400316
317 # Verify flow counters are preserved
Rich Laneae3428c2013-03-07 14:37:42 -0800318 verify_flow_stats(self, match, pkts=2, bytes=2*len(str(pkt)))
ShreyaPandita9306c772012-09-28 12:21:40 -0400319
320
Rich Laneb90a1c42012-10-05 09:16:05 -0700321class DeleteNonexistingFlow(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400322
323 """Request deletion of non-existing flow"""
324
325 def runTest(self):
326
Rich Lane9a003812012-10-04 17:17:59 -0700327 logging.info("Delete_NonExisting_Flow test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400328
Rich Lane477f4812012-10-04 22:49:00 -0700329 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400330 of_ports.sort()
331 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
332
333 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800334 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400335
Rich Lane9a003812012-10-04 17:17:59 -0700336 logging.info("Deleting a non-existing flow")
337 logging.info("Expecting switch to ignore the command , without generating errors")
ShreyaPandita9306c772012-09-28 12:21:40 -0400338
339 # Issue a delete command
Rich Lane28fa9272013-03-08 16:00:25 -0800340 msg = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400341 msg.match.wildcards = ofp.OFPFW_ALL
342 msg.out_port = ofp.OFPP_NONE
343 msg.command = ofp.OFPFC_DELETE
344 msg.buffer_id = 0xffffffff
345
346 # Verify no message or error is generated by polling the the control plane
347 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
348 timeout=2)
349 self.assertTrue(response is None,
350 'Recieved Error for deleting non-exiting flow ')
351
352
353
Rich Laneb90a1c42012-10-05 09:16:05 -0700354class SendFlowRem(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400355
356 """Check deletion of flows happens and generates messages as configured.
357 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,
358 vice versa also exists """
359
360 def runTest(self):
361
Rich Lane9a003812012-10-04 17:17:59 -0700362 logging.info("Running Send_Flow_Rem test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400363
Rich Lane477f4812012-10-04 22:49:00 -0700364 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400365 of_ports.sort()
366 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
367
368 #Clear swicth state
Rich Lane32bf9482013-01-03 17:26:30 -0800369 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400370
Rich Lane9a003812012-10-04 17:17:59 -0700371 logging.info("Inserting flows F1 and F2 without and with send_flow_removed_message flag set ")
372 logging.info("Deleting the flows")
373 logging.info("Expecting flow removed message only for F2")
ShreyaPandita9306c772012-09-28 12:21:40 -0400374
375 # Insert flow-1 with F without OFPFF_SEND_FLOW_REM flag set.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400376 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400377
378 # Verify flow is inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400379 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400380
381 #Delete the flow-1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400382 nonstrict_delete(self,match,priority=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400383
384 # Verify no flow removed message is generated for the FLOW-1
385
386 (response1, pkt1) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
387 timeout=2)
388 self.assertTrue(response1 is None,
389 'Received flow removed message for the flow with flow_rem flag not set')
390
391 # Insert another flow F' with OFPFF_SEND_FLOW_REM flag set.
Rich Lane28fa9272013-03-08 16:00:25 -0800392 msg9 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400393 msg9.match.wildcards = ofp.OFPFW_ALL
394 msg9.cookie = random.randint(0,9007199254740992)
395 msg9.buffer_id = 0xffffffff
396 msg9.idle_timeout = 1
397 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
398 rv1 = self.controller.message_send(msg9)
399 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800400 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400401
402 # Delete the flow-2
Rich Lane32bf9482013-01-03 17:26:30 -0800403 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400404
405 # Verify flow removed message is generated for the FLOW-2
406
407 (response2, pkt2) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
408 timeout=2)
409 self.assertTrue(response2 is not None,
410 'Did not receive flow removed message for this flow')
411
412
Rich Laneb90a1c42012-10-05 09:16:05 -0700413class DeleteEmerFlow(base_tests.SimpleProtocol):
ShreyaPandita9306c772012-09-28 12:21:40 -0400414
415 """Delete emergency flow and verify no message is generated.An emergency flow deletion will not generate flow-removed messages even if
416 Send Flow removed message flag was set during the emergency flow entry"""
417
418 def runTest(self):
419
Rich Lane9a003812012-10-04 17:17:59 -0700420 logging.info("Running Delete_Emer_Flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400421
Rich Lane477f4812012-10-04 22:49:00 -0700422 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400423 of_ports.sort()
424
425 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800426 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400427
Rich Lane9a003812012-10-04 17:17:59 -0700428 logging.info("Inserting a emergency flow with send_flow_removed flag set")
429 logging.info("Expecting no flow_removed_message on the deletion of the emergency flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400430
431 # Insert a flow with emergency bit set.
432 pkt = simple_tcp_packet()
433 match = parse.packet_to_flow_match(pkt)
434 match.in_port = of_ports[0]
Rich Lane28fa9272013-03-08 16:00:25 -0800435 request = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400436 request.match = match
437 request.command = ofp.OFPFC_ADD
438 request.flags = request.flags|ofp.OFPFF_EMERG|ofp.OFPFF_SEND_FLOW_REM
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800439 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400440 act.port = of_ports[1]
441 request.actions.add(act)
442
Rich Lane5c3151c2013-01-03 17:15:41 -0800443 self.controller.message_send(request)
ShreyaPandita9306c772012-09-28 12:21:40 -0400444
445 # Delete the emergency flow
446
ShreyaPandita8dab4662012-11-02 13:40:14 -0400447 nonstrict_delete(self,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400448 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPFF_SEND_FLOW_REM ,
449 timeout=2)
450 self.assertTrue(response is None,
451 'Test Failed ')
452
453
Rich Laneb90a1c42012-10-05 09:16:05 -0700454class StrictVsNonstrict(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400455
456 """Delete and verify strict and non-strict behaviors
457 This test compares the behavior of delete strict and non-strict"""
458
459 def runTest(self):
460
Rich Lane9a003812012-10-04 17:17:59 -0700461 logging.info("Strict_Vs_Nonstrict test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400462
Rich Lane477f4812012-10-04 22:49:00 -0700463 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400464 of_ports.sort()
465 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
466
467 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800468 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400469
Rich Lane9a003812012-10-04 17:17:59 -0700470 logging.info("Inserting a flow with exact match")
471 logging.info("Issue Strict Delete command , verify it gets deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400472
473 #Insert F with an exact Match
ShreyaPandita8dab4662012-11-02 13:40:14 -0400474 (pkt,match) = exact_match(self,of_ports)
475 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400476
477 #Issue Strict Delete Command , verify F gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400478 strict_delete(self,match)
479 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400480
Rich Lane9a003812012-10-04 17:17:59 -0700481 logging.info("Inserting two overlapping flows")
482 logging.info("Issue Strict Delete command ")
483 logging.info("Expecting only one flow gets deleted , because Strict Delete matches on wildcards as well")
ShreyaPandita9306c772012-09-28 12:21:40 -0400484
485 #Insert Flow T with match on all , except one wildcarded ( say src adddress ).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400486 (pkt,match) = match_all_except_source_address(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400487
488 #Insert another flow T' with match on ingress_port , wildcarded rest.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400489 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
490 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400491
492 #Issue Strict Delete matching on ingress_port. Verify only T' gets deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400493 strict_delete(self,match1)
494 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400495
Rich Lane9a003812012-10-04 17:17:59 -0700496 logging.info("Inserting two overlapping flows")
497 logging.info("Issue Non-Strict Delete command ")
498 logging.info("Expecting both the flow gets deleted , because wildcards are active")
ShreyaPandita9306c772012-09-28 12:21:40 -0400499
500 #Insert T and T' again .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400501 (pkt,match) = match_all_except_source_address(self,of_ports)
502 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports)
503 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400504
505 #Issue Non-strict Delete with match on ingress_port.Verify T+T' gets deleted .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400506 nonstrict_delete(self,match1)
507 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400508
Rich Lane9a003812012-10-04 17:17:59 -0700509 logging.info("Inserting three overlapping flows with different priorities")
510 logging.info("Issue Non-Strict Delete command ")
511 logging.info("Expecting all the flows to get deleted")
ShreyaPandita9306c772012-09-28 12:21:40 -0400512
513 #Insert T , add Priority P (say 100 )
ShreyaPandita8dab4662012-11-02 13:40:14 -0400514 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
ShreyaPandita9306c772012-09-28 12:21:40 -0400515
516 #Insert T' add priority (200).
ShreyaPandita8dab4662012-11-02 13:40:14 -0400517 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
ShreyaPandita9306c772012-09-28 12:21:40 -0400518
519 #Insert T' again add priority 300 --> T" .
ShreyaPandita8dab4662012-11-02 13:40:14 -0400520 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
521 verify_tablestats(self,expect_active=3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400522
523 #Issue Non-Strict Delete and verify all getting deleted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400524 nonstrict_delete(self,match1,priority=200)
525 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400526
Rich Lane9a003812012-10-04 17:17:59 -0700527 logging.info("Inserting three overlapping flows with different priorities")
528 logging.info("Issue Strict Delete command ")
529 logging.info("Expecting only one to get deleted because here priorities & wildcards are being matched")
ShreyaPandita9306c772012-09-28 12:21:40 -0400530
531 #Issue Strict-Delete and verify only T'' gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400532 (pkt,match) = match_all_except_source_address(self,of_ports,priority=100)
533 (pkt1,match1) = wildcard_all_except_ingress(self,of_ports,priority=200)
534 (pkt2,match2) = wildcard_all_except_ingress(self,of_ports,priority=300)
535 strict_delete(self,match1,priority=200)
536 verify_tablestats(self,expect_active=2)
ShreyaPandita9306c772012-09-28 12:21:40 -0400537
538
539
Rich Laneb90a1c42012-10-05 09:16:05 -0700540class Outport1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400541
542 """Delete flows filtered by action outport.If the out_port field in the delete command contains a value other than OFPP_NONE,
543 it introduces a constraint when matching. This constraint is that the rule must contain an output action directed at that port."""
544
545 def runTest(self):
546
Rich Lane9a003812012-10-04 17:17:59 -0700547 logging.info("Outport1 test begins")
ShreyaPandita9306c772012-09-28 12:21:40 -0400548
Rich Lane477f4812012-10-04 22:49:00 -0700549 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400550 of_ports.sort()
551 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
552
553 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800554 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400555
Rich Lane9a003812012-10-04 17:17:59 -0700556 logging.info("Inserting a flow with output action --> of_port[1]")
557 logging.info("Deleting the flow but with out_port set to of_port[2]")
558 logging.info("Expecting switch to filter the delete command")
ShreyaPandita9306c772012-09-28 12:21:40 -0400559
560 #Build and send Flow-1 with action output to of_port[1]
ShreyaPandita8dab4662012-11-02 13:40:14 -0400561 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400562
563 # Verify active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400564 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400565
566 #Send delete command matching the flow-1 but with contraint out_port = of_port[2]
Rich Lane28fa9272013-03-08 16:00:25 -0800567 msg7 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400568 msg7.out_port = of_ports[2]
569 msg7.command = ofp.OFPFC_DELETE
570 msg7.buffer_id = 0xffffffff
571 msg7.match = match
572
Rich Lane5c3151c2013-01-03 17:15:41 -0800573 self.controller.message_send(msg7)
Rich Lane3a261d52013-01-03 17:45:08 -0800574 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400575
576 # Verify flow will not get deleted, active_entries in table_stats_request = 1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400577 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400578
Rich Lane9a003812012-10-04 17:17:59 -0700579 logging.info("Deleting the flow with out_port set to of_port[1]")
580 logging.info("Expecting switch to delete the flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400581
582 #Send Delete command with contraint out_port = of_ports[1]
Rich Lane28fa9272013-03-08 16:00:25 -0800583 msg7 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400584 msg7.out_port = of_ports[1]
585 msg7.command = ofp.OFPFC_DELETE
586 msg7.buffer_id = 0xffffffff
587 msg7.match = match
588
Rich Lane5c3151c2013-01-03 17:15:41 -0800589 self.controller.message_send(msg7)
Rich Lane3a261d52013-01-03 17:45:08 -0800590 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400591
592 #Verify flow gets deleted.
ShreyaPandita8dab4662012-11-02 13:40:14 -0400593 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400594
595
Rich Laneb90a1c42012-10-05 09:16:05 -0700596class IdleTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400597
598 """ Verify that idle timeout is implemented"""
599
600 def runTest(self):
601
Rich Lane9a003812012-10-04 17:17:59 -0700602 logging.info("Running Idle_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400603
Rich Lane477f4812012-10-04 22:49:00 -0700604 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400605 of_ports.sort()
606 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
607
608 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800609 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400610
Rich Lane9a003812012-10-04 17:17:59 -0700611 logging.info("Inserting flow entry with idle_timeout set. Also send_flow_removed_message flag set")
612 logging.info("Expecting the flow entry to delete with given idle_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400613
614 #Insert a flow entry with idle_timeout=1.Send_Flow_Rem flag set
Rich Lane28fa9272013-03-08 16:00:25 -0800615 msg9 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400616 msg9.match.wildcards = ofp.OFPFW_ALL
617 msg9.cookie = random.randint(0,9007199254740992)
618 msg9.buffer_id = 0xffffffff
619 msg9.idle_timeout = 1
620 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
621 rv1 = self.controller.message_send(msg9)
622 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800623 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400624
625 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400626 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400627
628 # Verify flow removed message is recieved.
629 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
630 timeout=5)
631 self.assertTrue(response is not None,
632 'Did not receive flow removed message ')
633 self.assertEqual(ofp.OFPRR_IDLE_TIMEOUT, response.reason,
634 'Flow table entry removal reason is not idle_timeout')
635 self.assertEqual(1, response.duration_sec,
636 'Flow was not alive for 1 sec')
637
638
Rich Laneb90a1c42012-10-05 09:16:05 -0700639class Outport2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400640
641 """Add, modify flows with outport set. This field is ignored by ADD, MODIFY, and MODIFY STRICT messages."""
642
643 def runTest(self):
644
Rich Lane9a003812012-10-04 17:17:59 -0700645 logging.info("Running Outport2 test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400646
Rich Lane477f4812012-10-04 22:49:00 -0700647 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400648 of_ports.sort()
649 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
650
651 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800652 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400653
Rich Lane9a003812012-10-04 17:17:59 -0700654 logging.info("Adding and modifying flow with out_port fields set")
655 logging.info("Expecting switch to ignore out_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400656
657 # 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 -0400658 (pkt,match) = wildcard_all_except_ingress(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400659
660 # Verify flow is active
ShreyaPandita8dab4662012-11-02 13:40:14 -0400661 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400662
663 # Send Packet matching the flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400664 send_packet(self,pkt,of_ports[0],of_ports[1])
ShreyaPandita9306c772012-09-28 12:21:40 -0400665
666 # 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 -0400667 modify_flow_action(self,of_ports,match)
ShreyaPandita9306c772012-09-28 12:21:40 -0400668
669 # Again verify active_entries in table_stats_request =1
ShreyaPandita8dab4662012-11-02 13:40:14 -0400670 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400671
672 #Verify action is modified
ShreyaPandita8dab4662012-11-02 13:40:14 -0400673 send_packet(self,pkt,of_ports[0],of_ports[2])
ShreyaPandita9306c772012-09-28 12:21:40 -0400674
675
676
677
Rich Laneb90a1c42012-10-05 09:16:05 -0700678class HardTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400679
680 """ Verify that hard timeout is implemented """
681
682 def runTest(self):
683
Rich Lane9a003812012-10-04 17:17:59 -0700684 logging.info("Running Hard_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400685
Rich Lane477f4812012-10-04 22:49:00 -0700686 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400687 of_ports.sort()
688 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
689
690 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800691 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400692
Rich Lane9a003812012-10-04 17:17:59 -0700693 logging.info("Inserting flow entry with hard_timeout set. Also send_flow_removed_message flag set")
694 logging.info("Expecting the flow entry to delete with given hard_timeout")
ShreyaPandita9306c772012-09-28 12:21:40 -0400695
696 # Insert a flow entry with hardtimeout=1 and send_flow_removed flag set
Rich Lane28fa9272013-03-08 16:00:25 -0800697 msg9 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400698 msg9.match.wildcards = ofp.OFPFW_ALL
699 msg9.cookie = random.randint(0,9007199254740992)
700 msg9.buffer_id = 0xffffffff
701 msg9.hard_timeout = 1
702 msg9.flags |= ofp.OFPFF_SEND_FLOW_REM
703 rv1 = self.controller.message_send(msg9)
704 self.assertTrue(rv1 != -1, "Error installing flow mod")
Rich Lane3a261d52013-01-03 17:45:08 -0800705 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400706
707 #Verify flow gets inserted
ShreyaPandita8dab4662012-11-02 13:40:14 -0400708 verify_tablestats(self,expect_active=1)
ShreyaPandita9306c772012-09-28 12:21:40 -0400709
710 # Verify flow removed message is recieved.
711 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
712 timeout=5)
713 self.assertTrue(response is not None,
714 'Did not receive flow removed message ')
715 self.assertEqual(ofp.OFPRR_HARD_TIMEOUT, response.reason,
716 'Flow table entry removal reason is not hard_timeout')
717 self.assertEqual(1, response.duration_sec,
718 'Flow was not alive for 1 sec')
719
720
Rich Laneb90a1c42012-10-05 09:16:05 -0700721class FlowTimeout(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400722
723 """Verify that Flow removed messages are generated as expected
724 Flow removed messages being generated when flag is set, is already tested in the above tests
725 So here, we test the vice-versa condition"""
726
727
728 def runTest(self):
729
Rich Lane9a003812012-10-04 17:17:59 -0700730 logging.info("Running Flow_Timeout test ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400731
Rich Lane477f4812012-10-04 22:49:00 -0700732 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400733 of_ports.sort()
734 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
735
736 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800737 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400738
Rich Lane9a003812012-10-04 17:17:59 -0700739 logging.info("Inserting flow entry with hard_timeout set and send_flow_removed_message flag not set")
740 logging.info("Expecting the flow entry to delete, but no flow removed message")
ShreyaPandita9306c772012-09-28 12:21:40 -0400741
742 # Insert a flow with hard_timeout = 1 but no Send_Flow_Rem flag set
743 pkt = simple_tcp_packet()
744 match3 = parse.packet_to_flow_match(pkt)
745 self.assertTrue(match3 is not None, "Could not generate flow match from pkt")
746 match3.wildcards = ofp.OFPFW_ALL-ofp.OFPFW_IN_PORT
747 match3.in_port = of_ports[0]
Rich Lane28fa9272013-03-08 16:00:25 -0800748 msg3 = ofp.message.flow_mod()
ShreyaPandita9306c772012-09-28 12:21:40 -0400749 msg3.out_port = of_ports[2] # ignored by flow add,flow modify
750 msg3.command = ofp.OFPFC_ADD
751 msg3.cookie = random.randint(0,9007199254740992)
752 msg3.buffer_id = 0xffffffff
753 msg3.hard_timeout = 1
754 msg3.buffer_id = 0xffffffff
755 msg3.match = match3
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800756 act3 = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400757 act3.port = of_ports[1]
Rich Lanee30455b2013-01-03 16:24:44 -0800758 msg3.actions.add(act3)
ShreyaPandita9306c772012-09-28 12:21:40 -0400759
Rich Lane5c3151c2013-01-03 17:15:41 -0800760 self.controller.message_send(msg3)
Rich Lane3a261d52013-01-03 17:45:08 -0800761 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400762
763 #Verify no flow removed message is generated
764 (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_FLOW_REMOVED,
765 timeout=3)
766 self.assertTrue(response is None,
767 'Recieved flow removed message ')
768
769 # Verify no entries in the table
ShreyaPandita8dab4662012-11-02 13:40:14 -0400770 verify_tablestats(self,expect_active=0)
ShreyaPandita9306c772012-09-28 12:21:40 -0400771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793