blob: 2c36d58223e5552fe9bdd0807f7702336a26831f [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
alshabibd6be76e2016-03-01 22:21:00 -08008from oltbase import OltBaseTest
Jonathan Hartf2511ca2015-07-07 14:18:19 -07009import oftest.base_tests as base_tests
10import oftest.packet as scapy
11
alshabibd6be76e2016-03-01 22:21:00 -080012
Jonathan Hartf2511ca2015-07-07 14:18:19 -070013import ofp
Admin7e9c91d2015-08-25 15:53:49 -070014import time
Adminef7a0552015-12-09 15:21:45 -080015import copy
Jonathan Hartf2511ca2015-07-07 14:18:19 -070016
17from oftest.testutils import *
18
Zsolt Harasztiecf89452016-03-01 22:38:13 -080019from IGMP import IGMPv3, IGMPv3gr, IGMP_TYPE_V3_MEMBERSHIP_REPORT, IGMP_V3_GR_TYPE_INCLUDE
20
Zsolt Harasztife525502016-03-02 05:18:52 +000021
22# These parameters can be altered from the command line using the -t or --test-params= options.
23# Example: -t 'onu_port=129;olt_port=288;device_type=pmc'
24#
25onu_port = test_param_get("onu_port", 130)
26onu_port2 = test_param_get("onu_port2", 131)
27olt_port = test_param_get("olt_port", 258)
28device_type = test_param_get("device_type", "normal") # options: "normal", "pmc", "cpqd"
29logging.info("device_type: %s" % device_type)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070030
alshabibb9d4ee82016-03-01 14:12:42 -080031
Adminb17b1662015-10-19 15:50:53 -070032def double_vlan_udp_packet(pktlen=100,
alshabibb9d4ee82016-03-01 14:12:42 -080033 eth_dst='00:01:02:03:04:05',
34 eth_src='00:06:07:08:09:0a',
35 dl_vlan_enable=False,
36 c_vlan_vid=0,
37 c_vlan_pcp=0,
38 s_vlan_vid=0,
39 s_vlan_pcp=0,
40 ip_src='192.168.0.1',
41 ip_dst='192.168.0.2',
42 ip_tos=0,
43 ip_ttl=64,
44 udp_sport=1234,
45 udp_dport=80,
46 ip_ihl=None,
47 ip_options=False,
48 eth_type=0x8100
49 ):
Adminb17b1662015-10-19 15:50:53 -070050 """
51 Return a double vlan tagged dataplane UDP packet
52 Supports a few parameters:
53 @param len Length of packet in bytes w/o CRC
54 @param eth_dst Destination MAC
55 @param eth_src Source MAC
56 @param dl_vlan_enable True if the packet is with vlan, False otherwise
57 @param c_vlan_vid CVLAN ID
58 @param c_vlan_pcp CVLAN priority
59 @param s_vlan_vid SVLAN ID
60 @param s_vlan_pcp SVLAN priority
61 @param ip_src IP source
62 @param ip_dst IP destination
63 @param ip_tos IP ToS
64 @param ip_ttl IP TTL
65 @param udp_dport UDP destination port
66 @param udp_sport UDP source port
67
68 Generates a simple UDP packet. Users shouldn't assume anything about
69 this packet other than that it is a valid ethernet/IP/UDP frame.
70 """
71
72 if MINSIZE > pktlen:
73 pktlen = MINSIZE
74
75 # Note Dot1Q.id is really CFI
76 if (dl_vlan_enable):
alshabibb9d4ee82016-03-01 14:12:42 -080077 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
78 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
79 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
80 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
81 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070082 else:
83 if not ip_options:
Zsolt Harasztife525502016-03-02 05:18:52 +000084 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
85 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
86 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070087
alshabibb9d4ee82016-03-01 14:12:42 -080088 else:
89 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
90 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
91 scapy.UDP(sport=udp_sport, dport=udp_dport)
92
93 pkt = pkt / ("D" * (pktlen - len(pkt)))
Adminb17b1662015-10-19 15:50:53 -070094
95 return pkt
96
Jonathan Hartf2511ca2015-07-07 14:18:19 -070097def testPacketIn(self, match, parsed_pkt):
98 delete_all_flows(self.controller)
99
100 pkt = str(parsed_pkt)
101
Adminef7a0552015-12-09 15:21:45 -0800102 for of_port in config["port_map"]:
alshabibb9d4ee82016-03-01 14:12:42 -0800103 m = copy.deepcopy(match)
Adminef7a0552015-12-09 15:21:45 -0800104 m.oxm_list.append(ofp.oxm.in_port(of_port))
105 request = ofp.message.flow_add(
alshabibb9d4ee82016-03-01 14:12:42 -0800106 table_id=test_param_get("table", 0),
107 cookie=42,
108 match=m,
109 instructions=[
110 ofp.instruction.apply_actions(
111 actions=[
112 ofp.action.output(
113 port=ofp.OFPP_CONTROLLER,
114 max_len=ofp.OFPCML_NO_BUFFER)])],
115 buffer_id=ofp.OFP_NO_BUFFER,
116 priority=1000)
Adminef7a0552015-12-09 15:21:45 -0800117 logging.info("Inserting flow sending matching packets to controller")
118 self.controller.message_send(request)
119 do_barrier(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800120
Admin7e9c91d2015-08-25 15:53:49 -0700121 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700122 logging.info("PacketInExact test, port %d", of_port)
123 self.dataplane.send(of_port, pkt)
124 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
125 verify_packets(self, pkt, [])
126
alshabibb9d4ee82016-03-01 14:12:42 -0800127
Admind5212782015-12-09 17:17:57 -0800128def buildIgmp(payload):
Zsolt Harasztife525502016-03-02 05:18:52 +0000129 pkt = pkt = IGMPv3.fixup(scapy.Ether() / scapy.IP() / payload)
alshabibb9d4ee82016-03-01 14:12:42 -0800130 if len(pkt) < 60:
131 pad_len = 60 - len(pkt)
Zsolt Harasztife525502016-03-02 05:18:52 +0000132 pad = scapy.scapy.layers.l2.Padding()
alshabibb9d4ee82016-03-01 14:12:42 -0800133 pad.load = '\x00' * pad_len
134 pkt = pkt / pad
135 return pkt
136
Admind5212782015-12-09 17:17:57 -0800137
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700138class EapolPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700139 """Verify packet-ins are sent for EAPOL packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800140
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700141 def runTest(self):
142 logging.info("Running EAPOL Packet In test")
143
144 match = ofp.match()
145 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
146 # Use ethertype 0x888e and multicast destination MAC address
147 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
alshabibb9d4ee82016-03-01 14:12:42 -0800148
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700149 testPacketIn(self, match, pkt)
150
alshabibb9d4ee82016-03-01 14:12:42 -0800151
Zsolt Harasztife525502016-03-02 05:18:52 +0000152class ARPPacketIn(base_tests.SimpleDataPlane):
153 """Verify packet-ins are sent for ARP packets """
alshabib9929a152016-03-01 21:25:18 -0800154
Zsolt Harasztife525502016-03-02 05:18:52 +0000155 def runTest(self):
156 logging.info("Running ARP Packet In test")
alshabib9929a152016-03-01 21:25:18 -0800157
Zsolt Harasztife525502016-03-02 05:18:52 +0000158 match = ofp.match()
159 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
160
161 # Use ethertype 0x0806
162 pkt = simple_eth_packet(eth_type=0x0806)
163
164 testPacketIn(self, match, pkt)
alshabib9929a152016-03-01 21:25:18 -0800165
166
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700167class IGMPPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700168 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800169
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700170 def runTest(self):
171 logging.info("Running IGMP Packet In test")
172
173 match = ofp.match()
174 match.oxm_list.append(ofp.oxm.eth_type(0x800))
175 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700176
Zsolt Harasztiecf89452016-03-01 22:38:13 -0800177 igmp = IGMPv3(type=IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, gaddr="224.0.0.1")
178 igmp.grps = [IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr="229.10.20.30")]
179 pkt = IGMPv3.fixup( scapy.Ether(src='00:00:00:00:be:ef') / scapy.IP() / igmp )
alshabibb9d4ee82016-03-01 14:12:42 -0800180 pkt = pkt / ("0" * (100 - len(pkt)))
181
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700182 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700183
alshabibb9d4ee82016-03-01 14:12:42 -0800184
Admind5212782015-12-09 17:17:57 -0800185class IGMPQueryPacketOut(base_tests.SimpleDataPlane):
Admind5212782015-12-09 17:17:57 -0800186 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -0800187
Admind5212782015-12-09 17:17:57 -0800188 def runTest(self):
189 logging.info("Running IGMP query packet out")
190
Zsolt Harasztife525502016-03-02 05:18:52 +0000191 igmp = IGMPv3() # by default this is a query
Admind5212782015-12-09 17:17:57 -0800192 pkt = buildIgmp(igmp)
193
Zsolt Harasztife525502016-03-02 05:18:52 +0000194 msg = ofp.message.packet_out(
195 in_port=ofp.OFPP_CONTROLLER,
196 actions=[ofp.action.output(port=onu_port)],
197 buffer_id=ofp.OFP_NO_BUFFER,
198 data=str(pkt))
Admind5212782015-12-09 17:17:57 -0800199
alshabibb9d4ee82016-03-01 14:12:42 -0800200 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -0800201
Zsolt Harasztife525502016-03-02 05:18:52 +0000202 rv = self.controller.message_send(msg)
203 self.assertTrue(rv == 0, "Error sending put message")
Admind5212782015-12-09 17:17:57 -0800204 verify_no_errors(self.controller)
205
206 verify_packet(self, pkt, onu_port)
207
alshabibb9d4ee82016-03-01 14:12:42 -0800208
Admin7e9c91d2015-08-25 15:53:49 -0700209class TestMeter(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000210
Admin7e9c91d2015-08-25 15:53:49 -0700211 def runTest(self):
212 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -0800213 dropMeterBand = ofp.meter_band.drop(rate=640)
214 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700215 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -0800216
Admin7e9c91d2015-08-25 15:53:49 -0700217 time.sleep(1)
218
219 verify_no_errors(self.controller)
220
Jonathan Hartf65e1812015-10-05 15:15:37 -0700221 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700222 match = ofp.match()
223 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800224 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700225
226 request = ofp.message.flow_add(
227 table_id=test_param_get("table", 0),
228 cookie=42,
229 match=match,
230 instructions=[
231 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000232 actions=[ofp.action.output(port=olt_port)]),
233 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800234 ],
Admin02d052c2015-10-10 19:08:26 -0700235 buffer_id=ofp.OFP_NO_BUFFER,
236 priority=1000)
237
238 self.controller.message_send(request)
239 time.sleep(1)
240 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800241
Admin02d052c2015-10-10 19:08:26 -0700242 match = ofp.match()
243 match.oxm_list.append(ofp.oxm.in_port(olt_port))
244 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700245
246 request = ofp.message.flow_add(
247 table_id=test_param_get("table", 0),
248 cookie=43,
249 match=match,
250 instructions=[
251 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000252 actions=[ofp.action.output(port=onu_port)]),
253 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800254 ],
Admin7e9c91d2015-08-25 15:53:49 -0700255 buffer_id=ofp.OFP_NO_BUFFER,
256 priority=1000)
257
258 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700259 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700260 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700261 do_barrier(self.controller)
262 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800263
Jonathan Hartf65e1812015-10-05 15:15:37 -0700264 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
265 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800266 # self.dataplane.send(olt_port, str(inPkt))
267 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700268 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800269 # for i in range(1,400):
270 # self.dataplane.send(onu_port, str(inPkt))
271 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700272
Jonathan Hartf65e1812015-10-05 15:15:37 -0700273 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800274 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700275 self.controller.message_send(meter_mod)
276 time.sleep(1)
277 delete_all_flows(self.controller)
278 verify_no_errors(self.controller)
279
Admin7e9c91d2015-08-25 15:53:49 -0700280
alshabibb9d4ee82016-03-01 14:12:42 -0800281class TestDuplicateMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700282 def runTest(self):
283 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800284 dropMeterBand = ofp.meter_band.drop(rate=500)
285 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700286 self.controller.message_send(meter_mod)
287 self.controller.message_send(meter_mod)
288
289 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800290
Admin7e9c91d2015-08-25 15:53:49 -0700291 try:
292 verify_no_errors(self.controller)
293 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700294 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700295 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800296
297
Admin7e9c91d2015-08-25 15:53:49 -0700298class VlanTest(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700299 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800300
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700301 def runTest(self):
302 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800303
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700304 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800305
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700306 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800307
308 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700309 match = ofp.match()
310 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000311 if device_type == "cpqd":
312 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
313 actions = [
314 ofp.action.push_vlan(ethertype=0x8100),
315 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
316 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
317 ofp.action.output(port=olt_port)
318 ]
319 else: # pmc, normal
320 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
321 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
322 actions = [
323 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
324 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
325 ofp.action.output(port=olt_port)
326 ]
alshabibb9d4ee82016-03-01 14:12:42 -0800327
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700328 request = ofp.message.flow_add(
329 table_id=test_param_get("table", 0),
330 cookie=42,
331 match=match,
Zsolt Harasztife525502016-03-02 05:18:52 +0000332 instructions=[ofp.instruction.apply_actions(actions=actions)],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700333 buffer_id=ofp.OFP_NO_BUFFER,
334 priority=1000)
335
Admin7e9c91d2015-08-25 15:53:49 -0700336 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700337 self.controller.message_send(request)
Zsolt Harasztife525502016-03-02 05:18:52 +0000338 do_barrier(self.controller)
339 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800340
341 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700342 match = ofp.match()
343 match.oxm_list.append(ofp.oxm.in_port(olt_port))
344 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700345
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700346 request = ofp.message.flow_add(
347 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700348 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700349 match=match,
350 instructions=[
351 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700352 actions=[
353 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800354 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700355 buffer_id=ofp.OFP_NO_BUFFER,
356 priority=1000)
357
Admin7e9c91d2015-08-25 15:53:49 -0700358 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700359 self.controller.message_send(request)
360 do_barrier(self.controller)
Zsolt Harasztife525502016-03-02 05:18:52 +0000361 verify_no_errors(self.controller)
362
Admin7e9c91d2015-08-25 15:53:49 -0700363 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800364
Admin7e9c91d2015-08-25 15:53:49 -0700365 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800366 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700367 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800368
Admin7e9c91d2015-08-25 15:53:49 -0700369 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
370 self.dataplane.send(onu_port, str(inPkt))
371 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800372
Admin7e9c91d2015-08-25 15:53:49 -0700373 # Send untagged packet in the OLT port and expect no packets to come out
374 self.dataplane.send(olt_port, str(inPkt))
375 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800376
Admin7e9c91d2015-08-25 15:53:49 -0700377 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700378 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000379 if device_type == 'pmc':
380 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
381 else: # "normal", "cpqd""
382 outPkt = simple_udp_packet(pktlen=100)
Admin7e9c91d2015-08-25 15:53:49 -0700383
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700384 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
385 self.dataplane.send(olt_port, str(inPkt))
386 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700387
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700388 # Send tagged packet in the ONU port and expect no packets to come out
389 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700390 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700391
alshabibb9d4ee82016-03-01 14:12:42 -0800392
Jonathan Hartf65e1812015-10-05 15:15:37 -0700393def createAllGroupAdd(group_id, ports=[]):
394 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800395
Jonathan Hartf65e1812015-10-05 15:15:37 -0700396 for portNum in ports:
397 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Admin99c2a272016-03-01 12:56:39 -0800398 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800399
400 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
401
Jonathan Hartf65e1812015-10-05 15:15:37 -0700402 return group_add
403
alshabibb9d4ee82016-03-01 14:12:42 -0800404
Jonathan Hartf65e1812015-10-05 15:15:37 -0700405def createAllGroupMod(group_id, ports=[]):
406 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800407
Jonathan Hartf65e1812015-10-05 15:15:37 -0700408 for portNum in ports:
409 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
410 actions=[ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800411
412 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
413 buckets=buckets)
414
Jonathan Hartf65e1812015-10-05 15:15:37 -0700415 return group_mod
alshabibb9d4ee82016-03-01 14:12:42 -0800416
Jonathan Hartf65e1812015-10-05 15:15:37 -0700417
Admin02d052c2015-10-10 19:08:26 -0700418class TestGroupAdd(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000419
Admin02d052c2015-10-10 19:08:26 -0700420 def runTest(self):
421 logging.info("Running Group tests")
422 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700423 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700424
alshabibb9d4ee82016-03-01 14:12:42 -0800425 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700426
427 # output to two ONU
428 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700429
430 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700431 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700432 verify_no_errors(self.controller)
433
434 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800435 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700436 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700437 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700438 verify_no_errors(self.controller)
439
Jonathan Hartf65e1812015-10-05 15:15:37 -0700440 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700441 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700442 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700443 verify_no_errors(self.controller)
444
445
Jonathan Hartf65e1812015-10-05 15:15:37 -0700446 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800447 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700448 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800449
Jonathan Hartf65e1812015-10-05 15:15:37 -0700450 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700451 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800452
453
Admin02d052c2015-10-10 19:08:26 -0700454class TestGroupMod(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000455
Admin02d052c2015-10-10 19:08:26 -0700456 def runTest(self):
457 logging.info("Running Group tests")
458 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700459 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700460
alshabibb9d4ee82016-03-01 14:12:42 -0800461 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700462
463 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700464
465 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700466 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700467 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800468
Jonathan Hartf65e1812015-10-05 15:15:37 -0700469 # Modifying the group
470 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800471
Jonathan Hartf65e1812015-10-05 15:15:37 -0700472 self.controller.message_send(group_mod)
473 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700474 verify_no_errors(self.controller)
475
Jonathan Hartf65e1812015-10-05 15:15:37 -0700476 # Add a bucket into the group
477 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
478 self.controller.message_send(group_mod)
479 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700480 verify_no_errors(self.controller)
481
482 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700483 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700484
Jonathan Hartf65e1812015-10-05 15:15:37 -0700485 self.controller.message_send(group_mod)
486 do_barrier(self.controller)
487 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700488 try:
489 verify_no_errors(self.controller)
490 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700491 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700492 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700493 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800494 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700495 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800496
497
Jonathan Hartf65e1812015-10-05 15:15:37 -0700498 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800499 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700500 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800501
Jonathan Hartf65e1812015-10-05 15:15:37 -0700502 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700503 verify_no_errors(self.controller)
504
alshabibb9d4ee82016-03-01 14:12:42 -0800505
Admin02d052c2015-10-10 19:08:26 -0700506class TestDuplicateGroup(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000507
Admin02d052c2015-10-10 19:08:26 -0700508 def runTest(self):
509 logging.info("Running Group tests")
510 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700511 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700512
alshabibb9d4ee82016-03-01 14:12:42 -0800513 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700514 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700515
516 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700517 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700518 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800519
Jonathan Hartf65e1812015-10-05 15:15:37 -0700520 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800521 duplicate_group_fail = 0
522
Admin02d052c2015-10-10 19:08:26 -0700523 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700524 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700525 try:
526 verify_no_errors(self.controller)
527 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800528 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700529 if (not e.message == "unexpected error type=6 code=0"):
530 raise AssertionError("Incorrect error type: %s" % e.message)
531 if not duplicate_group_fail:
532 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800533
Jonathan Hartf65e1812015-10-05 15:15:37 -0700534 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800535 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700536 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800537
Jonathan Hartf65e1812015-10-05 15:15:37 -0700538 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700539 verify_no_errors(self.controller)
540
alshabibb9d4ee82016-03-01 14:12:42 -0800541
Admin02d052c2015-10-10 19:08:26 -0700542class TestGroupAndFlow(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000543
Admin02d052c2015-10-10 19:08:26 -0700544 def runTest(self):
545 logging.info("Running Group tests")
546 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700547 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700548
Jonathan Hartf65e1812015-10-05 15:15:37 -0700549 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800550 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700551 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700552
553 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700554 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700555 verify_no_errors(self.controller)
556
557 # Create a flow rule matching olt port and vlan id
558 match = ofp.match()
559 match.oxm_list.append(ofp.oxm.in_port(olt_port))
560 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
561
Jonathan Hartf65e1812015-10-05 15:15:37 -0700562 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700563 table_id=test_param_get("table", 0),
564 cookie=43,
565 match=match,
566 instructions=[
567 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800568 actions=[ofp.action.group(group_id=test_group_id)])],
569 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700570
Jonathan Hartf65e1812015-10-05 15:15:37 -0700571 self.controller.message_send(flow_pointing_to_group)
572 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700573 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800574
Jonathan Hartf65e1812015-10-05 15:15:37 -0700575 # After letting a flow rule point to the group, test we can do group_mod
576 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
577 self.controller.message_send(group_mod)
578 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700579 verify_no_errors(self.controller)
580
581 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800582 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700583 self.controller.message_send(flow_delete)
584 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700585 verify_no_errors(self.controller)
586
alshabibb9d4ee82016-03-01 14:12:42 -0800587 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700588 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700589 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700590 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800591
Zsolt Harasztife525502016-03-02 05:18:52 +0000592 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800593 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700594 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700595
596 self.controller.message_send(flow_pointing_to_group)
597 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700598 verify_no_errors(self.controller)
599
600 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800601 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700602
603 self.controller.message_send(flow_delete)
604 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700605 verify_no_errors(self.controller)
606
607
608class TestGroupForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000609
Admin02d052c2015-10-10 19:08:26 -0700610 def runTest(self):
611 logging.info("Running Group datapath forwarding tests")
612 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800613 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700614
Admin09b5cc62015-10-11 13:53:59 -0700615 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700616
Jonathan Hartf65e1812015-10-05 15:15:37 -0700617 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800618 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700619 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700620
621 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700622 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700623 verify_no_errors(self.controller)
624
625 # Create a flow rule matching olt port and vlan id
626 match = ofp.match()
627 match.oxm_list.append(ofp.oxm.in_port(olt_port))
628 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
629
630 request = ofp.message.flow_add(
631 table_id=test_param_get("table", 0),
632 cookie=43,
633 match=match,
634 instructions=[
635 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800636 actions=[ofp.action.group(group_id=test_group_id)]),
637 ],
638 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700639
640 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700641 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700642 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700643
644 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800645 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800646
647 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800648 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 -0700649 outPkt = inPkt
650 self.dataplane.send(olt_port, str(inPkt))
651 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700652
Admindcb1bc72015-11-12 18:24:56 -0800653
Zsolt Harasztife525502016-03-02 05:18:52 +0000654 # Now put 2 ONU ports in the group and test that the input packet is
Jonathan Hartf65e1812015-10-05 15:15:37 -0700655 # duplicated out both ports
656 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
657 self.controller.message_send(group_mod)
658 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700659 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800660
Admin09b5cc62015-10-11 13:53:59 -0700661 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800662 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700663
Jonathan Hartf65e1812015-10-05 15:15:37 -0700664 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700665 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800666 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800667 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700668
Jonathan Hartf65e1812015-10-05 15:15:37 -0700669 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800670 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700671 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800672 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700673 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800674
Jonathan Hartf65e1812015-10-05 15:15:37 -0700675 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700676 verify_no_errors(self.controller)
677
Admindcb1bc72015-11-12 18:24:56 -0800678
679class TestGroupModForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000680
Admindcb1bc72015-11-12 18:24:56 -0800681 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800682 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800683 delete_all_flows(self.controller)
684 delete_all_groups(self.controller)
685
686 vlan_id = 201
687
688 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800689 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800690 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
691
692 self.controller.message_send(group_add)
693 do_barrier(self.controller)
694 verify_no_errors(self.controller)
695
696 # Create a flow rule matching olt port and vlan id
697 match = ofp.match()
698 match.oxm_list.append(ofp.oxm.in_port(olt_port))
699 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
700
701 request = ofp.message.flow_add(
702 table_id=test_param_get("table", 0),
703 cookie=43,
704 match=match,
705 instructions=[
706 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800707 actions=[ofp.action.group(group_id=test_group_id)]),
708 ],
709 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800710
711 self.controller.message_send(request)
712 do_barrier(self.controller)
713 verify_no_errors(self.controller)
714
715 # It takes some time for flows to propagate down to the data plane
716 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800717
718 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800719 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
720 outPkt = inPkt
721 self.dataplane.send(olt_port, str(inPkt))
722 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800723 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800724
725 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
726 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
727 self.controller.message_send(group_mod)
728 do_barrier(self.controller)
729 verify_no_errors(self.controller)
730
731 time.sleep(10)
732 self.dataplane.send(olt_port, str(inPkt))
733 verify_no_packet(self, outPkt, onu_port)
734 verify_packet(self, outPkt, onu_port2)
735
Zsolt Harasztife525502016-03-02 05:18:52 +0000736 # 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 -0800737 group_mod = createAllGroupMod(test_group_id, ports=[])
738 self.controller.message_send(group_mod)
739 do_barrier(self.controller)
740 verify_no_errors(self.controller)
741 time.sleep(10)
742 self.dataplane.send(olt_port, str(inPkt))
743 verify_packets(self, outPkt, [])
744
745
Admin02d052c2015-10-10 19:08:26 -0700746class TransparentVlanTest(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000747
Admin02d052c2015-10-10 19:08:26 -0700748 def runTest(self):
749 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700750 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700751
Jonathan Hartf65e1812015-10-05 15:15:37 -0700752 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700753 match = ofp.match()
754 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800755 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700756
757 request = ofp.message.flow_add(
758 table_id=test_param_get("table", 0),
759 cookie=42,
760 match=match,
761 instructions=[
762 ofp.instruction.apply_actions(
763 actions=[
764 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800765 ],
Admin02d052c2015-10-10 19:08:26 -0700766 buffer_id=ofp.OFP_NO_BUFFER,
767 priority=1000)
768
769 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800770
Admin02d052c2015-10-10 19:08:26 -0700771 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 | vlan_id))
774
775 request = ofp.message.flow_add(
776 table_id=test_param_get("table", 0),
777 cookie=43,
778 match=match,
779 instructions=[
780 ofp.instruction.apply_actions(
781 actions=[
782 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800783 ],
Admin02d052c2015-10-10 19:08:26 -0700784 buffer_id=ofp.OFP_NO_BUFFER,
785 priority=1000)
786
787 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700788 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700789 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700790
Admin09b5cc62015-10-11 13:53:59 -0700791 # It takes some time for flows to propagate down to the data plane
792 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800793
Jonathan Hartf65e1812015-10-05 15:15:37 -0700794 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000795
Admin02d052c2015-10-10 19:08:26 -0700796 # upstream
797 self.dataplane.send(onu_port, str(inPkt))
798 verify_packet(self, inPkt, olt_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000799
Admin99c2a272016-03-01 12:56:39 -0800800 # downstream
801 self.dataplane.send(olt_port, str(inPkt))
802 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700803
Jonathan Hartf65e1812015-10-05 15:15:37 -0700804 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700805 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700806 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700807 verify_no_errors(self.controller)
808
alshabib28c03c32016-03-01 20:33:51 -0800809class RemoveRuleTest(base_tests.SimpleDataPlane):
810
811 def runTest(self):
812 logging.info("Testing Rule removal")
alshabibe165af22016-03-01 21:42:17 -0800813 delete_all_flows(self.controller)
alshabib9929a152016-03-01 21:25:18 -0800814 processEapolRule(self, onu_port)
alshabibe165af22016-03-01 21:42:17 -0800815
alshabib9929a152016-03-01 21:25:18 -0800816 #wait for the rule to settle
817 time.sleep(3)
818
alshabibdde38ea2016-03-01 21:49:44 -0800819 installDoubleTaggingRules(1, 2, self.controller)
alshabibe165af22016-03-01 21:42:17 -0800820
alshabib9929a152016-03-01 21:25:18 -0800821 #wait for the rules to settle
822 time.sleep(3)
823
824 stats = get_flow_stats(self, ofp.match())
825
Admin53e10b62016-03-01 21:52:18 -0800826 self.assertTrue(len(stats) == 5, \
827 "Wrong number of rules reports; reported %s, expected 5\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800828
829 processEapolRule(self, onu_port, install = False)
830 time.sleep(3)
831
832 stats = get_flow_stats(self, ofp.match())
833
Admin53e10b62016-03-01 21:52:18 -0800834 self.assertTrue(len(stats) == 4, \
835 "Wrong number of rules reports; reported %s, expected 4\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800836
alshabibd6be76e2016-03-01 22:21:00 -0800837 eapol = ofp.oxm.eth_type(0x888e)
838 found = False
839 for fe in stats:
840 if eapol in fe.match.oxm_list:
841 found = True
842
843 self.assertFalse(found, "Removed incorrect flow rule")
alshabib28c03c32016-03-01 20:33:51 -0800844
845
846class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane):
847
848 def runTests(self):
849 logging.info("Testing multiple Q-in-Q rules")
850 pass
851
alshabibb9d4ee82016-03-01 14:12:42 -0800852
alshabibd6be76e2016-03-01 22:21:00 -0800853class DoubleVlanTest(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000854
Adminb17b1662015-10-19 15:50:53 -0700855 def runTest(self):
856 logging.info("Running double vlan tests")
857 delete_all_flows(self.controller)
858
859 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800860 s_vlan_id = 102
Zsolt Harasztife525502016-03-02 05:18:52 +0000861
alshabibd6be76e2016-03-01 22:21:00 -0800862 self.installDoubleTaggingRules(s_vlan_id, c_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700863
Adminb17b1662015-10-19 15:50:53 -0700864 # It takes some time for flows to propagate down to the data plane
865 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800866
Zsolt Harasztife525502016-03-02 05:18:52 +0000867 # Test packet flows
868 testPacketFlow(self, c_vlan_id, s_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700869
870 # clean up the test
871 delete_all_flows(self.controller)
872 do_barrier(self.controller)
873 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800874
875
876class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
877 """Cycle through vlans and test traffic flow"""
878
879 def runTest(self):
880 logging.info("Running cycling vlan test")
881
alshabib2ecca692016-03-01 15:10:38 -0800882 for stag in xrange(2, 4000, 100):
883 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800884 delete_all_flows(self.controller)
885 time.sleep(5)
alshabibdde38ea2016-03-01 21:49:44 -0800886 installDoubleTaggingRules(stag, ctag, self.controller)
alshabibf1f07dd2016-03-01 15:50:35 -0800887 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800888 testPacketFlow(self, ctag, stag)
alshabibb9d4ee82016-03-01 14:12:42 -0800889
alshabib9929a152016-03-01 21:25:18 -0800890def processEapolRule(test, in_port, install = True):
891 match = ofp.match()
892 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
893 match.oxm_list.append(ofp.oxm.in_port(in_port))
894 if install:
895 request = ofp.message.flow_add(
896 table_id=test_param_get("table", 0),
897 cookie=42,
alshabibd24fca62016-03-01 21:26:35 -0800898 match=match,
alshabib9929a152016-03-01 21:25:18 -0800899 instructions=[
900 ofp.instruction.apply_actions(
901 actions=[
902 ofp.action.output(
903 port=ofp.OFPP_CONTROLLER,
904 max_len=ofp.OFPCML_NO_BUFFER)])],
905 buffer_id=ofp.OFP_NO_BUFFER,
906 priority=1000)
907 else:
908 request = ofp.message.flow_delete(
909 table_id=test_param_get("table", 0),
910 cookie=42,
Admin53e10b62016-03-01 21:52:18 -0800911 match=match,
alshabib9929a152016-03-01 21:25:18 -0800912 instructions=[
913 ofp.instruction.apply_actions(
914 actions=[
915 ofp.action.output(
916 port=ofp.OFPP_CONTROLLER,
917 max_len=ofp.OFPCML_NO_BUFFER)])],
918 buffer_id=ofp.OFP_NO_BUFFER,
919 priority=1000)
920 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
921 test.controller.message_send(request)
922 do_barrier(test.controller)
923
alshabib28c03c32016-03-01 20:33:51 -0800924def testPacketFlow(test, c_vlan_id, s_vlan_id):
alshabibb9b39a72016-03-01 15:52:03 -0800925
Zsolt Harasztife525502016-03-02 05:18:52 +0000926 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1)
927 zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
928 untaggedPkt = simple_udp_packet(pktlen=96)
alshabibb9d4ee82016-03-01 14:12:42 -0800929
alshabib28c03c32016-03-01 20:33:51 -0800930 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
931 c_vlan_vid=c_vlan_id,
932 s_vlan_vid=s_vlan_id,
933 c_vlan_pcp=0, s_vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800934
alshabib28c03c32016-03-01 20:33:51 -0800935 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800936
Zsolt Harasztife525502016-03-02 05:18:52 +0000937 # test upstream untagged packet got double tag at OLT
Zsolt Haraszti68883832016-03-02 05:45:11 +0000938 test.dataplane.send(onu_port, str(zeroTaggedPkt))
939 verify_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800940
alshabib28c03c32016-03-01 20:33:51 -0800941 # test downstream doubletagged packet got untagged at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000942 test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
Zsolt Harasztife525502016-03-02 05:18:52 +0000943 if device_type == "pmc":
Zsolt Haraszti68883832016-03-02 05:45:11 +0000944 verify_packet(test, zeroTaggedPkt, onu_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000945 else:
Zsolt Haraszti68883832016-03-02 05:45:11 +0000946 verify_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800947
alshabib28c03c32016-03-01 20:33:51 -0800948 # test upstream doubletagged packet got dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000949 test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
950 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800951
alshabib28c03c32016-03-01 20:33:51 -0800952 # test downstream untagged packet got dropped at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000953 test.dataplane.send(olt_port, str(untaggedPkt))
954 verify_no_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800955
alshabib28c03c32016-03-01 20:33:51 -0800956 # test upstream icorrectly tagged packet; should get dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000957 test.dataplane.send(onu_port, str(incorrectTagPkt))
958 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800959
alshabibb9d4ee82016-03-01 14:12:42 -0800960