blob: d0dab71b11274e60b834dbeea2cc7b911a63c330 [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
13
14import oftest.controller as controller
15import oftest.cstruct as ofp
16import oftest.message as message
17import oftest.dataplane as dataplane
18import oftest.action as action
19import oftest.parse as parse
20import basic
21import time
22
Rich Laneda3b5ad2012-10-03 09:05:32 -070023from oftest.testutils import *
ShreyaPandita9306c772012-09-28 12:21:40 -040024from time import sleep
25from FuncUtils import *
26
27ac_port_map = None
ShreyaPandita9306c772012-09-28 12:21:40 -040028ac_config = None
29of_ports = None
30
31def test_set_init(config):
32 basic.test_set_init(config)
33
34 global ac_port_map
ShreyaPandita9306c772012-09-28 12:21:40 -040035 global ac_config
36 global of_ports
37
ShreyaPandita9306c772012-09-28 12:21:40 -040038 ac_port_map = config["port_map"]
39 ac_config = config
40
41 of_ports = ac_port_map.keys()
42 of_ports.sort()
43
44
45
46class NoAction(basic.SimpleDataPlane):
47
48 """NoActionDrop : no action added to flow , drops the packet."""
49
50 def runTest(self):
51
Rich Lane9a003812012-10-04 17:17:59 -070052 logging.info("Running No_Action test")
ShreyaPandita9306c772012-09-28 12:21:40 -040053
54 of_ports = ac_port_map.keys()
55 of_ports.sort()
56 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
57
58 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -070059 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -040060 self.assertEqual(rv, 0, "Failed to delete all flows")
61
Rich Lane9a003812012-10-04 17:17:59 -070062 logging.info("Install a flow without action")
63 logging.info("Send packets matching that flow")
64 logging.info("Expecting switch to drop all packets")
ShreyaPandita9306c772012-09-28 12:21:40 -040065
66 # Insert a flow wildcard all without any action
67 pkt = simple_tcp_packet()
68 match = parse.packet_to_flow_match(pkt)
69 self.assertTrue(match is not None, "Could not generate flow match from pkt")
70 match.wildcards=ofp.OFPFW_ALL
71 match.in_port = of_ports[0]
72
73 msg = message.flow_mod()
74 msg.out_port = ofp.OFPP_NONE
75 msg.command = ofp.OFPFC_ADD
76 msg.buffer_id = 0xffffffff
77 msg.match = match
78 rv = self.controller.message_send(msg)
79 self.assertTrue(rv != -1, "Error installing flow mod")
ShreyaPanditab46f8522012-09-28 15:12:15 -040080 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
81
ShreyaPandita9306c772012-09-28 12:21:40 -040082 #Sending N packets matching the flow inserted
83 for pkt_cnt in range(5):
84 self.dataplane.send(of_ports[0],str(pkt))
85
86 #Verify packets not recieved on any of the dataplane ports
ShreyaPandita7b9ec982012-09-28 14:43:08 -040087 (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1,exp_pkt=pkt)
88 self.assertTrue(rcv_pkt is None,
ShreyaPanditad4a42c62012-09-28 15:35:27 -040089 "Packet received on port " + str(rcv_port))
ShreyaPandita9306c772012-09-28 12:21:40 -040090
91 #Verify packets not sent on control plane either
92 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1)
93 self.assertTrue(response is None,
94 'Packets not received on control plane')
95
96
97class Announcement(basic.SimpleDataPlane):
98
99 """Announcement : Get all supported actions by the switch.
100 Send OFPT_FEATURES_REQUEST to get features supported by sw."""
101
102 def runTest(self):
103
Rich Lane9a003812012-10-04 17:17:59 -0700104 logging.info("Running Announcement test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400105
Rich Lane9a003812012-10-04 17:17:59 -0700106 logging.info("Sending Features_Request")
107 logging.info("Expecting Features Reply with supported actions")
ShreyaPandita9306c772012-09-28 12:21:40 -0400108
109 # Sending Features_Request
110 request = message.features_request()
111 (reply, pkt) = self.controller.transact(request)
112 self.assertTrue(reply is not None, "Failed to get any reply")
113 self.assertEqual(reply.header.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
114
115 supported_actions =[]
116 if(reply.actions &1<<ofp.OFPAT_OUTPUT):
117 supported_actions.append('OFPAT_OUTPUT')
118 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
119 supported_actions.append('OFPAT_SET_VLAN_VID')
120 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
121 supported_actions.append('OFPAT_SET_VLAN_PCP')
122 if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
123 supported_actions.append('OFPAT_STRIP_VLAN')
124 if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
125 supported_actions.append('OFPAT_SET_DL_SRC')
126 if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
127 supported_actions.append('OFPAT_SET_NW_SRC')
128 if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
129 supported_actions.append('OFPAT_SET_NW_DST')
130 if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
131 supported_actions.append('OFPAT_SET_NW_TOS')
132 if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
133 supported_actions.append('OFPAT_SET_TP_SRC')
134 if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
135 supported_actions.append('OFPAT_SET_TP_DST')
136 if(reply.actions &1<<ofp.OFPAT_VENDOR):
137 supported_actions.append('OFPAT_VENDOR')
138 if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
139 supported_actions.append('OFPAT_ENQUEUE')
140
Rich Lane9a003812012-10-04 17:17:59 -0700141 logging.info(supported_actions)
ShreyaPandita9306c772012-09-28 12:21:40 -0400142
143
144class ForwardAll(basic.SimpleDataPlane):
145
146 """ForwardAll : Packet is sent to all dataplane ports
147 except ingress port when output action.port = OFPP_ALL"""
148
149 def runTest(self):
150
Rich Lane9a003812012-10-04 17:17:59 -0700151 logging.info("Running Forward_All test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400152
153 of_ports = ac_port_map.keys()
154 of_ports.sort()
155 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
156
157 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700158 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400159 self.assertEqual(rv, 0, "Failed to delete all flows")
160
Rich Lane9a003812012-10-04 17:17:59 -0700161 logging.info("Insert a flow with output action port OFPP_ALL")
162 logging.info("Send packet matching the flow")
163 logging.info("Expecting packet on all dataplane ports except ingress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400164
165 #Create a packet
166 pkt = simple_tcp_packet()
167 match = parse.packet_to_flow_match(pkt)
168 act = action.action_output()
169
170 #Delete all flows
Rich Lane9a003812012-10-04 17:17:59 -0700171 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400172 self.assertEqual(rv, 0, "Failed to delete all flows")
173 ingress_port=of_ports[0]
174 match.in_port = ingress_port
175
176 #Create a flow mod with action.port = OFPP_ALL
177 request = message.flow_mod()
178 request.match = match
179 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
180 act.port = ofp.OFPP_ALL
181 request.actions.add(act)
182
Rich Lane9a003812012-10-04 17:17:59 -0700183 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400184 rv = self.controller.message_send(request)
185 self.assertTrue(rv != -1, "Error installing flow mod")
186 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
187
188 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700189 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400190 self.dataplane.send(ingress_port, str(pkt))
191
192 #Verifying packets recieved on expected dataplane ports
193 yes_ports = set(of_ports).difference([ingress_port])
194 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
Rich Lane9a003812012-10-04 17:17:59 -0700195 self, ac_config)
ShreyaPandita9306c772012-09-28 12:21:40 -0400196
197
198class ForwardController(basic.SimpleDataPlane):
199
200 """ForwardController : Packet is sent to controller
201 output.port = OFPP_CONTROLLER"""
202
203 def runTest(self):
204
Rich Lane9a003812012-10-04 17:17:59 -0700205 logging.info("Running Forward_Controller test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400206
207 of_ports = ac_port_map.keys()
208 of_ports.sort()
209 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
210
211 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700212 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400213 self.assertEqual(rv, 0, "Failed to delete all flows")
214
Rich Lane9a003812012-10-04 17:17:59 -0700215 logging.info("Insert a flow with output action port OFPP_CONTROLLER")
216 logging.info("Send packet matching the flow")
217 logging.info("Expecting packet on the control plane")
ShreyaPandita9306c772012-09-28 12:21:40 -0400218
219 #Create packet
220 pkt = simple_tcp_packet()
221 match = parse.packet_to_flow_match(pkt)
222 act = action.action_output()
223
224 for ingress_port in of_ports:
225 #Delete all flows
Rich Lane9a003812012-10-04 17:17:59 -0700226 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400227 self.assertEqual(rv, 0, "Failed to delete all flows")
228
229 match.in_port = ingress_port
230
231 #Create a flow mod message
232 request = message.flow_mod()
233 request.match = match
234 act.port = ofp.OFPP_CONTROLLER
235 request.actions.add(act)
236
Rich Lane9a003812012-10-04 17:17:59 -0700237 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400238 rv = self.controller.message_send(request)
239 self.assertTrue(rv != -1, "Error installing flow mod")
240 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
241
242 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700243 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400244 self.dataplane.send(ingress_port, str(pkt))
245
246 #Verifying packet recieved on the control plane port
247 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10)
248 self.assertTrue(response is not None,
249 'Packet in message not received by controller')
250
251
252
253class ForwardLocal(basic.SimpleDataPlane):
254
255 """ForwardLocal : Packet is sent to OFPP_LOCAL port .
256 TBD : To verify packet recieved in the local networking stack of switch"""
257
258 def runTest(self):
259
Rich Lane9a003812012-10-04 17:17:59 -0700260 logging.info("Running Forward_Local test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400261
262 of_ports = ac_port_map.keys()
263 of_ports.sort()
264 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
265
266 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700267 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400268 self.assertEqual(rv, 0, "Failed to delete all flows")
269
Rich Lane9a003812012-10-04 17:17:59 -0700270 logging.info("Insert a flow with output action port OFPP_LOCAL")
271 logging.info("Send packet matching the flow")
272 logging.info("Expecting packet in the local networking stack of switch")
ShreyaPandita9306c772012-09-28 12:21:40 -0400273
274 #Clear switch state
275 pkt = simple_tcp_packet()
276 match = parse.packet_to_flow_match(pkt)
277 act = action.action_output()
278
279 for ingress_port in of_ports:
280 #Delete the flows
Rich Lane9a003812012-10-04 17:17:59 -0700281 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400282 self.assertEqual(rv, 0, "Failed to delete all flows")
283
284 match.in_port = ingress_port
285 #Create flow mod message
286 request = message.flow_mod()
287 request.match = match
288 act.port = ofp.OFPP_LOCAL
289 request.actions.add(act)
290
Rich Lane9a003812012-10-04 17:17:59 -0700291 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400292 rv = self.controller.message_send(request)
293 self.assertTrue(rv != -1, "Error installing flow mod")
294 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
295
296 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700297 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400298 self.dataplane.send(ingress_port, str(pkt))
299
300 #TBD: Verification of packets being recieved.
301
302
303class ForwardFlood(basic.SimpleDataPlane):
304
305 """Forward:Flood : Packet is sent to all dataplane ports
306 except ingress port when output action.port = OFPP_FLOOD
307 TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
308 not including the incoming interface. """
309
310 def runTest(self):
311
Rich Lane9a003812012-10-04 17:17:59 -0700312 logging.info("Running Forward_Flood test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400313 of_ports = ac_port_map.keys()
314 of_ports.sort()
315 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
316
317 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700318 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400319 self.assertEqual(rv, 0, "Failed to delete all flows")
320
Rich Lane9a003812012-10-04 17:17:59 -0700321 logging.info("Insert a flow with output action port OFPP_FORWARD")
322 logging.info("Send packet matching the flow")
323 logging.info("Expecting packet on all the ports except the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400324
325 #Create a packet
326 pkt = simple_tcp_packet()
327 match = parse.packet_to_flow_match(pkt)
328 act = action.action_output()
329
330 #Delete all flows
Rich Lane9a003812012-10-04 17:17:59 -0700331 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400332 self.assertEqual(rv, 0, "Failed to delete all flows")
333 ingress_port=of_ports[0]
334 match.in_port = ingress_port
335
336 #Create a flow mod with action.port = OFPP_ALL
337 request = message.flow_mod()
338 request.match = match
339 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
340 act.port = ofp.OFPP_FLOOD
341 request.actions.add(act)
342
Rich Lane9a003812012-10-04 17:17:59 -0700343 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400344 rv = self.controller.message_send(request)
345 self.assertTrue(rv != -1, "Error installing flow mod")
346 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
347
348 #Send Packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700349 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400350 self.dataplane.send(ingress_port, str(pkt))
351
352 #Verifying packets recieved on expected dataplane ports
353 yes_ports = set(of_ports).difference([ingress_port])
354 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
Rich Lane9a003812012-10-04 17:17:59 -0700355 self, ac_config)
ShreyaPandita9306c772012-09-28 12:21:40 -0400356
357class ForwardInport(basic.SimpleDataPlane):
358
359 """ ForwardInPort : Packet sent to virtual port IN_PORT
360 If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
361
362 def runTest(self):
363
Rich Lane9a003812012-10-04 17:17:59 -0700364 logging.info("Running Forward_Inport test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400365
366 of_ports = ac_port_map.keys()
367 of_ports.sort()
368 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
369
370 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700371 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400372 self.assertEqual(rv, 0, "Failed to delete all flows")
373
Rich Lane9a003812012-10-04 17:17:59 -0700374 logging.info("Insert a flow with output action port OFPP_INPORT")
375 logging.info("Send packet matching the flow")
376 logging.info("Expecting packet on the input port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400377
378 #Create a packet
379 pkt = simple_tcp_packet()
380 match = parse.packet_to_flow_match(pkt)
381 act = action.action_output()
382
383 #Delete the flows
Rich Lane9a003812012-10-04 17:17:59 -0700384 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400385 self.assertEqual(rv, 0, "Failed to delete all flows")
386 ingress_port=of_ports[0]
387 match.in_port = ingress_port
388
389 # Create a flow mod message
390 request = message.flow_mod()
391 request.match = match
392 act.port = ofp.OFPP_IN_PORT
393
394 request.actions.add(act)
Rich Lane9a003812012-10-04 17:17:59 -0700395 logging.info("Inserting flow")
ShreyaPandita9306c772012-09-28 12:21:40 -0400396 rv = self.controller.message_send(request)
397 self.assertTrue(rv != -1, "Error installing flow mod")
398 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
399
400 #Send packet matching the flow
Rich Lane9a003812012-10-04 17:17:59 -0700401 logging.info("Sending packet to dp port " + str(ingress_port))
ShreyaPandita9306c772012-09-28 12:21:40 -0400402 self.dataplane.send(ingress_port, str(pkt))
403 yes_ports = [ingress_port]
404
405 #Verfying packet recieved on expected dataplane ports
406 receive_pkt_check(self.dataplane, pkt, yes_ports,set(of_ports).difference([ingress_port]),
Rich Lane9a003812012-10-04 17:17:59 -0700407 self, ac_config)
ShreyaPandita9306c772012-09-28 12:21:40 -0400408
409class ForwardTable(basic.SimpleDataPlane):
410
411 """ForwardTable : Perform actions in flow table. Only for packet-out messages.
412 If the output action.port in the packetout message = OFP.TABLE , then
413 the packet implements the action specified in the matching flow of the FLOW-TABLE"""
414
415 def runTest(self):
416
Rich Lane9a003812012-10-04 17:17:59 -0700417 logging.info("Running Forward_Table test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400418
419 of_ports = ac_port_map.keys()
420 of_ports.sort()
421 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
422
423 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700424 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400425 self.assertEqual(rv, 0, "Failed to delete all flows")
426
Rich Lane9a003812012-10-04 17:17:59 -0700427 logging.info("Insert a flow F with output action port set to some egress_port")
428 logging.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
429 logging.info("Expecting packet on the egress_port")
ShreyaPandita9306c772012-09-28 12:21:40 -0400430
431 #Insert a all wildcarded flow
432 (pkt,match) = Wildcard_All(self,of_ports)
433
434 #Create a packet out message
435 pkt_out =message.packet_out();
436 pkt_out.data = str(pkt)
437 pkt_out.in_port = of_ports[0]
438 act = action.action_output()
439 act.port = ofp.OFPP_TABLE
440 pkt_out.actions.add(act)
441 rv = self.controller.message_send(pkt_out)
442 self.assertTrue(rv == 0, "Error sending out message")
443
444 #Verifying packet out message recieved on the expected dataplane port.
445 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
446 exp_pkt=pkt,timeout=3)
447 self.assertTrue(pkt is not None, 'Packet not received')
448
449
ShreyaPandita82c43be2012-09-28 13:16:30 -0400450class AddVlanTag(basic.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400451
452 """AddVlanTag : Adds VLAN Tag to untagged packet."""
453
454 def runTest(self):
455
Rich Lane9a003812012-10-04 17:17:59 -0700456 logging.info("Running Add_vlan_tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400457
458 of_ports = ac_port_map.keys()
459 of_ports.sort()
460 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
461
462 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700463 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400464 self.assertEqual(rv, 0, "Failed to delete all flows")
465
Rich Lane9a003812012-10-04 17:17:59 -0700466 logging.info("Verify if switch supports the action -- set vlan id, if not skip the test")
467 logging.info("Insert a flow with set vid action")
468 logging.info("Send packet matching the flow , verify recieved packet has vid set")
ShreyaPandita9306c772012-09-28 12:21:40 -0400469
470 #Verify set_vlan_id is a supported action
471 sup_acts = sw_supported_actions(self)
472 if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
473 skip_message_emit(self, "Add VLAN tag test skipped")
474 return
475
476 #Create packet to be sent and an expected packet with vid set
477 new_vid = 2
478 len_wo_vid = 100
479 len_w_vid = 104
480 pkt = simple_tcp_packet(pktlen=len_wo_vid)
481 exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True,
482 dl_vlan=new_vid,dl_vlan_pcp=0)
483 vid_act = action.action_set_vlan_vid()
484 vid_act.vlan_vid = new_vid
485
486 #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
487 flow_match_test(self, ac_port_map, pkt=pkt,
488 exp_pkt=exp_pkt, action_list=[vid_act])
489
490class ModifyVlanTag(basic.SimpleDataPlane):
491
492 """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
493
494 def runTest(self):
495
Rich Lane9a003812012-10-04 17:17:59 -0700496 logging.info("Running Modify_Vlan_Tag test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400497
498 of_ports = ac_port_map.keys()
499 of_ports.sort()
500 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
501
502 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700503 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400504 self.assertEqual(rv, 0, "Failed to delete all flows")
505
Rich Lane9a003812012-10-04 17:17:59 -0700506 logging.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
507 logging.info("Insert a flow with action --set vid ")
508 logging.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400509
510 #Verify set_vlan_id is a supported action
511 sup_acts = sw_supported_actions(self)
512 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
513 skip_message_emit(self, "Modify VLAN tag test skipped")
514 return
515
516 #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
517 old_vid = 2
518 new_vid = 3
519 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid)
520 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid)
521 vid_act = action.action_set_vlan_vid()
522 vid_act.vlan_vid = new_vid
523
524 #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
525 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
526 action_list=[vid_act])
527
528class VlanPrio1(basic.SimpleDataPlane):
529
530 """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
531
532 def runTest(self):
533
Rich Lane9a003812012-10-04 17:17:59 -0700534 logging.info("Running vlan_Prio_1 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400535
536 of_ports = ac_port_map.keys()
537 of_ports.sort()
538 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
539
540 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700541 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400542 self.assertEqual(rv, 0, "Failed to delete all flows")
543
Rich Lane9a003812012-10-04 17:17:59 -0700544 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
545 logging.info("Insert a flow with action -- set vlan priority ")
546 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 -0400547
548 #Verify set_vlan_priority is a supported action
549 sup_acts = sw_supported_actions(self)
550 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
551 skip_message_emit(self, "Set VLAN priority test skipped")
552 return
553
554 #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set.
555 vlan_id = 0
Rich Lane123928c2012-10-04 21:28:53 -0700556 vlan_pcp = 1
557 pkt = simple_tcp_packet(pktlen=60)
558 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=vlan_pcp, pktlen=64)
559 act = action.action_set_vlan_pcp()
560 act.vlan_pcp = vlan_pcp
ShreyaPandita9306c772012-09-28 12:21:40 -0400561
562 #Insert flow with action -- set vLAN priority, Send packet matching the flow, Verify recieved packet is expected packet
563 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
564 action_list=[act])
565
566
567class VlanPrio2(basic.SimpleDataPlane):
568
569 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
570
571 def runTest(self):
572
Rich Lane9a003812012-10-04 17:17:59 -0700573 logging.info("Running Vlan_Prio_2 test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400574
575 of_ports = ac_port_map.keys()
576 of_ports.sort()
577 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
578
579 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700580 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400581 self.assertEqual(rv, 0, "Failed to delete all flows")
582
Rich Lane9a003812012-10-04 17:17:59 -0700583 logging.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
584 logging.info("Insert a flow with action -- set vlan priority ")
585 logging.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
ShreyaPandita9306c772012-09-28 12:21:40 -0400586
587 #Verify set_vlan_priority is a supported action
588 sup_acts = sw_supported_actions(self,"true")
589 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
590 skip_message_emit(self, "modify_vlan_prio test skipped")
591 return
592
593 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
594 vid = 123
595 old_vlan_pcp = 2
596 new_vlan_pcp = 3
597 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp)
598 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp)
599 vid_act = action.action_set_vlan_pcp()
600 vid_act.vlan_pcp = new_vlan_pcp
601
602 #Insert flow with action -- set vLAN priority, Send tagged packet matching the flow, Verify recieved packet is expected packet
603 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
604 action_list=[vid_act])
605
606
607class ModifyL2Src(basic.SimpleDataPlane):
608
609 """ModifyL2Src :Modify the source MAC address"""
610
611 def runTest(self):
612
Rich Lane9a003812012-10-04 17:17:59 -0700613 logging.info("Running Modify_L2_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400614
615 of_ports = ac_port_map.keys()
616 of_ports.sort()
617 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
618
619 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700620 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400621 self.assertEqual(rv, 0, "Failed to delete all flows")
622
Rich Lane9a003812012-10-04 17:17:59 -0700623 logging.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
624 logging.info("Insert a flow with action -- set etherent src address")
625 logging.info("Send packet matching the flow, verify recieved packet src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400626
627 #Verify set_dl_src is a supported action
628 sup_acts = sw_supported_actions(self,use_cache="true")
629 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
630 skip_message_emit(self, "modify_l2_src test skipped")
631 return
632
633 #Create packet to be sent and expected packet with dl_src set to specified value
634 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'],
635 check_test_params=True)
636
637 #Insert flow with action -- set src address, Send packet matching the flow, Verify recieved packet is expected packet
638 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
639 action_list=acts, max_test=2)
640
641
642class ModifyL2Dst(basic.SimpleDataPlane):
643
644 """ModifyL2SDSt :Modify the dest MAC address"""
645
646 def runTest(self):
647
Rich Lane9a003812012-10-04 17:17:59 -0700648 logging.info("Running Modify_L2_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400649
650 of_ports = ac_port_map.keys()
651 of_ports.sort()
652 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
653
654 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700655 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400656 self.assertEqual(rv, 0, "Failed to delete all flows")
657
Rich Lane9a003812012-10-04 17:17:59 -0700658 logging.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
659 logging.info("Insert a flow with action -- set etherent dst address ")
660 logging.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400661
662 #Verify set_dl_dst is a supported action
663 sup_acts = sw_supported_actions(self)
664 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
665 skip_message_emit(self, "modify_l2_dst test skipped")
666 return
667
668 #Create packet to be sent and expected packet with dl_src set to specified value
669 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'],
670 check_test_params=True)
671
672 #Insert flow with action -- set dst address, Send packet matching the flow, Verify recieved packet is expected packet
673 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
674 action_list=acts, max_test=2)
675
676class ModifyL3Src(basic.SimpleDataPlane):
677
678 """ModifyL3Src : Modify the source IP address of an IP packet """
679
680 def runTest(self):
681
Rich Lane9a003812012-10-04 17:17:59 -0700682 logging.info("Running Modify_L3_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400683
684 of_ports = ac_port_map.keys()
685 of_ports.sort()
686 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
687
688 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700689 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400690 self.assertEqual(rv, 0, "Failed to delete all flows")
691
Rich Lane9a003812012-10-04 17:17:59 -0700692 logging.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
693 logging.info("Insert a flow with action -- set network src address ")
694 logging.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400695
696 #Verify set_nw_src is a supported action
697 sup_acts = sw_supported_actions(self)
698 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
699 skip_message_emit(self, "modify_l3_src test")
700 return
701
702 #Create packet to be sent and expected packet with nw_src set to specified value
703 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
704 check_test_params=True)
705
706 #Insert flow with action -- set nw src address, Send packet matching the flow, Verify recieved packet is expected packet
707 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
708 action_list=acts, max_test=2)
709
710class ModifyL3Dst(basic.SimpleDataPlane):
711
712 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
713
714 def runTest(self):
715
Rich Lane9a003812012-10-04 17:17:59 -0700716 logging.info("Running Modify_L3_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400717
718 of_ports = ac_port_map.keys()
719 of_ports.sort()
720 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
721
722 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700723 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400724 self.assertEqual(rv, 0, "Failed to delete all flows")
725
Rich Lane9a003812012-10-04 17:17:59 -0700726 logging.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
727 logging.info("Insert a flow with action -- set network dst address ")
728 logging.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400729
730 #Verify set_nw_dst is a supported action
731 sup_acts = sw_supported_actions(self,use_cache="true")
732 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
733 skip_message_emit(self, "modify_l3_dst test skipped")
734 return
735
736 #Create packet to be sent and expected packet with nw_dst set to specified value
737 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
738 check_test_params=True)
739
740 #Insert flow with action -- set nw dst address, Send packet matching the flow, Verify recieved packet is expected packet
741 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
742 action_list=acts, max_test=2)
743
744
745class ModifyL4Src(basic.SimpleDataPlane):
746
747 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
748
749 def runTest(self):
750
Rich Lane9a003812012-10-04 17:17:59 -0700751 logging.info("Running Modify_L4_Src test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400752
753 of_ports = ac_port_map.keys()
754 of_ports.sort()
755 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
756
757 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700758 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400759 self.assertEqual(rv, 0, "Failed to delete all flows")
760
Rich Lane9a003812012-10-04 17:17:59 -0700761 logging.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
762 logging.info("Insert a flow with action -- set src tcp port")
763 logging.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400764
765 #Verify set_tp_src is a supported action
766 sup_acts = sw_supported_actions(self,use_cache="true")
767 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
768 skip_message_emit(self, "modify_l4_src test skipped")
769 return
770
771 #Create packet to be sent and expected packet with tcp_src set to specified value
772 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
773 check_test_params=True)
774
775 #Insert flow with action -- set tcp src port, Send packet matching the flow, Verify recieved packet is expected packet
776 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
777 action_list=acts, max_test=2)
778
779class ModifyL4Dst(basic.SimpleDataPlane):
780
781 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
782
783 def runTest(self):
784
Rich Lane9a003812012-10-04 17:17:59 -0700785 logging.info("Running Modify_L4_Dst test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400786
787 of_ports = ac_port_map.keys()
788 of_ports.sort()
789 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
790
791 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700792 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400793 self.assertEqual(rv, 0, "Failed to delete all flows")
794
Rich Lane9a003812012-10-04 17:17:59 -0700795 logging.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
796 logging.info("Insert a flow with action -- set dst tcp port")
797 logging.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400798
799 #Verify set_tp_dst is a supported action
800 sup_acts = sw_supported_actions(self,use_cache="true")
801 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
802 skip_message_emit(self, "ModifyL4Dst test")
803 return
804
805 #Create packet to be sent and expected packet with tcp_dst set to specified value
806 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
807 check_test_params=True)
808
809 #Insert flow with action -- set tcp dst port, Send packet matching the flow, Verify recieved packet is expected packet
810 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
811 action_list=acts, max_test=2)
812
813class ModifyTos(basic.SimpleDataPlane):
814
815 """ModifyTOS :Modify the IP type of service of an IP packet"""
816
817 def runTest(self):
818
Rich Lane9a003812012-10-04 17:17:59 -0700819 logging.info("Running Modify_Tos test")
ShreyaPandita9306c772012-09-28 12:21:40 -0400820
821 of_ports = ac_port_map.keys()
822 of_ports.sort()
823 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
824
825 #Clear switch state
Rich Lane9a003812012-10-04 17:17:59 -0700826 rv = delete_all_flows(self.controller)
ShreyaPandita9306c772012-09-28 12:21:40 -0400827 self.assertEqual(rv, 0, "Failed to delete all flows")
828
Rich Lane9a003812012-10-04 17:17:59 -0700829 logging.info("Verify if switch supports the action -- modify_tos, if not skip the test")
830 logging.info("Insert a flow with action -- set type of service ")
831 logging.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
ShreyaPandita9306c772012-09-28 12:21:40 -0400832
833 #Verify set_tos is a supported action
834 sup_acts = sw_supported_actions(self,use_cache="true")
835 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
836 skip_message_emit(self, "ModifyTOS test")
837 return
838
839 #Create packet to be sent and expected packet with TOS set to specified value
840 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
841 check_test_params=True)
842
843 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
844 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
845 action_list=acts, max_test=2, egr_count=-1)