blob: 67f1044e72aaad120450b88182cc5553b4a87939 [file] [log] [blame]
Jonathan Hartf2511ca2015-07-07 14:18:19 -07001'''
2OFTests for functionality needed from the OLT.
3'''
Zsolt Harasztife525502016-03-02 05:18:52 +00004
Jonathan Hartf2511ca2015-07-07 14:18:19 -07005import logging
alshabibb9d4ee82016-03-01 14:12:42 -08006from __builtin__ import xrange
Jonathan Hartf2511ca2015-07-07 14:18:19 -07007from oftest import config
8import oftest.base_tests as base_tests
9import oftest.packet as scapy
10
11import ofp
Admin7e9c91d2015-08-25 15:53:49 -070012import time
Adminef7a0552015-12-09 15:21:45 -080013import copy
Jonathan Hartf2511ca2015-07-07 14:18:19 -070014
15from oftest.testutils import *
16
Zsolt Harasztife525502016-03-02 05:18:52 +000017from IGMP import IGMPv3
18
19# These parameters can be altered from the command line using the -t or --test-params= options.
20# Example: -t 'onu_port=129;olt_port=288;device_type=pmc'
21#
22onu_port = test_param_get("onu_port", 130)
23onu_port2 = test_param_get("onu_port2", 131)
24olt_port = test_param_get("olt_port", 258)
25device_type = test_param_get("device_type", "normal") # options: "normal", "pmc", "cpqd"
26logging.info("device_type: %s" % device_type)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070027
alshabibb9d4ee82016-03-01 14:12:42 -080028
Adminb17b1662015-10-19 15:50:53 -070029def double_vlan_udp_packet(pktlen=100,
alshabibb9d4ee82016-03-01 14:12:42 -080030 eth_dst='00:01:02:03:04:05',
31 eth_src='00:06:07:08:09:0a',
32 dl_vlan_enable=False,
33 c_vlan_vid=0,
34 c_vlan_pcp=0,
35 s_vlan_vid=0,
36 s_vlan_pcp=0,
37 ip_src='192.168.0.1',
38 ip_dst='192.168.0.2',
39 ip_tos=0,
40 ip_ttl=64,
41 udp_sport=1234,
42 udp_dport=80,
43 ip_ihl=None,
44 ip_options=False,
45 eth_type=0x8100
46 ):
Adminb17b1662015-10-19 15:50:53 -070047 """
48 Return a double vlan tagged dataplane UDP packet
49 Supports a few parameters:
50 @param len Length of packet in bytes w/o CRC
51 @param eth_dst Destination MAC
52 @param eth_src Source MAC
53 @param dl_vlan_enable True if the packet is with vlan, False otherwise
54 @param c_vlan_vid CVLAN ID
55 @param c_vlan_pcp CVLAN priority
56 @param s_vlan_vid SVLAN ID
57 @param s_vlan_pcp SVLAN priority
58 @param ip_src IP source
59 @param ip_dst IP destination
60 @param ip_tos IP ToS
61 @param ip_ttl IP TTL
62 @param udp_dport UDP destination port
63 @param udp_sport UDP source port
64
65 Generates a simple UDP packet. Users shouldn't assume anything about
66 this packet other than that it is a valid ethernet/IP/UDP frame.
67 """
68
69 if MINSIZE > pktlen:
70 pktlen = MINSIZE
71
72 # Note Dot1Q.id is really CFI
73 if (dl_vlan_enable):
alshabibb9d4ee82016-03-01 14:12:42 -080074 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
75 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
76 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
77 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
78 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070079 else:
80 if not ip_options:
Zsolt Harasztife525502016-03-02 05:18:52 +000081 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
82 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
83 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070084
alshabibb9d4ee82016-03-01 14:12:42 -080085 else:
86 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
87 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
88 scapy.UDP(sport=udp_sport, dport=udp_dport)
89
90 pkt = pkt / ("D" * (pktlen - len(pkt)))
Adminb17b1662015-10-19 15:50:53 -070091
92 return pkt
93
Jonathan Hartf2511ca2015-07-07 14:18:19 -070094def testPacketIn(self, match, parsed_pkt):
95 delete_all_flows(self.controller)
96
97 pkt = str(parsed_pkt)
98
Adminef7a0552015-12-09 15:21:45 -080099 for of_port in config["port_map"]:
alshabibb9d4ee82016-03-01 14:12:42 -0800100 m = copy.deepcopy(match)
Adminef7a0552015-12-09 15:21:45 -0800101 m.oxm_list.append(ofp.oxm.in_port(of_port))
102 request = ofp.message.flow_add(
alshabibb9d4ee82016-03-01 14:12:42 -0800103 table_id=test_param_get("table", 0),
104 cookie=42,
105 match=m,
106 instructions=[
107 ofp.instruction.apply_actions(
108 actions=[
109 ofp.action.output(
110 port=ofp.OFPP_CONTROLLER,
111 max_len=ofp.OFPCML_NO_BUFFER)])],
112 buffer_id=ofp.OFP_NO_BUFFER,
113 priority=1000)
Adminef7a0552015-12-09 15:21:45 -0800114 logging.info("Inserting flow sending matching packets to controller")
115 self.controller.message_send(request)
116 do_barrier(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800117
Admin7e9c91d2015-08-25 15:53:49 -0700118 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700119 logging.info("PacketInExact test, port %d", of_port)
120 self.dataplane.send(of_port, pkt)
121 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
122 verify_packets(self, pkt, [])
123
alshabibb9d4ee82016-03-01 14:12:42 -0800124
Admind5212782015-12-09 17:17:57 -0800125def buildIgmp(payload):
Zsolt Harasztife525502016-03-02 05:18:52 +0000126 pkt = pkt = IGMPv3.fixup(scapy.Ether() / scapy.IP() / payload)
alshabibb9d4ee82016-03-01 14:12:42 -0800127 if len(pkt) < 60:
128 pad_len = 60 - len(pkt)
Zsolt Harasztife525502016-03-02 05:18:52 +0000129 pad = scapy.scapy.layers.l2.Padding()
alshabibb9d4ee82016-03-01 14:12:42 -0800130 pad.load = '\x00' * pad_len
131 pkt = pkt / pad
132 return pkt
133
Admind5212782015-12-09 17:17:57 -0800134
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700135class EapolPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700136 """Verify packet-ins are sent for EAPOL packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800137
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700138 def runTest(self):
139 logging.info("Running EAPOL Packet In test")
140
141 match = ofp.match()
142 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
143 # Use ethertype 0x888e and multicast destination MAC address
144 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
alshabibb9d4ee82016-03-01 14:12:42 -0800145
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700146 testPacketIn(self, match, pkt)
147
alshabibb9d4ee82016-03-01 14:12:42 -0800148
Zsolt Harasztife525502016-03-02 05:18:52 +0000149class ARPPacketIn(base_tests.SimpleDataPlane):
150 """Verify packet-ins are sent for ARP packets """
alshabib9929a152016-03-01 21:25:18 -0800151
Zsolt Harasztife525502016-03-02 05:18:52 +0000152 def runTest(self):
153 logging.info("Running ARP Packet In test")
alshabib9929a152016-03-01 21:25:18 -0800154
Zsolt Harasztife525502016-03-02 05:18:52 +0000155 match = ofp.match()
156 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
157
158 # Use ethertype 0x0806
159 pkt = simple_eth_packet(eth_type=0x0806)
160
161 testPacketIn(self, match, pkt)
alshabib9929a152016-03-01 21:25:18 -0800162
163
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700164class IGMPPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700165 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800166
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700167 def runTest(self):
168 logging.info("Running IGMP Packet In test")
169
170 match = ofp.match()
171 match.oxm_list.append(ofp.oxm.eth_type(0x800))
172 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700173
Zsolt Harasztife525502016-03-02 05:18:52 +0000174 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
alshabibb9d4ee82016-03-01 14:12:42 -0800175 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
176
177 pkt = pkt / ("0" * (100 - len(pkt)))
178
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700179 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700180
alshabibb9d4ee82016-03-01 14:12:42 -0800181
Admind5212782015-12-09 17:17:57 -0800182class IGMPQueryPacketOut(base_tests.SimpleDataPlane):
Admind5212782015-12-09 17:17:57 -0800183 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -0800184
Admind5212782015-12-09 17:17:57 -0800185 def runTest(self):
186 logging.info("Running IGMP query packet out")
187
Zsolt Harasztife525502016-03-02 05:18:52 +0000188 igmp = IGMPv3() # by default this is a query
Admind5212782015-12-09 17:17:57 -0800189 pkt = buildIgmp(igmp)
190
Zsolt Harasztife525502016-03-02 05:18:52 +0000191 msg = ofp.message.packet_out(
192 in_port=ofp.OFPP_CONTROLLER,
193 actions=[ofp.action.output(port=onu_port)],
194 buffer_id=ofp.OFP_NO_BUFFER,
195 data=str(pkt))
Admind5212782015-12-09 17:17:57 -0800196
alshabibb9d4ee82016-03-01 14:12:42 -0800197 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -0800198
Zsolt Harasztife525502016-03-02 05:18:52 +0000199 rv = self.controller.message_send(msg)
200 self.assertTrue(rv == 0, "Error sending put message")
Admind5212782015-12-09 17:17:57 -0800201 verify_no_errors(self.controller)
202
203 verify_packet(self, pkt, onu_port)
204
alshabibb9d4ee82016-03-01 14:12:42 -0800205
Admin7e9c91d2015-08-25 15:53:49 -0700206class TestMeter(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000207
Admin7e9c91d2015-08-25 15:53:49 -0700208 def runTest(self):
209 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -0800210 dropMeterBand = ofp.meter_band.drop(rate=640)
211 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700212 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -0800213
Admin7e9c91d2015-08-25 15:53:49 -0700214 time.sleep(1)
215
216 verify_no_errors(self.controller)
217
Jonathan Hartf65e1812015-10-05 15:15:37 -0700218 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700219 match = ofp.match()
220 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800221 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700222
223 request = ofp.message.flow_add(
224 table_id=test_param_get("table", 0),
225 cookie=42,
226 match=match,
227 instructions=[
228 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000229 actions=[ofp.action.output(port=olt_port)]),
230 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800231 ],
Admin02d052c2015-10-10 19:08:26 -0700232 buffer_id=ofp.OFP_NO_BUFFER,
233 priority=1000)
234
235 self.controller.message_send(request)
236 time.sleep(1)
237 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800238
Admin02d052c2015-10-10 19:08:26 -0700239 match = ofp.match()
240 match.oxm_list.append(ofp.oxm.in_port(olt_port))
241 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700242
243 request = ofp.message.flow_add(
244 table_id=test_param_get("table", 0),
245 cookie=43,
246 match=match,
247 instructions=[
248 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000249 actions=[ofp.action.output(port=onu_port)]),
250 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800251 ],
Admin7e9c91d2015-08-25 15:53:49 -0700252 buffer_id=ofp.OFP_NO_BUFFER,
253 priority=1000)
254
255 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700256 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700257 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700258 do_barrier(self.controller)
259 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800260
Jonathan Hartf65e1812015-10-05 15:15:37 -0700261 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
262 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800263 # self.dataplane.send(olt_port, str(inPkt))
264 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700265 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800266 # for i in range(1,400):
267 # self.dataplane.send(onu_port, str(inPkt))
268 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700269
Jonathan Hartf65e1812015-10-05 15:15:37 -0700270 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800271 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700272 self.controller.message_send(meter_mod)
273 time.sleep(1)
274 delete_all_flows(self.controller)
275 verify_no_errors(self.controller)
276
Admin7e9c91d2015-08-25 15:53:49 -0700277
alshabibb9d4ee82016-03-01 14:12:42 -0800278class TestDuplicateMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700279 def runTest(self):
280 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800281 dropMeterBand = ofp.meter_band.drop(rate=500)
282 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700283 self.controller.message_send(meter_mod)
284 self.controller.message_send(meter_mod)
285
286 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800287
Admin7e9c91d2015-08-25 15:53:49 -0700288 try:
289 verify_no_errors(self.controller)
290 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700291 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700292 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800293
294
Admin7e9c91d2015-08-25 15:53:49 -0700295class VlanTest(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700296 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800297
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700298 def runTest(self):
299 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800300
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700301 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800302
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700303 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800304
305 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700306 match = ofp.match()
307 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000308 if device_type == "cpqd":
309 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
310 actions = [
311 ofp.action.push_vlan(ethertype=0x8100),
312 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
313 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
314 ofp.action.output(port=olt_port)
315 ]
316 else: # pmc, normal
317 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
318 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
319 actions = [
320 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
321 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
322 ofp.action.output(port=olt_port)
323 ]
alshabibb9d4ee82016-03-01 14:12:42 -0800324
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700325 request = ofp.message.flow_add(
326 table_id=test_param_get("table", 0),
327 cookie=42,
328 match=match,
Zsolt Harasztife525502016-03-02 05:18:52 +0000329 instructions=[ofp.instruction.apply_actions(actions=actions)],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700330 buffer_id=ofp.OFP_NO_BUFFER,
331 priority=1000)
332
Admin7e9c91d2015-08-25 15:53:49 -0700333 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700334 self.controller.message_send(request)
Zsolt Harasztife525502016-03-02 05:18:52 +0000335 do_barrier(self.controller)
336 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800337
338 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700339 match = ofp.match()
340 match.oxm_list.append(ofp.oxm.in_port(olt_port))
341 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700342
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700343 request = ofp.message.flow_add(
344 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700345 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700346 match=match,
347 instructions=[
348 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700349 actions=[
350 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800351 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700352 buffer_id=ofp.OFP_NO_BUFFER,
353 priority=1000)
354
Admin7e9c91d2015-08-25 15:53:49 -0700355 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700356 self.controller.message_send(request)
357 do_barrier(self.controller)
Zsolt Harasztife525502016-03-02 05:18:52 +0000358 verify_no_errors(self.controller)
359
Admin7e9c91d2015-08-25 15:53:49 -0700360 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800361
Admin7e9c91d2015-08-25 15:53:49 -0700362 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800363 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700364 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800365
Admin7e9c91d2015-08-25 15:53:49 -0700366 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
367 self.dataplane.send(onu_port, str(inPkt))
368 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800369
Admin7e9c91d2015-08-25 15:53:49 -0700370 # Send untagged packet in the OLT port and expect no packets to come out
371 self.dataplane.send(olt_port, str(inPkt))
372 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800373
Admin7e9c91d2015-08-25 15:53:49 -0700374 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700375 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000376 if device_type == 'pmc':
377 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
378 else: # "normal", "cpqd""
379 outPkt = simple_udp_packet(pktlen=100)
Admin7e9c91d2015-08-25 15:53:49 -0700380
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700381 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
382 self.dataplane.send(olt_port, str(inPkt))
383 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700384
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700385 # Send tagged packet in the ONU port and expect no packets to come out
386 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700387 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700388
alshabibb9d4ee82016-03-01 14:12:42 -0800389
Jonathan Hartf65e1812015-10-05 15:15:37 -0700390def createAllGroupAdd(group_id, ports=[]):
391 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800392
Jonathan Hartf65e1812015-10-05 15:15:37 -0700393 for portNum in ports:
394 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Admin99c2a272016-03-01 12:56:39 -0800395 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800396
397 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
398
Jonathan Hartf65e1812015-10-05 15:15:37 -0700399 return group_add
400
alshabibb9d4ee82016-03-01 14:12:42 -0800401
Jonathan Hartf65e1812015-10-05 15:15:37 -0700402def createAllGroupMod(group_id, ports=[]):
403 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800404
Jonathan Hartf65e1812015-10-05 15:15:37 -0700405 for portNum in ports:
406 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
407 actions=[ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800408
409 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
410 buckets=buckets)
411
Jonathan Hartf65e1812015-10-05 15:15:37 -0700412 return group_mod
alshabibb9d4ee82016-03-01 14:12:42 -0800413
Jonathan Hartf65e1812015-10-05 15:15:37 -0700414
Admin02d052c2015-10-10 19:08:26 -0700415class TestGroupAdd(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000416
Admin02d052c2015-10-10 19:08:26 -0700417 def runTest(self):
418 logging.info("Running Group tests")
419 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700420 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700421
alshabibb9d4ee82016-03-01 14:12:42 -0800422 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700423
424 # output to two ONU
425 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700426
427 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700428 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700429 verify_no_errors(self.controller)
430
431 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800432 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700433 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700434 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700435 verify_no_errors(self.controller)
436
Jonathan Hartf65e1812015-10-05 15:15:37 -0700437 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700438 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700439 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700440 verify_no_errors(self.controller)
441
442
Jonathan Hartf65e1812015-10-05 15:15:37 -0700443 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800444 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700445 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800446
Jonathan Hartf65e1812015-10-05 15:15:37 -0700447 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700448 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800449
450
Admin02d052c2015-10-10 19:08:26 -0700451class TestGroupMod(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000452
Admin02d052c2015-10-10 19:08:26 -0700453 def runTest(self):
454 logging.info("Running Group tests")
455 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700456 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700457
alshabibb9d4ee82016-03-01 14:12:42 -0800458 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700459
460 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700461
462 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700463 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700464 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800465
Jonathan Hartf65e1812015-10-05 15:15:37 -0700466 # Modifying the group
467 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800468
Jonathan Hartf65e1812015-10-05 15:15:37 -0700469 self.controller.message_send(group_mod)
470 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700471 verify_no_errors(self.controller)
472
Jonathan Hartf65e1812015-10-05 15:15:37 -0700473 # Add a bucket into the group
474 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
475 self.controller.message_send(group_mod)
476 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700477 verify_no_errors(self.controller)
478
479 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700480 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700481
Jonathan Hartf65e1812015-10-05 15:15:37 -0700482 self.controller.message_send(group_mod)
483 do_barrier(self.controller)
484 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700485 try:
486 verify_no_errors(self.controller)
487 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700488 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700489 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700490 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800491 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700492 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800493
494
Jonathan Hartf65e1812015-10-05 15:15:37 -0700495 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800496 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700497 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800498
Jonathan Hartf65e1812015-10-05 15:15:37 -0700499 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700500 verify_no_errors(self.controller)
501
alshabibb9d4ee82016-03-01 14:12:42 -0800502
Admin02d052c2015-10-10 19:08:26 -0700503class TestDuplicateGroup(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000504
Admin02d052c2015-10-10 19:08:26 -0700505 def runTest(self):
506 logging.info("Running Group tests")
507 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700508 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700509
alshabibb9d4ee82016-03-01 14:12:42 -0800510 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700511 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700512
513 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700514 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700515 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800516
Jonathan Hartf65e1812015-10-05 15:15:37 -0700517 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800518 duplicate_group_fail = 0
519
Admin02d052c2015-10-10 19:08:26 -0700520 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700521 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700522 try:
523 verify_no_errors(self.controller)
524 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800525 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700526 if (not e.message == "unexpected error type=6 code=0"):
527 raise AssertionError("Incorrect error type: %s" % e.message)
528 if not duplicate_group_fail:
529 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800530
Jonathan Hartf65e1812015-10-05 15:15:37 -0700531 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800532 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700533 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800534
Jonathan Hartf65e1812015-10-05 15:15:37 -0700535 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700536 verify_no_errors(self.controller)
537
alshabibb9d4ee82016-03-01 14:12:42 -0800538
Admin02d052c2015-10-10 19:08:26 -0700539class TestGroupAndFlow(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000540
Admin02d052c2015-10-10 19:08:26 -0700541 def runTest(self):
542 logging.info("Running Group tests")
543 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700544 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700545
Jonathan Hartf65e1812015-10-05 15:15:37 -0700546 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800547 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700548 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700549
550 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700551 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700552 verify_no_errors(self.controller)
553
554 # Create a flow rule matching olt port and vlan id
555 match = ofp.match()
556 match.oxm_list.append(ofp.oxm.in_port(olt_port))
557 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
558
Jonathan Hartf65e1812015-10-05 15:15:37 -0700559 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700560 table_id=test_param_get("table", 0),
561 cookie=43,
562 match=match,
563 instructions=[
564 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800565 actions=[ofp.action.group(group_id=test_group_id)])],
566 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700567
Jonathan Hartf65e1812015-10-05 15:15:37 -0700568 self.controller.message_send(flow_pointing_to_group)
569 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700570 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800571
Jonathan Hartf65e1812015-10-05 15:15:37 -0700572 # After letting a flow rule point to the group, test we can do group_mod
573 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
574 self.controller.message_send(group_mod)
575 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700576 verify_no_errors(self.controller)
577
578 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800579 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700580 self.controller.message_send(flow_delete)
581 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700582 verify_no_errors(self.controller)
583
alshabibb9d4ee82016-03-01 14:12:42 -0800584 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700585 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700586 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700587 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800588
Zsolt Harasztife525502016-03-02 05:18:52 +0000589 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800590 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700591 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700592
593 self.controller.message_send(flow_pointing_to_group)
594 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700595 verify_no_errors(self.controller)
596
597 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800598 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700599
600 self.controller.message_send(flow_delete)
601 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700602 verify_no_errors(self.controller)
603
604
605class TestGroupForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000606
Admin02d052c2015-10-10 19:08:26 -0700607 def runTest(self):
608 logging.info("Running Group datapath forwarding tests")
609 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800610 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700611
Admin09b5cc62015-10-11 13:53:59 -0700612 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700613
Jonathan Hartf65e1812015-10-05 15:15:37 -0700614 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800615 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700616 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700617
618 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700619 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700620 verify_no_errors(self.controller)
621
622 # Create a flow rule matching olt port and vlan id
623 match = ofp.match()
624 match.oxm_list.append(ofp.oxm.in_port(olt_port))
625 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
626
627 request = ofp.message.flow_add(
628 table_id=test_param_get("table", 0),
629 cookie=43,
630 match=match,
631 instructions=[
632 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800633 actions=[ofp.action.group(group_id=test_group_id)]),
634 ],
635 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700636
637 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700638 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700639 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700640
641 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800642 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800643
644 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800645 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 -0700646 outPkt = inPkt
647 self.dataplane.send(olt_port, str(inPkt))
648 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700649
Admindcb1bc72015-11-12 18:24:56 -0800650
Zsolt Harasztife525502016-03-02 05:18:52 +0000651 # Now put 2 ONU ports in the group and test that the input packet is
Jonathan Hartf65e1812015-10-05 15:15:37 -0700652 # duplicated out both ports
653 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
654 self.controller.message_send(group_mod)
655 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700656 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800657
Admin09b5cc62015-10-11 13:53:59 -0700658 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800659 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700660
Jonathan Hartf65e1812015-10-05 15:15:37 -0700661 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700662 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800663 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800664 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700665
Jonathan Hartf65e1812015-10-05 15:15:37 -0700666 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800667 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700668 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800669 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700670 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800671
Jonathan Hartf65e1812015-10-05 15:15:37 -0700672 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700673 verify_no_errors(self.controller)
674
Admindcb1bc72015-11-12 18:24:56 -0800675
676class TestGroupModForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000677
Admindcb1bc72015-11-12 18:24:56 -0800678 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800679 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800680 delete_all_flows(self.controller)
681 delete_all_groups(self.controller)
682
683 vlan_id = 201
684
685 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800686 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800687 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
688
689 self.controller.message_send(group_add)
690 do_barrier(self.controller)
691 verify_no_errors(self.controller)
692
693 # Create a flow rule matching olt port and vlan id
694 match = ofp.match()
695 match.oxm_list.append(ofp.oxm.in_port(olt_port))
696 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
697
698 request = ofp.message.flow_add(
699 table_id=test_param_get("table", 0),
700 cookie=43,
701 match=match,
702 instructions=[
703 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800704 actions=[ofp.action.group(group_id=test_group_id)]),
705 ],
706 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800707
708 self.controller.message_send(request)
709 do_barrier(self.controller)
710 verify_no_errors(self.controller)
711
712 # It takes some time for flows to propagate down to the data plane
713 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800714
715 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800716 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
717 outPkt = inPkt
718 self.dataplane.send(olt_port, str(inPkt))
719 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800720 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800721
722 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
723 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
724 self.controller.message_send(group_mod)
725 do_barrier(self.controller)
726 verify_no_errors(self.controller)
727
728 time.sleep(10)
729 self.dataplane.send(olt_port, str(inPkt))
730 verify_no_packet(self, outPkt, onu_port)
731 verify_packet(self, outPkt, onu_port2)
732
Zsolt Harasztife525502016-03-02 05:18:52 +0000733 # Now remove all ports in the group and test that the input packet is no longer forwarded to any port
Admindcb1bc72015-11-12 18:24:56 -0800734 group_mod = createAllGroupMod(test_group_id, ports=[])
735 self.controller.message_send(group_mod)
736 do_barrier(self.controller)
737 verify_no_errors(self.controller)
738 time.sleep(10)
739 self.dataplane.send(olt_port, str(inPkt))
740 verify_packets(self, outPkt, [])
741
742
Admin02d052c2015-10-10 19:08:26 -0700743class TransparentVlanTest(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000744
Admin02d052c2015-10-10 19:08:26 -0700745 def runTest(self):
746 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700747 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700748
Jonathan Hartf65e1812015-10-05 15:15:37 -0700749 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700750 match = ofp.match()
751 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800752 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700753
754 request = ofp.message.flow_add(
755 table_id=test_param_get("table", 0),
756 cookie=42,
757 match=match,
758 instructions=[
759 ofp.instruction.apply_actions(
760 actions=[
761 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800762 ],
Admin02d052c2015-10-10 19:08:26 -0700763 buffer_id=ofp.OFP_NO_BUFFER,
764 priority=1000)
765
766 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800767
Admin02d052c2015-10-10 19:08:26 -0700768 match = ofp.match()
769 match.oxm_list.append(ofp.oxm.in_port(olt_port))
770 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
771
772 request = ofp.message.flow_add(
773 table_id=test_param_get("table", 0),
774 cookie=43,
775 match=match,
776 instructions=[
777 ofp.instruction.apply_actions(
778 actions=[
779 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800780 ],
Admin02d052c2015-10-10 19:08:26 -0700781 buffer_id=ofp.OFP_NO_BUFFER,
782 priority=1000)
783
784 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700785 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700786 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700787
Admin09b5cc62015-10-11 13:53:59 -0700788 # It takes some time for flows to propagate down to the data plane
789 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800790
Jonathan Hartf65e1812015-10-05 15:15:37 -0700791 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000792
Admin02d052c2015-10-10 19:08:26 -0700793 # upstream
794 self.dataplane.send(onu_port, str(inPkt))
795 verify_packet(self, inPkt, olt_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000796
Admin99c2a272016-03-01 12:56:39 -0800797 # downstream
798 self.dataplane.send(olt_port, str(inPkt))
799 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700800
Jonathan Hartf65e1812015-10-05 15:15:37 -0700801 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700802 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700803 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700804 verify_no_errors(self.controller)
805
alshabib28c03c32016-03-01 20:33:51 -0800806class RemoveRuleTest(base_tests.SimpleDataPlane):
807
808 def runTest(self):
809 logging.info("Testing Rule removal")
alshabibe165af22016-03-01 21:42:17 -0800810 delete_all_flows(self.controller)
alshabib9929a152016-03-01 21:25:18 -0800811 processEapolRule(self, onu_port)
alshabibe165af22016-03-01 21:42:17 -0800812
alshabib9929a152016-03-01 21:25:18 -0800813 #wait for the rule to settle
814 time.sleep(3)
815
816 installDoubleTaggingRule(1, 2, self.controller)
alshabibe165af22016-03-01 21:42:17 -0800817
alshabib9929a152016-03-01 21:25:18 -0800818 #wait for the rules to settle
819 time.sleep(3)
820
821 stats = get_flow_stats(self, ofp.match())
822
Admin53395592016-03-01 21:29:21 -0800823 self.assertTrue(len(stats) == 3, \
alshabib9929a152016-03-01 21:25:18 -0800824 "Wrong number of rules reports; reported %s, expected 3\n\n %s" % (len(stats), stats))
825
826 processEapolRule(self, onu_port, install = False)
827 time.sleep(3)
828
829 stats = get_flow_stats(self, ofp.match())
830
Admin53395592016-03-01 21:29:21 -0800831 self.assertTrue(len(stats) == 2, \
alshabib9929a152016-03-01 21:25:18 -0800832 "Wrong number of rules reports; reported %s, expected 2\n\n %s" % (len(stats), stats))
833
834 logging.info(stats)
alshabib28c03c32016-03-01 20:33:51 -0800835
836
837class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane):
838
839 def runTests(self):
840 logging.info("Testing multiple Q-in-Q rules")
841 pass
842
alshabibb9d4ee82016-03-01 14:12:42 -0800843
Adminb17b1662015-10-19 15:50:53 -0700844class DoubleVlanTest(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000845
Adminb17b1662015-10-19 15:50:53 -0700846 def runTest(self):
847 logging.info("Running double vlan tests")
848 delete_all_flows(self.controller)
849
850 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800851 s_vlan_id = 102
Zsolt Harasztife525502016-03-02 05:18:52 +0000852
853 installDoubleTaggingRules(s_vlan_id, c_vlan_id, self.controller)
Adminb17b1662015-10-19 15:50:53 -0700854
Adminb17b1662015-10-19 15:50:53 -0700855 # It takes some time for flows to propagate down to the data plane
856 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800857
Zsolt Harasztife525502016-03-02 05:18:52 +0000858 # Test packet flows
859 testPacketFlow(self, c_vlan_id, s_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700860
861 # clean up the test
862 delete_all_flows(self.controller)
863 do_barrier(self.controller)
864 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800865
866
867class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
868 """Cycle through vlans and test traffic flow"""
869
870 def runTest(self):
871 logging.info("Running cycling vlan test")
872
alshabib2ecca692016-03-01 15:10:38 -0800873 for stag in xrange(2, 4000, 100):
874 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800875 delete_all_flows(self.controller)
876 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800877 installDoubleTaggingRule(stag, ctag, self.controller)
alshabibf1f07dd2016-03-01 15:50:35 -0800878 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800879 testPacketFlow(self, ctag, stag)
alshabibb9d4ee82016-03-01 14:12:42 -0800880
alshabib9929a152016-03-01 21:25:18 -0800881def processEapolRule(test, in_port, install = True):
882 match = ofp.match()
883 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
884 match.oxm_list.append(ofp.oxm.in_port(in_port))
885 if install:
886 request = ofp.message.flow_add(
887 table_id=test_param_get("table", 0),
888 cookie=42,
alshabibd24fca62016-03-01 21:26:35 -0800889 match=match,
alshabib9929a152016-03-01 21:25:18 -0800890 instructions=[
891 ofp.instruction.apply_actions(
892 actions=[
893 ofp.action.output(
894 port=ofp.OFPP_CONTROLLER,
895 max_len=ofp.OFPCML_NO_BUFFER)])],
896 buffer_id=ofp.OFP_NO_BUFFER,
897 priority=1000)
898 else:
899 request = ofp.message.flow_delete(
900 table_id=test_param_get("table", 0),
901 cookie=42,
902 match=m,
903 instructions=[
904 ofp.instruction.apply_actions(
905 actions=[
906 ofp.action.output(
907 port=ofp.OFPP_CONTROLLER,
908 max_len=ofp.OFPCML_NO_BUFFER)])],
909 buffer_id=ofp.OFP_NO_BUFFER,
910 priority=1000)
911 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
912 test.controller.message_send(request)
913 do_barrier(test.controller)
914
alshabib28c03c32016-03-01 20:33:51 -0800915def testPacketFlow(test, c_vlan_id, s_vlan_id):
alshabibb9b39a72016-03-01 15:52:03 -0800916
Zsolt Harasztife525502016-03-02 05:18:52 +0000917 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1)
918 zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
919 untaggedPkt = simple_udp_packet(pktlen=96)
alshabibb9d4ee82016-03-01 14:12:42 -0800920
alshabib28c03c32016-03-01 20:33:51 -0800921 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
922 c_vlan_vid=c_vlan_id,
923 s_vlan_vid=s_vlan_id,
924 c_vlan_pcp=0, s_vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800925
alshabib28c03c32016-03-01 20:33:51 -0800926 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800927
Zsolt Harasztife525502016-03-02 05:18:52 +0000928 # test upstream untagged packet got double tag at OLT
Zsolt Haraszti68883832016-03-02 05:45:11 +0000929 test.dataplane.send(onu_port, str(zeroTaggedPkt))
930 verify_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800931
alshabib28c03c32016-03-01 20:33:51 -0800932 # test downstream doubletagged packet got untagged at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000933 test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
Zsolt Harasztife525502016-03-02 05:18:52 +0000934 if device_type == "pmc":
Zsolt Haraszti68883832016-03-02 05:45:11 +0000935 verify_packet(test, zeroTaggedPkt, onu_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000936 else:
Zsolt Haraszti68883832016-03-02 05:45:11 +0000937 verify_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800938
alshabib28c03c32016-03-01 20:33:51 -0800939 # test upstream doubletagged packet got dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000940 test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
941 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800942
alshabib28c03c32016-03-01 20:33:51 -0800943 # test downstream untagged packet got dropped at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000944 test.dataplane.send(olt_port, str(untaggedPkt))
945 verify_no_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800946
alshabib28c03c32016-03-01 20:33:51 -0800947 # test upstream icorrectly tagged packet; should get dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000948 test.dataplane.send(onu_port, str(incorrectTagPkt))
949 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800950
alshabibb9d4ee82016-03-01 14:12:42 -0800951
Zsolt Harasztife525502016-03-02 05:18:52 +0000952def installDoubleTaggingRules(s_vlan_id, c_vlan_id, controller, cookie=42):
953
alshabib28c03c32016-03-01 20:33:51 -0800954 # upstream flow rule
955 match = ofp.match()
956 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000957 if device_type == "cpqd":
958 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
959 actions = [
960 ofp.action.push_vlan(ethertype=0x8100),
961 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)),
962 ofp.action.set_field(ofp.oxm.vlan_pcp(0))
963 ]
964 else: # "pmc", "normal"
965 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
966 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
967 actions = [
968 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
969 ]
alshabib28c03c32016-03-01 20:33:51 -0800970 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800971
alshabib28c03c32016-03-01 20:33:51 -0800972 # push inner vlan (c-vlan) for upstream
973 request = ofp.message.flow_add(
974 table_id=test_param_get("table", 0),
Admin965eeda2016-03-01 20:56:14 -0800975 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800976 match=match,
977 instructions=[
Zsolt Haraszti68883832016-03-02 05:45:11 +0000978 ofp.instruction.apply_actions(actions=actions),
alshabib28c03c32016-03-01 20:33:51 -0800979 ofp.instruction.goto_table(1)],
980 buffer_id=ofp.OFP_NO_BUFFER,
981 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800982
alshabib28c03c32016-03-01 20:33:51 -0800983 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -0800984 do_barrier(controller)
985 verify_no_errors(controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800986
alshabib28c03c32016-03-01 20:33:51 -0800987 # push outer vlan (s-vlan) for upstream
988 match = ofp.match()
989 match.oxm_list.append(ofp.oxm.in_port(onu_port))
990 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
991 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
992 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800993
alshabib28c03c32016-03-01 20:33:51 -0800994 request = ofp.message.flow_add(
995 table_id=test_param_get("table", 1),
Admin965eeda2016-03-01 20:56:14 -0800996 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800997 match=match,
998 instructions=[
999 ofp.instruction.apply_actions(
1000 actions=[
1001 ofp.action.push_vlan(ethertype=0x8100),
1002 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
1003 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
1004 ofp.action.output(port=olt_port)]),
1005 ],
1006 buffer_id=ofp.OFP_NO_BUFFER,
1007 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -08001008
alshabib28c03c32016-03-01 20:33:51 -08001009 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001010 do_barrier(controller)
1011 verify_no_errors(controller)
alshabib28c03c32016-03-01 20:33:51 -08001012 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -08001013
alshabib28c03c32016-03-01 20:33:51 -08001014 # strip outer vlan (s-vlan) for downstream
1015 match = ofp.match()
1016 match.oxm_list.append(ofp.oxm.in_port(olt_port))
1017 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
1018 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1019 request = ofp.message.flow_add(
1020 table_id=test_param_get("table", 0),
Admin965eeda2016-03-01 20:56:14 -08001021 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -08001022 match=match,
1023 instructions=[
1024 ofp.instruction.apply_actions(
1025 actions=[ofp.action.pop_vlan()]),
1026 ofp.instruction.goto_table(1)],
1027 buffer_id=ofp.OFP_NO_BUFFER,
1028 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -08001029
alshabib28c03c32016-03-01 20:33:51 -08001030 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001031 do_barrier(controller)
1032 verify_no_errors(controller)
alshabibb9d4ee82016-03-01 14:12:42 -08001033
alshabib28c03c32016-03-01 20:33:51 -08001034 # rewrite inner vlan (c-vlan) to default (0) for downstream
1035 match = ofp.match()
1036 match.oxm_list.append(ofp.oxm.in_port(olt_port))
1037 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
1038 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1039 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -08001040
alshabib28c03c32016-03-01 20:33:51 -08001041 request = ofp.message.flow_add(
1042 table_id=test_param_get("table", 1),
Admin965eeda2016-03-01 20:56:14 -08001043 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -08001044 match=match,
1045 instructions=[
1046 ofp.instruction.apply_actions(
1047 actions=[
1048 ofp.action.pop_vlan(),
1049 ofp.action.output(port=onu_port)])
1050 ],
1051 buffer_id=ofp.OFP_NO_BUFFER,
1052 priority=1000)
alshabibf1f07dd2016-03-01 15:50:35 -08001053
alshabib28c03c32016-03-01 20:33:51 -08001054 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001055 do_barrier(controller)
1056 verify_no_errors(controller)