blob: 1868421331493a4dbbd0e4296e4b56b3b2f47959 [file] [log] [blame]
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001/*
2 * Copyright 2016-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.opencord.olt.impl;
17
Andrea Campanellacbbb7952019-11-25 06:38:41 +000018import org.onlab.packet.EthType;
19import org.onlab.packet.IPv4;
20import org.onlab.packet.IPv6;
21import org.onlab.packet.MacAddress;
22import org.onlab.packet.TpPort;
23import org.onlab.packet.VlanId;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000024import org.onlab.util.KryoNamespace;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000025import org.onlab.util.Tools;
26import org.onosproject.cfg.ComponentConfigService;
27import org.onosproject.core.ApplicationId;
28import org.onosproject.core.CoreService;
29import org.onosproject.mastership.MastershipService;
yasin saplib4b8ee12021-06-13 18:25:20 +000030import org.onosproject.net.Annotations;
Matteo Scandolo3a037a32020-04-01 12:17:50 -070031import org.onosproject.net.ConnectPoint;
yasin saplib4b8ee12021-06-13 18:25:20 +000032import org.onosproject.net.DefaultAnnotations;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000033import org.onosproject.net.DeviceId;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000034import org.onosproject.net.PortNumber;
35import org.onosproject.net.device.DeviceService;
36import org.onosproject.net.flow.DefaultTrafficSelector;
37import org.onosproject.net.flow.DefaultTrafficTreatment;
38import org.onosproject.net.flow.TrafficSelector;
39import org.onosproject.net.flow.TrafficTreatment;
40import org.onosproject.net.flow.criteria.Criteria;
41import org.onosproject.net.flowobjective.DefaultFilteringObjective;
42import org.onosproject.net.flowobjective.DefaultForwardingObjective;
43import org.onosproject.net.flowobjective.FilteringObjective;
44import org.onosproject.net.flowobjective.FlowObjectiveService;
45import org.onosproject.net.flowobjective.ForwardingObjective;
46import org.onosproject.net.flowobjective.Objective;
47import org.onosproject.net.flowobjective.ObjectiveContext;
48import org.onosproject.net.flowobjective.ObjectiveError;
49import org.onosproject.net.meter.MeterId;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000050import org.onosproject.store.serializers.KryoNamespaces;
51import org.onosproject.store.service.Serializer;
52import org.onosproject.store.service.StorageService;
Tunahan Sezenf0843b92021-04-30 07:13:16 +000053import org.opencord.olt.AccessDevicePort;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000054import org.opencord.olt.internalapi.AccessDeviceFlowService;
55import org.opencord.olt.internalapi.AccessDeviceMeterService;
56import org.opencord.sadis.BandwidthProfileInformation;
57import org.opencord.sadis.BaseInformationService;
58import org.opencord.sadis.SadisService;
59import org.opencord.sadis.SubscriberAndDeviceInformation;
60import org.opencord.sadis.UniTagInformation;
61import org.osgi.service.component.ComponentContext;
62import org.osgi.service.component.annotations.Activate;
63import org.osgi.service.component.annotations.Component;
64import org.osgi.service.component.annotations.Deactivate;
65import org.osgi.service.component.annotations.Modified;
66import org.osgi.service.component.annotations.Reference;
67import org.osgi.service.component.annotations.ReferenceCardinality;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000068import org.osgi.service.component.annotations.ReferencePolicy;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000069import org.slf4j.Logger;
70
yasin saplib4b8ee12021-06-13 18:25:20 +000071import java.util.Arrays;
Andrea Campanella7a1d7e72020-11-05 10:40:10 +010072import java.util.Dictionary;
yasin saplib4b8ee12021-06-13 18:25:20 +000073import java.util.List;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000074import java.util.Map;
yasin saplib4b8ee12021-06-13 18:25:20 +000075import java.util.Objects;
Andrea Campanellabfb47af2021-06-03 11:09:45 +020076import java.util.Optional;
Andrea Campanella7a1d7e72020-11-05 10:40:10 +010077import java.util.Properties;
78import java.util.concurrent.BlockingQueue;
79import java.util.concurrent.CompletableFuture;
Andrea Campanella7a1d7e72020-11-05 10:40:10 +010080import java.util.concurrent.LinkedBlockingQueue;
81
82import static com.google.common.base.Strings.isNullOrEmpty;
83import static org.onlab.util.Tools.get;
84import static org.opencord.olt.impl.OsgiPropertyConstants.*;
85import static org.slf4j.LoggerFactory.getLogger;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000086
87/**
88 * Provisions flow rules on access devices.
89 */
90@Component(immediate = true, property = {
Saurav Dasf62cea82020-08-26 17:43:04 -070091 ENABLE_DHCP_ON_NNI + ":Boolean=" + ENABLE_DHCP_ON_NNI_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000092 ENABLE_DHCP_V4 + ":Boolean=" + ENABLE_DHCP_V4_DEFAULT,
93 ENABLE_DHCP_V6 + ":Boolean=" + ENABLE_DHCP_V6_DEFAULT,
Saurav Dasf62cea82020-08-26 17:43:04 -070094 ENABLE_IGMP_ON_NNI + ":Boolean=" + ENABLE_IGMP_ON_NNI_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000095 ENABLE_EAPOL + ":Boolean=" + ENABLE_EAPOL_DEFAULT,
Gustavo Silva5c492dd2021-02-12 10:21:11 -030096 ENABLE_PPPOE + ":Boolean=" + ENABLE_PPPOE_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000097 DEFAULT_TP_ID + ":Integer=" + DEFAULT_TP_ID_DEFAULT
98})
99public class OltFlowService implements AccessDeviceFlowService {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000100 private static final String SADIS_NOT_RUNNING = "Sadis is not running.";
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000101 private static final String APP_NAME = "org.opencord.olt";
102 private static final int NONE_TP_ID = -1;
103 private static final int NO_PCP = -1;
104 private static final Integer MAX_PRIORITY = 10000;
105 private static final Integer MIN_PRIORITY = 1000;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000106 private static final String INSTALLED = "installed";
107 private static final String REMOVED = "removed";
108 private static final String INSTALLATION = "installation";
109 private static final String REMOVAL = "removal";
110 private static final String V4 = "V4";
111 private static final String V6 = "V6";
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000112
113 private final Logger log = getLogger(getClass());
114
115 @Reference(cardinality = ReferenceCardinality.MANDATORY)
116 protected FlowObjectiveService flowObjectiveService;
117
118 @Reference(cardinality = ReferenceCardinality.MANDATORY)
119 protected CoreService coreService;
120
121 @Reference(cardinality = ReferenceCardinality.MANDATORY)
122 protected MastershipService mastershipService;
123
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000124 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
125 bind = "bindSadisService",
126 unbind = "unbindSadisService",
127 policy = ReferencePolicy.DYNAMIC)
128 protected volatile SadisService sadisService;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000129
130 @Reference(cardinality = ReferenceCardinality.MANDATORY)
131 protected DeviceService deviceService;
132
133 @Reference(cardinality = ReferenceCardinality.MANDATORY)
134 protected AccessDeviceMeterService oltMeterService;
135
136 @Reference(cardinality = ReferenceCardinality.MANDATORY)
137 protected ComponentConfigService componentConfigService;
138
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000139 @Reference(cardinality = ReferenceCardinality.MANDATORY)
140 protected StorageService storageService;
141
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000142 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700143 * Create DHCP trap flow on NNI port(s).
144 */
145 protected boolean enableDhcpOnNni = ENABLE_DHCP_ON_NNI_DEFAULT;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000146
147 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700148 * Enable flows for DHCP v4 if dhcp is required in sadis config.
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000149 **/
150 protected boolean enableDhcpV4 = ENABLE_DHCP_V4_DEFAULT;
151
152 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700153 * Enable flows for DHCP v6 if dhcp is required in sadis config.
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000154 **/
155 protected boolean enableDhcpV6 = ENABLE_DHCP_V6_DEFAULT;
156
157 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700158 * Create IGMP trap flow on NNI port(s).
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000159 **/
Saurav Dasf62cea82020-08-26 17:43:04 -0700160 protected boolean enableIgmpOnNni = ENABLE_IGMP_ON_NNI_DEFAULT;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000161
162 /**
163 * Send EAPOL authentication trap flows before subscriber provisioning.
164 **/
165 protected boolean enableEapol = ENABLE_EAPOL_DEFAULT;
166
167 /**
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300168 * Send PPPoED authentication trap flows before subscriber provisioning.
169 **/
170 protected boolean enablePppoe = ENABLE_PPPOE_DEFAULT;
171
172 /**
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000173 * Default technology profile id that is used for authentication trap flows.
174 **/
175 protected int defaultTechProfileId = DEFAULT_TP_ID_DEFAULT;
176
177 protected ApplicationId appId;
178 protected BaseInformationService<BandwidthProfileInformation> bpService;
179 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000180 protected Map<DeviceId, BlockingQueue<SubscriberFlowInfo>> pendingEapolForDevice;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000181
182 @Activate
183 public void activate(ComponentContext context) {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000184 if (sadisService != null) {
185 bpService = sadisService.getBandwidthProfileService();
186 subsService = sadisService.getSubscriberInfoService();
187 } else {
188 log.warn(SADIS_NOT_RUNNING);
189 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000190 componentConfigService.registerProperties(getClass());
191 appId = coreService.getAppId(APP_NAME);
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000192 KryoNamespace serializer = KryoNamespace.newBuilder()
193 .register(KryoNamespaces.API)
194 .register(UniTagInformation.class)
195 .register(SubscriberFlowInfo.class)
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000196 .register(AccessDevicePort.class)
197 .register(AccessDevicePort.Type.class)
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000198 .register(LinkedBlockingQueue.class)
199 .build();
200 pendingEapolForDevice = storageService.<DeviceId, BlockingQueue<SubscriberFlowInfo>>consistentMapBuilder()
201 .withName("volt-pending-eapol")
202 .withSerializer(Serializer.using(serializer))
203 .withApplicationId(appId)
204 .build().asJavaMap();
Andrea Campanellafee86422020-06-04 16:01:27 +0200205 log.info("started");
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000206 }
207
208
209 @Deactivate
210 public void deactivate(ComponentContext context) {
211 componentConfigService.unregisterProperties(getClass(), false);
Andrea Campanellafee86422020-06-04 16:01:27 +0200212 log.info("stopped");
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000213 }
214
215 @Modified
216 public void modified(ComponentContext context) {
217
218 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
219
Saurav Dasf62cea82020-08-26 17:43:04 -0700220 Boolean o = Tools.isPropertyEnabled(properties, ENABLE_DHCP_ON_NNI);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000221 if (o != null) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700222 enableDhcpOnNni = o;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000223 }
224
Andrea Campanella7c49b792020-05-11 11:36:53 +0200225 Boolean v4 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V4);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000226 if (v4 != null) {
227 enableDhcpV4 = v4;
228 }
229
Andrea Campanella7c49b792020-05-11 11:36:53 +0200230 Boolean v6 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V6);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000231 if (v6 != null) {
232 enableDhcpV6 = v6;
233 }
234
Saurav Dasf62cea82020-08-26 17:43:04 -0700235 Boolean p = Tools.isPropertyEnabled(properties, ENABLE_IGMP_ON_NNI);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000236 if (p != null) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700237 enableIgmpOnNni = p;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000238 }
239
Andrea Campanella7c49b792020-05-11 11:36:53 +0200240 Boolean eap = Tools.isPropertyEnabled(properties, ENABLE_EAPOL);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000241 if (eap != null) {
242 enableEapol = eap;
243 }
244
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300245 Boolean pppoe = Tools.isPropertyEnabled(properties, ENABLE_PPPOE);
246 if (pppoe != null) {
247 enablePppoe = pppoe;
248 }
249
Andrea Campanella7c49b792020-05-11 11:36:53 +0200250 String tpId = get(properties, DEFAULT_TP_ID);
251 defaultTechProfileId = isNullOrEmpty(tpId) ? DEFAULT_TP_ID_DEFAULT : Integer.parseInt(tpId.trim());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000252
Saurav Dasf62cea82020-08-26 17:43:04 -0700253 log.info("modified. Values = enableDhcpOnNni: {}, enableDhcpV4: {}, " +
254 "enableDhcpV6:{}, enableIgmpOnNni:{}, " +
Andrea Campanella438e1ad2021-03-26 11:41:16 +0100255 "enableEapol:{}, enablePppoe:{}, defaultTechProfileId:{}",
Saurav Dasf62cea82020-08-26 17:43:04 -0700256 enableDhcpOnNni, enableDhcpV4, enableDhcpV6,
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300257 enableIgmpOnNni, enableEapol, enablePppoe,
258 defaultTechProfileId);
Andrea Campanellafee86422020-06-04 16:01:27 +0200259
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000260 }
261
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000262 protected void bindSadisService(SadisService service) {
263 sadisService = service;
264 bpService = sadisService.getBandwidthProfileService();
265 subsService = sadisService.getSubscriberInfoService();
266 log.info("Sadis-service binds to onos.");
267 }
268
269 protected void unbindSadisService(SadisService service) {
270 sadisService = null;
271 bpService = null;
272 subsService = null;
273 log.info("Sadis-service unbinds from onos.");
274 }
275
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000276 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000277 public void processDhcpFilteringObjectives(AccessDevicePort port,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000278 MeterId upstreamMeterId,
yasin saplib4b8ee12021-06-13 18:25:20 +0000279 MeterId upstreamOltMeterId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000280 UniTagInformation tagInformation,
281 boolean install,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000282 boolean upstream,
283 Optional<CompletableFuture<ObjectiveError>> dhcpFuture) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700284 if (upstream) {
285 // for UNI ports
286 if (tagInformation != null && !tagInformation.getIsDhcpRequired()) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000287 log.debug("Dhcp provisioning is disabled for UNI port {} for service {}",
288 port, tagInformation.getServiceName());
Tunahan Sezena07fe962021-02-24 08:24:24 +0000289 dhcpFuture.ifPresent(f -> f.complete(null));
Saurav Dasf62cea82020-08-26 17:43:04 -0700290 return;
291 }
292 } else {
293 // for NNI ports
294 if (!enableDhcpOnNni) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000295 log.debug("Dhcp provisioning is disabled for NNI port {}", port);
Tunahan Sezena07fe962021-02-24 08:24:24 +0000296 dhcpFuture.ifPresent(f -> f.complete(null));
Saurav Dasf62cea82020-08-26 17:43:04 -0700297 return;
298 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000299 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000300 int techProfileId = tagInformation != null ? tagInformation.getTechnologyProfileId() : NONE_TP_ID;
301 VlanId cTag = tagInformation != null ? tagInformation.getPonCTag() : VlanId.NONE;
302 VlanId unitagMatch = tagInformation != null ? tagInformation.getUniTagMatch() : VlanId.ANY;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100303 Byte vlanPcp = tagInformation != null && tagInformation.getUsPonCTagPriority() != NO_PCP
304 ? (byte) tagInformation.getUsPonCTagPriority() : null;
Andrea Campanella0e34f562020-06-11 10:47:10 +0200305
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000306
307 if (enableDhcpV4) {
308 int udpSrc = (upstream) ? 68 : 67;
309 int udpDst = (upstream) ? 67 : 68;
310
311 EthType ethType = EthType.EtherType.IPV4.ethType();
312 byte protocol = IPv4.PROTOCOL_UDP;
313
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000314 addDhcpFilteringObjectives(port, udpSrc, udpDst, ethType,
yasin saplib4b8ee12021-06-13 18:25:20 +0000315 upstreamMeterId, upstreamOltMeterId, techProfileId, protocol, cTag, unitagMatch,
316 vlanPcp, upstream, install, dhcpFuture);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000317 }
318
319 if (enableDhcpV6) {
320 int udpSrc = (upstream) ? 547 : 546;
321 int udpDst = (upstream) ? 546 : 547;
322
323 EthType ethType = EthType.EtherType.IPV6.ethType();
324 byte protocol = IPv6.PROTOCOL_UDP;
325
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000326 addDhcpFilteringObjectives(port, udpSrc, udpDst, ethType,
yasin saplib4b8ee12021-06-13 18:25:20 +0000327 upstreamMeterId, upstreamOltMeterId, techProfileId, protocol, cTag, unitagMatch,
328 vlanPcp, upstream, install, dhcpFuture);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000329 }
330 }
331
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000332 private void addDhcpFilteringObjectives(AccessDevicePort port, int udpSrc, int udpDst,
yasin saplib4b8ee12021-06-13 18:25:20 +0000333 EthType ethType, MeterId upstreamMeterId, MeterId upstreamOltMeterId,
334 int techProfileId, byte protocol, VlanId cTag, VlanId unitagMatch,
Andrea Campanella0e34f562020-06-11 10:47:10 +0200335 Byte vlanPcp, boolean upstream,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000336 boolean install, Optional<CompletableFuture<ObjectiveError>> dhcpFuture) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000337
338 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
339 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
340
341 if (upstreamMeterId != null) {
342 treatmentBuilder.meter(upstreamMeterId);
343 }
344
345 if (techProfileId != NONE_TP_ID) {
yasin saplib4b8ee12021-06-13 18:25:20 +0000346 treatmentBuilder.writeMetadata(createTechProfValueForWm(unitagMatch, techProfileId, upstreamOltMeterId), 0);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000347 }
348
349 FilteringObjective.Builder dhcpUpstreamBuilder = (install ? builder.permit() : builder.deny())
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000350 .withKey(Criteria.matchInPort(port.number()))
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000351 .addCondition(Criteria.matchEthType(ethType))
352 .addCondition(Criteria.matchIPProtocol(protocol))
353 .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc)))
354 .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst)))
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000355 .fromApp(appId)
356 .withPriority(MAX_PRIORITY);
357
Andrea Campanella0e34f562020-06-11 10:47:10 +0200358 //VLAN changes and PCP matching need to happen only in the upstream directions
359 if (upstream) {
360 treatmentBuilder.setVlanId(cTag);
361 if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) {
362 dhcpUpstreamBuilder.addCondition(Criteria.matchVlanId(unitagMatch));
363 }
364 if (vlanPcp != null) {
365 treatmentBuilder.setVlanPcp(vlanPcp);
366 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000367 }
368
Andrea Campanella0e34f562020-06-11 10:47:10 +0200369 dhcpUpstreamBuilder.withMeta(treatmentBuilder
370 .setOutput(PortNumber.CONTROLLER).build());
371
372
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000373 FilteringObjective dhcpUpstream = dhcpUpstreamBuilder.add(new ObjectiveContext() {
374 @Override
375 public void onSuccess(Objective objective) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000376 log.info("DHCP {} filter for {} {}.",
377 (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, port,
378 (install) ? INSTALLED : REMOVED);
Tunahan Sezena07fe962021-02-24 08:24:24 +0000379 dhcpFuture.ifPresent(f -> f.complete(null));
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000380 }
381
382 @Override
383 public void onError(Objective objective, ObjectiveError error) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000384 log.error("DHCP {} filter for {} failed {} because {}",
385 (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, port,
386 (install) ? INSTALLATION : REMOVAL,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000387 error);
Tunahan Sezena07fe962021-02-24 08:24:24 +0000388 dhcpFuture.ifPresent(f -> f.complete(error));
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000389 }
390 });
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000391 flowObjectiveService.filter(port.deviceId(), dhcpUpstream);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000392
393 }
394
395 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000396 public void processPPPoEDFilteringObjectives(AccessDevicePort port,
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300397 MeterId upstreamMeterId,
yasin saplib4b8ee12021-06-13 18:25:20 +0000398 MeterId upstreamOltMeterId,
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300399 UniTagInformation tagInformation,
400 boolean install,
401 boolean upstream) {
402 if (!enablePppoe) {
403 log.debug("PPPoED filtering is disabled. Ignoring request.");
404 return;
405 }
406
407 int techProfileId = NONE_TP_ID;
408 VlanId cTag = VlanId.NONE;
409 VlanId unitagMatch = VlanId.ANY;
410 Byte vlanPcp = null;
411
412 if (tagInformation != null) {
413 techProfileId = tagInformation.getTechnologyProfileId();
414 cTag = tagInformation.getPonCTag();
415 unitagMatch = tagInformation.getUniTagMatch();
416 if (tagInformation.getUsPonCTagPriority() != NO_PCP) {
417 vlanPcp = (byte) tagInformation.getUsPonCTagPriority();
418 }
419 }
420
421 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
422 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
423 CompletableFuture<Object> meterFuture = new CompletableFuture<>();
424
425 if (upstreamMeterId != null) {
426 treatmentBuilder.meter(upstreamMeterId);
427 }
428
429 if (techProfileId != NONE_TP_ID) {
yasin saplib4b8ee12021-06-13 18:25:20 +0000430 treatmentBuilder.writeMetadata(createTechProfValueForWm(cTag, techProfileId, upstreamOltMeterId), 0);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300431 }
432
433 DefaultFilteringObjective.Builder pppoedBuilder = (install ? builder.permit() : builder.deny())
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000434 .withKey(Criteria.matchInPort(port.number()))
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300435 .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType()))
436 .fromApp(appId)
437 .withPriority(10000);
438
439 if (upstream) {
440 treatmentBuilder.setVlanId(cTag);
441 if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) {
442 pppoedBuilder.addCondition(Criteria.matchVlanId(unitagMatch));
443 }
444 if (vlanPcp != null) {
445 treatmentBuilder.setVlanPcp(vlanPcp);
446 }
447 }
448 pppoedBuilder = pppoedBuilder.withMeta(treatmentBuilder.setOutput(PortNumber.CONTROLLER).build());
449
450 FilteringObjective pppoed = pppoedBuilder
451 .add(new ObjectiveContext() {
452 @Override
453 public void onSuccess(Objective objective) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000454 log.info("PPPoED filter for {} {}.", port, (install) ? INSTALLED : REMOVED);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300455 }
456
457 @Override
458 public void onError(Objective objective, ObjectiveError error) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000459 log.info("PPPoED filter for {} failed {} because {}", port,
460 (install) ? INSTALLATION : REMOVAL, error);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300461 }
462 });
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000463 flowObjectiveService.filter(port.deviceId(), pppoed);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300464 }
465
466 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000467 public void processIgmpFilteringObjectives(AccessDevicePort port,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000468 MeterId upstreamMeterId,
yasin saplib4b8ee12021-06-13 18:25:20 +0000469 MeterId upstreamOltMeterId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000470 UniTagInformation tagInformation,
471 boolean install,
472 boolean upstream) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700473 if (upstream) {
474 // for UNI ports
475 if (tagInformation != null && !tagInformation.getIsIgmpRequired()) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000476 log.debug("Igmp provisioning is disabled for UNI port {} for service {}",
477 port, tagInformation.getServiceName());
Saurav Dasf62cea82020-08-26 17:43:04 -0700478 return;
479 }
480 } else {
481 // for NNI ports
482 if (!enableIgmpOnNni) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000483 log.debug("Igmp provisioning is disabled for NNI port {}", port);
Saurav Dasf62cea82020-08-26 17:43:04 -0700484 return;
485 }
Matteo Scandolo34556e52020-05-08 12:34:13 -0700486 }
487
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000488 log.debug("{} IGMP flows on {}", (install) ? "Installing" : "Removing", port);
Andrea Campanella0e34f562020-06-11 10:47:10 +0200489 DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000490 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
491 if (upstream) {
492
493 if (tagInformation.getTechnologyProfileId() != NONE_TP_ID) {
494 treatmentBuilder.writeMetadata(createTechProfValueForWm(null,
yasin saplib4b8ee12021-06-13 18:25:20 +0000495 tagInformation.getTechnologyProfileId(), upstreamOltMeterId), 0);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000496 }
497
498
499 if (upstreamMeterId != null) {
500 treatmentBuilder.meter(upstreamMeterId);
501 }
502
Andrea Campanella0e34f562020-06-11 10:47:10 +0200503 if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getUniTagMatch())) {
504 filterBuilder.addCondition(Criteria.matchVlanId(tagInformation.getUniTagMatch()));
505 }
506
507 if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getPonCTag())) {
508 treatmentBuilder.setVlanId(tagInformation.getPonCTag());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000509 }
510
511 if (tagInformation.getUsPonCTagPriority() != NO_PCP) {
Andrea Campanella0e34f562020-06-11 10:47:10 +0200512 treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000513 }
514 }
515
Andrea Campanella0e34f562020-06-11 10:47:10 +0200516 filterBuilder = install ? filterBuilder.permit() : filterBuilder.deny();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000517
Andrea Campanella0e34f562020-06-11 10:47:10 +0200518 FilteringObjective igmp = filterBuilder
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000519 .withKey(Criteria.matchInPort(port.number()))
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000520 .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType()))
521 .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP))
522 .withMeta(treatmentBuilder
523 .setOutput(PortNumber.CONTROLLER).build())
524 .fromApp(appId)
525 .withPriority(MAX_PRIORITY)
526 .add(new ObjectiveContext() {
527 @Override
528 public void onSuccess(Objective objective) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000529 log.info("Igmp filter for {} {}.", port, (install) ? INSTALLED : REMOVED);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000530 }
531
532 @Override
533 public void onError(Objective objective, ObjectiveError error) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000534 log.error("Igmp filter for {} failed {} because {}.", port, (install) ? INSTALLATION : REMOVAL,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000535 error);
536 }
537 });
538
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000539 flowObjectiveService.filter(port.deviceId(), igmp);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000540 }
541
542 @Override
yasin saplib4b8ee12021-06-13 18:25:20 +0000543 public void processEapolFilteringObjectives(AccessDevicePort port, String bpId, Optional<String> oltBpId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000544 CompletableFuture<ObjectiveError> filterFuture,
545 VlanId vlanId, boolean install) {
546
547 if (!enableEapol) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000548 log.debug("Eapol filtering is disabled. Completing filteringFuture immediately for the device {}",
549 port.deviceId());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000550 if (filterFuture != null) {
551 filterFuture.complete(null);
552 }
553 return;
554 }
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000555 log.info("Processing EAPOL with Bandwidth profile {} on {}", bpId, port);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000556 BandwidthProfileInformation bpInfo = getBandwidthProfileInformation(bpId);
yasin saplib4b8ee12021-06-13 18:25:20 +0000557 BandwidthProfileInformation oltBpInfo;
558 if (oltBpId.isPresent()) {
559 oltBpInfo = getBandwidthProfileInformation(oltBpId.get());
560 } else {
561 oltBpInfo = bpInfo;
562 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000563 if (bpInfo == null) {
564 log.warn("Bandwidth profile {} is not found. Authentication flow"
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000565 + " will not be installed on {}", bpId, port);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000566 if (filterFuture != null) {
567 filterFuture.complete(ObjectiveError.BADPARAMS);
568 }
569 return;
570 }
571
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000572 ConnectPoint cp = new ConnectPoint(port.deviceId(), port.number());
Andrea Campanella0e34f562020-06-11 10:47:10 +0200573 DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000574 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000575 // check if meter exists and create it only for an install
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000576 final MeterId meterId = oltMeterService.getMeterIdFromBpMapping(port.deviceId(), bpInfo.id());
yasin saplib4b8ee12021-06-13 18:25:20 +0000577 MeterId oltMeterId = null;
578 if (oltBpId.isPresent()) {
579 oltMeterId = oltBpId.map(id -> oltMeterService.getMeterIdFromBpMapping(port.deviceId(), id)).orElse(null);
580 }
581 log.info("Meter id {} for Bandwidth profile {} and OLT meter id {} for OLT Bandwidth profile {} " +
582 "associated to EAPOL on {}", meterId, bpInfo.id(), oltMeterId, oltBpId, port.deviceId());
583 if (meterId == null || (oltBpId.isPresent() && oltMeterId == null)) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000584 if (install) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000585 log.debug("Need to install meter for EAPOL with bwp {} on {}", bpInfo.id(), port);
586 SubscriberFlowInfo fi = new SubscriberFlowInfo(null, port,
yasin saplib4b8ee12021-06-13 18:25:20 +0000587 new UniTagInformation.Builder()
588 .setPonCTag(vlanId).build(),
589 null, meterId, null, oltMeterId,
590 null, bpInfo.id(), null, oltBpInfo.id());
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000591 pendingEapolForDevice.compute(port.deviceId(), (id, queue) -> {
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100592 if (queue == null) {
593 queue = new LinkedBlockingQueue<>();
594 }
595 queue.add(fi);
596 return queue;
597 });
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200598
Andrea Campanellad1e26642020-10-23 12:08:32 +0200599 //If false the meter is already being installed, skipping installation
yasin saplib4b8ee12021-06-13 18:25:20 +0000600 if (!oltMeterService.checkAndAddPendingMeter(port.deviceId(), bpInfo) &&
601 !oltMeterService.checkAndAddPendingMeter(port.deviceId(), oltBpInfo)) {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200602 return;
603 }
yasin saplib4b8ee12021-06-13 18:25:20 +0000604 List<BandwidthProfileInformation> bwpList = Arrays.asList(bpInfo, oltBpInfo);
605 bwpList.stream().distinct().filter(Objects::nonNull)
606 .forEach(bwp -> createMeterAndProceedEapol(port, bwp, filterFuture, install,
607 cp, filterBuilder, treatmentBuilder));
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000608 } else {
609 // this case should not happen as the request to remove an eapol
610 // flow should mean that the flow points to a meter that exists.
611 // Nevertheless we can still delete the flow as we only need the
612 // correct 'match' to do so.
613 log.warn("Unknown meter id for bp {}, still proceeding with "
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000614 + "delete of eapol flow on {}", bpInfo.id(), port);
615 SubscriberFlowInfo fi = new SubscriberFlowInfo(null, port,
yasin saplib4b8ee12021-06-13 18:25:20 +0000616 new UniTagInformation.Builder().setPonCTag(vlanId).build(),
617 null, meterId, null, oltMeterId, null,
618 bpInfo.id(), null, oltBpInfo.id());
619 handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId, oltMeterId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000620 }
621 } else {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000622 log.debug("Meter {} was previously created for bp {} on {}", meterId, bpInfo.id(), port);
623 SubscriberFlowInfo fi = new SubscriberFlowInfo(null, port,
yasin saplib4b8ee12021-06-13 18:25:20 +0000624 new UniTagInformation.Builder().setPonCTag(vlanId).build(),
625 null, meterId, null, oltMeterId, null,
626 bpInfo.id(), null, oltBpInfo.id());
627 handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId, oltMeterId);
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200628 //No need for the future, meter is present.
629 return;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000630 }
yasin saplib4b8ee12021-06-13 18:25:20 +0000631 }
632
633 private void createMeterAndProceedEapol(AccessDevicePort port, BandwidthProfileInformation bwpInfo,
634 CompletableFuture<ObjectiveError> filterFuture,
635 boolean install, ConnectPoint cp,
636 DefaultFilteringObjective.Builder filterBuilder,
637 TrafficTreatment.Builder treatmentBuilder) {
638 CompletableFuture<Object> meterFuture = new CompletableFuture<>();
639 MeterId meterId = oltMeterService.createMeter(port.deviceId(), bwpInfo, meterFuture);
640 DeviceId deviceId = port.deviceId();
641 meterFuture.thenAccept(result -> {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200642 //for each pending eapol flow we check if the meter is there.
yasin saplib4b8ee12021-06-13 18:25:20 +0000643 pendingEapolForDevice.compute(deviceId, (id, queue) -> {
644 if (queue != null && !queue.isEmpty()) {
645 while (true) {
646 //TODO this might return the reference and not the actual object
647 // so it can be actually swapped underneath us.
648 SubscriberFlowInfo fi = queue.peek();
649 if (fi == null) {
650 log.debug("No more subscribers eapol flows on {}", deviceId);
651 queue = new LinkedBlockingQueue<>();
652 break;
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100653 }
yasin saplib4b8ee12021-06-13 18:25:20 +0000654 log.debug("handing pending eapol on {} for {}", fi.getUniPort(), fi);
655 if (result == null) {
656 MeterId mId = oltMeterService
657 .getMeterIdFromBpMapping(port.deviceId(), fi.getUpBpInfo());
658 MeterId oltMeterId = oltMeterService
659 .getMeterIdFromBpMapping(port.deviceId(), fi.getUpOltBpInfo());
660 if (mId != null && oltMeterId != null) {
661 log.debug("Meter installation completed for subscriber on {}, " +
662 "handling EAPOL trap flow", port);
663 fi.setUpMeterId(mId);
664 fi.setUpOltMeterId(oltMeterId);
665 handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi,
666 mId, oltMeterId);
667 queue.remove(fi);
668 } else {
669 log.debug("Not all meters for {} are yet installed for EAPOL meterID {}, " +
670 "oltMeterId {}", fi, meterId, oltMeterId);
671 }
672 } else {
673 log.warn("Meter installation error while sending EAPOL trap flow to {}. " +
674 "Result {} and MeterId {}", port, result, meterId);
675 queue.remove(fi);
676 }
677 oltMeterService.removeFromPendingMeters(port.deviceId(), bwpInfo);
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100678 }
yasin saplib4b8ee12021-06-13 18:25:20 +0000679 } else {
680 log.info("No pending EAPOLs on {}", port.deviceId());
681 queue = new LinkedBlockingQueue<>();
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200682 }
yasin saplib4b8ee12021-06-13 18:25:20 +0000683 return queue;
684 });
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000685 });
686 }
687
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200688 private void handleEapol(CompletableFuture<ObjectiveError> filterFuture,
689 boolean install, ConnectPoint cp,
Andrea Campanella0e34f562020-06-11 10:47:10 +0200690 DefaultFilteringObjective.Builder filterBuilder,
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200691 TrafficTreatment.Builder treatmentBuilder,
yasin saplib4b8ee12021-06-13 18:25:20 +0000692 SubscriberFlowInfo fi, MeterId mId, MeterId oltMeterId) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000693 log.info("Meter {} for {} on {} exists. {} EAPOL trap flow",
694 mId, fi.getUpBpInfo(), fi.getUniPort(),
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200695 (install) ? "Installing" : "Removing");
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000696 int techProfileId = getDefaultTechProfileId(fi.getUniPort());
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200697 // can happen in case of removal
698 if (mId != null) {
699 treatmentBuilder.meter(mId);
700 }
701 //Authentication trap flow uses only tech profile id as write metadata value
Andrea Campanella0e34f562020-06-11 10:47:10 +0200702 FilteringObjective eapol = (install ? filterBuilder.permit() : filterBuilder.deny())
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000703 .withKey(Criteria.matchInPort(fi.getUniPort().number()))
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200704 .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType()))
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200705 .withMeta(treatmentBuilder
706 .writeMetadata(createTechProfValueForWm(
707 fi.getTagInfo().getPonCTag(),
yasin saplib4b8ee12021-06-13 18:25:20 +0000708 techProfileId, oltMeterId), 0)
Andrea Campanella0e34f562020-06-11 10:47:10 +0200709 .setOutput(PortNumber.CONTROLLER)
710 .pushVlan()
711 .setVlanId(fi.getTagInfo().getPonCTag())
712 .build())
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200713 .fromApp(appId)
714 .withPriority(MAX_PRIORITY)
715 .add(new ObjectiveContext() {
716 @Override
717 public void onSuccess(Objective objective) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000718 log.info("Eapol filter {} for {} on {} with meter {}.",
719 objective.id(), (install) ? INSTALLED : REMOVED, fi.getUniPort(), mId);
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200720 if (filterFuture != null) {
721 filterFuture.complete(null);
722 }
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200723 }
724
725 @Override
726 public void onError(Objective objective, ObjectiveError error) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000727 log.error("Eapol filter {} for {} with meter {} " +
728 "failed {} because {}", objective.id(), fi.getUniPort(), mId,
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200729 (install) ? INSTALLATION : REMOVAL,
730 error);
731 if (filterFuture != null) {
732 filterFuture.complete(error);
733 }
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200734 }
735 });
736 flowObjectiveService.filter(fi.getDevId(), eapol);
737 }
738
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000739 /**
740 * Installs trap filtering objectives for particular traffic types on an
741 * NNI port.
742 *
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000743 * @param nniPort NNI port
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000744 * @param install true to install, false to remove
745 */
746 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000747 public void processNniFilteringObjectives(AccessDevicePort nniPort, boolean install) {
748 log.info("{} flows for NNI port {}",
749 install ? "Adding" : "Removing", nniPort);
750 processLldpFilteringObjective(nniPort, install);
yasin saplib4b8ee12021-06-13 18:25:20 +0000751 processDhcpFilteringObjectives(nniPort, null, null, null, install, false, Optional.empty());
752 processIgmpFilteringObjectives(nniPort, null, null, null, install, false);
753 processPPPoEDFilteringObjectives(nniPort, null, null, null, install, false);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000754 }
755
756
757 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000758 public void processLldpFilteringObjective(AccessDevicePort port, boolean install) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000759 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
760
761 FilteringObjective lldp = (install ? builder.permit() : builder.deny())
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000762 .withKey(Criteria.matchInPort(port.number()))
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000763 .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType()))
764 .withMeta(DefaultTrafficTreatment.builder()
765 .setOutput(PortNumber.CONTROLLER).build())
766 .fromApp(appId)
767 .withPriority(MAX_PRIORITY)
768 .add(new ObjectiveContext() {
769 @Override
770 public void onSuccess(Objective objective) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000771 log.info("LLDP filter for {} {}.", port, (install) ? INSTALLED : REMOVED);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000772 }
773
774 @Override
775 public void onError(Objective objective, ObjectiveError error) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000776 log.error("LLDP filter for {} failed {} because {}", port, (install) ? INSTALLATION : REMOVAL,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000777 error);
778 }
779 });
780
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000781 flowObjectiveService.filter(port.deviceId(), lldp);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000782 }
783
784 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000785 public ForwardingObjective.Builder createTransparentBuilder(AccessDevicePort uplinkPort,
786 AccessDevicePort subscriberPort,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000787 MeterId meterId,
788 UniTagInformation tagInfo,
789 boolean upstream) {
790
791 TrafficSelector selector = DefaultTrafficSelector.builder()
792 .matchVlanId(tagInfo.getPonSTag())
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000793 .matchInPort(upstream ? subscriberPort.number() : uplinkPort.number())
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000794 .matchInnerVlanId(tagInfo.getPonCTag())
795 .build();
796
797 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
798 if (meterId != null) {
799 tBuilder.meter(meterId);
800 }
801
802 TrafficTreatment treatment = tBuilder
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000803 .setOutput(upstream ? uplinkPort.number() : subscriberPort.number())
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000804 .writeMetadata(createMetadata(upstream ? tagInfo.getPonSTag() : tagInfo.getPonCTag(),
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000805 tagInfo.getTechnologyProfileId(),
806 upstream ? uplinkPort.number() : subscriberPort.number()), 0)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000807 .build();
808
yasin saplib4b8ee12021-06-13 18:25:20 +0000809 return createForwardingObjectiveBuilder(selector, treatment, MIN_PRIORITY,
810 DefaultAnnotations.builder().build());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000811 }
812
813 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000814 public ForwardingObjective.Builder createUpBuilder(AccessDevicePort uplinkPort,
815 AccessDevicePort subscriberPort,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000816 MeterId upstreamMeterId,
yasin saplib4b8ee12021-06-13 18:25:20 +0000817 MeterId upstreamOltMeterId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000818 UniTagInformation uniTagInformation) {
819
820 TrafficSelector selector = DefaultTrafficSelector.builder()
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000821 .matchInPort(subscriberPort.number())
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000822 .matchVlanId(uniTagInformation.getUniTagMatch())
823 .build();
824
Andrea Campanella327c5722020-01-30 11:34:13 +0100825 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
826 //if the subscriberVlan (cTag) is different than ANY it needs to set.
827 if (uniTagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) {
828 treatmentBuilder.pushVlan()
829 .setVlanId(uniTagInformation.getPonCTag());
830 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000831
832 if (uniTagInformation.getUsPonCTagPriority() != NO_PCP) {
833 treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonCTagPriority());
834 }
835
836 treatmentBuilder.pushVlan()
837 .setVlanId(uniTagInformation.getPonSTag());
838
839 if (uniTagInformation.getUsPonSTagPriority() != NO_PCP) {
840 treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonSTagPriority());
841 }
842
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000843 treatmentBuilder.setOutput(uplinkPort.number())
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000844 .writeMetadata(createMetadata(uniTagInformation.getPonCTag(),
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000845 uniTagInformation.getTechnologyProfileId(), uplinkPort.number()), 0L);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000846
yasin saplib4b8ee12021-06-13 18:25:20 +0000847 DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder();
848
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000849 if (upstreamMeterId != null) {
850 treatmentBuilder.meter(upstreamMeterId);
yasin saplib4b8ee12021-06-13 18:25:20 +0000851 annotationBuilder.set(UPSTREAM_ONU, upstreamMeterId.toString());
852 }
853 if (upstreamOltMeterId != null) {
854 treatmentBuilder.meter(upstreamOltMeterId);
855 annotationBuilder.set(UPSTREAM_OLT, upstreamOltMeterId.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000856 }
857
yasin saplib4b8ee12021-06-13 18:25:20 +0000858 return createForwardingObjectiveBuilder(selector, treatmentBuilder.build(), MIN_PRIORITY,
859 annotationBuilder.build());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000860 }
861
862 @Override
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000863 public ForwardingObjective.Builder createDownBuilder(AccessDevicePort uplinkPort,
864 AccessDevicePort subscriberPort,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000865 MeterId downstreamMeterId,
yasin saplib4b8ee12021-06-13 18:25:20 +0000866 MeterId downstreamOltMeterId,
Tunahan Sezena07fe962021-02-24 08:24:24 +0000867 UniTagInformation tagInformation,
868 Optional<MacAddress> macAddress) {
Andrea Campanella327c5722020-01-30 11:34:13 +0100869
870 //subscriberVlan can be any valid Vlan here including ANY to make sure the packet is tagged
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000871 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder()
872 .matchVlanId(tagInformation.getPonSTag())
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000873 .matchInPort(uplinkPort.number())
Andrea Campanella090e4a02020-02-05 13:53:55 +0100874 .matchInnerVlanId(tagInformation.getPonCTag());
875
876
877 if (tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) {
878 selectorBuilder.matchMetadata(tagInformation.getPonCTag().toShort());
879 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000880
881 if (tagInformation.getDsPonSTagPriority() != NO_PCP) {
882 selectorBuilder.matchVlanPcp((byte) tagInformation.getDsPonSTagPriority());
883 }
884
Tunahan Sezena07fe962021-02-24 08:24:24 +0000885 macAddress.ifPresent(selectorBuilder::matchEthDst);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000886
887 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder()
888 .popVlan()
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000889 .setOutput(subscriberPort.number());
Andrea Campanella327c5722020-01-30 11:34:13 +0100890
Andrea Campanella327c5722020-01-30 11:34:13 +0100891 treatmentBuilder.writeMetadata(createMetadata(tagInformation.getPonCTag(),
892 tagInformation.getTechnologyProfileId(),
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000893 subscriberPort.number()), 0);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000894
Andrea Campanella981e86c2021-03-12 11:35:33 +0100895 // Upstream pbit is used to remark inner vlan pbit.
896 // Upstream is used to avoid trusting the BNG to send the packet with correct pbit.
897 // this is done because ds mode 0 is used because ds mode 3 or 6 that allow for
898 // all pbit acceptance are not widely supported by vendors even though present in
899 // the OMCI spec.
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000900 if (tagInformation.getUsPonCTagPriority() != NO_PCP) {
901 treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority());
902 }
903
Andrea Campanella9a779292020-02-03 19:19:09 +0100904 if (!VlanId.NONE.equals(tagInformation.getUniTagMatch()) &&
905 tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000906 treatmentBuilder.setVlanId(tagInformation.getUniTagMatch());
907 }
908
yasin saplib4b8ee12021-06-13 18:25:20 +0000909 DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder();
910
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000911 if (downstreamMeterId != null) {
912 treatmentBuilder.meter(downstreamMeterId);
yasin saplib4b8ee12021-06-13 18:25:20 +0000913 annotationBuilder.set(DOWNSTREAM_ONU, downstreamMeterId.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000914 }
915
yasin saplib4b8ee12021-06-13 18:25:20 +0000916 if (downstreamOltMeterId != null) {
917 treatmentBuilder.meter(downstreamOltMeterId);
918 annotationBuilder.set(DOWNSTREAM_OLT, downstreamOltMeterId.toString());
919 }
920
921 return createForwardingObjectiveBuilder(selectorBuilder.build(), treatmentBuilder.build(), MIN_PRIORITY,
922 annotationBuilder.build());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000923 }
924
Andrea Campanella600d2e22020-06-22 11:00:31 +0200925 @Override
926 public void clearDeviceState(DeviceId deviceId) {
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100927 pendingEapolForDevice.remove(deviceId);
Andrea Campanella600d2e22020-06-22 11:00:31 +0200928 }
929
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000930 private DefaultForwardingObjective.Builder createForwardingObjectiveBuilder(TrafficSelector selector,
931 TrafficTreatment treatment,
yasin saplib4b8ee12021-06-13 18:25:20 +0000932 Integer priority,
933 Annotations annotations) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000934 return DefaultForwardingObjective.builder()
935 .withFlag(ForwardingObjective.Flag.VERSATILE)
936 .withPriority(priority)
937 .makePermanent()
938 .withSelector(selector)
yasin saplib4b8ee12021-06-13 18:25:20 +0000939 .withAnnotations(annotations)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000940 .fromApp(appId)
941 .withTreatment(treatment);
942 }
943
944 /**
945 * Returns the write metadata value including tech profile reference and innerVlan.
946 * For param cVlan, null can be sent
947 *
yasin saplib4b8ee12021-06-13 18:25:20 +0000948 * @param cVlan c (customer) tag of one subscriber
949 * @param techProfileId tech profile id of one subscriber
950 * @param upstreamOltMeterId upstream meter id for OLT device.
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000951 * @return the write metadata value including tech profile reference and innerVlan
952 */
yasin saplib4b8ee12021-06-13 18:25:20 +0000953 private Long createTechProfValueForWm(VlanId cVlan, int techProfileId, MeterId upstreamOltMeterId) {
954 Long writeMetadata;
955
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000956 if (cVlan == null || VlanId.NONE.equals(cVlan)) {
yasin saplib4b8ee12021-06-13 18:25:20 +0000957 writeMetadata = (long) techProfileId << 32;
958 } else {
959 writeMetadata = ((long) (cVlan.id()) << 48 | (long) techProfileId << 32);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000960 }
yasin saplib4b8ee12021-06-13 18:25:20 +0000961 if (upstreamOltMeterId == null) {
962 return writeMetadata;
963 } else {
964 return writeMetadata | upstreamOltMeterId.id();
965 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000966 }
967
968 private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000969 if (bpService == null) {
970 log.warn(SADIS_NOT_RUNNING);
971 return null;
972 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000973 if (bandwidthProfile == null) {
974 return null;
975 }
976 return bpService.get(bandwidthProfile);
977 }
978
979 /**
980 * It will be used to support AT&T use case (for EAPOL flows).
981 * If multiple services are found in uniServiceList, returns default tech profile id
982 * If one service is found, returns the found one
983 *
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000984 * @param port uni port
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000985 * @return the default technology profile id
986 */
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000987 private int getDefaultTechProfileId(AccessDevicePort port) {
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000988 if (subsService == null) {
989 log.warn(SADIS_NOT_RUNNING);
990 return defaultTechProfileId;
991 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000992 if (port != null) {
Tunahan Sezenf0843b92021-04-30 07:13:16 +0000993 SubscriberAndDeviceInformation info = subsService.get(port.name());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000994 if (info != null && info.uniTagList().size() == 1) {
995 return info.uniTagList().get(0).getTechnologyProfileId();
996 }
997 }
998 return defaultTechProfileId;
999 }
1000
1001 /**
1002 * Write metadata instruction value (metadata) is 8 bytes.
1003 * <p>
1004 * MS 2 bytes: C Tag
1005 * Next 2 bytes: Technology Profile Id
1006 * Next 4 bytes: Port number (uni or nni)
1007 */
1008 private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) {
1009 if (techProfileId == NONE_TP_ID) {
Andrea Campanella7c49b792020-05-11 11:36:53 +02001010 techProfileId = DEFAULT_TP_ID_DEFAULT;
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001011 }
1012
1013 return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong();
1014 }
1015
1016
1017}