blob: 408004cfa997a49b71f48c01fb1c6f5e28c59861 [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);
alshabibbf23a1f2016-01-14 17:27:11 -0800632
alshabib4ceaed32016-03-03 18:00:58 -0800633 flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() {
634 @Override
635 public void onSuccess(Objective objective) {
636 upFuture.complete(null);
637 }
alshabibbf23a1f2016-01-14 17:27:11 -0800638
alshabib4ceaed32016-03-03 18:00:58 -0800639 @Override
640 public void onError(Objective objective, ObjectiveError error) {
641 upFuture.complete(error);
642 }
643 }));
644
645 flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() {
646 @Override
647 public void onSuccess(Objective objective) {
648 downFuture.complete(null);
649 }
650
651 @Override
652 public void onError(Objective objective, ObjectiveError error) {
653 downFuture.complete(error);
654 }
655 }));
alshabibbf23a1f2016-01-14 17:27:11 -0800656
657 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000658 AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED;
alshabibbf23a1f2016-01-14 17:27:11 -0800659 if (upStatus == null && downStatus == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000660 log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {}, and" +
661 "Device/Port{}", uniTag.getPonCTag(), uniTag.getPonSTag(),
662 uniTag.getTechnologyProfileId(), subscriberPort);
663 updateProgrammedSubscriber(new ConnectPoint(deviceId, subscriberPort), uniTag, false);
alshabibbf23a1f2016-01-14 17:27:11 -0800664 } else if (downStatus != null) {
665 log.error("Subscriber with vlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000666 "on port {} failed downstream uninstallation: {}",
667 subscriberVlan, deviceId, subscriberPort, downStatus);
668 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED;
alshabibbf23a1f2016-01-14 17:27:11 -0800669 } else if (upStatus != null) {
670 log.error("Subscriber with vlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000671 "on port {} failed upstream uninstallation: {}",
672 subscriberVlan, deviceId, subscriberPort, upStatus);
673 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED;
alshabibbf23a1f2016-01-14 17:27:11 -0800674 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000675 Port port = deviceService.getPort(deviceId, subscriberPort);
676 post(new AccessDeviceEvent(type, deviceId, port, deviceVlan, subscriberVlan,
677 uniTag.getTechnologyProfileId()));
alshabibbf23a1f2016-01-14 17:27:11 -0800678 }, oltInstallers);
Jonathan Harte533a422015-10-20 17:31:24 -0700679 }
680
Gamze Abaka838d8142019-02-21 07:06:55 +0000681 /**
Gamze Abaka33feef52019-02-27 08:16:47 +0000682 * Adds subscriber vlan flows, dhcp, eapol and igmp trap flows for the related uni port.
Gamze Abaka838d8142019-02-21 07:06:55 +0000683 *
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000684 * @param connectPoint the connection point of the subscriber
685 * @param uplinkPort uplink port of the OLT (the nni port)
686 * @param sub subscriber information that includes s, c tags, tech profile and bandwidth profile references
Gamze Abaka838d8142019-02-21 07:06:55 +0000687 */
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000688 private void provisionUniTagList(ConnectPoint connectPoint, PortNumber uplinkPort,
689 SubscriberAndDeviceInformation sub) {
Gamze Abaka641fc072018-09-04 09:16:27 +0000690
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700691 log.debug("Provisioning vlans for subscriber on dev/port: {}", connectPoint.toString());
692 if (log.isTraceEnabled()) {
693 log.trace("Subscriber informations {}", sub);
694 }
Gamze Abaka641fc072018-09-04 09:16:27 +0000695
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000696 if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700697 log.warn("Unitaglist doesn't exist for the subscriber {} on dev/port {}",
698 sub.id(), connectPoint.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000699 return;
700 }
Gamze Abaka641fc072018-09-04 09:16:27 +0000701
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000702 DeviceId deviceId = connectPoint.deviceId();
703 PortNumber subscriberPort = connectPoint.port();
Gamze Abaka641fc072018-09-04 09:16:27 +0000704
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000705 for (UniTagInformation uniTag : sub.uniTagList()) {
706 handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, uniTag);
707 }
708 }
alshabib3ea82642016-01-12 18:06:53 -0800709
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000710 /**
711 * Finds the uni tag information and provisions the found information.
712 * If the uni tag information is not found, returns
713 *
714 * @param deviceId the access device id
715 * @param uplinkPort the nni port
716 * @param subscriberPort the uni port
717 * @param innerVlan the pon c tag
718 * @param outerVlan the pon s tag
719 * @param tpId the technology profile id
720 */
721 private void provisionUniTagInformation(DeviceId deviceId, PortNumber uplinkPort,
722 PortNumber subscriberPort,
723 VlanId innerVlan,
724 VlanId outerVlan,
725 Integer tpId) {
Jonathan Harte533a422015-10-20 17:31:24 -0700726
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000727 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
728 Optional<UniTagInformation> gotTagInformation = getUniTagInformation(cp, innerVlan, outerVlan, tpId);
729 if (!gotTagInformation.isPresent()) {
730 return;
731 }
732 UniTagInformation tagInformation = gotTagInformation.get();
733 handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, tagInformation);
734 }
alshabib3ea82642016-01-12 18:06:53 -0800735
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000736 private void updateProgrammedSubscriber(ConnectPoint connectPoint, UniTagInformation tagInformation, Boolean add) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800737 if (add) {
738 programmedSubs.put(connectPoint, tagInformation);
739 } else {
740 programmedSubs.remove(connectPoint, tagInformation);
741 }
Jonathan Harte533a422015-10-20 17:31:24 -0700742 }
743
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000744 /**
745 * Installs a uni tag information flow.
746 *
747 * @param deviceId the access device id
748 * @param uplinkPort the nni port
749 * @param subscriberPort the uni port
750 * @param tagInfo the uni tag information
751 */
752 private void handleSubscriberFlows(DeviceId deviceId, PortNumber uplinkPort, PortNumber subscriberPort,
753 UniTagInformation tagInfo) {
754
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700755 log.debug("Provisioning vlan-based flows for the uniTagInformation {} on dev/port {}/{}",
756 tagInfo, deviceId, subscriberPort);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000757
758 Port port = deviceService.getPort(deviceId, subscriberPort);
759
760 if (multicastServiceName.equals(tagInfo.getServiceName())) {
761 // IGMP flows are taken care of along with VOD service
762 // Please note that for each service, Subscriber Registered event will be sent
763 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED,
764 deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(),
765 tagInfo.getTechnologyProfileId()));
766 return;
Gamze Abaka641fc072018-09-04 09:16:27 +0000767 }
768
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000769 BandwidthProfileInformation upstreamBpInfo =
770 getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile());
771 BandwidthProfileInformation downstreamBpInfo =
772 getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700773 if (upstreamBpInfo == null) {
774 log.warn("No meter installed since no Upstream BW Profile definition found for "
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700775 + "ctag {} stag {} tpId {} and dev/port: {}/{}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700776 tagInfo.getPonCTag(), tagInfo.getPonSTag(),
777 tagInfo.getTechnologyProfileId(), deviceId,
778 subscriberPort);
779 return;
780 }
781 if (downstreamBpInfo == null) {
782 log.warn("No meter installed since no Downstream BW Profile definition found for "
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700783 + "ctag {} stag {} tpId {} and dev/port: {}/{}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700784 tagInfo.getPonCTag(), tagInfo.getPonSTag(),
785 tagInfo.getTechnologyProfileId(), deviceId,
786 subscriberPort);
787 return;
788 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000789
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700790 // check for meterIds for the upstream and downstream bandwidth profiles
791 MeterId upMeterId = oltMeterService
792 .getMeterIdFromBpMapping(deviceId, upstreamBpInfo.id());
793 MeterId downMeterId = oltMeterService
794 .getMeterIdFromBpMapping(deviceId, downstreamBpInfo.id());
795 SubscriberFlowInfo fi = new SubscriberFlowInfo(deviceId, uplinkPort, subscriberPort,
796 tagInfo, downMeterId, upMeterId,
797 downstreamBpInfo.id(), upstreamBpInfo.id());
798
799 if (upMeterId != null && downMeterId != null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700800 log.debug("Meters are existing for upstream {} and downstream {} on dev/port {}/{}",
801 upstreamBpInfo.id(), downstreamBpInfo.id(), deviceId, subscriberPort);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700802 handleSubFlowsWithMeters(fi);
803 } else {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700804 log.debug("Adding {} on {}/{} to pending subs", fi, deviceId, subscriberPort);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700805 // one or both meters are not ready. It's possible they are in the process of being
806 // created for other subscribers that share the same bandwidth profile.
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100807 pendingSubscribersForDevice.compute(deviceId, (id, queue) -> {
808 if (queue == null) {
809 queue = new LinkedBlockingQueue<>();
810 }
811 queue.add(fi);
812 log.info("Added {} to pending subscribers on {}/{}", fi, deviceId, subscriberPort);
813 return queue;
814 });
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700815
816 // queue up the meters to be created
817 if (upMeterId == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700818 log.debug("Missing meter for upstream {} on {}/{}", upstreamBpInfo.id(), deviceId, subscriberPort);
Andrea Campanella600d2e22020-06-22 11:00:31 +0200819 checkAndCreateDevMeter(deviceId, upstreamBpInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700820 }
821 if (downMeterId == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700822 log.debug("Missing meter for downstream {} on {}/{}", downstreamBpInfo.id(), deviceId, subscriberPort);
Andrea Campanella600d2e22020-06-22 11:00:31 +0200823 checkAndCreateDevMeter(deviceId, downstreamBpInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700824 }
825 }
826 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200827 private void checkAndCreateDevMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Andrea Campanellad1e26642020-10-23 12:08:32 +0200828 //If false the meter is already being installed, skipping installation
829 if (!oltMeterService.checkAndAddPendingMeter(deviceId, bwpInfo)) {
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700830 return;
831 }
Andrea Campanella600d2e22020-06-22 11:00:31 +0200832 createMeter(deviceId, bwpInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700833 }
834
Andrea Campanella600d2e22020-06-22 11:00:31 +0200835 private void createMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700836 log.debug("Creating Meter with {} on {}", bwpInfo, deviceId);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700837 CompletableFuture<Object> meterFuture = new CompletableFuture<>();
Andrea Campanella3ce4d282020-06-09 13:46:58 +0200838
Andrea Campanella600d2e22020-06-22 11:00:31 +0200839 MeterId meterId = oltMeterService.createMeter(deviceId, bwpInfo,
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700840 meterFuture);
841
842 meterFuture.thenAcceptAsync(result -> {
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100843 BlockingQueue<SubscriberFlowInfo> queue = pendingSubscribersForDevice.get(deviceId);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700844 // iterate through the subscribers on hold
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100845 if (queue != null) {
846 while (true) {
847 //TODO this might return the reference and not the actual object so
848 // it can be actually swapped underneath us.
849 SubscriberFlowInfo fi = queue.peek();
850 if (fi == null) {
851 log.debug("No more subscribers pending on {}", deviceId);
852 break;
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700853 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100854 if (result == null) {
855 // meter install sent to device
856 log.debug("Meter {} installed for bw {} on {}", meterId, bwpInfo, deviceId);
857
858 MeterId upMeterId = oltMeterService
859 .getMeterIdFromBpMapping(deviceId, fi.getUpBpInfo());
860 MeterId downMeterId = oltMeterService
861 .getMeterIdFromBpMapping(deviceId, fi.getDownBpInfo());
862 if (upMeterId != null && downMeterId != null) {
863 log.debug("Provisioning subscriber after meter {} " +
864 "installation and both meters are present " +
865 "upstream {} and downstream {} on {}/{}",
866 meterId, upMeterId, downMeterId, deviceId, fi.getUniPort());
867 // put in the meterIds because when fi was first
868 // created there may or may not have been a meterId
869 // depending on whether the meter was created or
870 // not at that time.
871 fi.setUpMeterId(upMeterId);
872 fi.setDownMeterId(downMeterId);
873 handleSubFlowsWithMeters(fi);
874 queue.remove(fi);
875 }
876 oltMeterService.removeFromPendingMeters(deviceId, bwpInfo);
877 } else {
878 // meter install failed
879 log.error("Addition of subscriber {} on {}/{} failed due to meter " +
880 "{} with result {}", fi, deviceId, fi.getUniPort(),
881 meterId, result);
882 queue.remove(fi);
883 oltMeterService.removeFromPendingMeters(deviceId, bwpInfo);
884 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700885 }
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100886 } else {
887 log.info("No pending subscribers on {}", deviceId);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700888 }
889 });
Andrea Campanella7a1d7e72020-11-05 10:40:10 +0100890
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700891 }
892 /**
893 * Add subscriber flows given meter information for both upstream and
894 * downstream directions.
895 *
896 * @param subscriberFlowInfo relevant information for subscriber
897 */
898 private void handleSubFlowsWithMeters(SubscriberFlowInfo subscriberFlowInfo) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700899 log.debug("Provisioning subscriber flows on {}/{} based on {}",
900 subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort(), subscriberFlowInfo);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700901 UniTagInformation tagInfo = subscriberFlowInfo.getTagInfo();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000902 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>();
903 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>();
Gamze Abakaf59c0912019-04-19 08:24:28 +0000904
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700905 ForwardingObjective.Builder upFwd =
906 oltFlowService.createUpBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(),
907 subscriberFlowInfo.getUpId(), subscriberFlowInfo.getTagInfo());
908 flowObjectiveService.forward(subscriberFlowInfo.getDevId(), upFwd.add(new ObjectiveContext() {
909 @Override
910 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700911 log.debug("Upstream HSIA flow {} installed successfully on {}/{}",
912 subscriberFlowInfo, subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700913 upFuture.complete(null);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000914 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000915
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700916 @Override
917 public void onError(Objective objective, ObjectiveError error) {
918 upFuture.complete(error);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000919 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700920 }));
921
922 ForwardingObjective.Builder downFwd =
923 oltFlowService.createDownBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(),
924 subscriberFlowInfo.getDownId(), subscriberFlowInfo.getTagInfo());
925 flowObjectiveService.forward(subscriberFlowInfo.getDevId(), downFwd.add(new ObjectiveContext() {
926 @Override
927 public void onSuccess(Objective objective) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700928 log.debug("Downstream HSIA flow {} installed successfully on {}/{}",
929 subscriberFlowInfo, subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700930 downFuture.complete(null);
931 }
932
933 @Override
934 public void onError(Objective objective, ObjectiveError error) {
935 downFuture.complete(error);
936 }
937 }));
Gamze Abakaf59c0912019-04-19 08:24:28 +0000938
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100939 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000940 AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED;
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100941 if (downStatus != null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700942 log.error("Flow with innervlan {} and outerVlan {} on {}/{} failed downstream installation: {}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700943 tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(),
944 subscriberFlowInfo.getUniPort(), downStatus);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000945 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED;
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100946 } else if (upStatus != null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700947 log.error("Flow with innervlan {} and outerVlan {} on {}/{} failed downstream installation: {}",
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700948 tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(),
949 subscriberFlowInfo.getUniPort(), upStatus);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000950 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED;
Gamze Abakaf59c0912019-04-19 08:24:28 +0000951 } else {
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700952 log.debug("Upstream and downstream data plane flows are installed successfully " +
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700953 "for {}/{}", subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort());
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700954 oltFlowService.processEapolFilteringObjectives(subscriberFlowInfo.getDevId(),
955 subscriberFlowInfo.getUniPort(),
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000956 tagInfo.getUpstreamBandwidthProfile(),
957 null, tagInfo.getPonCTag(), true);
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700958 oltFlowService.processDhcpFilteringObjectives(subscriberFlowInfo.getDevId(),
959 subscriberFlowInfo.getUniPort(),
960 subscriberFlowInfo.getUpId(),
961 tagInfo, true, true);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000962
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700963 oltFlowService.processIgmpFilteringObjectives(subscriberFlowInfo.getDevId(),
964 subscriberFlowInfo.getUniPort(),
965 subscriberFlowInfo.getUpId(),
966 tagInfo, true, true);
967 updateProgrammedSubscriber(new ConnectPoint(subscriberFlowInfo.getDevId(),
968 subscriberFlowInfo.getUniPort()),
969 tagInfo, true);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100970 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -0700971 post(new AccessDeviceEvent(type, subscriberFlowInfo.getDevId(),
972 deviceService.getPort(subscriberFlowInfo.getDevId(),
973 subscriberFlowInfo.getUniPort()),
974 tagInfo.getPonSTag(), tagInfo.getPonCTag(),
975 tagInfo.getTechnologyProfileId()));
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100976 }, oltInstallers);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100977 }
978
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000979 /**
980 * Checks the subscriber uni tag list and find the uni tag information.
981 * using the pon c tag, pon s tag and the technology profile id
982 * May return Optional<null>
983 *
984 * @param cp the connection point of the subscriber
985 * @param innerVlan pon c tag
986 * @param outerVlan pon s tag
987 * @param tpId the technology profile id
988 * @return the found uni tag information
989 */
990 private Optional<UniTagInformation> getUniTagInformation(ConnectPoint cp, VlanId innerVlan, VlanId outerVlan,
991 int tpId) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700992 log.debug("Getting uni tag information for cp: {}, innerVlan: {}, outerVlan: {}, tpId: {}",
993 cp.toString(), innerVlan, outerVlan, tpId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000994 SubscriberAndDeviceInformation subInfo = getSubscriber(cp);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000995 if (subInfo == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -0700996 log.warn("Subscriber information doesn't exist for the connect point {}", cp.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000997 return Optional.empty();
Gamze Abakaf59c0912019-04-19 08:24:28 +0000998 }
999
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001000 List<UniTagInformation> uniTagList = subInfo.uniTagList();
1001 if (uniTagList == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001002 log.warn("Uni tag list is not found for the subscriber {} on {}", subInfo.id(), cp.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001003 return Optional.empty();
1004 }
Amit Ghoshe1d3f092018-10-09 19:44:33 +01001005
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001006 UniTagInformation service = null;
1007 for (UniTagInformation tagInfo : subInfo.uniTagList()) {
1008 if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag())
1009 && tpId == tagInfo.getTechnologyProfileId()) {
1010 service = tagInfo;
1011 break;
Andy Bavier160e8682019-05-07 18:32:22 -07001012 }
Gamze Abaka1efc80c2019-02-15 12:10:54 +00001013 }
Gamze Abaka1efc80c2019-02-15 12:10:54 +00001014
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001015 if (service == null) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001016 log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {} on {}",
1017 innerVlan, outerVlan, tpId, cp.toString());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001018 return Optional.empty();
Gamze Abaka33feef52019-02-27 08:16:47 +00001019 }
1020
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001021 return Optional.of(service);
Amit Ghosh95e2f652017-08-23 12:49:46 +01001022 }
1023
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001024 /**
Jonathan Hart403372d2018-08-22 11:44:13 -07001025 * Creates trap flows for device, including DHCP and LLDP trap on NNI and
1026 * EAPOL trap on the UNIs, if device is present in Sadis config.
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001027 *
1028 * @param dev Device to look for
1029 */
Jonathan Hart403372d2018-08-22 11:44:13 -07001030 private void checkAndCreateDeviceFlows(Device dev) {
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001031 // check if this device is provisioned in Sadis
Gamze Abaka641fc072018-09-04 09:16:27 +00001032 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001033 log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001034
1035 if (deviceInfo != null) {
Jonathan Hart403372d2018-08-22 11:44:13 -07001036 // This is an OLT device as per Sadis, we create flows for UNI and NNI ports
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001037 for (Port p : deviceService.getPorts(dev.id())) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001038 if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001039 continue;
1040 }
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001041 if (isUniPort(dev, p)) {
Andrea Campanellaa2491782020-03-13 18:09:31 +01001042 if (!programmedSubs.containsKey(new ConnectPoint(dev.id(), p.number()))) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001043 log.info("Creating Eapol on {}/{}", dev.id(), p.number());
Andrea Campanellaa2491782020-03-13 18:09:31 +01001044 oltFlowService.processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null,
1045 VlanId.vlanId(EAPOL_DEFAULT_VLAN), true);
1046 } else {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001047 log.debug("Subscriber Eapol on {}/{} is already provisioned, not installing default",
1048 dev.id(), p.number());
Andrea Campanellaa2491782020-03-13 18:09:31 +01001049 }
Jonathan Hart403372d2018-08-22 11:44:13 -07001050 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001051 oltFlowService.processNniFilteringObjectives(dev.id(), p.number(), true);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001052 }
1053 }
1054 }
1055 }
1056
Jonathan Hart403372d2018-08-22 11:44:13 -07001057
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001058 /**
1059 * Get the uplink for of the OLT device.
Gamze Abakaad329652018-12-20 10:12:21 +00001060 * <p>
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001061 * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported
1062 * this logic needs to be changed
1063 *
1064 * @param dev Device to look for
1065 * @return The uplink Port of the OLT
1066 */
1067 private Port getUplinkPort(Device dev) {
1068 // check if this device is provisioned in Sadis
Gamze Abaka641fc072018-09-04 09:16:27 +00001069 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
Saurav Daseae48de2019-06-19 13:26:15 -07001070 log.trace("getUplinkPort: deviceInfo {}", deviceInfo);
Saurav Das82b8e6d2018-10-04 15:25:12 -07001071 if (deviceInfo == null) {
1072 log.warn("Device {} is not configured in SADIS .. cannot fetch device"
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001073 + " info", dev.id());
Saurav Das82b8e6d2018-10-04 15:25:12 -07001074 return null;
1075 }
1076 // Return the port that has been configured as the uplink port of this OLT in Sadis
kdarapuaa5da252020-04-10 15:58:05 +05301077 Optional<Port> optionalPort = deviceService.getPorts(dev.id()).stream()
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001078 .filter(port -> isNniPort(port) ||
1079 (port.number().toLong() == deviceInfo.uplinkPort()))
1080 .findFirst();
kdarapuaa5da252020-04-10 15:58:05 +05301081 if (optionalPort.isPresent()) {
1082 log.trace("getUplinkPort: Found port {}", optionalPort.get());
1083 return optionalPort.get();
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001084 }
1085
Saurav Daseae48de2019-06-19 13:26:15 -07001086 log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id());
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001087 return null;
1088 }
1089
1090 /**
1091 * Return the subscriber on a port.
1092 *
Matteo Scandolo962a6ad2018-12-11 15:39:42 -08001093 * @param cp ConnectPoint on which to find the subscriber
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001094 * @return subscriber if found else null
1095 */
Matteo Scandolo962a6ad2018-12-11 15:39:42 -08001096 SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) {
1097 Port port = deviceService.getPort(cp);
1098 checkNotNull(port, "Invalid connect point");
1099 String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001100 return subsService.get(portName);
1101 }
1102
Gamze Abakaad329652018-12-20 10:12:21 +00001103 /**
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001104 * Checks whether the given port of the device is a uni port or not.
1105 *
1106 * @param d the access device
1107 * @param p the port of the device
1108 * @return true if the given port is a uni port
Gamze Abakaad329652018-12-20 10:12:21 +00001109 */
Amit Ghosh1ed9aef2018-07-17 17:08:16 +01001110 private boolean isUniPort(Device d, Port p) {
1111 Port ulPort = getUplinkPort(d);
1112 if (ulPort != null) {
1113 return (ulPort.number().toLong() != p.number().toLong());
1114 }
Thomas Lee Sd7735f92020-02-20 19:21:47 +05301115 //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null
1116 //checks whether the port name starts with nni- which is the signature of an NNI Port
1117 if (p.annotations().value(AnnotationKeys.PORT_NAME) != null &&
1118 p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) {
1119 log.error("NNI port number {} is not matching with configured value", p.number().toLong());
1120 return false;
1121 }
1122 return true;
Jonathan Hart1d34c8b2018-05-05 15:37:28 -07001123 }
1124
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001125 /**
1126 * Gets the given device details from SADIS.
1127 * If the device is not found, returns null
1128 *
1129 * @param dev the access device
1130 * @return the olt information
1131 */
Jonathan Hart4c538002018-08-23 10:11:54 -07001132 private SubscriberAndDeviceInformation getOltInfo(Device dev) {
1133 String devSerialNo = dev.serialNumber();
Gamze Abaka641fc072018-09-04 09:16:27 +00001134 return subsService.get(devSerialNo);
Jonathan Hart4c538002018-08-23 10:11:54 -07001135 }
1136
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001137 // Custom-built function, when the device is not available we need a fallback mechanism
1138 private boolean isLocalLeader(DeviceId deviceId) {
1139 if (!mastershipService.isLocalMaster(deviceId)) {
1140 // When the device is available we just check the mastership
1141 if (deviceService.isAvailable(deviceId)) {
1142 return false;
1143 }
1144 // Fallback with Leadership service - device id is used as topic
1145 NodeId leader = leadershipService.runForLeadership(
1146 deviceId.toString()).leaderNodeId();
1147 // Verify if this node is the leader
1148 return clusterService.getLocalNode().id().equals(leader);
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001149 }
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001150 return true;
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001151 }
1152
kdarapuaa5da252020-04-10 15:58:05 +05301153 private boolean isNniPort(Port port) {
1154 if (port.annotations().keys().contains(AnnotationKeys.PORT_NAME)) {
1155 return port.annotations().value(AnnotationKeys.PORT_NAME).contains(NNI);
1156 }
1157 return false;
1158 }
1159
alshabibf0e7e702015-05-30 18:22:36 -07001160 private class InternalDeviceListener implements DeviceListener {
Saurav Dasa9d5f442019-03-06 19:32:48 -08001161 private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet();
1162
alshabibf0e7e702015-05-30 18:22:36 -07001163 @Override
1164 public void event(DeviceEvent event) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001165 eventExecutor.execute(() -> {
1166 DeviceId devId = event.subject().id();
1167 Device dev = event.subject();
Gamze Abaka838d8142019-02-21 07:06:55 +00001168 Port port = event.port();
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001169 DeviceEvent.Type eventType = event.type();
Jonathan Hart4c538002018-08-23 10:11:54 -07001170
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001171 if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) ||
1172 DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) ||
1173 DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001174 return;
1175 }
Jonathan Hart4c538002018-08-23 10:11:54 -07001176
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001177 boolean isLocalLeader = isLocalLeader(devId);
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001178 // Only handle the event if the device belongs to us
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001179 if (!isLocalLeader && event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED)
1180 && !deviceService.isAvailable(devId) && deviceService.getPorts(devId).isEmpty()) {
1181 log.info("Cleaning local state for non master instance upon " +
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001182 "device disconnection {}", devId);
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001183 // Since no mastership of the device is present upon disconnection
1184 // the method in the FlowRuleManager only empties the local copy
1185 // of the DeviceFlowTable thus this method needs to get called
1186 // on every instance, see how it's done in the InternalDeviceListener
1187 // in FlowRuleManager: no mastership check for purgeOnDisconnection
Andrea Campanella3f34c992020-07-15 10:54:10 +02001188 handleDeviceDisconnection(dev, false, false);
Andrea Campanellaaf39b4c2020-05-13 14:07:44 +02001189 return;
1190 } else if (!isLocalLeader) {
Andrea Campanella506df202020-05-21 10:26:12 +02001191 log.debug("Not handling event because instance is not leader for {}", devId);
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001192 return;
1193 }
1194
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001195 log.debug("OLT got {} event for {}/{}", eventType, event.subject(), event.port());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001196
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001197 if (getOltInfo(dev) == null) {
Saurav Dasa9d5f442019-03-06 19:32:48 -08001198 // it's possible that we got an event for a previously
1199 // programmed OLT that is no longer available in SADIS
1200 // we let such events go through
1201 if (!programmedDevices.contains(devId)) {
1202 log.warn("No device info found for {}, this is either "
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001203 + "not an OLT or not known to sadis", dev);
Saurav Dasa9d5f442019-03-06 19:32:48 -08001204 return;
1205 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001206 }
Jonathan Hart4c538002018-08-23 10:11:54 -07001207
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001208 switch (event.type()) {
1209 //TODO: Port handling and bookkeeping should be improved once
1210 // olt firmware handles correct behaviour.
1211 case PORT_ADDED:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001212 if (!deviceService.isAvailable(devId)) {
1213 log.warn("Received {} for disconnected device {}, ignoring", event, devId);
1214 return;
1215 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001216 if (isUniPort(dev, port)) {
1217 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port));
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001218
1219 if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001220 log.info("eapol will be sent for port added {}/{}", devId, port);
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001221 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
1222 null,
Andrea Campanella3f34c992020-07-15 10:54:10 +02001223 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
1224 true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001225 }
1226 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001227 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
1228 if (deviceInfo != null) {
1229 oltFlowService.processNniFilteringObjectives(dev.id(), port.number(), true);
1230 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001231 }
1232 break;
1233 case PORT_REMOVED:
Gamze Abaka838d8142019-02-21 07:06:55 +00001234 if (isUniPort(dev, port)) {
Andrea Campanellacf0e3052020-08-27 11:05:39 +02001235 // if no subscriber is provisioned we need to remove the default EAPOL
1236 // if a subscriber was provisioned the default EAPOL will not be there and we can skip.
1237 // The EAPOL with subscriber tag will be removed by removeSubscriber call.
1238 Collection<? extends UniTagInformation> uniTagInformationSet =
1239 programmedSubs.get(new ConnectPoint(port.element().id(), port.number())).value();
1240 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Matteo Scandolo19b56f62020-10-29 13:29:21 -07001241 log.info("No subscriber provisioned on port {}/{} in PORT_REMOVED event, " +
1242 "removing default EAPOL flow", devId, port);
Andrea Campanellacf0e3052020-08-27 11:05:39 +02001243 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
1244 null,
1245 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
1246 false);
1247 } else {
1248 removeSubscriber(new ConnectPoint(devId, port.number()));
1249 }
Andy Bavier160e8682019-05-07 18:32:22 -07001250
Gamze Abaka838d8142019-02-21 07:06:55 +00001251 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port));
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001252 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001253 break;
1254 case PORT_UPDATED:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001255 if (!deviceService.isAvailable(devId)) {
1256 log.warn("Received {} for disconnected device {}, ignoring", event, devId);
1257 return;
1258 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001259 if (!isUniPort(dev, port)) {
Saurav Das9da7d522020-03-23 19:14:35 -07001260 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
1261 if (deviceInfo != null && port.isEnabled()) {
1262 log.debug("NNI dev/port {}/{} enabled", dev.id(),
1263 port.number());
1264 oltFlowService.processNniFilteringObjectives(dev.id(),
1265 port.number(), true);
1266 }
1267 return;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001268 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001269 ConnectPoint cp = new ConnectPoint(devId, port.number());
1270 Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value();
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001271 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Saurav Dasb776aef2020-03-09 14:29:46 -07001272 if (!port.number().equals(PortNumber.LOCAL)) {
Matteo Scandolo3a037a32020-04-01 12:17:50 -07001273 log.info("eapol will be {} for dev/port updated {}/{} with default vlan {}",
Saurav Dasb776aef2020-03-09 14:29:46 -07001274 (port.isEnabled()) ? "added" : "removed",
Matteo Scandolo3a037a32020-04-01 12:17:50 -07001275 devId, port.number(), EAPOL_DEFAULT_VLAN);
Matteo Scandolo27c471c2020-02-11 16:41:53 -08001276 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001277 null,
1278 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
1279 port.isEnabled());
1280 }
1281 } else {
Saurav Dasb776aef2020-03-09 14:29:46 -07001282 log.info("eapol will be {} for dev/port updated {}/{}",
1283 (port.isEnabled()) ? "added" : "removed",
1284 devId, port.number());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001285 uniTagInformationSet.forEach(uniTag ->
1286 oltFlowService.processEapolFilteringObjectives(devId, port.number(),
1287 uniTag.getUpstreamBandwidthProfile(), null,
1288 uniTag.getPonCTag(), port.isEnabled()));
1289 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001290 if (port.isEnabled()) {
Gamze Abaka838d8142019-02-21 07:06:55 +00001291 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port));
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001292 } else {
Gamze Abaka838d8142019-02-21 07:06:55 +00001293 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port));
Jonathan Hart1d34c8b2018-05-05 15:37:28 -07001294 }
alshabibbb83aa22016-02-10 15:08:23 -08001295 break;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001296 case DEVICE_ADDED:
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001297 handleDeviceConnection(dev, true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001298 break;
1299 case DEVICE_REMOVED:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001300 handleDeviceDisconnection(dev, true, true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001301 break;
1302 case DEVICE_AVAILABILITY_CHANGED:
1303 if (deviceService.isAvailable(devId)) {
Saurav Dasbd3b6712020-03-31 23:28:35 -07001304 log.info("Handling available device: {}", dev.id());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001305 handleDeviceConnection(dev, false);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001306 } else {
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301307 if (deviceService.getPorts(devId).isEmpty()) {
Saurav Dasbd3b6712020-03-31 23:28:35 -07001308 log.info("Handling controlled device disconnection .. "
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001309 + "flushing all state for dev:{}", devId);
Andrea Campanella3f34c992020-07-15 10:54:10 +02001310 handleDeviceDisconnection(dev, true, false);
Saurav Dasbd3b6712020-03-31 23:28:35 -07001311 } else {
1312 log.info("Disconnected device has available ports .. "
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001313 + "assuming temporary disconnection, "
1314 + "retaining state for device {}", devId);
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301315 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001316 }
1317 break;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001318 default:
Andrea Campanella3f34c992020-07-15 10:54:10 +02001319 log.debug("Not handling event {}", event);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001320 return;
1321 }
1322 });
alshabibf0e7e702015-05-30 18:22:36 -07001323 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001324
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001325 private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) {
1326 deviceService.getPorts(device.id()).stream()
1327 .filter(p -> !PortNumber.LOCAL.equals(p.number()))
1328 .filter(p -> isUniPort(device, p))
1329 .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p)));
1330 }
1331
Andrea Campanella3f34c992020-07-15 10:54:10 +02001332 private void handleDeviceDisconnection(Device device, boolean sendDisconnectedEvent, boolean sendUniEvent) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001333 programmedDevices.remove(device.id());
1334 removeAllSubscribers(device.id());
Andrea Campanella600d2e22020-06-22 11:00:31 +02001335 //Handle case where OLT disconnects during subscriber provisioning
Andrea Campanella7a1d7e72020-11-05 10:40:10 +01001336 pendingSubscribersForDevice.remove(device.id());
Andrea Campanella600d2e22020-06-22 11:00:31 +02001337 oltFlowService.clearDeviceState(device.id());
1338
1339 //Complete meter and flow purge
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301340 flowRuleService.purgeFlowRules(device.id());
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001341 oltMeterService.clearMeters(device.id());
Andrea Campanella3f34c992020-07-15 10:54:10 +02001342 if (sendDisconnectedEvent) {
1343 post(new AccessDeviceEvent(
1344 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(),
1345 null, null, null));
1346 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001347 if (sendUniEvent) {
1348 sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED);
Gamze Abaka838d8142019-02-21 07:06:55 +00001349 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001350 }
1351
1352 private void handleDeviceConnection(Device dev, boolean sendUniEvent) {
1353 post(new AccessDeviceEvent(
1354 AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(),
1355 null, null, null));
1356 programmedDevices.add(dev.id());
1357 checkAndCreateDeviceFlows(dev);
1358 if (sendUniEvent) {
1359 sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED);
1360 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001361 }
Gamze Abakada282b42019-03-11 13:16:48 +00001362
1363 private void removeAllSubscribers(DeviceId deviceId) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001364 List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream()
1365 .filter(e -> e.getKey().deviceId().equals(deviceId))
1366 .collect(toList());
Gamze Abakada282b42019-03-11 13:16:48 +00001367
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001368 subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue()));
Gamze Abakada282b42019-03-11 13:16:48 +00001369 }
Gamze Abaka641fc072018-09-04 09:16:27 +00001370
Gamze Abaka641fc072018-09-04 09:16:27 +00001371 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001372
1373 private class InternalClusterListener implements ClusterEventListener {
1374
1375 @Override
1376 public void event(ClusterEvent event) {
1377 if (event.type() == ClusterEvent.Type.INSTANCE_READY) {
1378 hasher.addServer(event.subject().id());
1379 }
1380 if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
1381 hasher.removeServer(event.subject().id());
1382 }
1383 }
1384 }
Andrea Campanella0c3309d2020-05-29 01:51:18 -07001385
Hardik Windlass395ff372019-06-13 05:16:00 +00001386}