blob: 3bed7822bf5deab7ea2a058647fa028feabd13e4 [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
alshabib28c03c32016-03-01 20:33:51 -0800765class RemoveRuleTest(base_tests.SimpleDataPlane):
766
767 def runTest(self):
768 logging.info("Testing Rule removal")
769 pass
770
771
772class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane):
773
774 def runTests(self):
775 logging.info("Testing multiple Q-in-Q rules")
776 pass
777
alshabibb9d4ee82016-03-01 14:12:42 -0800778
Adminb17b1662015-10-19 15:50:53 -0700779class DoubleVlanTest(base_tests.SimpleDataPlane):
Adminb17b1662015-10-19 15:50:53 -0700780 def runTest(self):
781 logging.info("Running double vlan tests")
782 delete_all_flows(self.controller)
783
784 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800785 s_vlan_id = 102
786 # upstream flow rule
alshabib28c03c32016-03-01 20:33:51 -0800787 installDoubleTaggingRule(s_vlan_id, c_vlan_id, self.controller)
Adminb17b1662015-10-19 15:50:53 -0700788
Adminb17b1662015-10-19 15:50:53 -0700789 # It takes some time for flows to propagate down to the data plane
790 time.sleep(10)
alshabib28c03c32016-03-01 20:33:51 -0800791 testPacketFlow(self, c_vlan_id, s_vlan_id)
alshabibb9d4ee82016-03-01 14:12:42 -0800792
793 time.sleep(2)
Adminb17b1662015-10-19 15:50:53 -0700794
795 # clean up the test
796 delete_all_flows(self.controller)
797 do_barrier(self.controller)
798 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800799
800
801class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
802 """Cycle through vlans and test traffic flow"""
803
804 def runTest(self):
805 logging.info("Running cycling vlan test")
806
alshabib2ecca692016-03-01 15:10:38 -0800807 for stag in xrange(2, 4000, 100):
808 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800809 delete_all_flows(self.controller)
810 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800811 installDoubleTaggingRule(stag, ctag, self.controller)
alshabibf1f07dd2016-03-01 15:50:35 -0800812 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800813 testPacketFlow(self, ctag, stag)
alshabibb9d4ee82016-03-01 14:12:42 -0800814
alshabib28c03c32016-03-01 20:33:51 -0800815def testPacketFlow(test, c_vlan_id, s_vlan_id):
alshabibb9b39a72016-03-01 15:52:03 -0800816
alshabib28c03c32016-03-01 20:33:51 -0800817 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=0)
818 untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800819
alshabib28c03c32016-03-01 20:33:51 -0800820 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
821 c_vlan_vid=c_vlan_id,
822 s_vlan_vid=s_vlan_id,
823 c_vlan_pcp=0, s_vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800824
alshabib28c03c32016-03-01 20:33:51 -0800825 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800826
alshabib28c03c32016-03-01 20:33:51 -0800827 test.dataplane.send(onu_port, str(untaggedPkt))
828 verify_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800829
alshabib28c03c32016-03-01 20:33:51 -0800830 # test downstream doubletagged packet got untagged at ONU
831 test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
832 verify_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800833
alshabib28c03c32016-03-01 20:33:51 -0800834 # test upstream doubletagged packet got dropped
835 test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
836 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800837
alshabib28c03c32016-03-01 20:33:51 -0800838 # test downstream untagged packet got dropped at ONU
839 test.dataplane.send(olt_port, str(untaggedPkt))
840 verify_no_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800841
alshabib28c03c32016-03-01 20:33:51 -0800842 # test upstream icorrectly tagged packet; should get dropped
843 test.dataplane.send(onu_port, str(incorrectTagPkt))
844 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800845
alshabibb9d4ee82016-03-01 14:12:42 -0800846
alshabib28c03c32016-03-01 20:33:51 -0800847def installDoubleTaggingRule(s_vlan_id, c_vlan_id, controller, cookie = 42):
848 # upstream flow rule
849 match = ofp.match()
850 match.oxm_list.append(ofp.oxm.in_port(onu_port))
851 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
852 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
853 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800854
alshabib28c03c32016-03-01 20:33:51 -0800855 # push inner vlan (c-vlan) for upstream
856 request = ofp.message.flow_add(
857 table_id=test_param_get("table", 0),
858 cookie=self.cookie,
859 match=match,
860 instructions=[
861 ofp.instruction.apply_actions(
862 actions=[
863 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))]),
864 ofp.instruction.goto_table(1)],
865 buffer_id=ofp.OFP_NO_BUFFER,
866 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800867
alshabib28c03c32016-03-01 20:33:51 -0800868 controller.message_send(request)
869 do_barrier(self.controller)
870 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800871
alshabib28c03c32016-03-01 20:33:51 -0800872 # push outer vlan (s-vlan) for upstream
873 match = ofp.match()
874 match.oxm_list.append(ofp.oxm.in_port(onu_port))
875 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
876 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
877 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800878
alshabib28c03c32016-03-01 20:33:51 -0800879 request = ofp.message.flow_add(
880 table_id=test_param_get("table", 1),
881 cookie=self.cookie,
882 match=match,
883 instructions=[
884 ofp.instruction.apply_actions(
885 actions=[
886 ofp.action.push_vlan(ethertype=0x8100),
887 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
888 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
889 ofp.action.output(port=olt_port)]),
890 ],
891 buffer_id=ofp.OFP_NO_BUFFER,
892 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800893
alshabib28c03c32016-03-01 20:33:51 -0800894 controller.message_send(request)
895 do_barrier(self.controller)
896 verify_no_errors(self.controller)
897 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800898
alshabib28c03c32016-03-01 20:33:51 -0800899 # strip outer vlan (s-vlan) for downstream
900 match = ofp.match()
901 match.oxm_list.append(ofp.oxm.in_port(olt_port))
902 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
903 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
904 request = ofp.message.flow_add(
905 table_id=test_param_get("table", 0),
906 cookie=self.cookie,
907 match=match,
908 instructions=[
909 ofp.instruction.apply_actions(
910 actions=[ofp.action.pop_vlan()]),
911 ofp.instruction.goto_table(1)],
912 buffer_id=ofp.OFP_NO_BUFFER,
913 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800914
alshabib28c03c32016-03-01 20:33:51 -0800915 controller.message_send(request)
916 do_barrier(self.controller)
917 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800918
alshabib28c03c32016-03-01 20:33:51 -0800919 # rewrite inner vlan (c-vlan) to default (0) for downstream
920 match = ofp.match()
921 match.oxm_list.append(ofp.oxm.in_port(olt_port))
922 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
923 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
924 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800925
alshabib28c03c32016-03-01 20:33:51 -0800926 request = ofp.message.flow_add(
927 table_id=test_param_get("table", 1),
928 cookie=self.cookie,
929 match=match,
930 instructions=[
931 ofp.instruction.apply_actions(
932 actions=[
933 ofp.action.pop_vlan(),
934 ofp.action.output(port=onu_port)])
935 ],
936 buffer_id=ofp.OFP_NO_BUFFER,
937 priority=1000)
alshabibf1f07dd2016-03-01 15:50:35 -0800938
alshabib28c03c32016-03-01 20:33:51 -0800939 controller.message_send(request)
940 do_barrier(self.controller)
941 verify_no_errors(self.controller)
942
943
944