blob: 4f78f2a71ffef8199ced7ddcac37d0ba7edd6020 [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 Harasztiecf89452016-03-01 22:38:13 -080017from IGMP import IGMPv3, IGMPv3gr, IGMP_TYPE_V3_MEMBERSHIP_REPORT, IGMP_V3_GR_TYPE_INCLUDE
18
Zsolt Harasztife525502016-03-02 05:18:52 +000019
20# These parameters can be altered from the command line using the -t or --test-params= options.
21# Example: -t 'onu_port=129;olt_port=288;device_type=pmc'
22#
23onu_port = test_param_get("onu_port", 130)
24onu_port2 = test_param_get("onu_port2", 131)
25olt_port = test_param_get("olt_port", 258)
26device_type = test_param_get("device_type", "normal") # options: "normal", "pmc", "cpqd"
27logging.info("device_type: %s" % device_type)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070028
alshabibb9d4ee82016-03-01 14:12:42 -080029
Adminb17b1662015-10-19 15:50:53 -070030def double_vlan_udp_packet(pktlen=100,
alshabibb9d4ee82016-03-01 14:12:42 -080031 eth_dst='00:01:02:03:04:05',
32 eth_src='00:06:07:08:09:0a',
33 dl_vlan_enable=False,
34 c_vlan_vid=0,
35 c_vlan_pcp=0,
36 s_vlan_vid=0,
37 s_vlan_pcp=0,
38 ip_src='192.168.0.1',
39 ip_dst='192.168.0.2',
40 ip_tos=0,
41 ip_ttl=64,
42 udp_sport=1234,
43 udp_dport=80,
44 ip_ihl=None,
45 ip_options=False,
46 eth_type=0x8100
47 ):
Adminb17b1662015-10-19 15:50:53 -070048 """
49 Return a double vlan tagged dataplane UDP packet
50 Supports a few parameters:
51 @param len Length of packet in bytes w/o CRC
52 @param eth_dst Destination MAC
53 @param eth_src Source MAC
54 @param dl_vlan_enable True if the packet is with vlan, False otherwise
55 @param c_vlan_vid CVLAN ID
56 @param c_vlan_pcp CVLAN priority
57 @param s_vlan_vid SVLAN ID
58 @param s_vlan_pcp SVLAN priority
59 @param ip_src IP source
60 @param ip_dst IP destination
61 @param ip_tos IP ToS
62 @param ip_ttl IP TTL
63 @param udp_dport UDP destination port
64 @param udp_sport UDP source port
65
66 Generates a simple UDP packet. Users shouldn't assume anything about
67 this packet other than that it is a valid ethernet/IP/UDP frame.
68 """
69
70 if MINSIZE > pktlen:
71 pktlen = MINSIZE
72
73 # Note Dot1Q.id is really CFI
74 if (dl_vlan_enable):
alshabibb9d4ee82016-03-01 14:12:42 -080075 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
76 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
77 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
78 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
79 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070080 else:
81 if not ip_options:
Zsolt Harasztife525502016-03-02 05:18:52 +000082 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
83 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
84 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070085
alshabibb9d4ee82016-03-01 14:12:42 -080086 else:
87 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
88 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
89 scapy.UDP(sport=udp_sport, dport=udp_dport)
90
91 pkt = pkt / ("D" * (pktlen - len(pkt)))
Adminb17b1662015-10-19 15:50:53 -070092
93 return pkt
94
Jonathan Hartf2511ca2015-07-07 14:18:19 -070095def testPacketIn(self, match, parsed_pkt):
96 delete_all_flows(self.controller)
97
98 pkt = str(parsed_pkt)
99
Adminef7a0552015-12-09 15:21:45 -0800100 for of_port in config["port_map"]:
alshabibb9d4ee82016-03-01 14:12:42 -0800101 m = copy.deepcopy(match)
Adminef7a0552015-12-09 15:21:45 -0800102 m.oxm_list.append(ofp.oxm.in_port(of_port))
103 request = ofp.message.flow_add(
alshabibb9d4ee82016-03-01 14:12:42 -0800104 table_id=test_param_get("table", 0),
105 cookie=42,
106 match=m,
107 instructions=[
108 ofp.instruction.apply_actions(
109 actions=[
110 ofp.action.output(
111 port=ofp.OFPP_CONTROLLER,
112 max_len=ofp.OFPCML_NO_BUFFER)])],
113 buffer_id=ofp.OFP_NO_BUFFER,
114 priority=1000)
Adminef7a0552015-12-09 15:21:45 -0800115 logging.info("Inserting flow sending matching packets to controller")
116 self.controller.message_send(request)
117 do_barrier(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800118
Admin7e9c91d2015-08-25 15:53:49 -0700119 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700120 logging.info("PacketInExact test, port %d", of_port)
121 self.dataplane.send(of_port, pkt)
122 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
123 verify_packets(self, pkt, [])
124
alshabibb9d4ee82016-03-01 14:12:42 -0800125
Admind5212782015-12-09 17:17:57 -0800126def buildIgmp(payload):
Zsolt Harasztife525502016-03-02 05:18:52 +0000127 pkt = pkt = IGMPv3.fixup(scapy.Ether() / scapy.IP() / payload)
alshabibb9d4ee82016-03-01 14:12:42 -0800128 if len(pkt) < 60:
129 pad_len = 60 - len(pkt)
Zsolt Harasztife525502016-03-02 05:18:52 +0000130 pad = scapy.scapy.layers.l2.Padding()
alshabibb9d4ee82016-03-01 14:12:42 -0800131 pad.load = '\x00' * pad_len
132 pkt = pkt / pad
133 return pkt
134
Admind5212782015-12-09 17:17:57 -0800135
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700136class EapolPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700137 """Verify packet-ins are sent for EAPOL packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800138
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700139 def runTest(self):
140 logging.info("Running EAPOL Packet In test")
141
142 match = ofp.match()
143 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
144 # Use ethertype 0x888e and multicast destination MAC address
145 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
alshabibb9d4ee82016-03-01 14:12:42 -0800146
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700147 testPacketIn(self, match, pkt)
148
alshabibb9d4ee82016-03-01 14:12:42 -0800149
Zsolt Harasztife525502016-03-02 05:18:52 +0000150class ARPPacketIn(base_tests.SimpleDataPlane):
151 """Verify packet-ins are sent for ARP packets """
alshabib9929a152016-03-01 21:25:18 -0800152
Zsolt Harasztife525502016-03-02 05:18:52 +0000153 def runTest(self):
154 logging.info("Running ARP Packet In test")
alshabib9929a152016-03-01 21:25:18 -0800155
Zsolt Harasztife525502016-03-02 05:18:52 +0000156 match = ofp.match()
157 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
158
159 # Use ethertype 0x0806
160 pkt = simple_eth_packet(eth_type=0x0806)
161
162 testPacketIn(self, match, pkt)
alshabib9929a152016-03-01 21:25:18 -0800163
164
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700165class IGMPPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700166 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800167
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700168 def runTest(self):
169 logging.info("Running IGMP Packet In test")
170
171 match = ofp.match()
172 match.oxm_list.append(ofp.oxm.eth_type(0x800))
173 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700174
Zsolt Harasztiecf89452016-03-01 22:38:13 -0800175 igmp = IGMPv3(type=IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30, gaddr="224.0.0.1")
176 igmp.grps = [IGMPv3gr(rtype=IGMP_V3_GR_TYPE_INCLUDE, mcaddr="229.10.20.30")]
177 pkt = IGMPv3.fixup( scapy.Ether(src='00:00:00:00:be:ef') / scapy.IP() / igmp )
alshabibb9d4ee82016-03-01 14:12:42 -0800178 pkt = pkt / ("0" * (100 - len(pkt)))
179
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700180 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700181
alshabibb9d4ee82016-03-01 14:12:42 -0800182
Admind5212782015-12-09 17:17:57 -0800183class IGMPQueryPacketOut(base_tests.SimpleDataPlane):
Admind5212782015-12-09 17:17:57 -0800184 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -0800185
Admind5212782015-12-09 17:17:57 -0800186 def runTest(self):
187 logging.info("Running IGMP query packet out")
188
Zsolt Harasztife525502016-03-02 05:18:52 +0000189 igmp = IGMPv3() # by default this is a query
Admind5212782015-12-09 17:17:57 -0800190 pkt = buildIgmp(igmp)
191
Zsolt Harasztife525502016-03-02 05:18:52 +0000192 msg = ofp.message.packet_out(
193 in_port=ofp.OFPP_CONTROLLER,
194 actions=[ofp.action.output(port=onu_port)],
195 buffer_id=ofp.OFP_NO_BUFFER,
196 data=str(pkt))
Admind5212782015-12-09 17:17:57 -0800197
alshabibb9d4ee82016-03-01 14:12:42 -0800198 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -0800199
Zsolt Harasztife525502016-03-02 05:18:52 +0000200 rv = self.controller.message_send(msg)
201 self.assertTrue(rv == 0, "Error sending put message")
Admind5212782015-12-09 17:17:57 -0800202 verify_no_errors(self.controller)
203
204 verify_packet(self, pkt, onu_port)
205
alshabibb9d4ee82016-03-01 14:12:42 -0800206
Admin7e9c91d2015-08-25 15:53:49 -0700207class TestMeter(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000208
Admin7e9c91d2015-08-25 15:53:49 -0700209 def runTest(self):
210 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -0800211 dropMeterBand = ofp.meter_band.drop(rate=640)
212 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700213 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -0800214
Admin7e9c91d2015-08-25 15:53:49 -0700215 time.sleep(1)
216
217 verify_no_errors(self.controller)
218
Jonathan Hartf65e1812015-10-05 15:15:37 -0700219 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700220 match = ofp.match()
221 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800222 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700223
224 request = ofp.message.flow_add(
225 table_id=test_param_get("table", 0),
226 cookie=42,
227 match=match,
228 instructions=[
229 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000230 actions=[ofp.action.output(port=olt_port)]),
231 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800232 ],
Admin02d052c2015-10-10 19:08:26 -0700233 buffer_id=ofp.OFP_NO_BUFFER,
234 priority=1000)
235
236 self.controller.message_send(request)
237 time.sleep(1)
238 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800239
Admin02d052c2015-10-10 19:08:26 -0700240 match = ofp.match()
241 match.oxm_list.append(ofp.oxm.in_port(olt_port))
242 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700243
244 request = ofp.message.flow_add(
245 table_id=test_param_get("table", 0),
246 cookie=43,
247 match=match,
248 instructions=[
249 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000250 actions=[ofp.action.output(port=onu_port)]),
251 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800252 ],
Admin7e9c91d2015-08-25 15:53:49 -0700253 buffer_id=ofp.OFP_NO_BUFFER,
254 priority=1000)
255
256 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700257 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700258 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700259 do_barrier(self.controller)
260 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800261
Jonathan Hartf65e1812015-10-05 15:15:37 -0700262 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
263 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800264 # self.dataplane.send(olt_port, str(inPkt))
265 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700266 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800267 # for i in range(1,400):
268 # self.dataplane.send(onu_port, str(inPkt))
269 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700270
Jonathan Hartf65e1812015-10-05 15:15:37 -0700271 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800272 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700273 self.controller.message_send(meter_mod)
274 time.sleep(1)
275 delete_all_flows(self.controller)
276 verify_no_errors(self.controller)
277
Admin7e9c91d2015-08-25 15:53:49 -0700278
alshabibb9d4ee82016-03-01 14:12:42 -0800279class TestDuplicateMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700280 def runTest(self):
281 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800282 dropMeterBand = ofp.meter_band.drop(rate=500)
283 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700284 self.controller.message_send(meter_mod)
285 self.controller.message_send(meter_mod)
286
287 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800288
Admin7e9c91d2015-08-25 15:53:49 -0700289 try:
290 verify_no_errors(self.controller)
291 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700292 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700293 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800294
295
Admin7e9c91d2015-08-25 15:53:49 -0700296class VlanTest(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700297 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800298
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700299 def runTest(self):
300 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800301
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700302 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800303
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700304 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800305
306 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700307 match = ofp.match()
308 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000309 if device_type == "cpqd":
310 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
311 actions = [
312 ofp.action.push_vlan(ethertype=0x8100),
313 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
314 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
315 ofp.action.output(port=olt_port)
316 ]
317 else: # pmc, normal
318 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
319 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
320 actions = [
321 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
322 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
323 ofp.action.output(port=olt_port)
324 ]
alshabibb9d4ee82016-03-01 14:12:42 -0800325
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700326 request = ofp.message.flow_add(
327 table_id=test_param_get("table", 0),
328 cookie=42,
329 match=match,
Zsolt Harasztife525502016-03-02 05:18:52 +0000330 instructions=[ofp.instruction.apply_actions(actions=actions)],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700331 buffer_id=ofp.OFP_NO_BUFFER,
332 priority=1000)
333
Admin7e9c91d2015-08-25 15:53:49 -0700334 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700335 self.controller.message_send(request)
Zsolt Harasztife525502016-03-02 05:18:52 +0000336 do_barrier(self.controller)
337 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800338
339 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700340 match = ofp.match()
341 match.oxm_list.append(ofp.oxm.in_port(olt_port))
342 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700343
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700344 request = ofp.message.flow_add(
345 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700346 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700347 match=match,
348 instructions=[
349 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700350 actions=[
351 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800352 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700353 buffer_id=ofp.OFP_NO_BUFFER,
354 priority=1000)
355
Admin7e9c91d2015-08-25 15:53:49 -0700356 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700357 self.controller.message_send(request)
358 do_barrier(self.controller)
Zsolt Harasztife525502016-03-02 05:18:52 +0000359 verify_no_errors(self.controller)
360
Admin7e9c91d2015-08-25 15:53:49 -0700361 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800362
Admin7e9c91d2015-08-25 15:53:49 -0700363 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800364 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700365 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800366
Admin7e9c91d2015-08-25 15:53:49 -0700367 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
368 self.dataplane.send(onu_port, str(inPkt))
369 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800370
Admin7e9c91d2015-08-25 15:53:49 -0700371 # Send untagged packet in the OLT port and expect no packets to come out
372 self.dataplane.send(olt_port, str(inPkt))
373 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800374
Admin7e9c91d2015-08-25 15:53:49 -0700375 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700376 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000377 if device_type == 'pmc':
378 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
379 else: # "normal", "cpqd""
380 outPkt = simple_udp_packet(pktlen=100)
Admin7e9c91d2015-08-25 15:53:49 -0700381
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700382 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
383 self.dataplane.send(olt_port, str(inPkt))
384 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700385
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700386 # Send tagged packet in the ONU port and expect no packets to come out
387 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700388 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700389
alshabibb9d4ee82016-03-01 14:12:42 -0800390
Jonathan Hartf65e1812015-10-05 15:15:37 -0700391def createAllGroupAdd(group_id, ports=[]):
392 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800393
Jonathan Hartf65e1812015-10-05 15:15:37 -0700394 for portNum in ports:
395 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Admin99c2a272016-03-01 12:56:39 -0800396 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800397
398 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
399
Jonathan Hartf65e1812015-10-05 15:15:37 -0700400 return group_add
401
alshabibb9d4ee82016-03-01 14:12:42 -0800402
Jonathan Hartf65e1812015-10-05 15:15:37 -0700403def createAllGroupMod(group_id, ports=[]):
404 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800405
Jonathan Hartf65e1812015-10-05 15:15:37 -0700406 for portNum in ports:
407 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
408 actions=[ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800409
410 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
411 buckets=buckets)
412
Jonathan Hartf65e1812015-10-05 15:15:37 -0700413 return group_mod
alshabibb9d4ee82016-03-01 14:12:42 -0800414
Jonathan Hartf65e1812015-10-05 15:15:37 -0700415
Admin02d052c2015-10-10 19:08:26 -0700416class TestGroupAdd(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000417
Admin02d052c2015-10-10 19:08:26 -0700418 def runTest(self):
419 logging.info("Running Group tests")
420 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700421 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700422
alshabibb9d4ee82016-03-01 14:12:42 -0800423 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700424
425 # output to two ONU
426 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700427
428 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700429 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700430 verify_no_errors(self.controller)
431
432 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800433 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700434 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700435 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700436 verify_no_errors(self.controller)
437
Jonathan Hartf65e1812015-10-05 15:15:37 -0700438 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700439 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700440 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700441 verify_no_errors(self.controller)
442
443
Jonathan Hartf65e1812015-10-05 15:15:37 -0700444 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800445 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700446 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800447
Jonathan Hartf65e1812015-10-05 15:15:37 -0700448 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700449 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800450
451
Admin02d052c2015-10-10 19:08:26 -0700452class TestGroupMod(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000453
Admin02d052c2015-10-10 19:08:26 -0700454 def runTest(self):
455 logging.info("Running Group tests")
456 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700457 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700458
alshabibb9d4ee82016-03-01 14:12:42 -0800459 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700460
461 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700462
463 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700464 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700465 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800466
Jonathan Hartf65e1812015-10-05 15:15:37 -0700467 # Modifying the group
468 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800469
Jonathan Hartf65e1812015-10-05 15:15:37 -0700470 self.controller.message_send(group_mod)
471 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700472 verify_no_errors(self.controller)
473
Jonathan Hartf65e1812015-10-05 15:15:37 -0700474 # Add a bucket into the group
475 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
476 self.controller.message_send(group_mod)
477 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700478 verify_no_errors(self.controller)
479
480 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700481 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700482
Jonathan Hartf65e1812015-10-05 15:15:37 -0700483 self.controller.message_send(group_mod)
484 do_barrier(self.controller)
485 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700486 try:
487 verify_no_errors(self.controller)
488 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700489 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700490 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700491 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800492 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700493 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800494
495
Jonathan Hartf65e1812015-10-05 15:15:37 -0700496 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800497 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700498 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800499
Jonathan Hartf65e1812015-10-05 15:15:37 -0700500 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700501 verify_no_errors(self.controller)
502
alshabibb9d4ee82016-03-01 14:12:42 -0800503
Admin02d052c2015-10-10 19:08:26 -0700504class TestDuplicateGroup(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000505
Admin02d052c2015-10-10 19:08:26 -0700506 def runTest(self):
507 logging.info("Running Group tests")
508 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700509 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700510
alshabibb9d4ee82016-03-01 14:12:42 -0800511 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700512 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700513
514 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700515 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700516 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800517
Jonathan Hartf65e1812015-10-05 15:15:37 -0700518 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800519 duplicate_group_fail = 0
520
Admin02d052c2015-10-10 19:08:26 -0700521 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700522 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700523 try:
524 verify_no_errors(self.controller)
525 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800526 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700527 if (not e.message == "unexpected error type=6 code=0"):
528 raise AssertionError("Incorrect error type: %s" % e.message)
529 if not duplicate_group_fail:
530 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800531
Jonathan Hartf65e1812015-10-05 15:15:37 -0700532 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800533 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700534 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800535
Jonathan Hartf65e1812015-10-05 15:15:37 -0700536 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700537 verify_no_errors(self.controller)
538
alshabibb9d4ee82016-03-01 14:12:42 -0800539
Admin02d052c2015-10-10 19:08:26 -0700540class TestGroupAndFlow(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000541
Admin02d052c2015-10-10 19:08:26 -0700542 def runTest(self):
543 logging.info("Running Group tests")
544 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700545 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700546
Jonathan Hartf65e1812015-10-05 15:15:37 -0700547 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800548 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700549 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700550
551 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700552 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700553 verify_no_errors(self.controller)
554
555 # Create a flow rule matching olt port and vlan id
556 match = ofp.match()
557 match.oxm_list.append(ofp.oxm.in_port(olt_port))
558 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
559
Jonathan Hartf65e1812015-10-05 15:15:37 -0700560 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700561 table_id=test_param_get("table", 0),
562 cookie=43,
563 match=match,
564 instructions=[
565 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800566 actions=[ofp.action.group(group_id=test_group_id)])],
567 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700568
Jonathan Hartf65e1812015-10-05 15:15:37 -0700569 self.controller.message_send(flow_pointing_to_group)
570 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700571 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800572
Jonathan Hartf65e1812015-10-05 15:15:37 -0700573 # After letting a flow rule point to the group, test we can do group_mod
574 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
575 self.controller.message_send(group_mod)
576 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700577 verify_no_errors(self.controller)
578
579 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800580 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700581 self.controller.message_send(flow_delete)
582 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700583 verify_no_errors(self.controller)
584
alshabibb9d4ee82016-03-01 14:12:42 -0800585 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700586 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700587 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700588 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800589
Zsolt Harasztife525502016-03-02 05:18:52 +0000590 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800591 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700592 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700593
594 self.controller.message_send(flow_pointing_to_group)
595 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700596 verify_no_errors(self.controller)
597
598 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800599 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700600
601 self.controller.message_send(flow_delete)
602 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700603 verify_no_errors(self.controller)
604
605
606class TestGroupForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000607
Admin02d052c2015-10-10 19:08:26 -0700608 def runTest(self):
609 logging.info("Running Group datapath forwarding tests")
610 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800611 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700612
Admin09b5cc62015-10-11 13:53:59 -0700613 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700614
Jonathan Hartf65e1812015-10-05 15:15:37 -0700615 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800616 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700617 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700618
619 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700620 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700621 verify_no_errors(self.controller)
622
623 # Create a flow rule matching olt port and vlan id
624 match = ofp.match()
625 match.oxm_list.append(ofp.oxm.in_port(olt_port))
626 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
627
628 request = ofp.message.flow_add(
629 table_id=test_param_get("table", 0),
630 cookie=43,
631 match=match,
632 instructions=[
633 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800634 actions=[ofp.action.group(group_id=test_group_id)]),
635 ],
636 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700637
638 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700639 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700640 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700641
642 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800643 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800644
645 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800646 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 -0700647 outPkt = inPkt
648 self.dataplane.send(olt_port, str(inPkt))
649 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700650
Admindcb1bc72015-11-12 18:24:56 -0800651
Zsolt Harasztife525502016-03-02 05:18:52 +0000652 # Now put 2 ONU ports in the group and test that the input packet is
Jonathan Hartf65e1812015-10-05 15:15:37 -0700653 # duplicated out both ports
654 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
655 self.controller.message_send(group_mod)
656 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700657 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800658
Admin09b5cc62015-10-11 13:53:59 -0700659 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800660 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700661
Jonathan Hartf65e1812015-10-05 15:15:37 -0700662 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700663 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800664 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800665 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700666
Jonathan Hartf65e1812015-10-05 15:15:37 -0700667 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800668 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700669 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800670 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700671 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800672
Jonathan Hartf65e1812015-10-05 15:15:37 -0700673 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700674 verify_no_errors(self.controller)
675
Admindcb1bc72015-11-12 18:24:56 -0800676
677class TestGroupModForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000678
Admindcb1bc72015-11-12 18:24:56 -0800679 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800680 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800681 delete_all_flows(self.controller)
682 delete_all_groups(self.controller)
683
684 vlan_id = 201
685
686 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800687 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800688 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
689
690 self.controller.message_send(group_add)
691 do_barrier(self.controller)
692 verify_no_errors(self.controller)
693
694 # Create a flow rule matching olt port and vlan id
695 match = ofp.match()
696 match.oxm_list.append(ofp.oxm.in_port(olt_port))
697 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
698
699 request = ofp.message.flow_add(
700 table_id=test_param_get("table", 0),
701 cookie=43,
702 match=match,
703 instructions=[
704 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800705 actions=[ofp.action.group(group_id=test_group_id)]),
706 ],
707 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800708
709 self.controller.message_send(request)
710 do_barrier(self.controller)
711 verify_no_errors(self.controller)
712
713 # It takes some time for flows to propagate down to the data plane
714 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800715
716 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800717 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
718 outPkt = inPkt
719 self.dataplane.send(olt_port, str(inPkt))
720 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800721 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800722
723 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
724 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
725 self.controller.message_send(group_mod)
726 do_barrier(self.controller)
727 verify_no_errors(self.controller)
728
729 time.sleep(10)
730 self.dataplane.send(olt_port, str(inPkt))
731 verify_no_packet(self, outPkt, onu_port)
732 verify_packet(self, outPkt, onu_port2)
733
Zsolt Harasztife525502016-03-02 05:18:52 +0000734 # 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 -0800735 group_mod = createAllGroupMod(test_group_id, ports=[])
736 self.controller.message_send(group_mod)
737 do_barrier(self.controller)
738 verify_no_errors(self.controller)
739 time.sleep(10)
740 self.dataplane.send(olt_port, str(inPkt))
741 verify_packets(self, outPkt, [])
742
743
Admin02d052c2015-10-10 19:08:26 -0700744class TransparentVlanTest(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000745
Admin02d052c2015-10-10 19:08:26 -0700746 def runTest(self):
747 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700748 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700749
Jonathan Hartf65e1812015-10-05 15:15:37 -0700750 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700751 match = ofp.match()
752 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800753 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700754
755 request = ofp.message.flow_add(
756 table_id=test_param_get("table", 0),
757 cookie=42,
758 match=match,
759 instructions=[
760 ofp.instruction.apply_actions(
761 actions=[
762 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800763 ],
Admin02d052c2015-10-10 19:08:26 -0700764 buffer_id=ofp.OFP_NO_BUFFER,
765 priority=1000)
766
767 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800768
Admin02d052c2015-10-10 19:08:26 -0700769 match = ofp.match()
770 match.oxm_list.append(ofp.oxm.in_port(olt_port))
771 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
772
773 request = ofp.message.flow_add(
774 table_id=test_param_get("table", 0),
775 cookie=43,
776 match=match,
777 instructions=[
778 ofp.instruction.apply_actions(
779 actions=[
780 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800781 ],
Admin02d052c2015-10-10 19:08:26 -0700782 buffer_id=ofp.OFP_NO_BUFFER,
783 priority=1000)
784
785 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700786 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700787 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700788
Admin09b5cc62015-10-11 13:53:59 -0700789 # It takes some time for flows to propagate down to the data plane
790 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800791
Jonathan Hartf65e1812015-10-05 15:15:37 -0700792 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000793
Admin02d052c2015-10-10 19:08:26 -0700794 # upstream
795 self.dataplane.send(onu_port, str(inPkt))
796 verify_packet(self, inPkt, olt_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000797
Admin99c2a272016-03-01 12:56:39 -0800798 # downstream
799 self.dataplane.send(olt_port, str(inPkt))
800 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700801
Jonathan Hartf65e1812015-10-05 15:15:37 -0700802 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700803 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700804 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700805 verify_no_errors(self.controller)
806
alshabib28c03c32016-03-01 20:33:51 -0800807class RemoveRuleTest(base_tests.SimpleDataPlane):
808
809 def runTest(self):
810 logging.info("Testing Rule removal")
alshabibe165af22016-03-01 21:42:17 -0800811 delete_all_flows(self.controller)
alshabib9929a152016-03-01 21:25:18 -0800812 processEapolRule(self, onu_port)
alshabibe165af22016-03-01 21:42:17 -0800813
alshabib9929a152016-03-01 21:25:18 -0800814 #wait for the rule to settle
815 time.sleep(3)
816
alshabibdde38ea2016-03-01 21:49:44 -0800817 installDoubleTaggingRules(1, 2, self.controller)
alshabibe165af22016-03-01 21:42:17 -0800818
alshabib9929a152016-03-01 21:25:18 -0800819 #wait for the rules to settle
820 time.sleep(3)
821
822 stats = get_flow_stats(self, ofp.match())
823
Admin53e10b62016-03-01 21:52:18 -0800824 self.assertTrue(len(stats) == 5, \
825 "Wrong number of rules reports; reported %s, expected 5\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800826
827 processEapolRule(self, onu_port, install = False)
828 time.sleep(3)
829
830 stats = get_flow_stats(self, ofp.match())
831
Admin53e10b62016-03-01 21:52:18 -0800832 self.assertTrue(len(stats) == 4, \
833 "Wrong number of rules reports; reported %s, expected 4\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800834
835 logging.info(stats)
alshabib28c03c32016-03-01 20:33:51 -0800836
837
838class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane):
839
840 def runTests(self):
841 logging.info("Testing multiple Q-in-Q rules")
842 pass
843
alshabibb9d4ee82016-03-01 14:12:42 -0800844
Adminb17b1662015-10-19 15:50:53 -0700845class DoubleVlanTest(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000846
Adminb17b1662015-10-19 15:50:53 -0700847 def runTest(self):
848 logging.info("Running double vlan tests")
849 delete_all_flows(self.controller)
850
851 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800852 s_vlan_id = 102
Zsolt Harasztife525502016-03-02 05:18:52 +0000853
854 installDoubleTaggingRules(s_vlan_id, c_vlan_id, self.controller)
Adminb17b1662015-10-19 15:50:53 -0700855
Adminb17b1662015-10-19 15:50:53 -0700856 # It takes some time for flows to propagate down to the data plane
857 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800858
Zsolt Harasztife525502016-03-02 05:18:52 +0000859 # Test packet flows
860 testPacketFlow(self, c_vlan_id, s_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700861
862 # clean up the test
863 delete_all_flows(self.controller)
864 do_barrier(self.controller)
865 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800866
867
868class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
869 """Cycle through vlans and test traffic flow"""
870
871 def runTest(self):
872 logging.info("Running cycling vlan test")
873
alshabib2ecca692016-03-01 15:10:38 -0800874 for stag in xrange(2, 4000, 100):
875 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800876 delete_all_flows(self.controller)
877 time.sleep(5)
alshabibdde38ea2016-03-01 21:49:44 -0800878 installDoubleTaggingRules(stag, ctag, self.controller)
alshabibf1f07dd2016-03-01 15:50:35 -0800879 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800880 testPacketFlow(self, ctag, stag)
alshabibb9d4ee82016-03-01 14:12:42 -0800881
alshabib9929a152016-03-01 21:25:18 -0800882def processEapolRule(test, in_port, install = True):
883 match = ofp.match()
884 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
885 match.oxm_list.append(ofp.oxm.in_port(in_port))
886 if install:
887 request = ofp.message.flow_add(
888 table_id=test_param_get("table", 0),
889 cookie=42,
alshabibd24fca62016-03-01 21:26:35 -0800890 match=match,
alshabib9929a152016-03-01 21:25:18 -0800891 instructions=[
892 ofp.instruction.apply_actions(
893 actions=[
894 ofp.action.output(
895 port=ofp.OFPP_CONTROLLER,
896 max_len=ofp.OFPCML_NO_BUFFER)])],
897 buffer_id=ofp.OFP_NO_BUFFER,
898 priority=1000)
899 else:
900 request = ofp.message.flow_delete(
901 table_id=test_param_get("table", 0),
902 cookie=42,
Admin53e10b62016-03-01 21:52:18 -0800903 match=match,
alshabib9929a152016-03-01 21:25:18 -0800904 instructions=[
905 ofp.instruction.apply_actions(
906 actions=[
907 ofp.action.output(
908 port=ofp.OFPP_CONTROLLER,
909 max_len=ofp.OFPCML_NO_BUFFER)])],
910 buffer_id=ofp.OFP_NO_BUFFER,
911 priority=1000)
912 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
913 test.controller.message_send(request)
914 do_barrier(test.controller)
915
alshabib28c03c32016-03-01 20:33:51 -0800916def testPacketFlow(test, c_vlan_id, s_vlan_id):
alshabibb9b39a72016-03-01 15:52:03 -0800917
Zsolt Harasztife525502016-03-02 05:18:52 +0000918 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1)
919 zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
920 untaggedPkt = simple_udp_packet(pktlen=96)
alshabibb9d4ee82016-03-01 14:12:42 -0800921
alshabib28c03c32016-03-01 20:33:51 -0800922 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
923 c_vlan_vid=c_vlan_id,
924 s_vlan_vid=s_vlan_id,
925 c_vlan_pcp=0, s_vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800926
alshabib28c03c32016-03-01 20:33:51 -0800927 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800928
Zsolt Harasztife525502016-03-02 05:18:52 +0000929 # test upstream untagged packet got double tag at OLT
Zsolt Haraszti68883832016-03-02 05:45:11 +0000930 test.dataplane.send(onu_port, str(zeroTaggedPkt))
931 verify_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800932
alshabib28c03c32016-03-01 20:33:51 -0800933 # test downstream doubletagged packet got untagged at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000934 test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
Zsolt Harasztife525502016-03-02 05:18:52 +0000935 if device_type == "pmc":
Zsolt Haraszti68883832016-03-02 05:45:11 +0000936 verify_packet(test, zeroTaggedPkt, onu_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000937 else:
Zsolt Haraszti68883832016-03-02 05:45:11 +0000938 verify_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800939
alshabib28c03c32016-03-01 20:33:51 -0800940 # test upstream doubletagged packet got dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000941 test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
942 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800943
alshabib28c03c32016-03-01 20:33:51 -0800944 # test downstream untagged packet got dropped at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000945 test.dataplane.send(olt_port, str(untaggedPkt))
946 verify_no_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800947
alshabib28c03c32016-03-01 20:33:51 -0800948 # test upstream icorrectly tagged packet; should get dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000949 test.dataplane.send(onu_port, str(incorrectTagPkt))
950 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800951
alshabibb9d4ee82016-03-01 14:12:42 -0800952
Zsolt Harasztife525502016-03-02 05:18:52 +0000953def installDoubleTaggingRules(s_vlan_id, c_vlan_id, controller, cookie=42):
954
alshabib28c03c32016-03-01 20:33:51 -0800955 # upstream flow rule
956 match = ofp.match()
957 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000958 if device_type == "cpqd":
959 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
960 actions = [
961 ofp.action.push_vlan(ethertype=0x8100),
962 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)),
963 ofp.action.set_field(ofp.oxm.vlan_pcp(0))
964 ]
965 else: # "pmc", "normal"
966 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
967 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
968 actions = [
969 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
970 ]
alshabib28c03c32016-03-01 20:33:51 -0800971 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800972
alshabib28c03c32016-03-01 20:33:51 -0800973 # push inner vlan (c-vlan) for upstream
974 request = ofp.message.flow_add(
975 table_id=test_param_get("table", 0),
Admin965eeda2016-03-01 20:56:14 -0800976 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800977 match=match,
978 instructions=[
Zsolt Haraszti68883832016-03-02 05:45:11 +0000979 ofp.instruction.apply_actions(actions=actions),
alshabib28c03c32016-03-01 20:33:51 -0800980 ofp.instruction.goto_table(1)],
981 buffer_id=ofp.OFP_NO_BUFFER,
982 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800983
alshabib28c03c32016-03-01 20:33:51 -0800984 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -0800985 do_barrier(controller)
986 verify_no_errors(controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800987
alshabib28c03c32016-03-01 20:33:51 -0800988 # push outer vlan (s-vlan) for upstream
989 match = ofp.match()
990 match.oxm_list.append(ofp.oxm.in_port(onu_port))
991 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
992 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
993 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800994
alshabib28c03c32016-03-01 20:33:51 -0800995 request = ofp.message.flow_add(
996 table_id=test_param_get("table", 1),
Admin965eeda2016-03-01 20:56:14 -0800997 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800998 match=match,
999 instructions=[
1000 ofp.instruction.apply_actions(
1001 actions=[
1002 ofp.action.push_vlan(ethertype=0x8100),
1003 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
1004 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
1005 ofp.action.output(port=olt_port)]),
1006 ],
1007 buffer_id=ofp.OFP_NO_BUFFER,
1008 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -08001009
alshabib28c03c32016-03-01 20:33:51 -08001010 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001011 do_barrier(controller)
1012 verify_no_errors(controller)
alshabib28c03c32016-03-01 20:33:51 -08001013 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -08001014
alshabib28c03c32016-03-01 20:33:51 -08001015 # strip outer vlan (s-vlan) for downstream
1016 match = ofp.match()
1017 match.oxm_list.append(ofp.oxm.in_port(olt_port))
1018 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
1019 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1020 request = ofp.message.flow_add(
1021 table_id=test_param_get("table", 0),
Admin965eeda2016-03-01 20:56:14 -08001022 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -08001023 match=match,
1024 instructions=[
1025 ofp.instruction.apply_actions(
1026 actions=[ofp.action.pop_vlan()]),
1027 ofp.instruction.goto_table(1)],
1028 buffer_id=ofp.OFP_NO_BUFFER,
1029 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -08001030
alshabib28c03c32016-03-01 20:33:51 -08001031 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001032 do_barrier(controller)
1033 verify_no_errors(controller)
alshabibb9d4ee82016-03-01 14:12:42 -08001034
alshabib28c03c32016-03-01 20:33:51 -08001035 # rewrite inner vlan (c-vlan) to default (0) for downstream
1036 match = ofp.match()
1037 match.oxm_list.append(ofp.oxm.in_port(olt_port))
1038 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
1039 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1040 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -08001041
alshabib28c03c32016-03-01 20:33:51 -08001042 request = ofp.message.flow_add(
1043 table_id=test_param_get("table", 1),
Admin965eeda2016-03-01 20:56:14 -08001044 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -08001045 match=match,
1046 instructions=[
1047 ofp.instruction.apply_actions(
1048 actions=[
1049 ofp.action.pop_vlan(),
1050 ofp.action.output(port=onu_port)])
1051 ],
1052 buffer_id=ofp.OFP_NO_BUFFER,
1053 priority=1000)
alshabibf1f07dd2016-03-01 15:50:35 -08001054
alshabib28c03c32016-03-01 20:33:51 -08001055 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001056 do_barrier(controller)
1057 verify_no_errors(controller)