blob: ca6928f29b7e74780b0837f4e3c477a9bad10ab8 [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
Adminb17b1662015-10-19 15:50:53 -070018def double_vlan_udp_packet(pktlen=100,
19 eth_dst='00:01:02:03:04:05',
20 eth_src='00:06:07:08:09:0a',
21 dl_vlan_enable=False,
22 c_vlan_vid=0,
23 c_vlan_pcp=0,
24 s_vlan_vid=0,
25 s_vlan_pcp=0,
26 ip_src='192.168.0.1',
27 ip_dst='192.168.0.2',
28 ip_tos=0,
29 ip_ttl=64,
30 udp_sport=1234,
31 udp_dport=80,
32 ip_ihl=None,
33 ip_options=False
34 ):
35 """
36 Return a double vlan tagged dataplane UDP packet
37 Supports a few parameters:
38 @param len Length of packet in bytes w/o CRC
39 @param eth_dst Destination MAC
40 @param eth_src Source MAC
41 @param dl_vlan_enable True if the packet is with vlan, False otherwise
42 @param c_vlan_vid CVLAN ID
43 @param c_vlan_pcp CVLAN priority
44 @param s_vlan_vid SVLAN ID
45 @param s_vlan_pcp SVLAN priority
46 @param ip_src IP source
47 @param ip_dst IP destination
48 @param ip_tos IP ToS
49 @param ip_ttl IP TTL
50 @param udp_dport UDP destination port
51 @param udp_sport UDP source port
52
53 Generates a simple UDP packet. Users shouldn't assume anything about
54 this packet other than that it is a valid ethernet/IP/UDP frame.
55 """
56
57 if MINSIZE > pktlen:
58 pktlen = MINSIZE
59
60 # Note Dot1Q.id is really CFI
61 if (dl_vlan_enable):
62 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
63 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid)/ \
64 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid)/ \
65 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
66 scapy.UDP(sport=udp_sport, dport=udp_dport)
67 else:
68 if not ip_options:
69 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
70 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
71 scapy.UDP(sport=udp_sport, dport=udp_dport)
72
73 else:
74 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
75 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options)/ \
76 scapy.UDP(sport=udp_sport, dport=udp_dport)
77
78 pkt = pkt/("D" * (pktlen - len(pkt)))
79
80 return pkt
81
82
Jonathan Hartf2511ca2015-07-07 14:18:19 -070083def testPacketIn(self, match, parsed_pkt):
Admin7e9c91d2015-08-25 15:53:49 -070084
Jonathan Hartf2511ca2015-07-07 14:18:19 -070085 delete_all_flows(self.controller)
86
87 pkt = str(parsed_pkt)
88
89 request = ofp.message.flow_add(
90 table_id=test_param_get("table", 0),
91 cookie=42,
92 match=match,
93 instructions=[
94 ofp.instruction.apply_actions(
95 actions=[
96 ofp.action.output(
97 port=ofp.OFPP_CONTROLLER,
98 max_len=ofp.OFPCML_NO_BUFFER)])],
99 buffer_id=ofp.OFP_NO_BUFFER,
100 priority=1000)
101
102 logging.info("Inserting flow sending matching packets to controller")
103 self.controller.message_send(request)
104 do_barrier(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700105
Admin7e9c91d2015-08-25 15:53:49 -0700106 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700107 logging.info("PacketInExact test, port %d", of_port)
108 self.dataplane.send(of_port, pkt)
109 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
110 verify_packets(self, pkt, [])
111
112class EapolPacketIn(base_tests.SimpleDataPlane):
113
114 """Verify packet-ins are sent for EAPOL packets """
115
116 def runTest(self):
117 logging.info("Running EAPOL Packet In test")
118
119 match = ofp.match()
120 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
121 # Use ethertype 0x888e and multicast destination MAC address
122 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
123
124 testPacketIn(self, match, pkt)
125
126class ARPPacketIn(base_tests.SimpleDataPlane):
127
128 """Verify packet-ins are sent for ARP packets """
129
130 def runTest(self):
131 logging.info("Running ARP Packet In test")
132
133 match = ofp.match()
134 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
135
136 # Use ethertype 0x0806
137 pkt = simple_eth_packet(eth_type=0x0806)
138
139 testPacketIn(self, match, pkt)
140
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700141class DHCPPacketIn(base_tests.SimpleDataPlane):
142
143 """Verify packet-ins are sent for DHCP packets """
144
145 def runTest(self):
146 logging.info("Running DHCP Packet In test")
147
148 pkt = simple_udp_packet(udp_sport=68, udp_dport=67)
Admin02d052c2015-10-10 19:08:26 -0700149
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700150 match = ofp.match()
151 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
152 match.oxm_list.append(ofp.oxm.ip_proto(17))
153 match.oxm_list.append(ofp.oxm.udp_src(68))
154 match.oxm_list.append(ofp.oxm.udp_dst(67))
155
156 testPacketIn(self, match, pkt)
157
158 # Other UDP packets should not match the rule
159 radiusPkt = simple_udp_packet(udp_sport=1812, udp_dport=1812)
Admin02d052c2015-10-10 19:08:26 -0700160
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700161 self.dataplane.send(1, str(radiusPkt))
162 verify_no_packet_in(self, radiusPkt, 1)
163
164class IGMPPacketIn(base_tests.SimpleDataPlane):
165
166 """Verify packet-ins are sent for IGMP packets """
167
168 def runTest(self):
169 logging.info("Running IGMP Packet In test")
170
171 match = ofp.match()
172 match.oxm_list.append(ofp.oxm.eth_type(0x800))
173 match.oxm_list.append(ofp.oxm.ip_proto(2))
174
175 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
176 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
177
178 pkt = pkt/("0" * (100 - len(pkt)))
179
180 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700181
182class TestMeter(base_tests.SimpleDataPlane):
183
184 def runTest(self):
185 logging.info("Running Meter tests")
186 dropMeterBand = ofp.meter_band.drop(rate = 500)
187 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
188 self.controller.message_send(meter_mod)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700189
Admin7e9c91d2015-08-25 15:53:49 -0700190 time.sleep(1)
191
192 verify_no_errors(self.controller)
193
Jonathan Hartf65e1812015-10-05 15:15:37 -0700194 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700195 match = ofp.match()
196 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin02d052c2015-10-10 19:08:26 -0700197 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
198
199 request = ofp.message.flow_add(
200 table_id=test_param_get("table", 0),
201 cookie=42,
202 match=match,
203 instructions=[
204 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700205 actions=[ofp.action.output(port=olt_port)]
206 ),
Admin02d052c2015-10-10 19:08:26 -0700207 ofp.instruction.meter(meter_id = 1)
208 ],
209 buffer_id=ofp.OFP_NO_BUFFER,
210 priority=1000)
211
212 self.controller.message_send(request)
213 time.sleep(1)
214 verify_no_errors(self.controller)
215
216 match = ofp.match()
217 match.oxm_list.append(ofp.oxm.in_port(olt_port))
218 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700219
220 request = ofp.message.flow_add(
221 table_id=test_param_get("table", 0),
222 cookie=43,
223 match=match,
224 instructions=[
225 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700226 actions=[ofp.action.output(port=onu_port)]
227 ),
228 ofp.instruction.meter(meter_id = 1)
Admin7e9c91d2015-08-25 15:53:49 -0700229 ],
230 buffer_id=ofp.OFP_NO_BUFFER,
231 priority=1000)
232
233 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700234 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700235 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700236 do_barrier(self.controller)
237 time.sleep(5)
Admin7e9c91d2015-08-25 15:53:49 -0700238
Jonathan Hartf65e1812015-10-05 15:15:37 -0700239 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
240 # downstream
Admin02d052c2015-10-10 19:08:26 -0700241 self.dataplane.send(olt_port, str(inPkt))
242 verify_packet(self, inPkt, onu_port)
243 # upstream
Admin09b5cc62015-10-11 13:53:59 -0700244 self.dataplane.send(onu_port, str(inPkt))
245 verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700246
Jonathan Hartf65e1812015-10-05 15:15:37 -0700247 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700248 meter_mod = ofp.message.meter_mod(xid = 2, command = ofp.OFPMC_DELETE, meter_id = 1)
249 self.controller.message_send(meter_mod)
250 time.sleep(1)
251 delete_all_flows(self.controller)
252 verify_no_errors(self.controller)
253
254
Admin7e9c91d2015-08-25 15:53:49 -0700255class TestDuplicateMeter(base_tests.SimpleDataPlane):
256
257 def runTest(self):
258 logging.info("Running Duplicate Meter Test")
259 dropMeterBand = ofp.meter_band.drop(rate = 500)
260 meter_mod = ofp.message.meter_mod(xid = 1, command = ofp.OFPMC_ADD, meter_id = 1, meters = [ dropMeterBand ])
261 self.controller.message_send(meter_mod)
262 self.controller.message_send(meter_mod)
263
264 time.sleep(1)
265
266 try:
267 verify_no_errors(self.controller)
268 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700269 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700270 raise AssertionError("Incorrect error type: %s" % e.message)
271
272
273class VlanTest(base_tests.SimpleDataPlane):
274
275 """Verify the switch can push/pop a VLAN tag and forward out a port """
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700276
277 def runTest(self):
278 logging.info("Running push VLAN test")
279
280 vlan_id = 200
281
282 delete_all_flows(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700283
284 #PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700285 match = ofp.match()
286 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700287 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
288 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700289
290 request = ofp.message.flow_add(
291 table_id=test_param_get("table", 0),
292 cookie=42,
293 match=match,
294 instructions=[
295 ofp.instruction.apply_actions(
296 actions=[
297 ofp.action.push_vlan(ethertype=0x8100),
298 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
Admin7e9c91d2015-08-25 15:53:49 -0700299 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700300 ofp.action.output(port=olt_port)])],
301 buffer_id=ofp.OFP_NO_BUFFER,
302 priority=1000)
303
Admin7e9c91d2015-08-25 15:53:49 -0700304 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700305 self.controller.message_send(request)
Adminb17b1662015-10-19 15:50:53 -0700306
Admin02d052c2015-10-10 19:08:26 -0700307 #POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700308 match = ofp.match()
309 match.oxm_list.append(ofp.oxm.in_port(olt_port))
310 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700311
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700312 request = ofp.message.flow_add(
313 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700314 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700315 match=match,
316 instructions=[
317 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700318 actions=[
319 ofp.action.pop_vlan(),
Admin09b5cc62015-10-11 13:53:59 -0700320 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700321 buffer_id=ofp.OFP_NO_BUFFER,
322 priority=1000)
323
Admin7e9c91d2015-08-25 15:53:49 -0700324 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700325 self.controller.message_send(request)
326 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700327 time.sleep(5)
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700328
Admin7e9c91d2015-08-25 15:53:49 -0700329 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
330 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
331 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
332
333 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
334 self.dataplane.send(onu_port, str(inPkt))
335 verify_packet(self, outPkt, olt_port)
336
337 # Send untagged packet in the OLT port and expect no packets to come out
338 self.dataplane.send(olt_port, str(inPkt))
339 verify_packets(self, outPkt, [])
Adminb17b1662015-10-19 15:50:53 -0700340
Admin7e9c91d2015-08-25 15:53:49 -0700341 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700342 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700343 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
344
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700345 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
346 self.dataplane.send(olt_port, str(inPkt))
347 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700348
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700349 # Send tagged packet in the ONU port and expect no packets to come out
350 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700351 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700352
353def createAllGroupAdd(group_id, ports=[]):
354 buckets = []
355
356 for portNum in ports:
357 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
358 actions=[ofp.action.output(port=portNum)]))
359
360 group_add = ofp.message.group_add(group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
361
362 return group_add
363
364def createAllGroupMod(group_id, ports=[]):
365 buckets = []
366
367 for portNum in ports:
368 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
369 actions=[ofp.action.output(port=portNum)]))
370
371 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type = ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
372
373 return group_mod
374
375
Admin02d052c2015-10-10 19:08:26 -0700376class TestGroupAdd(base_tests.SimpleDataPlane):
377
378 def runTest(self):
379 logging.info("Running Group tests")
380 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700381 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700382
Jonathan Hartf65e1812015-10-05 15:15:37 -0700383 test_group_id = 1
384
385 # output to two ONU
386 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700387
388 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700389 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700390 verify_no_errors(self.controller)
391
392 # Remove the group and then readd it.
Jonathan Hartf65e1812015-10-05 15:15:37 -0700393 group_delete = ofp.message.group_delete(group_id = test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700394 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700395 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700396 verify_no_errors(self.controller)
397
Jonathan Hartf65e1812015-10-05 15:15:37 -0700398 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700399 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700400 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700401 verify_no_errors(self.controller)
402
403
Jonathan Hartf65e1812015-10-05 15:15:37 -0700404 # clean up the test
405 group_delete = ofp.message.group_delete(group_id = test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700406 self.controller.message_send(group_delete)
407
Jonathan Hartf65e1812015-10-05 15:15:37 -0700408 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700409 verify_no_errors(self.controller)
410
411class TestGroupMod(base_tests.SimpleDataPlane):
412
413 def runTest(self):
414 logging.info("Running Group tests")
415 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700416 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700417
Jonathan Hartf65e1812015-10-05 15:15:37 -0700418 test_group_id = 1
419
420 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700421
422 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700423 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700424 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700425
426 # Modifying the group
427 group_mod = createAllGroupMod(test_group_id, [onu_port2])
428
429 self.controller.message_send(group_mod)
430 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700431 verify_no_errors(self.controller)
432
Jonathan Hartf65e1812015-10-05 15:15:37 -0700433 # Add a bucket into the group
434 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
435 self.controller.message_send(group_mod)
436 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700437 verify_no_errors(self.controller)
438
439 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700440 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700441
Jonathan Hartf65e1812015-10-05 15:15:37 -0700442 self.controller.message_send(group_mod)
443 do_barrier(self.controller)
444 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700445 try:
446 verify_no_errors(self.controller)
447 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700448 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700449 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700450 raise AssertionError("Incorrect error type: %s" % e.message)
451 if not errorExperienced:
452 raise AssertionError("An error message is expected, but not shown.")
453
Admin02d052c2015-10-10 19:08:26 -0700454
Jonathan Hartf65e1812015-10-05 15:15:37 -0700455 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700456 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
457 self.controller.message_send(group_delete)
458
Jonathan Hartf65e1812015-10-05 15:15:37 -0700459 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700460 verify_no_errors(self.controller)
461
462class TestDuplicateGroup(base_tests.SimpleDataPlane):
463
464 def runTest(self):
465 logging.info("Running Group tests")
466 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700467 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700468
Jonathan Hartf65e1812015-10-05 15:15:37 -0700469 test_group_id = 1
470 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700471
472 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700473 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700474 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700475
476 # Add the same group id
Admin02d052c2015-10-10 19:08:26 -0700477 duplicate_group_fail = 0
Jonathan Hartf65e1812015-10-05 15:15:37 -0700478
Admin02d052c2015-10-10 19:08:26 -0700479 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700480 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700481 try:
482 verify_no_errors(self.controller)
483 except AssertionError as e:
484 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700485 if (not e.message == "unexpected error type=6 code=0"):
486 raise AssertionError("Incorrect error type: %s" % e.message)
487 if not duplicate_group_fail:
488 raise AssertionError("Adding duplicate groups didn't raise an error.")
489
490 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700491 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
492 self.controller.message_send(group_delete)
493
Jonathan Hartf65e1812015-10-05 15:15:37 -0700494 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700495 verify_no_errors(self.controller)
496
497class TestGroupAndFlow(base_tests.SimpleDataPlane):
498
499 def runTest(self):
500 logging.info("Running Group tests")
501 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700502 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700503
Jonathan Hartf65e1812015-10-05 15:15:37 -0700504 # Create a group
505 test_group_id = 1
506 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700507
508 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700509 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700510 verify_no_errors(self.controller)
511
512 # Create a flow rule matching olt port and vlan id
513 match = ofp.match()
514 match.oxm_list.append(ofp.oxm.in_port(olt_port))
515 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
516
Jonathan Hartf65e1812015-10-05 15:15:37 -0700517 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700518 table_id=test_param_get("table", 0),
519 cookie=43,
520 match=match,
521 instructions=[
522 ofp.instruction.apply_actions(
523 actions=[ ofp.action.group( group_id = test_group_id ) ] ) ],
524 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
525
Jonathan Hartf65e1812015-10-05 15:15:37 -0700526 self.controller.message_send(flow_pointing_to_group)
527 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700528 verify_no_errors(self.controller)
529
Jonathan Hartf65e1812015-10-05 15:15:37 -0700530 # After letting a flow rule point to the group, test we can do group_mod
531 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
532 self.controller.message_send(group_mod)
533 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700534 verify_no_errors(self.controller)
535
536 # Test we can remove flows and then remove group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700537 flow_delete = ofp.message.flow_delete( table_id=test_param_get("table", 0))
538 self.controller.message_send(flow_delete)
539 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700540 verify_no_errors(self.controller)
541
542 group_delete = ofp.message.group_delete(xid = 3, group_id = test_group_id)
543 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700544 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700545 verify_no_errors(self.controller)
546
Jonathan Hartf65e1812015-10-05 15:15:37 -0700547 # Add the group and flow back, test it we can first remove group and then remove the flow.
548 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700549 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700550
551 self.controller.message_send(flow_pointing_to_group)
552 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700553 verify_no_errors(self.controller)
554
555 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
556 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700557
558 self.controller.message_send(flow_delete)
559 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700560 verify_no_errors(self.controller)
561
562
563class TestGroupForwarding(base_tests.SimpleDataPlane):
564
565 def runTest(self):
566 logging.info("Running Group datapath forwarding tests")
567 delete_all_flows(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700568 #delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700569
Admin09b5cc62015-10-11 13:53:59 -0700570 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700571
Jonathan Hartf65e1812015-10-05 15:15:37 -0700572 # Create a group
573 test_group_id = 1
574 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700575
576 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700577 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700578 verify_no_errors(self.controller)
579
580 # Create a flow rule matching olt port and vlan id
581 match = ofp.match()
582 match.oxm_list.append(ofp.oxm.in_port(olt_port))
583 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
584
585 request = ofp.message.flow_add(
586 table_id=test_param_get("table", 0),
587 cookie=43,
588 match=match,
589 instructions=[
590 ofp.instruction.apply_actions(
591 actions=[ ofp.action.group( group_id = test_group_id ) ] ),
Jonathan Hartf65e1812015-10-05 15:15:37 -0700592 ],
Admin02d052c2015-10-10 19:08:26 -0700593 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
594
595 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700596 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700597 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700598
599 # It takes some time for flows to propagate down to the data plane
600 time.sleep(2)
Admin02d052c2015-10-10 19:08:26 -0700601
602 inPkt = simple_udp_packet(pktlen=104,dl_vlan_enable=True,
603 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
604 outPkt = inPkt
605 self.dataplane.send(olt_port, str(inPkt))
606 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700607
608 # Now put 2 ONU ports in the group and test that the input packet is
609 # duplicated out both ports
610 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
611 self.controller.message_send(group_mod)
612 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700613 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700614
Admin09b5cc62015-10-11 13:53:59 -0700615 # It takes some time for flows to propagate down to the data plane
616 time.sleep(2)
617
Jonathan Hartf65e1812015-10-05 15:15:37 -0700618 self.dataplane.send(olt_port, str(inPkt))
619 verify_packet(self, outPkt, onu_port)
620 verify_packet(self, outPkt, onu_port2)
Admin02d052c2015-10-10 19:08:26 -0700621
622
Jonathan Hartf65e1812015-10-05 15:15:37 -0700623 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700624 request = ofp.message.flow_delete( table_id=test_param_get("table", 0))
625 self.controller.message_send(request)
626 group_delete = ofp.message.group_delete(xid = 2, group_id = test_group_id)
627 self.controller.message_send(group_delete)
628
Jonathan Hartf65e1812015-10-05 15:15:37 -0700629 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700630 verify_no_errors(self.controller)
631
632class TransparentVlanTest(base_tests.SimpleDataPlane):
633
634 def runTest(self):
635 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700636 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700637
Jonathan Hartf65e1812015-10-05 15:15:37 -0700638 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700639 match = ofp.match()
640 match.oxm_list.append(ofp.oxm.in_port(onu_port))
641 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id ))
642
643 request = ofp.message.flow_add(
644 table_id=test_param_get("table", 0),
645 cookie=42,
646 match=match,
647 instructions=[
648 ofp.instruction.apply_actions(
649 actions=[
650 ofp.action.output(port=olt_port)]),
651 ],
652 buffer_id=ofp.OFP_NO_BUFFER,
653 priority=1000)
654
655 self.controller.message_send(request)
Admin02d052c2015-10-10 19:08:26 -0700656
657 match = ofp.match()
658 match.oxm_list.append(ofp.oxm.in_port(olt_port))
659 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
660
661 request = ofp.message.flow_add(
662 table_id=test_param_get("table", 0),
663 cookie=43,
664 match=match,
665 instructions=[
666 ofp.instruction.apply_actions(
667 actions=[
668 ofp.action.output(port=onu_port)]),
669 ],
670 buffer_id=ofp.OFP_NO_BUFFER,
671 priority=1000)
672
673 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700674 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700675 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700676
Admin09b5cc62015-10-11 13:53:59 -0700677 # It takes some time for flows to propagate down to the data plane
678 time.sleep(2)
Admin02d052c2015-10-10 19:08:26 -0700679
Jonathan Hartf65e1812015-10-05 15:15:37 -0700680 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
681 # downstream
Admin02d052c2015-10-10 19:08:26 -0700682 self.dataplane.send(olt_port, str(inPkt))
683 verify_packet(self, inPkt, onu_port)
684 # upstream
685 self.dataplane.send(onu_port, str(inPkt))
686 verify_packet(self, inPkt, olt_port)
687
688
Jonathan Hartf65e1812015-10-05 15:15:37 -0700689 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700690 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700691 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700692 verify_no_errors(self.controller)
693
Adminb17b1662015-10-19 15:50:53 -0700694class DoubleVlanTest(base_tests.SimpleDataPlane):
695
696 def runTest(self):
697 logging.info("Running double vlan tests")
698 delete_all_flows(self.controller)
699
700 c_vlan_id = 100
701 s_vlan_id = 102
702 # upstream flow rule
703 match = ofp.match()
704 match.oxm_list.append(ofp.oxm.in_port(onu_port))
705 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
706 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
707
708 # push inner vlan (c-vlan) for upstream
709 request = ofp.message.flow_add(
710 table_id=test_param_get("table", 0),
711 cookie=42,
712 match=match,
713 instructions=[
714 ofp.instruction.apply_actions(
715 actions=[
716 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)) ] ),
717 ofp.instruction.goto_table(1) ],
718 buffer_id=ofp.OFP_NO_BUFFER,
719 priority=1000)
720
721 self.controller.message_send(request)
722 do_barrier(self.controller)
723 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700724
Adminb17b1662015-10-19 15:50:53 -0700725 # push outer vlan (s-vlan) for upstream
726 match = ofp.match()
727 match.oxm_list.append(ofp.oxm.in_port(onu_port))
728 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
729 match.oxm_list.append(ofp.oxm.vlan_pcp( 0 ))
730
731 request = ofp.message.flow_add(
732 table_id=test_param_get("table", 1),
733 cookie=43,
734 match=match,
735 instructions=[
736 ofp.instruction.apply_actions(
737 actions=[
738 ofp.action.push_vlan(ethertype=0x8100),
739 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
740 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
741 ofp.action.output(port=olt_port)]),
742 ],
743 buffer_id=ofp.OFP_NO_BUFFER,
744 priority=1000)
745
746 self.controller.message_send(request)
747 do_barrier(self.controller)
748 verify_no_errors(self.controller)
749
750 # strip outer vlan (s-vlan) for downstream
751 match = ofp.match()
752 match.oxm_list.append(ofp.oxm.in_port(olt_port))
753 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
754 match.oxm_list.append(ofp.oxm.vlan_pcp( 0 ))
755 request = ofp.message.flow_add(
756 table_id=test_param_get("table", 0),
757 cookie=44,
758 match=match,
759 instructions=[
760 ofp.instruction.apply_actions(
761 actions=[ ofp.action.pop_vlan() ] ),
762 ofp.instruction.goto_table(1) ],
763 buffer_id=ofp.OFP_NO_BUFFER,
764 priority=1000)
765
766 self.controller.message_send(request)
767 do_barrier(self.controller)
768 verify_no_errors(self.controller)
769
770 # strip inner vlan (c-vlan) for downstream
771 match = ofp.match()
772 match.oxm_list.append(ofp.oxm.in_port(olt_port))
773 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
774 match.oxm_list.append(ofp.oxm.vlan_pcp( 0 ))
775
776 request = ofp.message.flow_add(
777 table_id=test_param_get("table", 1),
778 cookie=45,
779 match=match,
780 instructions=[
781 ofp.instruction.apply_actions(
782 actions=[
783 ofp.action.pop_vlan(),
784 ofp.action.output(port=onu_port) ] )
785 ],
786 buffer_id=ofp.OFP_NO_BUFFER,
787 priority=1000)
788
789 self.controller.message_send(request)
790 do_barrier(self.controller)
791 verify_no_errors(self.controller)
792 # It takes some time for flows to propagate down to the data plane
793 time.sleep(10)
794 untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
795 doubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
796 c_vlan_vid=c_vlan_id,
797 s_vlan_vid=s_vlan_id,
798 c_vlan_pcp=0, s_vlan_pcp=0)
799 # test upstream untagged packet got double tag at OLT
800 logging.info(str(doubleTaggedPkt))
801 self.dataplane.send(onu_port, str(untaggedPkt))
802 verify_packet(self, doubleTaggedPkt, olt_port)
803 # test downstream doubletagged packet got untagged at ONU
804 self.dataplane.send(olt_port, str(doubleTaggedPkt))
805 verify_packet(self, untaggedPkt, onu_port)
806 # test upstream doubletagged packet got dropped
807 self.dataplane.send(onu_port, str(doubleTaggedPkt))
808 verify_packets(self, untaggedPkt, [])
809 # test downstream untagged packet got dropped at ONU
810 self.dataplane.send(olt_port, str(untaggedPkt))
811 verify_packet(self, doubleTaggedPkt, [])
812
813
814 # clean up the test
815 delete_all_flows(self.controller)
816 do_barrier(self.controller)
817 verify_no_errors(self.controller)