blob: 7330177705a60ba21438bbf04b79af0c5972e2a0 [file] [log] [blame]
Jonathan Hartf2511ca2015-07-07 14:18:19 -07001'''
2OFTests for functionality needed from the OLT.
3'''
Zsolt Harasztife525502016-03-02 05:18:52 +00004
Jonathan Hartf2511ca2015-07-07 14:18:19 -07005import logging
alshabibb9d4ee82016-03-01 14:12:42 -08006from __builtin__ import xrange
alshabibd6be76e2016-03-01 22:21:00 -08007from oltbase import OltBaseTest
Jonathan Hartf2511ca2015-07-07 14:18:19 -07008import oftest.packet as scapy
Jonathan Hartf2511ca2015-07-07 14:18:19 -07009import ofp
Admin7e9c91d2015-08-25 15:53:49 -070010import time
Jonathan Hartf2511ca2015-07-07 14:18:19 -070011
12from oftest.testutils import *
13
alshabibed97b5f2016-03-01 23:46:53 -080014from IGMP import IGMPv3, IGMPv3gr, IGMP_TYPE_V3_MEMBERSHIP_REPORT,\
15 IGMP_V3_GR_TYPE_INCLUDE,\
16 IGMP_V3_GR_TYPE_EXCLUDE
Zsolt Harasztife525502016-03-02 05:18:52 +000017
alshabibcde318b2016-03-01 22:49:13 -080018from oltconstants import *
Jonathan Hartf2511ca2015-07-07 14:18:19 -070019
alshabibb9d4ee82016-03-01 14:12:42 -080020
alshabibcde318b2016-03-01 22:49:13 -080021class EapolPacketIn(OltBaseTest):
Jonathan Hartf2511ca2015-07-07 14:18:19 -070022 """Verify packet-ins are sent for EAPOL packets """
alshabibb9d4ee82016-03-01 14:12:42 -080023
Jonathan Hartf2511ca2015-07-07 14:18:19 -070024 def runTest(self):
25 logging.info("Running EAPOL Packet In test")
26
27 match = ofp.match()
28 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
29 # Use ethertype 0x888e and multicast destination MAC address
30 pkt = simple_eth_packet(pktlen=60, eth_dst='01:00:5E:7F:FF:FF', eth_type=0x888e)
alshabibb9d4ee82016-03-01 14:12:42 -080031
alshabibcde318b2016-03-01 22:49:13 -080032 self.testPacketIn(match, pkt)
Jonathan Hartf2511ca2015-07-07 14:18:19 -070033
alshabibb9d4ee82016-03-01 14:12:42 -080034
alshabibcde318b2016-03-01 22:49:13 -080035class ARPPacketIn(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +000036 """Verify packet-ins are sent for ARP packets """
alshabib9929a152016-03-01 21:25:18 -080037
Zsolt Harasztife525502016-03-02 05:18:52 +000038 def runTest(self):
39 logging.info("Running ARP Packet In test")
alshabib9929a152016-03-01 21:25:18 -080040
Zsolt Harasztife525502016-03-02 05:18:52 +000041 match = ofp.match()
42 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
43
44 # Use ethertype 0x0806
45 pkt = simple_eth_packet(eth_type=0x0806)
46
alshabibcde318b2016-03-01 22:49:13 -080047 self.testPacketIn(match, pkt)
alshabib9929a152016-03-01 21:25:18 -080048
49
alshabibcde318b2016-03-01 22:49:13 -080050class IGMPPacketIn(OltBaseTest):
Jonathan Hartf2511ca2015-07-07 14:18:19 -070051 """Verify packet-ins are sent for IGMP packets """
alshabibb9d4ee82016-03-01 14:12:42 -080052
Jonathan Hartf2511ca2015-07-07 14:18:19 -070053 def runTest(self):
54 logging.info("Running IGMP Packet In test")
55
56 match = ofp.match()
57 match.oxm_list.append(ofp.oxm.eth_type(0x800))
58 match.oxm_list.append(ofp.oxm.ip_proto(2))
Jonathan Hartf2511ca2015-07-07 14:18:19 -070059
Zsolt Harasztid0571402016-03-02 18:40:50 -080060 mcast_group = "229.10.20.30"
61 ip_src = '192.168.0.123'
62 ip_dst = '224.0.0.22'
63 pkt = self.buildIgmpReport(ip_src, ip_dst, '00:00:00:00:be:ef', join=[mcast_group], pad_to=60)
alshabibb9d4ee82016-03-01 14:12:42 -080064
alshabibcde318b2016-03-01 22:49:13 -080065 self.testPacketIn(match, pkt)
Admin7e9c91d2015-08-25 15:53:49 -070066
alshabibb9d4ee82016-03-01 14:12:42 -080067
alshabibcde318b2016-03-01 22:49:13 -080068class IGMPQueryPacketOut(OltBaseTest):
Admind5212782015-12-09 17:17:57 -080069 """Verify sending multicast membership queries down to onu_ports"""
alshabibb9d4ee82016-03-01 14:12:42 -080070
Admind5212782015-12-09 17:17:57 -080071 def runTest(self):
72 logging.info("Running IGMP query packet out")
73
Zsolt Harasztife525502016-03-02 05:18:52 +000074 igmp = IGMPv3() # by default this is a query
Zsolt Harasztid0571402016-03-02 18:40:50 -080075 pkt = self.buildIgmp(igmp)
Admind5212782015-12-09 17:17:57 -080076
Zsolt Harasztife525502016-03-02 05:18:52 +000077 msg = ofp.message.packet_out(
78 in_port=ofp.OFPP_CONTROLLER,
79 actions=[ofp.action.output(port=onu_port)],
80 buffer_id=ofp.OFP_NO_BUFFER,
81 data=str(pkt))
Admind5212782015-12-09 17:17:57 -080082
alshabibb9d4ee82016-03-01 14:12:42 -080083 self.controller.message_send(msg)
Admind5212782015-12-09 17:17:57 -080084
Zsolt Harasztife525502016-03-02 05:18:52 +000085 rv = self.controller.message_send(msg)
86 self.assertTrue(rv == 0, "Error sending put message")
Admind5212782015-12-09 17:17:57 -080087 verify_no_errors(self.controller)
88
89 verify_packet(self, pkt, onu_port)
90
alshabibb9d4ee82016-03-01 14:12:42 -080091
alshabibcde318b2016-03-01 22:49:13 -080092class TestMeter(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +000093
Admin7e9c91d2015-08-25 15:53:49 -070094 def runTest(self):
95 logging.info("Running Meter tests")
alshabibb9d4ee82016-03-01 14:12:42 -080096 dropMeterBand = ofp.meter_band.drop(rate=640)
97 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -070098 self.controller.message_send(meter_mod)
alshabibb9d4ee82016-03-01 14:12:42 -080099
Admin7e9c91d2015-08-25 15:53:49 -0700100 time.sleep(1)
101
102 verify_no_errors(self.controller)
103
Jonathan Hartf65e1812015-10-05 15:15:37 -0700104 vlan_id = 201
Admin7e9c91d2015-08-25 15:53:49 -0700105 match = ofp.match()
106 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800107 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700108
109 request = ofp.message.flow_add(
110 table_id=test_param_get("table", 0),
111 cookie=42,
112 match=match,
113 instructions=[
114 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000115 actions=[ofp.action.output(port=olt_port)]),
116 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800117 ],
Admin02d052c2015-10-10 19:08:26 -0700118 buffer_id=ofp.OFP_NO_BUFFER,
119 priority=1000)
120
121 self.controller.message_send(request)
122 time.sleep(1)
123 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800124
Admin02d052c2015-10-10 19:08:26 -0700125 match = ofp.match()
126 match.oxm_list.append(ofp.oxm.in_port(olt_port))
127 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin7e9c91d2015-08-25 15:53:49 -0700128
129 request = ofp.message.flow_add(
130 table_id=test_param_get("table", 0),
131 cookie=43,
132 match=match,
133 instructions=[
134 ofp.instruction.apply_actions(
Zsolt Harasztife525502016-03-02 05:18:52 +0000135 actions=[ofp.action.output(port=onu_port)]),
136 ofp.instruction.meter(meter_id = 1)
alshabibb9d4ee82016-03-01 14:12:42 -0800137 ],
Admin7e9c91d2015-08-25 15:53:49 -0700138 buffer_id=ofp.OFP_NO_BUFFER,
139 priority=1000)
140
141 self.controller.message_send(request)
Admin7e9c91d2015-08-25 15:53:49 -0700142 time.sleep(1)
Admin7e9c91d2015-08-25 15:53:49 -0700143 verify_no_errors(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700144 do_barrier(self.controller)
145 time.sleep(5)
alshabibb9d4ee82016-03-01 14:12:42 -0800146
Jonathan Hartf65e1812015-10-05 15:15:37 -0700147 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
148 # downstream
alshabibb9d4ee82016-03-01 14:12:42 -0800149 # self.dataplane.send(olt_port, str(inPkt))
150 # verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700151 # upstream
alshabibb9d4ee82016-03-01 14:12:42 -0800152 # for i in range(1,400):
153 # self.dataplane.send(onu_port, str(inPkt))
154 # verify_packet(self, inPkt, olt_port)
Admin02d052c2015-10-10 19:08:26 -0700155
Jonathan Hartf65e1812015-10-05 15:15:37 -0700156 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800157 meter_mod = ofp.message.meter_mod(xid=2, command=ofp.OFPMC_DELETE, meter_id=1)
Admin02d052c2015-10-10 19:08:26 -0700158 self.controller.message_send(meter_mod)
159 time.sleep(1)
160 delete_all_flows(self.controller)
161 verify_no_errors(self.controller)
162
Admin7e9c91d2015-08-25 15:53:49 -0700163
alshabibcde318b2016-03-01 22:49:13 -0800164class TestDuplicateMeter(OltBaseTest):
Admin7e9c91d2015-08-25 15:53:49 -0700165 def runTest(self):
166 logging.info("Running Duplicate Meter Test")
alshabibb9d4ee82016-03-01 14:12:42 -0800167 dropMeterBand = ofp.meter_band.drop(rate=500)
168 meter_mod = ofp.message.meter_mod(xid=1, command=ofp.OFPMC_ADD, meter_id=1, meters=[dropMeterBand])
Admin7e9c91d2015-08-25 15:53:49 -0700169 self.controller.message_send(meter_mod)
170 self.controller.message_send(meter_mod)
171
172 time.sleep(1)
alshabibb9d4ee82016-03-01 14:12:42 -0800173
Admin7e9c91d2015-08-25 15:53:49 -0700174 try:
175 verify_no_errors(self.controller)
176 except AssertionError as e:
Admin09b5cc62015-10-11 13:53:59 -0700177 if (not e.message == "unexpected error type=12 code=1"):
Admin7e9c91d2015-08-25 15:53:49 -0700178 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800179
180
alshabibcde318b2016-03-01 22:49:13 -0800181class VlanTest(OltBaseTest):
Admin7e9c91d2015-08-25 15:53:49 -0700182 """Verify the switch can push/pop a VLAN tag and forward out a port """
alshabibb9d4ee82016-03-01 14:12:42 -0800183
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700184 def runTest(self):
185 logging.info("Running push VLAN test")
alshabibb9d4ee82016-03-01 14:12:42 -0800186
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700187 vlan_id = 200
alshabibb9d4ee82016-03-01 14:12:42 -0800188
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700189 delete_all_flows(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800190
191 # PUSH
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700192 match = ofp.match()
193 match.oxm_list.append(ofp.oxm.in_port(onu_port))
Zsolt Harasztife525502016-03-02 05:18:52 +0000194 if device_type == "cpqd":
195 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
196 actions = [
197 ofp.action.push_vlan(ethertype=0x8100),
198 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
199 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
200 ofp.action.output(port=olt_port)
201 ]
202 else: # pmc, normal
203 match.oxm_list.append(ofp.oxm.vlan_vid_masked(value=ofp.OFPVID_PRESENT, value_mask=ofp.OFPVID_PRESENT))
204 match.oxm_list.append(ofp.oxm.vlan_pcp(value = 0))
205 actions = [
206 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id)),
207 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
208 ofp.action.output(port=olt_port)
209 ]
alshabibb9d4ee82016-03-01 14:12:42 -0800210
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700211 request = ofp.message.flow_add(
212 table_id=test_param_get("table", 0),
213 cookie=42,
214 match=match,
Zsolt Harasztife525502016-03-02 05:18:52 +0000215 instructions=[ofp.instruction.apply_actions(actions=actions)],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700216 buffer_id=ofp.OFP_NO_BUFFER,
217 priority=1000)
218
Admin7e9c91d2015-08-25 15:53:49 -0700219 logging.info("Inserting flow tagging upstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700220 self.controller.message_send(request)
Zsolt Harasztife525502016-03-02 05:18:52 +0000221 do_barrier(self.controller)
222 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800223
224 # POP
Jonathan Hartf2511ca2015-07-07 14:18:19 -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
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700229 request = ofp.message.flow_add(
230 table_id=test_param_get("table", 0),
Admin7e9c91d2015-08-25 15:53:49 -0700231 cookie=43,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700232 match=match,
233 instructions=[
234 ofp.instruction.apply_actions(
Jonathan Hartf65e1812015-10-05 15:15:37 -0700235 actions=[
236 ofp.action.pop_vlan(),
alshabibb9d4ee82016-03-01 14:12:42 -0800237 ofp.action.output(port=onu_port)])],
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700238 buffer_id=ofp.OFP_NO_BUFFER,
239 priority=1000)
240
Admin7e9c91d2015-08-25 15:53:49 -0700241 logging.info("Inserting flow tagging downstream")
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700242 self.controller.message_send(request)
243 do_barrier(self.controller)
Zsolt Harasztife525502016-03-02 05:18:52 +0000244 verify_no_errors(self.controller)
245
Admin7e9c91d2015-08-25 15:53:49 -0700246 time.sleep(5)
Admin99c2a272016-03-01 12:56:39 -0800247
Admin7e9c91d2015-08-25 15:53:49 -0700248 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800249 outPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
Admin7e9c91d2015-08-25 15:53:49 -0700250 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
alshabibb9d4ee82016-03-01 14:12:42 -0800251
Admin7e9c91d2015-08-25 15:53:49 -0700252 # Send untagged packet in the ONU port and expect tagged packet out the OLT port
253 self.dataplane.send(onu_port, str(inPkt))
254 verify_packet(self, outPkt, olt_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800255
Admin7e9c91d2015-08-25 15:53:49 -0700256 # Send untagged packet in the OLT port and expect no packets to come out
257 self.dataplane.send(olt_port, str(inPkt))
258 verify_packets(self, outPkt, [])
alshabibb9d4ee82016-03-01 14:12:42 -0800259
Admin7e9c91d2015-08-25 15:53:49 -0700260 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700261 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000262 if device_type == 'pmc':
263 outPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
264 else: # "normal", "cpqd""
265 outPkt = simple_udp_packet(pktlen=100)
Admin7e9c91d2015-08-25 15:53:49 -0700266
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700267 # Send tagged packet in the OLT port and expect untagged packet out the OLT port
268 self.dataplane.send(olt_port, str(inPkt))
269 verify_packet(self, outPkt, onu_port)
Admin7e9c91d2015-08-25 15:53:49 -0700270
Jonathan Hartf2511ca2015-07-07 14:18:19 -0700271 # Send tagged packet in the ONU port and expect no packets to come out
272 self.dataplane.send(onu_port, str(inPkt))
Admin7e9c91d2015-08-25 15:53:49 -0700273 verify_packets(self, outPkt, [])
Jonathan Hartf65e1812015-10-05 15:15:37 -0700274
alshabibb9d4ee82016-03-01 14:12:42 -0800275
alshabibcde318b2016-03-01 22:49:13 -0800276class TestGroupAdd(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000277
Admin02d052c2015-10-10 19:08:26 -0700278 def runTest(self):
279 logging.info("Running Group tests")
280 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700281 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700282
alshabibb9d4ee82016-03-01 14:12:42 -0800283 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700284
285 # output to two ONU
286 group_add = createAllGroupAdd(test_group_id, ports=[onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700287
288 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700289 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700290 verify_no_errors(self.controller)
291
292 # Remove the group and then readd it.
alshabibb9d4ee82016-03-01 14:12:42 -0800293 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700294 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700295 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700296 verify_no_errors(self.controller)
297
Jonathan Hartf65e1812015-10-05 15:15:37 -0700298 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700299 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700300 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700301 verify_no_errors(self.controller)
302
303
Jonathan Hartf65e1812015-10-05 15:15:37 -0700304 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800305 group_delete = ofp.message.group_delete(group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700306 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800307
Jonathan Hartf65e1812015-10-05 15:15:37 -0700308 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700309 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800310
311
alshabibcde318b2016-03-01 22:49:13 -0800312class TestGroupMod(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000313
Admin02d052c2015-10-10 19:08:26 -0700314 def runTest(self):
315 logging.info("Running Group tests")
316 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700317 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700318
alshabibb9d4ee82016-03-01 14:12:42 -0800319 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700320
321 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700322
323 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700324 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700325 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800326
Jonathan Hartf65e1812015-10-05 15:15:37 -0700327 # Modifying the group
328 group_mod = createAllGroupMod(test_group_id, [onu_port2])
alshabibb9d4ee82016-03-01 14:12:42 -0800329
Jonathan Hartf65e1812015-10-05 15:15:37 -0700330 self.controller.message_send(group_mod)
331 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700332 verify_no_errors(self.controller)
333
Jonathan Hartf65e1812015-10-05 15:15:37 -0700334 # Add a bucket into the group
335 group_mod = createAllGroupMod(test_group_id, [onu_port, onu_port2])
336 self.controller.message_send(group_mod)
337 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700338 verify_no_errors(self.controller)
339
340 # Modifying a non-existing group
Jonathan Hartf65e1812015-10-05 15:15:37 -0700341 group_mod = createAllGroupMod(777, [onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700342
Jonathan Hartf65e1812015-10-05 15:15:37 -0700343 self.controller.message_send(group_mod)
344 do_barrier(self.controller)
345 errorExperienced = 0
Admin02d052c2015-10-10 19:08:26 -0700346 try:
347 verify_no_errors(self.controller)
348 except AssertionError as e:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700349 errorExperienced = 1
Admin02d052c2015-10-10 19:08:26 -0700350 if (not (e.message == "unexpected error type=6 code=8")):
Jonathan Hartf65e1812015-10-05 15:15:37 -0700351 raise AssertionError("Incorrect error type: %s" % e.message)
alshabibb9d4ee82016-03-01 14:12:42 -0800352 if not errorExperienced:
Jonathan Hartf65e1812015-10-05 15:15:37 -0700353 raise AssertionError("An error message is expected, but not shown.")
alshabibb9d4ee82016-03-01 14:12:42 -0800354
355
Jonathan Hartf65e1812015-10-05 15:15:37 -0700356 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800357 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700358 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800359
Jonathan Hartf65e1812015-10-05 15:15:37 -0700360 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700361 verify_no_errors(self.controller)
362
alshabibb9d4ee82016-03-01 14:12:42 -0800363
alshabibcde318b2016-03-01 22:49:13 -0800364class TestDuplicateGroup(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000365
Admin02d052c2015-10-10 19:08:26 -0700366 def runTest(self):
367 logging.info("Running Group tests")
368 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700369 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700370
alshabibb9d4ee82016-03-01 14:12:42 -0800371 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700372 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700373
374 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700375 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700376 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800377
Jonathan Hartf65e1812015-10-05 15:15:37 -0700378 # Add the same group id
alshabibb9d4ee82016-03-01 14:12:42 -0800379 duplicate_group_fail = 0
380
Admin02d052c2015-10-10 19:08:26 -0700381 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700382 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700383 try:
384 verify_no_errors(self.controller)
385 except AssertionError as e:
alshabibb9d4ee82016-03-01 14:12:42 -0800386 duplicate_group_fail = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700387 if (not e.message == "unexpected error type=6 code=0"):
388 raise AssertionError("Incorrect error type: %s" % e.message)
389 if not duplicate_group_fail:
390 raise AssertionError("Adding duplicate groups didn't raise an error.")
alshabibb9d4ee82016-03-01 14:12:42 -0800391
Jonathan Hartf65e1812015-10-05 15:15:37 -0700392 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800393 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700394 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800395
Jonathan Hartf65e1812015-10-05 15:15:37 -0700396 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700397 verify_no_errors(self.controller)
398
alshabibb9d4ee82016-03-01 14:12:42 -0800399
alshabibcde318b2016-03-01 22:49:13 -0800400class TestGroupAndFlow(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000401
Admin02d052c2015-10-10 19:08:26 -0700402 def runTest(self):
403 logging.info("Running Group tests")
404 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700405 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700406
Jonathan Hartf65e1812015-10-05 15:15:37 -0700407 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800408 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700409 group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700410
411 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700412 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700413 verify_no_errors(self.controller)
414
415 # Create a flow rule matching olt port and vlan id
416 match = ofp.match()
417 match.oxm_list.append(ofp.oxm.in_port(olt_port))
418 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | 201))
419
Jonathan Hartf65e1812015-10-05 15:15:37 -0700420 flow_pointing_to_group = ofp.message.flow_add(
Admin02d052c2015-10-10 19:08:26 -0700421 table_id=test_param_get("table", 0),
422 cookie=43,
423 match=match,
424 instructions=[
425 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800426 actions=[ofp.action.group(group_id=test_group_id)])],
427 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700428
Jonathan Hartf65e1812015-10-05 15:15:37 -0700429 self.controller.message_send(flow_pointing_to_group)
430 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700431 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800432
Jonathan Hartf65e1812015-10-05 15:15:37 -0700433 # After letting a flow rule point to the group, test we can do group_mod
434 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
435 self.controller.message_send(group_mod)
436 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700437 verify_no_errors(self.controller)
438
439 # Test we can remove flows and then remove group
alshabibb9d4ee82016-03-01 14:12:42 -0800440 flow_delete = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700441 self.controller.message_send(flow_delete)
442 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700443 verify_no_errors(self.controller)
444
alshabibb9d4ee82016-03-01 14:12:42 -0800445 group_delete = ofp.message.group_delete(xid=3, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700446 self.controller.message_send(group_delete)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700447 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700448 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800449
Zsolt Harasztife525502016-03-02 05:18:52 +0000450 # Add the group and flow back, test it we can first remove group and then remove the flow.
Admindcb1bc72015-11-12 18:24:56 -0800451 '''group_add = createAllGroupAdd(test_group_id, ports=[onu_port])
Admin02d052c2015-10-10 19:08:26 -0700452 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700453
454 self.controller.message_send(flow_pointing_to_group)
455 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700456 verify_no_errors(self.controller)
457
458 group_delete = ofp.message.group_delete(xid = 4, group_id = test_group_id)
Admindcb1bc72015-11-12 18:24:56 -0800459 self.controller.message_send(group_delete)'''
Jonathan Hartf65e1812015-10-05 15:15:37 -0700460
461 self.controller.message_send(flow_delete)
462 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700463 verify_no_errors(self.controller)
464
465
alshabibcde318b2016-03-01 22:49:13 -0800466class TestGroupForwarding(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000467
Admin02d052c2015-10-10 19:08:26 -0700468 def runTest(self):
469 logging.info("Running Group datapath forwarding tests")
470 delete_all_flows(self.controller)
Admin99c2a272016-03-01 12:56:39 -0800471 delete_all_groups(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700472
Admin09b5cc62015-10-11 13:53:59 -0700473 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700474
Jonathan Hartf65e1812015-10-05 15:15:37 -0700475 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800476 test_group_id = 1
Jonathan Hartf65e1812015-10-05 15:15:37 -0700477 group_add = createAllGroupAdd(test_group_id, [onu_port])
Admin02d052c2015-10-10 19:08:26 -0700478
479 self.controller.message_send(group_add)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700480 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700481 verify_no_errors(self.controller)
482
483 # Create a flow rule matching olt port and vlan id
484 match = ofp.match()
485 match.oxm_list.append(ofp.oxm.in_port(olt_port))
486 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
487
488 request = ofp.message.flow_add(
489 table_id=test_param_get("table", 0),
490 cookie=43,
491 match=match,
492 instructions=[
493 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800494 actions=[ofp.action.group(group_id=test_group_id)]),
495 ],
496 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admin02d052c2015-10-10 19:08:26 -0700497
498 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700499 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700500 verify_no_errors(self.controller)
Admin09b5cc62015-10-11 13:53:59 -0700501
502 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800503 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800504
505 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800506 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 -0700507 outPkt = inPkt
508 self.dataplane.send(olt_port, str(inPkt))
509 verify_packet(self, outPkt, onu_port)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700510
Admindcb1bc72015-11-12 18:24:56 -0800511
Zsolt Harasztife525502016-03-02 05:18:52 +0000512 # Now put 2 ONU ports in the group and test that the input packet is
Jonathan Hartf65e1812015-10-05 15:15:37 -0700513 # duplicated out both ports
514 group_mod = createAllGroupMod(test_group_id, ports=[onu_port, onu_port2])
515 self.controller.message_send(group_mod)
516 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700517 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800518
Admin09b5cc62015-10-11 13:53:59 -0700519 # It takes some time for flows to propagate down to the data plane
Admindcb1bc72015-11-12 18:24:56 -0800520 time.sleep(10)
Admin09b5cc62015-10-11 13:53:59 -0700521
Jonathan Hartf65e1812015-10-05 15:15:37 -0700522 self.dataplane.send(olt_port, str(inPkt))
Jonathan Hartf65e1812015-10-05 15:15:37 -0700523 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800524 verify_packet(self, outPkt, onu_port)
alshabibb9d4ee82016-03-01 14:12:42 -0800525 # verify_packets(self, outPkt, [onu_port,onu_port2])
Admin02d052c2015-10-10 19:08:26 -0700526
Jonathan Hartf65e1812015-10-05 15:15:37 -0700527 # clean up the test
alshabibb9d4ee82016-03-01 14:12:42 -0800528 request = ofp.message.flow_delete(table_id=test_param_get("table", 0))
Admin02d052c2015-10-10 19:08:26 -0700529 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800530 group_delete = ofp.message.group_delete(xid=2, group_id=test_group_id)
Admin02d052c2015-10-10 19:08:26 -0700531 self.controller.message_send(group_delete)
alshabibb9d4ee82016-03-01 14:12:42 -0800532
Jonathan Hartf65e1812015-10-05 15:15:37 -0700533 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700534 verify_no_errors(self.controller)
535
Admindcb1bc72015-11-12 18:24:56 -0800536
alshabibcde318b2016-03-01 22:49:13 -0800537class TestGroupModForwarding(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000538
Admindcb1bc72015-11-12 18:24:56 -0800539 def runTest(self):
alshabibb9d4ee82016-03-01 14:12:42 -0800540 logging.info("Running datapath forwarding tests for group mod")
Admindcb1bc72015-11-12 18:24:56 -0800541 delete_all_flows(self.controller)
542 delete_all_groups(self.controller)
543
544 vlan_id = 201
545
546 # Create a group
alshabibb9d4ee82016-03-01 14:12:42 -0800547 test_group_id = 1
Admindcb1bc72015-11-12 18:24:56 -0800548 group_add = createAllGroupAdd(test_group_id, [onu_port, onu_port2])
549
550 self.controller.message_send(group_add)
551 do_barrier(self.controller)
552 verify_no_errors(self.controller)
553
554 # Create a flow rule matching olt port and vlan id
555 match = ofp.match()
556 match.oxm_list.append(ofp.oxm.in_port(olt_port))
557 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
558
559 request = ofp.message.flow_add(
560 table_id=test_param_get("table", 0),
561 cookie=43,
562 match=match,
563 instructions=[
564 ofp.instruction.apply_actions(
alshabibb9d4ee82016-03-01 14:12:42 -0800565 actions=[ofp.action.group(group_id=test_group_id)]),
566 ],
567 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
Admindcb1bc72015-11-12 18:24:56 -0800568
569 self.controller.message_send(request)
570 do_barrier(self.controller)
571 verify_no_errors(self.controller)
572
573 # It takes some time for flows to propagate down to the data plane
574 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800575
576 inPkt = simple_udp_packet(pktlen=104, dl_vlan_enable=True,
Admindcb1bc72015-11-12 18:24:56 -0800577 vlan_vid=vlan_id, vlan_pcp=0, dl_vlan_cfi=0, eth_dst="01:01:11:12:11:12")
578 outPkt = inPkt
579 self.dataplane.send(olt_port, str(inPkt))
580 verify_packet(self, outPkt, onu_port)
Admin99c2a272016-03-01 12:56:39 -0800581 verify_packet(self, outPkt, onu_port2)
Admindcb1bc72015-11-12 18:24:56 -0800582
583 # Now remove onu port 1 from the group and test that the input packet is no longer forwarded to onu port 1
584 group_mod = createAllGroupMod(test_group_id, ports=[onu_port2])
585 self.controller.message_send(group_mod)
586 do_barrier(self.controller)
587 verify_no_errors(self.controller)
588
589 time.sleep(10)
590 self.dataplane.send(olt_port, str(inPkt))
591 verify_no_packet(self, outPkt, onu_port)
592 verify_packet(self, outPkt, onu_port2)
593
Zsolt Harasztife525502016-03-02 05:18:52 +0000594 # Now remove all ports in the group and test that the input packet is no longer forwarded to any port
Admindcb1bc72015-11-12 18:24:56 -0800595 group_mod = createAllGroupMod(test_group_id, ports=[])
596 self.controller.message_send(group_mod)
597 do_barrier(self.controller)
598 verify_no_errors(self.controller)
599 time.sleep(10)
600 self.dataplane.send(olt_port, str(inPkt))
601 verify_packets(self, outPkt, [])
602
603
alshabibcde318b2016-03-01 22:49:13 -0800604class TransparentVlanTest(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000605
Admin02d052c2015-10-10 19:08:26 -0700606 def runTest(self):
607 logging.info("Running transparent vlan tests")
Admin09b5cc62015-10-11 13:53:59 -0700608 delete_all_flows(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700609
Jonathan Hartf65e1812015-10-05 15:15:37 -0700610 vlan_id = 201
Admin02d052c2015-10-10 19:08:26 -0700611 match = ofp.match()
612 match.oxm_list.append(ofp.oxm.in_port(onu_port))
alshabibb9d4ee82016-03-01 14:12:42 -0800613 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
Admin02d052c2015-10-10 19:08:26 -0700614
615 request = ofp.message.flow_add(
616 table_id=test_param_get("table", 0),
617 cookie=42,
618 match=match,
619 instructions=[
620 ofp.instruction.apply_actions(
621 actions=[
622 ofp.action.output(port=olt_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800623 ],
Admin02d052c2015-10-10 19:08:26 -0700624 buffer_id=ofp.OFP_NO_BUFFER,
625 priority=1000)
626
627 self.controller.message_send(request)
alshabibb9d4ee82016-03-01 14:12:42 -0800628
Admin02d052c2015-10-10 19:08:26 -0700629 match = ofp.match()
630 match.oxm_list.append(ofp.oxm.in_port(olt_port))
631 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
632
633 request = ofp.message.flow_add(
634 table_id=test_param_get("table", 0),
635 cookie=43,
636 match=match,
637 instructions=[
638 ofp.instruction.apply_actions(
639 actions=[
640 ofp.action.output(port=onu_port)]),
alshabibb9d4ee82016-03-01 14:12:42 -0800641 ],
Admin02d052c2015-10-10 19:08:26 -0700642 buffer_id=ofp.OFP_NO_BUFFER,
643 priority=1000)
644
645 self.controller.message_send(request)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700646 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700647 verify_no_errors(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700648
Admin09b5cc62015-10-11 13:53:59 -0700649 # It takes some time for flows to propagate down to the data plane
650 time.sleep(2)
alshabibb9d4ee82016-03-01 14:12:42 -0800651
Jonathan Hartf65e1812015-10-05 15:15:37 -0700652 inPkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0)
Zsolt Harasztife525502016-03-02 05:18:52 +0000653
Admin02d052c2015-10-10 19:08:26 -0700654 # upstream
655 self.dataplane.send(onu_port, str(inPkt))
656 verify_packet(self, inPkt, olt_port)
Zsolt Harasztife525502016-03-02 05:18:52 +0000657
Admin99c2a272016-03-01 12:56:39 -0800658 # downstream
659 self.dataplane.send(olt_port, str(inPkt))
660 verify_packet(self, inPkt, onu_port)
Admin02d052c2015-10-10 19:08:26 -0700661
Jonathan Hartf65e1812015-10-05 15:15:37 -0700662 # clean up the test
Admin02d052c2015-10-10 19:08:26 -0700663 delete_all_flows(self.controller)
Jonathan Hartf65e1812015-10-05 15:15:37 -0700664 do_barrier(self.controller)
Admin02d052c2015-10-10 19:08:26 -0700665 verify_no_errors(self.controller)
666
alshabibed97b5f2016-03-01 23:46:53 -0800667class TestMulticastForwarding(IGMPPacketIn):
668
669 def runTest(self):
670 delete_all_groups(self.controller)
671 # send igmp join packet
672 super(TestMulticastForwarding, self).runTest()
673
674 vlan_id = 201
675
alshabibc49e69c2016-03-01 23:49:25 -0800676 group = createAllGroupAdd(1, [onu_port])
alshabibed97b5f2016-03-01 23:46:53 -0800677
alshabib23f0e372016-03-01 23:50:37 -0800678 self.controller.message_send(group)
alshabibed97b5f2016-03-01 23:46:53 -0800679 do_barrier(self.controller)
680 verify_no_errors(self.controller)
681
682 # Create a flow rule matching olt port and vlan id
683 match = ofp.match()
684 match.oxm_list.append(ofp.oxm.in_port(olt_port))
685 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | vlan_id))
686
687 request = ofp.message.flow_add(
688 table_id=test_param_get("table", 0),
689 cookie=43,
690 match=match,
691 instructions=[
692 ofp.instruction.apply_actions(
693 actions=[ofp.action.group(group_id=1)]),
694 ],
695 buffer_id=ofp.OFP_NO_BUFFER, priority=1000)
696
697 self.controller.message_send(request)
698 do_barrier(self.controller)
699 verify_no_errors(self.controller)
700
701 # It takes some time for flows to propagate down to the data plane
702 time.sleep(5)
703
704 pkt = simple_udp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, vlan_pcp=0, \
Admin99a3ed92016-03-02 17:22:50 -0800705 eth_dst = "01:00:5e:0a:14:1e", ip_dst = "229.10.20.30")
alshabibed97b5f2016-03-01 23:46:53 -0800706
707 # downstream
708 self.dataplane.send(olt_port, str(pkt))
709 verify_packet(self, pkt, onu_port)
710
711 # clean up the test
712 delete_all_flows(self.controller)
713 do_barrier(self.controller)
714 verify_no_errors(self.controller)
715 delete_all_groups(self.controller)
716
717
alshabibcde318b2016-03-01 22:49:13 -0800718class RemoveRuleTest(OltBaseTest):
alshabib28c03c32016-03-01 20:33:51 -0800719
720 def runTest(self):
721 logging.info("Testing Rule removal")
alshabibe165af22016-03-01 21:42:17 -0800722 delete_all_flows(self.controller)
Zsolt Haraszti5b8b39c2016-03-02 22:25:51 -0800723 self.installEapolRule(onu_port)
alshabibe165af22016-03-01 21:42:17 -0800724
alshabib9929a152016-03-01 21:25:18 -0800725 #wait for the rule to settle
726 time.sleep(3)
727
Admin44f754e2016-03-01 23:00:46 -0800728 self.installDoubleTaggingRules(1, 2)
alshabibe165af22016-03-01 21:42:17 -0800729
alshabib9929a152016-03-01 21:25:18 -0800730 #wait for the rules to settle
731 time.sleep(3)
732
733 stats = get_flow_stats(self, ofp.match())
734
Admin53e10b62016-03-01 21:52:18 -0800735 self.assertTrue(len(stats) == 5, \
736 "Wrong number of rules reports; reported %s, expected 5\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800737
Zsolt Haraszti5b8b39c2016-03-02 22:25:51 -0800738 self.installEapolRule(onu_port, install=False)
alshabib9929a152016-03-01 21:25:18 -0800739 time.sleep(3)
740
741 stats = get_flow_stats(self, ofp.match())
742
Admin53e10b62016-03-01 21:52:18 -0800743 self.assertTrue(len(stats) == 4, \
744 "Wrong number of rules reports; reported %s, expected 4\n\n %s" % (len(stats), stats))
alshabib9929a152016-03-01 21:25:18 -0800745
alshabibd6be76e2016-03-01 22:21:00 -0800746 eapol = ofp.oxm.eth_type(0x888e)
747 found = False
748 for fe in stats:
749 if eapol in fe.match.oxm_list:
750 found = True
751
752 self.assertFalse(found, "Removed incorrect flow rule")
alshabib28c03c32016-03-01 20:33:51 -0800753
754
alshabibb5a09bc2016-03-02 13:26:43 -0800755class MultipleDoubleTaggingForwarding(OltBaseTest):
alshabib28c03c32016-03-01 20:33:51 -0800756
alshabib5d53c482016-03-01 23:25:39 -0800757 def runTest(self):
alshabib28c03c32016-03-01 20:33:51 -0800758 logging.info("Testing multiple Q-in-Q rules")
Adminb3bae672016-03-02 13:00:08 -0800759 delete_all_flows(self.controller)
alshabib3f3da0e2016-03-01 23:23:45 -0800760
Zsolt Haraszti5b8b39c2016-03-02 22:25:51 -0800761 self.installEapolRule(onu_port)
alshabib57a536a2016-03-02 13:21:28 -0800762
763 time.sleep(1)
764
Zsolt Harasztid0571402016-03-02 18:40:50 -0800765 self.installDoubleTaggingRules(10, 5, cookie=42, onu=onu_port)
alshabib3f3da0e2016-03-01 23:23:45 -0800766
Adminb3bae672016-03-02 13:00:08 -0800767 time.sleep(1)
alshabib3f3da0e2016-03-01 23:23:45 -0800768
Zsolt Harasztid0571402016-03-02 18:40:50 -0800769 self.installDoubleTaggingRules(10, 30, cookie=50, onu=onu_port2)
alshabib3f3da0e2016-03-01 23:23:45 -0800770
Adminb3bae672016-03-02 13:00:08 -0800771 time.sleep(1)
alshabib3f3da0e2016-03-01 23:23:45 -0800772
773 self.testPacketFlow(10, 5, onu=onu_port)
Adminb3bae672016-03-02 13:00:08 -0800774 self.testPacketFlow(10, 30, onu=onu_port2)
alshabib3f3da0e2016-03-01 23:23:45 -0800775
Adminb3bae672016-03-02 13:00:08 -0800776 delete_all_flows(self.controller)
alshabib28c03c32016-03-01 20:33:51 -0800777
alshabibb9d4ee82016-03-01 14:12:42 -0800778
alshabibd6be76e2016-03-01 22:21:00 -0800779class DoubleVlanTest(OltBaseTest):
Zsolt Harasztife525502016-03-02 05:18:52 +0000780
Adminb17b1662015-10-19 15:50:53 -0700781 def runTest(self):
782 logging.info("Running double vlan tests")
783 delete_all_flows(self.controller)
784
785 c_vlan_id = 100
alshabibb9d4ee82016-03-01 14:12:42 -0800786 s_vlan_id = 102
Zsolt Harasztife525502016-03-02 05:18:52 +0000787
alshabibd6be76e2016-03-01 22:21:00 -0800788 self.installDoubleTaggingRules(s_vlan_id, c_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700789
Adminb17b1662015-10-19 15:50:53 -0700790 # It takes some time for flows to propagate down to the data plane
791 time.sleep(10)
alshabibb9d4ee82016-03-01 14:12:42 -0800792
Zsolt Harasztife525502016-03-02 05:18:52 +0000793 # Test packet flows
alshabib3f3da0e2016-03-01 23:23:45 -0800794 self.testPacketFlow(s_vlan_id, c_vlan_id)
Adminb17b1662015-10-19 15:50:53 -0700795
796 # clean up the test
797 delete_all_flows(self.controller)
798 do_barrier(self.controller)
799 verify_no_errors(self.controller)
alshabibb9d4ee82016-03-01 14:12:42 -0800800
801
alshabibcde318b2016-03-01 22:49:13 -0800802class TestCyclingDoubleVlan(OltBaseTest):
alshabibb9d4ee82016-03-01 14:12:42 -0800803 """Cycle through vlans and test traffic flow"""
804
805 def runTest(self):
806 logging.info("Running cycling vlan test")
807
alshabib2ecca692016-03-01 15:10:38 -0800808 for stag in xrange(2, 4000, 100):
809 for ctag in xrange(2, 4000, 100):
alshabibf1f07dd2016-03-01 15:50:35 -0800810 delete_all_flows(self.controller)
811 time.sleep(5)
Admin44f754e2016-03-01 23:00:46 -0800812 self.installDoubleTaggingRules(stag, ctag)
alshabibf1f07dd2016-03-01 15:50:35 -0800813 time.sleep(5)
alshabib3f3da0e2016-03-01 23:23:45 -0800814 self.testPacketFlow(stag, ctag)