blob: 494d941922d176c4f24890aa22cdab1d9261b6da [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
69 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1)
70 self.assertTrue(response is None,
71 'Packets not received on control plane')
72
73
Rich Laneb90a1c42012-10-05 09:16:05 -070074class Announcement(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040075
76 """Announcement : Get all supported actions by the switch.
77 Send OFPT_FEATURES_REQUEST to get features supported by sw."""
78
79 def runTest(self):
80
Rich Lane9a003812012-10-04 17:17:59 -070081 logging.info("Running Announcement test")
ShreyaPandita9306c772012-09-28 12:21:40 -040082
Rich Lane9a003812012-10-04 17:17:59 -070083 logging.info("Sending Features_Request")
84 logging.info("Expecting Features Reply with supported actions")
ShreyaPandita9306c772012-09-28 12:21:40 -040085
86 # Sending Features_Request
Rich Lane28fa9272013-03-08 16:00:25 -080087 request = ofp.message.features_request()
ShreyaPandita9306c772012-09-28 12:21:40 -040088 (reply, pkt) = self.controller.transact(request)
89 self.assertTrue(reply is not None, "Failed to get any reply")
Rich Laneb73808c2013-03-11 15:22:23 -070090 self.assertEqual(reply.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
ShreyaPandita9306c772012-09-28 12:21:40 -040091
92 supported_actions =[]
93 if(reply.actions &1<<ofp.OFPAT_OUTPUT):
94 supported_actions.append('OFPAT_OUTPUT')
95 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
96 supported_actions.append('OFPAT_SET_VLAN_VID')
97 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
98 supported_actions.append('OFPAT_SET_VLAN_PCP')
99 if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
100 supported_actions.append('OFPAT_STRIP_VLAN')
101 if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
102 supported_actions.append('OFPAT_SET_DL_SRC')
103 if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
104 supported_actions.append('OFPAT_SET_NW_SRC')
105 if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
106 supported_actions.append('OFPAT_SET_NW_DST')
107 if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
108 supported_actions.append('OFPAT_SET_NW_TOS')
109 if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
110 supported_actions.append('OFPAT_SET_TP_SRC')
111 if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
112 supported_actions.append('OFPAT_SET_TP_DST')
113 if(reply.actions &1<<ofp.OFPAT_VENDOR):
114 supported_actions.append('OFPAT_VENDOR')
115 if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
116 supported_actions.append('OFPAT_ENQUEUE')
117
Rich Lane9a003812012-10-04 17:17:59 -0700118 logging.info(supported_actions)
ShreyaPandita9306c772012-09-28 12:21:40 -0400119
120
Rich Laneb90a1c42012-10-05 09:16:05 -0700121class ForwardAll(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400122
123 """ForwardAll : Packet is sent to all dataplane ports
124 except ingress port when output action.port = OFPP_ALL"""
125
126 def runTest(self):
127
Rich Lane9a003812012-10-04 17:17:59 -0700128 logging.info("Running Forward_All test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400129
Rich Lane477f4812012-10-04 22:49:00 -0700130 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400131 of_ports.sort()
132 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
133
134 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800135 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400136
Rich Lane9a003812012-10-04 17:17:59 -0700137 logging.info("Insert a flow with output action port OFPP_ALL")
138 logging.info("Send packet matching the flow")
139 logging.info("Expecting packet on all dataplane ports except ingress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400140
141 #Create a packet
142 pkt = simple_tcp_packet()
143 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800144 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400145
146 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800147 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400148 ingress_port=of_ports[0]
149 match.in_port = ingress_port
150
151 #Create a flow mod with action.port = OFPP_ALL
Rich Laneba3f0e22013-03-11 16:43:57 -0700152 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400153 request.match = match
154 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
155 act.port = ofp.OFPP_ALL
Rich Lanec495d9e2013-03-08 17:43:36 -0800156 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400157
Rich Lane9a003812012-10-04 17:17:59 -0700158 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800159 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800160 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400161
162 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700163 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400164 self.dataplane.send(ingress_port, str(pkt))
165
166 #Verifying packets recieved on expected dataplane ports
167 yes_ports = set(of_ports).difference([ingress_port])
168 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
Rich Lane2014f9b2012-10-05 15:29:40 -0700169 self)
ShreyaPandita9306c772012-09-28 12:21:40 -0400170
171
Rich Laneb90a1c42012-10-05 09:16:05 -0700172class ForwardController(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400173
174 """ForwardController : Packet is sent to controller
175 output.port = OFPP_CONTROLLER"""
176
177 def runTest(self):
178
Rich Lane9a003812012-10-04 17:17:59 -0700179 logging.info("Running Forward_Controller test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400180
Rich Lane477f4812012-10-04 22:49:00 -0700181 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400182 of_ports.sort()
183 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
184
185 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800186 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400187
Rich Lane9a003812012-10-04 17:17:59 -0700188 logging.info("Insert a flow with output action port OFPP_CONTROLLER")
189 logging.info("Send packet matching the flow")
190 logging.info("Expecting packet on the control plane")
ShreyaPandita9306c772012-09-28 12:21:40 -0400191
192 #Create packet
193 pkt = simple_tcp_packet()
194 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800195 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400196
197 for ingress_port in of_ports:
198 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800199 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400200
201 match.in_port = ingress_port
202
203 #Create a flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700204 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400205 request.match = match
206 act.port = ofp.OFPP_CONTROLLER
Rich Lanec495d9e2013-03-08 17:43:36 -0800207 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400208
Rich Lane9a003812012-10-04 17:17:59 -0700209 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800210 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800211 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400212
213 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700214 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400215 self.dataplane.send(ingress_port, str(pkt))
216
217 #Verifying packet recieved on the control plane port
218 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10)
219 self.assertTrue(response is not None,
220 'Packet in message not received by controller')
221
222
223
Rich Laneb90a1c42012-10-05 09:16:05 -0700224class ForwardLocal(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400225
226 """ForwardLocal : Packet is sent to OFPP_LOCAL port .
227 TBD : To verify packet recieved in the local networking stack of switch"""
228
229 def runTest(self):
230
Rich Lane9a003812012-10-04 17:17:59 -0700231 logging.info("Running Forward_Local test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400232
Rich Lane477f4812012-10-04 22:49:00 -0700233 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400234 of_ports.sort()
235 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
236
237 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800238 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400239
Rich Lane9a003812012-10-04 17:17:59 -0700240 logging.info("Insert a flow with output action port OFPP_LOCAL")
241 logging.info("Send packet matching the flow")
242 logging.info("Expecting packet in the local networking stack of switch")
ShreyaPandita9306c772012-09-28 12:21:40 -0400243
244 #Clear switch state
245 pkt = simple_tcp_packet()
246 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800247 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400248
249 for ingress_port in of_ports:
250 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800251 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400252
253 match.in_port = ingress_port
254 #Create flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700255 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400256 request.match = match
257 act.port = ofp.OFPP_LOCAL
Rich Lanec495d9e2013-03-08 17:43:36 -0800258 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400259
Rich Lane9a003812012-10-04 17:17:59 -0700260 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800261 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800262 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400263
264 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700265 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400266 self.dataplane.send(ingress_port, str(pkt))
267
268 #TBD: Verification of packets being recieved.
269
270
Rich Laneb90a1c42012-10-05 09:16:05 -0700271class ForwardFlood(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400272
273 """Forward:Flood : Packet is sent to all dataplane ports
274 except ingress port when output action.port = OFPP_FLOOD
275 TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
276 not including the incoming interface. """
277
278 def runTest(self):
279
Rich Lane9a003812012-10-04 17:17:59 -0700280 logging.info("Running Forward_Flood test")
Rich Lane477f4812012-10-04 22:49:00 -0700281 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400282 of_ports.sort()
283 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
284
285 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800286 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400287
Rich Lane9a003812012-10-04 17:17:59 -0700288 logging.info("Insert a flow with output action port OFPP_FORWARD")
289 logging.info("Send packet matching the flow")
290 logging.info("Expecting packet on all the ports except the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400291
292 #Create a packet
293 pkt = simple_tcp_packet()
294 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800295 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400296
297 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800298 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400299 ingress_port=of_ports[0]
300 match.in_port = ingress_port
301
302 #Create a flow mod with action.port = OFPP_ALL
Rich Laneba3f0e22013-03-11 16:43:57 -0700303 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400304 request.match = match
305 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
306 act.port = ofp.OFPP_FLOOD
Rich Lanec495d9e2013-03-08 17:43:36 -0800307 request.actions.append(act)
ShreyaPandita9306c772012-09-28 12:21:40 -0400308
Rich Lane9a003812012-10-04 17:17:59 -0700309 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800310 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800311 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400312
313 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700314 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400315 self.dataplane.send(ingress_port, str(pkt))
316
317 #Verifying packets recieved on expected dataplane ports
318 yes_ports = set(of_ports).difference([ingress_port])
319 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
Rich Lane2014f9b2012-10-05 15:29:40 -0700320 self)
ShreyaPandita9306c772012-09-28 12:21:40 -0400321
Rich Laneb90a1c42012-10-05 09:16:05 -0700322class ForwardInport(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400323
324 """ ForwardInPort : Packet sent to virtual port IN_PORT
325 If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
326
327 def runTest(self):
328
Rich Lane9a003812012-10-04 17:17:59 -0700329 logging.info("Running Forward_Inport test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400330
Rich Lane477f4812012-10-04 22:49:00 -0700331 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400332 of_ports.sort()
333 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
334
335 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800336 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400337
Rich Lane9a003812012-10-04 17:17:59 -0700338 logging.info("Insert a flow with output action port OFPP_INPORT")
339 logging.info("Send packet matching the flow")
340 logging.info("Expecting packet on the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400341
342 #Create a packet
343 pkt = simple_tcp_packet()
344 match = parse.packet_to_flow_match(pkt)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800345 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400346
347 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800348 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400349 ingress_port=of_ports[0]
350 match.in_port = ingress_port
351
352 # Create a flow mod message
Rich Laneba3f0e22013-03-11 16:43:57 -0700353 request = ofp.message.flow_add()
ShreyaPandita9306c772012-09-28 12:21:40 -0400354 request.match = match
355 act.port = ofp.OFPP_IN_PORT
356
Rich Lanec495d9e2013-03-08 17:43:36 -0800357 request.actions.append(act)
Rich Lane9a003812012-10-04 17:17:59 -0700358 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800359 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800360 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400361
362 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700363 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400364 self.dataplane.send(ingress_port, str(pkt))
365 yes_ports = [ingress_port]
366
367 #Verfying packet recieved on expected dataplane ports
368 receive_pkt_check(self.dataplane, pkt, yes_ports,set(of_ports).difference([ingress_port]),
Rich Lane2014f9b2012-10-05 15:29:40 -0700369 self)
ShreyaPandita9306c772012-09-28 12:21:40 -0400370
Rich Laneb90a1c42012-10-05 09:16:05 -0700371class ForwardTable(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400372
373 """ForwardTable : Perform actions in flow table. Only for packet-out messages.
374 If the output action.port in the packetout message = OFP.TABLE , then
375 the packet implements the action specified in the matching flow of the FLOW-TABLE"""
376
377 def runTest(self):
378
Rich Lane9a003812012-10-04 17:17:59 -0700379 logging.info("Running Forward_Table test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400380
Rich Lane477f4812012-10-04 22:49:00 -0700381 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400382 of_ports.sort()
383 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
384
385 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800386 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400387
Rich Lane9a003812012-10-04 17:17:59 -0700388 logging.info("Insert a flow F with output action port set to some egress_port")
389 logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
390 logging.info("Expecting packet on the egress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400391
392 #Insert a all wildcarded flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400393 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400394
395 #Create a packet out message
Rich Lane28fa9272013-03-08 16:00:25 -0800396 pkt_out =ofp.message.packet_out();
ShreyaPandita9306c772012-09-28 12:21:40 -0400397 pkt_out.data = str(pkt)
398 pkt_out.in_port = of_ports[0]
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800399 act = ofp.action.output()
ShreyaPandita9306c772012-09-28 12:21:40 -0400400 act.port = ofp.OFPP_TABLE
Rich Lanec495d9e2013-03-08 17:43:36 -0800401 pkt_out.actions.append(act)
Rich Lane5c3151c2013-01-03 17:15:41 -0800402 self.controller.message_send(pkt_out)
ShreyaPandita9306c772012-09-28 12:21:40 -0400403
404 #Verifying packet out message recieved on the expected dataplane port.
405 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
406 exp_pkt=pkt,timeout=3)
407 self.assertTrue(pkt is not None, 'Packet not received')
408
409
Rich Laneb90a1c42012-10-05 09:16:05 -0700410class AddVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400411
412 """AddVlanTag : Adds VLAN Tag to untagged packet."""
413
414 def runTest(self):
415
Rich Lane9a003812012-10-04 17:17:59 -0700416 logging.info("Running Add_vlan_tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400417
Rich Lane477f4812012-10-04 22:49:00 -0700418 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400419 of_ports.sort()
420 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
421
422 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800423 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400424
Rich Lane9a003812012-10-04 17:17:59 -0700425 logging.info("Verify if switch supports the action -- set vlan id, if not skip the test")
426 logging.info("Insert a flow with set vid action")
427 logging.info("Send packet matching the flow , verify recieved packet has vid set")
ShreyaPandita9306c772012-09-28 12:21:40 -0400428
429 #Verify set_vlan_id is a supported action
430 sup_acts = sw_supported_actions(self)
431 if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
432 skip_message_emit(self, "Add VLAN tag test skipped")
433 return
434
435 #Create packet to be sent and an expected packet with vid set
436 new_vid = 2
437 len_wo_vid = 100
438 len_w_vid = 104
439 pkt = simple_tcp_packet(pktlen=len_wo_vid)
440 exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True,
Rich Laned0478ff2013-03-11 12:46:58 -0700441 vlan_vid=new_vid,vlan_pcp=0)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800442 vid_act = ofp.action.set_vlan_vid()
ShreyaPandita9306c772012-09-28 12:21:40 -0400443 vid_act.vlan_vid = new_vid
444
445 #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700446 flow_match_test(self, config["port_map"], pkt=pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400447 exp_pkt=exp_pkt, action_list=[vid_act])
448
Rich Laneb90a1c42012-10-05 09:16:05 -0700449class ModifyVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400450
451 """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
452
453 def runTest(self):
454
Rich Lane9a003812012-10-04 17:17:59 -0700455 logging.info("Running Modify_Vlan_Tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400456
Rich Lane477f4812012-10-04 22:49:00 -0700457 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400458 of_ports.sort()
459 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
460
461 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800462 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400463
Rich Lane9a003812012-10-04 17:17:59 -0700464 logging.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
465 logging.info("Insert a flow with action --set vid ")
466 logging.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400467
468 #Verify set_vlan_id is a supported action
469 sup_acts = sw_supported_actions(self)
470 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
471 skip_message_emit(self, "Modify VLAN tag test skipped")
472 return
473
474 #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
475 old_vid = 2
476 new_vid = 3
Rich Laned0478ff2013-03-11 12:46:58 -0700477 pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=old_vid)
478 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=new_vid)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800479 vid_act = ofp.action.set_vlan_vid()
ShreyaPandita9306c772012-09-28 12:21:40 -0400480 vid_act.vlan_vid = new_vid
481
482 #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
Rich Lane477f4812012-10-04 22:49:00 -0700483 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400484 action_list=[vid_act])
485
Rich Laneb90a1c42012-10-05 09:16:05 -0700486class VlanPrio1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400487
488 """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
489
490 def runTest(self):
491
Rich Lane9a003812012-10-04 17:17:59 -0700492 logging.info("Running vlan_Prio_1 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400493
Rich Lane477f4812012-10-04 22:49:00 -0700494 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400495 of_ports.sort()
496 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
497
498 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800499 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400500
Rich Lane9a003812012-10-04 17:17:59 -0700501 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
502 logging.info("Insert a flow with action -- set vlan priority ")
503 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 -0400504
505 #Verify set_vlan_priority is a supported action
506 sup_acts = sw_supported_actions(self)
507 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
508 skip_message_emit(self, "Set VLAN priority test skipped")
509 return
510
511 #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set.
512 vlan_id = 0
Rich Lane123928c2012-10-04 21:28:53 -0700513 vlan_pcp = 1
Dan Talayco3bfc8222013-02-13 18:18:57 -0800514 pktlen = 64 if config["minsize"] < 64 else config["minsize"]
515 pkt = simple_tcp_packet(pktlen=pktlen)
Rich Laned0478ff2013-03-11 12:46:58 -0700516 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 -0800517 act = ofp.action.set_vlan_pcp()
Rich Lane123928c2012-10-04 21:28:53 -0700518 act.vlan_pcp = vlan_pcp
ShreyaPandita9306c772012-09-28 12:21:40 -0400519
520 #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 -0700521 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400522 action_list=[act])
523
524
Rich Laneb90a1c42012-10-05 09:16:05 -0700525class VlanPrio2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400526
527 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
528
529 def runTest(self):
530
Rich Lane9a003812012-10-04 17:17:59 -0700531 logging.info("Running Vlan_Prio_2 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400532
Rich Lane477f4812012-10-04 22:49:00 -0700533 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400534 of_ports.sort()
535 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
536
537 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800538 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400539
Rich Lane9a003812012-10-04 17:17:59 -0700540 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
541 logging.info("Insert a flow with action -- set vlan priority ")
542 logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400543
544 #Verify set_vlan_priority is a supported action
545 sup_acts = sw_supported_actions(self,"true")
546 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
547 skip_message_emit(self, "modify_vlan_prio test skipped")
548 return
549
550 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
551 vid = 123
552 old_vlan_pcp = 2
553 new_vlan_pcp = 3
Rich Laned0478ff2013-03-11 12:46:58 -0700554 pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vid, vlan_pcp=old_vlan_pcp)
555 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vid, vlan_pcp=new_vlan_pcp)
Rich Lane9d3cc6b2013-03-08 16:33:08 -0800556 vid_act = ofp.action.set_vlan_pcp()
ShreyaPandita9306c772012-09-28 12:21:40 -0400557 vid_act.vlan_pcp = new_vlan_pcp
558
559 #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 -0700560 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400561 action_list=[vid_act])
562
563
Rich Laneb90a1c42012-10-05 09:16:05 -0700564class ModifyL2Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400565
566 """ModifyL2Src :Modify the source MAC address"""
567
568 def runTest(self):
569
Rich Lane9a003812012-10-04 17:17:59 -0700570 logging.info("Running Modify_L2_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400571
Rich Lane477f4812012-10-04 22:49:00 -0700572 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400573 of_ports.sort()
574 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
575
576 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800577 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400578
Rich Lane9a003812012-10-04 17:17:59 -0700579 logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
580 logging.info("Insert a flow with action -- set etherent src address")
581 logging.info("Send packet matching the flow, verify recieved packet src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400582
583 #Verify set_dl_src is a supported action
584 sup_acts = sw_supported_actions(self,use_cache="true")
585 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
586 skip_message_emit(self, "modify_l2_src test skipped")
587 return
588
Rich Laned0478ff2013-03-11 12:46:58 -0700589 #Create packet to be sent and expected packet with eth_src set to specified value
590 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['eth_src'],
ShreyaPandita9306c772012-09-28 12:21:40 -0400591 check_test_params=True)
592
593 #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 -0700594 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400595 action_list=acts, max_test=2)
596
597
Rich Laneb90a1c42012-10-05 09:16:05 -0700598class ModifyL2Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400599
600 """ModifyL2SDSt :Modify the dest MAC address"""
601
602 def runTest(self):
603
Rich Lane9a003812012-10-04 17:17:59 -0700604 logging.info("Running Modify_L2_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400605
Rich Lane477f4812012-10-04 22:49:00 -0700606 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400607 of_ports.sort()
608 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
609
610 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800611 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400612
Rich Lane9a003812012-10-04 17:17:59 -0700613 logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
614 logging.info("Insert a flow with action -- set etherent dst address ")
615 logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400616
617 #Verify set_dl_dst is a supported action
618 sup_acts = sw_supported_actions(self)
619 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
620 skip_message_emit(self, "modify_l2_dst test skipped")
621 return
622
Rich Laned0478ff2013-03-11 12:46:58 -0700623 #Create packet to be sent and expected packet with eth_src set to specified value
624 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['eth_dst'],
ShreyaPandita9306c772012-09-28 12:21:40 -0400625 check_test_params=True)
626
627 #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 -0700628 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400629 action_list=acts, max_test=2)
630
Rich Laneb90a1c42012-10-05 09:16:05 -0700631class ModifyL3Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400632
633 """ModifyL3Src : Modify the source IP address of an IP packet """
634
635 def runTest(self):
636
Rich Lane9a003812012-10-04 17:17:59 -0700637 logging.info("Running Modify_L3_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400638
Rich Lane477f4812012-10-04 22:49:00 -0700639 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400640 of_ports.sort()
641 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
642
643 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800644 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400645
Rich Lane9a003812012-10-04 17:17:59 -0700646 logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
647 logging.info("Insert a flow with action -- set network src address ")
648 logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400649
650 #Verify set_nw_src is a supported action
651 sup_acts = sw_supported_actions(self)
652 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
653 skip_message_emit(self, "modify_l3_src test")
654 return
655
Rich Laned0478ff2013-03-11 12:46:58 -0700656 #Create packet to be sent and expected packet with ipv4_src set to specified value
ShreyaPandita9306c772012-09-28 12:21:40 -0400657 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
658 check_test_params=True)
659
660 #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 -0700661 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400662 action_list=acts, max_test=2)
663
Rich Laneb90a1c42012-10-05 09:16:05 -0700664class ModifyL3Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400665
666 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
667
668 def runTest(self):
669
Rich Lane9a003812012-10-04 17:17:59 -0700670 logging.info("Running Modify_L3_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400671
Rich Lane477f4812012-10-04 22:49:00 -0700672 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400673 of_ports.sort()
674 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
675
676 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800677 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400678
Rich Lane9a003812012-10-04 17:17:59 -0700679 logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
680 logging.info("Insert a flow with action -- set network dst address ")
681 logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400682
683 #Verify set_nw_dst is a supported action
684 sup_acts = sw_supported_actions(self,use_cache="true")
685 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
686 skip_message_emit(self, "modify_l3_dst test skipped")
687 return
688
Rich Laned0478ff2013-03-11 12:46:58 -0700689 #Create packet to be sent and expected packet with ipv4_dst set to specified value
ShreyaPandita9306c772012-09-28 12:21:40 -0400690 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
691 check_test_params=True)
692
693 #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 -0700694 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400695 action_list=acts, max_test=2)
696
697
Rich Laneb90a1c42012-10-05 09:16:05 -0700698class ModifyL4Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400699
700 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
701
702 def runTest(self):
703
Rich Lane9a003812012-10-04 17:17:59 -0700704 logging.info("Running Modify_L4_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400705
Rich Lane477f4812012-10-04 22:49:00 -0700706 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400707 of_ports.sort()
708 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
709
710 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800711 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400712
Rich Lane9a003812012-10-04 17:17:59 -0700713 logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
714 logging.info("Insert a flow with action -- set src tcp port")
715 logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400716
717 #Verify set_tp_src is a supported action
718 sup_acts = sw_supported_actions(self,use_cache="true")
719 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
720 skip_message_emit(self, "modify_l4_src test skipped")
721 return
722
723 #Create packet to be sent and expected packet with tcp_src set to specified value
724 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
725 check_test_params=True)
726
727 #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 -0700728 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400729 action_list=acts, max_test=2)
730
Rich Laneb90a1c42012-10-05 09:16:05 -0700731class ModifyL4Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400732
733 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
734
735 def runTest(self):
736
Rich Lane9a003812012-10-04 17:17:59 -0700737 logging.info("Running Modify_L4_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400738
Rich Lane477f4812012-10-04 22:49:00 -0700739 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400740 of_ports.sort()
741 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
742
743 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800744 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400745
Rich Lane9a003812012-10-04 17:17:59 -0700746 logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
747 logging.info("Insert a flow with action -- set dst tcp port")
748 logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400749
750 #Verify set_tp_dst is a supported action
751 sup_acts = sw_supported_actions(self,use_cache="true")
752 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
753 skip_message_emit(self, "ModifyL4Dst test")
754 return
755
756 #Create packet to be sent and expected packet with tcp_dst set to specified value
757 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
758 check_test_params=True)
759
760 #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 -0700761 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400762 action_list=acts, max_test=2)
763
Rich Laneb90a1c42012-10-05 09:16:05 -0700764class ModifyTos(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400765
766 """ModifyTOS :Modify the IP type of service of an IP packet"""
767
768 def runTest(self):
769
Rich Lane9a003812012-10-04 17:17:59 -0700770 logging.info("Running Modify_Tos test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400771
Rich Lane477f4812012-10-04 22:49:00 -0700772 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400773 of_ports.sort()
774 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
775
776 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800777 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400778
Rich Lane9a003812012-10-04 17:17:59 -0700779 logging.info("Verify if switch supports the action -- modify_tos, if not skip the test")
780 logging.info("Insert a flow with action -- set type of service ")
781 logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400782
783 #Verify set_tos is a supported action
784 sup_acts = sw_supported_actions(self,use_cache="true")
785 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
786 skip_message_emit(self, "ModifyTOS test")
787 return
788
789 #Create packet to be sent and expected packet with TOS set to specified value
790 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
791 check_test_params=True)
792
793 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700794 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400795 action_list=acts, max_test=2, egr_count=-1)