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