blob: 82b520f696ac3d38f5223beb8ea85d09bdda0d38 [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
alshabib9929a152016-03-01 21:25:18 -0800145
146
147
148
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700149class IGMPPacketIn(base_tests.SimpleDataPlane):
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700150 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -0800151
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700152 def runTest(self):
153 logging.info("Running IGMP Packet In test")
154
155 match = ofp.match()
156 match.oxm_list.append(ofp.oxm.eth_type(0x800))
157 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700158
alshabibb9d4ee82016-03-01 14:12:42 -0800159 pkt = scapy.Ether(dst='01:00:5E:7F:FF:FF', src='00:00:00:00:00:01') / \
160 scapy.IP(src='10.0.0.1', dst='10.0.0.2', ttl=60, tos=0, id=0, proto=2)
161
162 pkt = pkt / ("0" * (100 - len(pkt)))
163
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700164 testPacketIn(self, match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -0700165
alshabibb9d4ee82016-03-01 14:12:42 -0800166
Admind5212782015-12-09 17:17:57 -0800167class IGMPQueryPacketOut(base_tests.SimpleDataPlane):
Admind5212782015-12-09 17:17:57 -0800168 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -0800169
Admind5212782015-12-09 17:17:57 -0800170 def runTest(self):
171 logging.info("Running IGMP query packet out")
172
alshabibb9d4ee82016-03-01 14:12:42 -0800173 igmp = scapy.IGMP(type=0x11, gaddr="224.0.0.1")
Admind5212782015-12-09 17:17:57 -0800174 pkt = buildIgmp(igmp)
175
176 msg = ofp.message.packet_out()
177 msg.in_port = ofp.OFPP_CONTROLLER
Admin99c2a272016-03-01 12:56:39 -0800178 msg.buffer_id = 0xffffffff
Admind5212782015-12-09 17:17:57 -0800179 msg.data = str(pkt)
180 msg.actions = [ofp.action.output(
alshabibb9d4ee82016-03-01 14:12:42 -0800181 port=onu_port,
182 max_len=ofp.OFPCML_NO_BUFFER)]
Admind5212782015-12-09 17:17:57 -0800183 time.sleep(1)
184
alshabibb9d4ee82016-03-01 14:12:42 -0800185 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -0800186
187 verify_no_errors(self.controller)
188
189 verify_packet(self, pkt, onu_port)
190
alshabibb9d4ee82016-03-01 14:12:42 -0800191
Admin7e9c91d2015-08-25 15:53:49 -0700192class TestMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700193 def runTest(self):
194 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -0800195 dropMeterBand = ofp.meter_band.drop(rate=640)
196 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700197 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -0800198
Admin7e9c91d2015-08-25 15:53:49 -0700199 time.sleep(1)
200
201 verify_no_errors(self.controller)
202
Jonathan Hartf65e1812015-10-05 15:15:37 -0700203 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700204 match = ofp.match()
205 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800206 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700207
208 request = ofp.message.flow_add(
209 table_id=test_param_get("table", 0),
210 cookie=42,
211 match=match,
212 instructions=[
213 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700214 actions=[ofp.action.output(port=olt_port)]
215 ),
alshabibb9d4ee82016-03-01 14:12:42 -0800216 ofp.instruction.meter(meter_id=1)
217 ],
Admin02d052c2015-10-10 19:08:26 -0700218 buffer_id=ofp.OFP_NO_BUFFER,
219 priority=1000)
220
221 self.controller.message_send(request)
222 time.sleep(1)
223 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800224
Admin02d052c2015-10-10 19:08:26 -0700225 match = ofp.match()
226 match.oxm_list.append(ofp.oxm.in_port(olt_port))
227 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700228
229 request = ofp.message.flow_add(
230 table_id=test_param_get("table", 0),
231 cookie=43,
232 match=match,
233 instructions=[
234 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700235 actions=[ofp.action.output(port=onu_port)]
236 ),
alshabibb9d4ee82016-03-01 14:12:42 -0800237 ofp.instruction.meter(meter_id=1)
238 ],
Admin7e9c91d2015-08-25 15:53:49 -0700239 buffer_id=ofp.OFP_NO_BUFFER,
240 priority=1000)
241
242 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700243 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700244 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700245 do_barrier(self.controller)
246 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800247
Jonathan Hartf65e1812015-10-05 15:15:37 -0700248 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
249 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800250 # self.dataplane.send(olt_port, str(inPkt))
251 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700252 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800253 # for i in range(1,400):
254 # self.dataplane.send(onu_port, str(inPkt))
255 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700256
Jonathan Hartf65e1812015-10-05 15:15:37 -0700257 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800258 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700259 self.controller.message_send(meter_mod)
260 time.sleep(1)
261 delete_all_flows(self.controller)
262 verify_no_errors(self.controller)
263
Admin7e9c91d2015-08-25 15:53:49 -0700264
alshabibb9d4ee82016-03-01 14:12:42 -0800265class TestDuplicateMeter(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700266 def runTest(self):
267 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800268 dropMeterBand = ofp.meter_band.drop(rate=500)
269 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700270 self.controller.message_send(meter_mod)
271 self.controller.message_send(meter_mod)
272
273 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800274
Admin7e9c91d2015-08-25 15:53:49 -0700275 try:
276 verify_no_errors(self.controller)
277 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700278 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700279 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800280
281
Admin7e9c91d2015-08-25 15:53:49 -0700282class VlanTest(base_tests.SimpleDataPlane):
Admin7e9c91d2015-08-25 15:53:49 -0700283 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800284
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700285 def runTest(self):
286 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800287
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700288 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800289
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700290 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800291
292 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700293 match = ofp.match()
294 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Admin7e9c91d2015-08-25 15:53:49 -0700295 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
alshabibb9d4ee82016-03-01 14:12:42 -0800296 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
297
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700298 request = ofp.message.flow_add(
299 table_id=test_param_get("table", 0),
300 cookie=42,
301 match=match,
302 instructions=[
303 ofp.instruction.apply_actions(
304 actions=[
305 ofp.action.push_vlan(ethertype=0x8100),
306 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
Admin7e9c91d2015-08-25 15:53:49 -0700307 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700308 ofp.action.output(port=olt_port)])],
309 buffer_id=ofp.OFP_NO_BUFFER,
310 priority=1000)
311
Admin7e9c91d2015-08-25 15:53:49 -0700312 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700313 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800314
315 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700316 match = ofp.match()
317 match.oxm_list.append(ofp.oxm.in_port(olt_port))
318 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700319
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700320 request = ofp.message.flow_add(
321 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700322 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700323 match=match,
324 instructions=[
325 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700326 actions=[
327 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800328 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700329 buffer_id=ofp.OFP_NO_BUFFER,
330 priority=1000)
331
Admin7e9c91d2015-08-25 15:53:49 -0700332 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700333 self.controller.message_send(request)
334 do_barrier(self.controller)
Admin7e9c91d2015-08-25 15:53:49 -0700335 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800336
Admin7e9c91d2015-08-25 15:53:49 -0700337 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800338 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700339 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800340
Admin7e9c91d2015-08-25 15:53:49 -0700341 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
342 self.dataplane.send(onu_port, str(inPkt))
343 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800344
Admin7e9c91d2015-08-25 15:53:49 -0700345 # Send untagged packet in the OLT port and expect no packets to come out
346 self.dataplane.send(olt_port, str(inPkt))
347 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800348
Admin7e9c91d2015-08-25 15:53:49 -0700349 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700350 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Admin7e9c91d2015-08-25 15:53:49 -0700351 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
352
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700353 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
354 self.dataplane.send(olt_port, str(inPkt))
355 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700356
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700357 # Send tagged packet in the ONU port and expect no packets to come out
358 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700359 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700360
alshabibb9d4ee82016-03-01 14:12:42 -0800361
Jonathan Hartf65e1812015-10-05 15:15:37 -0700362def createAllGroupAdd(group_id, ports=[]):
363 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800364
Jonathan Hartf65e1812015-10-05 15:15:37 -0700365 for portNum in ports:
366 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
Admin99c2a272016-03-01 12:56:39 -0800367 actions=[ofp.action.pop_vlan(), ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800368
369 group_add = ofp.message.group_add(group_type=ofp.OFPGT_ALL, group_id=group_id, buckets=buckets)
370
Jonathan Hartf65e1812015-10-05 15:15:37 -0700371 return group_add
372
alshabibb9d4ee82016-03-01 14:12:42 -0800373
Jonathan Hartf65e1812015-10-05 15:15:37 -0700374def createAllGroupMod(group_id, ports=[]):
375 buckets = []
alshabibb9d4ee82016-03-01 14:12:42 -0800376
Jonathan Hartf65e1812015-10-05 15:15:37 -0700377 for portNum in ports:
378 buckets.append(ofp.common.bucket(watch_port=ofp.OFPP_ANY, watch_group=ofp.OFPG_ANY,
379 actions=[ofp.action.output(port=portNum)]))
alshabibb9d4ee82016-03-01 14:12:42 -0800380
381 group_mod = ofp.message.group_mod(command=ofp.OFPGC_MODIFY, group_type=ofp.OFPGT_ALL, group_id=group_id,
382 buckets=buckets)
383
Jonathan Hartf65e1812015-10-05 15:15:37 -0700384 return group_mod
alshabibb9d4ee82016-03-01 14:12:42 -0800385
Jonathan Hartf65e1812015-10-05 15:15:37 -0700386
Admin02d052c2015-10-10 19:08:26 -0700387class TestGroupAdd(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700388 def runTest(self):
389 logging.info("Running Group tests")
390 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700391 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700392
alshabibb9d4ee82016-03-01 14:12:42 -0800393 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700394
395 # output to two ONU
396 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700397
398 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700399 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700400 verify_no_errors(self.controller)
401
402 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800403 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700404 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700405 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700406 verify_no_errors(self.controller)
407
Jonathan Hartf65e1812015-10-05 15:15:37 -0700408 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700409 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700410 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700411 verify_no_errors(self.controller)
412
413
Jonathan Hartf65e1812015-10-05 15:15:37 -0700414 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800415 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700416 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800417
Jonathan Hartf65e1812015-10-05 15:15:37 -0700418 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700419 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800420
421
Admin02d052c2015-10-10 19:08:26 -0700422class TestGroupMod(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700423 def runTest(self):
424 logging.info("Running Group tests")
425 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700426 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700427
alshabibb9d4ee82016-03-01 14:12:42 -0800428 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700429
430 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700431
432 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700433 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700434 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800435
Jonathan Hartf65e1812015-10-05 15:15:37 -0700436 # Modifying the group
437 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800438
Jonathan Hartf65e1812015-10-05 15:15:37 -0700439 self.controller.message_send(group_mod)
440 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700441 verify_no_errors(self.controller)
442
Jonathan Hartf65e1812015-10-05 15:15:37 -0700443 # Add a bucket into the group
444 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
445 self.controller.message_send(group_mod)
446 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700447 verify_no_errors(self.controller)
448
449 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700450 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700451
Jonathan Hartf65e1812015-10-05 15:15:37 -0700452 self.controller.message_send(group_mod)
453 do_barrier(self.controller)
454 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700455 try:
456 verify_no_errors(self.controller)
457 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700458 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700459 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700460 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800461 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700462 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800463
464
Jonathan Hartf65e1812015-10-05 15:15:37 -0700465 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800466 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700467 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800468
Jonathan Hartf65e1812015-10-05 15:15:37 -0700469 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700470 verify_no_errors(self.controller)
471
alshabibb9d4ee82016-03-01 14:12:42 -0800472
Admin02d052c2015-10-10 19:08:26 -0700473class TestDuplicateGroup(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700474 def runTest(self):
475 logging.info("Running Group tests")
476 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700477 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700478
alshabibb9d4ee82016-03-01 14:12:42 -0800479 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700480 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700481
482 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700483 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700484 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800485
Jonathan Hartf65e1812015-10-05 15:15:37 -0700486 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800487 duplicate_group_fail = 0
488
Admin02d052c2015-10-10 19:08:26 -0700489 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700490 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700491 try:
492 verify_no_errors(self.controller)
493 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800494 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700495 if (not e.message == "unexpected error type=6 code=0"):
496 raise AssertionError("Incorrect error type: %s" % e.message)
497 if not duplicate_group_fail:
498 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800499
Jonathan Hartf65e1812015-10-05 15:15:37 -0700500 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800501 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700502 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800503
Jonathan Hartf65e1812015-10-05 15:15:37 -0700504 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700505 verify_no_errors(self.controller)
506
alshabibb9d4ee82016-03-01 14:12:42 -0800507
Admin02d052c2015-10-10 19:08:26 -0700508class TestGroupAndFlow(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700509 def runTest(self):
510 logging.info("Running Group tests")
511 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700512 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700513
Jonathan Hartf65e1812015-10-05 15:15:37 -0700514 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800515 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700516 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700517
518 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700519 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700520 verify_no_errors(self.controller)
521
522 # Create a flow rule matching olt port and vlan id
523 match = ofp.match()
524 match.oxm_list.append(ofp.oxm.in_port(olt_port))
525 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
526
Jonathan Hartf65e1812015-10-05 15:15:37 -0700527 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700528 table_id=test_param_get("table", 0),
529 cookie=43,
530 match=match,
531 instructions=[
532 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800533 actions=[ofp.action.group(group_id=test_group_id)])],
534 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700535
Jonathan Hartf65e1812015-10-05 15:15:37 -0700536 self.controller.message_send(flow_pointing_to_group)
537 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700538 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800539
Jonathan Hartf65e1812015-10-05 15:15:37 -0700540 # After letting a flow rule point to the group, test we can do group_mod
541 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
542 self.controller.message_send(group_mod)
543 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700544 verify_no_errors(self.controller)
545
546 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800547 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700548 self.controller.message_send(flow_delete)
549 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700550 verify_no_errors(self.controller)
551
alshabibb9d4ee82016-03-01 14:12:42 -0800552 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700553 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700554 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700555 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800556
Jonathan Hartf65e1812015-10-05 15:15:37 -0700557 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800558 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700559 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700560
561 self.controller.message_send(flow_pointing_to_group)
562 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700563 verify_no_errors(self.controller)
564
565 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800566 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700567
568 self.controller.message_send(flow_delete)
569 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700570 verify_no_errors(self.controller)
571
572
573class TestGroupForwarding(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700574 def runTest(self):
575 logging.info("Running Group datapath forwarding tests")
576 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800577 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700578
Admin09b5cc62015-10-11 13:53:59 -0700579 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700580
Jonathan Hartf65e1812015-10-05 15:15:37 -0700581 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800582 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700583 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700584
585 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700586 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700587 verify_no_errors(self.controller)
588
589 # Create a flow rule matching olt port and vlan id
590 match = ofp.match()
591 match.oxm_list.append(ofp.oxm.in_port(olt_port))
592 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
593
594 request = ofp.message.flow_add(
595 table_id=test_param_get("table", 0),
596 cookie=43,
597 match=match,
598 instructions=[
599 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800600 actions=[ofp.action.group(group_id=test_group_id)]),
601 ],
602 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700603
604 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700605 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700606 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700607
608 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800609 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800610
611 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800612 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 -0700613 outPkt = inPkt
614 self.dataplane.send(olt_port, str(inPkt))
615 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700616
Admindcb1bc72015-11-12 18:24:56 -0800617
Jonathan Hartf65e1812015-10-05 15:15:37 -0700618 # Now put 2 ONU ports in the group and test that the input packet is
619 # duplicated out both ports
620 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
621 self.controller.message_send(group_mod)
622 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700623 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800624
Admin09b5cc62015-10-11 13:53:59 -0700625 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800626 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700627
Jonathan Hartf65e1812015-10-05 15:15:37 -0700628 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700629 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800630 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800631 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700632
Jonathan Hartf65e1812015-10-05 15:15:37 -0700633 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800634 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700635 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800636 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700637 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800638
Jonathan Hartf65e1812015-10-05 15:15:37 -0700639 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700640 verify_no_errors(self.controller)
641
Admindcb1bc72015-11-12 18:24:56 -0800642
643class TestGroupModForwarding(base_tests.SimpleDataPlane):
Admindcb1bc72015-11-12 18:24:56 -0800644 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800645 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800646 delete_all_flows(self.controller)
647 delete_all_groups(self.controller)
648
649 vlan_id = 201
650
651 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800652 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800653 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
654
655 self.controller.message_send(group_add)
656 do_barrier(self.controller)
657 verify_no_errors(self.controller)
658
659 # Create a flow rule matching olt port and vlan id
660 match = ofp.match()
661 match.oxm_list.append(ofp.oxm.in_port(olt_port))
662 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
663
664 request = ofp.message.flow_add(
665 table_id=test_param_get("table", 0),
666 cookie=43,
667 match=match,
668 instructions=[
669 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800670 actions=[ofp.action.group(group_id=test_group_id)]),
671 ],
672 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800673
674 self.controller.message_send(request)
675 do_barrier(self.controller)
676 verify_no_errors(self.controller)
677
678 # It takes some time for flows to propagate down to the data plane
679 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800680
681 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800682 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
683 outPkt = inPkt
684 self.dataplane.send(olt_port, str(inPkt))
685 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800686 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800687
688 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
689 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
690 self.controller.message_send(group_mod)
691 do_barrier(self.controller)
692 verify_no_errors(self.controller)
693
694 time.sleep(10)
695 self.dataplane.send(olt_port, str(inPkt))
696 verify_no_packet(self, outPkt, onu_port)
697 verify_packet(self, outPkt, onu_port2)
698
699 # Now remove all ports in the group and test that the input packet is no longer forwarded to any port
700 group_mod = createAllGroupMod(test_group_id, ports=[])
701 self.controller.message_send(group_mod)
702 do_barrier(self.controller)
703 verify_no_errors(self.controller)
704 time.sleep(10)
705 self.dataplane.send(olt_port, str(inPkt))
706 verify_packets(self, outPkt, [])
707
708
Admin02d052c2015-10-10 19:08:26 -0700709class TransparentVlanTest(base_tests.SimpleDataPlane):
Admin02d052c2015-10-10 19:08:26 -0700710 def runTest(self):
711 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700712 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700713
Jonathan Hartf65e1812015-10-05 15:15:37 -0700714 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700715 match = ofp.match()
716 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800717 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700718
719 request = ofp.message.flow_add(
720 table_id=test_param_get("table", 0),
721 cookie=42,
722 match=match,
723 instructions=[
724 ofp.instruction.apply_actions(
725 actions=[
726 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800727 ],
Admin02d052c2015-10-10 19:08:26 -0700728 buffer_id=ofp.OFP_NO_BUFFER,
729 priority=1000)
730
731 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800732
Admin02d052c2015-10-10 19:08:26 -0700733 match = ofp.match()
734 match.oxm_list.append(ofp.oxm.in_port(olt_port))
735 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
736
737 request = ofp.message.flow_add(
738 table_id=test_param_get("table", 0),
739 cookie=43,
740 match=match,
741 instructions=[
742 ofp.instruction.apply_actions(
743 actions=[
744 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800745 ],
Admin02d052c2015-10-10 19:08:26 -0700746 buffer_id=ofp.OFP_NO_BUFFER,
747 priority=1000)
748
749 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700750 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700751 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700752
Admin09b5cc62015-10-11 13:53:59 -0700753 # It takes some time for flows to propagate down to the data plane
754 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800755
Jonathan Hartf65e1812015-10-05 15:15:37 -0700756 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Admin02d052c2015-10-10 19:08:26 -0700757 # upstream
758 self.dataplane.send(onu_port, str(inPkt))
759 verify_packet(self, inPkt, olt_port)
Admin99c2a272016-03-01 12:56:39 -0800760 # downstream
761 self.dataplane.send(olt_port, str(inPkt))
762 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700763
Jonathan Hartf65e1812015-10-05 15:15:37 -0700764 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700765 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700766 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700767 verify_no_errors(self.controller)
768
alshabib28c03c32016-03-01 20:33:51 -0800769class RemoveRuleTest(base_tests.SimpleDataPlane):
770
771 def runTest(self):
772 logging.info("Testing Rule removal")
Admin53395592016-03-01 21:29:21 -0800773 delete_all_flows(self.controller)
alshabib9929a152016-03-01 21:25:18 -0800774 processEapolRule(self, onu_port)
775 #wait for the rule to settle
776 time.sleep(3)
777
778 installDoubleTaggingRule(1, 2, self.controller)
779 #wait for the rules to settle
780 time.sleep(3)
781
782 stats = get_flow_stats(self, ofp.match())
783
Admin53395592016-03-01 21:29:21 -0800784 self.assertTrue(len(stats) == 3, \
alshabib9929a152016-03-01 21:25:18 -0800785 "Wrong number of rules reports; reported %s, expected 3\n\n %s" % (len(stats), stats))
786
787 processEapolRule(self, onu_port, install = False)
788 time.sleep(3)
789
790 stats = get_flow_stats(self, ofp.match())
791
Admin53395592016-03-01 21:29:21 -0800792 self.assertTrue(len(stats) == 2, \
alshabib9929a152016-03-01 21:25:18 -0800793 "Wrong number of rules reports; reported %s, expected 2\n\n %s" % (len(stats), stats))
794
795 logging.info(stats)
alshabib28c03c32016-03-01 20:33:51 -0800796
797
798class MultipleDoubleTaggingForwarding(base_tests.SimpleDataPlane):
799
800 def runTests(self):
801 logging.info("Testing multiple Q-in-Q rules")
802 pass
803
alshabibb9d4ee82016-03-01 14:12:42 -0800804
Adminb17b1662015-10-19 15:50:53 -0700805class DoubleVlanTest(base_tests.SimpleDataPlane):
Adminb17b1662015-10-19 15:50:53 -0700806 def runTest(self):
807 logging.info("Running double vlan tests")
808 delete_all_flows(self.controller)
809
810 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800811 s_vlan_id = 102
812 # upstream flow rule
alshabib28c03c32016-03-01 20:33:51 -0800813 installDoubleTaggingRule(s_vlan_id, c_vlan_id, self.controller)
Adminb17b1662015-10-19 15:50:53 -0700814
Adminb17b1662015-10-19 15:50:53 -0700815 # It takes some time for flows to propagate down to the data plane
816 time.sleep(10)
alshabib28c03c32016-03-01 20:33:51 -0800817 testPacketFlow(self, c_vlan_id, s_vlan_id)
alshabibb9d4ee82016-03-01 14:12:42 -0800818
819 time.sleep(2)
Adminb17b1662015-10-19 15:50:53 -0700820
821 # clean up the test
822 delete_all_flows(self.controller)
823 do_barrier(self.controller)
824 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800825
826
827class TestCyclingDoubleVlan(base_tests.SimpleDataPlane):
828 """Cycle through vlans and test traffic flow"""
829
830 def runTest(self):
831 logging.info("Running cycling vlan test")
832
alshabib2ecca692016-03-01 15:10:38 -0800833 for stag in xrange(2, 4000, 100):
834 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800835 delete_all_flows(self.controller)
836 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800837 installDoubleTaggingRule(stag, ctag, self.controller)
alshabibf1f07dd2016-03-01 15:50:35 -0800838 time.sleep(5)
alshabib28c03c32016-03-01 20:33:51 -0800839 testPacketFlow(self, ctag, stag)
alshabibb9d4ee82016-03-01 14:12:42 -0800840
alshabib9929a152016-03-01 21:25:18 -0800841def processEapolRule(test, in_port, install = True):
842 match = ofp.match()
843 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
844 match.oxm_list.append(ofp.oxm.in_port(in_port))
845 if install:
846 request = ofp.message.flow_add(
847 table_id=test_param_get("table", 0),
848 cookie=42,
alshabibd24fca62016-03-01 21:26:35 -0800849 match=match,
alshabib9929a152016-03-01 21:25:18 -0800850 instructions=[
851 ofp.instruction.apply_actions(
852 actions=[
853 ofp.action.output(
854 port=ofp.OFPP_CONTROLLER,
855 max_len=ofp.OFPCML_NO_BUFFER)])],
856 buffer_id=ofp.OFP_NO_BUFFER,
857 priority=1000)
858 else:
859 request = ofp.message.flow_delete(
860 table_id=test_param_get("table", 0),
861 cookie=42,
862 match=m,
863 instructions=[
864 ofp.instruction.apply_actions(
865 actions=[
866 ofp.action.output(
867 port=ofp.OFPP_CONTROLLER,
868 max_len=ofp.OFPCML_NO_BUFFER)])],
869 buffer_id=ofp.OFP_NO_BUFFER,
870 priority=1000)
871 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
872 test.controller.message_send(request)
873 do_barrier(test.controller)
874
alshabib28c03c32016-03-01 20:33:51 -0800875def testPacketFlow(test, c_vlan_id, s_vlan_id):
alshabibb9b39a72016-03-01 15:52:03 -0800876
alshabib28c03c32016-03-01 20:33:51 -0800877 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=0)
878 untaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800879
alshabib28c03c32016-03-01 20:33:51 -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)
alshabibb9d4ee82016-03-01 14:12:42 -0800884
alshabib28c03c32016-03-01 20:33:51 -0800885 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
alshabibb9d4ee82016-03-01 14:12:42 -0800886
alshabib28c03c32016-03-01 20:33:51 -0800887 test.dataplane.send(onu_port, str(untaggedPkt))
888 verify_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800889
alshabib28c03c32016-03-01 20:33:51 -0800890 # test downstream doubletagged packet got untagged at ONU
891 test.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
892 verify_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800893
alshabib28c03c32016-03-01 20:33:51 -0800894 # test upstream doubletagged packet got dropped
895 test.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
896 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800897
alshabib28c03c32016-03-01 20:33:51 -0800898 # test downstream untagged packet got dropped at ONU
899 test.dataplane.send(olt_port, str(untaggedPkt))
900 verify_no_packet(test, untaggedPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800901
alshabib28c03c32016-03-01 20:33:51 -0800902 # test upstream icorrectly tagged packet; should get dropped
903 test.dataplane.send(onu_port, str(incorrectTagPkt))
904 verify_no_packet(test, upstreamDoubleTaggedPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800905
alshabibb9d4ee82016-03-01 14:12:42 -0800906
alshabib28c03c32016-03-01 20:33:51 -0800907def installDoubleTaggingRule(s_vlan_id, c_vlan_id, controller, cookie = 42):
908 # upstream flow rule
909 match = ofp.match()
910 match.oxm_list.append(ofp.oxm.in_port(onu_port))
911 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
912 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
913 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800914
alshabib28c03c32016-03-01 20:33:51 -0800915 # push inner vlan (c-vlan) for upstream
916 request = ofp.message.flow_add(
917 table_id=test_param_get("table", 0),
Admin965eeda2016-03-01 20:56:14 -0800918 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800919 match=match,
920 instructions=[
921 ofp.instruction.apply_actions(
922 actions=[
923 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))]),
924 ofp.instruction.goto_table(1)],
925 buffer_id=ofp.OFP_NO_BUFFER,
926 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800927
alshabib28c03c32016-03-01 20:33:51 -0800928 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -0800929 do_barrier(controller)
930 verify_no_errors(controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800931
alshabib28c03c32016-03-01 20:33:51 -0800932 # push outer vlan (s-vlan) for upstream
933 match = ofp.match()
934 match.oxm_list.append(ofp.oxm.in_port(onu_port))
935 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
936 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
937 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800938
alshabib28c03c32016-03-01 20:33:51 -0800939 request = ofp.message.flow_add(
940 table_id=test_param_get("table", 1),
Admin965eeda2016-03-01 20:56:14 -0800941 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800942 match=match,
943 instructions=[
944 ofp.instruction.apply_actions(
945 actions=[
946 ofp.action.push_vlan(ethertype=0x8100),
947 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
948 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
949 ofp.action.output(port=olt_port)]),
950 ],
951 buffer_id=ofp.OFP_NO_BUFFER,
952 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800953
alshabib28c03c32016-03-01 20:33:51 -0800954 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -0800955 do_barrier(controller)
956 verify_no_errors(controller)
alshabib28c03c32016-03-01 20:33:51 -0800957 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800958
alshabib28c03c32016-03-01 20:33:51 -0800959 # strip outer vlan (s-vlan) for downstream
960 match = ofp.match()
961 match.oxm_list.append(ofp.oxm.in_port(olt_port))
962 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
963 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
964 request = ofp.message.flow_add(
965 table_id=test_param_get("table", 0),
Admin965eeda2016-03-01 20:56:14 -0800966 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800967 match=match,
968 instructions=[
969 ofp.instruction.apply_actions(
970 actions=[ofp.action.pop_vlan()]),
971 ofp.instruction.goto_table(1)],
972 buffer_id=ofp.OFP_NO_BUFFER,
973 priority=1000)
alshabibb9d4ee82016-03-01 14:12:42 -0800974
alshabib28c03c32016-03-01 20:33:51 -0800975 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -0800976 do_barrier(controller)
977 verify_no_errors(controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800978
alshabib28c03c32016-03-01 20:33:51 -0800979 # rewrite inner vlan (c-vlan) to default (0) for downstream
980 match = ofp.match()
981 match.oxm_list.append(ofp.oxm.in_port(olt_port))
982 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
983 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
984 cookie += 1
alshabibb9d4ee82016-03-01 14:12:42 -0800985
alshabib28c03c32016-03-01 20:33:51 -0800986 request = ofp.message.flow_add(
987 table_id=test_param_get("table", 1),
Admin965eeda2016-03-01 20:56:14 -0800988 cookie=cookie,
alshabib28c03c32016-03-01 20:33:51 -0800989 match=match,
990 instructions=[
991 ofp.instruction.apply_actions(
992 actions=[
993 ofp.action.pop_vlan(),
994 ofp.action.output(port=onu_port)])
995 ],
996 buffer_id=ofp.OFP_NO_BUFFER,
997 priority=1000)
alshabibf1f07dd2016-03-01 15:50:35 -0800998
alshabib28c03c32016-03-01 20:33:51 -0800999 controller.message_send(request)
Admin965eeda2016-03-01 20:56:14 -08001000 do_barrier(controller)
1001 verify_no_errors(controller)
alshabib28c03c32016-03-01 20:33:51 -08001002
1003
1004