blob: 5b157711e078bab74eb1271fe4f08cc732f30bce [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)
Jonathan Hartf65e1812015-10-05 15:15:37 -070015onu_port2 = test_param_get("onu_port2", 2)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070016olt_port = test_param_get("olt_port", 129)
17
18def testPacketIn(self, match, parsed_pkt):
Admin7e9c91d2015-08-25 15:53:49 -070019
Jonathan Hartf2511ca2015-07-07 14:18:19 -070020 delete_all_flows(self.controller)
21
22 pkt = str(parsed_pkt)
23
24 request = ofp.message.flow_add(
25 table_id=test_param_get("table", 0),
26 cookie=42,
27 match=match,
28 instructions=[
29 ofp.instruction.apply_actions(
30 actions=[
31 ofp.action.output(
32 port=ofp.OFPP_CONTROLLER,
33 max_len=ofp.OFPCML_NO_BUFFER)])],
34 buffer_id=ofp.OFP_NO_BUFFER,
35 priority=1000)
36
37 logging.info("Inserting flow sending matching packets to controller")
38 self.controller.message_send(request)
39 do_barrier(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -070040
Admin7e9c91d2015-08-25 15:53:49 -070041 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -070042 logging.info("PacketInExact test, port %d", of_port)
43 self.dataplane.send(of_port, pkt)
44 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
45 verify_packets(self, pkt, [])
46
47class EapolPacketIn(base_tests.SimpleDataPlane):
48
49 """Verify packet-ins are sent for EAPOL packets """
50
51 def runTest(self):
52 logging.info("Running EAPOL Packet In test")
53
54 match = ofp.match()
55 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
56 # Use ethertype 0x888e and multicast destination MAC address
57 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
58
59 testPacketIn(self, match, pkt)
60
61class ARPPacketIn(base_tests.SimpleDataPlane):
62
63 """Verify packet-ins are sent for ARP packets """
64
65 def runTest(self):
66 logging.info("Running ARP Packet In test")
67
68 match = ofp.match()
69 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
70
71 # Use ethertype 0x0806
72 pkt = simple_eth_packet(eth_type=0x0806)
73
74 testPacketIn(self, match, pkt)
75
Jonathan Hartf2511ca2015-07-07 14:18:19 -070076class DHCPPacketIn(base_tests.SimpleDataPlane):
77
78 """Verify packet-ins are sent for DHCP packets """
79
80 def runTest(self):
81 logging.info("Running DHCP Packet In test")
82
83 pkt = simple_udp_packet(udp_sport=68, udp_dport=67)
Admin02d052c2015-10-10 19:08:26 -070084
Jonathan Hartf2511ca2015-07-07 14:18:19 -070085 match = ofp.match()
86 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
87 match.oxm_list.append(ofp.oxm.ip_proto(17))
88 match.oxm_list.append(ofp.oxm.udp_src(68))
89 match.oxm_list.append(ofp.oxm.udp_dst(67))
90
91 testPacketIn(self, match, pkt)
92
93 # Other UDP packets should not match the rule
94 radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812)
Admin02d052c2015-10-10 19:08:26 -070095
Jonathan Hartf2511ca2015-07-07 14:18:19 -070096 self.dataplane.send(1, str(radiusPkt))
97 verify_no_packet_in(self, radiusPkt, 1)
98
99class IGMPPacketIn(base_tests.SimpleDataPlane):
100
101 """Verify packet-ins are sent for IGMP packets """
102
103 def runTest(self):
104 logging.info("Running IGMP Packet In test")
105
106 match = ofp.match()
107 match.oxm_list.append(ofp.oxm.eth_type(0x800))
108 match.oxm_list.append(ofp.oxm.ip_proto(2))
109
110 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
111 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
112
113 pkt = pkt/("0" * (100 - len(pkt)))
114
115 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700116
117class TestMeter(base_tests.SimpleDataPlane):
118
119 def runTest(self):
120 logging.info("Running Meter tests")
121 dropMeterBand = ofp.meter_band.drop(rate = 500)
122 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
123 self.controller.message_send(meter_mod)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700124
Admin7e9c91d2015-08-25 15:53:49 -0700125 time.sleep(1)
126
127 verify_no_errors(self.controller)
128
Jonathan Hartf65e1812015-10-05 15:15:37 -0700129 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700130 match = ofp.match()
131 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin02d052c2015-10-10 19:08:26 -0700132 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
133
134 request = ofp.message.flow_add(
135 table_id=test_param_get("table", 0),
136 cookie=42,
137 match=match,
138 instructions=[
139 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700140 actions=[ofp.action.output(port=olt_port)]
141 ),
Admin02d052c2015-10-10 19:08:26 -0700142 ofp.instruction.meter(meter_id = 1)
143 ],
144 buffer_id=ofp.OFP_NO_BUFFER,
145 priority=1000)
146
147 self.controller.message_send(request)
148 time.sleep(1)
149 verify_no_errors(self.controller)
150
151 match = ofp.match()
152 match.oxm_list.append(ofp.oxm.in_port(olt_port))
153 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700154
155 request = ofp.message.flow_add(
156 table_id=test_param_get("table", 0),
157 cookie=43,
158 match=match,
159 instructions=[
160 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700161 actions=[ofp.action.output(port=onu_port)]
162 ),
163 ofp.instruction.meter(meter_id = 1)
Admin7e9c91d2015-08-25 15:53:49 -0700164 ],
165 buffer_id=ofp.OFP_NO_BUFFER,
166 priority=1000)
167
168 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700169 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700170 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700171 do_barrier(self.controller)
172 time.sleep(5)
Admin7e9c91d2015-08-25 15:53:49 -0700173
Jonathan Hartf65e1812015-10-05 15:15:37 -0700174 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
175 # downstream
Admin02d052c2015-10-10 19:08:26 -0700176 self.dataplane.send(olt_port, str(inPkt))
177 verify_packet(self, inPkt, onu_port)
178 # upstream
179 self.dataplane.send(olt_port, str(inPkt))
180 verify_packet(self, inPkt, onu_port)
181
Jonathan Hartf65e1812015-10-05 15:15:37 -0700182 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700183 meter_mod = ofp.message.meter_mod(xid = 2, command = ofp.OFPMC_DELETE, meter_id = 1)
184 self.controller.message_send(meter_mod)
185 time.sleep(1)
186 delete_all_flows(self.controller)
187 verify_no_errors(self.controller)
188
189
Admin7e9c91d2015-08-25 15:53:49 -0700190class TestDuplicateMeter(base_tests.SimpleDataPlane):
191
192 def runTest(self):
193 logging.info("Running Duplicate Meter Test")
194 dropMeterBand = ofp.meter_band.drop(rate = 500)
195 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
196 self.controller.message_send(meter_mod)
197 self.controller.message_send(meter_mod)
198
199 time.sleep(1)
200
201 try:
202 verify_no_errors(self.controller)
203 except AssertionError as e:
204 if (not e.message is "unexpected error type=12 code=1"):
205 raise AssertionError("Incorrect error type: %s" % e.message)
206
207
208class VlanTest(base_tests.SimpleDataPlane):
209
210 """Verify the switch can push/pop a VLAN tag and forward out a port """
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700211
212 def runTest(self):
213 logging.info("Running push VLAN test")
214
215 vlan_id = 200
216
217 delete_all_flows(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700218
219 #PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700220 match = ofp.match()
221 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700222 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
223 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700224
225 request = ofp.message.flow_add(
226 table_id=test_param_get("table", 0),
227 cookie=42,
228 match=match,
229 instructions=[
230 ofp.instruction.apply_actions(
231 actions=[
232 ofp.action.push_vlan(ethertype=0x8100),
233 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
Admin7e9c91d2015-08-25 15:53:49 -0700234 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700235 ofp.action.output(port=olt_port)])],
236 buffer_id=ofp.OFP_NO_BUFFER,
237 priority=1000)
238
Admin7e9c91d2015-08-25 15:53:49 -0700239 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700240 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700241
Admin02d052c2015-10-10 19:08:26 -0700242 #POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700243 match = ofp.match()
244 match.oxm_list.append(ofp.oxm.in_port(olt_port))
245 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700246
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700247 request = ofp.message.flow_add(
248 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700249 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700250 match=match,
251 instructions=[
252 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700253 actions=[
254 ofp.action.pop_vlan(),
255 ofp.action.output(port=1)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700256 buffer_id=ofp.OFP_NO_BUFFER,
257 priority=1000)
258
Admin7e9c91d2015-08-25 15:53:49 -0700259 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700260 self.controller.message_send(request)
261 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700262 time.sleep(5)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700263
Admin7e9c91d2015-08-25 15:53:49 -0700264 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
265 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
266 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
267
268 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
269 self.dataplane.send(onu_port, str(inPkt))
270 verify_packet(self, outPkt, olt_port)
271
272 # Send untagged packet in the OLT port and expect no packets to come out
273 self.dataplane.send(olt_port, str(inPkt))
274 verify_packets(self, outPkt, [])
275
276 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700277 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700278 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
279
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700280 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
281 self.dataplane.send(olt_port, str(inPkt))
282 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700283
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700284 # Send tagged packet in the ONU port and expect no packets to come out
285 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700286 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700287
288def createAllGroupAdd(group_id, ports=[]):
289 buckets = []
290
291 for portNum in ports:
292 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
293 actions=[ofp.action.output(port=portNum)]))
294
295 group_add = ofp.message.group_add(group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
296
297 return group_add
298
299def createAllGroupMod(group_id, ports=[]):
300 buckets = []
301
302 for portNum in ports:
303 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
304 actions=[ofp.action.output(port=portNum)]))
305
306 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
307
308 return group_mod
309
310
Admin02d052c2015-10-10 19:08:26 -0700311class TestGroupAdd(base_tests.SimpleDataPlane):
312
313 def runTest(self):
314 logging.info("Running Group tests")
315 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700316 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700317
Jonathan Hartf65e1812015-10-05 15:15:37 -0700318 test_group_id = 1
319
320 # output to two ONU
321 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700322
323 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700324 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700325 verify_no_errors(self.controller)
326
327 # Remove the group and then readd it.
Jonathan Hartf65e1812015-10-05 15:15:37 -0700328 group_delete = ofp.message.group_delete(group_id = test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700329 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700330 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700331 verify_no_errors(self.controller)
332
Jonathan Hartf65e1812015-10-05 15:15:37 -0700333 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700334 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700335 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700336 verify_no_errors(self.controller)
337
338
Jonathan Hartf65e1812015-10-05 15:15:37 -0700339 # clean up the test
340 group_delete = ofp.message.group_delete(group_id = test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700341 self.controller.message_send(group_delete)
342
Jonathan Hartf65e1812015-10-05 15:15:37 -0700343 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700344 verify_no_errors(self.controller)
345
346class TestGroupMod(base_tests.SimpleDataPlane):
347
348 def runTest(self):
349 logging.info("Running Group tests")
350 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700351 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700352
Jonathan Hartf65e1812015-10-05 15:15:37 -0700353 test_group_id = 1
354
355 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700356
357 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700358 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700359 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700360
361 # Modifying the group
362 group_mod = createAllGroupMod(test_group_id, [onu_port2])
363
364 self.controller.message_send(group_mod)
365 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700366 verify_no_errors(self.controller)
367
Jonathan Hartf65e1812015-10-05 15:15:37 -0700368 # Add a bucket into the group
369 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
370 self.controller.message_send(group_mod)
371 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700372 verify_no_errors(self.controller)
373
374 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700375 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700376
Jonathan Hartf65e1812015-10-05 15:15:37 -0700377 self.controller.message_send(group_mod)
378 do_barrier(self.controller)
379 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700380 try:
381 verify_no_errors(self.controller)
382 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700383 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700384 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700385 raise AssertionError("Incorrect error type: %s" % e.message)
386 if not errorExperienced:
387 raise AssertionError("An error message is expected, but not shown.")
388
Admin02d052c2015-10-10 19:08:26 -0700389
Jonathan Hartf65e1812015-10-05 15:15:37 -0700390 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700391 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
392 self.controller.message_send(group_delete)
393
Jonathan Hartf65e1812015-10-05 15:15:37 -0700394 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700395 verify_no_errors(self.controller)
396
397class TestDuplicateGroup(base_tests.SimpleDataPlane):
398
399 def runTest(self):
400 logging.info("Running Group tests")
401 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700402 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700403
Jonathan Hartf65e1812015-10-05 15:15:37 -0700404 test_group_id = 1
405 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700406
407 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700408 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700409 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700410
411 # Add the same group id
Admin02d052c2015-10-10 19:08:26 -0700412 duplicate_group_fail = 0
Jonathan Hartf65e1812015-10-05 15:15:37 -0700413
Admin02d052c2015-10-10 19:08:26 -0700414 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700415 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700416 try:
417 verify_no_errors(self.controller)
418 except AssertionError as e:
419 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700420 if (not e.message == "unexpected error type=6 code=0"):
421 raise AssertionError("Incorrect error type: %s" % e.message)
422 if not duplicate_group_fail:
423 raise AssertionError("Adding duplicate groups didn't raise an error.")
424
425 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700426 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
427 self.controller.message_send(group_delete)
428
Jonathan Hartf65e1812015-10-05 15:15:37 -0700429 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700430 verify_no_errors(self.controller)
431
432class TestGroupAndFlow(base_tests.SimpleDataPlane):
433
434 def runTest(self):
435 logging.info("Running Group tests")
436 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700437 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700438
Jonathan Hartf65e1812015-10-05 15:15:37 -0700439 # Create a group
440 test_group_id = 1
441 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700442
443 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700444 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700445 verify_no_errors(self.controller)
446
447 # Create a flow rule matching olt port and vlan id
448 match = ofp.match()
449 match.oxm_list.append(ofp.oxm.in_port(olt_port))
450 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
451
Jonathan Hartf65e1812015-10-05 15:15:37 -0700452 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700453 table_id=test_param_get("table", 0),
454 cookie=43,
455 match=match,
456 instructions=[
457 ofp.instruction.apply_actions(
458 actions=[ ofp.action.group( group_id = test_group_id ) ] ) ],
459 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
460
Jonathan Hartf65e1812015-10-05 15:15:37 -0700461 self.controller.message_send(flow_pointing_to_group)
462 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700463 verify_no_errors(self.controller)
464
Jonathan Hartf65e1812015-10-05 15:15:37 -0700465 # After letting a flow rule point to the group, test we can do group_mod
466 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
467 self.controller.message_send(group_mod)
468 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700469 verify_no_errors(self.controller)
470
471 # Test we can remove flows and then remove group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700472 flow_delete = ofp.message.flow_delete( table_id=test_param_get("table", 0))
473 self.controller.message_send(flow_delete)
474 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700475 verify_no_errors(self.controller)
476
477 group_delete = ofp.message.group_delete(xid = 3, group_id = test_group_id)
478 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700479 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700480 verify_no_errors(self.controller)
481
Jonathan Hartf65e1812015-10-05 15:15:37 -0700482 # Add the group and flow back, test it we can first remove group and then remove the flow.
483 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700484 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700485
486 self.controller.message_send(flow_pointing_to_group)
487 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700488 verify_no_errors(self.controller)
489
490 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
491 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700492
493 self.controller.message_send(flow_delete)
494 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700495 verify_no_errors(self.controller)
496
497
498class TestGroupForwarding(base_tests.SimpleDataPlane):
499
500 def runTest(self):
501 logging.info("Running Group datapath forwarding tests")
502 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700503 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700504
Jonathan Hartf65e1812015-10-05 15:15:37 -0700505 vlan_id = 200
Admin02d052c2015-10-10 19:08:26 -0700506
Jonathan Hartf65e1812015-10-05 15:15:37 -0700507 # Create a group
508 test_group_id = 1
509 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700510
511 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700512 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700513 verify_no_errors(self.controller)
514
515 # Create a flow rule matching olt port and vlan id
516 match = ofp.match()
517 match.oxm_list.append(ofp.oxm.in_port(olt_port))
518 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
519
520 request = ofp.message.flow_add(
521 table_id=test_param_get("table", 0),
522 cookie=43,
523 match=match,
524 instructions=[
525 ofp.instruction.apply_actions(
526 actions=[ ofp.action.group( group_id = test_group_id ) ] ),
Jonathan Hartf65e1812015-10-05 15:15:37 -0700527 ],
Admin02d052c2015-10-10 19:08:26 -0700528 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
529
530 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700531 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700532 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700533 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700534
535 inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True,
536 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
537 outPkt = inPkt
538 self.dataplane.send(olt_port, str(inPkt))
539 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700540
541 # Now put 2 ONU ports in the group and test that the input packet is
542 # duplicated out both ports
543 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
544 self.controller.message_send(group_mod)
545 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700546 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700547
548 self.dataplane.send(olt_port, str(inPkt))
549 verify_packet(self, outPkt, onu_port)
550 verify_packet(self, outPkt, onu_port2)
Admin02d052c2015-10-10 19:08:26 -0700551
552
Jonathan Hartf65e1812015-10-05 15:15:37 -0700553 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700554 request = ofp.message.flow_delete( table_id=test_param_get("table", 0))
555 self.controller.message_send(request)
556 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
557 self.controller.message_send(group_delete)
558
Jonathan Hartf65e1812015-10-05 15:15:37 -0700559 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700560 verify_no_errors(self.controller)
561
562class TransparentVlanTest(base_tests.SimpleDataPlane):
563
564 def runTest(self):
565 logging.info("Running transparent vlan tests")
566
Jonathan Hartf65e1812015-10-05 15:15:37 -0700567 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700568 match = ofp.match()
569 match.oxm_list.append(ofp.oxm.in_port(onu_port))
570 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
571
572 request = ofp.message.flow_add(
573 table_id=test_param_get("table", 0),
574 cookie=42,
575 match=match,
576 instructions=[
577 ofp.instruction.apply_actions(
578 actions=[
579 ofp.action.output(port=olt_port)]),
580 ],
581 buffer_id=ofp.OFP_NO_BUFFER,
582 priority=1000)
583
584 self.controller.message_send(request)
Admin02d052c2015-10-10 19:08:26 -0700585
586 match = ofp.match()
587 match.oxm_list.append(ofp.oxm.in_port(olt_port))
588 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
589
590 request = ofp.message.flow_add(
591 table_id=test_param_get("table", 0),
592 cookie=43,
593 match=match,
594 instructions=[
595 ofp.instruction.apply_actions(
596 actions=[
597 ofp.action.output(port=onu_port)]),
598 ],
599 buffer_id=ofp.OFP_NO_BUFFER,
600 priority=1000)
601
602 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700603 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700604 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700605
Admin02d052c2015-10-10 19:08:26 -0700606
Jonathan Hartf65e1812015-10-05 15:15:37 -0700607 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
608 # downstream
Admin02d052c2015-10-10 19:08:26 -0700609 self.dataplane.send(olt_port, str(inPkt))
610 verify_packet(self, inPkt, onu_port)
611 # upstream
612 self.dataplane.send(onu_port, str(inPkt))
613 verify_packet(self, inPkt, olt_port)
614
615
Jonathan Hartf65e1812015-10-05 15:15:37 -0700616 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700617 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700618 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700619 verify_no_errors(self.controller)
620
621