blob: b2ea42193c72b1f24e2a573d9fa048b24c64fe34 [file] [log] [blame]
Jonathan Hartf2511ca2015-07-07 14:18:19 -07001'''
2OFTests for functionality needed from the OLT.
3'''
4import logging
5from oftest import config
6import oftest.base_tests as base_tests
7import oftest.packet as scapy
8
9import ofp
Admin7e9c91d2015-08-25 15:53:49 -070010import time
Jonathan Hartf2511ca2015-07-07 14:18:19 -070011
12from oftest.testutils import *
13
14onu_port = test_param_get("onu_port", 1)
15olt_port = test_param_get("olt_port", 129)
16
17def testPacketIn(self, match, parsed_pkt):
Admin7e9c91d2015-08-25 15:53:49 -070018
Jonathan Hartf2511ca2015-07-07 14:18:19 -070019 delete_all_flows(self.controller)
20
21 pkt = str(parsed_pkt)
22
23 request = ofp.message.flow_add(
24 table_id=test_param_get("table", 0),
25 cookie=42,
26 match=match,
27 instructions=[
28 ofp.instruction.apply_actions(
29 actions=[
30 ofp.action.output(
31 port=ofp.OFPP_CONTROLLER,
32 max_len=ofp.OFPCML_NO_BUFFER)])],
33 buffer_id=ofp.OFP_NO_BUFFER,
34 priority=1000)
35
36 logging.info("Inserting flow sending matching packets to controller")
37 self.controller.message_send(request)
38 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -070039
40 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -070041 logging.info("PacketInExact test, port %d", of_port)
42 self.dataplane.send(of_port, pkt)
43 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
44 verify_packets(self, pkt, [])
45
46class EapolPacketIn(base_tests.SimpleDataPlane):
47
48 """Verify packet-ins are sent for EAPOL packets """
49
50 def runTest(self):
51 logging.info("Running EAPOL Packet In test")
52
53 match = ofp.match()
54 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
55 # Use ethertype 0x888e and multicast destination MAC address
56 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
57
58 testPacketIn(self, match, pkt)
59
60class ARPPacketIn(base_tests.SimpleDataPlane):
61
62 """Verify packet-ins are sent for ARP packets """
63
64 def runTest(self):
65 logging.info("Running ARP Packet In test")
66
67 match = ofp.match()
68 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
69
70 # Use ethertype 0x0806
71 pkt = simple_eth_packet(eth_type=0x0806)
72
73 testPacketIn(self, match, pkt)
74
Jonathan Hartf2511ca2015-07-07 14:18:19 -070075class DHCPPacketIn(base_tests.SimpleDataPlane):
76
77 """Verify packet-ins are sent for DHCP packets """
78
79 def runTest(self):
80 logging.info("Running DHCP Packet In test")
81
82 pkt = simple_udp_packet(udp_sport=68, udp_dport=67)
Admin02d052c2015-10-10 19:08:26 -070083
Jonathan Hartf2511ca2015-07-07 14:18:19 -070084 match = ofp.match()
85 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
86 match.oxm_list.append(ofp.oxm.ip_proto(17))
87 match.oxm_list.append(ofp.oxm.udp_src(68))
88 match.oxm_list.append(ofp.oxm.udp_dst(67))
89
90 testPacketIn(self, match, pkt)
91
92 # Other UDP packets should not match the rule
93 radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812)
Admin02d052c2015-10-10 19:08:26 -070094
Jonathan Hartf2511ca2015-07-07 14:18:19 -070095 self.dataplane.send(1, str(radiusPkt))
96 verify_no_packet_in(self, radiusPkt, 1)
97
98class IGMPPacketIn(base_tests.SimpleDataPlane):
99
100 """Verify packet-ins are sent for IGMP packets """
101
102 def runTest(self):
103 logging.info("Running IGMP Packet In test")
104
105 match = ofp.match()
106 match.oxm_list.append(ofp.oxm.eth_type(0x800))
107 match.oxm_list.append(ofp.oxm.ip_proto(2))
108
109 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
110 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
111
112 pkt = pkt/("0" * (100 - len(pkt)))
113
114 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700115
116class TestMeter(base_tests.SimpleDataPlane):
117
118 def runTest(self):
119 logging.info("Running Meter tests")
120 dropMeterBand = ofp.meter_band.drop(rate = 500)
121 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
122 self.controller.message_send(meter_mod)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700123
Admin7e9c91d2015-08-25 15:53:49 -0700124 time.sleep(1)
125
126 verify_no_errors(self.controller)
127
Admin02d052c2015-10-10 19:08:26 -0700128 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700129 match = ofp.match()
130 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin02d052c2015-10-10 19:08:26 -0700131 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
132
133 request = ofp.message.flow_add(
134 table_id=test_param_get("table", 0),
135 cookie=42,
136 match=match,
137 instructions=[
138 ofp.instruction.apply_actions(
139 actions=[
140 ofp.action.output(port=olt_port)]),
141 ofp.instruction.meter(meter_id = 1)
142 ],
143 buffer_id=ofp.OFP_NO_BUFFER,
144 priority=1000)
145
146 self.controller.message_send(request)
147 time.sleep(1)
148 verify_no_errors(self.controller)
149
150 match = ofp.match()
151 match.oxm_list.append(ofp.oxm.in_port(olt_port))
152 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700153
154 request = ofp.message.flow_add(
155 table_id=test_param_get("table", 0),
156 cookie=43,
157 match=match,
158 instructions=[
159 ofp.instruction.apply_actions(
160 actions=[
Admin02d052c2015-10-10 19:08:26 -0700161 ofp.action.output(port=onu_port)]),
Admin7e9c91d2015-08-25 15:53:49 -0700162 ofp.instruction.meter(meter_id = 1)
163 ],
164 buffer_id=ofp.OFP_NO_BUFFER,
165 priority=1000)
166
167 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700168 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700169 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700170 do_barrier(self.controller)
171 time.sleep(5)
Admin7e9c91d2015-08-25 15:53:49 -0700172
Admin02d052c2015-10-10 19:08:26 -0700173 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
174 # downstream
175 self.dataplane.send(olt_port, str(inPkt))
176 verify_packet(self, inPkt, onu_port)
177 # upstream
178 self.dataplane.send(olt_port, str(inPkt))
179 verify_packet(self, inPkt, onu_port)
180
181 # clean up the test
182 meter_mod = ofp.message.meter_mod(xid = 2, command = ofp.OFPMC_DELETE, meter_id = 1)
183 self.controller.message_send(meter_mod)
184 time.sleep(1)
185 delete_all_flows(self.controller)
186 verify_no_errors(self.controller)
187
188
Admin7e9c91d2015-08-25 15:53:49 -0700189class TestDuplicateMeter(base_tests.SimpleDataPlane):
190
191 def runTest(self):
192 logging.info("Running Duplicate Meter Test")
193 dropMeterBand = ofp.meter_band.drop(rate = 500)
194 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
195 self.controller.message_send(meter_mod)
196 self.controller.message_send(meter_mod)
197
198 time.sleep(1)
199
200 try:
201 verify_no_errors(self.controller)
202 except AssertionError as e:
203 if (not e.message is "unexpected error type=12 code=1"):
204 raise AssertionError("Incorrect error type: %s" % e.message)
205
206
207class VlanTest(base_tests.SimpleDataPlane):
208
209 """Verify the switch can push/pop a VLAN tag and forward out a port """
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700210
211 def runTest(self):
212 logging.info("Running push VLAN test")
213
214 vlan_id = 200
215
216 delete_all_flows(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700217
218 #PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700219 match = ofp.match()
220 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700221 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
222 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700223
224 request = ofp.message.flow_add(
225 table_id=test_param_get("table", 0),
226 cookie=42,
227 match=match,
228 instructions=[
229 ofp.instruction.apply_actions(
230 actions=[
231 ofp.action.push_vlan(ethertype=0x8100),
232 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
Admin7e9c91d2015-08-25 15:53:49 -0700233 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700234 ofp.action.output(port=olt_port)])],
235 buffer_id=ofp.OFP_NO_BUFFER,
236 priority=1000)
237
Admin7e9c91d2015-08-25 15:53:49 -0700238 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700239 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700240
Admin02d052c2015-10-10 19:08:26 -0700241 #POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700242 match = ofp.match()
243 match.oxm_list.append(ofp.oxm.in_port(olt_port))
244 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700245
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700246 request = ofp.message.flow_add(
247 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700248 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700249 match=match,
250 instructions=[
251 ofp.instruction.apply_actions(
Admin02d052c2015-10-10 19:08:26 -0700252 actions=[
253 ofp.action.pop_vlan(),
254 ofp.action.output(port=1)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700255 buffer_id=ofp.OFP_NO_BUFFER,
256 priority=1000)
257
Admin7e9c91d2015-08-25 15:53:49 -0700258 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700259 self.controller.message_send(request)
260 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700261 time.sleep(5)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700262
Admin7e9c91d2015-08-25 15:53:49 -0700263 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
264 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
265 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
266
267 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
268 self.dataplane.send(onu_port, str(inPkt))
269 verify_packet(self, outPkt, olt_port)
270
271 # Send untagged packet in the OLT port and expect no packets to come out
272 self.dataplane.send(olt_port, str(inPkt))
273 verify_packets(self, outPkt, [])
274
275 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700276 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700277 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
278
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700279 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
280 self.dataplane.send(olt_port, str(inPkt))
281 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700282
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700283 # Send tagged packet in the ONU port and expect no packets to come out
284 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700285 verify_packets(self, outPkt, [])
286
Admin02d052c2015-10-10 19:08:26 -0700287class TestGroupAdd(base_tests.SimpleDataPlane):
288
289 def runTest(self):
290 logging.info("Running Group tests")
291 delete_all_flows(self.controller)
292
293 test_group_id = 1
294 onu_port1 = 130
295 onu_port2 = 131
296 # output to two ONU
297 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port1), ofp.action.output(port=onu_port2)])
298 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
299
300 self.controller.message_send(group_add)
301 time.sleep(1)
302 verify_no_errors(self.controller)
303
304 # Remove the group and then readd it.
305 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
306 self.controller.message_send(group_delete)
307 time.sleep(1)
308 verify_no_errors(self.controller)
309
310 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
311 self.controller.message_send(group_add)
312 time.sleep(1)
313 verify_no_errors(self.controller)
314
315
316 # clean up the test
317 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
318 self.controller.message_send(group_delete)
319
320 time.sleep(1)
321 verify_no_errors(self.controller)
322
323class TestGroupMod(base_tests.SimpleDataPlane):
324
325 def runTest(self):
326 logging.info("Running Group tests")
327 delete_all_flows(self.controller)
328
329 test_group_id = 1
330 onu_port1 = 130
331 onu_port2 = 131
332 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port1)])
333 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
334
335 self.controller.message_send(group_add)
336 time.sleep(1)
337 verify_no_errors(self.controller)
338
339 # Modifying the group
340 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port2)])
341 group_mod = ofp.message.group_mod(xid = 2, command = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
342
343 self.controller.message_send(group_mod)
344 time.sleep(1)
345 verify_no_errors(self.controller)
346
347 # Add a bucket into the group
348 bucket2 = ofp.common.bucket(actions=[ofp.action.output(port=onu_port1)])
349 group_mod = ofp.message.group_mod(xid = 2, command = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket, bucket2 ])
350 self.controller.message_send(group_mod)
351 time.sleep(1)
352 verify_no_errors(self.controller)
353
354 # Modifying a non-existing group
355 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port2)])
356 group_mod = ofp.message.group_mod(xid = 3, command = 1, group_type = ofp.OFPGT_ALL, group_id = 777, buckets = [ bucket ])
357
358 self.controller.message_send(group_mod)
359 time.sleep(10)
360 errorExperienced = 0
361 try:
362 verify_no_errors(self.controller)
363 except AssertionError as e:
364 errorExperienced = 1
365 if (not (e.message == "unexpected error type=6 code=8")):
366 raise AssertionError("Incorrect error type: %s" % e.message)
367 if not errorExperienced:
368 raise AssertionError("An error message is expected, but not shown.")
369
370
371 # clean up the test
372 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
373 self.controller.message_send(group_delete)
374
375 time.sleep(1)
376 verify_no_errors(self.controller)
377
378class TestDuplicateGroup(base_tests.SimpleDataPlane):
379
380 def runTest(self):
381 logging.info("Running Group tests")
382 delete_all_flows(self.controller)
383
384 test_group_id = 1
385 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port)])
386 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
387
388 self.controller.message_send(group_add)
389 time.sleep(1)
390 verify_no_errors(self.controller)
391
392 # Add the same group id
393 duplicate_group_fail = 0
394 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
395
396 self.controller.message_send(group_add)
397 time.sleep(1)
398 try:
399 verify_no_errors(self.controller)
400 except AssertionError as e:
401 duplicate_group_fail = 1
402 if (not e.message is "unexpected error type=12 code=1"):
403 raise AssertionError("Incorrect error type: %s" % e.message)
404 if not duplicate_group_fail:
405 raise AssertionError("Adding duplicate groups didn't raise an error.")
406
407 # clean up the test
408 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
409 self.controller.message_send(group_delete)
410
411 time.sleep(1)
412 verify_no_errors(self.controller)
413
414class TestGroupAndFlow(base_tests.SimpleDataPlane):
415
416 def runTest(self):
417 logging.info("Running Group tests")
418 delete_all_flows(self.controller)
419
420 # Create a group
421 test_group_id = 1
422 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port)])
423 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
424
425 self.controller.message_send(group_add)
426 time.sleep(1)
427 verify_no_errors(self.controller)
428
429 # Create a flow rule matching olt port and vlan id
430 match = ofp.match()
431 match.oxm_list.append(ofp.oxm.in_port(olt_port))
432 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
433
434 request = ofp.message.flow_add(
435 table_id=test_param_get("table", 0),
436 cookie=43,
437 match=match,
438 instructions=[
439 ofp.instruction.apply_actions(
440 actions=[ ofp.action.group( group_id = test_group_id ) ] ) ],
441 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
442
443 self.controller.message_send(request)
444 time.sleep(1)
445 verify_no_errors(self.controller)
446
447 # After letting a flow rule point to the group, test we can do group_mod
448 onu_port2 = 131
449 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port2)])
450 group_mod = ofp.message.group_mod(xid = 2, command = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
451 self.controller.message_send(group_mod)
452 time.sleep(1)
453 verify_no_errors(self.controller)
454
455 # Test we can remove flows and then remove group
456 request = ofp.message.flow_delete( table_id=test_param_get("table", 0))
457 self.controller.message_send(request)
458 time.sleep(1)
459 verify_no_errors(self.controller)
460
461 group_delete = ofp.message.group_delete(xid = 3, group_id = test_group_id)
462 self.controller.message_send(group_delete)
463 time.sleep(1)
464 verify_no_errors(self.controller)
465
466 # Add the group and flow back, test it we can first remove group and then remove the flow.
467 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
468 self.controller.message_send(group_add)
469 request = ofp.message.flow_add(
470 table_id=test_param_get("table", 0),
471 cookie=43,
472 match=match,
473 instructions=[
474 ofp.instruction.apply_actions(
475 actions=[ ofp.action.group( group_id = test_group_id ) ] ) ],
476 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
477 self.controller.message_send(request)
478 verify_no_errors(self.controller)
479
480 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
481 self.controller.message_send(group_delete)
482 request = ofp.message.flow_delete( table_id=test_param_get("table", 0))
483 self.controller.message_send(request)
484 time.sleep(1)
485 verify_no_errors(self.controller)
486
487
488class TestGroupForwarding(base_tests.SimpleDataPlane):
489
490 def runTest(self):
491 logging.info("Running Group datapath forwarding tests")
492 delete_all_flows(self.controller)
493
494 vlan_id = 200
495
496 # Create a group
497 test_group_id = 1
498 onu_port = 130
499 bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port)])
500 group_add = ofp.message.group_add(xid = 1, group_type = ofp.OFPGT_ALL, group_id = test_group_id, buckets = [ bucket ])
501
502 self.controller.message_send(group_add)
503 time.sleep(1)
504 verify_no_errors(self.controller)
505
506 # Create a flow rule matching olt port and vlan id
507 match = ofp.match()
508 match.oxm_list.append(ofp.oxm.in_port(olt_port))
509 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
510
511 request = ofp.message.flow_add(
512 table_id=test_param_get("table", 0),
513 cookie=43,
514 match=match,
515 instructions=[
516 ofp.instruction.apply_actions(
517 actions=[ ofp.action.group( group_id = test_group_id ) ] ),
518 ],
519 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
520
521 self.controller.message_send(request)
522 time.sleep(1)
523 verify_no_errors(self.controller)
524 do_barrier(self.controller)
525 time.sleep(5)
526
527 inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True,
528 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
529 outPkt = inPkt
530 self.dataplane.send(olt_port, str(inPkt))
531 verify_packet(self, outPkt, onu_port)
532 time.sleep(1)
533 verify_no_errors(self.controller)
534
535 #group_mod test
536 #bucket = ofp.common.bucket(actions=[ofp.action.output(port=onu_port), ofp.action.push_vlan(0x0081)])
537 #group_mod = ofp.message.group_mod(xid = 1, command = 1, group_type = ofp.OFPGT_ALL, group_id = 2, buckets = [ bucket ])
538
539 #self.controller.message_send(group_mod)
540 #time.sleep(1)
541 #verify_no_errors(self.controller)
542
543
544 # clean up the test
545 request = ofp.message.flow_delete( table_id=test_param_get("table", 0))
546 self.controller.message_send(request)
547 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
548 self.controller.message_send(group_delete)
549
550 time.sleep(1)
551 verify_no_errors(self.controller)
552
553class TransparentVlanTest(base_tests.SimpleDataPlane):
554
555 def runTest(self):
556 logging.info("Running transparent vlan tests")
557
558 vlan_id = 201
559 match = ofp.match()
560 match.oxm_list.append(ofp.oxm.in_port(onu_port))
561 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
562
563 request = ofp.message.flow_add(
564 table_id=test_param_get("table", 0),
565 cookie=42,
566 match=match,
567 instructions=[
568 ofp.instruction.apply_actions(
569 actions=[
570 ofp.action.output(port=olt_port)]),
571 ],
572 buffer_id=ofp.OFP_NO_BUFFER,
573 priority=1000)
574
575 self.controller.message_send(request)
576 time.sleep(1)
577 verify_no_errors(self.controller)
578
579 match = ofp.match()
580 match.oxm_list.append(ofp.oxm.in_port(olt_port))
581 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
582
583 request = ofp.message.flow_add(
584 table_id=test_param_get("table", 0),
585 cookie=43,
586 match=match,
587 instructions=[
588 ofp.instruction.apply_actions(
589 actions=[
590 ofp.action.output(port=onu_port)]),
591 ],
592 buffer_id=ofp.OFP_NO_BUFFER,
593 priority=1000)
594
595 self.controller.message_send(request)
596 verify_no_errors(self.controller)
597 do_barrier(self.controller)
598 time.sleep(5)
599
600 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=(vlan_id), vlan_pcp=0)
601 # downstream
602 self.dataplane.send(olt_port, str(inPkt))
603 verify_packet(self, inPkt, onu_port)
604 # upstream
605 self.dataplane.send(onu_port, str(inPkt))
606 verify_packet(self, inPkt, olt_port)
607
608
609 # clean up the test
610 delete_all_flows(self.controller)
611 time.sleep(1)
612 verify_no_errors(self.controller)
613
614