blob: 1a99debba08c44a788cac27bd813515bd810c21e [file] [log] [blame]
ShreyaPandita9306c772012-09-28 12:21:40 -04001
2"""These tests fall under Conformance Test-Suite (OF-SWITCH-1.0.0 TestCases).
3 Refer Documentation -- Detailed testing methodology
4 <Some of test-cases are directly taken from oftest> """
5
6"Test Suite 6 ---> Actions "
7
8
9import logging
10
11import unittest
12import random
Rich Laneb90a1c42012-10-05 09:16:05 -070013import time
ShreyaPandita9306c772012-09-28 12:21:40 -040014
Rich Lane477f4812012-10-04 22:49:00 -070015from oftest import config
ShreyaPandita9306c772012-09-28 12:21:40 -040016import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080017import ofp
ShreyaPandita9306c772012-09-28 12:21:40 -040018import oftest.dataplane as dataplane
ShreyaPandita9306c772012-09-28 12:21:40 -040019import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070020import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040021
Rich Laneda3b5ad2012-10-03 09:05:32 -070022from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040023from time import sleep
24from FuncUtils import *
25
Rich Laneb90a1c42012-10-05 09:16:05 -070026class NoAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040027
28 """NoActionDrop : no action added to flow , drops the packet."""
29
30 def runTest(self):
31
Rich Lane9a003812012-10-04 17:17:59 -070032 logging.info("Running No_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -040033
Rich Lane477f4812012-10-04 22:49:00 -070034 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040035 of_ports.sort()
36 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
37
38 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080039 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040040
Rich Lane9a003812012-10-04 17:17:59 -070041 logging.info("Install a flow without action")
42 logging.info("Send packets matching that flow")
43 logging.info("Expecting switch to drop all packets")
ShreyaPandita9306c772012-09-28 12:21:40 -040044
45 # Insert a flow wildcard all without any action
46 pkt = simple_tcp_packet()
47 match = parse.packet_to_flow_match(pkt)
48 self.assertTrue(match is not None, "Could not generate flow match from pkt")
49 match.wildcards=ofp.OFPFW_ALL
50 match.in_port = of_ports[0]
51
Rich Laneba3f0e22013-03-11 16:43:57 -070052 msg = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -040053 msg.out_port = ofp.OFPP_NONE
ShreyaPandita9306c772012-09-28 12:21:40 -040054 msg.buffer_id = 0xffffffff
55 msg.match = match
Rich Lane5c3151c2013-01-03 17:15:41 -080056 self.controller.message_send(msg)
Rich Lane3a261d52013-01-03 17:45:08 -080057 do_barrier(self.controller)
ShreyaPanditab46f8522012-09-28 15:12:15 -040058
ShreyaPandita9306c772012-09-28 12:21:40 -040059 #Sending N packets matching the flow inserted
60 for pkt_cnt in range(5):
61 self.dataplane.send(of_ports[0],str(pkt))
62
63 #Verify packets not recieved on any of the dataplane ports
ShreyaPandita7b9ec982012-09-28 14:43:08 -040064 (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1,exp_pkt=pkt)
65 self.assertTrue(rcv_pkt is None,
ShreyaPanditad4a42c62012-09-28 15:35:27 -040066 "Packet received on port " + str(rcv_port))
ShreyaPandita9306c772012-09-28 12:21:40 -040067
68 #Verify packets not sent on control plane either
Rich Lane4c504f32013-06-07 17:24:14 -070069 verify_no_packet_in(self, str(pkt), of_ports[0])
ShreyaPandita9306c772012-09-28 12:21:40 -040070
71
Rich Laneb90a1c42012-10-05 09:16:05 -070072class Announcement(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040073
74 """Announcement : Get all supported actions by the switch.
75 Send OFPT_FEATURES_REQUEST to get features supported by sw."""
76
77 def runTest(self):
78
Rich Lane9a003812012-10-04 17:17:59 -070079 logging.info("Running Announcement test")
ShreyaPandita9306c772012-09-28 12:21:40 -040080
Rich Lane9a003812012-10-04 17:17:59 -070081 logging.info("Sending Features_Request")
82 logging.info("Expecting Features Reply with supported actions")
ShreyaPandita9306c772012-09-28 12:21:40 -040083
84 # Sending Features_Request
Rich Lane28fa9272013-03-08 16:00:25 -080085 request = ofp.message.features_request()
ShreyaPandita9306c772012-09-28 12:21:40 -040086 (reply, pkt) = self.controller.transact(request)
87 self.assertTrue(reply is not None, "Failed to get any reply")
Rich Laneb73808c2013-03-11 15:22:23 -070088 self.assertEqual(reply.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
ShreyaPandita9306c772012-09-28 12:21:40 -040089
90 supported_actions =[]
91 if(reply.actions &1<<ofp.OFPAT_OUTPUT):
92 supported_actions.append('OFPAT_OUTPUT')
93 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
94 supported_actions.append('OFPAT_SET_VLAN_VID')
95 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
96 supported_actions.append('OFPAT_SET_VLAN_PCP')
97 if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
98 supported_actions.append('OFPAT_STRIP_VLAN')
99 if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
100 supported_actions.append('OFPAT_SET_DL_SRC')
101 if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
102 supported_actions.append('OFPAT_SET_NW_SRC')
103 if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
104 supported_actions.append('OFPAT_SET_NW_DST')
105 if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
106 supported_actions.append('OFPAT_SET_NW_TOS')
107 if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
108 supported_actions.append('OFPAT_SET_TP_SRC')
109 if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
110 supported_actions.append('OFPAT_SET_TP_DST')
111 if(reply.actions &1<<ofp.OFPAT_VENDOR):
112 supported_actions.append('OFPAT_VENDOR')
113 if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
114 supported_actions.append('OFPAT_ENQUEUE')
115
Rich Lane9a003812012-10-04 17:17:59 -0700116 logging.info(supported_actions)
ShreyaPandita9306c772012-09-28 12:21:40 -0400117
118
Rich Laneb90a1c42012-10-05 09:16:05 -0700119class ForwardAll(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400120
121 """ForwardAll : Packet is sent to all dataplane ports
122 except ingress port when output action.port = OFPP_ALL"""
123
124 def runTest(self):
125
Rich Lane9a003812012-10-04 17:17:59 -0700126 logging.info("Running Forward_All test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400127
Rich Lane477f4812012-10-04 22:49:00 -0700128 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400129 of_ports.sort()
130 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
131
132 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800133 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400134
Rich Lane9a003812012-10-04 17:17:59 -0700135 logging.info("Insert a flow with output action port OFPP_ALL")
136 logging.info("Send packet matching the flow")
137 logging.info("Expecting packet on all dataplane ports except ingress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400138
139 #Create a packet
140 pkt = simple_tcp_packet()
141 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800142 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400143
144 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800145 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400146 ingress_port=of_ports[0]
147 match.in_port = ingress_port
148
149 #Create a flow mod with action.port = OFPP_ALL
Rich Laneba3f0e22013-03-11 16:43:57 -0700150 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400151 request.match = match
152 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
153 act.port = ofp.OFPP_ALL
Rich Lanec495d9e2013-03-08 17:43:36 -0800154 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400155
Rich Lane9a003812012-10-04 17:17:59 -0700156 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800157 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800158 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400159
160 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700161 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400162 self.dataplane.send(ingress_port, str(pkt))
163
164 #Verifying packets recieved on expected dataplane ports
165 yes_ports = set(of_ports).difference([ingress_port])
Rich Lanee4b384d2013-09-13 14:33:40 -0700166 verify_packets(self, pkt, yes_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400167
168
Rich Laneb90a1c42012-10-05 09:16:05 -0700169class ForwardController(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400170
171 """ForwardController : Packet is sent to controller
172 output.port = OFPP_CONTROLLER"""
173
174 def runTest(self):
175
Rich Lane9a003812012-10-04 17:17:59 -0700176 logging.info("Running Forward_Controller test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400177
Rich Lane477f4812012-10-04 22:49:00 -0700178 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400179 of_ports.sort()
180 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
181
182 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800183 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400184
Rich Lane9a003812012-10-04 17:17:59 -0700185 logging.info("Insert a flow with output action port OFPP_CONTROLLER")
186 logging.info("Send packet matching the flow")
187 logging.info("Expecting packet on the control plane")
ShreyaPandita9306c772012-09-28 12:21:40 -0400188
189 #Create packet
190 pkt = simple_tcp_packet()
191 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800192 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400193
194 for ingress_port in of_ports:
195 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800196 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400197
198 match.in_port = ingress_port
199
200 #Create a flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700201 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400202 request.match = match
203 act.port = ofp.OFPP_CONTROLLER
Rich Lanec495d9e2013-03-08 17:43:36 -0800204 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400205
Rich Lane9a003812012-10-04 17:17:59 -0700206 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800207 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800208 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400209
210 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700211 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400212 self.dataplane.send(ingress_port, str(pkt))
213
214 #Verifying packet recieved on the control plane port
Rich Lane4c504f32013-06-07 17:24:14 -0700215 verify_packet_in(self, str(pkt), ingress_port, ofp.OFPR_ACTION)
ShreyaPandita9306c772012-09-28 12:21:40 -0400216
217
218
Rich Laneb90a1c42012-10-05 09:16:05 -0700219class ForwardLocal(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400220
221 """ForwardLocal : Packet is sent to OFPP_LOCAL port .
222 TBD : To verify packet recieved in the local networking stack of switch"""
223
224 def runTest(self):
225
Rich Lane9a003812012-10-04 17:17:59 -0700226 logging.info("Running Forward_Local test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400227
Rich Lane477f4812012-10-04 22:49:00 -0700228 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400229 of_ports.sort()
230 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
231
232 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800233 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400234
Rich Lane9a003812012-10-04 17:17:59 -0700235 logging.info("Insert a flow with output action port OFPP_LOCAL")
236 logging.info("Send packet matching the flow")
237 logging.info("Expecting packet in the local networking stack of switch")
ShreyaPandita9306c772012-09-28 12:21:40 -0400238
239 #Clear switch state
240 pkt = simple_tcp_packet()
241 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800242 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400243
244 for ingress_port in of_ports:
245 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800246 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400247
248 match.in_port = ingress_port
249 #Create flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700250 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400251 request.match = match
252 act.port = ofp.OFPP_LOCAL
Rich Lanec495d9e2013-03-08 17:43:36 -0800253 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400254
Rich Lane9a003812012-10-04 17:17:59 -0700255 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800256 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800257 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400258
259 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700260 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400261 self.dataplane.send(ingress_port, str(pkt))
262
263 #TBD: Verification of packets being recieved.
264
265
Rich Laneb90a1c42012-10-05 09:16:05 -0700266class ForwardFlood(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400267
268 """Forward:Flood : Packet is sent to all dataplane ports
269 except ingress port when output action.port = OFPP_FLOOD
270 TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
271 not including the incoming interface. """
272
273 def runTest(self):
274
Rich Lane9a003812012-10-04 17:17:59 -0700275 logging.info("Running Forward_Flood test")
Rich Lane477f4812012-10-04 22:49:00 -0700276 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400277 of_ports.sort()
278 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
279
280 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800281 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400282
Rich Lane9a003812012-10-04 17:17:59 -0700283 logging.info("Insert a flow with output action port OFPP_FORWARD")
284 logging.info("Send packet matching the flow")
285 logging.info("Expecting packet on all the ports except the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400286
287 #Create a packet
288 pkt = simple_tcp_packet()
289 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800290 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400291
292 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800293 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400294 ingress_port=of_ports[0]
295 match.in_port = ingress_port
296
297 #Create a flow mod with action.port = OFPP_ALL
Rich Laneba3f0e22013-03-11 16:43:57 -0700298 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400299 request.match = match
300 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
301 act.port = ofp.OFPP_FLOOD
Rich Lanec495d9e2013-03-08 17:43:36 -0800302 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400303
Rich Lane9a003812012-10-04 17:17:59 -0700304 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800305 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800306 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400307
308 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700309 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400310 self.dataplane.send(ingress_port, str(pkt))
311
312 #Verifying packets recieved on expected dataplane ports
313 yes_ports = set(of_ports).difference([ingress_port])
Rich Lanee4b384d2013-09-13 14:33:40 -0700314 verify_packets(self, pkt, yes_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400315
Rich Laneb90a1c42012-10-05 09:16:05 -0700316class ForwardInport(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400317
318 """ ForwardInPort : Packet sent to virtual port IN_PORT
319 If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
320
321 def runTest(self):
322
Rich Lane9a003812012-10-04 17:17:59 -0700323 logging.info("Running Forward_Inport test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400324
Rich Lane477f4812012-10-04 22:49:00 -0700325 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400326 of_ports.sort()
327 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
328
329 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800330 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400331
Rich Lane9a003812012-10-04 17:17:59 -0700332 logging.info("Insert a flow with output action port OFPP_INPORT")
333 logging.info("Send packet matching the flow")
334 logging.info("Expecting packet on the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400335
336 #Create a packet
337 pkt = simple_tcp_packet()
338 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800339 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400340
341 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800342 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400343 ingress_port=of_ports[0]
344 match.in_port = ingress_port
345
346 # Create a flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700347 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400348 request.match = match
349 act.port = ofp.OFPP_IN_PORT
350
Rich Lanec495d9e2013-03-08 17:43:36 -0800351 request.actions.append(act)
Rich Lane9a003812012-10-04 17:17:59 -0700352 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800353 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800354 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400355
356 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700357 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400358 self.dataplane.send(ingress_port, str(pkt))
ShreyaPandita9306c772012-09-28 12:21:40 -0400359
360 #Verfying packet recieved on expected dataplane ports
Rich Lanee4b384d2013-09-13 14:33:40 -0700361 verify_packets(self, pkt, [ingress_port])
ShreyaPandita9306c772012-09-28 12:21:40 -0400362
Rich Laneb90a1c42012-10-05 09:16:05 -0700363class ForwardTable(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400364
365 """ForwardTable : Perform actions in flow table. Only for packet-out messages.
366 If the output action.port in the packetout message = OFP.TABLE , then
367 the packet implements the action specified in the matching flow of the FLOW-TABLE"""
368
369 def runTest(self):
370
Rich Lane9a003812012-10-04 17:17:59 -0700371 logging.info("Running Forward_Table test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400372
Rich Lane477f4812012-10-04 22:49:00 -0700373 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400374 of_ports.sort()
375 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
376
377 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800378 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400379
Rich Lane9a003812012-10-04 17:17:59 -0700380 logging.info("Insert a flow F with output action port set to some egress_port")
381 logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
382 logging.info("Expecting packet on the egress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400383
384 #Insert a all wildcarded flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400385 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400386
387 #Create a packet out message
Rich Lane28fa9272013-03-08 16:00:25 -0800388 pkt_out =ofp.message.packet_out();
ShreyaPandita9306c772012-09-28 12:21:40 -0400389 pkt_out.data = str(pkt)
390 pkt_out.in_port = of_ports[0]
Rich Laneea8c4722013-04-04 15:30:20 -0700391 pkt_out.buffer_id = 0xffffffff
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800392 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400393 act.port = ofp.OFPP_TABLE
Rich Lanec495d9e2013-03-08 17:43:36 -0800394 pkt_out.actions.append(act)
Rich Lane5c3151c2013-01-03 17:15:41 -0800395 self.controller.message_send(pkt_out)
ShreyaPandita9306c772012-09-28 12:21:40 -0400396
397 #Verifying packet out message recieved on the expected dataplane port.
398 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
399 exp_pkt=pkt,timeout=3)
400 self.assertTrue(pkt is not None, 'Packet not received')
401
402
Rich Laneb90a1c42012-10-05 09:16:05 -0700403class AddVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400404
405 """AddVlanTag : Adds VLAN Tag to untagged packet."""
406
407 def runTest(self):
408
Rich Lane9a003812012-10-04 17:17:59 -0700409 logging.info("Running Add_vlan_tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400410
Rich Lane477f4812012-10-04 22:49:00 -0700411 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400412 of_ports.sort()
413 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
414
415 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800416 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400417
Rich Lane9a003812012-10-04 17:17:59 -0700418 logging.info("Verify if switch supports the action -- set vlan id, if not skip the test")
419 logging.info("Insert a flow with set vid action")
420 logging.info("Send packet matching the flow , verify recieved packet has vid set")
ShreyaPandita9306c772012-09-28 12:21:40 -0400421
422 #Verify set_vlan_id is a supported action
423 sup_acts = sw_supported_actions(self)
424 if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
425 skip_message_emit(self, "Add VLAN tag test skipped")
426 return
427
428 #Create packet to be sent and an expected packet with vid set
429 new_vid = 2
430 len_wo_vid = 100
431 len_w_vid = 104
432 pkt = simple_tcp_packet(pktlen=len_wo_vid)
433 exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True,
Rich Laned0478ff2013-03-11 12:46:58 -0700434 vlan_vid=new_vid,vlan_pcp=0)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800435 vid_act = ofp.action.set_vlan_vid()
ShreyaPandita9306c772012-09-28 12:21:40 -0400436 vid_act.vlan_vid = new_vid
437
438 #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700439 flow_match_test(self, config["port_map"], pkt=pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400440 exp_pkt=exp_pkt, action_list=[vid_act])
441
Rich Laneb90a1c42012-10-05 09:16:05 -0700442class ModifyVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400443
444 """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
445
446 def runTest(self):
447
Rich Lane9a003812012-10-04 17:17:59 -0700448 logging.info("Running Modify_Vlan_Tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400449
Rich Lane477f4812012-10-04 22:49:00 -0700450 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400451 of_ports.sort()
452 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
453
454 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800455 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400456
Rich Lane9a003812012-10-04 17:17:59 -0700457 logging.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
458 logging.info("Insert a flow with action --set vid ")
459 logging.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400460
461 #Verify set_vlan_id is a supported action
462 sup_acts = sw_supported_actions(self)
463 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
464 skip_message_emit(self, "Modify VLAN tag test skipped")
465 return
466
467 #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
468 old_vid = 2
469 new_vid = 3
Rich Laned0478ff2013-03-11 12:46:58 -0700470 pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=old_vid)
471 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=new_vid)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800472 vid_act = ofp.action.set_vlan_vid()
ShreyaPandita9306c772012-09-28 12:21:40 -0400473 vid_act.vlan_vid = new_vid
474
475 #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
Rich Lane477f4812012-10-04 22:49:00 -0700476 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400477 action_list=[vid_act])
478
Rich Laneb90a1c42012-10-05 09:16:05 -0700479class VlanPrio1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400480
481 """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
482
483 def runTest(self):
484
Rich Lane9a003812012-10-04 17:17:59 -0700485 logging.info("Running vlan_Prio_1 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400486
Rich Lane477f4812012-10-04 22:49:00 -0700487 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400488 of_ports.sort()
489 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
490
491 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800492 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400493
Rich Lane9a003812012-10-04 17:17:59 -0700494 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
495 logging.info("Insert a flow with action -- set vlan priority ")
496 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 -0400497
498 #Verify set_vlan_priority is a supported action
499 sup_acts = sw_supported_actions(self)
500 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
501 skip_message_emit(self, "Set VLAN priority test skipped")
502 return
503
504 #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set.
505 vlan_id = 0
Rich Lane123928c2012-10-04 21:28:53 -0700506 vlan_pcp = 1
Dan Talayco3bfc8222013-02-13 18:18:57 -0800507 pktlen = 64 if config["minsize"] < 64 else config["minsize"]
508 pkt = simple_tcp_packet(pktlen=pktlen)
Rich Laned0478ff2013-03-11 12:46:58 -0700509 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 -0800510 act = ofp.action.set_vlan_pcp()
Rich Lane123928c2012-10-04 21:28:53 -0700511 act.vlan_pcp = vlan_pcp
ShreyaPandita9306c772012-09-28 12:21:40 -0400512
513 #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 -0700514 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400515 action_list=[act])
516
517
Rich Laneb90a1c42012-10-05 09:16:05 -0700518class VlanPrio2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400519
520 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
521
522 def runTest(self):
523
Rich Lane9a003812012-10-04 17:17:59 -0700524 logging.info("Running Vlan_Prio_2 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400525
Rich Lane477f4812012-10-04 22:49:00 -0700526 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400527 of_ports.sort()
528 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
529
530 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800531 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400532
Rich Lane9a003812012-10-04 17:17:59 -0700533 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
534 logging.info("Insert a flow with action -- set vlan priority ")
535 logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400536
537 #Verify set_vlan_priority is a supported action
538 sup_acts = sw_supported_actions(self,"true")
539 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
540 skip_message_emit(self, "modify_vlan_prio test skipped")
541 return
542
543 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
544 vid = 123
545 old_vlan_pcp = 2
546 new_vlan_pcp = 3
Rich Laned0478ff2013-03-11 12:46:58 -0700547 pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vid, vlan_pcp=old_vlan_pcp)
548 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vid, vlan_pcp=new_vlan_pcp)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800549 vid_act = ofp.action.set_vlan_pcp()
ShreyaPandita9306c772012-09-28 12:21:40 -0400550 vid_act.vlan_pcp = new_vlan_pcp
551
552 #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 -0700553 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400554 action_list=[vid_act])
555
556
Rich Laneb90a1c42012-10-05 09:16:05 -0700557class ModifyL2Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400558
559 """ModifyL2Src :Modify the source MAC address"""
560
561 def runTest(self):
562
Rich Lane9a003812012-10-04 17:17:59 -0700563 logging.info("Running Modify_L2_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400564
Rich Lane477f4812012-10-04 22:49:00 -0700565 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400566 of_ports.sort()
567 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
568
569 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800570 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400571
Rich Lane9a003812012-10-04 17:17:59 -0700572 logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
573 logging.info("Insert a flow with action -- set etherent src address")
574 logging.info("Send packet matching the flow, verify recieved packet src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400575
576 #Verify set_dl_src is a supported action
577 sup_acts = sw_supported_actions(self,use_cache="true")
578 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
579 skip_message_emit(self, "modify_l2_src test skipped")
580 return
581
Rich Laned0478ff2013-03-11 12:46:58 -0700582 #Create packet to be sent and expected packet with eth_src set to specified value
583 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['eth_src'],
ShreyaPandita9306c772012-09-28 12:21:40 -0400584 check_test_params=True)
585
586 #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 -0700587 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400588 action_list=acts, max_test=2)
589
590
Rich Laneb90a1c42012-10-05 09:16:05 -0700591class ModifyL2Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400592
593 """ModifyL2SDSt :Modify the dest MAC address"""
594
595 def runTest(self):
596
Rich Lane9a003812012-10-04 17:17:59 -0700597 logging.info("Running Modify_L2_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400598
Rich Lane477f4812012-10-04 22:49:00 -0700599 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400600 of_ports.sort()
601 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
602
603 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800604 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400605
Rich Lane9a003812012-10-04 17:17:59 -0700606 logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
607 logging.info("Insert a flow with action -- set etherent dst address ")
608 logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400609
610 #Verify set_dl_dst is a supported action
611 sup_acts = sw_supported_actions(self)
612 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
613 skip_message_emit(self, "modify_l2_dst test skipped")
614 return
615
Rich Laned0478ff2013-03-11 12:46:58 -0700616 #Create packet to be sent and expected packet with eth_src set to specified value
617 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['eth_dst'],
ShreyaPandita9306c772012-09-28 12:21:40 -0400618 check_test_params=True)
619
620 #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 -0700621 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400622 action_list=acts, max_test=2)
623
Rich Laneb90a1c42012-10-05 09:16:05 -0700624class ModifyL3Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400625
626 """ModifyL3Src : Modify the source IP address of an IP packet """
627
628 def runTest(self):
629
Rich Lane9a003812012-10-04 17:17:59 -0700630 logging.info("Running Modify_L3_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400631
Rich Lane477f4812012-10-04 22:49:00 -0700632 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400633 of_ports.sort()
634 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
635
636 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800637 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400638
Rich Lane9a003812012-10-04 17:17:59 -0700639 logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
640 logging.info("Insert a flow with action -- set network src address ")
641 logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400642
643 #Verify set_nw_src is a supported action
644 sup_acts = sw_supported_actions(self)
645 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
646 skip_message_emit(self, "modify_l3_src test")
647 return
648
Rich Laned0478ff2013-03-11 12:46:58 -0700649 #Create packet to be sent and expected packet with ipv4_src set to specified value
ShreyaPandita9306c772012-09-28 12:21:40 -0400650 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
651 check_test_params=True)
652
653 #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 -0700654 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400655 action_list=acts, max_test=2)
656
Rich Laneb90a1c42012-10-05 09:16:05 -0700657class ModifyL3Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400658
659 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
660
661 def runTest(self):
662
Rich Lane9a003812012-10-04 17:17:59 -0700663 logging.info("Running Modify_L3_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400664
Rich Lane477f4812012-10-04 22:49:00 -0700665 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400666 of_ports.sort()
667 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
668
669 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800670 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400671
Rich Lane9a003812012-10-04 17:17:59 -0700672 logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
673 logging.info("Insert a flow with action -- set network dst address ")
674 logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400675
676 #Verify set_nw_dst is a supported action
677 sup_acts = sw_supported_actions(self,use_cache="true")
678 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
679 skip_message_emit(self, "modify_l3_dst test skipped")
680 return
681
Rich Laned0478ff2013-03-11 12:46:58 -0700682 #Create packet to be sent and expected packet with ipv4_dst set to specified value
ShreyaPandita9306c772012-09-28 12:21:40 -0400683 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
684 check_test_params=True)
685
686 #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 -0700687 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400688 action_list=acts, max_test=2)
689
690
Rich Laneb90a1c42012-10-05 09:16:05 -0700691class ModifyL4Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400692
693 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
694
695 def runTest(self):
696
Rich Lane9a003812012-10-04 17:17:59 -0700697 logging.info("Running Modify_L4_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400698
Rich Lane477f4812012-10-04 22:49:00 -0700699 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400700 of_ports.sort()
701 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
702
703 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800704 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400705
Rich Lane9a003812012-10-04 17:17:59 -0700706 logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
707 logging.info("Insert a flow with action -- set src tcp port")
708 logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400709
710 #Verify set_tp_src is a supported action
711 sup_acts = sw_supported_actions(self,use_cache="true")
712 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
713 skip_message_emit(self, "modify_l4_src test skipped")
714 return
715
716 #Create packet to be sent and expected packet with tcp_src set to specified value
717 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
718 check_test_params=True)
719
720 #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 -0700721 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400722 action_list=acts, max_test=2)
723
Rich Laneb90a1c42012-10-05 09:16:05 -0700724class ModifyL4Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400725
726 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
727
728 def runTest(self):
729
Rich Lane9a003812012-10-04 17:17:59 -0700730 logging.info("Running Modify_L4_Dst 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("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
740 logging.info("Insert a flow with action -- set dst tcp port")
741 logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400742
743 #Verify set_tp_dst is a supported action
744 sup_acts = sw_supported_actions(self,use_cache="true")
745 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
746 skip_message_emit(self, "ModifyL4Dst test")
747 return
748
749 #Create packet to be sent and expected packet with tcp_dst set to specified value
750 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
751 check_test_params=True)
752
753 #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 -0700754 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400755 action_list=acts, max_test=2)
756
Rich Laneb90a1c42012-10-05 09:16:05 -0700757class ModifyTos(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400758
759 """ModifyTOS :Modify the IP type of service of an IP packet"""
760
761 def runTest(self):
762
Rich Lane9a003812012-10-04 17:17:59 -0700763 logging.info("Running Modify_Tos test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400764
Rich Lane477f4812012-10-04 22:49:00 -0700765 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400766 of_ports.sort()
767 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
768
769 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800770 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400771
Rich Lane9a003812012-10-04 17:17:59 -0700772 logging.info("Verify if switch supports the action -- modify_tos, if not skip the test")
773 logging.info("Insert a flow with action -- set type of service ")
774 logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400775
776 #Verify set_tos is a supported action
777 sup_acts = sw_supported_actions(self,use_cache="true")
778 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
779 skip_message_emit(self, "ModifyTOS test")
780 return
781
782 #Create packet to be sent and expected packet with TOS set to specified value
783 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
784 check_test_params=True)
785
786 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700787 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400788 action_list=acts, max_test=2, egr_count=-1)