blob: 8be69dc625a822a727fb6d6faac90f091a806ac5 [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
17import oftest.cstruct as ofp
18import oftest.message as message
19import oftest.dataplane as dataplane
20import oftest.action as action
21import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070022import oftest.base_tests as base_tests
ShreyaPandita9306c772012-09-28 12:21:40 -040023
Rich Laneda3b5ad2012-10-03 09:05:32 -070024from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040025from time import sleep
26from FuncUtils import *
27
Rich Laneb90a1c42012-10-05 09:16:05 -070028class NoAction(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040029
30 """NoActionDrop : no action added to flow , drops the packet."""
31
32 def runTest(self):
33
Rich Lane9a003812012-10-04 17:17:59 -070034 logging.info("Running No_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -040035
Rich Lane477f4812012-10-04 22:49:00 -070036 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -040037 of_ports.sort()
38 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
39
40 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -080041 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040042
Rich Lane9a003812012-10-04 17:17:59 -070043 logging.info("Install a flow without action")
44 logging.info("Send packets matching that flow")
45 logging.info("Expecting switch to drop all packets")
ShreyaPandita9306c772012-09-28 12:21:40 -040046
47 # Insert a flow wildcard all without any action
48 pkt = simple_tcp_packet()
49 match = parse.packet_to_flow_match(pkt)
50 self.assertTrue(match is not None, "Could not generate flow match from pkt")
51 match.wildcards=ofp.OFPFW_ALL
52 match.in_port = of_ports[0]
53
54 msg = message.flow_mod()
55 msg.out_port = ofp.OFPP_NONE
56 msg.command = ofp.OFPFC_ADD
57 msg.buffer_id = 0xffffffff
58 msg.match = match
Rich Lane5c3151c2013-01-03 17:15:41 -080059 self.controller.message_send(msg)
Rich Lane3a261d52013-01-03 17:45:08 -080060 do_barrier(self.controller)
ShreyaPanditab46f8522012-09-28 15:12:15 -040061
ShreyaPandita9306c772012-09-28 12:21:40 -040062 #Sending N packets matching the flow inserted
63 for pkt_cnt in range(5):
64 self.dataplane.send(of_ports[0],str(pkt))
65
66 #Verify packets not recieved on any of the dataplane ports
ShreyaPandita7b9ec982012-09-28 14:43:08 -040067 (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1,exp_pkt=pkt)
68 self.assertTrue(rcv_pkt is None,
ShreyaPanditad4a42c62012-09-28 15:35:27 -040069 "Packet received on port " + str(rcv_port))
ShreyaPandita9306c772012-09-28 12:21:40 -040070
71 #Verify packets not sent on control plane either
72 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1)
73 self.assertTrue(response is None,
74 'Packets not received on control plane')
75
76
Rich Laneb90a1c42012-10-05 09:16:05 -070077class Announcement(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -040078
79 """Announcement : Get all supported actions by the switch.
80 Send OFPT_FEATURES_REQUEST to get features supported by sw."""
81
82 def runTest(self):
83
Rich Lane9a003812012-10-04 17:17:59 -070084 logging.info("Running Announcement test")
ShreyaPandita9306c772012-09-28 12:21:40 -040085
Rich Lane9a003812012-10-04 17:17:59 -070086 logging.info("Sending Features_Request")
87 logging.info("Expecting Features Reply with supported actions")
ShreyaPandita9306c772012-09-28 12:21:40 -040088
89 # Sending Features_Request
90 request = message.features_request()
91 (reply, pkt) = self.controller.transact(request)
92 self.assertTrue(reply is not None, "Failed to get any reply")
93 self.assertEqual(reply.header.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
94
95 supported_actions =[]
96 if(reply.actions &1<<ofp.OFPAT_OUTPUT):
97 supported_actions.append('OFPAT_OUTPUT')
98 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
99 supported_actions.append('OFPAT_SET_VLAN_VID')
100 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
101 supported_actions.append('OFPAT_SET_VLAN_PCP')
102 if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
103 supported_actions.append('OFPAT_STRIP_VLAN')
104 if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
105 supported_actions.append('OFPAT_SET_DL_SRC')
106 if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
107 supported_actions.append('OFPAT_SET_NW_SRC')
108 if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
109 supported_actions.append('OFPAT_SET_NW_DST')
110 if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
111 supported_actions.append('OFPAT_SET_NW_TOS')
112 if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
113 supported_actions.append('OFPAT_SET_TP_SRC')
114 if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
115 supported_actions.append('OFPAT_SET_TP_DST')
116 if(reply.actions &1<<ofp.OFPAT_VENDOR):
117 supported_actions.append('OFPAT_VENDOR')
118 if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
119 supported_actions.append('OFPAT_ENQUEUE')
120
Rich Lane9a003812012-10-04 17:17:59 -0700121 logging.info(supported_actions)
ShreyaPandita9306c772012-09-28 12:21:40 -0400122
123
Rich Laneb90a1c42012-10-05 09:16:05 -0700124class ForwardAll(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400125
126 """ForwardAll : Packet is sent to all dataplane ports
127 except ingress port when output action.port = OFPP_ALL"""
128
129 def runTest(self):
130
Rich Lane9a003812012-10-04 17:17:59 -0700131 logging.info("Running Forward_All test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400132
Rich Lane477f4812012-10-04 22:49:00 -0700133 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400134 of_ports.sort()
135 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
136
137 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800138 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400139
Rich Lane9a003812012-10-04 17:17:59 -0700140 logging.info("Insert a flow with output action port OFPP_ALL")
141 logging.info("Send packet matching the flow")
142 logging.info("Expecting packet on all dataplane ports except ingress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400143
144 #Create a packet
145 pkt = simple_tcp_packet()
146 match = parse.packet_to_flow_match(pkt)
147 act = action.action_output()
148
149 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800150 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400151 ingress_port=of_ports[0]
152 match.in_port = ingress_port
153
154 #Create a flow mod with action.port = OFPP_ALL
155 request = message.flow_mod()
156 request.match = match
157 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
158 act.port = ofp.OFPP_ALL
159 request.actions.add(act)
160
Rich Lane9a003812012-10-04 17:17:59 -0700161 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800162 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800163 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400164
165 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700166 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400167 self.dataplane.send(ingress_port, str(pkt))
168
169 #Verifying packets recieved on expected dataplane ports
170 yes_ports = set(of_ports).difference([ingress_port])
171 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
Rich Lane2014f9b2012-10-05 15:29:40 -0700172 self)
ShreyaPandita9306c772012-09-28 12:21:40 -0400173
174
Rich Laneb90a1c42012-10-05 09:16:05 -0700175class ForwardController(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400176
177 """ForwardController : Packet is sent to controller
178 output.port = OFPP_CONTROLLER"""
179
180 def runTest(self):
181
Rich Lane9a003812012-10-04 17:17:59 -0700182 logging.info("Running Forward_Controller test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400183
Rich Lane477f4812012-10-04 22:49:00 -0700184 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400185 of_ports.sort()
186 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
187
188 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800189 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400190
Rich Lane9a003812012-10-04 17:17:59 -0700191 logging.info("Insert a flow with output action port OFPP_CONTROLLER")
192 logging.info("Send packet matching the flow")
193 logging.info("Expecting packet on the control plane")
ShreyaPandita9306c772012-09-28 12:21:40 -0400194
195 #Create packet
196 pkt = simple_tcp_packet()
197 match = parse.packet_to_flow_match(pkt)
198 act = action.action_output()
199
200 for ingress_port in of_ports:
201 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800202 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400203
204 match.in_port = ingress_port
205
206 #Create a flow mod message
207 request = message.flow_mod()
208 request.match = match
209 act.port = ofp.OFPP_CONTROLLER
210 request.actions.add(act)
211
Rich Lane9a003812012-10-04 17:17:59 -0700212 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800213 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800214 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400215
216 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700217 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400218 self.dataplane.send(ingress_port, str(pkt))
219
220 #Verifying packet recieved on the control plane port
221 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10)
222 self.assertTrue(response is not None,
223 'Packet in message not received by controller')
224
225
226
Rich Laneb90a1c42012-10-05 09:16:05 -0700227class ForwardLocal(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400228
229 """ForwardLocal : Packet is sent to OFPP_LOCAL port .
230 TBD : To verify packet recieved in the local networking stack of switch"""
231
232 def runTest(self):
233
Rich Lane9a003812012-10-04 17:17:59 -0700234 logging.info("Running Forward_Local test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400235
Rich Lane477f4812012-10-04 22:49:00 -0700236 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400237 of_ports.sort()
238 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
239
240 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800241 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400242
Rich Lane9a003812012-10-04 17:17:59 -0700243 logging.info("Insert a flow with output action port OFPP_LOCAL")
244 logging.info("Send packet matching the flow")
245 logging.info("Expecting packet in the local networking stack of switch")
ShreyaPandita9306c772012-09-28 12:21:40 -0400246
247 #Clear switch state
248 pkt = simple_tcp_packet()
249 match = parse.packet_to_flow_match(pkt)
250 act = action.action_output()
251
252 for ingress_port in of_ports:
253 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800254 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400255
256 match.in_port = ingress_port
257 #Create flow mod message
258 request = message.flow_mod()
259 request.match = match
260 act.port = ofp.OFPP_LOCAL
261 request.actions.add(act)
262
Rich Lane9a003812012-10-04 17:17:59 -0700263 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800264 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800265 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400266
267 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700268 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400269 self.dataplane.send(ingress_port, str(pkt))
270
271 #TBD: Verification of packets being recieved.
272
273
Rich Laneb90a1c42012-10-05 09:16:05 -0700274class ForwardFlood(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400275
276 """Forward:Flood : Packet is sent to all dataplane ports
277 except ingress port when output action.port = OFPP_FLOOD
278 TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
279 not including the incoming interface. """
280
281 def runTest(self):
282
Rich Lane9a003812012-10-04 17:17:59 -0700283 logging.info("Running Forward_Flood test")
Rich Lane477f4812012-10-04 22:49:00 -0700284 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400285 of_ports.sort()
286 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
287
288 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800289 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400290
Rich Lane9a003812012-10-04 17:17:59 -0700291 logging.info("Insert a flow with output action port OFPP_FORWARD")
292 logging.info("Send packet matching the flow")
293 logging.info("Expecting packet on all the ports except the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400294
295 #Create a packet
296 pkt = simple_tcp_packet()
297 match = parse.packet_to_flow_match(pkt)
298 act = action.action_output()
299
300 #Delete all flows
Rich Lane32bf9482013-01-03 17:26:30 -0800301 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400302 ingress_port=of_ports[0]
303 match.in_port = ingress_port
304
305 #Create a flow mod with action.port = OFPP_ALL
306 request = message.flow_mod()
307 request.match = match
308 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
309 act.port = ofp.OFPP_FLOOD
310 request.actions.add(act)
311
Rich Lane9a003812012-10-04 17:17:59 -0700312 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800313 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800314 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400315
316 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700317 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400318 self.dataplane.send(ingress_port, str(pkt))
319
320 #Verifying packets recieved on expected dataplane ports
321 yes_ports = set(of_ports).difference([ingress_port])
322 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
Rich Lane2014f9b2012-10-05 15:29:40 -0700323 self)
ShreyaPandita9306c772012-09-28 12:21:40 -0400324
Rich Laneb90a1c42012-10-05 09:16:05 -0700325class ForwardInport(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400326
327 """ ForwardInPort : Packet sent to virtual port IN_PORT
328 If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
329
330 def runTest(self):
331
Rich Lane9a003812012-10-04 17:17:59 -0700332 logging.info("Running Forward_Inport test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400333
Rich Lane477f4812012-10-04 22:49:00 -0700334 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400335 of_ports.sort()
336 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
337
338 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800339 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400340
Rich Lane9a003812012-10-04 17:17:59 -0700341 logging.info("Insert a flow with output action port OFPP_INPORT")
342 logging.info("Send packet matching the flow")
343 logging.info("Expecting packet on the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400344
345 #Create a packet
346 pkt = simple_tcp_packet()
347 match = parse.packet_to_flow_match(pkt)
348 act = action.action_output()
349
350 #Delete the flows
Rich Lane32bf9482013-01-03 17:26:30 -0800351 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400352 ingress_port=of_ports[0]
353 match.in_port = ingress_port
354
355 # Create a flow mod message
356 request = message.flow_mod()
357 request.match = match
358 act.port = ofp.OFPP_IN_PORT
359
360 request.actions.add(act)
Rich Lane9a003812012-10-04 17:17:59 -0700361 logging.info("Inserting flow")
Rich Lane5c3151c2013-01-03 17:15:41 -0800362 self.controller.message_send(request)
Rich Lane3a261d52013-01-03 17:45:08 -0800363 do_barrier(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400364
365 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700366 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400367 self.dataplane.send(ingress_port, str(pkt))
368 yes_ports = [ingress_port]
369
370 #Verfying packet recieved on expected dataplane ports
371 receive_pkt_check(self.dataplane, pkt, yes_ports,set(of_ports).difference([ingress_port]),
Rich Lane2014f9b2012-10-05 15:29:40 -0700372 self)
ShreyaPandita9306c772012-09-28 12:21:40 -0400373
Rich Laneb90a1c42012-10-05 09:16:05 -0700374class ForwardTable(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400375
376 """ForwardTable : Perform actions in flow table. Only for packet-out messages.
377 If the output action.port in the packetout message = OFP.TABLE , then
378 the packet implements the action specified in the matching flow of the FLOW-TABLE"""
379
380 def runTest(self):
381
Rich Lane9a003812012-10-04 17:17:59 -0700382 logging.info("Running Forward_Table test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400383
Rich Lane477f4812012-10-04 22:49:00 -0700384 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400385 of_ports.sort()
386 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
387
388 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800389 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400390
Rich Lane9a003812012-10-04 17:17:59 -0700391 logging.info("Insert a flow F with output action port set to some egress_port")
392 logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
393 logging.info("Expecting packet on the egress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400394
395 #Insert a all wildcarded flow
ShreyaPandita8dab4662012-11-02 13:40:14 -0400396 (pkt,match) = wildcard_all(self,of_ports)
ShreyaPandita9306c772012-09-28 12:21:40 -0400397
398 #Create a packet out message
399 pkt_out =message.packet_out();
400 pkt_out.data = str(pkt)
401 pkt_out.in_port = of_ports[0]
402 act = action.action_output()
403 act.port = ofp.OFPP_TABLE
404 pkt_out.actions.add(act)
Rich Lane5c3151c2013-01-03 17:15:41 -0800405 self.controller.message_send(pkt_out)
ShreyaPandita9306c772012-09-28 12:21:40 -0400406
407 #Verifying packet out message recieved on the expected dataplane port.
408 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
409 exp_pkt=pkt,timeout=3)
410 self.assertTrue(pkt is not None, 'Packet not received')
411
412
Rich Laneb90a1c42012-10-05 09:16:05 -0700413class AddVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400414
415 """AddVlanTag : Adds VLAN Tag to untagged packet."""
416
417 def runTest(self):
418
Rich Lane9a003812012-10-04 17:17:59 -0700419 logging.info("Running Add_vlan_tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400420
Rich Lane477f4812012-10-04 22:49:00 -0700421 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400422 of_ports.sort()
423 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
424
425 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800426 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400427
Rich Lane9a003812012-10-04 17:17:59 -0700428 logging.info("Verify if switch supports the action -- set vlan id, if not skip the test")
429 logging.info("Insert a flow with set vid action")
430 logging.info("Send packet matching the flow , verify recieved packet has vid set")
ShreyaPandita9306c772012-09-28 12:21:40 -0400431
432 #Verify set_vlan_id is a supported action
433 sup_acts = sw_supported_actions(self)
434 if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
435 skip_message_emit(self, "Add VLAN tag test skipped")
436 return
437
438 #Create packet to be sent and an expected packet with vid set
439 new_vid = 2
440 len_wo_vid = 100
441 len_w_vid = 104
442 pkt = simple_tcp_packet(pktlen=len_wo_vid)
443 exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True,
444 dl_vlan=new_vid,dl_vlan_pcp=0)
445 vid_act = action.action_set_vlan_vid()
446 vid_act.vlan_vid = new_vid
447
448 #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700449 flow_match_test(self, config["port_map"], pkt=pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400450 exp_pkt=exp_pkt, action_list=[vid_act])
451
Rich Laneb90a1c42012-10-05 09:16:05 -0700452class ModifyVlanTag(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400453
454 """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
455
456 def runTest(self):
457
Rich Lane9a003812012-10-04 17:17:59 -0700458 logging.info("Running Modify_Vlan_Tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400459
Rich Lane477f4812012-10-04 22:49:00 -0700460 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400461 of_ports.sort()
462 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
463
464 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800465 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400466
Rich Lane9a003812012-10-04 17:17:59 -0700467 logging.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
468 logging.info("Insert a flow with action --set vid ")
469 logging.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400470
471 #Verify set_vlan_id is a supported action
472 sup_acts = sw_supported_actions(self)
473 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
474 skip_message_emit(self, "Modify VLAN tag test skipped")
475 return
476
477 #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
478 old_vid = 2
479 new_vid = 3
480 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid)
481 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid)
482 vid_act = action.action_set_vlan_vid()
483 vid_act.vlan_vid = new_vid
484
485 #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
Rich Lane477f4812012-10-04 22:49:00 -0700486 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400487 action_list=[vid_act])
488
Rich Laneb90a1c42012-10-05 09:16:05 -0700489class VlanPrio1(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400490
491 """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
492
493 def runTest(self):
494
Rich Lane9a003812012-10-04 17:17:59 -0700495 logging.info("Running vlan_Prio_1 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400496
Rich Lane477f4812012-10-04 22:49:00 -0700497 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400498 of_ports.sort()
499 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
500
501 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800502 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400503
Rich Lane9a003812012-10-04 17:17:59 -0700504 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
505 logging.info("Insert a flow with action -- set vlan priority ")
506 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 -0400507
508 #Verify set_vlan_priority is a supported action
509 sup_acts = sw_supported_actions(self)
510 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
511 skip_message_emit(self, "Set VLAN priority test skipped")
512 return
513
514 #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set.
515 vlan_id = 0
Rich Lane123928c2012-10-04 21:28:53 -0700516 vlan_pcp = 1
517 pkt = simple_tcp_packet(pktlen=60)
518 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=vlan_pcp, pktlen=64)
519 act = action.action_set_vlan_pcp()
520 act.vlan_pcp = vlan_pcp
ShreyaPandita9306c772012-09-28 12:21:40 -0400521
522 #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 -0700523 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400524 action_list=[act])
525
526
Rich Laneb90a1c42012-10-05 09:16:05 -0700527class VlanPrio2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400528
529 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
530
531 def runTest(self):
532
Rich Lane9a003812012-10-04 17:17:59 -0700533 logging.info("Running Vlan_Prio_2 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400534
Rich Lane477f4812012-10-04 22:49:00 -0700535 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400536 of_ports.sort()
537 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
538
539 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800540 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400541
Rich Lane9a003812012-10-04 17:17:59 -0700542 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
543 logging.info("Insert a flow with action -- set vlan priority ")
544 logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400545
546 #Verify set_vlan_priority is a supported action
547 sup_acts = sw_supported_actions(self,"true")
548 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
549 skip_message_emit(self, "modify_vlan_prio test skipped")
550 return
551
552 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
553 vid = 123
554 old_vlan_pcp = 2
555 new_vlan_pcp = 3
556 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp)
557 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp)
558 vid_act = action.action_set_vlan_pcp()
559 vid_act.vlan_pcp = new_vlan_pcp
560
561 #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 -0700562 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400563 action_list=[vid_act])
564
565
Rich Laneb90a1c42012-10-05 09:16:05 -0700566class ModifyL2Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400567
568 """ModifyL2Src :Modify the source MAC address"""
569
570 def runTest(self):
571
Rich Lane9a003812012-10-04 17:17:59 -0700572 logging.info("Running Modify_L2_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400573
Rich Lane477f4812012-10-04 22:49:00 -0700574 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400575 of_ports.sort()
576 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
577
578 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800579 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400580
Rich Lane9a003812012-10-04 17:17:59 -0700581 logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
582 logging.info("Insert a flow with action -- set etherent src address")
583 logging.info("Send packet matching the flow, verify recieved packet src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400584
585 #Verify set_dl_src is a supported action
586 sup_acts = sw_supported_actions(self,use_cache="true")
587 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
588 skip_message_emit(self, "modify_l2_src test skipped")
589 return
590
591 #Create packet to be sent and expected packet with dl_src set to specified value
592 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'],
593 check_test_params=True)
594
595 #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 -0700596 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400597 action_list=acts, max_test=2)
598
599
Rich Laneb90a1c42012-10-05 09:16:05 -0700600class ModifyL2Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400601
602 """ModifyL2SDSt :Modify the dest MAC address"""
603
604 def runTest(self):
605
Rich Lane9a003812012-10-04 17:17:59 -0700606 logging.info("Running Modify_L2_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400607
Rich Lane477f4812012-10-04 22:49:00 -0700608 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400609 of_ports.sort()
610 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
611
612 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800613 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400614
Rich Lane9a003812012-10-04 17:17:59 -0700615 logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
616 logging.info("Insert a flow with action -- set etherent dst address ")
617 logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400618
619 #Verify set_dl_dst is a supported action
620 sup_acts = sw_supported_actions(self)
621 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
622 skip_message_emit(self, "modify_l2_dst test skipped")
623 return
624
625 #Create packet to be sent and expected packet with dl_src set to specified value
626 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'],
627 check_test_params=True)
628
629 #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 -0700630 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400631 action_list=acts, max_test=2)
632
Rich Laneb90a1c42012-10-05 09:16:05 -0700633class ModifyL3Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400634
635 """ModifyL3Src : Modify the source IP address of an IP packet """
636
637 def runTest(self):
638
Rich Lane9a003812012-10-04 17:17:59 -0700639 logging.info("Running Modify_L3_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400640
Rich Lane477f4812012-10-04 22:49:00 -0700641 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400642 of_ports.sort()
643 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
644
645 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800646 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400647
Rich Lane9a003812012-10-04 17:17:59 -0700648 logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
649 logging.info("Insert a flow with action -- set network src address ")
650 logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400651
652 #Verify set_nw_src is a supported action
653 sup_acts = sw_supported_actions(self)
654 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
655 skip_message_emit(self, "modify_l3_src test")
656 return
657
658 #Create packet to be sent and expected packet with nw_src set to specified value
659 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
660 check_test_params=True)
661
662 #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 -0700663 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400664 action_list=acts, max_test=2)
665
Rich Laneb90a1c42012-10-05 09:16:05 -0700666class ModifyL3Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400667
668 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
669
670 def runTest(self):
671
Rich Lane9a003812012-10-04 17:17:59 -0700672 logging.info("Running Modify_L3_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400673
Rich Lane477f4812012-10-04 22:49:00 -0700674 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400675 of_ports.sort()
676 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
677
678 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800679 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400680
Rich Lane9a003812012-10-04 17:17:59 -0700681 logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
682 logging.info("Insert a flow with action -- set network dst address ")
683 logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400684
685 #Verify set_nw_dst is a supported action
686 sup_acts = sw_supported_actions(self,use_cache="true")
687 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
688 skip_message_emit(self, "modify_l3_dst test skipped")
689 return
690
691 #Create packet to be sent and expected packet with nw_dst set to specified value
692 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
693 check_test_params=True)
694
695 #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 -0700696 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400697 action_list=acts, max_test=2)
698
699
Rich Laneb90a1c42012-10-05 09:16:05 -0700700class ModifyL4Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400701
702 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
703
704 def runTest(self):
705
Rich Lane9a003812012-10-04 17:17:59 -0700706 logging.info("Running Modify_L4_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400707
Rich Lane477f4812012-10-04 22:49:00 -0700708 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400709 of_ports.sort()
710 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
711
712 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800713 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400714
Rich Lane9a003812012-10-04 17:17:59 -0700715 logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
716 logging.info("Insert a flow with action -- set src tcp port")
717 logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400718
719 #Verify set_tp_src is a supported action
720 sup_acts = sw_supported_actions(self,use_cache="true")
721 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
722 skip_message_emit(self, "modify_l4_src test skipped")
723 return
724
725 #Create packet to be sent and expected packet with tcp_src set to specified value
726 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
727 check_test_params=True)
728
729 #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 -0700730 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400731 action_list=acts, max_test=2)
732
Rich Laneb90a1c42012-10-05 09:16:05 -0700733class ModifyL4Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400734
735 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
736
737 def runTest(self):
738
Rich Lane9a003812012-10-04 17:17:59 -0700739 logging.info("Running Modify_L4_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400740
Rich Lane477f4812012-10-04 22:49:00 -0700741 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400742 of_ports.sort()
743 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
744
745 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800746 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400747
Rich Lane9a003812012-10-04 17:17:59 -0700748 logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
749 logging.info("Insert a flow with action -- set dst tcp port")
750 logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400751
752 #Verify set_tp_dst is a supported action
753 sup_acts = sw_supported_actions(self,use_cache="true")
754 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
755 skip_message_emit(self, "ModifyL4Dst test")
756 return
757
758 #Create packet to be sent and expected packet with tcp_dst set to specified value
759 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
760 check_test_params=True)
761
762 #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 -0700763 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400764 action_list=acts, max_test=2)
765
Rich Laneb90a1c42012-10-05 09:16:05 -0700766class ModifyTos(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400767
768 """ModifyTOS :Modify the IP type of service of an IP packet"""
769
770 def runTest(self):
771
Rich Lane9a003812012-10-04 17:17:59 -0700772 logging.info("Running Modify_Tos test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400773
Rich Lane477f4812012-10-04 22:49:00 -0700774 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400775 of_ports.sort()
776 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
777
778 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800779 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400780
Rich Lane9a003812012-10-04 17:17:59 -0700781 logging.info("Verify if switch supports the action -- modify_tos, if not skip the test")
782 logging.info("Insert a flow with action -- set type of service ")
783 logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400784
785 #Verify set_tos is a supported action
786 sup_acts = sw_supported_actions(self,use_cache="true")
787 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
788 skip_message_emit(self, "ModifyTOS test")
789 return
790
791 #Create packet to be sent and expected packet with TOS set to specified value
792 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
793 check_test_params=True)
794
795 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700796 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400797 action_list=acts, max_test=2, egr_count=-1)