blob: 664365a5f94ae1fd6dded777535bd080349e2a22 [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
Adminef7a0552015-12-09 15:21:45 -080011import copy
Jonathan Hartf2511ca2015-07-07 14:18:19 -070012
13from oftest.testutils import *
14
Admindcb1bc72015-11-12 18:24:56 -080015onu_port = test_param_get("onu_port", 130)
16onu_port2 = test_param_get("onu_port2", 131)
17olt_port = test_param_get("olt_port", 258)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070018
Adminb17b1662015-10-19 15:50:53 -070019def double_vlan_udp_packet(pktlen=100,
20 eth_dst='00:01:02:03:04:05',
21 eth_src='00:06:07:08:09:0a',
22 dl_vlan_enable=False,
23 c_vlan_vid=0,
24 c_vlan_pcp=0,
25 s_vlan_vid=0,
26 s_vlan_pcp=0,
27 ip_src='192.168.0.1',
28 ip_dst='192.168.0.2',
29 ip_tos=0,
30 ip_ttl=64,
31 udp_sport=1234,
32 udp_dport=80,
33 ip_ihl=None,
Admindcb1bc72015-11-12 18:24:56 -080034 ip_options=False,
35 eth_type=0x8100
Adminb17b1662015-10-19 15:50:53 -070036 ):
37 """
38 Return a double vlan tagged dataplane UDP packet
39 Supports a few parameters:
40 @param len Length of packet in bytes w/o CRC
41 @param eth_dst Destination MAC
42 @param eth_src Source MAC
43 @param dl_vlan_enable True if the packet is with vlan, False otherwise
44 @param c_vlan_vid CVLAN ID
45 @param c_vlan_pcp CVLAN priority
46 @param s_vlan_vid SVLAN ID
47 @param s_vlan_pcp SVLAN priority
48 @param ip_src IP source
49 @param ip_dst IP destination
50 @param ip_tos IP ToS
51 @param ip_ttl IP TTL
52 @param udp_dport UDP destination port
53 @param udp_sport UDP source port
54
55 Generates a simple UDP packet. Users shouldn't assume anything about
56 this packet other than that it is a valid ethernet/IP/UDP frame.
57 """
58
59 if MINSIZE > pktlen:
60 pktlen = MINSIZE
61
62 # Note Dot1Q.id is really CFI
63 if (dl_vlan_enable):
Admindcb1bc72015-11-12 18:24:56 -080064 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type)/ \
Adminb17b1662015-10-19 15:50:53 -070065 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid)/ \
66 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid)/ \
67 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
68 scapy.UDP(sport=udp_sport, dport=udp_dport)
69 else:
70 if not ip_options:
71 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
72 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
73 scapy.UDP(sport=udp_sport, dport=udp_dport)
74
75 else:
76 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
77 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options)/ \
78 scapy.UDP(sport=udp_sport, dport=udp_dport)
79
80 pkt = pkt/("D" * (pktlen - len(pkt)))
81
82 return pkt
83
84
Jonathan Hartf2511ca2015-07-07 14:18:19 -070085def testPacketIn(self, match, parsed_pkt):
Admin7e9c91d2015-08-25 15:53:49 -070086
Jonathan Hartf2511ca2015-07-07 14:18:19 -070087 delete_all_flows(self.controller)
88
89 pkt = str(parsed_pkt)
90
Adminef7a0552015-12-09 15:21:45 -080091 for of_port in config["port_map"]:
92 m = copy.deepcopy(match)
93 m.oxm_list.append(ofp.oxm.in_port(of_port))
94 request = ofp.message.flow_add(
Jonathan Hartf2511ca2015-07-07 14:18:19 -070095 table_id=test_param_get("table", 0),
96 cookie=42,
Adminef7a0552015-12-09 15:21:45 -080097 match=m,
Jonathan Hartf2511ca2015-07-07 14:18:19 -070098 instructions=[
99 ofp.instruction.apply_actions(
100 actions=[
101 ofp.action.output(
102 port=ofp.OFPP_CONTROLLER,
103 max_len=ofp.OFPCML_NO_BUFFER)])],
104 buffer_id=ofp.OFP_NO_BUFFER,
105 priority=1000)
Adminef7a0552015-12-09 15:21:45 -0800106 logging.info("Inserting flow sending matching packets to controller")
107 self.controller.message_send(request)
108 do_barrier(self.controller)
109
Admin7e9c91d2015-08-25 15:53:49 -0700110 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700111 logging.info("PacketInExact test, port %d", of_port)
112 self.dataplane.send(of_port, pkt)
113 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
114 verify_packets(self, pkt, [])
115
116class EapolPacketIn(base_tests.SimpleDataPlane):
117
118 """Verify packet-ins are sent for EAPOL packets """
119
120 def runTest(self):
121 logging.info("Running EAPOL Packet In test")
122
123 match = ofp.match()
124 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
125 # Use ethertype 0x888e and multicast destination MAC address
126 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
127
128 testPacketIn(self, match, pkt)
129
130class ARPPacketIn(base_tests.SimpleDataPlane):
131
132 """Verify packet-ins are sent for ARP packets """
133
134 def runTest(self):
135 logging.info("Running ARP Packet In test")
136
137 match = ofp.match()
138 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
139
140 # Use ethertype 0x0806
141 pkt = simple_eth_packet(eth_type=0x0806)
142
143 testPacketIn(self, match, pkt)
144
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700145class IGMPPacketIn(base_tests.SimpleDataPlane):
146
147 """Verify packet-ins are sent for IGMP packets """
148
149 def runTest(self):
150 logging.info("Running IGMP Packet In test")
151
152 match = ofp.match()
153 match.oxm_list.append(ofp.oxm.eth_type(0x800))
154 match.oxm_list.append(ofp.oxm.ip_proto(2))
155
156 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
157 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
158
159 pkt = pkt/("0" * (100 - len(pkt)))
160
161 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700162
163class TestMeter(base_tests.SimpleDataPlane):
164
165 def runTest(self):
166 logging.info("Running Meter tests")
Adminef7a0552015-12-09 15:21:45 -0800167 dropMeterBand = ofp.meter_band.drop(rate = 64)
Admin7e9c91d2015-08-25 15:53:49 -0700168 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
169 self.controller.message_send(meter_mod)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700170
Admin7e9c91d2015-08-25 15:53:49 -0700171 time.sleep(1)
172
173 verify_no_errors(self.controller)
174
Jonathan Hartf65e1812015-10-05 15:15:37 -0700175 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700176 match = ofp.match()
177 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin02d052c2015-10-10 19:08:26 -0700178 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
179
180 request = ofp.message.flow_add(
181 table_id=test_param_get("table", 0),
182 cookie=42,
183 match=match,
184 instructions=[
185 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700186 actions=[ofp.action.output(port=olt_port)]
187 ),
Admin02d052c2015-10-10 19:08:26 -0700188 ofp.instruction.meter(meter_id = 1)
189 ],
190 buffer_id=ofp.OFP_NO_BUFFER,
191 priority=1000)
192
193 self.controller.message_send(request)
194 time.sleep(1)
195 verify_no_errors(self.controller)
196
197 match = ofp.match()
198 match.oxm_list.append(ofp.oxm.in_port(olt_port))
199 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700200
201 request = ofp.message.flow_add(
202 table_id=test_param_get("table", 0),
203 cookie=43,
204 match=match,
205 instructions=[
206 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700207 actions=[ofp.action.output(port=onu_port)]
208 ),
209 ofp.instruction.meter(meter_id = 1)
Admin7e9c91d2015-08-25 15:53:49 -0700210 ],
211 buffer_id=ofp.OFP_NO_BUFFER,
212 priority=1000)
213
214 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700215 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700216 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700217 do_barrier(self.controller)
218 time.sleep(5)
Admin7e9c91d2015-08-25 15:53:49 -0700219
Jonathan Hartf65e1812015-10-05 15:15:37 -0700220 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
221 # downstream
Adminef7a0552015-12-09 15:21:45 -0800222 #self.dataplane.send(olt_port, str(inPkt))
223 #verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700224 # upstream
Adminef7a0552015-12-09 15:21:45 -0800225 for i in range(1,400):
226 self.dataplane.send(onu_port, str(inPkt))
Admin09b5cc62015-10-11 13:53:59 -0700227 verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700228
Jonathan Hartf65e1812015-10-05 15:15:37 -0700229 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700230 meter_mod = ofp.message.meter_mod(xid = 2, command = ofp.OFPMC_DELETE, meter_id = 1)
231 self.controller.message_send(meter_mod)
232 time.sleep(1)
233 delete_all_flows(self.controller)
234 verify_no_errors(self.controller)
235
236
Admin7e9c91d2015-08-25 15:53:49 -0700237class TestDuplicateMeter(base_tests.SimpleDataPlane):
238
239 def runTest(self):
240 logging.info("Running Duplicate Meter Test")
241 dropMeterBand = ofp.meter_band.drop(rate = 500)
242 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
243 self.controller.message_send(meter_mod)
244 self.controller.message_send(meter_mod)
245
246 time.sleep(1)
247
248 try:
249 verify_no_errors(self.controller)
250 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700251 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700252 raise AssertionError("Incorrect error type: %s" % e.message)
253
254
255class VlanTest(base_tests.SimpleDataPlane):
256
257 """Verify the switch can push/pop a VLAN tag and forward out a port """
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700258
259 def runTest(self):
260 logging.info("Running push VLAN test")
261
262 vlan_id = 200
263
264 delete_all_flows(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700265
266 #PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700267 match = ofp.match()
268 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700269 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
270 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700271
272 request = ofp.message.flow_add(
273 table_id=test_param_get("table", 0),
274 cookie=42,
275 match=match,
276 instructions=[
277 ofp.instruction.apply_actions(
278 actions=[
279 ofp.action.push_vlan(ethertype=0x8100),
280 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
Admin7e9c91d2015-08-25 15:53:49 -0700281 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700282 ofp.action.output(port=olt_port)])],
283 buffer_id=ofp.OFP_NO_BUFFER,
284 priority=1000)
285
Admin7e9c91d2015-08-25 15:53:49 -0700286 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700287 self.controller.message_send(request)
Adminb17b1662015-10-19 15:50:53 -0700288
Admin02d052c2015-10-10 19:08:26 -0700289 #POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700290 match = ofp.match()
291 match.oxm_list.append(ofp.oxm.in_port(olt_port))
292 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700293
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700294 request = ofp.message.flow_add(
295 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700296 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700297 match=match,
298 instructions=[
299 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700300 actions=[
301 ofp.action.pop_vlan(),
Admin09b5cc62015-10-11 13:53:59 -0700302 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700303 buffer_id=ofp.OFP_NO_BUFFER,
304 priority=1000)
305
Admin7e9c91d2015-08-25 15:53:49 -0700306 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700307 self.controller.message_send(request)
308 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700309 time.sleep(5)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700310
Admin7e9c91d2015-08-25 15:53:49 -0700311 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
312 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
313 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
314
315 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
316 self.dataplane.send(onu_port, str(inPkt))
317 verify_packet(self, outPkt, olt_port)
318
319 # Send untagged packet in the OLT port and expect no packets to come out
320 self.dataplane.send(olt_port, str(inPkt))
321 verify_packets(self, outPkt, [])
Adminb17b1662015-10-19 15:50:53 -0700322
Admin7e9c91d2015-08-25 15:53:49 -0700323 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700324 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700325 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
326
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700327 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
328 self.dataplane.send(olt_port, str(inPkt))
329 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700330
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700331 # Send tagged packet in the ONU port and expect no packets to come out
332 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700333 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700334
335def createAllGroupAdd(group_id, ports=[]):
336 buckets = []
337
338 for portNum in ports:
339 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
340 actions=[ofp.action.output(port=portNum)]))
341
342 group_add = ofp.message.group_add(group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
343
344 return group_add
345
346def createAllGroupMod(group_id, ports=[]):
347 buckets = []
348
349 for portNum in ports:
350 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
351 actions=[ofp.action.output(port=portNum)]))
352
353 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
354
355 return group_mod
356
357
Admin02d052c2015-10-10 19:08:26 -0700358class TestGroupAdd(base_tests.SimpleDataPlane):
359
360 def runTest(self):
361 logging.info("Running Group tests")
362 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700363 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700364
Jonathan Hartf65e1812015-10-05 15:15:37 -0700365 test_group_id = 1
366
367 # output to two ONU
368 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700369
370 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700371 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700372 verify_no_errors(self.controller)
373
374 # Remove the group and then readd it.
Jonathan Hartf65e1812015-10-05 15:15:37 -0700375 group_delete = ofp.message.group_delete(group_id = test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700376 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700377 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700378 verify_no_errors(self.controller)
379
Jonathan Hartf65e1812015-10-05 15:15:37 -0700380 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700381 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700382 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700383 verify_no_errors(self.controller)
384
385
Jonathan Hartf65e1812015-10-05 15:15:37 -0700386 # clean up the test
387 group_delete = ofp.message.group_delete(group_id = test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700388 self.controller.message_send(group_delete)
389
Jonathan Hartf65e1812015-10-05 15:15:37 -0700390 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700391 verify_no_errors(self.controller)
392
393class TestGroupMod(base_tests.SimpleDataPlane):
394
395 def runTest(self):
396 logging.info("Running Group tests")
397 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700398 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700399
Jonathan Hartf65e1812015-10-05 15:15:37 -0700400 test_group_id = 1
401
402 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700403
404 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700405 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700406 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700407
408 # Modifying the group
409 group_mod = createAllGroupMod(test_group_id, [onu_port2])
410
411 self.controller.message_send(group_mod)
412 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700413 verify_no_errors(self.controller)
414
Jonathan Hartf65e1812015-10-05 15:15:37 -0700415 # Add a bucket into the group
416 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
417 self.controller.message_send(group_mod)
418 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700419 verify_no_errors(self.controller)
420
421 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700422 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700423
Jonathan Hartf65e1812015-10-05 15:15:37 -0700424 self.controller.message_send(group_mod)
425 do_barrier(self.controller)
426 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700427 try:
428 verify_no_errors(self.controller)
429 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700430 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700431 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700432 raise AssertionError("Incorrect error type: %s" % e.message)
433 if not errorExperienced:
434 raise AssertionError("An error message is expected, but not shown.")
435
Admin02d052c2015-10-10 19:08:26 -0700436
Jonathan Hartf65e1812015-10-05 15:15:37 -0700437 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700438 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
439 self.controller.message_send(group_delete)
440
Jonathan Hartf65e1812015-10-05 15:15:37 -0700441 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700442 verify_no_errors(self.controller)
443
444class TestDuplicateGroup(base_tests.SimpleDataPlane):
445
446 def runTest(self):
447 logging.info("Running Group tests")
448 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700449 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700450
Jonathan Hartf65e1812015-10-05 15:15:37 -0700451 test_group_id = 1
452 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700453
454 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700455 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700456 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700457
458 # Add the same group id
Admin02d052c2015-10-10 19:08:26 -0700459 duplicate_group_fail = 0
Jonathan Hartf65e1812015-10-05 15:15:37 -0700460
Admin02d052c2015-10-10 19:08:26 -0700461 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700462 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700463 try:
464 verify_no_errors(self.controller)
465 except AssertionError as e:
466 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700467 if (not e.message == "unexpected error type=6 code=0"):
468 raise AssertionError("Incorrect error type: %s" % e.message)
469 if not duplicate_group_fail:
470 raise AssertionError("Adding duplicate groups didn't raise an error.")
471
472 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700473 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
474 self.controller.message_send(group_delete)
475
Jonathan Hartf65e1812015-10-05 15:15:37 -0700476 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700477 verify_no_errors(self.controller)
478
479class TestGroupAndFlow(base_tests.SimpleDataPlane):
480
481 def runTest(self):
482 logging.info("Running Group tests")
483 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700484 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700485
Jonathan Hartf65e1812015-10-05 15:15:37 -0700486 # Create a group
487 test_group_id = 1
488 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700489
490 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700491 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700492 verify_no_errors(self.controller)
493
494 # Create a flow rule matching olt port and vlan id
495 match = ofp.match()
496 match.oxm_list.append(ofp.oxm.in_port(olt_port))
497 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
498
Jonathan Hartf65e1812015-10-05 15:15:37 -0700499 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700500 table_id=test_param_get("table", 0),
501 cookie=43,
502 match=match,
503 instructions=[
504 ofp.instruction.apply_actions(
505 actions=[ ofp.action.group( group_id = test_group_id ) ] ) ],
506 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
507
Jonathan Hartf65e1812015-10-05 15:15:37 -0700508 self.controller.message_send(flow_pointing_to_group)
509 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700510 verify_no_errors(self.controller)
511
Jonathan Hartf65e1812015-10-05 15:15:37 -0700512 # After letting a flow rule point to the group, test we can do group_mod
513 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
514 self.controller.message_send(group_mod)
515 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700516 verify_no_errors(self.controller)
517
518 # Test we can remove flows and then remove group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700519 flow_delete = ofp.message.flow_delete( table_id=test_param_get("table", 0))
520 self.controller.message_send(flow_delete)
521 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700522 verify_no_errors(self.controller)
523
524 group_delete = ofp.message.group_delete(xid = 3, group_id = test_group_id)
525 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700526 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700527 verify_no_errors(self.controller)
Admindcb1bc72015-11-12 18:24:56 -0800528
Jonathan Hartf65e1812015-10-05 15:15:37 -0700529 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800530 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700531 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700532
533 self.controller.message_send(flow_pointing_to_group)
534 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700535 verify_no_errors(self.controller)
536
537 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800538 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700539
540 self.controller.message_send(flow_delete)
541 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700542 verify_no_errors(self.controller)
543
544
545class TestGroupForwarding(base_tests.SimpleDataPlane):
546
547 def runTest(self):
548 logging.info("Running Group datapath forwarding tests")
549 delete_all_flows(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700550 #delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700551
Admin09b5cc62015-10-11 13:53:59 -0700552 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700553
Jonathan Hartf65e1812015-10-05 15:15:37 -0700554 # Create a group
555 test_group_id = 1
556 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700557
558 self.controller.message_send(group_add)
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
562 # Create a flow rule matching olt port and vlan id
563 match = ofp.match()
564 match.oxm_list.append(ofp.oxm.in_port(olt_port))
565 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
566
567 request = ofp.message.flow_add(
568 table_id=test_param_get("table", 0),
569 cookie=43,
570 match=match,
571 instructions=[
572 ofp.instruction.apply_actions(
573 actions=[ ofp.action.group( group_id = test_group_id ) ] ),
Jonathan Hartf65e1812015-10-05 15:15:37 -0700574 ],
Admin02d052c2015-10-10 19:08:26 -0700575 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
576
577 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700578 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700579 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700580
581 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800582 time.sleep(10)
Admin02d052c2015-10-10 19:08:26 -0700583
584 inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800585 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
Admin02d052c2015-10-10 19:08:26 -0700586 outPkt = inPkt
587 self.dataplane.send(olt_port, str(inPkt))
588 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700589
Admindcb1bc72015-11-12 18:24:56 -0800590
Jonathan Hartf65e1812015-10-05 15:15:37 -0700591 # Now put 2 ONU ports in the group and test that the input packet is
592 # duplicated out both ports
593 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
594 self.controller.message_send(group_mod)
595 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700596 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700597
Admin09b5cc62015-10-11 13:53:59 -0700598 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800599 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700600
Jonathan Hartf65e1812015-10-05 15:15:37 -0700601 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700602 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800603 verify_packet(self, outPkt, onu_port)
604 #verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700605
Jonathan Hartf65e1812015-10-05 15:15:37 -0700606 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700607 request = ofp.message.flow_delete( table_id=test_param_get("table", 0))
608 self.controller.message_send(request)
609 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
610 self.controller.message_send(group_delete)
611
Jonathan Hartf65e1812015-10-05 15:15:37 -0700612 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700613 verify_no_errors(self.controller)
614
Admindcb1bc72015-11-12 18:24:56 -0800615
616class TestGroupModForwarding(base_tests.SimpleDataPlane):
617
618 def runTest(self):
619 logging.info("Running datapath forwarding tests for group mod" )
620 delete_all_flows(self.controller)
621 delete_all_groups(self.controller)
622
623 vlan_id = 201
624
625 # Create a group
626 test_group_id = 1
627 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
628
629 self.controller.message_send(group_add)
630 do_barrier(self.controller)
631 verify_no_errors(self.controller)
632
633 # Create a flow rule matching olt port and vlan id
634 match = ofp.match()
635 match.oxm_list.append(ofp.oxm.in_port(olt_port))
636 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
637
638 request = ofp.message.flow_add(
639 table_id=test_param_get("table", 0),
640 cookie=43,
641 match=match,
642 instructions=[
643 ofp.instruction.apply_actions(
644 actions=[ ofp.action.group( group_id = test_group_id ) ] ),
645 ],
646 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
647
648 self.controller.message_send(request)
649 do_barrier(self.controller)
650 verify_no_errors(self.controller)
651
652 # It takes some time for flows to propagate down to the data plane
653 time.sleep(10)
654
655 inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True,
656 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
657 outPkt = inPkt
658 self.dataplane.send(olt_port, str(inPkt))
659 verify_packet(self, outPkt, onu_port)
660 #verify_packet(self, outPkt, onu_port2)
661
662 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
663 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
664 self.controller.message_send(group_mod)
665 do_barrier(self.controller)
666 verify_no_errors(self.controller)
667
668 time.sleep(10)
669 self.dataplane.send(olt_port, str(inPkt))
670 verify_no_packet(self, outPkt, onu_port)
671 verify_packet(self, outPkt, onu_port2)
672
673 # Now remove all ports in the group and test that the input packet is no longer forwarded to any port
674 group_mod = createAllGroupMod(test_group_id, ports=[])
675 self.controller.message_send(group_mod)
676 do_barrier(self.controller)
677 verify_no_errors(self.controller)
678 time.sleep(10)
679 self.dataplane.send(olt_port, str(inPkt))
680 verify_packets(self, outPkt, [])
681
682
Admin02d052c2015-10-10 19:08:26 -0700683class TransparentVlanTest(base_tests.SimpleDataPlane):
684
685 def runTest(self):
686 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700687 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700688
Jonathan Hartf65e1812015-10-05 15:15:37 -0700689 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700690 match = ofp.match()
691 match.oxm_list.append(ofp.oxm.in_port(onu_port))
692 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
693
694 request = ofp.message.flow_add(
695 table_id=test_param_get("table", 0),
696 cookie=42,
697 match=match,
698 instructions=[
699 ofp.instruction.apply_actions(
700 actions=[
701 ofp.action.output(port=olt_port)]),
702 ],
703 buffer_id=ofp.OFP_NO_BUFFER,
704 priority=1000)
705
706 self.controller.message_send(request)
Admin02d052c2015-10-10 19:08:26 -0700707
708 match = ofp.match()
709 match.oxm_list.append(ofp.oxm.in_port(olt_port))
710 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
711
712 request = ofp.message.flow_add(
713 table_id=test_param_get("table", 0),
714 cookie=43,
715 match=match,
716 instructions=[
717 ofp.instruction.apply_actions(
718 actions=[
719 ofp.action.output(port=onu_port)]),
720 ],
721 buffer_id=ofp.OFP_NO_BUFFER,
722 priority=1000)
723
724 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700725 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700726 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700727
Admin09b5cc62015-10-11 13:53:59 -0700728 # It takes some time for flows to propagate down to the data plane
729 time.sleep(2)
Admin02d052c2015-10-10 19:08:26 -0700730
Jonathan Hartf65e1812015-10-05 15:15:37 -0700731 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
732 # downstream
Admin02d052c2015-10-10 19:08:26 -0700733 self.dataplane.send(olt_port, str(inPkt))
734 verify_packet(self, inPkt, onu_port)
735 # upstream
736 self.dataplane.send(onu_port, str(inPkt))
737 verify_packet(self, inPkt, olt_port)
738
739
Jonathan Hartf65e1812015-10-05 15:15:37 -0700740 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700741 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700742 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700743 verify_no_errors(self.controller)
744
Adminb17b1662015-10-19 15:50:53 -0700745class DoubleVlanTest(base_tests.SimpleDataPlane):
746
747 def runTest(self):
748 logging.info("Running double vlan tests")
749 delete_all_flows(self.controller)
750
751 c_vlan_id = 100
752 s_vlan_id = 102
753 # upstream flow rule
754 match = ofp.match()
755 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admindcb1bc72015-11-12 18:24:56 -0800756 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
Adminb17b1662015-10-19 15:50:53 -0700757 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
758
759 # push inner vlan (c-vlan) for upstream
760 request = ofp.message.flow_add(
761 table_id=test_param_get("table", 0),
762 cookie=42,
763 match=match,
764 instructions=[
765 ofp.instruction.apply_actions(
766 actions=[
767 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) ] ),
768 ofp.instruction.goto_table(1) ],
769 buffer_id=ofp.OFP_NO_BUFFER,
770 priority=1000)
771
772 self.controller.message_send(request)
773 do_barrier(self.controller)
774 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700775
Adminb17b1662015-10-19 15:50:53 -0700776 # push outer vlan (s-vlan) for upstream
777 match = ofp.match()
778 match.oxm_list.append(ofp.oxm.in_port(onu_port))
779 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
780 match.oxm_list.append(ofp.oxm.vlan_pcp( 0 ))
781
782 request = ofp.message.flow_add(
783 table_id=test_param_get("table", 1),
784 cookie=43,
785 match=match,
786 instructions=[
787 ofp.instruction.apply_actions(
788 actions=[
Adminef7a0552015-12-09 15:21:45 -0800789 ofp.action.push_vlan(ethertype=0x8100),
Adminb17b1662015-10-19 15:50:53 -0700790 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
791 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
792 ofp.action.output(port=olt_port)]),
793 ],
794 buffer_id=ofp.OFP_NO_BUFFER,
795 priority=1000)
796
797 self.controller.message_send(request)
798 do_barrier(self.controller)
799 verify_no_errors(self.controller)
800
801 # strip outer vlan (s-vlan) for downstream
802 match = ofp.match()
803 match.oxm_list.append(ofp.oxm.in_port(olt_port))
804 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
805 match.oxm_list.append(ofp.oxm.vlan_pcp( 0 ))
806 request = ofp.message.flow_add(
807 table_id=test_param_get("table", 0),
808 cookie=44,
809 match=match,
810 instructions=[
811 ofp.instruction.apply_actions(
812 actions=[ ofp.action.pop_vlan() ] ),
813 ofp.instruction.goto_table(1) ],
814 buffer_id=ofp.OFP_NO_BUFFER,
815 priority=1000)
816
817 self.controller.message_send(request)
818 do_barrier(self.controller)
819 verify_no_errors(self.controller)
820
Admindcb1bc72015-11-12 18:24:56 -0800821 # rewrite inner vlan (c-vlan) to default (0) for downstream
Adminb17b1662015-10-19 15:50:53 -0700822 match = ofp.match()
823 match.oxm_list.append(ofp.oxm.in_port(olt_port))
824 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
825 match.oxm_list.append(ofp.oxm.vlan_pcp( 0 ))
826
827 request = ofp.message.flow_add(
828 table_id=test_param_get("table", 1),
829 cookie=45,
830 match=match,
831 instructions=[
832 ofp.instruction.apply_actions(
833 actions=[
Admindcb1bc72015-11-12 18:24:56 -0800834 ofp.action.pop_vlan(),
Adminb17b1662015-10-19 15:50:53 -0700835 ofp.action.output(port=onu_port) ] )
836 ],
837 buffer_id=ofp.OFP_NO_BUFFER,
838 priority=1000)
839
840 self.controller.message_send(request)
841 do_barrier(self.controller)
842 verify_no_errors(self.controller)
843 # It takes some time for flows to propagate down to the data plane
844 time.sleep(10)
Admindcb1bc72015-11-12 18:24:56 -0800845 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=0)
Adminb17b1662015-10-19 15:50:53 -0700846 untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
Admindcb1bc72015-11-12 18:24:56 -0800847
848
849 '''
850 FIXME: hack because OLT does _not_ tag packets correctly
851 it ignores the eth_type in the push_vlan action
852 and always slaps on 0x8100 even though the
853 down stream flow must be 0x88a8.
854 '''
Adminb17b1662015-10-19 15:50:53 -0700855 doubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
856 c_vlan_vid=c_vlan_id,
857 s_vlan_vid=s_vlan_id,
Admindcb1bc72015-11-12 18:24:56 -0800858 c_vlan_pcp=0, s_vlan_pcp=0, eth_type=0x88a8)
859
860 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
861 c_vlan_vid=c_vlan_id,
862 s_vlan_vid=s_vlan_id,
Adminb17b1662015-10-19 15:50:53 -0700863 c_vlan_pcp=0, s_vlan_pcp=0)
Admindcb1bc72015-11-12 18:24:56 -0800864
Adminb17b1662015-10-19 15:50:53 -0700865 # test upstream untagged packet got double tag at OLT
866 logging.info(str(doubleTaggedPkt))
867 self.dataplane.send(onu_port, str(untaggedPkt))
Admindcb1bc72015-11-12 18:24:56 -0800868 verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
869
870 # test downstream doubletagged packet got untagged at ONU
Adminb17b1662015-10-19 15:50:53 -0700871 self.dataplane.send(olt_port, str(doubleTaggedPkt))
872 verify_packet(self, untaggedPkt, onu_port)
Adminb17b1662015-10-19 15:50:53 -0700873
Admindcb1bc72015-11-12 18:24:56 -0800874 # test upstream doubletagged packet got dropped
875 self.dataplane.send(onu_port, str(doubleTaggedPkt))
876 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
877
878 # test downstream untagged packet got dropped at ONU
879 self.dataplane.send(olt_port, str(untaggedPkt))
880 verify_no_packet(self, untaggedPkt, onu_port)
881
882 # test upstream icorrectly tagged packet; should get dropped
883 self.dataplane.send(onu_port, str(incorrectTagPkt))
884 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
885
886 time.sleep(2)
Adminb17b1662015-10-19 15:50:53 -0700887
888 # clean up the test
889 delete_all_flows(self.controller)
890 do_barrier(self.controller)
891 verify_no_errors(self.controller)