blob: 24073b086877993bc923dec2ef1a4ec40a4b06c8 [file] [log] [blame]
alshabibf0e7e702015-05-30 18:22:36 -07001/*
Brian O'Connord6a135a2017-08-03 22:46:05 -07002 * Copyright 2016-present Open Networking Foundation
alshabibf0e7e702015-05-30 18:22:36 -07003 *
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 */
alshabib36a4d732016-06-01 16:03:59 -070016package org.opencord.olt.impl;
alshabibf0e7e702015-05-30 18:22:36 -070017
Andrea Campanella7a1d7e72020-11-05 10:40:10 +010018import com.google.common.collect.ImmutableMap;
19import com.google.common.collect.Sets;
alshabibf0e7e702015-05-30 18:22:36 -070020import org.onlab.packet.VlanId;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080021import org.onlab.util.KryoNamespace;
Gamze Abaka1f62dd92020-05-07 08:58:13 +000022import org.onosproject.cfg.ComponentConfigService;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080023import org.onosproject.cluster.ClusterEvent;
24import org.onosproject.cluster.ClusterEventListener;
25import org.onosproject.cluster.ClusterService;
26import org.onosproject.cluster.ControllerNode;
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +020027import org.onosproject.cluster.LeadershipService;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080028import org.onosproject.cluster.NodeId;
alshabibf0e7e702015-05-30 18:22:36 -070029import org.onosproject.core.ApplicationId;
30import org.onosproject.core.CoreService;
alshabib8e4fd2f2016-01-12 15:55:53 -080031import org.onosproject.event.AbstractListenerManager;
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +020032import org.onosproject.mastership.MastershipService;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010033import org.onosproject.net.AnnotationKeys;
Jonathan Harte533a422015-10-20 17:31:24 -070034import org.onosproject.net.ConnectPoint;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010035import org.onosproject.net.Device;
alshabibf0e7e702015-05-30 18:22:36 -070036import org.onosproject.net.DeviceId;
alshabibdec2e252016-01-15 12:20:25 -080037import org.onosproject.net.Port;
alshabibf0e7e702015-05-30 18:22:36 -070038import org.onosproject.net.PortNumber;
39import org.onosproject.net.device.DeviceEvent;
40import org.onosproject.net.device.DeviceListener;
41import org.onosproject.net.device.DeviceService;
Hardik Windlassa58fbee2020-03-12 18:33:55 +053042import org.onosproject.net.flow.FlowRuleService;
alshabibf0e7e702015-05-30 18:22:36 -070043import org.onosproject.net.flowobjective.FlowObjectiveService;
44import org.onosproject.net.flowobjective.ForwardingObjective;
alshabib3ea82642016-01-12 18:06:53 -080045import org.onosproject.net.flowobjective.Objective;
46import org.onosproject.net.flowobjective.ObjectiveContext;
47import org.onosproject.net.flowobjective.ObjectiveError;
Saurav Daseae48de2019-06-19 13:26:15 -070048import org.onosproject.net.meter.MeterId;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080049import org.onosproject.store.serializers.KryoNamespaces;
50import org.onosproject.store.service.ConsistentMultimap;
51import org.onosproject.store.service.Serializer;
52import org.onosproject.store.service.StorageService;
alshabib36a4d732016-06-01 16:03:59 -070053import org.opencord.olt.AccessDeviceEvent;
54import org.opencord.olt.AccessDeviceListener;
55import org.opencord.olt.AccessDeviceService;
Amit Ghosh31939522018-08-16 13:28:21 +010056import org.opencord.olt.AccessSubscriberId;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000057import org.opencord.olt.internalapi.AccessDeviceFlowService;
58import org.opencord.olt.internalapi.AccessDeviceMeterService;
Gamze Abaka641fc072018-09-04 09:16:27 +000059import org.opencord.sadis.BandwidthProfileInformation;
60import org.opencord.sadis.BaseInformationService;
61import org.opencord.sadis.SadisService;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010062import org.opencord.sadis.SubscriberAndDeviceInformation;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000063import org.opencord.sadis.UniTagInformation;
alshabibe0559672016-02-21 14:49:51 -080064import org.osgi.service.component.ComponentContext;
Carmelo Casconeca931162019-07-15 18:22:24 -070065import org.osgi.service.component.annotations.Activate;
66import org.osgi.service.component.annotations.Component;
67import org.osgi.service.component.annotations.Deactivate;
68import org.osgi.service.component.annotations.Modified;
69import org.osgi.service.component.annotations.Reference;
70import org.osgi.service.component.annotations.ReferenceCardinality;
alshabibf0e7e702015-05-30 18:22:36 -070071import org.slf4j.Logger;
72
Andrea Campanella7a1d7e72020-11-05 10:40:10 +010073import java.util.ArrayList;
74import java.util.Collection;
75import java.util.Dictionary;
76import java.util.List;
77import java.util.Map;
78import java.util.Optional;
79import java.util.Properties;
80import java.util.Set;
81import java.util.concurrent.BlockingQueue;
82import java.util.concurrent.CompletableFuture;
83import java.util.concurrent.ConcurrentHashMap;
84import java.util.concurrent.ConcurrentMap;
85import java.util.concurrent.ExecutorService;
86import java.util.concurrent.Executors;
87import java.util.concurrent.LinkedBlockingQueue;
88import java.util.concurrent.ScheduledExecutorService;
89import java.util.concurrent.TimeUnit;
90import java.util.concurrent.atomic.AtomicBoolean;
91
92import static com.google.common.base.Preconditions.checkNotNull;
93import static com.google.common.base.Strings.isNullOrEmpty;
94import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
95import static java.util.stream.Collectors.*;
96import static org.onlab.util.Tools.get;
97import static org.onlab.util.Tools.groupedThreads;
98import static org.opencord.olt.impl.OsgiPropertyConstants.*;
99import static org.slf4j.LoggerFactory.getLogger;
alshabibf0e7e702015-05-30 18:22:36 -0700100
101/**
Jonathan Harte533a422015-10-20 17:31:24 -0700102 * Provisions rules on access devices.
alshabibf0e7e702015-05-30 18:22:36 -0700103 */
Carmelo Casconeca931162019-07-15 18:22:24 -0700104@Component(immediate = true,
105 property = {
Carmelo Casconeca931162019-07-15 18:22:24 -0700106 DEFAULT_BP_ID + ":String=" + DEFAULT_BP_ID_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000107 DEFAULT_MCAST_SERVICE_NAME + ":String=" + DEFAULT_MCAST_SERVICE_NAME_DEFAULT,
Saurav Das2d3777a2020-08-07 18:48:51 -0700108 EAPOL_DELETE_RETRY_MAX_ATTEMPS + ":Integer=" +
109 EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT,
Matteo Scandoloa4aaa972020-10-23 15:24:38 -0700110 PROVISION_DELAY + ":Integer=" + PROVISION_DELAY_DEFAULT,
Carmelo Casconeca931162019-07-15 18:22:24 -0700111 })
alshabib8e4fd2f2016-01-12 15:55:53 -0800112public class Olt
113 extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener>
114 implements AccessDeviceService {
Charles Chan54f110f2017-01-20 11:22:42 -0800115 private static final String APP_NAME = "org.opencord.olt";
alshabibe0559672016-02-21 14:49:51 -0800116
Gamze Abakada282b42019-03-11 13:16:48 +0000117 private static final short EAPOL_DEFAULT_VLAN = 4091;
Gamze Abaka838d8142019-02-21 07:06:55 +0000118 private static final String NO_UPLINK_PORT = "No uplink port found for OLT device {}";
alshabibe0559672016-02-21 14:49:51 -0800119
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800120 public static final int HASH_WEIGHT = 10;
121
alshabibf0e7e702015-05-30 18:22:36 -0700122 private final Logger log = getLogger(getClass());
123
Thomas Lee Sd7735f92020-02-20 19:21:47 +0530124 private static final String NNI = "nni-";
125
Carmelo Casconeca931162019-07-15 18:22:24 -0700126 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabibf0e7e702015-05-30 18:22:36 -0700127 protected FlowObjectiveService flowObjectiveService;
128
Carmelo Casconeca931162019-07-15 18:22:24 -0700129 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabibf0e7e702015-05-30 18:22:36 -0700130 protected DeviceService deviceService;
131
Carmelo Casconeca931162019-07-15 18:22:24 -0700132 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabibf0e7e702015-05-30 18:22:36 -0700133 protected CoreService coreService;
134
Carmelo Casconeca931162019-07-15 18:22:24 -0700135 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Gamze Abaka641fc072018-09-04 09:16:27 +0000136 protected SadisService sadisService;
137
Carmelo Casconeca931162019-07-15 18:22:24 -0700138 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000139 protected AccessDeviceFlowService oltFlowService;
alshabibe0559672016-02-21 14:49:51 -0800140
Carmelo Casconeca931162019-07-15 18:22:24 -0700141 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000142 protected AccessDeviceMeterService oltMeterService;
Gamze Abakaad329652018-12-20 10:12:21 +0000143
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800144 @Reference(cardinality = ReferenceCardinality.MANDATORY)
145 protected StorageService storageService;
146
147 @Reference(cardinality = ReferenceCardinality.MANDATORY)
148 protected ClusterService clusterService;
149
Hardik Windlassa58fbee2020-03-12 18:33:55 +0530150 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +0200151 protected MastershipService mastershipService;
152
153 @Reference(cardinality = ReferenceCardinality.MANDATORY)
154 protected LeadershipService leadershipService;
155
156 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Hardik Windlassa58fbee2020-03-12 18:33:55 +0530157 protected FlowRuleService flowRuleService;
158
Gamze Abaka1f62dd92020-05-07 08:58:13 +0000159 @Reference(cardinality = ReferenceCardinality.MANDATORY)
160 protected ComponentConfigService componentConfigService;
161
Carmelo Casconeca931162019-07-15 18:22:24 -0700162 /**
Carmelo Cascone95ff5122019-11-14 14:19:13 -0800163 * Default bandwidth profile id that is used for authentication trap flows.
Carmelo Casconeca931162019-07-15 18:22:24 -0700164 **/
165 protected String defaultBpId = DEFAULT_BP_ID_DEFAULT;
Gamze Abakaad329652018-12-20 10:12:21 +0000166
Carmelo Casconeca931162019-07-15 18:22:24 -0700167 /**
Gamze Abaka51a34e82020-05-08 13:03:14 +0000168 * Default multicast service name.
Carmelo Casconeca931162019-07-15 18:22:24 -0700169 **/
Gamze Abaka51a34e82020-05-08 13:03:14 +0000170 protected String multicastServiceName = DEFAULT_MCAST_SERVICE_NAME_DEFAULT;
Gamze Abaka33feef52019-02-27 08:16:47 +0000171
Saurav Das2d3777a2020-08-07 18:48:51 -0700172 /**
173 * Default amounts of eapol retry.
174 **/
175 protected int eapolDeleteRetryMaxAttempts = EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT;
176
Matteo Scandoloa4aaa972020-10-23 15:24:38 -0700177 /**
178 * Delay between EAPOL removal and data plane flows provisioning.
179 */
180 protected int provisionDelay = PROVISION_DELAY_DEFAULT;
181
alshabibf0e7e702015-05-30 18:22:36 -0700182 private final DeviceListener deviceListener = new InternalDeviceListener();
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800183 private final ClusterEventListener clusterListener = new InternalClusterListener();
184
185 private ConsistentHasher hasher;
alshabibf0e7e702015-05-30 18:22:36 -0700186
Gamze Abaka641fc072018-09-04 09:16:27 +0000187 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
188 private BaseInformationService<BandwidthProfileInformation> bpService;
alshabibf0e7e702015-05-30 18:22:36 -0700189
Gamze Abaka641fc072018-09-04 09:16:27 +0000190 private ExecutorService oltInstallers = Executors.newFixedThreadPool(4,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000191 groupedThreads("onos/olt-service",
192 "olt-installer-%d"));
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100193
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700194 protected ExecutorService eventExecutor;
Saurav Das2d3777a2020-08-07 18:48:51 -0700195 protected ExecutorService retryExecutor;
Matteo Scandoloa4aaa972020-10-23 15:24:38 -0700196 protected ScheduledExecutorService provisionExecutor;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700197
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800198 private ConsistentMultimap<ConnectPoint, UniTagInformation> programmedSubs;
Saurav Das2d3777a2020-08-07 18:48:51 -0700199 private ConsistentMultimap<ConnectPoint, UniTagInformation> failedSubs;
Saurav Dasa9d5f442019-03-06 19:32:48 -0800200
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100201 private ConcurrentMap<DeviceId, BlockingQueue<SubscriberFlowInfo>> pendingSubscribersForDevice;
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700202
alshabibf0e7e702015-05-30 18:22:36 -0700203 @Activate
alshabibe0559672016-02-21 14:49:51 -0800204 public void activate(ComponentContext context) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000205 eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt",
206 "events-%d", log));
Saurav Das2d3777a2020-08-07 18:48:51 -0700207 retryExecutor = Executors.newCachedThreadPool();
Matteo Scandoloa4aaa972020-10-23 15:24:38 -0700208 provisionExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("onos/olt",
209 "provision-%d", log));
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700210
alshabibe0559672016-02-21 14:49:51 -0800211 modified(context);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000212 ApplicationId appId = coreService.registerApplication(APP_NAME);
Gamze Abaka1f62dd92020-05-07 08:58:13 +0000213 componentConfigService.registerProperties(getClass());
Saurav Das62ad75e2019-03-05 12:22:22 -0800214
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800215 KryoNamespace serializer = KryoNamespace.newBuilder()
216 .register(KryoNamespaces.API)
217 .register(UniTagInformation.class)
218 .build();
219
220 programmedSubs = storageService.<ConnectPoint, UniTagInformation>consistentMultimapBuilder()
221 .withName("volt-programmed-subs")
222 .withSerializer(Serializer.using(serializer))
223 .withApplicationId(appId)
224 .build();
alshabibc4dfe852015-06-05 13:35:13 -0700225
Saurav Das2d3777a2020-08-07 18:48:51 -0700226 failedSubs = storageService.<ConnectPoint, UniTagInformation>consistentMultimapBuilder()
227 .withName("volt-failed-subs")
228 .withSerializer(Serializer.using(serializer))
229 .withApplicationId(appId)
230 .build();
231
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100232 pendingSubscribersForDevice = new ConcurrentHashMap<>();
alshabib8e4fd2f2016-01-12 15:55:53 -0800233 eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry);
234
Gamze Abaka641fc072018-09-04 09:16:27 +0000235 subsService = sadisService.getSubscriberInfoService();
236 bpService = sadisService.getBandwidthProfileService();
237
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800238 List<NodeId> readyNodes = clusterService.getNodes().stream()
239 .filter(c -> clusterService.getState(c.id()) == ControllerNode.State.READY)
240 .map(ControllerNode::id)
241 .collect(toList());
242 hasher = new ConsistentHasher(readyNodes, HASH_WEIGHT);
243 clusterService.addListener(clusterListener);
244
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100245 // look for all provisioned devices in Sadis and create EAPOL flows for the
246 // UNI ports
247 Iterable<Device> devices = deviceService.getDevices();
248 for (Device d : devices) {
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +0200249 if (isLocalLeader(d.id())) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800250 checkAndCreateDeviceFlows(d);
251 }
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100252 }
alshabib4ceaed32016-03-03 18:00:58 -0800253
alshabibba357492016-01-27 13:49:46 -0800254 deviceService.addListener(deviceListener);
alshabibf0e7e702015-05-30 18:22:36 -0700255 log.info("Started with Application ID {}", appId.id());
256 }
257
258 @Deactivate
259 public void deactivate() {
Gamze Abaka1f62dd92020-05-07 08:58:13 +0000260 componentConfigService.unregisterProperties(getClass(), false);
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800261 clusterService.removeListener(clusterListener);
alshabib62e9ce72016-02-11 17:31:36 -0800262 deviceService.removeListener(deviceListener);
Jonathan Hart5f1c8142018-07-24 17:31:59 -0700263 eventDispatcher.removeSink(AccessDeviceEvent.class);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700264 eventExecutor.shutdown();
Saurav Das2d3777a2020-08-07 18:48:51 -0700265 retryExecutor.shutdown();
Matteo Scandoloa4aaa972020-10-23 15:24:38 -0700266 provisionExecutor.shutdown();
alshabibf0e7e702015-05-30 18:22:36 -0700267 log.info("Stopped");
268 }
269
alshabibe0559672016-02-21 14:49:51 -0800270 @Modified
271 public void modified(ComponentContext context) {
272 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
273
274 try {
Andrea Campanella971d5b92020-05-07 11:20:43 +0200275 String bpId = get(properties, DEFAULT_BP_ID);
276 defaultBpId = isNullOrEmpty(bpId) ? defaultBpId : bpId;
Gamze Abakaad329652018-12-20 10:12:21 +0000277
Andrea Campanella971d5b92020-05-07 11:20:43 +0200278 String mcastSN = get(properties, DEFAULT_MCAST_SERVICE_NAME);
279 multicastServiceName = isNullOrEmpty(mcastSN) ? multicastServiceName : mcastSN;
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000280
Saurav Das2d3777a2020-08-07 18:48:51 -0700281 String eapolDeleteRetryNew = get(properties, EAPOL_DELETE_RETRY_MAX_ATTEMPS);
282 eapolDeleteRetryMaxAttempts = isNullOrEmpty(eapolDeleteRetryNew) ? EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT :
283 Integer.parseInt(eapolDeleteRetryNew.trim());
284
285 log.debug("OLT properties: DefaultBpId: {}, MulticastServiceName: {}, EapolDeleteRetryMaxAttempts: {}",
286 defaultBpId, multicastServiceName, eapolDeleteRetryMaxAttempts);
Gamze Abaka33feef52019-02-27 08:16:47 +0000287
alshabibe0559672016-02-21 14:49:51 -0800288 } catch (Exception e) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000289 log.error("Error while modifying the properties", e);
Andrea Campanella971d5b92020-05-07 11:20:43 +0200290 defaultBpId = DEFAULT_BP_ID_DEFAULT;
291 multicastServiceName = DEFAULT_MCAST_SERVICE_NAME_DEFAULT;
alshabibe0559672016-02-21 14:49:51 -0800292 }
293 }
294
alshabib32232c82016-02-25 17:57:24 -0500295 @Override
Gamze Abaka838d8142019-02-21 07:06:55 +0000296 public boolean provisionSubscriber(ConnectPoint connectPoint) {
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200297 log.info("Call to provision subscriber at {}", connectPoint);
Gamze Abaka838d8142019-02-21 07:06:55 +0000298 DeviceId deviceId = connectPoint.deviceId();
299 PortNumber subscriberPortNo = connectPoint.port();
Gamze Abaka838d8142019-02-21 07:06:55 +0000300 checkNotNull(deviceService.getPort(deviceId, subscriberPortNo),
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000301 "Invalid connect point:" + connectPoint);
Hardik Windlass395ff372019-06-13 05:16:00 +0000302
Saurav Das026650f2020-09-21 18:56:35 -0700303 if (isSubscriberInstalled(connectPoint)) {
304 log.warn("Subscriber at {} already provisioned or in the process .."
305 + " not taking any more action", connectPoint);
306 return true;
307 }
308
309 // Find the subscriber config at this connect point
Gamze Abaka838d8142019-02-21 07:06:55 +0000310 SubscriberAndDeviceInformation sub = getSubscriber(connectPoint);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100311 if (sub == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000312 log.warn("No subscriber found for {}", connectPoint);
Amit Ghosh31939522018-08-16 13:28:21 +0100313 return false;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100314 }
Jonathan Harte533a422015-10-20 17:31:24 -0700315
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100316 // Get the uplink port
Gamze Abaka838d8142019-02-21 07:06:55 +0000317 Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId));
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100318 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000319 log.warn(NO_UPLINK_PORT, deviceId);
Amit Ghosh31939522018-08-16 13:28:21 +0100320 return false;
Jonathan Harte533a422015-10-20 17:31:24 -0700321 }
322
Saurav Das2d3777a2020-08-07 18:48:51 -0700323 // delete Eapol authentication flow with default bandwidth
324 // wait until Eapol rule with defaultBpId is removed to install subscriber-based rules
325 // retry deletion if it fails/times-out
326 retryExecutor.execute(new DeleteEapolInstallSub(connectPoint,
327 uplinkPort, sub, 1));
Amit Ghosh31939522018-08-16 13:28:21 +0100328 return true;
alshabibb7a9e172016-01-13 11:23:53 -0800329 }
330
Saurav Das026650f2020-09-21 18:56:35 -0700331 // returns true if subscriber is programmed or in the process of being programmed
332 private boolean isSubscriberInstalled(ConnectPoint connectPoint) {
333 Collection<? extends UniTagInformation> uniTagInformationSet =
334 programmedSubs.get(connectPoint).value();
335 if (!uniTagInformationSet.isEmpty()) {
336 return true;
337 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100338 //Check if the subscriber is already getting provisioned
339 // so we do not provision twice
340 AtomicBoolean isPending = new AtomicBoolean(false);
341 pendingSubscribersForDevice.computeIfPresent(connectPoint.deviceId(), (id, infos) -> {
342 for (SubscriberFlowInfo fi : infos) {
343 if (fi.getUniPort().equals(connectPoint.port())) {
344 isPending.set(true);
345 break;
346 }
Saurav Das026650f2020-09-21 18:56:35 -0700347 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100348 return infos;
349 });
Saurav Das026650f2020-09-21 18:56:35 -0700350
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100351 return isPending.get();
Saurav Das026650f2020-09-21 18:56:35 -0700352 }
353
Saurav Das2d3777a2020-08-07 18:48:51 -0700354 private class DeleteEapolInstallSub implements Runnable {
355 ConnectPoint cp;
356 Port uplinkPort;
357 SubscriberAndDeviceInformation sub;
358 private int attemptNumber;
359
360 DeleteEapolInstallSub(ConnectPoint cp, Port uplinkPort,
361 SubscriberAndDeviceInformation sub,
362 int attemptNumber) {
363 this.cp = cp;
364 this.uplinkPort = uplinkPort;
365 this.sub = sub;
366 this.attemptNumber = attemptNumber;
367 }
368
369 @Override
370 public void run() {
371 CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture();
372 oltFlowService.processEapolFilteringObjectives(cp.deviceId(), cp.port(),
373 defaultBpId, filterFuture,
374 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
375 false);
376 filterFuture.thenAcceptAsync(filterStatus -> {
377 if (filterStatus == null) {
378 log.info("Default eapol flow deleted in attempt {} of {}"
379 + "... provisioning subscriber flows {}",
380 attemptNumber, eapolDeleteRetryMaxAttempts, cp);
Matteo Scandoloa4aaa972020-10-23 15:24:38 -0700381
382 // FIXME this is needed to prevent that default EAPOL flow removal and
383 // data plane flows install are received by the device at the same time
384 provisionExecutor.schedule(
385 () -> provisionUniTagList(cp, uplinkPort.number(), sub),
386 provisionDelay, TimeUnit.MILLISECONDS);
Saurav Das2d3777a2020-08-07 18:48:51 -0700387 } else {
388 if (attemptNumber <= eapolDeleteRetryMaxAttempts) {
389 log.warn("The filtering future failed {} for subscriber {}"
390 + "... retrying {} of {} attempts",
391 filterStatus, cp, attemptNumber, eapolDeleteRetryMaxAttempts);
392 retryExecutor.execute(
393 new DeleteEapolInstallSub(cp, uplinkPort, sub,
394 attemptNumber + 1));
395 } else {
396 log.error("The filtering future failed {} for subscriber {}"
397 + "after {} attempts. Subscriber provisioning failed",
398 filterStatus, cp, eapolDeleteRetryMaxAttempts);
399 sub.uniTagList().forEach(ut -> failedSubs.put(cp, ut));
400 }
401 }
402 });
403 }
404
405 }
406
alshabibb7a9e172016-01-13 11:23:53 -0800407 @Override
Gamze Abaka838d8142019-02-21 07:06:55 +0000408 public boolean removeSubscriber(ConnectPoint connectPoint) {
Saurav Daseae48de2019-06-19 13:26:15 -0700409 log.info("Call to un-provision subscriber at {}", connectPoint);
Gamze Abaka838d8142019-02-21 07:06:55 +0000410
Saurav Daseae48de2019-06-19 13:26:15 -0700411 // Get the subscriber connected to this port from the local cache
412 // If we don't know about the subscriber there's no need to remove it
Gamze Abaka838d8142019-02-21 07:06:55 +0000413 DeviceId deviceId = connectPoint.deviceId();
414 PortNumber subscriberPortNo = connectPoint.port();
415
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800416 Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(connectPoint).value();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000417 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000418 log.warn("Subscriber on connectionPoint {} was not previously programmed, " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000419 "no need to remove it", connectPoint);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800420 return true;
alshabibbf23a1f2016-01-14 17:27:11 -0800421 }
422
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100423 // Get the uplink port
Gamze Abaka838d8142019-02-21 07:06:55 +0000424 Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId));
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100425 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000426 log.warn(NO_UPLINK_PORT, deviceId);
Amit Ghosh31939522018-08-16 13:28:21 +0100427 return false;
alshabib4ceaed32016-03-03 18:00:58 -0800428 }
429
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000430 for (UniTagInformation uniTag : uniTagInformationSet) {
Amit Ghosh95e2f652017-08-23 12:49:46 +0100431
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000432 if (multicastServiceName.equals(uniTag.getServiceName())) {
433 continue;
434 }
Gamze Abaka838d8142019-02-21 07:06:55 +0000435
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000436 unprovisionVlans(deviceId, uplinkPort.number(), subscriberPortNo, uniTag);
alshabibbf23a1f2016-01-14 17:27:11 -0800437
Saurav Das9da7d522020-03-23 19:14:35 -0700438 // remove eapol with subscriber bandwidth profile
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000439 oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo,
440 uniTag.getUpstreamBandwidthProfile(),
441 null, uniTag.getPonCTag(), false);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100442
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000443 Port port = deviceService.getPort(deviceId, subscriberPortNo);
444 if (port != null && port.isEnabled()) {
Saurav Das9da7d522020-03-23 19:14:35 -0700445 // reinstall eapol with default bandwidth profile
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000446 oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId,
447 null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true);
448 } else {
449 log.debug("Port {} is no longer enabled or it's unavailable. Not "
450 + "reprogramming default eapol flow", connectPoint);
451 }
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100452 }
Amit Ghosh31939522018-08-16 13:28:21 +0100453 return true;
alshabibbf23a1f2016-01-14 17:27:11 -0800454 }
455
Gamze Abakaf59c0912019-04-19 08:24:28 +0000456
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000457 @Override
458 public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag,
459 Optional<VlanId> cTag, Optional<Integer> tpId) {
460
461 log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}, tpId {}" +
462 "", subscriberId, sTag, cTag, tpId);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000463
Amit Ghosh31939522018-08-16 13:28:21 +0100464 // Check if we can find the connect point to which this subscriber is connected
465 ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString());
466 if (subsPort == null) {
467 log.warn("ConnectPoint for {} not found", subscriberId);
468 return false;
469 }
470
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100471 if (!sTag.isPresent() && !cTag.isPresent()) {
472 return provisionSubscriber(subsPort);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000473 } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100474 Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId()));
475 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000476 log.warn(NO_UPLINK_PORT, subsPort.deviceId());
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100477 return false;
478 }
479
Gamze Abakaf59c0912019-04-19 08:24:28 +0000480 //delete Eapol authentication flow with default bandwidth
481 //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules
Gamze Abakaf59c0912019-04-19 08:24:28 +0000482 //install subscriber flows
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000483 CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture();
484 oltFlowService.processEapolFilteringObjectives(subsPort.deviceId(), subsPort.port(), defaultBpId,
485 filterFuture, VlanId.vlanId(EAPOL_DEFAULT_VLAN), false);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000486 filterFuture.thenAcceptAsync(filterStatus -> {
487 if (filterStatus == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000488 provisionUniTagInformation(subsPort.deviceId(), uplinkPort.number(), subsPort.port(),
489 cTag.get(), sTag.get(), tpId.get());
Gamze Abakaf59c0912019-04-19 08:24:28 +0000490 }
491 });
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100492 return true;
493 } else {
494 log.warn("Provisioning failed for subscriber: {}", subscriberId);
495 return false;
496 }
Amit Ghosh31939522018-08-16 13:28:21 +0100497 }
Amit Ghosh95e2f652017-08-23 12:49:46 +0100498
alshabibe0559672016-02-21 14:49:51 -0800499 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000500 public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag,
501 Optional<VlanId> cTag, Optional<Integer> tpId) {
Amit Ghosh31939522018-08-16 13:28:21 +0100502 // Check if we can find the connect point to which this subscriber is connected
503 ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString());
504 if (subsPort == null) {
505 log.warn("ConnectPoint for {} not found", subscriberId);
506 return false;
507 }
508
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100509 if (!sTag.isPresent() && !cTag.isPresent()) {
510 return removeSubscriber(subsPort);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000511 } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100512 // Get the uplink port
513 Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId()));
514 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000515 log.warn(NO_UPLINK_PORT, subsPort.deviceId());
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100516 return false;
517 }
518
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000519 Optional<UniTagInformation> tagInfo = getUniTagInformation(subsPort, cTag.get(), sTag.get(), tpId.get());
520 if (!tagInfo.isPresent()) {
521 log.warn("UniTagInformation does not exist for Device/Port {}, cTag {}, sTag {}, tpId {}",
522 subsPort, cTag, sTag, tpId);
523 return false;
524 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000525
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000526 unprovisionVlans(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), tagInfo.get());
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100527 return true;
528 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000529 log.warn("Removing subscriber is not possible - please check the provided information" +
530 "for the subscriber: {}", subscriberId);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100531 return false;
532 }
Amit Ghosh31939522018-08-16 13:28:21 +0100533 }
534
535 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000536 public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getProgSubs() {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800537 return programmedSubs.stream()
538 .collect(collectingAndThen(
539 groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())),
540 ImmutableMap::copyOf));
Saurav Das82b8e6d2018-10-04 15:25:12 -0700541 }
542
543 @Override
Saurav Das2d3777a2020-08-07 18:48:51 -0700544 public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getFailedSubs() {
545 return failedSubs.stream()
546 .collect(collectingAndThen(
547 groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())),
548 ImmutableMap::copyOf));
549 }
550
551 @Override
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100552 public List<DeviceId> fetchOlts() {
553 // look through all the devices and find the ones that are OLTs as per Sadis
554 List<DeviceId> olts = new ArrayList<>();
555 Iterable<Device> devices = deviceService.getDevices();
556 for (Device d : devices) {
Saurav Das82b8e6d2018-10-04 15:25:12 -0700557 if (getOltInfo(d) != null) {
558 // So this is indeed an OLT device
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100559 olts.add(d.id());
560 }
561 }
562 return olts;
alshabibe0559672016-02-21 14:49:51 -0800563 }
564
Amit Ghosh31939522018-08-16 13:28:21 +0100565 /**
566 * Finds the connect point to which a subscriber is connected.
567 *
568 * @param id The id of the subscriber, this is the same ID as in Sadis
569 * @return Subscribers ConnectPoint if found else null
570 */
571 private ConnectPoint findSubscriberConnectPoint(String id) {
572
573 Iterable<Device> devices = deviceService.getDevices();
574 for (Device d : devices) {
575 for (Port p : deviceService.getPorts(d.id())) {
576 log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id);
577 if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) {
578 log.debug("Found on device {} port {}", d.id(), p.number());
579 return new ConnectPoint(d.id(), p.number());
580 }
581 }
582 }
583 return null;
584 }
585
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000586 /**
587 * Gets the context of the bandwidth profile information for the given parameter.
588 *
589 * @param bandwidthProfile the bandwidth profile id
590 * @return the context of the bandwidth profile information
591 */
Gamze Abaka641fc072018-09-04 09:16:27 +0000592 private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) {
593 if (bandwidthProfile == null) {
594 return null;
595 }
596 return bpService.get(bandwidthProfile);
597 }
598
Gamze Abaka838d8142019-02-21 07:06:55 +0000599 /**
Gamze Abaka33feef52019-02-27 08:16:47 +0000600 * Removes subscriber vlan flows.
Gamze Abaka838d8142019-02-21 07:06:55 +0000601 *
602 * @param deviceId the device identifier
603 * @param uplink uplink port of the OLT
604 * @param subscriberPort uni port
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000605 * @param uniTag uni tag information
Gamze Abaka838d8142019-02-21 07:06:55 +0000606 */
Gamze Abaka33feef52019-02-27 08:16:47 +0000607 private void unprovisionVlans(DeviceId deviceId, PortNumber uplink,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000608 PortNumber subscriberPort, UniTagInformation uniTag) {
609
610 log.info("Unprovisioning vlans for {} at {}/{}", uniTag, deviceId, subscriberPort);
alshabibbf23a1f2016-01-14 17:27:11 -0800611
612 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
613 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
614
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000615 VlanId deviceVlan = uniTag.getPonSTag();
616 VlanId subscriberVlan = uniTag.getPonCTag();
Gamze Abaka641fc072018-09-04 09:16:27 +0000617
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000618 MeterId upstreamMeterId = oltMeterService
619 .getMeterIdFromBpMapping(deviceId, uniTag.getUpstreamBandwidthProfile());
620 MeterId downstreamMeterId = oltMeterService
621 .getMeterIdFromBpMapping(deviceId, uniTag.getDownstreamBandwidthProfile());
Gamze Abaka641fc072018-09-04 09:16:27 +0000622
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000623 ForwardingObjective.Builder upFwd =
624 oltFlowService.createUpBuilder(uplink, subscriberPort, upstreamMeterId, uniTag);
625 ForwardingObjective.Builder downFwd =
626 oltFlowService.createDownBuilder(uplink, subscriberPort, downstreamMeterId, uniTag);
627
Andrea Campanella7c49b792020-05-11 11:36:53 +0200628 oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort,
629 upstreamMeterId, uniTag, false, true);
630 oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort,
631 upstreamMeterId, uniTag, false, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300632 oltFlowService.processPPPoEDFilteringObjectives(deviceId, subscriberPort,
633 upstreamMeterId, uniTag, false, true);
alshabibbf23a1f2016-01-14 17:27:11 -0800634
alshabib4ceaed32016-03-03 18:00:58 -0800635 flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() {
636 @Override
637 public void onSuccess(Objective objective) {
638 upFuture.complete(null);
639 }
alshabibbf23a1f2016-01-14 17:27:11 -0800640
alshabib4ceaed32016-03-03 18:00:58 -0800641 @Override
642 public void onError(Objective objective, ObjectiveError error) {
643 upFuture.complete(error);
644 }
645 }));
646
647 flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() {
648 @Override
649 public void onSuccess(Objective objective) {
650 downFuture.complete(null);
651 }
652
653 @Override
654 public void onError(Objective objective, ObjectiveError error) {
655 downFuture.complete(error);
656 }
657 }));
alshabibbf23a1f2016-01-14 17:27:11 -0800658
659 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000660 AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED;
alshabibbf23a1f2016-01-14 17:27:11 -0800661 if (upStatus == null && downStatus == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000662 log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {}, and" +
663 "Device/Port{}", uniTag.getPonCTag(), uniTag.getPonSTag(),
664 uniTag.getTechnologyProfileId(), subscriberPort);
665 updateProgrammedSubscriber(new ConnectPoint(deviceId, subscriberPort), uniTag, false);
alshabibbf23a1f2016-01-14 17:27:11 -0800666 } else if (downStatus != null) {
667 log.error("Subscriber with vlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000668 "on port {} failed downstream uninstallation: {}",
669 subscriberVlan, deviceId, subscriberPort, downStatus);
670 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED;
alshabibbf23a1f2016-01-14 17:27:11 -0800671 } else if (upStatus != null) {
672 log.error("Subscriber with vlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000673 "on port {} failed upstream uninstallation: {}",
674 subscriberVlan, deviceId, subscriberPort, upStatus);
675 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED;
alshabibbf23a1f2016-01-14 17:27:11 -0800676 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000677 Port port = deviceService.getPort(deviceId, subscriberPort);
678 post(new AccessDeviceEvent(type, deviceId, port, deviceVlan, subscriberVlan,
679 uniTag.getTechnologyProfileId()));
alshabibbf23a1f2016-01-14 17:27:11 -0800680 }, oltInstallers);
Jonathan Harte533a422015-10-20 17:31:24 -0700681 }
682
Gamze Abaka838d8142019-02-21 07:06:55 +0000683 /**
Gamze Abaka33feef52019-02-27 08:16:47 +0000684 * Adds subscriber vlan flows, dhcp, eapol and igmp trap flows for the related uni port.
Gamze Abaka838d8142019-02-21 07:06:55 +0000685 *
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000686 * @param connectPoint the connection point of the subscriber
687 * @param uplinkPort uplink port of the OLT (the nni port)
688 * @param sub subscriber information that includes s, c tags, tech profile and bandwidth profile references
Gamze Abaka838d8142019-02-21 07:06:55 +0000689 */
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000690 private void provisionUniTagList(ConnectPoint connectPoint, PortNumber uplinkPort,
691 SubscriberAndDeviceInformation sub) {
Gamze Abaka641fc072018-09-04 09:16:27 +0000692
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700693 log.debug("Provisioning vlans for subscriber on dev/port: {}", connectPoint.toString());
694 if (log.isTraceEnabled()) {
695 log.trace("Subscriber informations {}", sub);
696 }
Gamze Abaka641fc072018-09-04 09:16:27 +0000697
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000698 if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700699 log.warn("Unitaglist doesn't exist for the subscriber {} on dev/port {}",
700 sub.id(), connectPoint.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000701 return;
702 }
Gamze Abaka641fc072018-09-04 09:16:27 +0000703
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000704 DeviceId deviceId = connectPoint.deviceId();
705 PortNumber subscriberPort = connectPoint.port();
Gamze Abaka641fc072018-09-04 09:16:27 +0000706
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000707 for (UniTagInformation uniTag : sub.uniTagList()) {
708 handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, uniTag);
709 }
710 }
alshabib3ea82642016-01-12 18:06:53 -0800711
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000712 /**
713 * Finds the uni tag information and provisions the found information.
714 * If the uni tag information is not found, returns
715 *
716 * @param deviceId the access device id
717 * @param uplinkPort the nni port
718 * @param subscriberPort the uni port
719 * @param innerVlan the pon c tag
720 * @param outerVlan the pon s tag
721 * @param tpId the technology profile id
722 */
723 private void provisionUniTagInformation(DeviceId deviceId, PortNumber uplinkPort,
724 PortNumber subscriberPort,
725 VlanId innerVlan,
726 VlanId outerVlan,
727 Integer tpId) {
Jonathan Harte533a422015-10-20 17:31:24 -0700728
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000729 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
730 Optional<UniTagInformation> gotTagInformation = getUniTagInformation(cp, innerVlan, outerVlan, tpId);
731 if (!gotTagInformation.isPresent()) {
732 return;
733 }
734 UniTagInformation tagInformation = gotTagInformation.get();
735 handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, tagInformation);
736 }
alshabib3ea82642016-01-12 18:06:53 -0800737
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000738 private void updateProgrammedSubscriber(ConnectPoint connectPoint, UniTagInformation tagInformation, Boolean add) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800739 if (add) {
740 programmedSubs.put(connectPoint, tagInformation);
741 } else {
742 programmedSubs.remove(connectPoint, tagInformation);
743 }
Jonathan Harte533a422015-10-20 17:31:24 -0700744 }
745
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000746 /**
747 * Installs a uni tag information flow.
748 *
749 * @param deviceId the access device id
750 * @param uplinkPort the nni port
751 * @param subscriberPort the uni port
752 * @param tagInfo the uni tag information
753 */
754 private void handleSubscriberFlows(DeviceId deviceId, PortNumber uplinkPort, PortNumber subscriberPort,
755 UniTagInformation tagInfo) {
756
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700757 log.debug("Provisioning vlan-based flows for the uniTagInformation {} on dev/port {}/{}",
758 tagInfo, deviceId, subscriberPort);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000759
760 Port port = deviceService.getPort(deviceId, subscriberPort);
761
762 if (multicastServiceName.equals(tagInfo.getServiceName())) {
763 // IGMP flows are taken care of along with VOD service
764 // Please note that for each service, Subscriber Registered event will be sent
765 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED,
766 deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(),
767 tagInfo.getTechnologyProfileId()));
768 return;
Gamze Abaka641fc072018-09-04 09:16:27 +0000769 }
770
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000771 BandwidthProfileInformation upstreamBpInfo =
772 getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile());
773 BandwidthProfileInformation downstreamBpInfo =
774 getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700775 if (upstreamBpInfo == null) {
776 log.warn("No meter installed since no Upstream BW Profile definition found for "
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700777 + "ctag {} stag {} tpId {} and dev/port: {}/{}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700778 tagInfo.getPonCTag(), tagInfo.getPonSTag(),
779 tagInfo.getTechnologyProfileId(), deviceId,
780 subscriberPort);
781 return;
782 }
783 if (downstreamBpInfo == null) {
784 log.warn("No meter installed since no Downstream BW Profile definition found for "
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700785 + "ctag {} stag {} tpId {} and dev/port: {}/{}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700786 tagInfo.getPonCTag(), tagInfo.getPonSTag(),
787 tagInfo.getTechnologyProfileId(), deviceId,
788 subscriberPort);
789 return;
790 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000791
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700792 // check for meterIds for the upstream and downstream bandwidth profiles
793 MeterId upMeterId = oltMeterService
794 .getMeterIdFromBpMapping(deviceId, upstreamBpInfo.id());
795 MeterId downMeterId = oltMeterService
796 .getMeterIdFromBpMapping(deviceId, downstreamBpInfo.id());
797 SubscriberFlowInfo fi = new SubscriberFlowInfo(deviceId, uplinkPort, subscriberPort,
798 tagInfo, downMeterId, upMeterId,
799 downstreamBpInfo.id(), upstreamBpInfo.id());
800
801 if (upMeterId != null && downMeterId != null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700802 log.debug("Meters are existing for upstream {} and downstream {} on dev/port {}/{}",
803 upstreamBpInfo.id(), downstreamBpInfo.id(), deviceId, subscriberPort);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700804 handleSubFlowsWithMeters(fi);
805 } else {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700806 log.debug("Adding {} on {}/{} to pending subs", fi, deviceId, subscriberPort);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700807 // one or both meters are not ready. It's possible they are in the process of being
808 // created for other subscribers that share the same bandwidth profile.
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100809 pendingSubscribersForDevice.compute(deviceId, (id, queue) -> {
810 if (queue == null) {
811 queue = new LinkedBlockingQueue<>();
812 }
813 queue.add(fi);
814 log.info("Added {} to pending subscribers on {}/{}", fi, deviceId, subscriberPort);
815 return queue;
816 });
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700817
818 // queue up the meters to be created
819 if (upMeterId == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700820 log.debug("Missing meter for upstream {} on {}/{}", upstreamBpInfo.id(), deviceId, subscriberPort);
Andrea Campanella600d2e22020-06-22 11:00:31 +0200821 checkAndCreateDevMeter(deviceId, upstreamBpInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700822 }
823 if (downMeterId == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700824 log.debug("Missing meter for downstream {} on {}/{}", downstreamBpInfo.id(), deviceId, subscriberPort);
Andrea Campanella600d2e22020-06-22 11:00:31 +0200825 checkAndCreateDevMeter(deviceId, downstreamBpInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700826 }
827 }
828 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200829 private void checkAndCreateDevMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Andrea Campanellad1e26642020-10-23 12:08:32 +0200830 //If false the meter is already being installed, skipping installation
831 if (!oltMeterService.checkAndAddPendingMeter(deviceId, bwpInfo)) {
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700832 return;
833 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200834 createMeter(deviceId, bwpInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700835 }
836
Andrea Campanella600d2e22020-06-22 11:00:31 +0200837 private void createMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700838 log.debug("Creating Meter with {} on {}", bwpInfo, deviceId);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700839 CompletableFuture<Object> meterFuture = new CompletableFuture<>();
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200840
Andrea Campanella600d2e22020-06-22 11:00:31 +0200841 MeterId meterId = oltMeterService.createMeter(deviceId, bwpInfo,
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700842 meterFuture);
843
844 meterFuture.thenAcceptAsync(result -> {
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100845 BlockingQueue<SubscriberFlowInfo> queue = pendingSubscribersForDevice.get(deviceId);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700846 // iterate through the subscribers on hold
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100847 if (queue != null) {
848 while (true) {
849 //TODO this might return the reference and not the actual object so
850 // it can be actually swapped underneath us.
851 SubscriberFlowInfo fi = queue.peek();
852 if (fi == null) {
853 log.debug("No more subscribers pending on {}", deviceId);
854 break;
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700855 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100856 if (result == null) {
857 // meter install sent to device
858 log.debug("Meter {} installed for bw {} on {}", meterId, bwpInfo, deviceId);
859
860 MeterId upMeterId = oltMeterService
861 .getMeterIdFromBpMapping(deviceId, fi.getUpBpInfo());
862 MeterId downMeterId = oltMeterService
863 .getMeterIdFromBpMapping(deviceId, fi.getDownBpInfo());
864 if (upMeterId != null && downMeterId != null) {
865 log.debug("Provisioning subscriber after meter {} " +
866 "installation and both meters are present " +
867 "upstream {} and downstream {} on {}/{}",
868 meterId, upMeterId, downMeterId, deviceId, fi.getUniPort());
869 // put in the meterIds because when fi was first
870 // created there may or may not have been a meterId
871 // depending on whether the meter was created or
872 // not at that time.
873 fi.setUpMeterId(upMeterId);
874 fi.setDownMeterId(downMeterId);
875 handleSubFlowsWithMeters(fi);
876 queue.remove(fi);
877 }
878 oltMeterService.removeFromPendingMeters(deviceId, bwpInfo);
879 } else {
880 // meter install failed
881 log.error("Addition of subscriber {} on {}/{} failed due to meter " +
882 "{} with result {}", fi, deviceId, fi.getUniPort(),
883 meterId, result);
884 queue.remove(fi);
885 oltMeterService.removeFromPendingMeters(deviceId, bwpInfo);
886 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700887 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100888 } else {
889 log.info("No pending subscribers on {}", deviceId);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700890 }
891 });
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100892
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700893 }
894 /**
895 * Add subscriber flows given meter information for both upstream and
896 * downstream directions.
897 *
898 * @param subscriberFlowInfo relevant information for subscriber
899 */
900 private void handleSubFlowsWithMeters(SubscriberFlowInfo subscriberFlowInfo) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700901 log.debug("Provisioning subscriber flows on {}/{} based on {}",
902 subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort(), subscriberFlowInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700903 UniTagInformation tagInfo = subscriberFlowInfo.getTagInfo();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000904 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>();
905 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>();
Gamze Abakaf59c0912019-04-19 08:24:28 +0000906
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700907 ForwardingObjective.Builder upFwd =
908 oltFlowService.createUpBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(),
909 subscriberFlowInfo.getUpId(), subscriberFlowInfo.getTagInfo());
910 flowObjectiveService.forward(subscriberFlowInfo.getDevId(), upFwd.add(new ObjectiveContext() {
911 @Override
912 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700913 log.debug("Upstream HSIA flow {} installed successfully on {}/{}",
914 subscriberFlowInfo, subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700915 upFuture.complete(null);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000916 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000917
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700918 @Override
919 public void onError(Objective objective, ObjectiveError error) {
920 upFuture.complete(error);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000921 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700922 }));
923
924 ForwardingObjective.Builder downFwd =
925 oltFlowService.createDownBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(),
926 subscriberFlowInfo.getDownId(), subscriberFlowInfo.getTagInfo());
927 flowObjectiveService.forward(subscriberFlowInfo.getDevId(), downFwd.add(new ObjectiveContext() {
928 @Override
929 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700930 log.debug("Downstream HSIA flow {} installed successfully on {}/{}",
931 subscriberFlowInfo, subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700932 downFuture.complete(null);
933 }
934
935 @Override
936 public void onError(Objective objective, ObjectiveError error) {
937 downFuture.complete(error);
938 }
939 }));
Gamze Abakaf59c0912019-04-19 08:24:28 +0000940
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100941 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000942 AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED;
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100943 if (downStatus != null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700944 log.error("Flow with innervlan {} and outerVlan {} on {}/{} failed downstream installation: {}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700945 tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(),
946 subscriberFlowInfo.getUniPort(), downStatus);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000947 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED;
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100948 } else if (upStatus != null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700949 log.error("Flow with innervlan {} and outerVlan {} on {}/{} failed downstream installation: {}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700950 tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(),
951 subscriberFlowInfo.getUniPort(), upStatus);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000952 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED;
Gamze Abakaf59c0912019-04-19 08:24:28 +0000953 } else {
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700954 log.debug("Upstream and downstream data plane flows are installed successfully " +
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700955 "for {}/{}", subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700956 oltFlowService.processEapolFilteringObjectives(subscriberFlowInfo.getDevId(),
957 subscriberFlowInfo.getUniPort(),
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000958 tagInfo.getUpstreamBandwidthProfile(),
959 null, tagInfo.getPonCTag(), true);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700960 oltFlowService.processDhcpFilteringObjectives(subscriberFlowInfo.getDevId(),
961 subscriberFlowInfo.getUniPort(),
962 subscriberFlowInfo.getUpId(),
963 tagInfo, true, true);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000964
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700965 oltFlowService.processIgmpFilteringObjectives(subscriberFlowInfo.getDevId(),
966 subscriberFlowInfo.getUniPort(),
967 subscriberFlowInfo.getUpId(),
968 tagInfo, true, true);
Gustavo Silva5c492dd2021-02-12 10:21:11 -0300969
970 oltFlowService.processPPPoEDFilteringObjectives(subscriberFlowInfo.getDevId(),
971 subscriberFlowInfo.getUniPort(),
972 subscriberFlowInfo.getUpId(),
973 tagInfo, true, true);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700974 updateProgrammedSubscriber(new ConnectPoint(subscriberFlowInfo.getDevId(),
975 subscriberFlowInfo.getUniPort()),
976 tagInfo, true);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100977 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700978 post(new AccessDeviceEvent(type, subscriberFlowInfo.getDevId(),
979 deviceService.getPort(subscriberFlowInfo.getDevId(),
980 subscriberFlowInfo.getUniPort()),
981 tagInfo.getPonSTag(), tagInfo.getPonCTag(),
982 tagInfo.getTechnologyProfileId()));
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100983 }, oltInstallers);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100984 }
985
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000986 /**
987 * Checks the subscriber uni tag list and find the uni tag information.
988 * using the pon c tag, pon s tag and the technology profile id
989 * May return Optional<null>
990 *
991 * @param cp the connection point of the subscriber
992 * @param innerVlan pon c tag
993 * @param outerVlan pon s tag
994 * @param tpId the technology profile id
995 * @return the found uni tag information
996 */
997 private Optional<UniTagInformation> getUniTagInformation(ConnectPoint cp, VlanId innerVlan, VlanId outerVlan,
998 int tpId) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700999 log.debug("Getting uni tag information for cp: {}, innerVlan: {}, outerVlan: {}, tpId: {}",
1000 cp.toString(), innerVlan, outerVlan, tpId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001001 SubscriberAndDeviceInformation subInfo = getSubscriber(cp);
Gamze Abakaf59c0912019-04-19 08:24:28 +00001002 if (subInfo == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001003 log.warn("Subscriber information doesn't exist for the connect point {}", cp.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001004 return Optional.empty();
Gamze Abakaf59c0912019-04-19 08:24:28 +00001005 }
1006
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001007 List<UniTagInformation> uniTagList = subInfo.uniTagList();
1008 if (uniTagList == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001009 log.warn("Uni tag list is not found for the subscriber {} on {}", subInfo.id(), cp.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001010 return Optional.empty();
1011 }
Amit Ghoshe1d3f092018-10-09 19:44:33 +01001012
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001013 UniTagInformation service = null;
1014 for (UniTagInformation tagInfo : subInfo.uniTagList()) {
1015 if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag())
1016 && tpId == tagInfo.getTechnologyProfileId()) {
1017 service = tagInfo;
1018 break;
Andy Bavier160e8682019-05-07 18:32:22 -07001019 }
Gamze Abaka1efc80c2019-02-15 12:10:54 +00001020 }
Gamze Abaka1efc80c2019-02-15 12:10:54 +00001021
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001022 if (service == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001023 log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {} on {}",
1024 innerVlan, outerVlan, tpId, cp.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001025 return Optional.empty();
Gamze Abaka33feef52019-02-27 08:16:47 +00001026 }
1027
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001028 return Optional.of(service);
Amit Ghosh95e2f652017-08-23 12:49:46 +01001029 }
1030
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001031 /**
Jonathan Hart403372d2018-08-22 11:44:13 -07001032 * Creates trap flows for device, including DHCP and LLDP trap on NNI and
1033 * EAPOL trap on the UNIs, if device is present in Sadis config.
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001034 *
1035 * @param dev Device to look for
1036 */
Jonathan Hart403372d2018-08-22 11:44:13 -07001037 private void checkAndCreateDeviceFlows(Device dev) {
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001038 // check if this device is provisioned in Sadis
Gamze Abaka641fc072018-09-04 09:16:27 +00001039 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001040 log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001041
1042 if (deviceInfo != null) {
Jonathan Hart403372d2018-08-22 11:44:13 -07001043 // This is an OLT device as per Sadis, we create flows for UNI and NNI ports
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001044 for (Port p : deviceService.getPorts(dev.id())) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001045 if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001046 continue;
1047 }
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001048 if (isUniPort(dev, p)) {
Andrea Campanellaa2491782020-03-13 18:09:31 +01001049 if (!programmedSubs.containsKey(new ConnectPoint(dev.id(), p.number()))) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001050 log.info("Creating Eapol on {}/{}", dev.id(), p.number());
Andrea Campanellaa2491782020-03-13 18:09:31 +01001051 oltFlowService.processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null,
1052 VlanId.vlanId(EAPOL_DEFAULT_VLAN), true);
1053 } else {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001054 log.debug("Subscriber Eapol on {}/{} is already provisioned, not installing default",
1055 dev.id(), p.number());
Andrea Campanellaa2491782020-03-13 18:09:31 +01001056 }
Jonathan Hart403372d2018-08-22 11:44:13 -07001057 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001058 oltFlowService.processNniFilteringObjectives(dev.id(), p.number(), true);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001059 }
1060 }
1061 }
1062 }
1063
Jonathan Hart403372d2018-08-22 11:44:13 -07001064
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001065 /**
1066 * Get the uplink for of the OLT device.
Gamze Abakaad329652018-12-20 10:12:21 +00001067 * <p>
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001068 * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported
1069 * this logic needs to be changed
1070 *
1071 * @param dev Device to look for
1072 * @return The uplink Port of the OLT
1073 */
1074 private Port getUplinkPort(Device dev) {
1075 // check if this device is provisioned in Sadis
Gamze Abaka641fc072018-09-04 09:16:27 +00001076 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
Saurav Daseae48de2019-06-19 13:26:15 -07001077 log.trace("getUplinkPort: deviceInfo {}", deviceInfo);
Saurav Das82b8e6d2018-10-04 15:25:12 -07001078 if (deviceInfo == null) {
1079 log.warn("Device {} is not configured in SADIS .. cannot fetch device"
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001080 + " info", dev.id());
Saurav Das82b8e6d2018-10-04 15:25:12 -07001081 return null;
1082 }
1083 // Return the port that has been configured as the uplink port of this OLT in Sadis
kdarapuaa5da252020-04-10 15:58:05 +05301084 Optional<Port> optionalPort = deviceService.getPorts(dev.id()).stream()
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001085 .filter(port -> isNniPort(port) ||
1086 (port.number().toLong() == deviceInfo.uplinkPort()))
1087 .findFirst();
kdarapuaa5da252020-04-10 15:58:05 +05301088 if (optionalPort.isPresent()) {
1089 log.trace("getUplinkPort: Found port {}", optionalPort.get());
1090 return optionalPort.get();
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001091 }
1092
Saurav Daseae48de2019-06-19 13:26:15 -07001093 log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id());
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001094 return null;
1095 }
1096
1097 /**
1098 * Return the subscriber on a port.
1099 *
Matteo Scandolo962a6ad2018-12-11 15:39:42 -08001100 * @param cp ConnectPoint on which to find the subscriber
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001101 * @return subscriber if found else null
1102 */
Matteo Scandolo962a6ad2018-12-11 15:39:42 -08001103 SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) {
1104 Port port = deviceService.getPort(cp);
1105 checkNotNull(port, "Invalid connect point");
1106 String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001107 return subsService.get(portName);
1108 }
1109
Gamze Abakaad329652018-12-20 10:12:21 +00001110 /**
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001111 * Checks whether the given port of the device is a uni port or not.
1112 *
1113 * @param d the access device
1114 * @param p the port of the device
1115 * @return true if the given port is a uni port
Gamze Abakaad329652018-12-20 10:12:21 +00001116 */
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001117 private boolean isUniPort(Device d, Port p) {
1118 Port ulPort = getUplinkPort(d);
1119 if (ulPort != null) {
1120 return (ulPort.number().toLong() != p.number().toLong());
1121 }
Thomas Lee Sd7735f92020-02-20 19:21:47 +05301122 //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null
1123 //checks whether the port name starts with nni- which is the signature of an NNI Port
1124 if (p.annotations().value(AnnotationKeys.PORT_NAME) != null &&
1125 p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) {
1126 log.error("NNI port number {} is not matching with configured value", p.number().toLong());
1127 return false;
1128 }
1129 return true;
Jonathan Hart1d34c8b2018-05-05 15:37:28 -07001130 }
1131
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001132 /**
1133 * Gets the given device details from SADIS.
1134 * If the device is not found, returns null
1135 *
1136 * @param dev the access device
1137 * @return the olt information
1138 */
Jonathan Hart4c538002018-08-23 10:11:54 -07001139 private SubscriberAndDeviceInformation getOltInfo(Device dev) {
1140 String devSerialNo = dev.serialNumber();
Gamze Abaka641fc072018-09-04 09:16:27 +00001141 return subsService.get(devSerialNo);
Jonathan Hart4c538002018-08-23 10:11:54 -07001142 }
1143
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001144 // Custom-built function, when the device is not available we need a fallback mechanism
1145 private boolean isLocalLeader(DeviceId deviceId) {
1146 if (!mastershipService.isLocalMaster(deviceId)) {
1147 // When the device is available we just check the mastership
1148 if (deviceService.isAvailable(deviceId)) {
1149 return false;
1150 }
1151 // Fallback with Leadership service - device id is used as topic
1152 NodeId leader = leadershipService.runForLeadership(
1153 deviceId.toString()).leaderNodeId();
1154 // Verify if this node is the leader
1155 return clusterService.getLocalNode().id().equals(leader);
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001156 }
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001157 return true;
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001158 }
1159
kdarapuaa5da252020-04-10 15:58:05 +05301160 private boolean isNniPort(Port port) {
1161 if (port.annotations().keys().contains(AnnotationKeys.PORT_NAME)) {
1162 return port.annotations().value(AnnotationKeys.PORT_NAME).contains(NNI);
1163 }
1164 return false;
1165 }
1166
alshabibf0e7e702015-05-30 18:22:36 -07001167 private class InternalDeviceListener implements DeviceListener {
Saurav Dasa9d5f442019-03-06 19:32:48 -08001168 private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet();
1169
alshabibf0e7e702015-05-30 18:22:36 -07001170 @Override
1171 public void event(DeviceEvent event) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001172 eventExecutor.execute(() -> {
1173 DeviceId devId = event.subject().id();
1174 Device dev = event.subject();
Gamze Abaka838d8142019-02-21 07:06:55 +00001175 Port port = event.port();
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001176 DeviceEvent.Type eventType = event.type();
Jonathan Hart4c538002018-08-23 10:11:54 -07001177
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001178 if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) ||
1179 DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) ||
1180 DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001181 return;
1182 }
Jonathan Hart4c538002018-08-23 10:11:54 -07001183
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001184 boolean isLocalLeader = isLocalLeader(devId);
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001185 // Only handle the event if the device belongs to us
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001186 if (!isLocalLeader && event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED)
1187 && !deviceService.isAvailable(devId) && deviceService.getPorts(devId).isEmpty()) {
1188 log.info("Cleaning local state for non master instance upon " +
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001189 "device disconnection {}", devId);
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001190 // Since no mastership of the device is present upon disconnection
1191 // the method in the FlowRuleManager only empties the local copy
1192 // of the DeviceFlowTable thus this method needs to get called
1193 // on every instance, see how it's done in the InternalDeviceListener
1194 // in FlowRuleManager: no mastership check for purgeOnDisconnection
Andrea Campanella3f34c992020-07-15 10:54:10 +02001195 handleDeviceDisconnection(dev, false, false);
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001196 return;
1197 } else if (!isLocalLeader) {
Andrea Campanella506df202020-05-21 10:26:12 +02001198 log.debug("Not handling event because instance is not leader for {}", devId);
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001199 return;
1200 }
1201
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001202 log.debug("OLT got {} event for {}/{}", eventType, event.subject(), event.port());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001203
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001204 if (getOltInfo(dev) == null) {
Saurav Dasa9d5f442019-03-06 19:32:48 -08001205 // it's possible that we got an event for a previously
1206 // programmed OLT that is no longer available in SADIS
1207 // we let such events go through
1208 if (!programmedDevices.contains(devId)) {
1209 log.warn("No device info found for {}, this is either "
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001210 + "not an OLT or not known to sadis", dev);
Saurav Dasa9d5f442019-03-06 19:32:48 -08001211 return;
1212 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001213 }
Jonathan Hart4c538002018-08-23 10:11:54 -07001214
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001215 switch (event.type()) {
1216 //TODO: Port handling and bookkeeping should be improved once
1217 // olt firmware handles correct behaviour.
1218 case PORT_ADDED:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001219 if (!deviceService.isAvailable(devId)) {
1220 log.warn("Received {} for disconnected device {}, ignoring", event, devId);
1221 return;
1222 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001223 if (isUniPort(dev, port)) {
1224 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port));
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001225
1226 if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001227 log.info("eapol will be sent for port added {}/{}", devId, port);
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001228 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
1229 null,
Andrea Campanella3f34c992020-07-15 10:54:10 +02001230 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
1231 true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001232 }
1233 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001234 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
1235 if (deviceInfo != null) {
1236 oltFlowService.processNniFilteringObjectives(dev.id(), port.number(), true);
1237 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001238 }
1239 break;
1240 case PORT_REMOVED:
Gamze Abaka838d8142019-02-21 07:06:55 +00001241 if (isUniPort(dev, port)) {
Andrea Campanellacf0e3052020-08-27 11:05:39 +02001242 // if no subscriber is provisioned we need to remove the default EAPOL
1243 // if a subscriber was provisioned the default EAPOL will not be there and we can skip.
1244 // The EAPOL with subscriber tag will be removed by removeSubscriber call.
1245 Collection<? extends UniTagInformation> uniTagInformationSet =
1246 programmedSubs.get(new ConnectPoint(port.element().id(), port.number())).value();
1247 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001248 log.info("No subscriber provisioned on port {}/{} in PORT_REMOVED event, " +
1249 "removing default EAPOL flow", devId, port);
Andrea Campanellacf0e3052020-08-27 11:05:39 +02001250 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
1251 null,
1252 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
1253 false);
1254 } else {
1255 removeSubscriber(new ConnectPoint(devId, port.number()));
1256 }
Andy Bavier160e8682019-05-07 18:32:22 -07001257
Gamze Abaka838d8142019-02-21 07:06:55 +00001258 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port));
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001259 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001260 break;
1261 case PORT_UPDATED:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001262 if (!deviceService.isAvailable(devId)) {
1263 log.warn("Received {} for disconnected device {}, ignoring", event, devId);
1264 return;
1265 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001266 if (!isUniPort(dev, port)) {
Saurav Das9da7d522020-03-23 19:14:35 -07001267 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
1268 if (deviceInfo != null && port.isEnabled()) {
1269 log.debug("NNI dev/port {}/{} enabled", dev.id(),
1270 port.number());
1271 oltFlowService.processNniFilteringObjectives(dev.id(),
1272 port.number(), true);
1273 }
1274 return;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001275 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001276 ConnectPoint cp = new ConnectPoint(devId, port.number());
1277 Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value();
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001278 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Saurav Dasb776aef2020-03-09 14:29:46 -07001279 if (!port.number().equals(PortNumber.LOCAL)) {
Matteo Scandolo3a037a32020-04-01 12:17:50 -07001280 log.info("eapol will be {} for dev/port updated {}/{} with default vlan {}",
Saurav Dasb776aef2020-03-09 14:29:46 -07001281 (port.isEnabled()) ? "added" : "removed",
Matteo Scandolo3a037a32020-04-01 12:17:50 -07001282 devId, port.number(), EAPOL_DEFAULT_VLAN);
Matteo Scandolo27c471c2020-02-11 16:41:53 -08001283 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001284 null,
1285 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
1286 port.isEnabled());
1287 }
1288 } else {
Saurav Dasb776aef2020-03-09 14:29:46 -07001289 log.info("eapol will be {} for dev/port updated {}/{}",
1290 (port.isEnabled()) ? "added" : "removed",
1291 devId, port.number());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001292 uniTagInformationSet.forEach(uniTag ->
1293 oltFlowService.processEapolFilteringObjectives(devId, port.number(),
1294 uniTag.getUpstreamBandwidthProfile(), null,
1295 uniTag.getPonCTag(), port.isEnabled()));
1296 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001297 if (port.isEnabled()) {
Gamze Abaka838d8142019-02-21 07:06:55 +00001298 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port));
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001299 } else {
Gamze Abaka838d8142019-02-21 07:06:55 +00001300 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port));
Jonathan Hart1d34c8b2018-05-05 15:37:28 -07001301 }
alshabibbb83aa22016-02-10 15:08:23 -08001302 break;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001303 case DEVICE_ADDED:
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001304 handleDeviceConnection(dev, true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001305 break;
1306 case DEVICE_REMOVED:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001307 handleDeviceDisconnection(dev, true, true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001308 break;
1309 case DEVICE_AVAILABILITY_CHANGED:
1310 if (deviceService.isAvailable(devId)) {
Saurav Dasbd3b6712020-03-31 23:28:35 -07001311 log.info("Handling available device: {}", dev.id());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001312 handleDeviceConnection(dev, false);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001313 } else {
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301314 if (deviceService.getPorts(devId).isEmpty()) {
Saurav Dasbd3b6712020-03-31 23:28:35 -07001315 log.info("Handling controlled device disconnection .. "
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001316 + "flushing all state for dev:{}", devId);
Andrea Campanella3f34c992020-07-15 10:54:10 +02001317 handleDeviceDisconnection(dev, true, false);
Saurav Dasbd3b6712020-03-31 23:28:35 -07001318 } else {
1319 log.info("Disconnected device has available ports .. "
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001320 + "assuming temporary disconnection, "
1321 + "retaining state for device {}", devId);
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301322 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001323 }
1324 break;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001325 default:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001326 log.debug("Not handling event {}", event);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001327 return;
1328 }
1329 });
alshabibf0e7e702015-05-30 18:22:36 -07001330 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001331
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001332 private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) {
1333 deviceService.getPorts(device.id()).stream()
1334 .filter(p -> !PortNumber.LOCAL.equals(p.number()))
1335 .filter(p -> isUniPort(device, p))
1336 .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p)));
1337 }
1338
Andrea Campanella3f34c992020-07-15 10:54:10 +02001339 private void handleDeviceDisconnection(Device device, boolean sendDisconnectedEvent, boolean sendUniEvent) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001340 programmedDevices.remove(device.id());
1341 removeAllSubscribers(device.id());
Andrea Campanella600d2e22020-06-22 11:00:31 +02001342 //Handle case where OLT disconnects during subscriber provisioning
Andrea Campanella7a1d7e72020-11-05 10:40:10 +01001343 pendingSubscribersForDevice.remove(device.id());
Andrea Campanella600d2e22020-06-22 11:00:31 +02001344 oltFlowService.clearDeviceState(device.id());
1345
1346 //Complete meter and flow purge
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301347 flowRuleService.purgeFlowRules(device.id());
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001348 oltMeterService.clearMeters(device.id());
Andrea Campanella3f34c992020-07-15 10:54:10 +02001349 if (sendDisconnectedEvent) {
1350 post(new AccessDeviceEvent(
1351 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(),
1352 null, null, null));
1353 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001354 if (sendUniEvent) {
1355 sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED);
Gamze Abaka838d8142019-02-21 07:06:55 +00001356 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001357 }
1358
1359 private void handleDeviceConnection(Device dev, boolean sendUniEvent) {
1360 post(new AccessDeviceEvent(
1361 AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(),
1362 null, null, null));
1363 programmedDevices.add(dev.id());
1364 checkAndCreateDeviceFlows(dev);
1365 if (sendUniEvent) {
1366 sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED);
1367 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001368 }
Gamze Abakada282b42019-03-11 13:16:48 +00001369
1370 private void removeAllSubscribers(DeviceId deviceId) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001371 List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream()
1372 .filter(e -> e.getKey().deviceId().equals(deviceId))
1373 .collect(toList());
Gamze Abakada282b42019-03-11 13:16:48 +00001374
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001375 subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue()));
Gamze Abakada282b42019-03-11 13:16:48 +00001376 }
Gamze Abaka641fc072018-09-04 09:16:27 +00001377
Gamze Abaka641fc072018-09-04 09:16:27 +00001378 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001379
1380 private class InternalClusterListener implements ClusterEventListener {
1381
1382 @Override
1383 public void event(ClusterEvent event) {
1384 if (event.type() == ClusterEvent.Type.INSTANCE_READY) {
1385 hasher.addServer(event.subject().id());
1386 }
1387 if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
1388 hasher.removeServer(event.subject().id());
1389 }
1390 }
1391 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001392
Hardik Windlass395ff372019-06-13 05:16:00 +00001393}