blob: 423a8d13454a4b2906956ebb8e36744b0a73f5ef [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
23from testutils import *
24from time import sleep
25from FuncUtils import *
26
27ac_port_map = None
28ac_logger = None
29ac_config = None
30of_ports = None
31
32def test_set_init(config):
33 basic.test_set_init(config)
34
35 global ac_port_map
36 global ac_logger
37 global ac_config
38 global of_ports
39
40 ac_logger = logging.getLogger("Running Actions test-suite")
41 ac_logger.info("Initializing test set")
42 ac_port_map = config["port_map"]
43 ac_config = config
44
45 of_ports = ac_port_map.keys()
46 of_ports.sort()
47
48
49
50class NoAction(basic.SimpleDataPlane):
51
52 """NoActionDrop : no action added to flow , drops the packet."""
53
54 def runTest(self):
55
56 ac_logger.info("Running No_Action test")
57
58 of_ports = ac_port_map.keys()
59 of_ports.sort()
60 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
61
62 #Clear switch state
63 rv = delete_all_flows(self.controller, ac_logger)
64 self.assertEqual(rv, 0, "Failed to delete all flows")
65
66 ac_logger.info("Install a flow without action")
67 ac_logger.info("Send packets matching that flow")
68 ac_logger.info("Expecting switch to drop all packets")
69
70 # Insert a flow wildcard all without any action
71 pkt = simple_tcp_packet()
72 match = parse.packet_to_flow_match(pkt)
73 self.assertTrue(match is not None, "Could not generate flow match from pkt")
74 match.wildcards=ofp.OFPFW_ALL
75 match.in_port = of_ports[0]
76
77 msg = message.flow_mod()
78 msg.out_port = ofp.OFPP_NONE
79 msg.command = ofp.OFPFC_ADD
80 msg.buffer_id = 0xffffffff
81 msg.match = match
82 rv = self.controller.message_send(msg)
83 self.assertTrue(rv != -1, "Error installing flow mod")
84
85 #Sending N packets matching the flow inserted
86 for pkt_cnt in range(5):
87 self.dataplane.send(of_ports[0],str(pkt))
88
89 #Verify packets not recieved on any of the dataplane ports
ShreyaPandita7b9ec982012-09-28 14:43:08 -040090 (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1,exp_pkt=pkt)
91 self.assertTrue(rcv_pkt is None,
92 "Packet received on port " + str(any_port))
ShreyaPandita9306c772012-09-28 12:21:40 -040093
94 #Verify packets not sent on control plane either
95 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=1)
96 self.assertTrue(response is None,
97 'Packets not received on control plane')
98
99
100class Announcement(basic.SimpleDataPlane):
101
102 """Announcement : Get all supported actions by the switch.
103 Send OFPT_FEATURES_REQUEST to get features supported by sw."""
104
105 def runTest(self):
106
107 ac_logger.info("Running Announcement test")
108
109 ac_logger.info("Sending Features_Request")
110 ac_logger.info("Expecting Features Reply with supported actions")
111
112 # Sending Features_Request
113 request = message.features_request()
114 (reply, pkt) = self.controller.transact(request)
115 self.assertTrue(reply is not None, "Failed to get any reply")
116 self.assertEqual(reply.header.type, ofp.OFPT_FEATURES_REPLY,'Response is not Features_reply')
117
118 supported_actions =[]
119 if(reply.actions &1<<ofp.OFPAT_OUTPUT):
120 supported_actions.append('OFPAT_OUTPUT')
121 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_VID):
122 supported_actions.append('OFPAT_SET_VLAN_VID')
123 if(reply.actions &1<<ofp.OFPAT_SET_VLAN_PCP):
124 supported_actions.append('OFPAT_SET_VLAN_PCP')
125 if(reply.actions &1<<ofp.OFPAT_STRIP_VLAN):
126 supported_actions.append('OFPAT_STRIP_VLAN')
127 if(reply.actions &1<<ofp.OFPAT_SET_DL_SRC):
128 supported_actions.append('OFPAT_SET_DL_SRC')
129 if(reply.actions &1<<ofp.OFPAT_SET_DL_DST):
130 supported_actions.append('OFPAT_SET_NW_SRC')
131 if(reply.actions &1<<ofp.OFPAT_SET_NW_DST):
132 supported_actions.append('OFPAT_SET_NW_DST')
133 if(reply.actions &1<<ofp.OFPAT_SET_NW_TOS):
134 supported_actions.append('OFPAT_SET_NW_TOS')
135 if(reply.actions &1<<ofp.OFPAT_SET_TP_SRC):
136 supported_actions.append('OFPAT_SET_TP_SRC')
137 if(reply.actions &1<<ofp.OFPAT_SET_TP_DST):
138 supported_actions.append('OFPAT_SET_TP_DST')
139 if(reply.actions &1<<ofp.OFPAT_VENDOR):
140 supported_actions.append('OFPAT_VENDOR')
141 if(reply.actions &1<<ofp.OFPAT_ENQUEUE):
142 supported_actions.append('OFPAT_ENQUEUE')
143
144 ac_logger.info(supported_actions)
145
146
147class ForwardAll(basic.SimpleDataPlane):
148
149 """ForwardAll : Packet is sent to all dataplane ports
150 except ingress port when output action.port = OFPP_ALL"""
151
152 def runTest(self):
153
154 ac_logger.info("Running Forward_All test")
155
156 of_ports = ac_port_map.keys()
157 of_ports.sort()
158 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
159
160 #Clear switch state
161 rv = delete_all_flows(self.controller, ac_logger)
162 self.assertEqual(rv, 0, "Failed to delete all flows")
163
164 ac_logger.info("Insert a flow with output action port OFPP_ALL")
165 ac_logger.info("Send packet matching the flow")
166 ac_logger.info("Expecting packet on all dataplane ports except ingress_port")
167
168 #Create a packet
169 pkt = simple_tcp_packet()
170 match = parse.packet_to_flow_match(pkt)
171 act = action.action_output()
172
173 #Delete all flows
174 rv = delete_all_flows(self.controller, ac_logger)
175 self.assertEqual(rv, 0, "Failed to delete all flows")
176 ingress_port=of_ports[0]
177 match.in_port = ingress_port
178
179 #Create a flow mod with action.port = OFPP_ALL
180 request = message.flow_mod()
181 request.match = match
182 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
183 act.port = ofp.OFPP_ALL
184 request.actions.add(act)
185
186 ac_logger.info("Inserting flow")
187 rv = self.controller.message_send(request)
188 self.assertTrue(rv != -1, "Error installing flow mod")
189 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
190
191 #Send Packet matching the flow
192 ac_logger.info("Sending packet to dp port " + str(ingress_port))
193 self.dataplane.send(ingress_port, str(pkt))
194
195 #Verifying packets recieved on expected dataplane ports
196 yes_ports = set(of_ports).difference([ingress_port])
197 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
198 self, ac_logger, ac_config)
199
200
201class ForwardController(basic.SimpleDataPlane):
202
203 """ForwardController : Packet is sent to controller
204 output.port = OFPP_CONTROLLER"""
205
206 def runTest(self):
207
208 ac_logger.info("Running Forward_Controller test")
209
210 of_ports = ac_port_map.keys()
211 of_ports.sort()
212 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
213
214 #Clear switch state
215 rv = delete_all_flows(self.controller, ac_logger)
216 self.assertEqual(rv, 0, "Failed to delete all flows")
217
218 ac_logger.info("Insert a flow with output action port OFPP_CONTROLLER")
219 ac_logger.info("Send packet matching the flow")
220 ac_logger.info("Expecting packet on the control plane")
221
222 #Create packet
223 pkt = simple_tcp_packet()
224 match = parse.packet_to_flow_match(pkt)
225 act = action.action_output()
226
227 for ingress_port in of_ports:
228 #Delete all flows
229 rv = delete_all_flows(self.controller, ac_logger)
230 self.assertEqual(rv, 0, "Failed to delete all flows")
231
232 match.in_port = ingress_port
233
234 #Create a flow mod message
235 request = message.flow_mod()
236 request.match = match
237 act.port = ofp.OFPP_CONTROLLER
238 request.actions.add(act)
239
240 ac_logger.info("Inserting flow")
241 rv = self.controller.message_send(request)
242 self.assertTrue(rv != -1, "Error installing flow mod")
243 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
244
245 #Send packet matching the flow
246 ac_logger.info("Sending packet to dp port " + str(ingress_port))
247 self.dataplane.send(ingress_port, str(pkt))
248
249 #Verifying packet recieved on the control plane port
250 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, timeout=10)
251 self.assertTrue(response is not None,
252 'Packet in message not received by controller')
253
254
255
256class ForwardLocal(basic.SimpleDataPlane):
257
258 """ForwardLocal : Packet is sent to OFPP_LOCAL port .
259 TBD : To verify packet recieved in the local networking stack of switch"""
260
261 def runTest(self):
262
263 ac_logger.info("Running Forward_Local test")
264
265 of_ports = ac_port_map.keys()
266 of_ports.sort()
267 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
268
269 #Clear switch state
270 rv = delete_all_flows(self.controller, ac_logger)
271 self.assertEqual(rv, 0, "Failed to delete all flows")
272
273 ac_logger.info("Insert a flow with output action port OFPP_LOCAL")
274 ac_logger.info("Send packet matching the flow")
275 ac_logger.info("Expecting packet in the local networking stack of switch")
276
277 #Clear switch state
278 pkt = simple_tcp_packet()
279 match = parse.packet_to_flow_match(pkt)
280 act = action.action_output()
281
282 for ingress_port in of_ports:
283 #Delete the flows
284 rv = delete_all_flows(self.controller, ac_logger)
285 self.assertEqual(rv, 0, "Failed to delete all flows")
286
287 match.in_port = ingress_port
288 #Create flow mod message
289 request = message.flow_mod()
290 request.match = match
291 act.port = ofp.OFPP_LOCAL
292 request.actions.add(act)
293
294 ac_logger.info("Inserting flow")
295 rv = self.controller.message_send(request)
296 self.assertTrue(rv != -1, "Error installing flow mod")
297 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
298
299 #Send packet matching the flow
300 ac_logger.info("Sending packet to dp port " + str(ingress_port))
301 self.dataplane.send(ingress_port, str(pkt))
302
303 #TBD: Verification of packets being recieved.
304
305
306class ForwardFlood(basic.SimpleDataPlane):
307
308 """Forward:Flood : Packet is sent to all dataplane ports
309 except ingress port when output action.port = OFPP_FLOOD
310 TBD : Verification---Incase of STP being implemented, flood the packet along the minimum spanning tree,
311 not including the incoming interface. """
312
313 def runTest(self):
314
315 ac_logger.info("Running Forward_Flood test")
316 of_ports = ac_port_map.keys()
317 of_ports.sort()
318 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
319
320 #Clear switch state
321 rv = delete_all_flows(self.controller, ac_logger)
322 self.assertEqual(rv, 0, "Failed to delete all flows")
323
324 ac_logger.info("Insert a flow with output action port OFPP_FORWARD")
325 ac_logger.info("Send packet matching the flow")
326 ac_logger.info("Expecting packet on all the ports except the input port")
327
328 #Create a packet
329 pkt = simple_tcp_packet()
330 match = parse.packet_to_flow_match(pkt)
331 act = action.action_output()
332
333 #Delete all flows
334 rv = delete_all_flows(self.controller, ac_logger)
335 self.assertEqual(rv, 0, "Failed to delete all flows")
336 ingress_port=of_ports[0]
337 match.in_port = ingress_port
338
339 #Create a flow mod with action.port = OFPP_ALL
340 request = message.flow_mod()
341 request.match = match
342 request.match.wildcards = ofp.OFPFW_ALL&~ofp.OFPFW_IN_PORT
343 act.port = ofp.OFPP_FLOOD
344 request.actions.add(act)
345
346 ac_logger.info("Inserting flow")
347 rv = self.controller.message_send(request)
348 self.assertTrue(rv != -1, "Error installing flow mod")
349 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
350
351 #Send Packet matching the flow
352 ac_logger.info("Sending packet to dp port " + str(ingress_port))
353 self.dataplane.send(ingress_port, str(pkt))
354
355 #Verifying packets recieved on expected dataplane ports
356 yes_ports = set(of_ports).difference([ingress_port])
357 receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port],
358 self, ac_logger, ac_config)
359
360class ForwardInport(basic.SimpleDataPlane):
361
362 """ ForwardInPort : Packet sent to virtual port IN_PORT
363 If the output.port = OFPP.INPORT then the packet is sent to the input port itself"""
364
365 def runTest(self):
366
367 ac_logger.info("Running Forward_Inport test")
368
369 of_ports = ac_port_map.keys()
370 of_ports.sort()
371 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
372
373 #Clear switch state
374 rv = delete_all_flows(self.controller, ac_logger)
375 self.assertEqual(rv, 0, "Failed to delete all flows")
376
377 ac_logger.info("Insert a flow with output action port OFPP_INPORT")
378 ac_logger.info("Send packet matching the flow")
379 ac_logger.info("Expecting packet on the input port")
380
381 #Create a packet
382 pkt = simple_tcp_packet()
383 match = parse.packet_to_flow_match(pkt)
384 act = action.action_output()
385
386 #Delete the flows
387 rv = delete_all_flows(self.controller, ac_logger)
388 self.assertEqual(rv, 0, "Failed to delete all flows")
389 ingress_port=of_ports[0]
390 match.in_port = ingress_port
391
392 # Create a flow mod message
393 request = message.flow_mod()
394 request.match = match
395 act.port = ofp.OFPP_IN_PORT
396
397 request.actions.add(act)
398 ac_logger.info("Inserting flow")
399 rv = self.controller.message_send(request)
400 self.assertTrue(rv != -1, "Error installing flow mod")
401 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
402
403 #Send packet matching the flow
404 ac_logger.info("Sending packet to dp port " + str(ingress_port))
405 self.dataplane.send(ingress_port, str(pkt))
406 yes_ports = [ingress_port]
407
408 #Verfying packet recieved on expected dataplane ports
409 receive_pkt_check(self.dataplane, pkt, yes_ports,set(of_ports).difference([ingress_port]),
410 self, ac_logger, ac_config)
411
412class ForwardTable(basic.SimpleDataPlane):
413
414 """ForwardTable : Perform actions in flow table. Only for packet-out messages.
415 If the output action.port in the packetout message = OFP.TABLE , then
416 the packet implements the action specified in the matching flow of the FLOW-TABLE"""
417
418 def runTest(self):
419
420 ac_logger.info("Running Forward_Table test")
421
422 of_ports = ac_port_map.keys()
423 of_ports.sort()
424 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
425
426 #Clear switch state
427 rv = delete_all_flows(self.controller, ac_logger)
428 self.assertEqual(rv, 0, "Failed to delete all flows")
429
430 ac_logger.info("Insert a flow F with output action port set to some egress_port")
431 ac_logger.info("Send packet out message (matching flow F) with action.port = OFP.TABLE")
432 ac_logger.info("Expecting packet on the egress_port")
433
434 #Insert a all wildcarded flow
435 (pkt,match) = Wildcard_All(self,of_ports)
436
437 #Create a packet out message
438 pkt_out =message.packet_out();
439 pkt_out.data = str(pkt)
440 pkt_out.in_port = of_ports[0]
441 act = action.action_output()
442 act.port = ofp.OFPP_TABLE
443 pkt_out.actions.add(act)
444 rv = self.controller.message_send(pkt_out)
445 self.assertTrue(rv == 0, "Error sending out message")
446
447 #Verifying packet out message recieved on the expected dataplane port.
448 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=of_ports[1],
449 exp_pkt=pkt,timeout=3)
450 self.assertTrue(pkt is not None, 'Packet not received')
451
452
ShreyaPandita82c43be2012-09-28 13:16:30 -0400453class AddVlanTag(basic.SimpleDataPlane):
ShreyaPandita9306c772012-09-28 12:21:40 -0400454
455 """AddVlanTag : Adds VLAN Tag to untagged packet."""
456
457 def runTest(self):
458
459 ac_logger.info("Running Add_vlan_tag test")
460
461 of_ports = ac_port_map.keys()
462 of_ports.sort()
463 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
464
465 #Clear switch state
466 rv = delete_all_flows(self.controller, ac_logger)
467 self.assertEqual(rv, 0, "Failed to delete all flows")
468
469 ac_logger.info("Verify if switch supports the action -- set vlan id, if not skip the test")
470 ac_logger.info("Insert a flow with set vid action")
471 ac_logger.info("Send packet matching the flow , verify recieved packet has vid set")
472
473 #Verify set_vlan_id is a supported action
474 sup_acts = sw_supported_actions(self)
475 if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
476 skip_message_emit(self, "Add VLAN tag test skipped")
477 return
478
479 #Create packet to be sent and an expected packet with vid set
480 new_vid = 2
481 len_wo_vid = 100
482 len_w_vid = 104
483 pkt = simple_tcp_packet(pktlen=len_wo_vid)
484 exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True,
485 dl_vlan=new_vid,dl_vlan_pcp=0)
486 vid_act = action.action_set_vlan_vid()
487 vid_act.vlan_vid = new_vid
488
489 #Insert flow with action -- set vid , Send packet matching the flow, Verify recieved packet is expected packet
490 flow_match_test(self, ac_port_map, pkt=pkt,
491 exp_pkt=exp_pkt, action_list=[vid_act])
492
493class ModifyVlanTag(basic.SimpleDataPlane):
494
495 """ModifyVlanTag : Modifies VLAN Tag to tagged packet."""
496
497 def runTest(self):
498
499 ac_logger.info("Running Modify_Vlan_Tag test")
500
501 of_ports = ac_port_map.keys()
502 of_ports.sort()
503 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
504
505 #Clear switch state
506 rv = delete_all_flows(self.controller, ac_logger)
507 self.assertEqual(rv, 0, "Failed to delete all flows")
508
509 ac_logger.info("Verify if switch supports the action -- modify vlan id, if not skip the test")
510 ac_logger.info("Insert a flow with action --set vid ")
511 ac_logger.info("Send tagged packet matching the flow , verify recieved packet has vid rewritten")
512
513 #Verify set_vlan_id is a supported action
514 sup_acts = sw_supported_actions(self)
515 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
516 skip_message_emit(self, "Modify VLAN tag test skipped")
517 return
518
519 #Create a tagged packet with old_vid to be sent, and expected packet with new_vid
520 old_vid = 2
521 new_vid = 3
522 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid)
523 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid)
524 vid_act = action.action_set_vlan_vid()
525 vid_act.vlan_vid = new_vid
526
527 #Insert flow with action -- set vid , Send packet matching the flow.Verify recieved packet is expected packet.
528 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
529 action_list=[vid_act])
530
531class VlanPrio1(basic.SimpleDataPlane):
532
533 """AddVlanPrioUntaggedPkt : Add VLAN priority to untagged packet."""
534
535 def runTest(self):
536
537 ac_logger.info("Running vlan_Prio_1 test")
538
539 of_ports = ac_port_map.keys()
540 of_ports.sort()
541 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
542
543 #Clear switch state
544 rv = delete_all_flows(self.controller, ac_logger)
545 self.assertEqual(rv, 0, "Failed to delete all flows")
546
547 ac_logger.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
548 ac_logger.info("Insert a flow with action -- set vlan priority ")
549 ac_logger.info("Send untagged packet matching the flow , verify recieved packet has specified VLAN priority and has vid set tO 0 ")
550
551 #Verify set_vlan_priority is a supported action
552 sup_acts = sw_supported_actions(self)
553 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
554 skip_message_emit(self, "Set VLAN priority test skipped")
555 return
556
557 #Create a untagged packet to be sent and an expected packet with vid = 0 , vlan_priority set.
558 vlan_id = 0
559 pkt = simple_tcp_packet()
560 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vlan_id,dl_vlan_pcp=0)
561 act = action.action_set_vlan_vid()
562
563 #Insert flow with action -- set vLAN priority, Send packet matching the flow, Verify recieved packet is expected packet
564 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
565 action_list=[act])
566
567
568class VlanPrio2(basic.SimpleDataPlane):
569
570 """ModifyVlanPrio : Modify VLAN priority to tagged packet."""
571
572 def runTest(self):
573
574 ac_logger.info("Running Vlan_Prio_2 test")
575
576 of_ports = ac_port_map.keys()
577 of_ports.sort()
578 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
579
580 #Clear switch state
581 rv = delete_all_flows(self.controller, ac_logger)
582 self.assertEqual(rv, 0, "Failed to delete all flows")
583
584 ac_logger.info("Verify if switch supports the action -- set vlan priority, if not skip the test")
585 ac_logger.info("Insert a flow with action -- set vlan priority ")
586 ac_logger.info("Send tagged packet matching the flow, verify recieved packet has vlan priority rewritten")
587
588 #Verify set_vlan_priority is a supported action
589 sup_acts = sw_supported_actions(self,"true")
590 if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP):
591 skip_message_emit(self, "modify_vlan_prio test skipped")
592 return
593
594 #Create a tagged packet , and an expected packet with vlan_priority set to specified value
595 vid = 123
596 old_vlan_pcp = 2
597 new_vlan_pcp = 3
598 pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp)
599 exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp)
600 vid_act = action.action_set_vlan_pcp()
601 vid_act.vlan_pcp = new_vlan_pcp
602
603 #Insert flow with action -- set vLAN priority, Send tagged packet matching the flow, Verify recieved packet is expected packet
604 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
605 action_list=[vid_act])
606
607
608class ModifyL2Src(basic.SimpleDataPlane):
609
610 """ModifyL2Src :Modify the source MAC address"""
611
612 def runTest(self):
613
614 ac_logger.info("Running Modify_L2_Src test")
615
616 of_ports = ac_port_map.keys()
617 of_ports.sort()
618 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
619
620 #Clear switch state
621 rv = delete_all_flows(self.controller, ac_logger)
622 self.assertEqual(rv, 0, "Failed to delete all flows")
623
624 ac_logger.info("Verify if switch supports the action -- modify_l2_src, if not skip the test")
625 ac_logger.info("Insert a flow with action -- set etherent src address")
626 ac_logger.info("Send packet matching the flow, verify recieved packet src address rewritten ")
627
628 #Verify set_dl_src is a supported action
629 sup_acts = sw_supported_actions(self,use_cache="true")
630 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC):
631 skip_message_emit(self, "modify_l2_src test skipped")
632 return
633
634 #Create packet to be sent and expected packet with dl_src set to specified value
635 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'],
636 check_test_params=True)
637
638 #Insert flow with action -- set src address, Send packet matching the flow, Verify recieved packet is expected packet
639 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
640 action_list=acts, max_test=2)
641
642
643class ModifyL2Dst(basic.SimpleDataPlane):
644
645 """ModifyL2SDSt :Modify the dest MAC address"""
646
647 def runTest(self):
648
649 ac_logger.info("Running Modify_L2_Dst test")
650
651 of_ports = ac_port_map.keys()
652 of_ports.sort()
653 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
654
655 #Clear switch state
656 rv = delete_all_flows(self.controller, ac_logger)
657 self.assertEqual(rv, 0, "Failed to delete all flows")
658
659 ac_logger.info("Verify if switch supports the action -- modify_l2_dst, if not skip the test")
660 ac_logger.info("Insert a flow with action -- set etherent dst address ")
661 ac_logger.info("Send packet matching the flow, verify recieved packet dst address rewritten ")
662
663 #Verify set_dl_dst is a supported action
664 sup_acts = sw_supported_actions(self)
665 if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST):
666 skip_message_emit(self, "modify_l2_dst test skipped")
667 return
668
669 #Create packet to be sent and expected packet with dl_src set to specified value
670 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'],
671 check_test_params=True)
672
673 #Insert flow with action -- set dst address, Send packet matching the flow, Verify recieved packet is expected packet
674 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
675 action_list=acts, max_test=2)
676
677class ModifyL3Src(basic.SimpleDataPlane):
678
679 """ModifyL3Src : Modify the source IP address of an IP packet """
680
681 def runTest(self):
682
683 ac_logger.info("Running Modify_L3_Src test")
684
685 of_ports = ac_port_map.keys()
686 of_ports.sort()
687 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
688
689 #Clear switch state
690 rv = delete_all_flows(self.controller, ac_logger)
691 self.assertEqual(rv, 0, "Failed to delete all flows")
692
693 ac_logger.info("Verify if switch supports the action -- modify_l3_src, if not skip the test")
694 ac_logger.info("Insert a flow with action -- set network src address ")
695 ac_logger.info("Send packet matching the flow, verify recieved packet network src address rewritten ")
696
697 #Verify set_nw_src is a supported action
698 sup_acts = sw_supported_actions(self)
699 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC):
700 skip_message_emit(self, "modify_l3_src test")
701 return
702
703 #Create packet to be sent and expected packet with nw_src set to specified value
704 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'],
705 check_test_params=True)
706
707 #Insert flow with action -- set nw src address, Send packet matching the flow, Verify recieved packet is expected packet
708 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
709 action_list=acts, max_test=2)
710
711class ModifyL3Dst(basic.SimpleDataPlane):
712
713 """ModifyL3Dst :Modify the dest IP address of an IP packet"""
714
715 def runTest(self):
716
717 ac_logger.info("Running Modify_L3_Dst test")
718
719 of_ports = ac_port_map.keys()
720 of_ports.sort()
721 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
722
723 #Clear switch state
724 rv = delete_all_flows(self.controller, ac_logger)
725 self.assertEqual(rv, 0, "Failed to delete all flows")
726
727 ac_logger.info("Verify if switch supports the action -- modify_l3_dst, if not skip the test")
728 ac_logger.info("Insert a flow with action -- set network dst address ")
729 ac_logger.info("Send packet matching the flow, verify recieved packet network dst address rewritten ")
730
731 #Verify set_nw_dst is a supported action
732 sup_acts = sw_supported_actions(self,use_cache="true")
733 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST):
734 skip_message_emit(self, "modify_l3_dst test skipped")
735 return
736
737 #Create packet to be sent and expected packet with nw_dst set to specified value
738 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'],
739 check_test_params=True)
740
741 #Insert flow with action -- set nw dst address, Send packet matching the flow, Verify recieved packet is expected packet
742 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
743 action_list=acts, max_test=2)
744
745
746class ModifyL4Src(basic.SimpleDataPlane):
747
748 """ModifyL4Src : Modify the source TCP port of a TCP packet"""
749
750 def runTest(self):
751
752 ac_logger.info("Running Modify_L4_Src test")
753
754 of_ports = ac_port_map.keys()
755 of_ports.sort()
756 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
757
758 #Clear switch state
759 rv = delete_all_flows(self.controller, ac_logger)
760 self.assertEqual(rv, 0, "Failed to delete all flows")
761
762 ac_logger.info("Verify if switch supports the action -- modify_l4_src, if not skip the test")
763 ac_logger.info("Insert a flow with action -- set src tcp port")
764 ac_logger.info("Send packet matching the flow, verify recieved packet src tcp port is rewritten ")
765
766 #Verify set_tp_src is a supported action
767 sup_acts = sw_supported_actions(self,use_cache="true")
768 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC):
769 skip_message_emit(self, "modify_l4_src test skipped")
770 return
771
772 #Create packet to be sent and expected packet with tcp_src set to specified value
773 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'],
774 check_test_params=True)
775
776 #Insert flow with action -- set tcp src port, Send packet matching the flow, Verify recieved packet is expected packet
777 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
778 action_list=acts, max_test=2)
779
780class ModifyL4Dst(basic.SimpleDataPlane):
781
782 """ ModifyL4Dst: Modify the dest TCP port of a TCP packet """
783
784 def runTest(self):
785
786 ac_logger.info("Running Modify_L4_Dst test")
787
788 of_ports = ac_port_map.keys()
789 of_ports.sort()
790 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
791
792 #Clear switch state
793 rv = delete_all_flows(self.controller, ac_logger)
794 self.assertEqual(rv, 0, "Failed to delete all flows")
795
796 ac_logger.info("Verify if switch supports the action -- modify_l4_dst, if not skip the test")
797 ac_logger.info("Insert a flow with action -- set dst tcp port")
798 ac_logger.info("Send packet matching the flow, verify recieved packet dst tcp port is rewritten ")
799
800 #Verify set_tp_dst is a supported action
801 sup_acts = sw_supported_actions(self,use_cache="true")
802 if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST):
803 skip_message_emit(self, "ModifyL4Dst test")
804 return
805
806 #Create packet to be sent and expected packet with tcp_dst set to specified value
807 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'],
808 check_test_params=True)
809
810 #Insert flow with action -- set tcp dst port, Send packet matching the flow, Verify recieved packet is expected packet
811 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
812 action_list=acts, max_test=2)
813
814class ModifyTos(basic.SimpleDataPlane):
815
816 """ModifyTOS :Modify the IP type of service of an IP packet"""
817
818 def runTest(self):
819
820 ac_logger.info("Running Modify_Tos test")
821
822 of_ports = ac_port_map.keys()
823 of_ports.sort()
824 self.assertTrue(len(of_ports) > 1, "Not enough ports for test")
825
826 #Clear switch state
827 rv = delete_all_flows(self.controller, ac_logger)
828 self.assertEqual(rv, 0, "Failed to delete all flows")
829
830 ac_logger.info("Verify if switch supports the action -- modify_tos, if not skip the test")
831 ac_logger.info("Insert a flow with action -- set type of service ")
832 ac_logger.info("Send packet matching the flow, verify recieved packet has TOS rewritten ")
833
834 #Verify set_tos is a supported action
835 sup_acts = sw_supported_actions(self,use_cache="true")
836 if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
837 skip_message_emit(self, "ModifyTOS test")
838 return
839
840 #Create packet to be sent and expected packet with TOS set to specified value
841 (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'],
842 check_test_params=True)
843
844 #Insert flow with action -- set TOS, Send packet matching the flow, Verify recieved packet is expected packet
845 flow_match_test(self, ac_port_map, pkt=pkt, exp_pkt=exp_pkt,
846 action_list=acts, max_test=2, egr_count=-1)