blob: 0fea8d8be3a36b7e57e31ea01559b18060a9833d [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
alshabibeff3ba92016-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
alshabibeff3ba92016-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 Harasztife525502016-03-02 05:18:52 +000019from IGMP import IGMPv3
20
21# These parameters can be altered from the command line using the -t or --test-params= options.
22# Example: -t 'onu_port=129;olt_port=288;device_type=pmc'
23#
24onu_port = test_param_get("onu_port", 130)
25onu_port2 = test_param_get("onu_port2", 131)
26olt_port = test_param_get("olt_port", 258)
27device_type = test_param_get("device_type", "normal") # options: "normal", "pmc", "cpqd"
28logging.info("device_type: %s" % device_type)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070029
alshabibb9d4ee82016-03-01 14:12:42 -080030
Adminb17b1662015-10-19 15:50:53 -070031def double_vlan_udp_packet(pktlen=100,
alshabibb9d4ee82016-03-01 14:12:42 -080032 eth_dst='00:01:02:03:04:05',
33 eth_src='00:06:07:08:09:0a',
34 dl_vlan_enable=False,
35 c_vlan_vid=0,
36 c_vlan_pcp=0,
37 s_vlan_vid=0,
38 s_vlan_pcp=0,
39 ip_src='192.168.0.1',
40 ip_dst='192.168.0.2',
41 ip_tos=0,
42 ip_ttl=64,
43 udp_sport=1234,
44 udp_dport=80,
45 ip_ihl=None,
46 ip_options=False,
47 eth_type=0x8100
48 ):
Adminb17b1662015-10-19 15:50:53 -070049 """
50 Return a double vlan tagged dataplane UDP packet
51 Supports a few parameters:
52 @param len Length of packet in bytes w/o CRC
53 @param eth_dst Destination MAC
54 @param eth_src Source MAC
55 @param dl_vlan_enable True if the packet is with vlan, False otherwise
56 @param c_vlan_vid CVLAN ID
57 @param c_vlan_pcp CVLAN priority
58 @param s_vlan_vid SVLAN ID
59 @param s_vlan_pcp SVLAN priority
60 @param ip_src IP source
61 @param ip_dst IP destination
62 @param ip_tos IP ToS
63 @param ip_ttl IP TTL
64 @param udp_dport UDP destination port
65 @param udp_sport UDP source port
66
67 Generates a simple UDP packet. Users shouldn't assume anything about
68 this packet other than that it is a valid ethernet/IP/UDP frame.
69 """
70
71 if MINSIZE > pktlen:
72 pktlen = MINSIZE
73
74 # Note Dot1Q.id is really CFI
75 if (dl_vlan_enable):
alshabibb9d4ee82016-03-01 14:12:42 -080076 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
77 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
78 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
79 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
80 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070081 else:
82 if not ip_options:
Zsolt Harasztife525502016-03-02 05:18:52 +000083 pkt = scapy.Ether(dst=eth_dst, src=eth_src)/ \
84 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl)/ \
85 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070086
alshabibb9d4ee82016-03-01 14:12:42 -080087 else:
88 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
89 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
90 scapy.UDP(sport=udp_sport, dport=udp_dport)
91
92 pkt = pkt / ("D" * (pktlen - len(pkt)))
Adminb17b1662015-10-19 15:50:53 -070093
94 return pkt
95
Jonathan Hartf2511ca2015-07-07 14:18:19 -070096def testPacketIn(self, match, parsed_pkt):
97 delete_all_flows(self.controller)
98
99 pkt = str(parsed_pkt)
100
Adminef7a0552015-12-09 15:21:45 -0800101 for of_port in config["port_map"]:
alshabibb9d4ee82016-03-01 14:12:42 -0800102 m = copy.deepcopy(match)
Adminef7a0552015-12-09 15:21:45 -0800103 m.oxm_list.append(ofp.oxm.in_port(of_port))
104 request = ofp.message.flow_add(
alshabibb9d4ee82016-03-01 14:12:42 -0800105 table_id=test_param_get("table", 0),
106 cookie=42,
107 match=m,
108 instructions=[
109 ofp.instruction.apply_actions(
110 actions=[
111 ofp.action.output(
112 port=ofp.OFPP_CONTROLLER,
113 max_len=ofp.OFPCML_NO_BUFFER)])],
114 buffer_id=ofp.OFP_NO_BUFFER,
115 priority=1000)
Adminef7a0552015-12-09 15:21:45 -0800116 logging.info("Inserting flow sending matching packets to controller")
117 self.controller.message_send(request)
118 do_barrier(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800119
Admin7e9c91d2015-08-25 15:53:49 -0700120 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700121 logging.info("PacketInExact test, port %d", of_port)
122 self.dataplane.send(of_port, pkt)
123 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
124 verify_packets(self, pkt, [])
125
alshabibb9d4ee82016-03-01 14:12:42 -0800126
Admind5212782015-12-09 17:17:57 -0800127def buildIgmp(payload):
Zsolt Harasztife525502016-03-02 05:18:52 +0000128 pkt = pkt = IGMPv3.fixup(scapy.Ether() / scapy.IP() / payload)
alshabibb9d4ee82016-03-01 14:12:42 -0800129 if len(pkt) < 60:
130 pad_len = 60 - len(pkt)
Zsolt Harasztife525502016-03-02 05:18:52 +0000131 pad = scapy.scapy.layers.l2.Padding()
alshabibb9d4ee82016-03-01 14:12:42 -0800132 pad.load = '\x00' * pad_len
133 pkt = pkt / pad
134 return pkt
135
Admind5212782015-12-09 17:17:57 -0800136
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700137class EapolPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700138 """Verify packet-ins are sent for EAPOL packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800139
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700140 def runTest(self):
141 logging.info("Running EAPOL Packet In test")
142
143 match = ofp.match()
144 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
145 # Use ethertype 0x888e and multicast destination MAC address
146 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
alshabibb9d4ee82016-03-01 14:12:42 -0800147
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700148 testPacketIn(self, match, pkt)
149
alshabibb9d4ee82016-03-01 14:12:42 -0800150
Zsolt Harasztife525502016-03-02 05:18:52 +0000151class ARPPacketIn(base_tests.SimpleDataPlane):
152 """Verify packet-ins are sent for ARP packets """
alshabib9929a152016-03-01 21:25:18 -0800153
Zsolt Harasztife525502016-03-02 05:18:52 +0000154 def runTest(self):
155 logging.info("Running ARP Packet In test")
alshabib9929a152016-03-01 21:25:18 -0800156
Zsolt Harasztife525502016-03-02 05:18:52 +0000157 match = ofp.match()
158 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
159
160 # Use ethertype 0x0806
161 pkt = simple_eth_packet(eth_type=0x0806)
162
163 testPacketIn(self, match, pkt)
alshabib9929a152016-03-01 21:25:18 -0800164
165
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700166class IGMPPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700167 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800168
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700169 def runTest(self):
170 logging.info("Running IGMP Packet In test")
171
172 match = ofp.match()
173 match.oxm_list.append(ofp.oxm.eth_type(0x800))
174 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700175
Zsolt Harasztife525502016-03-02 05:18:52 +0000176 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01')/ \
alshabibb9d4ee82016-03-01 14:12:42 -0800177 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
178
179 pkt = pkt / ("0" * (100 - len(pkt)))
180
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700181 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700182
alshabibb9d4ee82016-03-01 14:12:42 -0800183
Admind5212782015-12-09 17:17:57 -0800184class IGMPQueryPacketOut(base_tests.SimpleDataPlane):
Admind5212782015-12-09 17:17:57 -0800185 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -0800186
Admind5212782015-12-09 17:17:57 -0800187 def runTest(self):
188 logging.info("Running IGMP query packet out")
189
Zsolt Harasztife525502016-03-02 05:18:52 +0000190 igmp = IGMPv3() # by default this is a query
Admind5212782015-12-09 17:17:57 -0800191 pkt = buildIgmp(igmp)
192
Zsolt Harasztife525502016-03-02 05:18:52 +0000193 msg = ofp.message.packet_out(
194 in_port=ofp.OFPP_CONTROLLER,
195 actions=[ofp.action.output(port=onu_port)],
196 buffer_id=ofp.OFP_NO_BUFFER,
197 data=str(pkt))
Admind5212782015-12-09 17:17:57 -0800198
alshabibb9d4ee82016-03-01 14:12:42 -0800199 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -0800200
Zsolt Harasztife525502016-03-02 05:18:52 +0000201 rv = self.controller.message_send(msg)
202 self.assertTrue(rv == 0, "Error sending put message")
Admind5212782015-12-09 17:17:57 -0800203 verify_no_errors(self.controller)
204
205 verify_packet(self, pkt, onu_port)
206
alshabibb9d4ee82016-03-01 14:12:42 -0800207
Admin7e9c91d2015-08-25 15:53:49 -0700208class TestMeter(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000209
Admin7e9c91d2015-08-25 15:53:49 -0700210 def runTest(self):
211 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -0800212 dropMeterBand = ofp.meter_band.drop(rate=640)
213 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700214 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -0800215
Admin7e9c91d2015-08-25 15:53:49 -0700216 time.sleep(1)
217
218 verify_no_errors(self.controller)
219
Jonathan Hartf65e1812015-10-05 15:15:37 -0700220 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700221 match = ofp.match()
222 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800223 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700224
225 request = ofp.message.flow_add(
226 table_id=test_param_get("table", 0),
227 cookie=42,
228 match=match,
229 instructions=[
230 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000231 actions=[ofp.action.output(port=olt_port)]),
232 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800233 ],
Admin02d052c2015-10-10 19:08:26 -0700234 buffer_id=ofp.OFP_NO_BUFFER,
235 priority=1000)
236
237 self.controller.message_send(request)
238 time.sleep(1)
239 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800240
Admin02d052c2015-10-10 19:08:26 -0700241 match = ofp.match()
242 match.oxm_list.append(ofp.oxm.in_port(olt_port))
243 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700244
245 request = ofp.message.flow_add(
246 table_id=test_param_get("table", 0),
247 cookie=43,
248 match=match,
249 instructions=[
250 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000251 actions=[ofp.action.output(port=onu_port)]),
252 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800253 ],
Admin7e9c91d2015-08-25 15:53:49 -0700254 buffer_id=ofp.OFP_NO_BUFFER,
255 priority=1000)
256
257 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700258 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700259 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700260 do_barrier(self.controller)
261 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800262
Jonathan Hartf65e1812015-10-05 15:15:37 -0700263 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
264 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800265 # self.dataplane.send(olt_port, str(inPkt))
266 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700267 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800268 # for i in range(1,400):
269 # self.dataplane.send(onu_port, str(inPkt))
270 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700271
Jonathan Hartf65e1812015-10-05 15:15:37 -0700272 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800273 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700274 self.controller.message_send(meter_mod)
275 time.sleep(1)
276 delete_all_flows(self.controller)
277 verify_no_errors(self.controller)
278
Admin7e9c91d2015-08-25 15:53:49 -0700279
alshabibb9d4ee82016-03-01 14:12:42 -0800280class TestDuplicateMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700281 def runTest(self):
282 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800283 dropMeterBand = ofp.meter_band.drop(rate=500)
284 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700285 self.controller.message_send(meter_mod)
286 self.controller.message_send(meter_mod)
287
288 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800289
Admin7e9c91d2015-08-25 15:53:49 -0700290 try:
291 verify_no_errors(self.controller)
292 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700293 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700294 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800295
296
Admin7e9c91d2015-08-25 15:53:49 -0700297class VlanTest(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700298 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800299
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700300 def runTest(self):
301 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800302
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700303 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800304
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700305 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800306
307 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700308 match = ofp.match()
309 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000310 if device_type == "cpqd":
311 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
312 actions = [
313 ofp.action.push_vlan(ethertype=0x8100),
314 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
315 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
316 ofp.action.output(port=olt_port)
317 ]
318 else: # pmc, normal
319 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
320 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
321 actions = [
322 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
323 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
324 ofp.action.output(port=olt_port)
325 ]
alshabibb9d4ee82016-03-01 14:12:42 -0800326
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700327 request = ofp.message.flow_add(
328 table_id=test_param_get("table", 0),
329 cookie=42,
330 match=match,
Zsolt Harasztife525502016-03-02 05:18:52 +0000331 instructions=[ofp.instruction.apply_actions(actions=actions)],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700332 buffer_id=ofp.OFP_NO_BUFFER,
333 priority=1000)
334
Admin7e9c91d2015-08-25 15:53:49 -0700335 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700336 self.controller.message_send(request)
Zsolt Harasztife525502016-03-02 05:18:52 +0000337 do_barrier(self.controller)
338 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800339
340 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700341 match = ofp.match()
342 match.oxm_list.append(ofp.oxm.in_port(olt_port))
343 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700344
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700345 request = ofp.message.flow_add(
346 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700347 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700348 match=match,
349 instructions=[
350 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700351 actions=[
352 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800353 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700354 buffer_id=ofp.OFP_NO_BUFFER,
355 priority=1000)
356
Admin7e9c91d2015-08-25 15:53:49 -0700357 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700358 self.controller.message_send(request)
359 do_barrier(self.controller)
Zsolt Harasztife525502016-03-02 05:18:52 +0000360 verify_no_errors(self.controller)
361
Admin7e9c91d2015-08-25 15:53:49 -0700362 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800363
Admin7e9c91d2015-08-25 15:53:49 -0700364 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800365 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700366 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800367
Admin7e9c91d2015-08-25 15:53:49 -0700368 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
369 self.dataplane.send(onu_port, str(inPkt))
370 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800371
Admin7e9c91d2015-08-25 15:53:49 -0700372 # Send untagged packet in the OLT port and expect no packets to come out
373 self.dataplane.send(olt_port, str(inPkt))
374 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800375
Admin7e9c91d2015-08-25 15:53:49 -0700376 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700377 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000378 if device_type == 'pmc':
379 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
380 else: # "normal", "cpqd""
381 outPkt = simple_udp_packet(pktlen=100)
Admin7e9c91d2015-08-25 15:53:49 -0700382
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700383 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
384 self.dataplane.send(olt_port, str(inPkt))
385 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700386
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700387 # Send tagged packet in the ONU port and expect no packets to come out
388 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700389 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700390
alshabibb9d4ee82016-03-01 14:12:42 -0800391
Jonathan Hartf65e1812015-10-05 15:15:37 -0700392def createAllGroupAdd(group_id, ports=[]):
393 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800394
Jonathan Hartf65e1812015-10-05 15:15:37 -0700395 for portNum in ports:
396 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Admin99c2a272016-03-01 12:56:39 -0800397 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800398
399 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
400
Jonathan Hartf65e1812015-10-05 15:15:37 -0700401 return group_add
402
alshabibb9d4ee82016-03-01 14:12:42 -0800403
Jonathan Hartf65e1812015-10-05 15:15:37 -0700404def createAllGroupMod(group_id, ports=[]):
405 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800406
Jonathan Hartf65e1812015-10-05 15:15:37 -0700407 for portNum in ports:
408 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
409 actions=[ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800410
411 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
412 buckets=buckets)
413
Jonathan Hartf65e1812015-10-05 15:15:37 -0700414 return group_mod
alshabibb9d4ee82016-03-01 14:12:42 -0800415
Jonathan Hartf65e1812015-10-05 15:15:37 -0700416
Admin02d052c2015-10-10 19:08:26 -0700417class TestGroupAdd(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000418
Admin02d052c2015-10-10 19:08:26 -0700419 def runTest(self):
420 logging.info("Running Group tests")
421 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700422 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700423
alshabibb9d4ee82016-03-01 14:12:42 -0800424 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700425
426 # output to two ONU
427 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700428
429 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700430 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700431 verify_no_errors(self.controller)
432
433 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800434 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700435 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700436 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700437 verify_no_errors(self.controller)
438
Jonathan Hartf65e1812015-10-05 15:15:37 -0700439 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700440 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700441 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700442 verify_no_errors(self.controller)
443
444
Jonathan Hartf65e1812015-10-05 15:15:37 -0700445 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800446 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700447 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800448
Jonathan Hartf65e1812015-10-05 15:15:37 -0700449 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700450 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800451
452
Admin02d052c2015-10-10 19:08:26 -0700453class TestGroupMod(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000454
Admin02d052c2015-10-10 19:08:26 -0700455 def runTest(self):
456 logging.info("Running Group tests")
457 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700458 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700459
alshabibb9d4ee82016-03-01 14:12:42 -0800460 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700461
462 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700463
464 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700465 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700466 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800467
Jonathan Hartf65e1812015-10-05 15:15:37 -0700468 # Modifying the group
469 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800470
Jonathan Hartf65e1812015-10-05 15:15:37 -0700471 self.controller.message_send(group_mod)
472 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700473 verify_no_errors(self.controller)
474
Jonathan Hartf65e1812015-10-05 15:15:37 -0700475 # Add a bucket into the group
476 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
477 self.controller.message_send(group_mod)
478 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700479 verify_no_errors(self.controller)
480
481 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700482 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700483
Jonathan Hartf65e1812015-10-05 15:15:37 -0700484 self.controller.message_send(group_mod)
485 do_barrier(self.controller)
486 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700487 try:
488 verify_no_errors(self.controller)
489 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700490 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700491 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700492 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800493 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700494 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800495
496
Jonathan Hartf65e1812015-10-05 15:15:37 -0700497 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800498 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700499 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800500
Jonathan Hartf65e1812015-10-05 15:15:37 -0700501 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700502 verify_no_errors(self.controller)
503
alshabibb9d4ee82016-03-01 14:12:42 -0800504
Admin02d052c2015-10-10 19:08:26 -0700505class TestDuplicateGroup(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000506
Admin02d052c2015-10-10 19:08:26 -0700507 def runTest(self):
508 logging.info("Running Group tests")
509 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700510 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700511
alshabibb9d4ee82016-03-01 14:12:42 -0800512 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700513 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700514
515 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700516 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700517 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800518
Jonathan Hartf65e1812015-10-05 15:15:37 -0700519 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800520 duplicate_group_fail = 0
521
Admin02d052c2015-10-10 19:08:26 -0700522 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700523 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700524 try:
525 verify_no_errors(self.controller)
526 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800527 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700528 if (not e.message == "unexpected error type=6 code=0"):
529 raise AssertionError("Incorrect error type: %s" % e.message)
530 if not duplicate_group_fail:
531 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800532
Jonathan Hartf65e1812015-10-05 15:15:37 -0700533 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800534 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700535 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800536
Jonathan Hartf65e1812015-10-05 15:15:37 -0700537 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700538 verify_no_errors(self.controller)
539
alshabibb9d4ee82016-03-01 14:12:42 -0800540
Admin02d052c2015-10-10 19:08:26 -0700541class TestGroupAndFlow(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000542
Admin02d052c2015-10-10 19:08:26 -0700543 def runTest(self):
544 logging.info("Running Group tests")
545 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700546 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700547
Jonathan Hartf65e1812015-10-05 15:15:37 -0700548 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800549 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700550 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700551
552 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700553 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700554 verify_no_errors(self.controller)
555
556 # Create a flow rule matching olt port and vlan id
557 match = ofp.match()
558 match.oxm_list.append(ofp.oxm.in_port(olt_port))
559 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
560
Jonathan Hartf65e1812015-10-05 15:15:37 -0700561 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700562 table_id=test_param_get("table", 0),
563 cookie=43,
564 match=match,
565 instructions=[
566 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800567 actions=[ofp.action.group(group_id=test_group_id)])],
568 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700569
Jonathan Hartf65e1812015-10-05 15:15:37 -0700570 self.controller.message_send(flow_pointing_to_group)
571 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700572 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800573
Jonathan Hartf65e1812015-10-05 15:15:37 -0700574 # After letting a flow rule point to the group, test we can do group_mod
575 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
576 self.controller.message_send(group_mod)
577 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700578 verify_no_errors(self.controller)
579
580 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800581 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700582 self.controller.message_send(flow_delete)
583 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700584 verify_no_errors(self.controller)
585
alshabibb9d4ee82016-03-01 14:12:42 -0800586 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700587 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700588 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700589 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800590
Zsolt Harasztife525502016-03-02 05:18:52 +0000591 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800592 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700593 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700594
595 self.controller.message_send(flow_pointing_to_group)
596 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700597 verify_no_errors(self.controller)
598
599 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800600 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700601
602 self.controller.message_send(flow_delete)
603 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700604 verify_no_errors(self.controller)
605
606
607class TestGroupForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000608
Admin02d052c2015-10-10 19:08:26 -0700609 def runTest(self):
610 logging.info("Running Group datapath forwarding tests")
611 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800612 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700613
Admin09b5cc62015-10-11 13:53:59 -0700614 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700615
Jonathan Hartf65e1812015-10-05 15:15:37 -0700616 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800617 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700618 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700619
620 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700621 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700622 verify_no_errors(self.controller)
623
624 # Create a flow rule matching olt port and vlan id
625 match = ofp.match()
626 match.oxm_list.append(ofp.oxm.in_port(olt_port))
627 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
628
629 request = ofp.message.flow_add(
630 table_id=test_param_get("table", 0),
631 cookie=43,
632 match=match,
633 instructions=[
634 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800635 actions=[ofp.action.group(group_id=test_group_id)]),
636 ],
637 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700638
639 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700640 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700641 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700642
643 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800644 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800645
646 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800647 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 -0700648 outPkt = inPkt
649 self.dataplane.send(olt_port, str(inPkt))
650 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700651
Admindcb1bc72015-11-12 18:24:56 -0800652
Zsolt Harasztife525502016-03-02 05:18:52 +0000653 # Now put 2 ONU ports in the group and test that the input packet is
Jonathan Hartf65e1812015-10-05 15:15:37 -0700654 # duplicated out both ports
655 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
656 self.controller.message_send(group_mod)
657 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700658 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800659
Admin09b5cc62015-10-11 13:53:59 -0700660 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800661 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700662
Jonathan Hartf65e1812015-10-05 15:15:37 -0700663 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700664 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800665 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800666 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700667
Jonathan Hartf65e1812015-10-05 15:15:37 -0700668 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800669 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700670 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800671 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700672 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800673
Jonathan Hartf65e1812015-10-05 15:15:37 -0700674 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700675 verify_no_errors(self.controller)
676
Admindcb1bc72015-11-12 18:24:56 -0800677
678class TestGroupModForwarding(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000679
Admindcb1bc72015-11-12 18:24:56 -0800680 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800681 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800682 delete_all_flows(self.controller)
683 delete_all_groups(self.controller)
684
685 vlan_id = 201
686
687 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800688 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800689 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
690
691 self.controller.message_send(group_add)
692 do_barrier(self.controller)
693 verify_no_errors(self.controller)
694
695 # Create a flow rule matching olt port and vlan id
696 match = ofp.match()
697 match.oxm_list.append(ofp.oxm.in_port(olt_port))
698 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
699
700 request = ofp.message.flow_add(
701 table_id=test_param_get("table", 0),
702 cookie=43,
703 match=match,
704 instructions=[
705 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800706 actions=[ofp.action.group(group_id=test_group_id)]),
707 ],
708 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800709
710 self.controller.message_send(request)
711 do_barrier(self.controller)
712 verify_no_errors(self.controller)
713
714 # It takes some time for flows to propagate down to the data plane
715 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800716
717 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800718 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
719 outPkt = inPkt
720 self.dataplane.send(olt_port, str(inPkt))
721 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800722 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800723
724 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
725 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
726 self.controller.message_send(group_mod)
727 do_barrier(self.controller)
728 verify_no_errors(self.controller)
729
730 time.sleep(10)
731 self.dataplane.send(olt_port, str(inPkt))
732 verify_no_packet(self, outPkt, onu_port)
733 verify_packet(self, outPkt, onu_port2)
734
Zsolt Harasztife525502016-03-02 05:18:52 +0000735 # 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 -0800736 group_mod = createAllGroupMod(test_group_id, ports=[])
737 self.controller.message_send(group_mod)
738 do_barrier(self.controller)
739 verify_no_errors(self.controller)
740 time.sleep(10)
741 self.dataplane.send(olt_port, str(inPkt))
742 verify_packets(self, outPkt, [])
743
744
Admin02d052c2015-10-10 19:08:26 -0700745class TransparentVlanTest(base_tests.SimpleDataPlane):
Zsolt Harasztife525502016-03-02 05:18:52 +0000746
Admin02d052c2015-10-10 19:08:26 -0700747 def runTest(self):
748 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700749 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700750
Jonathan Hartf65e1812015-10-05 15:15:37 -0700751 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700752 match = ofp.match()
753 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800754 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700755
756 request = ofp.message.flow_add(
757 table_id=test_param_get("table", 0),
758 cookie=42,
759 match=match,
760 instructions=[
761 ofp.instruction.apply_actions(
762 actions=[
763 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800764 ],
Admin02d052c2015-10-10 19:08:26 -0700765 buffer_id=ofp.OFP_NO_BUFFER,
766 priority=1000)
767
768 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800769
Admin02d052c2015-10-10 19:08:26 -0700770 match = ofp.match()
771 match.oxm_list.append(ofp.oxm.in_port(olt_port))
772 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
773
774 request = ofp.message.flow_add(
775 table_id=test_param_get("table", 0),
776 cookie=43,
777 match=match,
778 instructions=[
779 ofp.instruction.apply_actions(
780 actions=[
781 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800782 ],
Admin02d052c2015-10-10 19:08:26 -0700783 buffer_id=ofp.OFP_NO_BUFFER,
784 priority=1000)
785
786 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700787 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700788 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700789
Admin09b5cc62015-10-11 13:53:59 -0700790 # It takes some time for flows to propagate down to the data plane
791 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800792
Jonathan Hartf65e1812015-10-05 15:15:37 -0700793 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000794
Admin02d052c2015-10-10 19:08:26 -0700795 # upstream
796 self.dataplane.send(onu_port, str(inPkt))
797 verify_packet(self, inPkt, olt_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000798
Admin99c2a272016-03-01 12:56:39 -0800799 # downstream
800 self.dataplane.send(olt_port, str(inPkt))
801 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700802
Jonathan Hartf65e1812015-10-05 15:15:37 -0700803 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700804 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700805 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700806 verify_no_errors(self.controller)
807
alshabib28c03c32016-03-01 20:33:51 -0800808class RemoveRuleTest(base_tests.SimpleDataPlane):
809
810 def runTest(self):
811 logging.info("Testing Rule removal")
alshabibe165af22016-03-01 21:42:17 -0800812 delete_all_flows(self.controller)
alshabib9929a152016-03-01 21:25:18 -0800813 processEapolRule(self, onu_port)
alshabibe165af22016-03-01 21:42:17 -0800814
alshabib9929a152016-03-01 21:25:18 -0800815 #wait for the rule to settle
816 time.sleep(3)
817
alshabibdde38ea2016-03-01 21:49:44 -0800818 installDoubleTaggingRules(1, 2, self.controller)
alshabibe165af22016-03-01 21:42:17 -0800819
alshabib9929a152016-03-01 21:25:18 -0800820 #wait for the rules to settle
821 time.sleep(3)
822
823 stats = get_flow_stats(self, ofp.match())
824
Admin53e10b62016-03-01 21:52:18 -0800825 self.assertTrue(len(stats) == 5, \
826 "Wrong number of rules reports; reported %s, expected 5\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800827
828 processEapolRule(self, onu_port, install = False)
829 time.sleep(3)
830
831 stats = get_flow_stats(self, ofp.match())
832
Admin53e10b62016-03-01 21:52:18 -0800833 self.assertTrue(len(stats) == 4, \
834 "Wrong number of rules reports; reported %s, expected 4\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800835
alshabibeff3ba92016-03-01 22:21:00 -0800836 eapol = ofp.oxm.eth_type(0x888e)
837 found = False
838 for fe in stats:
839 if eapol in fe.match.oxm_list:
840 found = True
841
842 self.assertFalse(found, "Removed incorrect flow rule")
alshabib28c03c32016-03-01 20:33:51 -0800843
844
845class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane):
846
847 def runTests(self):
848 logging.info("Testing multiple Q-in-Q rules")
849 pass
850
alshabibb9d4ee82016-03-01 14:12:42 -0800851
alshabibeff3ba92016-03-01 22:21:00 -0800852class DoubleVlanTest(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000853
Adminb17b1662015-10-19 15:50:53 -0700854 def runTest(self):
855 logging.info("Running double vlan tests")
856 delete_all_flows(self.controller)
857
858 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800859 s_vlan_id = 102
Zsolt Harasztife525502016-03-02 05:18:52 +0000860
alshabibeff3ba92016-03-01 22:21:00 -0800861 self.installDoubleTaggingRules(s_vlan_id, c_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700862
Adminb17b1662015-10-19 15:50:53 -0700863 # It takes some time for flows to propagate down to the data plane
864 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800865
Zsolt Harasztife525502016-03-02 05:18:52 +0000866 # Test packet flows
867 testPacketFlow(self, c_vlan_id, s_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700868
869 # clean up the test
870 delete_all_flows(self.controller)
871 do_barrier(self.controller)
872 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800873
874
875class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
876 """Cycle through vlans and test traffic flow"""
877
878 def runTest(self):
879 logging.info("Running cycling vlan test")
880
alshabib2ecca692016-03-01 15:10:38 -0800881 for stag in xrange(2, 4000, 100):
882 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800883 delete_all_flows(self.controller)
884 time.sleep(5)
alshabibdde38ea2016-03-01 21:49:44 -0800885 installDoubleTaggingRules(stag, ctag, self.controller)
alshabibf1f07dd2016-03-01 15:50:35 -0800886 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800887 testPacketFlow(self, ctag, stag)
alshabibb9d4ee82016-03-01 14:12:42 -0800888
alshabib9929a152016-03-01 21:25:18 -0800889def processEapolRule(test, in_port, install = True):
890 match = ofp.match()
891 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
892 match.oxm_list.append(ofp.oxm.in_port(in_port))
893 if install:
894 request = ofp.message.flow_add(
895 table_id=test_param_get("table", 0),
896 cookie=42,
alshabibd24fca62016-03-01 21:26:35 -0800897 match=match,
alshabib9929a152016-03-01 21:25:18 -0800898 instructions=[
899 ofp.instruction.apply_actions(
900 actions=[
901 ofp.action.output(
902 port=ofp.OFPP_CONTROLLER,
903 max_len=ofp.OFPCML_NO_BUFFER)])],
904 buffer_id=ofp.OFP_NO_BUFFER,
905 priority=1000)
906 else:
907 request = ofp.message.flow_delete(
908 table_id=test_param_get("table", 0),
909 cookie=42,
Admin53e10b62016-03-01 21:52:18 -0800910 match=match,
alshabib9929a152016-03-01 21:25:18 -0800911 instructions=[
912 ofp.instruction.apply_actions(
913 actions=[
914 ofp.action.output(
915 port=ofp.OFPP_CONTROLLER,
916 max_len=ofp.OFPCML_NO_BUFFER)])],
917 buffer_id=ofp.OFP_NO_BUFFER,
918 priority=1000)
919 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
920 test.controller.message_send(request)
921 do_barrier(test.controller)
922
alshabib28c03c32016-03-01 20:33:51 -0800923def testPacketFlow(test, c_vlan_id, s_vlan_id):
alshabibb9b39a72016-03-01 15:52:03 -0800924
Zsolt Harasztife525502016-03-02 05:18:52 +0000925 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1)
926 zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
927 untaggedPkt = simple_udp_packet(pktlen=96)
alshabibb9d4ee82016-03-01 14:12:42 -0800928
alshabib28c03c32016-03-01 20:33:51 -0800929 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
930 c_vlan_vid=c_vlan_id,
931 s_vlan_vid=s_vlan_id,
932 c_vlan_pcp=0, s_vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800933
alshabib28c03c32016-03-01 20:33:51 -0800934 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800935
Zsolt Harasztife525502016-03-02 05:18:52 +0000936 # test upstream untagged packet got double tag at OLT
Zsolt Haraszti68883832016-03-02 05:45:11 +0000937 test.dataplane.send(onu_port, str(zeroTaggedPkt))
938 verify_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800939
alshabib28c03c32016-03-01 20:33:51 -0800940 # test downstream doubletagged packet got untagged at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000941 test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
Zsolt Harasztife525502016-03-02 05:18:52 +0000942 if device_type == "pmc":
Zsolt Haraszti68883832016-03-02 05:45:11 +0000943 verify_packet(test, zeroTaggedPkt, onu_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000944 else:
Zsolt Haraszti68883832016-03-02 05:45:11 +0000945 verify_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800946
alshabib28c03c32016-03-01 20:33:51 -0800947 # test upstream doubletagged packet got dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000948 test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
949 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800950
alshabib28c03c32016-03-01 20:33:51 -0800951 # test downstream untagged packet got dropped at ONU
Zsolt Haraszti68883832016-03-02 05:45:11 +0000952 test.dataplane.send(olt_port, str(untaggedPkt))
953 verify_no_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800954
alshabib28c03c32016-03-01 20:33:51 -0800955 # test upstream icorrectly tagged packet; should get dropped
Zsolt Haraszti68883832016-03-02 05:45:11 +0000956 test.dataplane.send(onu_port, str(incorrectTagPkt))
957 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800958
alshabibb9d4ee82016-03-01 14:12:42 -0800959