blob: 5b1d0f5e9757992c966103b32eedd54298476d51 [file] [log] [blame]
Jonathan Hartf2511ca2015-07-07 14:18:19 -07001'''
2OFTests for functionality needed from the OLT.
3'''
4import logging
alshabibb9d4ee82016-03-01 14:12:42 -08005from __builtin__ import xrange
Jonathan Hartf2511ca2015-07-07 14:18:19 -07006from oftest import config
7import oftest.base_tests as base_tests
8import oftest.packet as scapy
9
10import ofp
Admin7e9c91d2015-08-25 15:53:49 -070011import time
Adminef7a0552015-12-09 15:21:45 -080012import copy
Jonathan Hartf2511ca2015-07-07 14:18:19 -070013
14from oftest.testutils import *
15
Admindcb1bc72015-11-12 18:24:56 -080016onu_port = test_param_get("onu_port", 130)
Admin99c2a272016-03-01 12:56:39 -080017onu_port2 = test_param_get("onu_port2", 130)
Admindcb1bc72015-11-12 18:24:56 -080018olt_port = test_param_get("olt_port", 258)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070019
alshabibb9d4ee82016-03-01 14:12:42 -080020
Adminb17b1662015-10-19 15:50:53 -070021def double_vlan_udp_packet(pktlen=100,
alshabibb9d4ee82016-03-01 14:12:42 -080022 eth_dst='00:01:02:03:04:05',
23 eth_src='00:06:07:08:09:0a',
24 dl_vlan_enable=False,
25 c_vlan_vid=0,
26 c_vlan_pcp=0,
27 s_vlan_vid=0,
28 s_vlan_pcp=0,
29 ip_src='192.168.0.1',
30 ip_dst='192.168.0.2',
31 ip_tos=0,
32 ip_ttl=64,
33 udp_sport=1234,
34 udp_dport=80,
35 ip_ihl=None,
36 ip_options=False,
37 eth_type=0x8100
38 ):
Adminb17b1662015-10-19 15:50:53 -070039 """
40 Return a double vlan tagged dataplane UDP packet
41 Supports a few parameters:
42 @param len Length of packet in bytes w/o CRC
43 @param eth_dst Destination MAC
44 @param eth_src Source MAC
45 @param dl_vlan_enable True if the packet is with vlan, False otherwise
46 @param c_vlan_vid CVLAN ID
47 @param c_vlan_pcp CVLAN priority
48 @param s_vlan_vid SVLAN ID
49 @param s_vlan_pcp SVLAN priority
50 @param ip_src IP source
51 @param ip_dst IP destination
52 @param ip_tos IP ToS
53 @param ip_ttl IP TTL
54 @param udp_dport UDP destination port
55 @param udp_sport UDP source port
56
57 Generates a simple UDP packet. Users shouldn't assume anything about
58 this packet other than that it is a valid ethernet/IP/UDP frame.
59 """
60
61 if MINSIZE > pktlen:
62 pktlen = MINSIZE
63
64 # Note Dot1Q.id is really CFI
65 if (dl_vlan_enable):
alshabibb9d4ee82016-03-01 14:12:42 -080066 pkt = scapy.Ether(dst=eth_dst, src=eth_src, type=eth_type) / \
67 scapy.Dot1Q(prio=s_vlan_pcp, vlan=s_vlan_vid) / \
68 scapy.Dot1Q(prio=c_vlan_pcp, vlan=c_vlan_vid) / \
69 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
70 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070071 else:
72 if not ip_options:
alshabibb9d4ee82016-03-01 14:12:42 -080073 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
74 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl) / \
75 scapy.UDP(sport=udp_sport, dport=udp_dport)
Adminb17b1662015-10-19 15:50:53 -070076
alshabibb9d4ee82016-03-01 14:12:42 -080077 else:
78 pkt = scapy.Ether(dst=eth_dst, src=eth_src) / \
79 scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ttl=ip_ttl, ihl=ip_ihl, options=ip_options) / \
80 scapy.UDP(sport=udp_sport, dport=udp_dport)
81
82 pkt = pkt / ("D" * (pktlen - len(pkt)))
Adminb17b1662015-10-19 15:50:53 -070083
84 return pkt
85
86
Jonathan Hartf2511ca2015-07-07 14:18:19 -070087def testPacketIn(self, match, parsed_pkt):
88 delete_all_flows(self.controller)
89
90 pkt = str(parsed_pkt)
91
Adminef7a0552015-12-09 15:21:45 -080092 for of_port in config["port_map"]:
alshabibb9d4ee82016-03-01 14:12:42 -080093 m = copy.deepcopy(match)
Adminef7a0552015-12-09 15:21:45 -080094 m.oxm_list.append(ofp.oxm.in_port(of_port))
95 request = ofp.message.flow_add(
alshabibb9d4ee82016-03-01 14:12:42 -080096 table_id=test_param_get("table", 0),
97 cookie=42,
98 match=m,
99 instructions=[
100 ofp.instruction.apply_actions(
101 actions=[
102 ofp.action.output(
103 port=ofp.OFPP_CONTROLLER,
104 max_len=ofp.OFPCML_NO_BUFFER)])],
105 buffer_id=ofp.OFP_NO_BUFFER,
106 priority=1000)
Adminef7a0552015-12-09 15:21:45 -0800107 logging.info("Inserting flow sending matching packets to controller")
108 self.controller.message_send(request)
109 do_barrier(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800110
Admin7e9c91d2015-08-25 15:53:49 -0700111 for of_port in config["port_map"]:
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700112 logging.info("PacketInExact test, port %d", of_port)
113 self.dataplane.send(of_port, pkt)
114 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
115 verify_packets(self, pkt, [])
116
alshabibb9d4ee82016-03-01 14:12:42 -0800117
Admind5212782015-12-09 17:17:57 -0800118def buildIgmp(payload):
alshabibb9d4ee82016-03-01 14:12:42 -0800119 ether = scapy.Ether(src="00:01:02:03:04:05")
120 ip = scapy.IP(src="1.2.3.4")
121 payload.igmpize(ip, ether)
122 pkt = ether / ip / payload
123 if len(pkt) < 60:
124 pad_len = 60 - len(pkt)
125 pad = scapy.PAD()
126 pad.load = '\x00' * pad_len
127 pkt = pkt / pad
128 return pkt
129
Admind5212782015-12-09 17:17:57 -0800130
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700131class EapolPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700132 """Verify packet-ins are sent for EAPOL packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800133
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700134 def runTest(self):
135 logging.info("Running EAPOL Packet In test")
136
137 match = ofp.match()
138 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
139 # Use ethertype 0x888e and multicast destination MAC address
140 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
alshabibb9d4ee82016-03-01 14:12:42 -0800141
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700142 testPacketIn(self, match, pkt)
143
alshabibb9d4ee82016-03-01 14:12:42 -0800144
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700145class IGMPPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700146 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800147
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700148 def runTest(self):
149 logging.info("Running IGMP Packet In test")
150
151 match = ofp.match()
152 match.oxm_list.append(ofp.oxm.eth_type(0x800))
153 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700154
alshabibb9d4ee82016-03-01 14:12:42 -0800155 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01') / \
156 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
157
158 pkt = pkt / ("0" * (100 - len(pkt)))
159
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700160 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700161
alshabibb9d4ee82016-03-01 14:12:42 -0800162
Admind5212782015-12-09 17:17:57 -0800163class IGMPQueryPacketOut(base_tests.SimpleDataPlane):
Admind5212782015-12-09 17:17:57 -0800164 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -0800165
Admind5212782015-12-09 17:17:57 -0800166 def runTest(self):
167 logging.info("Running IGMP query packet out")
168
alshabibb9d4ee82016-03-01 14:12:42 -0800169 igmp = scapy.IGMP(type=0x11, gaddr="224.0.0.1")
Admind5212782015-12-09 17:17:57 -0800170 pkt = buildIgmp(igmp)
171
172 msg = ofp.message.packet_out()
173 msg.in_port = ofp.OFPP_CONTROLLER
Admin99c2a272016-03-01 12:56:39 -0800174 msg.buffer_id = 0xffffffff
Admind5212782015-12-09 17:17:57 -0800175 msg.data = str(pkt)
176 msg.actions = [ofp.action.output(
alshabibb9d4ee82016-03-01 14:12:42 -0800177 port=onu_port,
178 max_len=ofp.OFPCML_NO_BUFFER)]
Admind5212782015-12-09 17:17:57 -0800179 time.sleep(1)
180
alshabibb9d4ee82016-03-01 14:12:42 -0800181 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -0800182
183 verify_no_errors(self.controller)
184
185 verify_packet(self, pkt, onu_port)
186
alshabibb9d4ee82016-03-01 14:12:42 -0800187
Admin7e9c91d2015-08-25 15:53:49 -0700188class TestMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700189 def runTest(self):
190 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -0800191 dropMeterBand = ofp.meter_band.drop(rate=640)
192 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700193 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -0800194
Admin7e9c91d2015-08-25 15:53:49 -0700195 time.sleep(1)
196
197 verify_no_errors(self.controller)
198
Jonathan Hartf65e1812015-10-05 15:15:37 -0700199 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700200 match = ofp.match()
201 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800202 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700203
204 request = ofp.message.flow_add(
205 table_id=test_param_get("table", 0),
206 cookie=42,
207 match=match,
208 instructions=[
209 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700210 actions=[ofp.action.output(port=olt_port)]
211 ),
alshabibb9d4ee82016-03-01 14:12:42 -0800212 ofp.instruction.meter(meter_id=1)
213 ],
Admin02d052c2015-10-10 19:08:26 -0700214 buffer_id=ofp.OFP_NO_BUFFER,
215 priority=1000)
216
217 self.controller.message_send(request)
218 time.sleep(1)
219 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800220
Admin02d052c2015-10-10 19:08:26 -0700221 match = ofp.match()
222 match.oxm_list.append(ofp.oxm.in_port(olt_port))
223 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700224
225 request = ofp.message.flow_add(
226 table_id=test_param_get("table", 0),
227 cookie=43,
228 match=match,
229 instructions=[
230 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700231 actions=[ofp.action.output(port=onu_port)]
232 ),
alshabibb9d4ee82016-03-01 14:12:42 -0800233 ofp.instruction.meter(meter_id=1)
234 ],
Admin7e9c91d2015-08-25 15:53:49 -0700235 buffer_id=ofp.OFP_NO_BUFFER,
236 priority=1000)
237
238 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700239 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700240 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700241 do_barrier(self.controller)
242 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800243
Jonathan Hartf65e1812015-10-05 15:15:37 -0700244 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
245 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800246 # self.dataplane.send(olt_port, str(inPkt))
247 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700248 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800249 # for i in range(1,400):
250 # self.dataplane.send(onu_port, str(inPkt))
251 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700252
Jonathan Hartf65e1812015-10-05 15:15:37 -0700253 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800254 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700255 self.controller.message_send(meter_mod)
256 time.sleep(1)
257 delete_all_flows(self.controller)
258 verify_no_errors(self.controller)
259
Admin7e9c91d2015-08-25 15:53:49 -0700260
alshabibb9d4ee82016-03-01 14:12:42 -0800261class TestDuplicateMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700262 def runTest(self):
263 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800264 dropMeterBand = ofp.meter_band.drop(rate=500)
265 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700266 self.controller.message_send(meter_mod)
267 self.controller.message_send(meter_mod)
268
269 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800270
Admin7e9c91d2015-08-25 15:53:49 -0700271 try:
272 verify_no_errors(self.controller)
273 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700274 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700275 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800276
277
Admin7e9c91d2015-08-25 15:53:49 -0700278class VlanTest(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700279 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800280
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700281 def runTest(self):
282 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800283
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700284 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800285
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700286 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800287
288 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700289 match = ofp.match()
290 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700291 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
alshabibb9d4ee82016-03-01 14:12:42 -0800292 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
293
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700294 request = ofp.message.flow_add(
295 table_id=test_param_get("table", 0),
296 cookie=42,
297 match=match,
298 instructions=[
299 ofp.instruction.apply_actions(
300 actions=[
301 ofp.action.push_vlan(ethertype=0x8100),
302 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
Admin7e9c91d2015-08-25 15:53:49 -0700303 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700304 ofp.action.output(port=olt_port)])],
305 buffer_id=ofp.OFP_NO_BUFFER,
306 priority=1000)
307
Admin7e9c91d2015-08-25 15:53:49 -0700308 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700309 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800310
311 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700312 match = ofp.match()
313 match.oxm_list.append(ofp.oxm.in_port(olt_port))
314 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700315
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700316 request = ofp.message.flow_add(
317 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700318 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700319 match=match,
320 instructions=[
321 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700322 actions=[
323 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800324 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700325 buffer_id=ofp.OFP_NO_BUFFER,
326 priority=1000)
327
Admin7e9c91d2015-08-25 15:53:49 -0700328 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700329 self.controller.message_send(request)
330 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700331 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800332
Admin7e9c91d2015-08-25 15:53:49 -0700333 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800334 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700335 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800336
Admin7e9c91d2015-08-25 15:53:49 -0700337 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
338 self.dataplane.send(onu_port, str(inPkt))
339 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800340
Admin7e9c91d2015-08-25 15:53:49 -0700341 # Send untagged packet in the OLT port and expect no packets to come out
342 self.dataplane.send(olt_port, str(inPkt))
343 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800344
Admin7e9c91d2015-08-25 15:53:49 -0700345 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700346 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700347 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
348
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700349 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
350 self.dataplane.send(olt_port, str(inPkt))
351 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700352
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700353 # Send tagged packet in the ONU port and expect no packets to come out
354 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700355 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700356
alshabibb9d4ee82016-03-01 14:12:42 -0800357
Jonathan Hartf65e1812015-10-05 15:15:37 -0700358def createAllGroupAdd(group_id, ports=[]):
359 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800360
Jonathan Hartf65e1812015-10-05 15:15:37 -0700361 for portNum in ports:
362 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Admin99c2a272016-03-01 12:56:39 -0800363 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800364
365 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
366
Jonathan Hartf65e1812015-10-05 15:15:37 -0700367 return group_add
368
alshabibb9d4ee82016-03-01 14:12:42 -0800369
Jonathan Hartf65e1812015-10-05 15:15:37 -0700370def createAllGroupMod(group_id, ports=[]):
371 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800372
Jonathan Hartf65e1812015-10-05 15:15:37 -0700373 for portNum in ports:
374 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
375 actions=[ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800376
377 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
378 buckets=buckets)
379
Jonathan Hartf65e1812015-10-05 15:15:37 -0700380 return group_mod
alshabibb9d4ee82016-03-01 14:12:42 -0800381
Jonathan Hartf65e1812015-10-05 15:15:37 -0700382
Admin02d052c2015-10-10 19:08:26 -0700383class TestGroupAdd(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700384 def runTest(self):
385 logging.info("Running Group tests")
386 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700387 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700388
alshabibb9d4ee82016-03-01 14:12:42 -0800389 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700390
391 # output to two ONU
392 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700393
394 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700395 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700396 verify_no_errors(self.controller)
397
398 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800399 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700400 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700401 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700402 verify_no_errors(self.controller)
403
Jonathan Hartf65e1812015-10-05 15:15:37 -0700404 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700405 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700406 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700407 verify_no_errors(self.controller)
408
409
Jonathan Hartf65e1812015-10-05 15:15:37 -0700410 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800411 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700412 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800413
Jonathan Hartf65e1812015-10-05 15:15:37 -0700414 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700415 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800416
417
Admin02d052c2015-10-10 19:08:26 -0700418class TestGroupMod(base_tests.SimpleDataPlane):
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 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700427
428 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700429 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700430 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800431
Jonathan Hartf65e1812015-10-05 15:15:37 -0700432 # Modifying the group
433 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800434
Jonathan Hartf65e1812015-10-05 15:15:37 -0700435 self.controller.message_send(group_mod)
436 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 # Add a bucket into the group
440 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
441 self.controller.message_send(group_mod)
442 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700443 verify_no_errors(self.controller)
444
445 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700446 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700447
Jonathan Hartf65e1812015-10-05 15:15:37 -0700448 self.controller.message_send(group_mod)
449 do_barrier(self.controller)
450 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700451 try:
452 verify_no_errors(self.controller)
453 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700454 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700455 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700456 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800457 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700458 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800459
460
Jonathan Hartf65e1812015-10-05 15:15:37 -0700461 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800462 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700463 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800464
Jonathan Hartf65e1812015-10-05 15:15:37 -0700465 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700466 verify_no_errors(self.controller)
467
alshabibb9d4ee82016-03-01 14:12:42 -0800468
Admin02d052c2015-10-10 19:08:26 -0700469class TestDuplicateGroup(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700470 def runTest(self):
471 logging.info("Running Group tests")
472 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700473 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700474
alshabibb9d4ee82016-03-01 14:12:42 -0800475 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700476 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700477
478 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700479 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700480 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800481
Jonathan Hartf65e1812015-10-05 15:15:37 -0700482 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800483 duplicate_group_fail = 0
484
Admin02d052c2015-10-10 19:08:26 -0700485 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700486 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700487 try:
488 verify_no_errors(self.controller)
489 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800490 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700491 if (not e.message == "unexpected error type=6 code=0"):
492 raise AssertionError("Incorrect error type: %s" % e.message)
493 if not duplicate_group_fail:
494 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800495
Jonathan Hartf65e1812015-10-05 15:15:37 -0700496 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800497 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700498 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800499
Jonathan Hartf65e1812015-10-05 15:15:37 -0700500 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700501 verify_no_errors(self.controller)
502
alshabibb9d4ee82016-03-01 14:12:42 -0800503
Admin02d052c2015-10-10 19:08:26 -0700504class TestGroupAndFlow(base_tests.SimpleDataPlane):
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
Jonathan Hartf65e1812015-10-05 15:15:37 -0700510 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800511 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700512 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700513
514 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700515 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700516 verify_no_errors(self.controller)
517
518 # Create a flow rule matching olt port and vlan id
519 match = ofp.match()
520 match.oxm_list.append(ofp.oxm.in_port(olt_port))
521 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
522
Jonathan Hartf65e1812015-10-05 15:15:37 -0700523 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700524 table_id=test_param_get("table", 0),
525 cookie=43,
526 match=match,
527 instructions=[
528 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800529 actions=[ofp.action.group(group_id=test_group_id)])],
530 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700531
Jonathan Hartf65e1812015-10-05 15:15:37 -0700532 self.controller.message_send(flow_pointing_to_group)
533 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700534 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800535
Jonathan Hartf65e1812015-10-05 15:15:37 -0700536 # After letting a flow rule point to the group, test we can do group_mod
537 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
538 self.controller.message_send(group_mod)
539 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700540 verify_no_errors(self.controller)
541
542 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800543 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700544 self.controller.message_send(flow_delete)
545 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700546 verify_no_errors(self.controller)
547
alshabibb9d4ee82016-03-01 14:12:42 -0800548 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700549 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700550 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700551 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800552
Jonathan Hartf65e1812015-10-05 15:15:37 -0700553 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800554 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700555 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700556
557 self.controller.message_send(flow_pointing_to_group)
558 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700559 verify_no_errors(self.controller)
560
561 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800562 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700563
564 self.controller.message_send(flow_delete)
565 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700566 verify_no_errors(self.controller)
567
568
569class TestGroupForwarding(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700570 def runTest(self):
571 logging.info("Running Group datapath forwarding tests")
572 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800573 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700574
Admin09b5cc62015-10-11 13:53:59 -0700575 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700576
Jonathan Hartf65e1812015-10-05 15:15:37 -0700577 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800578 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700579 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700580
581 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700582 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700583 verify_no_errors(self.controller)
584
585 # Create a flow rule matching olt port and vlan id
586 match = ofp.match()
587 match.oxm_list.append(ofp.oxm.in_port(olt_port))
588 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
589
590 request = ofp.message.flow_add(
591 table_id=test_param_get("table", 0),
592 cookie=43,
593 match=match,
594 instructions=[
595 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800596 actions=[ofp.action.group(group_id=test_group_id)]),
597 ],
598 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700599
600 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700601 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700602 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700603
604 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800605 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800606
607 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800608 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 -0700609 outPkt = inPkt
610 self.dataplane.send(olt_port, str(inPkt))
611 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700612
Admindcb1bc72015-11-12 18:24:56 -0800613
Jonathan Hartf65e1812015-10-05 15:15:37 -0700614 # Now put 2 ONU ports in the group and test that the input packet is
615 # duplicated out both ports
616 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
617 self.controller.message_send(group_mod)
618 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700619 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800620
Admin09b5cc62015-10-11 13:53:59 -0700621 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800622 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700623
Jonathan Hartf65e1812015-10-05 15:15:37 -0700624 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700625 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800626 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800627 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700628
Jonathan Hartf65e1812015-10-05 15:15:37 -0700629 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800630 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700631 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800632 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700633 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800634
Jonathan Hartf65e1812015-10-05 15:15:37 -0700635 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700636 verify_no_errors(self.controller)
637
Admindcb1bc72015-11-12 18:24:56 -0800638
639class TestGroupModForwarding(base_tests.SimpleDataPlane):
Admindcb1bc72015-11-12 18:24:56 -0800640 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800641 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800642 delete_all_flows(self.controller)
643 delete_all_groups(self.controller)
644
645 vlan_id = 201
646
647 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800648 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800649 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
650
651 self.controller.message_send(group_add)
652 do_barrier(self.controller)
653 verify_no_errors(self.controller)
654
655 # Create a flow rule matching olt port and vlan id
656 match = ofp.match()
657 match.oxm_list.append(ofp.oxm.in_port(olt_port))
658 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
659
660 request = ofp.message.flow_add(
661 table_id=test_param_get("table", 0),
662 cookie=43,
663 match=match,
664 instructions=[
665 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800666 actions=[ofp.action.group(group_id=test_group_id)]),
667 ],
668 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800669
670 self.controller.message_send(request)
671 do_barrier(self.controller)
672 verify_no_errors(self.controller)
673
674 # It takes some time for flows to propagate down to the data plane
675 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800676
677 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800678 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
679 outPkt = inPkt
680 self.dataplane.send(olt_port, str(inPkt))
681 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800682 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800683
684 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
685 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
686 self.controller.message_send(group_mod)
687 do_barrier(self.controller)
688 verify_no_errors(self.controller)
689
690 time.sleep(10)
691 self.dataplane.send(olt_port, str(inPkt))
692 verify_no_packet(self, outPkt, onu_port)
693 verify_packet(self, outPkt, onu_port2)
694
695 # Now remove all ports in the group and test that the input packet is no longer forwarded to any port
696 group_mod = createAllGroupMod(test_group_id, ports=[])
697 self.controller.message_send(group_mod)
698 do_barrier(self.controller)
699 verify_no_errors(self.controller)
700 time.sleep(10)
701 self.dataplane.send(olt_port, str(inPkt))
702 verify_packets(self, outPkt, [])
703
704
Admin02d052c2015-10-10 19:08:26 -0700705class TransparentVlanTest(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700706 def runTest(self):
707 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700708 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700709
Jonathan Hartf65e1812015-10-05 15:15:37 -0700710 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700711 match = ofp.match()
712 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800713 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700714
715 request = ofp.message.flow_add(
716 table_id=test_param_get("table", 0),
717 cookie=42,
718 match=match,
719 instructions=[
720 ofp.instruction.apply_actions(
721 actions=[
722 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800723 ],
Admin02d052c2015-10-10 19:08:26 -0700724 buffer_id=ofp.OFP_NO_BUFFER,
725 priority=1000)
726
727 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800728
Admin02d052c2015-10-10 19:08:26 -0700729 match = ofp.match()
730 match.oxm_list.append(ofp.oxm.in_port(olt_port))
731 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
732
733 request = ofp.message.flow_add(
734 table_id=test_param_get("table", 0),
735 cookie=43,
736 match=match,
737 instructions=[
738 ofp.instruction.apply_actions(
739 actions=[
740 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800741 ],
Admin02d052c2015-10-10 19:08:26 -0700742 buffer_id=ofp.OFP_NO_BUFFER,
743 priority=1000)
744
745 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700746 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700747 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700748
Admin09b5cc62015-10-11 13:53:59 -0700749 # It takes some time for flows to propagate down to the data plane
750 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800751
Jonathan Hartf65e1812015-10-05 15:15:37 -0700752 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Admin02d052c2015-10-10 19:08:26 -0700753 # upstream
754 self.dataplane.send(onu_port, str(inPkt))
755 verify_packet(self, inPkt, olt_port)
Admin99c2a272016-03-01 12:56:39 -0800756 # downstream
757 self.dataplane.send(olt_port, str(inPkt))
758 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700759
Jonathan Hartf65e1812015-10-05 15:15:37 -0700760 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700761 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700762 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700763 verify_no_errors(self.controller)
764
alshabibb9d4ee82016-03-01 14:12:42 -0800765
Adminb17b1662015-10-19 15:50:53 -0700766class DoubleVlanTest(base_tests.SimpleDataPlane):
Adminb17b1662015-10-19 15:50:53 -0700767 def runTest(self):
768 logging.info("Running double vlan tests")
769 delete_all_flows(self.controller)
770
771 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800772 s_vlan_id = 102
773 # upstream flow rule
Adminb17b1662015-10-19 15:50:53 -0700774 match = ofp.match()
775 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admindcb1bc72015-11-12 18:24:56 -0800776 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
alshabibb9d4ee82016-03-01 14:12:42 -0800777 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
Adminb17b1662015-10-19 15:50:53 -0700778
alshabibb9d4ee82016-03-01 14:12:42 -0800779 # push inner vlan (c-vlan) for upstream
Adminb17b1662015-10-19 15:50:53 -0700780 request = ofp.message.flow_add(
781 table_id=test_param_get("table", 0),
782 cookie=42,
783 match=match,
784 instructions=[
785 ofp.instruction.apply_actions(
786 actions=[
alshabibb9d4ee82016-03-01 14:12:42 -0800787 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))]),
788 ofp.instruction.goto_table(1)],
Adminb17b1662015-10-19 15:50:53 -0700789 buffer_id=ofp.OFP_NO_BUFFER,
790 priority=1000)
791
792 self.controller.message_send(request)
793 do_barrier(self.controller)
794 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800795
796 # push outer vlan (s-vlan) for upstream
Adminb17b1662015-10-19 15:50:53 -0700797 match = ofp.match()
798 match.oxm_list.append(ofp.oxm.in_port(onu_port))
799 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800800 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
Adminb17b1662015-10-19 15:50:53 -0700801
802 request = ofp.message.flow_add(
803 table_id=test_param_get("table", 1),
804 cookie=43,
805 match=match,
806 instructions=[
807 ofp.instruction.apply_actions(
808 actions=[
Adminef7a0552015-12-09 15:21:45 -0800809 ofp.action.push_vlan(ethertype=0x8100),
Adminb17b1662015-10-19 15:50:53 -0700810 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
811 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
812 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800813 ],
Adminb17b1662015-10-19 15:50:53 -0700814 buffer_id=ofp.OFP_NO_BUFFER,
815 priority=1000)
816
817 self.controller.message_send(request)
818 do_barrier(self.controller)
819 verify_no_errors(self.controller)
820
alshabibb9d4ee82016-03-01 14:12:42 -0800821 # strip outer vlan (s-vlan) for downstream
Adminb17b1662015-10-19 15:50:53 -0700822 match = ofp.match()
823 match.oxm_list.append(ofp.oxm.in_port(olt_port))
824 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800825 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
Adminb17b1662015-10-19 15:50:53 -0700826 request = ofp.message.flow_add(
827 table_id=test_param_get("table", 0),
828 cookie=44,
829 match=match,
830 instructions=[
831 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800832 actions=[ofp.action.pop_vlan()]),
833 ofp.instruction.goto_table(1)],
Adminb17b1662015-10-19 15:50:53 -0700834 buffer_id=ofp.OFP_NO_BUFFER,
835 priority=1000)
836
837 self.controller.message_send(request)
838 do_barrier(self.controller)
839 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800840
841 # rewrite inner vlan (c-vlan) to default (0) for downstream
Adminb17b1662015-10-19 15:50:53 -0700842 match = ofp.match()
843 match.oxm_list.append(ofp.oxm.in_port(olt_port))
844 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800845 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
Adminb17b1662015-10-19 15:50:53 -0700846
847 request = ofp.message.flow_add(
848 table_id=test_param_get("table", 1),
849 cookie=45,
850 match=match,
851 instructions=[
852 ofp.instruction.apply_actions(
853 actions=[
alshabibb9d4ee82016-03-01 14:12:42 -0800854 ofp.action.pop_vlan(),
855 ofp.action.output(port=onu_port)])
856 ],
Adminb17b1662015-10-19 15:50:53 -0700857 buffer_id=ofp.OFP_NO_BUFFER,
858 priority=1000)
859
860 self.controller.message_send(request)
861 do_barrier(self.controller)
862 verify_no_errors(self.controller)
863 # It takes some time for flows to propagate down to the data plane
alshabibb9d4ee82016-03-01 14:12:42 -0800864
Adminb17b1662015-10-19 15:50:53 -0700865 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800866 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=0)
Adminb17b1662015-10-19 15:50:53 -0700867 untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
Admindcb1bc72015-11-12 18:24:56 -0800868
alshabibb9d4ee82016-03-01 14:12:42 -0800869 '''
Admindcb1bc72015-11-12 18:24:56 -0800870 FIXME: hack because OLT does _not_ tag packets correctly
871 it ignores the eth_type in the push_vlan action
872 and always slaps on 0x8100 even though the
873 down stream flow must be 0x88a8.
alshabibb9d4ee82016-03-01 14:12:42 -0800874 '''
875 doubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
876 c_vlan_vid=c_vlan_id,
877 s_vlan_vid=s_vlan_id,
878 c_vlan_pcp=0, s_vlan_pcp=0, eth_type=0x88a8)
Admindcb1bc72015-11-12 18:24:56 -0800879
alshabibb9d4ee82016-03-01 14:12:42 -0800880 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
881 c_vlan_vid=c_vlan_id,
882 s_vlan_vid=s_vlan_id,
883 c_vlan_pcp=0, s_vlan_pcp=0)
Admindcb1bc72015-11-12 18:24:56 -0800884
Adminb17b1662015-10-19 15:50:53 -0700885 # test upstream untagged packet got double tag at OLT
alshabibb9d4ee82016-03-01 14:12:42 -0800886 logging.info(str(doubleTaggedPkt))
887
Adminb17b1662015-10-19 15:50:53 -0700888 self.dataplane.send(onu_port, str(untaggedPkt))
Admindcb1bc72015-11-12 18:24:56 -0800889 verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800890
891 # test downstream doubletagged packet got untagged at ONU
Adminb17b1662015-10-19 15:50:53 -0700892 self.dataplane.send(olt_port, str(doubleTaggedPkt))
893 verify_packet(self, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800894
895 # test upstream doubletagged packet got dropped
Admindcb1bc72015-11-12 18:24:56 -0800896 self.dataplane.send(onu_port, str(doubleTaggedPkt))
897 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800898
899 # test downstream untagged packet got dropped at ONU
Admindcb1bc72015-11-12 18:24:56 -0800900 self.dataplane.send(olt_port, str(untaggedPkt))
901 verify_no_packet(self, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800902
903 # test upstream icorrectly tagged packet; should get dropped
904 self.dataplane.send(onu_port, str(incorrectTagPkt))
905
906 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
907
908 time.sleep(2)
Adminb17b1662015-10-19 15:50:53 -0700909
910 # clean up the test
911 delete_all_flows(self.controller)
912 do_barrier(self.controller)
913 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800914
915
916class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
917 """Cycle through vlans and test traffic flow"""
918
919 def runTest(self):
920 logging.info("Running cycling vlan test")
921
922 self.vlan_pairs = []
923
924 for stag in xrange(1, 4000, 100):
925 for ctag in xrange(1, 4000, 100):
926 self.installDoubleTaggingRule(stag, ctag)
927 self.vlan_pairs.append((stag, ctag))
928 time.sleep(1)
929 self.testPacketFlow()
930
931 def testPacketFlow(self):
932 for (s_vlan_id, c_vlan_id) in self.vlan_pairs:
933 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=0)
934 untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
935
936 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
937 c_vlan_vid=c_vlan_id,
938 s_vlan_vid=s_vlan_id,
939 c_vlan_pcp=0, s_vlan_pcp=0)
940
941 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
942
943 self.dataplane.send(onu_port, str(untaggedPkt))
944 verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
945
946 # test downstream doubletagged packet got untagged at ONU
947 self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
948 verify_packet(self, untaggedPkt, onu_port)
949
950 # test upstream doubletagged packet got dropped
951 self.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
952 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
953
954 # test downstream untagged packet got dropped at ONU
955 self.dataplane.send(olt_port, str(untaggedPkt))
956 verify_no_packet(self, untaggedPkt, onu_port)
957
958 # test upstream icorrectly tagged packet; should get dropped
959 self.dataplane.send(onu_port, str(incorrectTagPkt))
960 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
961
962 def installDoubleTaggingRule(self, s_vlan_id, c_vlan_id):
963 match = ofp.match()
964 match.oxm_list.append(ofp.oxm.in_port(onu_port))
965 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
966 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
967
968 # push inner vlan (c-vlan) for upstream
969 request = ofp.message.flow_add(
970 table_id=test_param_get("table", 0),
971 cookie=42,
972 match=match,
973 instructions=[
974 ofp.instruction.apply_actions(
975 actions=[
976 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))]),
977 ofp.instruction.goto_table(1)],
978 buffer_id=ofp.OFP_NO_BUFFER,
979 priority=1000)
980
981 self.controller.message_send(request)
982 do_barrier(self.controller)
983 verify_no_errors(self.controller)
984
alshabib41d5b4f2016-03-01 14:49:19 -0800985 # push inner vlan (c-vlan) for upstream
986 request = ofp.message.flow_add(
987 table_id=test_param_get("table", 0),
988 cookie=42,
989 match=match,
990 instructions=[
991 ofp.instruction.apply_actions(
992 actions=[
993 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))]),
994 ofp.instruction.goto_table(1)],
995 buffer_id=ofp.OFP_NO_BUFFER,
996 priority=1000)
997
998 self.controller.message_send(request)
999 do_barrier(self.controller)
1000 verify_no_errors(self.controller)
1001
alshabibb9d4ee82016-03-01 14:12:42 -08001002 # push outer vlan (s-vlan) for upstream
1003 match = ofp.match()
1004 match.oxm_list.append(ofp.oxm.in_port(onu_port))
1005 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
1006 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1007
1008 request = ofp.message.flow_add(
1009 table_id=test_param_get("table", 1),
1010 cookie=43,
1011 match=match,
1012 instructions=[
1013 ofp.instruction.apply_actions(
1014 actions=[
1015 ofp.action.push_vlan(ethertype=0x8100),
1016 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
1017 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
1018 ofp.action.output(port=olt_port)]),
1019 ],
1020 buffer_id=ofp.OFP_NO_BUFFER,
1021 priority=1000)
1022
1023 self.controller.message_send(request)
1024 do_barrier(self.controller)
1025 verify_no_errors(self.controller)
1026
1027 # strip outer vlan (s-vlan) for downstream
1028 match = ofp.match()
1029 match.oxm_list.append(ofp.oxm.in_port(olt_port))
1030 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
1031 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1032 request = ofp.message.flow_add(
1033 table_id=test_param_get("table", 0),
1034 cookie=44,
1035 match=match,
1036 instructions=[
1037 ofp.instruction.apply_actions(
1038 actions=[ofp.action.pop_vlan()]),
1039 ofp.instruction.goto_table(1)],
1040 buffer_id=ofp.OFP_NO_BUFFER,
1041 priority=1000)
1042
1043 self.controller.message_send(request)
1044 do_barrier(self.controller)
1045 verify_no_errors(self.controller)
1046
1047 # rewrite inner vlan (c-vlan) to default (0) for downstream
1048 match = ofp.match()
1049 match.oxm_list.append(ofp.oxm.in_port(olt_port))
1050 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
1051 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
1052
1053 request = ofp.message.flow_add(
1054 table_id=test_param_get("table", 1),
1055 cookie=45,
1056 match=match,
1057 instructions=[
1058 ofp.instruction.apply_actions(
1059 actions=[
1060 ofp.action.pop_vlan(),
1061 ofp.action.output(port=onu_port)])
1062 ],
1063 buffer_id=ofp.OFP_NO_BUFFER,
1064 priority=1000)
1065
1066 self.controller.message_send(request)
1067 do_barrier(self.controller)
1068 verify_no_errors(self.controller)