blob: bacb67cd820d02d5d681270510b8a36464d7237f [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
Dan Talayco3bfc8222013-02-13 18:18:57 -0800517 pktlen = 64 if config["minsize"] < 64 else config["minsize"]
518 pkt = simple_tcp_packet(pktlen=pktlen)
519 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=vlan_pcp, pktlen=pktlen + 4)
Rich Lane123928c2012-10-04 21:28:53 -0700520 act = action.action_set_vlan_pcp()
521 act.vlan_pcp = vlan_pcp
ShreyaPandita9306c772012-09-28 12:21:40 -0400522
523 #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 -0700524 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400525 action_list=[act])
526
527
Rich Laneb90a1c42012-10-05 09:16:05 -0700528class VlanPrio2(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400529
530 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
531
532 def runTest(self):
533
Rich Lane9a003812012-10-04 17:17:59 -0700534 logging.info("Running Vlan_Prio_2 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400535
Rich Lane477f4812012-10-04 22:49:00 -0700536 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400537 of_ports.sort()
538 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
539
540 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800541 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400542
Rich Lane9a003812012-10-04 17:17:59 -0700543 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
544 logging.info("Insert a flow with action -- set vlan priority ")
545 logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400546
547 #Verify set_vlan_priority is a supported action
548 sup_acts = sw_supported_actions(self,"true")
549 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
550 skip_message_emit(self, "modify_vlan_prio test skipped")
551 return
552
553 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
554 vid = 123
555 old_vlan_pcp = 2
556 new_vlan_pcp = 3
557 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp)
558 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp)
559 vid_act = action.action_set_vlan_pcp()
560 vid_act.vlan_pcp = new_vlan_pcp
561
562 #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 -0700563 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400564 action_list=[vid_act])
565
566
Rich Laneb90a1c42012-10-05 09:16:05 -0700567class ModifyL2Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400568
569 """ModifyL2Src :Modify the source MAC address"""
570
571 def runTest(self):
572
Rich Lane9a003812012-10-04 17:17:59 -0700573 logging.info("Running Modify_L2_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400574
Rich Lane477f4812012-10-04 22:49:00 -0700575 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400576 of_ports.sort()
577 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
578
579 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800580 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400581
Rich Lane9a003812012-10-04 17:17:59 -0700582 logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
583 logging.info("Insert a flow with action -- set etherent src address")
584 logging.info("Send packet matching the flow, verify recieved packet src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400585
586 #Verify set_dl_src is a supported action
587 sup_acts = sw_supported_actions(self,use_cache="true")
588 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
589 skip_message_emit(self, "modify_l2_src test skipped")
590 return
591
592 #Create packet to be sent and expected packet with dl_src set to specified value
593 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'],
594 check_test_params=True)
595
596 #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 -0700597 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400598 action_list=acts, max_test=2)
599
600
Rich Laneb90a1c42012-10-05 09:16:05 -0700601class ModifyL2Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400602
603 """ModifyL2SDSt :Modify the dest MAC address"""
604
605 def runTest(self):
606
Rich Lane9a003812012-10-04 17:17:59 -0700607 logging.info("Running Modify_L2_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400608
Rich Lane477f4812012-10-04 22:49:00 -0700609 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400610 of_ports.sort()
611 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
612
613 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800614 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400615
Rich Lane9a003812012-10-04 17:17:59 -0700616 logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
617 logging.info("Insert a flow with action -- set etherent dst address ")
618 logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400619
620 #Verify set_dl_dst is a supported action
621 sup_acts = sw_supported_actions(self)
622 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
623 skip_message_emit(self, "modify_l2_dst test skipped")
624 return
625
626 #Create packet to be sent and expected packet with dl_src set to specified value
627 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'],
628 check_test_params=True)
629
630 #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 -0700631 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400632 action_list=acts, max_test=2)
633
Rich Laneb90a1c42012-10-05 09:16:05 -0700634class ModifyL3Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400635
636 """ModifyL3Src : Modify the source IP address of an IP packet """
637
638 def runTest(self):
639
Rich Lane9a003812012-10-04 17:17:59 -0700640 logging.info("Running Modify_L3_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400641
Rich Lane477f4812012-10-04 22:49:00 -0700642 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400643 of_ports.sort()
644 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
645
646 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800647 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400648
Rich Lane9a003812012-10-04 17:17:59 -0700649 logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
650 logging.info("Insert a flow with action -- set network src address ")
651 logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400652
653 #Verify set_nw_src is a supported action
654 sup_acts = sw_supported_actions(self)
655 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
656 skip_message_emit(self, "modify_l3_src test")
657 return
658
659 #Create packet to be sent and expected packet with nw_src set to specified value
660 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
661 check_test_params=True)
662
663 #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 -0700664 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400665 action_list=acts, max_test=2)
666
Rich Laneb90a1c42012-10-05 09:16:05 -0700667class ModifyL3Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400668
669 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
670
671 def runTest(self):
672
Rich Lane9a003812012-10-04 17:17:59 -0700673 logging.info("Running Modify_L3_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400674
Rich Lane477f4812012-10-04 22:49:00 -0700675 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400676 of_ports.sort()
677 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
678
679 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800680 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400681
Rich Lane9a003812012-10-04 17:17:59 -0700682 logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
683 logging.info("Insert a flow with action -- set network dst address ")
684 logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400685
686 #Verify set_nw_dst is a supported action
687 sup_acts = sw_supported_actions(self,use_cache="true")
688 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
689 skip_message_emit(self, "modify_l3_dst test skipped")
690 return
691
692 #Create packet to be sent and expected packet with nw_dst set to specified value
693 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
694 check_test_params=True)
695
696 #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 -0700697 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400698 action_list=acts, max_test=2)
699
700
Rich Laneb90a1c42012-10-05 09:16:05 -0700701class ModifyL4Src(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400702
703 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
704
705 def runTest(self):
706
Rich Lane9a003812012-10-04 17:17:59 -0700707 logging.info("Running Modify_L4_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400708
Rich Lane477f4812012-10-04 22:49:00 -0700709 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400710 of_ports.sort()
711 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
712
713 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800714 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400715
Rich Lane9a003812012-10-04 17:17:59 -0700716 logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
717 logging.info("Insert a flow with action -- set src tcp port")
718 logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400719
720 #Verify set_tp_src is a supported action
721 sup_acts = sw_supported_actions(self,use_cache="true")
722 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
723 skip_message_emit(self, "modify_l4_src test skipped")
724 return
725
726 #Create packet to be sent and expected packet with tcp_src set to specified value
727 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
728 check_test_params=True)
729
730 #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 -0700731 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400732 action_list=acts, max_test=2)
733
Rich Laneb90a1c42012-10-05 09:16:05 -0700734class ModifyL4Dst(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400735
736 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
737
738 def runTest(self):
739
Rich Lane9a003812012-10-04 17:17:59 -0700740 logging.info("Running Modify_L4_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400741
Rich Lane477f4812012-10-04 22:49:00 -0700742 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400743 of_ports.sort()
744 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
745
746 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800747 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400748
Rich Lane9a003812012-10-04 17:17:59 -0700749 logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
750 logging.info("Insert a flow with action -- set dst tcp port")
751 logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400752
753 #Verify set_tp_dst is a supported action
754 sup_acts = sw_supported_actions(self,use_cache="true")
755 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
756 skip_message_emit(self, "ModifyL4Dst test")
757 return
758
759 #Create packet to be sent and expected packet with tcp_dst set to specified value
760 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
761 check_test_params=True)
762
763 #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 -0700764 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400765 action_list=acts, max_test=2)
766
Rich Laneb90a1c42012-10-05 09:16:05 -0700767class ModifyTos(base_tests.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400768
769 """ModifyTOS :Modify the IP type of service of an IP packet"""
770
771 def runTest(self):
772
Rich Lane9a003812012-10-04 17:17:59 -0700773 logging.info("Running Modify_Tos test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400774
Rich Lane477f4812012-10-04 22:49:00 -0700775 of_ports = config["port_map"].keys()
ShreyaPandita9306c772012-09-28 12:21:40 -0400776 of_ports.sort()
777 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
778
779 #Clear switch state
Rich Lane32bf9482013-01-03 17:26:30 -0800780 delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400781
Rich Lane9a003812012-10-04 17:17:59 -0700782 logging.info("Verify if switch supports the action -- modify_tos, if not skip the test")
783 logging.info("Insert a flow with action -- set type of service ")
784 logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400785
786 #Verify set_tos is a supported action
787 sup_acts = sw_supported_actions(self,use_cache="true")
788 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
789 skip_message_emit(self, "ModifyTOS test")
790 return
791
792 #Create packet to be sent and expected packet with TOS set to specified value
793 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
794 check_test_params=True)
795
796 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
Rich Lane477f4812012-10-04 22:49:00 -0700797 flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt,
ShreyaPandita9306c772012-09-28 12:21:40 -0400798 action_list=acts, max_test=2, egr_count=-1)