blob: 7d8ce0feea5ad840c7b61a7d717619f77bc376b0 [file] [log] [blame]
ShreyaPandita9306c772012-09-28 12:21:40 -04001
Matteo Scandoloa229eca2017-08-08 13:05:28 -07002# 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
17
ShreyaPandita9306c772012-09-28 12:21:40 -040018"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
19 Refer Documentation -- Detailed testing methodology
20 <Some of test-cases are directly taken from oftest> """
21
22"Test Suite 6 ---> Actions "
23
24
25import logging
26
27import unittest
28import random
Rich Laneb90a1c42012-10-05 09:16:05 -070029import time
ShreyaPandita9306c772012-09-28 12:21:40 -040030
Rich Lane477f4812012-10-04 22:49:00 -070031from oftest import config
ShreyaPandita9306c772012-09-28 12:21:40 -040032import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080033import ofp
ShreyaPandita9306c772012-09-28 12:21:40 -040034import oftest.dataplane as dataplane
ShreyaPandita9306c772012-09-28 12:21:40 -040035import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070036import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040037
Rich Laneda3b5ad2012-10-03 09:05:32 -070038from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040039from time import sleep
40from FuncUtils import *
41
Rich Laneb90a1c42012-10-05 09:16:05 -070042class NoAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040043
44 """NoActionDrop : no action added to flow , drops the packet."""
45
46 def runTest(self):
47
Rich Lane9a003812012-10-04 17:17:59 -070048 logging.info("Running No_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -040049
Rich Lane477f4812012-10-04 22:49:00 -070050 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040051 of_ports.sort()
52 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
53
54 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080055 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040056
Rich Lane9a003812012-10-04 17:17:59 -070057 logging.info("Install a flow without action")
58 logging.info("Send packets matching that flow")
59 logging.info("Expecting switch to drop all packets")
ShreyaPandita9306c772012-09-28 12:21:40 -040060
61 # Insert a flow wildcard all without any action
62 pkt = simple_tcp_packet()
63 match = parse.packet_to_flow_match(pkt)
64 self.assertTrue(match is not None, "Could not generate flow match from pkt")
65 match.wildcards=ofp.OFPFW_ALL
66 match.in_port = of_ports[0]
67
Rich Laneba3f0e22013-03-11 16:43:57 -070068 msg = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -040069 msg.out_port = ofp.OFPP_NONE
ShreyaPandita9306c772012-09-28 12:21:40 -040070 msg.buffer_id = 0xffffffff
71 msg.match = match
Rich Lane5c3151c2013-01-03 17:15:41 -080072 self.controller.message_send(msg)
Rich Lane3a261d52013-01-03 17:45:08 -080073 do_barrier(self.controller)
ShreyaPanditab46f8522012-09-28 15:12:15 -040074
ShreyaPandita9306c772012-09-28 12:21:40 -040075 #Sending N packets matching the flow inserted
76 for pkt_cnt in range(5):
77 self.dataplane.send(of_ports[0],str(pkt))
78
79 #Verify packets not recieved on any of the dataplane ports
ShreyaPandita7b9ec982012-09-28 14:43:08 -040080 (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1,exp_pkt=pkt)
81 self.assertTrue(rcv_pkt is None,
ShreyaPanditad4a42c62012-09-28 15:35:27 -040082 "Packet received on port " + str(rcv_port))
ShreyaPandita9306c772012-09-28 12:21:40 -040083
84 #Verify packets not sent on control plane either
Rich Lane4c504f32013-06-07 17:24:14 -070085 verify_no_packet_in(self, str(pkt), of_ports[0])
ShreyaPandita9306c772012-09-28 12:21:40 -040086
87
Rich Laneb90a1c42012-10-05 09:16:05 -070088class Announcement(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040089
90 """Announcement : Get all supported actions by the switch.
91 Send OFPT_FEATURES_REQUEST to get features supported by sw."""
92
93 def runTest(self):
94
Rich Lane9a003812012-10-04 17:17:59 -070095 logging.info("Running Announcement test")
ShreyaPandita9306c772012-09-28 12:21:40 -040096
Rich Lane9a003812012-10-04 17:17:59 -070097 logging.info("Sending Features_Request")
98 logging.info("Expecting Features Reply with supported actions")
ShreyaPandita9306c772012-09-28 12:21:40 -040099
100 # Sending Features_Request
Rich Lane28fa9272013-03-08 16:00:25 -0800101 request = ofp.message.features_request()
ShreyaPandita9306c772012-09-28 12:21:40 -0400102 (reply, pkt) = self.controller.transact(request)
103 self.assertTrue(reply is not None, "Failed to get any reply")
Rich Laneb73808c2013-03-11 15:22:23 -0700104 self.assertEqual(reply.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
ShreyaPandita9306c772012-09-28 12:21:40 -0400105
106 supported_actions =[]
107 if(reply.actions &1<<ofp.OFPAT_OUTPUT):
108 supported_actions.append('OFPAT_OUTPUT')
109 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
110 supported_actions.append('OFPAT_SET_VLAN_VID')
111 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
112 supported_actions.append('OFPAT_SET_VLAN_PCP')
113 if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
114 supported_actions.append('OFPAT_STRIP_VLAN')
115 if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
116 supported_actions.append('OFPAT_SET_DL_SRC')
117 if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
118 supported_actions.append('OFPAT_SET_NW_SRC')
119 if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
120 supported_actions.append('OFPAT_SET_NW_DST')
121 if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
122 supported_actions.append('OFPAT_SET_NW_TOS')
123 if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
124 supported_actions.append('OFPAT_SET_TP_SRC')
125 if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
126 supported_actions.append('OFPAT_SET_TP_DST')
Rich Lane609194f2013-10-21 06:17:37 -0700127 if(reply.actions &1<<ofp.OFPAT_EXPERIMENTER):
128 supported_actions.append('OFPAT_EXPERIMENTER')
ShreyaPandita9306c772012-09-28 12:21:40 -0400129 if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
130 supported_actions.append('OFPAT_ENQUEUE')
131
Rich Lane9a003812012-10-04 17:17:59 -0700132 logging.info(supported_actions)
ShreyaPandita9306c772012-09-28 12:21:40 -0400133
134
Rich Laneb90a1c42012-10-05 09:16:05 -0700135class ForwardAll(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400136
137 """ForwardAll : Packet is sent to all dataplane ports
138 except ingress port when output action.port = OFPP_ALL"""
139
140 def runTest(self):
141
Rich Lane9a003812012-10-04 17:17:59 -0700142 logging.info("Running Forward_All test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400143
Rich Lane477f4812012-10-04 22:49:00 -0700144 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400145 of_ports.sort()
146 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
147
148 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800149 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400150
Rich Lane9a003812012-10-04 17:17:59 -0700151 logging.info("Insert a flow with output action port OFPP_ALL")
152 logging.info("Send packet matching the flow")
153 logging.info("Expecting packet on all dataplane ports except ingress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400154
155 #Create a packet
156 pkt = simple_tcp_packet()
157 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800158 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400159
160 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800161 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400162 ingress_port=of_ports[0]
163 match.in_port = ingress_port
164
165 #Create a flow mod with action.port = OFPP_ALL
Rich Laneba3f0e22013-03-11 16:43:57 -0700166 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400167 request.match = match
168 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
169 act.port = ofp.OFPP_ALL
Rich Lanec495d9e2013-03-08 17:43:36 -0800170 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400171
Rich Lane9a003812012-10-04 17:17:59 -0700172 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800173 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800174 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400175
176 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700177 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400178 self.dataplane.send(ingress_port, str(pkt))
179
180 #Verifying packets recieved on expected dataplane ports
181 yes_ports = set(of_ports).difference([ingress_port])
Rich Lanee4b384d2013-09-13 14:33:40 -0700182 verify_packets(self, pkt, yes_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400183
184
Rich Laneb90a1c42012-10-05 09:16:05 -0700185class ForwardController(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400186
187 """ForwardController : Packet is sent to controller
188 output.port = OFPP_CONTROLLER"""
189
190 def runTest(self):
191
Rich Lane9a003812012-10-04 17:17:59 -0700192 logging.info("Running Forward_Controller test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400193
Rich Lane477f4812012-10-04 22:49:00 -0700194 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400195 of_ports.sort()
196 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
197
198 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800199 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400200
Rich Lane9a003812012-10-04 17:17:59 -0700201 logging.info("Insert a flow with output action port OFPP_CONTROLLER")
202 logging.info("Send packet matching the flow")
203 logging.info("Expecting packet on the control plane")
ShreyaPandita9306c772012-09-28 12:21:40 -0400204
205 #Create packet
206 pkt = simple_tcp_packet()
207 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800208 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400209
210 for ingress_port in of_ports:
211 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800212 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400213
214 match.in_port = ingress_port
215
216 #Create a flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700217 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400218 request.match = match
219 act.port = ofp.OFPP_CONTROLLER
Rich Lanec495d9e2013-03-08 17:43:36 -0800220 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400221
Rich Lane9a003812012-10-04 17:17:59 -0700222 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800223 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800224 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400225
226 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700227 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400228 self.dataplane.send(ingress_port, str(pkt))
229
230 #Verifying packet recieved on the control plane port
Rich Lane4c504f32013-06-07 17:24:14 -0700231 verify_packet_in(self, str(pkt), ingress_port, ofp.OFPR_ACTION)
ShreyaPandita9306c772012-09-28 12:21:40 -0400232
233
234
Rich Laneb90a1c42012-10-05 09:16:05 -0700235class ForwardLocal(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400236
237 """ForwardLocal : Packet is sent to OFPP_LOCAL port .
238 TBD : To verify packet recieved in the local networking stack of switch"""
239
240 def runTest(self):
241
Rich Lane9a003812012-10-04 17:17:59 -0700242 logging.info("Running Forward_Local test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400243
Rich Lane477f4812012-10-04 22:49:00 -0700244 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400245 of_ports.sort()
246 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
247
248 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800249 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400250
Rich Lane9a003812012-10-04 17:17:59 -0700251 logging.info("Insert a flow with output action port OFPP_LOCAL")
252 logging.info("Send packet matching the flow")
253 logging.info("Expecting packet in the local networking stack of switch")
ShreyaPandita9306c772012-09-28 12:21:40 -0400254
255 #Clear switch state
256 pkt = simple_tcp_packet()
257 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800258 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400259
260 for ingress_port in of_ports:
261 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800262 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400263
264 match.in_port = ingress_port
265 #Create flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700266 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400267 request.match = match
268 act.port = ofp.OFPP_LOCAL
Rich Lanec495d9e2013-03-08 17:43:36 -0800269 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400270
Rich Lane9a003812012-10-04 17:17:59 -0700271 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800272 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800273 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400274
275 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700276 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400277 self.dataplane.send(ingress_port, str(pkt))
278
279 #TBD: Verification of packets being recieved.
280
281
Rich Laneb90a1c42012-10-05 09:16:05 -0700282class ForwardFlood(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400283
284 """Forward:Flood : Packet is sent to all dataplane ports
285 except ingress port when output action.port = OFPP_FLOOD
286 TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
287 not including the incoming interface. """
288
289 def runTest(self):
290
Rich Lane9a003812012-10-04 17:17:59 -0700291 logging.info("Running Forward_Flood test")
Rich Lane477f4812012-10-04 22:49:00 -0700292 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400293 of_ports.sort()
294 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
295
296 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800297 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400298
Rich Lane9a003812012-10-04 17:17:59 -0700299 logging.info("Insert a flow with output action port OFPP_FORWARD")
300 logging.info("Send packet matching the flow")
301 logging.info("Expecting packet on all the ports except the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400302
303 #Create a packet
304 pkt = simple_tcp_packet()
305 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800306 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400307
308 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800309 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400310 ingress_port=of_ports[0]
311 match.in_port = ingress_port
312
313 #Create a flow mod with action.port = OFPP_ALL
Rich Laneba3f0e22013-03-11 16:43:57 -0700314 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400315 request.match = match
316 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
317 act.port = ofp.OFPP_FLOOD
Rich Lanec495d9e2013-03-08 17:43:36 -0800318 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400319
Rich Lane9a003812012-10-04 17:17:59 -0700320 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800321 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800322 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400323
324 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700325 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400326 self.dataplane.send(ingress_port, str(pkt))
327
328 #Verifying packets recieved on expected dataplane ports
329 yes_ports = set(of_ports).difference([ingress_port])
Rich Lanee4b384d2013-09-13 14:33:40 -0700330 verify_packets(self, pkt, yes_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400331
Rich Laneb90a1c42012-10-05 09:16:05 -0700332class ForwardInport(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400333
334 """ ForwardInPort : Packet sent to virtual port IN_PORT
335 If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
336
337 def runTest(self):
338
Rich Lane9a003812012-10-04 17:17:59 -0700339 logging.info("Running Forward_Inport test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400340
Rich Lane477f4812012-10-04 22:49:00 -0700341 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400342 of_ports.sort()
343 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
344
345 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800346 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400347
Rich Lane9a003812012-10-04 17:17:59 -0700348 logging.info("Insert a flow with output action port OFPP_INPORT")
349 logging.info("Send packet matching the flow")
350 logging.info("Expecting packet on the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400351
352 #Create a packet
353 pkt = simple_tcp_packet()
354 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800355 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400356
357 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800358 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400359 ingress_port=of_ports[0]
360 match.in_port = ingress_port
361
362 # Create a flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700363 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400364 request.match = match
365 act.port = ofp.OFPP_IN_PORT
366
Rich Lanec495d9e2013-03-08 17:43:36 -0800367 request.actions.append(act)
Rich Lane9a003812012-10-04 17:17:59 -0700368 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800369 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800370 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400371
372 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700373 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400374 self.dataplane.send(ingress_port, str(pkt))
ShreyaPandita9306c772012-09-28 12:21:40 -0400375
376 #Verfying packet recieved on expected dataplane ports
Rich Lanee4b384d2013-09-13 14:33:40 -0700377 verify_packets(self, pkt, [ingress_port])
ShreyaPandita9306c772012-09-28 12:21:40 -0400378
Rich Laneb90a1c42012-10-05 09:16:05 -0700379class ForwardTable(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400380
381 """ForwardTable : Perform actions in flow table. Only for packet-out messages.
382 If the output action.port in the packetout message = OFP.TABLE , then
383 the packet implements the action specified in the matching flow of the FLOW-TABLE"""
384
385 def runTest(self):
386
Rich Lane9a003812012-10-04 17:17:59 -0700387 logging.info("Running Forward_Table test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400388
Rich Lane477f4812012-10-04 22:49:00 -0700389 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400390 of_ports.sort()
391 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
392
393 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800394 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400395
Rich Lane9a003812012-10-04 17:17:59 -0700396 logging.info("Insert a flow F with output action port set to some egress_port")
397 logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
398 logging.info("Expecting packet on the egress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400399
400 #Insert a all wildcarded flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400401 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400402
403 #Create a packet out message
Rich Lane28fa9272013-03-08 16:00:25 -0800404 pkt_out =ofp.message.packet_out();
ShreyaPandita9306c772012-09-28 12:21:40 -0400405 pkt_out.data = str(pkt)
406 pkt_out.in_port = of_ports[0]
Rich Laneea8c4722013-04-04 15:30:20 -0700407 pkt_out.buffer_id = 0xffffffff
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800408 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400409 act.port = ofp.OFPP_TABLE
Rich Lanec495d9e2013-03-08 17:43:36 -0800410 pkt_out.actions.append(act)
Rich Lane5c3151c2013-01-03 17:15:41 -0800411 self.controller.message_send(pkt_out)
ShreyaPandita9306c772012-09-28 12:21:40 -0400412
413 #Verifying packet out message recieved on the expected dataplane port.
414 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
415 exp_pkt=pkt,timeout=3)
416 self.assertTrue(pkt is not None, 'Packet not received')
417
418
Rich Laneb90a1c42012-10-05 09:16:05 -0700419class AddVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400420
421 """AddVlanTag : Adds VLAN Tag to untagged packet."""
422
423 def runTest(self):
424
Rich Lane9a003812012-10-04 17:17:59 -0700425 logging.info("Running Add_vlan_tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400426
Rich Lane477f4812012-10-04 22:49:00 -0700427 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400428 of_ports.sort()
429 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
430
431 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800432 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400433
Rich Lane9a003812012-10-04 17:17:59 -0700434 logging.info("Verify if switch supports the action -- set vlan id, if not skip the test")
435 logging.info("Insert a flow with set vid action")
436 logging.info("Send packet matching the flow , verify recieved packet has vid set")
ShreyaPandita9306c772012-09-28 12:21:40 -0400437
438 #Verify set_vlan_id is a supported action
439 sup_acts = sw_supported_actions(self)
440 if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
441 skip_message_emit(self, "Add VLAN tag test skipped")
442 return
443
444 #Create packet to be sent and an expected packet with vid set
445 new_vid = 2
446 len_wo_vid = 100
447 len_w_vid = 104
448 pkt = simple_tcp_packet(pktlen=len_wo_vid)
449 exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True,
Rich Laned0478ff2013-03-11 12:46:58 -0700450 vlan_vid=new_vid,vlan_pcp=0)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800451 vid_act = ofp.action.set_vlan_vid()
ShreyaPandita9306c772012-09-28 12:21:40 -0400452 vid_act.vlan_vid = new_vid
453
454 #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700455 flow_match_test(self, config["port_map"], pkt=pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400456 exp_pkt=exp_pkt, action_list=[vid_act])
457
Rich Laneb90a1c42012-10-05 09:16:05 -0700458class ModifyVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400459
460 """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
461
462 def runTest(self):
463
Rich Lane9a003812012-10-04 17:17:59 -0700464 logging.info("Running Modify_Vlan_Tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400465
Rich Lane477f4812012-10-04 22:49:00 -0700466 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400467 of_ports.sort()
468 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
469
470 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800471 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400472
Rich Lane9a003812012-10-04 17:17:59 -0700473 logging.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
474 logging.info("Insert a flow with action --set vid ")
475 logging.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400476
477 #Verify set_vlan_id is a supported action
478 sup_acts = sw_supported_actions(self)
479 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
480 skip_message_emit(self, "Modify VLAN tag test skipped")
481 return
482
483 #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
484 old_vid = 2
485 new_vid = 3
Rich Laned0478ff2013-03-11 12:46:58 -0700486 pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=old_vid)
487 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=new_vid)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800488 vid_act = ofp.action.set_vlan_vid()
ShreyaPandita9306c772012-09-28 12:21:40 -0400489 vid_act.vlan_vid = new_vid
490
491 #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
Rich Lane477f4812012-10-04 22:49:00 -0700492 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400493 action_list=[vid_act])
494
Rich Laneb90a1c42012-10-05 09:16:05 -0700495class VlanPrio1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400496
497 """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
498
499 def runTest(self):
500
Rich Lane9a003812012-10-04 17:17:59 -0700501 logging.info("Running vlan_Prio_1 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400502
Rich Lane477f4812012-10-04 22:49:00 -0700503 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400504 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)
ShreyaPandita9306c772012-09-28 12:21:40 -0400509
Rich Lane9a003812012-10-04 17:17:59 -0700510 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
511 logging.info("Insert a flow with action -- set vlan priority ")
512 logging.info("Send untagged packet matching the flow , verify recieved packet has specified VLAN priority and has vid set tO 0 ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400513
514 #Verify set_vlan_priority is a supported action
515 sup_acts = sw_supported_actions(self)
516 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
517 skip_message_emit(self, "Set VLAN priority test skipped")
518 return
519
520 #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set.
521 vlan_id = 0
Rich Lane123928c2012-10-04 21:28:53 -0700522 vlan_pcp = 1
Dan Talayco3bfc8222013-02-13 18:18:57 -0800523 pktlen = 64 if config["minsize"] < 64 else config["minsize"]
524 pkt = simple_tcp_packet(pktlen=pktlen)
Rich Laned0478ff2013-03-11 12:46:58 -0700525 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,vlan_pcp=vlan_pcp, pktlen=pktlen + 4)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800526 act = ofp.action.set_vlan_pcp()
Rich Lane123928c2012-10-04 21:28:53 -0700527 act.vlan_pcp = vlan_pcp
ShreyaPandita9306c772012-09-28 12:21:40 -0400528
529 #Insert flow with action -- set vLAN priority, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700530 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400531 action_list=[act])
532
533
Rich Laneb90a1c42012-10-05 09:16:05 -0700534class VlanPrio2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400535
536 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
537
538 def runTest(self):
539
Rich Lane9a003812012-10-04 17:17:59 -0700540 logging.info("Running Vlan_Prio_2 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400541
Rich Lane477f4812012-10-04 22:49:00 -0700542 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400543 of_ports.sort()
544 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
545
546 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800547 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400548
Rich Lane9a003812012-10-04 17:17:59 -0700549 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
550 logging.info("Insert a flow with action -- set vlan priority ")
551 logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400552
553 #Verify set_vlan_priority is a supported action
554 sup_acts = sw_supported_actions(self,"true")
555 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
556 skip_message_emit(self, "modify_vlan_prio test skipped")
557 return
558
559 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
560 vid = 123
561 old_vlan_pcp = 2
562 new_vlan_pcp = 3
Rich Laned0478ff2013-03-11 12:46:58 -0700563 pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vid, vlan_pcp=old_vlan_pcp)
564 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vid, vlan_pcp=new_vlan_pcp)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800565 vid_act = ofp.action.set_vlan_pcp()
ShreyaPandita9306c772012-09-28 12:21:40 -0400566 vid_act.vlan_pcp = new_vlan_pcp
567
568 #Insert flow with action -- set vLAN priority, Send tagged packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700569 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400570 action_list=[vid_act])
571
572
Rich Laneb90a1c42012-10-05 09:16:05 -0700573class ModifyL2Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400574
575 """ModifyL2Src :Modify the source MAC address"""
576
577 def runTest(self):
578
Rich Lane9a003812012-10-04 17:17:59 -0700579 logging.info("Running Modify_L2_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400580
Rich Lane477f4812012-10-04 22:49:00 -0700581 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400582 of_ports.sort()
583 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
584
585 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800586 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400587
Rich Lane9a003812012-10-04 17:17:59 -0700588 logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
589 logging.info("Insert a flow with action -- set etherent src address")
590 logging.info("Send packet matching the flow, verify recieved packet src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400591
592 #Verify set_dl_src is a supported action
593 sup_acts = sw_supported_actions(self,use_cache="true")
594 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
595 skip_message_emit(self, "modify_l2_src test skipped")
596 return
597
Rich Laned0478ff2013-03-11 12:46:58 -0700598 #Create packet to be sent and expected packet with eth_src set to specified value
599 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['eth_src'],
ShreyaPandita9306c772012-09-28 12:21:40 -0400600 check_test_params=True)
601
602 #Insert flow with action -- set src address, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700603 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400604 action_list=acts, max_test=2)
605
606
Rich Laneb90a1c42012-10-05 09:16:05 -0700607class ModifyL2Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400608
609 """ModifyL2SDSt :Modify the dest MAC address"""
610
611 def runTest(self):
612
Rich Lane9a003812012-10-04 17:17:59 -0700613 logging.info("Running Modify_L2_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400614
Rich Lane477f4812012-10-04 22:49:00 -0700615 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400616 of_ports.sort()
617 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
618
619 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800620 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400621
Rich Lane9a003812012-10-04 17:17:59 -0700622 logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
623 logging.info("Insert a flow with action -- set etherent dst address ")
624 logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400625
626 #Verify set_dl_dst is a supported action
627 sup_acts = sw_supported_actions(self)
628 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
629 skip_message_emit(self, "modify_l2_dst test skipped")
630 return
631
Rich Laned0478ff2013-03-11 12:46:58 -0700632 #Create packet to be sent and expected packet with eth_src set to specified value
633 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['eth_dst'],
ShreyaPandita9306c772012-09-28 12:21:40 -0400634 check_test_params=True)
635
636 #Insert flow with action -- set dst address, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700637 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400638 action_list=acts, max_test=2)
639
Rich Laneb90a1c42012-10-05 09:16:05 -0700640class ModifyL3Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400641
642 """ModifyL3Src : Modify the source IP address of an IP packet """
643
644 def runTest(self):
645
Rich Lane9a003812012-10-04 17:17:59 -0700646 logging.info("Running Modify_L3_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400647
Rich Lane477f4812012-10-04 22:49:00 -0700648 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400649 of_ports.sort()
650 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
651
652 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800653 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400654
Rich Lane9a003812012-10-04 17:17:59 -0700655 logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
656 logging.info("Insert a flow with action -- set network src address ")
657 logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400658
659 #Verify set_nw_src is a supported action
660 sup_acts = sw_supported_actions(self)
661 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
662 skip_message_emit(self, "modify_l3_src test")
663 return
664
Rich Laned0478ff2013-03-11 12:46:58 -0700665 #Create packet to be sent and expected packet with ipv4_src set to specified value
ShreyaPandita9306c772012-09-28 12:21:40 -0400666 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
667 check_test_params=True)
668
669 #Insert flow with action -- set nw src address, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700670 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400671 action_list=acts, max_test=2)
672
Rich Laneb90a1c42012-10-05 09:16:05 -0700673class ModifyL3Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400674
675 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
676
677 def runTest(self):
678
Rich Lane9a003812012-10-04 17:17:59 -0700679 logging.info("Running Modify_L3_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400680
Rich Lane477f4812012-10-04 22:49:00 -0700681 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400682 of_ports.sort()
683 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
684
685 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800686 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400687
Rich Lane9a003812012-10-04 17:17:59 -0700688 logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
689 logging.info("Insert a flow with action -- set network dst address ")
690 logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400691
692 #Verify set_nw_dst is a supported action
693 sup_acts = sw_supported_actions(self,use_cache="true")
694 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
695 skip_message_emit(self, "modify_l3_dst test skipped")
696 return
697
Rich Laned0478ff2013-03-11 12:46:58 -0700698 #Create packet to be sent and expected packet with ipv4_dst set to specified value
ShreyaPandita9306c772012-09-28 12:21:40 -0400699 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
700 check_test_params=True)
701
702 #Insert flow with action -- set nw dst address, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700703 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400704 action_list=acts, max_test=2)
705
706
Rich Laneb90a1c42012-10-05 09:16:05 -0700707class ModifyL4Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400708
709 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
710
711 def runTest(self):
712
Rich Lane9a003812012-10-04 17:17:59 -0700713 logging.info("Running Modify_L4_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400714
Rich Lane477f4812012-10-04 22:49:00 -0700715 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400716 of_ports.sort()
717 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
718
719 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800720 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400721
Rich Lane9a003812012-10-04 17:17:59 -0700722 logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
723 logging.info("Insert a flow with action -- set src tcp port")
724 logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400725
726 #Verify set_tp_src is a supported action
727 sup_acts = sw_supported_actions(self,use_cache="true")
728 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
729 skip_message_emit(self, "modify_l4_src test skipped")
730 return
731
732 #Create packet to be sent and expected packet with tcp_src set to specified value
733 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
734 check_test_params=True)
735
736 #Insert flow with action -- set tcp src port, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700737 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400738 action_list=acts, max_test=2)
739
Rich Laneb90a1c42012-10-05 09:16:05 -0700740class ModifyL4Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400741
742 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
743
744 def runTest(self):
745
Rich Lane9a003812012-10-04 17:17:59 -0700746 logging.info("Running Modify_L4_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400747
Rich Lane477f4812012-10-04 22:49:00 -0700748 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400749 of_ports.sort()
750 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
751
752 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800753 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400754
Rich Lane9a003812012-10-04 17:17:59 -0700755 logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
756 logging.info("Insert a flow with action -- set dst tcp port")
757 logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400758
759 #Verify set_tp_dst is a supported action
760 sup_acts = sw_supported_actions(self,use_cache="true")
761 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
762 skip_message_emit(self, "ModifyL4Dst test")
763 return
764
765 #Create packet to be sent and expected packet with tcp_dst set to specified value
766 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
767 check_test_params=True)
768
769 #Insert flow with action -- set tcp dst port, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700770 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400771 action_list=acts, max_test=2)
772
Rich Laneb90a1c42012-10-05 09:16:05 -0700773class ModifyTos(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400774
775 """ModifyTOS :Modify the IP type of service of an IP packet"""
776
777 def runTest(self):
778
Rich Lane9a003812012-10-04 17:17:59 -0700779 logging.info("Running Modify_Tos test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400780
Rich Lane477f4812012-10-04 22:49:00 -0700781 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400782 of_ports.sort()
783 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
784
785 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800786 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400787
Rich Lane9a003812012-10-04 17:17:59 -0700788 logging.info("Verify if switch supports the action -- modify_tos, if not skip the test")
789 logging.info("Insert a flow with action -- set type of service ")
790 logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400791
792 #Verify set_tos is a supported action
793 sup_acts = sw_supported_actions(self,use_cache="true")
794 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
795 skip_message_emit(self, "ModifyTOS test")
796 return
797
798 #Create packet to be sent and expected packet with TOS set to specified value
799 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
800 check_test_params=True)
801
802 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700803 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400804 action_list=acts, max_test=2, egr_count=-1)