blob: 14fa4f9fb9764fc39c8ec07141e8b25dfff9cdaa [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;
24import org.onlab.util.Tools;
25import org.onosproject.cfg.ComponentConfigService;
26import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
28import org.onosproject.mastership.MastershipService;
29import org.onosproject.net.AnnotationKeys;
Matteo Scandolo3a037a32020-04-01 12:17:50 -070030import org.onosproject.net.ConnectPoint;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000031import org.onosproject.net.DeviceId;
32import org.onosproject.net.Port;
33import org.onosproject.net.PortNumber;
34import org.onosproject.net.device.DeviceService;
35import org.onosproject.net.flow.DefaultTrafficSelector;
36import org.onosproject.net.flow.DefaultTrafficTreatment;
37import org.onosproject.net.flow.TrafficSelector;
38import org.onosproject.net.flow.TrafficTreatment;
39import org.onosproject.net.flow.criteria.Criteria;
40import org.onosproject.net.flowobjective.DefaultFilteringObjective;
41import org.onosproject.net.flowobjective.DefaultForwardingObjective;
42import org.onosproject.net.flowobjective.FilteringObjective;
43import org.onosproject.net.flowobjective.FlowObjectiveService;
44import org.onosproject.net.flowobjective.ForwardingObjective;
45import org.onosproject.net.flowobjective.Objective;
46import org.onosproject.net.flowobjective.ObjectiveContext;
47import org.onosproject.net.flowobjective.ObjectiveError;
48import org.onosproject.net.meter.MeterId;
49import org.opencord.olt.internalapi.AccessDeviceFlowService;
50import org.opencord.olt.internalapi.AccessDeviceMeterService;
51import org.opencord.sadis.BandwidthProfileInformation;
52import org.opencord.sadis.BaseInformationService;
53import org.opencord.sadis.SadisService;
54import org.opencord.sadis.SubscriberAndDeviceInformation;
55import org.opencord.sadis.UniTagInformation;
56import org.osgi.service.component.ComponentContext;
57import org.osgi.service.component.annotations.Activate;
58import org.osgi.service.component.annotations.Component;
59import org.osgi.service.component.annotations.Deactivate;
60import org.osgi.service.component.annotations.Modified;
61import org.osgi.service.component.annotations.Reference;
62import org.osgi.service.component.annotations.ReferenceCardinality;
63import org.slf4j.Logger;
64
Andrea Campanella7a1d7e72020-11-05 10:40:10 +010065import java.util.Dictionary;
66import java.util.Properties;
67import java.util.concurrent.BlockingQueue;
68import java.util.concurrent.CompletableFuture;
69import java.util.concurrent.ConcurrentHashMap;
70import java.util.concurrent.ConcurrentMap;
71import java.util.concurrent.LinkedBlockingQueue;
72
73import static com.google.common.base.Strings.isNullOrEmpty;
74import static org.onlab.util.Tools.get;
75import static org.opencord.olt.impl.OsgiPropertyConstants.*;
76import static org.slf4j.LoggerFactory.getLogger;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000077
78/**
79 * Provisions flow rules on access devices.
80 */
81@Component(immediate = true, property = {
Saurav Dasf62cea82020-08-26 17:43:04 -070082 ENABLE_DHCP_ON_NNI + ":Boolean=" + ENABLE_DHCP_ON_NNI_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000083 ENABLE_DHCP_V4 + ":Boolean=" + ENABLE_DHCP_V4_DEFAULT,
84 ENABLE_DHCP_V6 + ":Boolean=" + ENABLE_DHCP_V6_DEFAULT,
Saurav Dasf62cea82020-08-26 17:43:04 -070085 ENABLE_IGMP_ON_NNI + ":Boolean=" + ENABLE_IGMP_ON_NNI_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000086 ENABLE_EAPOL + ":Boolean=" + ENABLE_EAPOL_DEFAULT,
Gustavo Silva5c492dd2021-02-12 10:21:11 -030087 ENABLE_PPPOE + ":Boolean=" + ENABLE_PPPOE_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000088 DEFAULT_TP_ID + ":Integer=" + DEFAULT_TP_ID_DEFAULT
89})
90public class OltFlowService implements AccessDeviceFlowService {
91
92 private static final String APP_NAME = "org.opencord.olt";
93 private static final int NONE_TP_ID = -1;
94 private static final int NO_PCP = -1;
95 private static final Integer MAX_PRIORITY = 10000;
96 private static final Integer MIN_PRIORITY = 1000;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000097 private static final String INSTALLED = "installed";
98 private static final String REMOVED = "removed";
99 private static final String INSTALLATION = "installation";
100 private static final String REMOVAL = "removal";
101 private static final String V4 = "V4";
102 private static final String V6 = "V6";
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000103
104 private final Logger log = getLogger(getClass());
105
106 @Reference(cardinality = ReferenceCardinality.MANDATORY)
107 protected FlowObjectiveService flowObjectiveService;
108
109 @Reference(cardinality = ReferenceCardinality.MANDATORY)
110 protected CoreService coreService;
111
112 @Reference(cardinality = ReferenceCardinality.MANDATORY)
113 protected MastershipService mastershipService;
114
115 @Reference(cardinality = ReferenceCardinality.MANDATORY)
116 protected SadisService sadisService;
117
118 @Reference(cardinality = ReferenceCardinality.MANDATORY)
119 protected DeviceService deviceService;
120
121 @Reference(cardinality = ReferenceCardinality.MANDATORY)
122 protected AccessDeviceMeterService oltMeterService;
123
124 @Reference(cardinality = ReferenceCardinality.MANDATORY)
125 protected ComponentConfigService componentConfigService;
126
127 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700128 * Create DHCP trap flow on NNI port(s).
129 */
130 protected boolean enableDhcpOnNni = ENABLE_DHCP_ON_NNI_DEFAULT;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000131
132 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700133 * Enable flows for DHCP v4 if dhcp is required in sadis config.
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000134 **/
135 protected boolean enableDhcpV4 = ENABLE_DHCP_V4_DEFAULT;
136
137 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700138 * Enable flows for DHCP v6 if dhcp is required in sadis config.
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000139 **/
140 protected boolean enableDhcpV6 = ENABLE_DHCP_V6_DEFAULT;
141
142 /**
Saurav Dasf62cea82020-08-26 17:43:04 -0700143 * Create IGMP trap flow on NNI port(s).
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000144 **/
Saurav Dasf62cea82020-08-26 17:43:04 -0700145 protected boolean enableIgmpOnNni = ENABLE_IGMP_ON_NNI_DEFAULT;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000146
147 /**
148 * Send EAPOL authentication trap flows before subscriber provisioning.
149 **/
150 protected boolean enableEapol = ENABLE_EAPOL_DEFAULT;
151
152 /**
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300153 * Send PPPoED authentication trap flows before subscriber provisioning.
154 **/
155 protected boolean enablePppoe = ENABLE_PPPOE_DEFAULT;
156
157 /**
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000158 * Default technology profile id that is used for authentication trap flows.
159 **/
160 protected int defaultTechProfileId = DEFAULT_TP_ID_DEFAULT;
161
162 protected ApplicationId appId;
163 protected BaseInformationService<BandwidthProfileInformation> bpService;
164 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100165 private ConcurrentMap<DeviceId, BlockingQueue<SubscriberFlowInfo>> pendingEapolForDevice
166 = new ConcurrentHashMap<>();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000167
168 @Activate
169 public void activate(ComponentContext context) {
170 bpService = sadisService.getBandwidthProfileService();
171 subsService = sadisService.getSubscriberInfoService();
172 componentConfigService.registerProperties(getClass());
173 appId = coreService.getAppId(APP_NAME);
Andrea Campanellafee86422020-06-04 16:01:27 +0200174 log.info("started");
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000175 }
176
177
178 @Deactivate
179 public void deactivate(ComponentContext context) {
180 componentConfigService.unregisterProperties(getClass(), false);
Andrea Campanellafee86422020-06-04 16:01:27 +0200181 log.info("stopped");
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000182 }
183
184 @Modified
185 public void modified(ComponentContext context) {
186
187 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
188
Saurav Dasf62cea82020-08-26 17:43:04 -0700189 Boolean o = Tools.isPropertyEnabled(properties, ENABLE_DHCP_ON_NNI);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000190 if (o != null) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700191 enableDhcpOnNni = o;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000192 }
193
Andrea Campanella7c49b792020-05-11 11:36:53 +0200194 Boolean v4 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V4);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000195 if (v4 != null) {
196 enableDhcpV4 = v4;
197 }
198
Andrea Campanella7c49b792020-05-11 11:36:53 +0200199 Boolean v6 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V6);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000200 if (v6 != null) {
201 enableDhcpV6 = v6;
202 }
203
Saurav Dasf62cea82020-08-26 17:43:04 -0700204 Boolean p = Tools.isPropertyEnabled(properties, ENABLE_IGMP_ON_NNI);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000205 if (p != null) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700206 enableIgmpOnNni = p;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000207 }
208
Andrea Campanella7c49b792020-05-11 11:36:53 +0200209 Boolean eap = Tools.isPropertyEnabled(properties, ENABLE_EAPOL);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000210 if (eap != null) {
211 enableEapol = eap;
212 }
213
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300214 Boolean pppoe = Tools.isPropertyEnabled(properties, ENABLE_PPPOE);
215 if (pppoe != null) {
216 enablePppoe = pppoe;
217 }
218
Andrea Campanella7c49b792020-05-11 11:36:53 +0200219 String tpId = get(properties, DEFAULT_TP_ID);
220 defaultTechProfileId = isNullOrEmpty(tpId) ? DEFAULT_TP_ID_DEFAULT : Integer.parseInt(tpId.trim());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000221
Saurav Dasf62cea82020-08-26 17:43:04 -0700222 log.info("modified. Values = enableDhcpOnNni: {}, enableDhcpV4: {}, " +
223 "enableDhcpV6:{}, enableIgmpOnNni:{}, " +
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300224 "enableEapol{}, enablePppoe{}, defaultTechProfileId: {}",
Saurav Dasf62cea82020-08-26 17:43:04 -0700225 enableDhcpOnNni, enableDhcpV4, enableDhcpV6,
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300226 enableIgmpOnNni, enableEapol, enablePppoe,
227 defaultTechProfileId);
Andrea Campanellafee86422020-06-04 16:01:27 +0200228
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000229 }
230
231 @Override
232 public void processDhcpFilteringObjectives(DeviceId devId, PortNumber port,
233 MeterId upstreamMeterId,
234 UniTagInformation tagInformation,
235 boolean install,
236 boolean upstream) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700237 if (upstream) {
238 // for UNI ports
239 if (tagInformation != null && !tagInformation.getIsDhcpRequired()) {
240 log.debug("Dhcp provisioning is disabled for UNI port {} on "
241 + "device {} for service {}", port, devId,
242 tagInformation.getServiceName());
243 return;
244 }
245 } else {
246 // for NNI ports
247 if (!enableDhcpOnNni) {
248 log.debug("Dhcp provisioning is disabled for NNI port {} on "
249 + "device {}", port, devId);
250 return;
251 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000252 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000253 int techProfileId = tagInformation != null ? tagInformation.getTechnologyProfileId() : NONE_TP_ID;
254 VlanId cTag = tagInformation != null ? tagInformation.getPonCTag() : VlanId.NONE;
255 VlanId unitagMatch = tagInformation != null ? tagInformation.getUniTagMatch() : VlanId.ANY;
Andrea Campanella3a96ce82021-02-09 12:32:42 +0100256 Byte vlanPcp = tagInformation != null && tagInformation.getUsPonCTagPriority() != NO_PCP
257 ? (byte) tagInformation.getUsPonCTagPriority() : null;
Andrea Campanella0e34f562020-06-11 10:47:10 +0200258
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000259
260 if (enableDhcpV4) {
261 int udpSrc = (upstream) ? 68 : 67;
262 int udpDst = (upstream) ? 67 : 68;
263
264 EthType ethType = EthType.EtherType.IPV4.ethType();
265 byte protocol = IPv4.PROTOCOL_UDP;
266
Andrea Campanella7c49b792020-05-11 11:36:53 +0200267 addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType,
Andrea Campanella0e34f562020-06-11 10:47:10 +0200268 upstreamMeterId, techProfileId, protocol, cTag, unitagMatch,
269 vlanPcp, upstream, install);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000270 }
271
272 if (enableDhcpV6) {
273 int udpSrc = (upstream) ? 547 : 546;
274 int udpDst = (upstream) ? 546 : 547;
275
276 EthType ethType = EthType.EtherType.IPV6.ethType();
277 byte protocol = IPv6.PROTOCOL_UDP;
278
Andrea Campanella7c49b792020-05-11 11:36:53 +0200279 addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType,
Andrea Campanella0e34f562020-06-11 10:47:10 +0200280 upstreamMeterId, techProfileId, protocol, cTag, unitagMatch,
281 vlanPcp, upstream, install);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000282 }
283 }
284
285 private void addDhcpFilteringObjectives(DeviceId devId, PortNumber port, int udpSrc, int udpDst,
286 EthType ethType, MeterId upstreamMeterId, int techProfileId, byte protocol,
Andrea Campanella0e34f562020-06-11 10:47:10 +0200287 VlanId cTag, VlanId unitagMatch,
288 Byte vlanPcp, boolean upstream,
289 boolean install) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000290
291 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
292 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
293
294 if (upstreamMeterId != null) {
295 treatmentBuilder.meter(upstreamMeterId);
296 }
297
298 if (techProfileId != NONE_TP_ID) {
299 treatmentBuilder.writeMetadata(createTechProfValueForWm(unitagMatch, techProfileId), 0);
300 }
301
302 FilteringObjective.Builder dhcpUpstreamBuilder = (install ? builder.permit() : builder.deny())
303 .withKey(Criteria.matchInPort(port))
304 .addCondition(Criteria.matchEthType(ethType))
305 .addCondition(Criteria.matchIPProtocol(protocol))
306 .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc)))
307 .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst)))
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000308 .fromApp(appId)
309 .withPriority(MAX_PRIORITY);
310
Andrea Campanella0e34f562020-06-11 10:47:10 +0200311 //VLAN changes and PCP matching need to happen only in the upstream directions
312 if (upstream) {
313 treatmentBuilder.setVlanId(cTag);
314 if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) {
315 dhcpUpstreamBuilder.addCondition(Criteria.matchVlanId(unitagMatch));
316 }
317 if (vlanPcp != null) {
318 treatmentBuilder.setVlanPcp(vlanPcp);
319 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000320 }
321
Andrea Campanella0e34f562020-06-11 10:47:10 +0200322 dhcpUpstreamBuilder.withMeta(treatmentBuilder
323 .setOutput(PortNumber.CONTROLLER).build());
324
325
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000326 FilteringObjective dhcpUpstream = dhcpUpstreamBuilder.add(new ObjectiveContext() {
327 @Override
328 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700329 log.info("DHCP {} filter for dev/port {}/{} {}.",
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000330 (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6,
331 devId, port, (install) ? INSTALLED : REMOVED);
332 }
333
334 @Override
335 public void onError(Objective objective, ObjectiveError error) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700336 log.error("DHCP {} filter for dev/port {}/{} failed {} because {}",
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000337 (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6,
338 devId, port, (install) ? INSTALLATION : REMOVAL,
339 error);
340 }
341 });
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000342 flowObjectiveService.filter(devId, dhcpUpstream);
343
344 }
345
346 @Override
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300347 public void processPPPoEDFilteringObjectives(DeviceId devId, PortNumber portNumber,
348 MeterId upstreamMeterId,
349 UniTagInformation tagInformation,
350 boolean install,
351 boolean upstream) {
352 if (!enablePppoe) {
353 log.debug("PPPoED filtering is disabled. Ignoring request.");
354 return;
355 }
356
357 int techProfileId = NONE_TP_ID;
358 VlanId cTag = VlanId.NONE;
359 VlanId unitagMatch = VlanId.ANY;
360 Byte vlanPcp = null;
361
362 if (tagInformation != null) {
363 techProfileId = tagInformation.getTechnologyProfileId();
364 cTag = tagInformation.getPonCTag();
365 unitagMatch = tagInformation.getUniTagMatch();
366 if (tagInformation.getUsPonCTagPriority() != NO_PCP) {
367 vlanPcp = (byte) tagInformation.getUsPonCTagPriority();
368 }
369 }
370
371 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
372 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
373 CompletableFuture<Object> meterFuture = new CompletableFuture<>();
374
375 if (upstreamMeterId != null) {
376 treatmentBuilder.meter(upstreamMeterId);
377 }
378
379 if (techProfileId != NONE_TP_ID) {
380 treatmentBuilder.writeMetadata(createTechProfValueForWm(cTag, techProfileId), 0);
381 }
382
383 DefaultFilteringObjective.Builder pppoedBuilder = (install ? builder.permit() : builder.deny())
384 .withKey(Criteria.matchInPort(portNumber))
385 .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType()))
386 .fromApp(appId)
387 .withPriority(10000);
388
389 if (upstream) {
390 treatmentBuilder.setVlanId(cTag);
391 if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) {
392 pppoedBuilder.addCondition(Criteria.matchVlanId(unitagMatch));
393 }
394 if (vlanPcp != null) {
395 treatmentBuilder.setVlanPcp(vlanPcp);
396 }
397 }
398 pppoedBuilder = pppoedBuilder.withMeta(treatmentBuilder.setOutput(PortNumber.CONTROLLER).build());
399
400 FilteringObjective pppoed = pppoedBuilder
401 .add(new ObjectiveContext() {
402 @Override
403 public void onSuccess(Objective objective) {
404 log.info("PPPoED filter for {} on {} {}.",
405 devId, portNumber, (install) ? INSTALLED : REMOVED);
406 }
407
408 @Override
409 public void onError(Objective objective, ObjectiveError error) {
410 log.info("PPPoED filter for {} on {} failed {} because {}",
411 devId, portNumber, (install) ? INSTALLATION : REMOVAL, error);
412 }
413 });
414 flowObjectiveService.filter(devId, pppoed);
415 }
416
417 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000418 public void processIgmpFilteringObjectives(DeviceId devId, PortNumber port,
419 MeterId upstreamMeterId,
420 UniTagInformation tagInformation,
421 boolean install,
422 boolean upstream) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700423 if (upstream) {
424 // for UNI ports
425 if (tagInformation != null && !tagInformation.getIsIgmpRequired()) {
426 log.debug("Igmp provisioning is disabled for UNI port {} on "
427 + "device {} for service {}", port, devId,
428 tagInformation.getServiceName());
429 return;
430 }
431 } else {
432 // for NNI ports
433 if (!enableIgmpOnNni) {
434 log.debug("Igmp provisioning is disabled for NNI port {} on device {}",
435 port, devId);
436 return;
437 }
Matteo Scandolo34556e52020-05-08 12:34:13 -0700438 }
439
Andrea Campanellafee86422020-06-04 16:01:27 +0200440 log.debug("{} IGMP flows on {}:{}", (install) ?
441 "Installing" : "Removing", devId, port);
Andrea Campanella0e34f562020-06-11 10:47:10 +0200442 DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000443 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
444 if (upstream) {
445
446 if (tagInformation.getTechnologyProfileId() != NONE_TP_ID) {
447 treatmentBuilder.writeMetadata(createTechProfValueForWm(null,
448 tagInformation.getTechnologyProfileId()), 0);
449 }
450
451
452 if (upstreamMeterId != null) {
453 treatmentBuilder.meter(upstreamMeterId);
454 }
455
Andrea Campanella0e34f562020-06-11 10:47:10 +0200456 if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getUniTagMatch())) {
457 filterBuilder.addCondition(Criteria.matchVlanId(tagInformation.getUniTagMatch()));
458 }
459
460 if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getPonCTag())) {
461 treatmentBuilder.setVlanId(tagInformation.getPonCTag());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000462 }
463
464 if (tagInformation.getUsPonCTagPriority() != NO_PCP) {
Andrea Campanella0e34f562020-06-11 10:47:10 +0200465 treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000466 }
467 }
468
Andrea Campanella0e34f562020-06-11 10:47:10 +0200469 filterBuilder = install ? filterBuilder.permit() : filterBuilder.deny();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000470
Andrea Campanella0e34f562020-06-11 10:47:10 +0200471 FilteringObjective igmp = filterBuilder
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000472 .withKey(Criteria.matchInPort(port))
473 .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType()))
474 .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP))
475 .withMeta(treatmentBuilder
476 .setOutput(PortNumber.CONTROLLER).build())
477 .fromApp(appId)
478 .withPriority(MAX_PRIORITY)
479 .add(new ObjectiveContext() {
480 @Override
481 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700482 log.info("Igmp filter for dev/port {}/{} {}.",
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000483 devId, port, (install) ? INSTALLED : REMOVED);
484 }
485
486 @Override
487 public void onError(Objective objective, ObjectiveError error) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700488 log.error("Igmp filter for dev/port {}/{} failed {} because {}.",
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000489 devId, port, (install) ? INSTALLATION : REMOVAL,
490 error);
491 }
492 });
493
494 flowObjectiveService.filter(devId, igmp);
495 }
496
497 @Override
498 public void processEapolFilteringObjectives(DeviceId devId, PortNumber portNumber, String bpId,
499 CompletableFuture<ObjectiveError> filterFuture,
500 VlanId vlanId, boolean install) {
501
502 if (!enableEapol) {
503 log.debug("Eapol filtering is disabled. Completing filteringFuture immediately for the device {}", devId);
504 if (filterFuture != null) {
505 filterFuture.complete(null);
506 }
507 return;
508 }
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700509 log.info("Processing EAPOL with Bandwidth profile {} on {}/{}", bpId,
510 devId, portNumber);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000511 BandwidthProfileInformation bpInfo = getBandwidthProfileInformation(bpId);
512 if (bpInfo == null) {
513 log.warn("Bandwidth profile {} is not found. Authentication flow"
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700514 + " will not be installed on {}/{}", bpId, devId, portNumber);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000515 if (filterFuture != null) {
516 filterFuture.complete(ObjectiveError.BADPARAMS);
517 }
518 return;
519 }
520
Matteo Scandolo3a037a32020-04-01 12:17:50 -0700521 ConnectPoint cp = new ConnectPoint(devId, portNumber);
Andrea Campanella0e34f562020-06-11 10:47:10 +0200522 DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000523 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
524 CompletableFuture<Object> meterFuture = new CompletableFuture<>();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000525 // check if meter exists and create it only for an install
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200526 final MeterId meterId = oltMeterService.getMeterIdFromBpMapping(devId, bpInfo.id());
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700527 log.info("Meter id {} for Bandwidth profile {} associated to EAPOL on {}", meterId, bpInfo.id(), devId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000528 if (meterId == null) {
529 if (install) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700530 log.debug("Need to install meter for EAPOL with bwp {} on dev/port {}", bpInfo.id(), cp.toString());
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200531 SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(),
532 new UniTagInformation.Builder()
533 .setPonCTag(vlanId).build(),
534 null, null,
535 null, bpInfo.id());
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100536 pendingEapolForDevice.compute(devId, (id, queue) -> {
537 if (queue == null) {
538 queue = new LinkedBlockingQueue<>();
539 }
540 queue.add(fi);
541 return queue;
542 });
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200543
Andrea Campanellad1e26642020-10-23 12:08:32 +0200544 //If false the meter is already being installed, skipping installation
545 if (!oltMeterService.checkAndAddPendingMeter(devId, bpInfo)) {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200546 return;
547 }
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200548 MeterId innerMeterId = oltMeterService.createMeter(devId, bpInfo,
549 meterFuture);
550 fi.setUpMeterId(innerMeterId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000551 } else {
552 // this case should not happen as the request to remove an eapol
553 // flow should mean that the flow points to a meter that exists.
554 // Nevertheless we can still delete the flow as we only need the
555 // correct 'match' to do so.
556 log.warn("Unknown meter id for bp {}, still proceeding with "
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700557 + "delete of eapol flow for {}", bpInfo.id(), cp.toString());
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200558 SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(),
559 new UniTagInformation.Builder()
560 .setPonCTag(vlanId).build(),
561 null, meterId,
562 null, bpInfo.id());
Andrea Campanella0e34f562020-06-11 10:47:10 +0200563 handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000564 }
565 } else {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700566 log.debug("Meter {} was previously created for bp {} on {}", meterId, bpInfo.id(), cp.toString());
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200567 SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(),
568 new UniTagInformation.Builder()
569 .setPonCTag(vlanId).build(),
570 null, meterId,
571 null, bpInfo.id());
Andrea Campanella0e34f562020-06-11 10:47:10 +0200572 handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId);
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200573 //No need for the future, meter is present.
574 return;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000575 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000576 meterFuture.thenAcceptAsync(result -> {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200577 //for each pending eapol flow we check if the meter is there.
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100578 BlockingQueue<SubscriberFlowInfo> queue = pendingEapolForDevice.get(devId);
579 if (queue != null) {
580 while (true) {
581 SubscriberFlowInfo fi = queue.remove();
582 if (fi == null) {
583 break;
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200584 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100585 //TODO this might return the reference and not the actual object
586 // so it can be actually swapped underneath us.
587 log.debug("handing pending eapol on {}/{} for {}", fi.getDevId(), fi.getUniPort(), fi);
588 if (result == null) {
589 MeterId mId = oltMeterService
590 .getMeterIdFromBpMapping(devId, fi.getUpBpInfo());
591 if (mId != null) {
592 log.debug("Meter installation completed for subscriber on {}, handling EAPOL trap flow",
593 cp.toString());
594 handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, mId);
595 }
596 } else {
597 log.warn("Meter installation error while sending EAPOL trap flow to {}. " +
598 "Result {} and MeterId {}", cp.toString(), result, meterId);
599 }
600 oltMeterService.removeFromPendingMeters(devId, bpInfo);
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200601 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100602 } else {
603 log.info("No pending EAPOLs on {}", devId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000604 }
605 });
606 }
607
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200608 private void handleEapol(CompletableFuture<ObjectiveError> filterFuture,
609 boolean install, ConnectPoint cp,
Andrea Campanella0e34f562020-06-11 10:47:10 +0200610 DefaultFilteringObjective.Builder filterBuilder,
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200611 TrafficTreatment.Builder treatmentBuilder,
612 SubscriberFlowInfo fi, MeterId mId) {
613 log.info("Meter {} for {} on {}/{} exists. {} EAPOL trap flow",
614 mId, fi.getUpBpInfo(), fi.getDevId(), fi.getUniPort(),
615 (install) ? "Installing" : "Removing");
616 int techProfileId = getDefaultTechProfileId(fi.getDevId(), fi.getUniPort());
617 // can happen in case of removal
618 if (mId != null) {
619 treatmentBuilder.meter(mId);
620 }
621 //Authentication trap flow uses only tech profile id as write metadata value
Andrea Campanella0e34f562020-06-11 10:47:10 +0200622 FilteringObjective eapol = (install ? filterBuilder.permit() : filterBuilder.deny())
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200623 .withKey(Criteria.matchInPort(fi.getUniPort()))
624 .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType()))
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200625 .withMeta(treatmentBuilder
626 .writeMetadata(createTechProfValueForWm(
627 fi.getTagInfo().getPonCTag(),
628 techProfileId), 0)
Andrea Campanella0e34f562020-06-11 10:47:10 +0200629 .setOutput(PortNumber.CONTROLLER)
630 .pushVlan()
631 .setVlanId(fi.getTagInfo().getPonCTag())
632 .build())
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200633 .fromApp(appId)
634 .withPriority(MAX_PRIORITY)
635 .add(new ObjectiveContext() {
636 @Override
637 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700638 log.info("Eapol filter {} for {} on {}/{} with meter {}.",
Andrea Campanella600d2e22020-06-22 11:00:31 +0200639 objective.id(), fi.getDevId(), fi.getUniPort(),
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200640 (install) ? INSTALLED : REMOVED, mId);
641 if (filterFuture != null) {
642 filterFuture.complete(null);
643 }
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200644 }
645
646 @Override
647 public void onError(Objective objective, ObjectiveError error) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700648 log.error("Eapol filter {} for {}/{} with meter {} " +
Andrea Campanella600d2e22020-06-22 11:00:31 +0200649 "failed {} because {}", objective.id(),
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200650 fi.getDevId(), fi.getUniPort(), mId,
651 (install) ? INSTALLATION : REMOVAL,
652 error);
653 if (filterFuture != null) {
654 filterFuture.complete(error);
655 }
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200656 }
657 });
658 flowObjectiveService.filter(fi.getDevId(), eapol);
659 }
660
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000661 /**
662 * Installs trap filtering objectives for particular traffic types on an
663 * NNI port.
664 *
665 * @param devId device ID
666 * @param port port number
667 * @param install true to install, false to remove
668 */
669 @Override
670 public void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) {
Saurav Dasf62cea82020-08-26 17:43:04 -0700671 log.info("{} flows for NNI port {} on device {}",
672 install ? "Adding" : "Removing", port, devId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000673 processLldpFilteringObjective(devId, port, install);
674 processDhcpFilteringObjectives(devId, port, null, null, install, false);
675 processIgmpFilteringObjectives(devId, port, null, null, install, false);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300676 processPPPoEDFilteringObjectives(devId, port, null, null, install, false);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000677 }
678
679
680 @Override
681 public void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000682 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
683
684 FilteringObjective lldp = (install ? builder.permit() : builder.deny())
685 .withKey(Criteria.matchInPort(port))
686 .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType()))
687 .withMeta(DefaultTrafficTreatment.builder()
688 .setOutput(PortNumber.CONTROLLER).build())
689 .fromApp(appId)
690 .withPriority(MAX_PRIORITY)
691 .add(new ObjectiveContext() {
692 @Override
693 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700694 log.info("LLDP filter for dev/port {}/{} {}.",
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000695 devId, port, (install) ? INSTALLED : REMOVED);
696 }
697
698 @Override
699 public void onError(Objective objective, ObjectiveError error) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700700 log.error("LLDP filter for dev/port {}/{} failed {} because {}",
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000701 devId, port, (install) ? INSTALLATION : REMOVAL,
702 error);
703 }
704 });
705
706 flowObjectiveService.filter(devId, lldp);
707 }
708
709 @Override
710 public ForwardingObjective.Builder createTransparentBuilder(PortNumber uplinkPort,
711 PortNumber subscriberPort,
712 MeterId meterId,
713 UniTagInformation tagInfo,
714 boolean upstream) {
715
716 TrafficSelector selector = DefaultTrafficSelector.builder()
717 .matchVlanId(tagInfo.getPonSTag())
718 .matchInPort(upstream ? subscriberPort : uplinkPort)
719 .matchInnerVlanId(tagInfo.getPonCTag())
720 .build();
721
722 TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
723 if (meterId != null) {
724 tBuilder.meter(meterId);
725 }
726
727 TrafficTreatment treatment = tBuilder
728 .setOutput(upstream ? uplinkPort : subscriberPort)
729 .writeMetadata(createMetadata(upstream ? tagInfo.getPonSTag() : tagInfo.getPonCTag(),
730 tagInfo.getTechnologyProfileId(), upstream ? uplinkPort : subscriberPort), 0)
731 .build();
732
733 return createForwardingObjectiveBuilder(selector, treatment, MIN_PRIORITY);
734 }
735
736 @Override
737 public ForwardingObjective.Builder createUpBuilder(PortNumber uplinkPort,
738 PortNumber subscriberPort,
739 MeterId upstreamMeterId,
740 UniTagInformation uniTagInformation) {
741
742 TrafficSelector selector = DefaultTrafficSelector.builder()
743 .matchInPort(subscriberPort)
744 .matchVlanId(uniTagInformation.getUniTagMatch())
745 .build();
746
Andrea Campanella327c5722020-01-30 11:34:13 +0100747 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
748 //if the subscriberVlan (cTag) is different than ANY it needs to set.
749 if (uniTagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) {
750 treatmentBuilder.pushVlan()
751 .setVlanId(uniTagInformation.getPonCTag());
752 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000753
754 if (uniTagInformation.getUsPonCTagPriority() != NO_PCP) {
755 treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonCTagPriority());
756 }
757
758 treatmentBuilder.pushVlan()
759 .setVlanId(uniTagInformation.getPonSTag());
760
761 if (uniTagInformation.getUsPonSTagPriority() != NO_PCP) {
762 treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonSTagPriority());
763 }
764
765 treatmentBuilder.setOutput(uplinkPort)
766 .writeMetadata(createMetadata(uniTagInformation.getPonCTag(),
767 uniTagInformation.getTechnologyProfileId(), uplinkPort), 0L);
768
769 if (upstreamMeterId != null) {
770 treatmentBuilder.meter(upstreamMeterId);
771 }
772
773 return createForwardingObjectiveBuilder(selector, treatmentBuilder.build(), MIN_PRIORITY);
774 }
775
776 @Override
777 public ForwardingObjective.Builder createDownBuilder(PortNumber uplinkPort,
778 PortNumber subscriberPort,
779 MeterId downstreamMeterId,
780 UniTagInformation tagInformation) {
Andrea Campanella327c5722020-01-30 11:34:13 +0100781
782 //subscriberVlan can be any valid Vlan here including ANY to make sure the packet is tagged
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000783 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder()
784 .matchVlanId(tagInformation.getPonSTag())
785 .matchInPort(uplinkPort)
Andrea Campanella090e4a02020-02-05 13:53:55 +0100786 .matchInnerVlanId(tagInformation.getPonCTag());
787
788
789 if (tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) {
790 selectorBuilder.matchMetadata(tagInformation.getPonCTag().toShort());
791 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000792
793 if (tagInformation.getDsPonSTagPriority() != NO_PCP) {
794 selectorBuilder.matchVlanPcp((byte) tagInformation.getDsPonSTagPriority());
795 }
796
797 if (tagInformation.getConfiguredMacAddress() != null &&
Daniele Moro7cbf4312020-03-06 17:24:12 -0800798 !tagInformation.getConfiguredMacAddress().equals("") &&
799 !MacAddress.NONE.equals(MacAddress.valueOf(tagInformation.getConfiguredMacAddress()))) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000800 selectorBuilder.matchEthDst(MacAddress.valueOf(tagInformation.getConfiguredMacAddress()));
801 }
802
803 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder()
804 .popVlan()
Andrea Campanella327c5722020-01-30 11:34:13 +0100805 .setOutput(subscriberPort);
806
Andrea Campanella327c5722020-01-30 11:34:13 +0100807 treatmentBuilder.writeMetadata(createMetadata(tagInformation.getPonCTag(),
808 tagInformation.getTechnologyProfileId(),
809 subscriberPort), 0);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000810
811 // to remark inner vlan header
812 if (tagInformation.getUsPonCTagPriority() != NO_PCP) {
813 treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority());
814 }
815
Andrea Campanella9a779292020-02-03 19:19:09 +0100816 if (!VlanId.NONE.equals(tagInformation.getUniTagMatch()) &&
817 tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000818 treatmentBuilder.setVlanId(tagInformation.getUniTagMatch());
819 }
820
821 if (downstreamMeterId != null) {
822 treatmentBuilder.meter(downstreamMeterId);
823 }
824
825 return createForwardingObjectiveBuilder(selectorBuilder.build(), treatmentBuilder.build(), MIN_PRIORITY);
826 }
827
Andrea Campanella600d2e22020-06-22 11:00:31 +0200828 @Override
829 public void clearDeviceState(DeviceId deviceId) {
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100830 pendingEapolForDevice.remove(deviceId);
Andrea Campanella600d2e22020-06-22 11:00:31 +0200831 }
832
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000833 private DefaultForwardingObjective.Builder createForwardingObjectiveBuilder(TrafficSelector selector,
834 TrafficTreatment treatment,
835 Integer priority) {
836 return DefaultForwardingObjective.builder()
837 .withFlag(ForwardingObjective.Flag.VERSATILE)
838 .withPriority(priority)
839 .makePermanent()
840 .withSelector(selector)
841 .fromApp(appId)
842 .withTreatment(treatment);
843 }
844
845 /**
846 * Returns the write metadata value including tech profile reference and innerVlan.
847 * For param cVlan, null can be sent
848 *
849 * @param cVlan c (customer) tag of one subscriber
850 * @param techProfileId tech profile id of one subscriber
851 * @return the write metadata value including tech profile reference and innerVlan
852 */
853 private Long createTechProfValueForWm(VlanId cVlan, int techProfileId) {
854 if (cVlan == null || VlanId.NONE.equals(cVlan)) {
855 return (long) techProfileId << 32;
856 }
857 return ((long) (cVlan.id()) << 48 | (long) techProfileId << 32);
858 }
859
860 private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) {
861 if (bandwidthProfile == null) {
862 return null;
863 }
864 return bpService.get(bandwidthProfile);
865 }
866
867 /**
868 * It will be used to support AT&T use case (for EAPOL flows).
869 * If multiple services are found in uniServiceList, returns default tech profile id
870 * If one service is found, returns the found one
871 *
872 * @param devId
873 * @param portNumber
874 * @return the default technology profile id
875 */
876 private int getDefaultTechProfileId(DeviceId devId, PortNumber portNumber) {
877 Port port = deviceService.getPort(devId, portNumber);
878 if (port != null) {
879 SubscriberAndDeviceInformation info = subsService.get(port.annotations().value(AnnotationKeys.PORT_NAME));
880 if (info != null && info.uniTagList().size() == 1) {
881 return info.uniTagList().get(0).getTechnologyProfileId();
882 }
883 }
884 return defaultTechProfileId;
885 }
886
887 /**
888 * Write metadata instruction value (metadata) is 8 bytes.
889 * <p>
890 * MS 2 bytes: C Tag
891 * Next 2 bytes: Technology Profile Id
892 * Next 4 bytes: Port number (uni or nni)
893 */
894 private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) {
895 if (techProfileId == NONE_TP_ID) {
Andrea Campanella7c49b792020-05-11 11:36:53 +0200896 techProfileId = DEFAULT_TP_ID_DEFAULT;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000897 }
898
899 return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong();
900 }
901
902
903}