blob: 8932f0de172d22306d27a2d71ae63280317371d2 [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
Carmelo Casconeca931162019-07-15 18:22:24 -070018import com.google.common.collect.ImmutableMap;
Carmelo Casconeca931162019-07-15 18:22:24 -070019import 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;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080022import org.onosproject.cluster.ClusterEvent;
23import org.onosproject.cluster.ClusterEventListener;
24import org.onosproject.cluster.ClusterService;
25import org.onosproject.cluster.ControllerNode;
26import org.onosproject.cluster.NodeId;
alshabibf0e7e702015-05-30 18:22:36 -070027import org.onosproject.core.ApplicationId;
28import org.onosproject.core.CoreService;
alshabib8e4fd2f2016-01-12 15:55:53 -080029import org.onosproject.event.AbstractListenerManager;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010030import org.onosproject.net.AnnotationKeys;
Jonathan Harte533a422015-10-20 17:31:24 -070031import org.onosproject.net.ConnectPoint;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010032import org.onosproject.net.Device;
alshabibf0e7e702015-05-30 18:22:36 -070033import org.onosproject.net.DeviceId;
alshabibdec2e252016-01-15 12:20:25 -080034import org.onosproject.net.Port;
alshabibf0e7e702015-05-30 18:22:36 -070035import org.onosproject.net.PortNumber;
36import org.onosproject.net.device.DeviceEvent;
37import org.onosproject.net.device.DeviceListener;
38import org.onosproject.net.device.DeviceService;
Hardik Windlassa58fbee2020-03-12 18:33:55 +053039import org.onosproject.net.flow.FlowRuleService;
alshabibf0e7e702015-05-30 18:22:36 -070040import org.onosproject.net.flowobjective.FlowObjectiveService;
41import org.onosproject.net.flowobjective.ForwardingObjective;
alshabib3ea82642016-01-12 18:06:53 -080042import org.onosproject.net.flowobjective.Objective;
43import org.onosproject.net.flowobjective.ObjectiveContext;
44import org.onosproject.net.flowobjective.ObjectiveError;
Saurav Daseae48de2019-06-19 13:26:15 -070045import org.onosproject.net.meter.MeterId;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080046import org.onosproject.store.serializers.KryoNamespaces;
47import org.onosproject.store.service.ConsistentMultimap;
48import org.onosproject.store.service.Serializer;
49import org.onosproject.store.service.StorageService;
alshabib36a4d732016-06-01 16:03:59 -070050import org.opencord.olt.AccessDeviceEvent;
51import org.opencord.olt.AccessDeviceListener;
52import org.opencord.olt.AccessDeviceService;
Amit Ghosh31939522018-08-16 13:28:21 +010053import org.opencord.olt.AccessSubscriberId;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000054import org.opencord.olt.internalapi.AccessDeviceFlowService;
55import org.opencord.olt.internalapi.AccessDeviceMeterService;
Gamze Abaka641fc072018-09-04 09:16:27 +000056import org.opencord.sadis.BandwidthProfileInformation;
57import org.opencord.sadis.BaseInformationService;
58import org.opencord.sadis.SadisService;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +010059import org.opencord.sadis.SubscriberAndDeviceInformation;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000060import org.opencord.sadis.UniTagInformation;
alshabibe0559672016-02-21 14:49:51 -080061import org.osgi.service.component.ComponentContext;
Carmelo Casconeca931162019-07-15 18:22:24 -070062import org.osgi.service.component.annotations.Activate;
63import org.osgi.service.component.annotations.Component;
64import org.osgi.service.component.annotations.Deactivate;
65import org.osgi.service.component.annotations.Modified;
66import org.osgi.service.component.annotations.Reference;
67import org.osgi.service.component.annotations.ReferenceCardinality;
alshabibf0e7e702015-05-30 18:22:36 -070068import org.slf4j.Logger;
69
Carmelo Casconeca931162019-07-15 18:22:24 -070070import java.util.ArrayList;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080071import java.util.Collection;
Carmelo Casconeca931162019-07-15 18:22:24 -070072import java.util.Dictionary;
73import java.util.List;
74import java.util.Map;
Carmelo Casconeca931162019-07-15 18:22:24 -070075import java.util.Optional;
76import java.util.Properties;
77import java.util.Set;
78import java.util.concurrent.CompletableFuture;
Carmelo Casconeca931162019-07-15 18:22:24 -070079import java.util.concurrent.ExecutorService;
80import java.util.concurrent.Executors;
Carmelo Casconeca931162019-07-15 18:22:24 -070081
82import static com.google.common.base.Preconditions.checkNotNull;
Carmelo Casconeca931162019-07-15 18:22:24 -070083import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080084import static java.util.stream.Collectors.collectingAndThen;
85import static java.util.stream.Collectors.groupingBy;
86import static java.util.stream.Collectors.mapping;
87import static java.util.stream.Collectors.toList;
88import static java.util.stream.Collectors.toSet;
Carmelo Casconeca931162019-07-15 18:22:24 -070089import static org.onlab.util.Tools.get;
90import static org.onlab.util.Tools.groupedThreads;
Jonathan Hart4f178fa2020-02-03 10:46:01 -080091import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID;
92import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID_DEFAULT;
93import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME;
94import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME_DEFAULT;
Carmelo Casconeca931162019-07-15 18:22:24 -070095import static org.slf4j.LoggerFactory.getLogger;
alshabibf0e7e702015-05-30 18:22:36 -070096
97/**
Jonathan Harte533a422015-10-20 17:31:24 -070098 * Provisions rules on access devices.
alshabibf0e7e702015-05-30 18:22:36 -070099 */
Carmelo Casconeca931162019-07-15 18:22:24 -0700100@Component(immediate = true,
101 property = {
Carmelo Casconeca931162019-07-15 18:22:24 -0700102 DEFAULT_BP_ID + ":String=" + DEFAULT_BP_ID_DEFAULT,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000103 DEFAULT_MCAST_SERVICE_NAME + ":String=" + DEFAULT_MCAST_SERVICE_NAME_DEFAULT,
Carmelo Casconeca931162019-07-15 18:22:24 -0700104 })
alshabib8e4fd2f2016-01-12 15:55:53 -0800105public class Olt
106 extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener>
107 implements AccessDeviceService {
Charles Chan54f110f2017-01-20 11:22:42 -0800108 private static final String APP_NAME = "org.opencord.olt";
alshabibe0559672016-02-21 14:49:51 -0800109
Gamze Abakada282b42019-03-11 13:16:48 +0000110 private static final short EAPOL_DEFAULT_VLAN = 4091;
Gamze Abaka838d8142019-02-21 07:06:55 +0000111 private static final String NO_UPLINK_PORT = "No uplink port found for OLT device {}";
alshabibe0559672016-02-21 14:49:51 -0800112
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800113 public static final int HASH_WEIGHT = 10;
114
alshabibf0e7e702015-05-30 18:22:36 -0700115 private final Logger log = getLogger(getClass());
116
Thomas Lee Sd7735f92020-02-20 19:21:47 +0530117 private static final String NNI = "nni-";
118
Carmelo Casconeca931162019-07-15 18:22:24 -0700119 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabibf0e7e702015-05-30 18:22:36 -0700120 protected FlowObjectiveService flowObjectiveService;
121
Carmelo Casconeca931162019-07-15 18:22:24 -0700122 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabibf0e7e702015-05-30 18:22:36 -0700123 protected DeviceService deviceService;
124
Carmelo Casconeca931162019-07-15 18:22:24 -0700125 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabibf0e7e702015-05-30 18:22:36 -0700126 protected CoreService coreService;
127
Carmelo Casconeca931162019-07-15 18:22:24 -0700128 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Gamze Abaka641fc072018-09-04 09:16:27 +0000129 protected SadisService sadisService;
130
Carmelo Casconeca931162019-07-15 18:22:24 -0700131 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000132 protected AccessDeviceFlowService oltFlowService;
alshabibe0559672016-02-21 14:49:51 -0800133
Carmelo Casconeca931162019-07-15 18:22:24 -0700134 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000135 protected AccessDeviceMeterService oltMeterService;
Gamze Abakaad329652018-12-20 10:12:21 +0000136
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800137 @Reference(cardinality = ReferenceCardinality.MANDATORY)
138 protected StorageService storageService;
139
140 @Reference(cardinality = ReferenceCardinality.MANDATORY)
141 protected ClusterService clusterService;
142
Hardik Windlassa58fbee2020-03-12 18:33:55 +0530143 @Reference(cardinality = ReferenceCardinality.MANDATORY)
144 protected FlowRuleService flowRuleService;
145
Carmelo Casconeca931162019-07-15 18:22:24 -0700146 /**
Carmelo Cascone95ff5122019-11-14 14:19:13 -0800147 * Default bandwidth profile id that is used for authentication trap flows.
Carmelo Casconeca931162019-07-15 18:22:24 -0700148 **/
149 protected String defaultBpId = DEFAULT_BP_ID_DEFAULT;
Gamze Abakaad329652018-12-20 10:12:21 +0000150
Carmelo Casconeca931162019-07-15 18:22:24 -0700151 /**
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000152 * Deleting Meters based on flow count statistics.
Carmelo Casconeca931162019-07-15 18:22:24 -0700153 **/
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000154 protected String multicastServiceName = DEFAULT_MCAST_SERVICE_NAME;
Gamze Abaka33feef52019-02-27 08:16:47 +0000155
alshabibf0e7e702015-05-30 18:22:36 -0700156 private final DeviceListener deviceListener = new InternalDeviceListener();
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800157 private final ClusterEventListener clusterListener = new InternalClusterListener();
158
159 private ConsistentHasher hasher;
alshabibf0e7e702015-05-30 18:22:36 -0700160
Gamze Abaka641fc072018-09-04 09:16:27 +0000161 protected BaseInformationService<SubscriberAndDeviceInformation> subsService;
162 private BaseInformationService<BandwidthProfileInformation> bpService;
alshabibf0e7e702015-05-30 18:22:36 -0700163
Gamze Abaka641fc072018-09-04 09:16:27 +0000164 private ExecutorService oltInstallers = Executors.newFixedThreadPool(4,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000165 groupedThreads("onos/olt-service",
166 "olt-installer-%d"));
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100167
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700168 protected ExecutorService eventExecutor;
169
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800170 private ConsistentMultimap<ConnectPoint, UniTagInformation> programmedSubs;
Saurav Dasa9d5f442019-03-06 19:32:48 -0800171
alshabibf0e7e702015-05-30 18:22:36 -0700172 @Activate
alshabibe0559672016-02-21 14:49:51 -0800173 public void activate(ComponentContext context) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000174 eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt",
175 "events-%d", log));
alshabibe0559672016-02-21 14:49:51 -0800176 modified(context);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000177 ApplicationId appId = coreService.registerApplication(APP_NAME);
Saurav Das62ad75e2019-03-05 12:22:22 -0800178
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800179 KryoNamespace serializer = KryoNamespace.newBuilder()
180 .register(KryoNamespaces.API)
181 .register(UniTagInformation.class)
182 .build();
183
184 programmedSubs = storageService.<ConnectPoint, UniTagInformation>consistentMultimapBuilder()
185 .withName("volt-programmed-subs")
186 .withSerializer(Serializer.using(serializer))
187 .withApplicationId(appId)
188 .build();
alshabibc4dfe852015-06-05 13:35:13 -0700189
alshabib8e4fd2f2016-01-12 15:55:53 -0800190 eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry);
191
Gamze Abaka641fc072018-09-04 09:16:27 +0000192 subsService = sadisService.getSubscriberInfoService();
193 bpService = sadisService.getBandwidthProfileService();
194
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800195 List<NodeId> readyNodes = clusterService.getNodes().stream()
196 .filter(c -> clusterService.getState(c.id()) == ControllerNode.State.READY)
197 .map(ControllerNode::id)
198 .collect(toList());
199 hasher = new ConsistentHasher(readyNodes, HASH_WEIGHT);
200 clusterService.addListener(clusterListener);
201
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100202 // look for all provisioned devices in Sadis and create EAPOL flows for the
203 // UNI ports
204 Iterable<Device> devices = deviceService.getDevices();
205 for (Device d : devices) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800206 if (isDeviceMine(d.id())) {
207 checkAndCreateDeviceFlows(d);
208 }
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100209 }
alshabib4ceaed32016-03-03 18:00:58 -0800210
alshabibba357492016-01-27 13:49:46 -0800211 deviceService.addListener(deviceListener);
alshabibf0e7e702015-05-30 18:22:36 -0700212 log.info("Started with Application ID {}", appId.id());
213 }
214
215 @Deactivate
216 public void deactivate() {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800217 clusterService.removeListener(clusterListener);
alshabib62e9ce72016-02-11 17:31:36 -0800218 deviceService.removeListener(deviceListener);
Jonathan Hart5f1c8142018-07-24 17:31:59 -0700219 eventDispatcher.removeSink(AccessDeviceEvent.class);
alshabibf0e7e702015-05-30 18:22:36 -0700220 log.info("Stopped");
221 }
222
alshabibe0559672016-02-21 14:49:51 -0800223 @Modified
224 public void modified(ComponentContext context) {
225 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
226
227 try {
Gamze Abakaad329652018-12-20 10:12:21 +0000228 String bpId = get(properties, "defaultBpId");
229 defaultBpId = bpId;
230
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000231 String mcastSN = get(properties, "multicastServiceName");
232 multicastServiceName = mcastSN;
233
234 log.debug("OLT properties: DefaultBpId: {}, MulticastServiceName: {}", defaultBpId, multicastServiceName);
Gamze Abaka33feef52019-02-27 08:16:47 +0000235
alshabibe0559672016-02-21 14:49:51 -0800236 } catch (Exception e) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000237 log.error("Error while modifying the properties", e);
alshabibe0559672016-02-21 14:49:51 -0800238 }
239 }
240
alshabib32232c82016-02-25 17:57:24 -0500241 @Override
Gamze Abaka838d8142019-02-21 07:06:55 +0000242 public boolean provisionSubscriber(ConnectPoint connectPoint) {
Saurav Daseae48de2019-06-19 13:26:15 -0700243 log.info("Call to provision subscriber at {}", connectPoint);
Gamze Abaka838d8142019-02-21 07:06:55 +0000244 DeviceId deviceId = connectPoint.deviceId();
245 PortNumber subscriberPortNo = connectPoint.port();
246
247 checkNotNull(deviceService.getPort(deviceId, subscriberPortNo),
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000248 "Invalid connect point:" + connectPoint);
Hardik Windlass395ff372019-06-13 05:16:00 +0000249
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100250 // Find the subscriber on this connect point
Gamze Abaka838d8142019-02-21 07:06:55 +0000251 SubscriberAndDeviceInformation sub = getSubscriber(connectPoint);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100252 if (sub == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000253 log.warn("No subscriber found for {}", connectPoint);
Amit Ghosh31939522018-08-16 13:28:21 +0100254 return false;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100255 }
Jonathan Harte533a422015-10-20 17:31:24 -0700256
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100257 // Get the uplink port
Gamze Abaka838d8142019-02-21 07:06:55 +0000258 Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId));
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100259 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000260 log.warn(NO_UPLINK_PORT, deviceId);
Amit Ghosh31939522018-08-16 13:28:21 +0100261 return false;
Jonathan Harte533a422015-10-20 17:31:24 -0700262 }
263
Gamze Abaka838d8142019-02-21 07:06:55 +0000264 //delete Eapol authentication flow with default bandwidth
Gamze Abaka33feef52019-02-27 08:16:47 +0000265 //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules
Gamze Abaka33feef52019-02-27 08:16:47 +0000266 //install subscriber flows
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000267 CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture();
268 oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, filterFuture,
269 VlanId.vlanId(EAPOL_DEFAULT_VLAN), false);
Gamze Abaka33feef52019-02-27 08:16:47 +0000270 filterFuture.thenAcceptAsync(filterStatus -> {
271 if (filterStatus == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000272 provisionUniTagList(connectPoint, uplinkPort.number(), sub);
Gamze Abaka33feef52019-02-27 08:16:47 +0000273 }
274 });
Amit Ghosh31939522018-08-16 13:28:21 +0100275 return true;
alshabibb7a9e172016-01-13 11:23:53 -0800276 }
277
278 @Override
Gamze Abaka838d8142019-02-21 07:06:55 +0000279 public boolean removeSubscriber(ConnectPoint connectPoint) {
Saurav Daseae48de2019-06-19 13:26:15 -0700280 log.info("Call to un-provision subscriber at {}", connectPoint);
Gamze Abaka838d8142019-02-21 07:06:55 +0000281
Saurav Daseae48de2019-06-19 13:26:15 -0700282 // Get the subscriber connected to this port from the local cache
283 // If we don't know about the subscriber there's no need to remove it
Gamze Abaka838d8142019-02-21 07:06:55 +0000284 DeviceId deviceId = connectPoint.deviceId();
285 PortNumber subscriberPortNo = connectPoint.port();
286
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800287 Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(connectPoint).value();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000288 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000289 log.warn("Subscriber on connectionPoint {} was not previously programmed, " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000290 "no need to remove it", connectPoint);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800291 return true;
alshabibbf23a1f2016-01-14 17:27:11 -0800292 }
293
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100294 // Get the uplink port
Gamze Abaka838d8142019-02-21 07:06:55 +0000295 Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId));
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100296 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000297 log.warn(NO_UPLINK_PORT, deviceId);
Amit Ghosh31939522018-08-16 13:28:21 +0100298 return false;
alshabib4ceaed32016-03-03 18:00:58 -0800299 }
300
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000301 for (UniTagInformation uniTag : uniTagInformationSet) {
Amit Ghosh95e2f652017-08-23 12:49:46 +0100302
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000303 if (multicastServiceName.equals(uniTag.getServiceName())) {
304 continue;
305 }
Gamze Abaka838d8142019-02-21 07:06:55 +0000306
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000307 unprovisionVlans(deviceId, uplinkPort.number(), subscriberPortNo, uniTag);
alshabibbf23a1f2016-01-14 17:27:11 -0800308
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000309 // re-install eapol with default bandwidth profile
310 oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo,
311 uniTag.getUpstreamBandwidthProfile(),
312 null, uniTag.getPonCTag(), false);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100313
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000314 Port port = deviceService.getPort(deviceId, subscriberPortNo);
315 if (port != null && port.isEnabled()) {
316 oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId,
317 null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true);
318 } else {
319 log.debug("Port {} is no longer enabled or it's unavailable. Not "
320 + "reprogramming default eapol flow", connectPoint);
321 }
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100322 }
Amit Ghosh31939522018-08-16 13:28:21 +0100323 return true;
alshabibbf23a1f2016-01-14 17:27:11 -0800324 }
325
Gamze Abakaf59c0912019-04-19 08:24:28 +0000326
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000327 @Override
328 public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag,
329 Optional<VlanId> cTag, Optional<Integer> tpId) {
330
331 log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}, tpId {}" +
332 "", subscriberId, sTag, cTag, tpId);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000333
Amit Ghosh31939522018-08-16 13:28:21 +0100334 // Check if we can find the connect point to which this subscriber is connected
335 ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString());
336 if (subsPort == null) {
337 log.warn("ConnectPoint for {} not found", subscriberId);
338 return false;
339 }
340
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100341 if (!sTag.isPresent() && !cTag.isPresent()) {
342 return provisionSubscriber(subsPort);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000343 } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100344 Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId()));
345 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000346 log.warn(NO_UPLINK_PORT, subsPort.deviceId());
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100347 return false;
348 }
349
Gamze Abakaf59c0912019-04-19 08:24:28 +0000350 //delete Eapol authentication flow with default bandwidth
351 //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules
Gamze Abakaf59c0912019-04-19 08:24:28 +0000352 //install subscriber flows
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000353 CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture();
354 oltFlowService.processEapolFilteringObjectives(subsPort.deviceId(), subsPort.port(), defaultBpId,
355 filterFuture, VlanId.vlanId(EAPOL_DEFAULT_VLAN), false);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000356 filterFuture.thenAcceptAsync(filterStatus -> {
357 if (filterStatus == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000358 provisionUniTagInformation(subsPort.deviceId(), uplinkPort.number(), subsPort.port(),
359 cTag.get(), sTag.get(), tpId.get());
Gamze Abakaf59c0912019-04-19 08:24:28 +0000360 }
361 });
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100362 return true;
363 } else {
364 log.warn("Provisioning failed for subscriber: {}", subscriberId);
365 return false;
366 }
Amit Ghosh31939522018-08-16 13:28:21 +0100367 }
Amit Ghosh95e2f652017-08-23 12:49:46 +0100368
alshabibe0559672016-02-21 14:49:51 -0800369 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000370 public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag,
371 Optional<VlanId> cTag, Optional<Integer> tpId) {
Amit Ghosh31939522018-08-16 13:28:21 +0100372 // Check if we can find the connect point to which this subscriber is connected
373 ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString());
374 if (subsPort == null) {
375 log.warn("ConnectPoint for {} not found", subscriberId);
376 return false;
377 }
378
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100379 if (!sTag.isPresent() && !cTag.isPresent()) {
380 return removeSubscriber(subsPort);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000381 } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) {
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100382 // Get the uplink port
383 Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId()));
384 if (uplinkPort == null) {
Gamze Abaka838d8142019-02-21 07:06:55 +0000385 log.warn(NO_UPLINK_PORT, subsPort.deviceId());
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100386 return false;
387 }
388
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000389 Optional<UniTagInformation> tagInfo = getUniTagInformation(subsPort, cTag.get(), sTag.get(), tpId.get());
390 if (!tagInfo.isPresent()) {
391 log.warn("UniTagInformation does not exist for Device/Port {}, cTag {}, sTag {}, tpId {}",
392 subsPort, cTag, sTag, tpId);
393 return false;
394 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000395
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000396 unprovisionVlans(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), tagInfo.get());
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100397 return true;
398 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000399 log.warn("Removing subscriber is not possible - please check the provided information" +
400 "for the subscriber: {}", subscriberId);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100401 return false;
402 }
Amit Ghosh31939522018-08-16 13:28:21 +0100403 }
404
405 @Override
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000406 public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getProgSubs() {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800407 return programmedSubs.stream()
408 .collect(collectingAndThen(
409 groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())),
410 ImmutableMap::copyOf));
Saurav Das82b8e6d2018-10-04 15:25:12 -0700411 }
412
413 @Override
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100414 public List<DeviceId> fetchOlts() {
415 // look through all the devices and find the ones that are OLTs as per Sadis
416 List<DeviceId> olts = new ArrayList<>();
417 Iterable<Device> devices = deviceService.getDevices();
418 for (Device d : devices) {
Saurav Das82b8e6d2018-10-04 15:25:12 -0700419 if (getOltInfo(d) != null) {
420 // So this is indeed an OLT device
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100421 olts.add(d.id());
422 }
423 }
424 return olts;
alshabibe0559672016-02-21 14:49:51 -0800425 }
426
Amit Ghosh31939522018-08-16 13:28:21 +0100427 /**
428 * Finds the connect point to which a subscriber is connected.
429 *
430 * @param id The id of the subscriber, this is the same ID as in Sadis
431 * @return Subscribers ConnectPoint if found else null
432 */
433 private ConnectPoint findSubscriberConnectPoint(String id) {
434
435 Iterable<Device> devices = deviceService.getDevices();
436 for (Device d : devices) {
437 for (Port p : deviceService.getPorts(d.id())) {
438 log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id);
439 if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) {
440 log.debug("Found on device {} port {}", d.id(), p.number());
441 return new ConnectPoint(d.id(), p.number());
442 }
443 }
444 }
445 return null;
446 }
447
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000448 /**
449 * Gets the context of the bandwidth profile information for the given parameter.
450 *
451 * @param bandwidthProfile the bandwidth profile id
452 * @return the context of the bandwidth profile information
453 */
Gamze Abaka641fc072018-09-04 09:16:27 +0000454 private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) {
455 if (bandwidthProfile == null) {
456 return null;
457 }
458 return bpService.get(bandwidthProfile);
459 }
460
Gamze Abaka838d8142019-02-21 07:06:55 +0000461 /**
Gamze Abaka33feef52019-02-27 08:16:47 +0000462 * Removes subscriber vlan flows.
Gamze Abaka838d8142019-02-21 07:06:55 +0000463 *
464 * @param deviceId the device identifier
465 * @param uplink uplink port of the OLT
466 * @param subscriberPort uni port
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000467 * @param uniTag uni tag information
Gamze Abaka838d8142019-02-21 07:06:55 +0000468 */
Gamze Abaka33feef52019-02-27 08:16:47 +0000469 private void unprovisionVlans(DeviceId deviceId, PortNumber uplink,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000470 PortNumber subscriberPort, UniTagInformation uniTag) {
471
472 log.info("Unprovisioning vlans for {} at {}/{}", uniTag, deviceId, subscriberPort);
alshabibbf23a1f2016-01-14 17:27:11 -0800473
474 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
475 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
476
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000477 VlanId deviceVlan = uniTag.getPonSTag();
478 VlanId subscriberVlan = uniTag.getPonCTag();
Gamze Abaka641fc072018-09-04 09:16:27 +0000479
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000480 MeterId upstreamMeterId = oltMeterService
481 .getMeterIdFromBpMapping(deviceId, uniTag.getUpstreamBandwidthProfile());
482 MeterId downstreamMeterId = oltMeterService
483 .getMeterIdFromBpMapping(deviceId, uniTag.getDownstreamBandwidthProfile());
Gamze Abaka641fc072018-09-04 09:16:27 +0000484
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000485 ForwardingObjective.Builder upFwd =
486 oltFlowService.createUpBuilder(uplink, subscriberPort, upstreamMeterId, uniTag);
487 ForwardingObjective.Builder downFwd =
488 oltFlowService.createDownBuilder(uplink, subscriberPort, downstreamMeterId, uniTag);
489
490 if (uniTag.getIsIgmpRequired()) {
491 oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort,
492 upstreamMeterId, uniTag, false, true);
493 }
494 if (uniTag.getIsDhcpRequired()) {
495 oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort,
496 upstreamMeterId, uniTag, false, true);
497 }
alshabibbf23a1f2016-01-14 17:27:11 -0800498
alshabib4ceaed32016-03-03 18:00:58 -0800499 flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() {
500 @Override
501 public void onSuccess(Objective objective) {
502 upFuture.complete(null);
503 }
alshabibbf23a1f2016-01-14 17:27:11 -0800504
alshabib4ceaed32016-03-03 18:00:58 -0800505 @Override
506 public void onError(Objective objective, ObjectiveError error) {
507 upFuture.complete(error);
508 }
509 }));
510
511 flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() {
512 @Override
513 public void onSuccess(Objective objective) {
514 downFuture.complete(null);
515 }
516
517 @Override
518 public void onError(Objective objective, ObjectiveError error) {
519 downFuture.complete(error);
520 }
521 }));
alshabibbf23a1f2016-01-14 17:27:11 -0800522
523 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000524 AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED;
alshabibbf23a1f2016-01-14 17:27:11 -0800525 if (upStatus == null && downStatus == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000526 log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {}, and" +
527 "Device/Port{}", uniTag.getPonCTag(), uniTag.getPonSTag(),
528 uniTag.getTechnologyProfileId(), subscriberPort);
529 updateProgrammedSubscriber(new ConnectPoint(deviceId, subscriberPort), uniTag, false);
alshabibbf23a1f2016-01-14 17:27:11 -0800530 } else if (downStatus != null) {
531 log.error("Subscriber with vlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000532 "on port {} failed downstream uninstallation: {}",
533 subscriberVlan, deviceId, subscriberPort, downStatus);
534 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED;
alshabibbf23a1f2016-01-14 17:27:11 -0800535 } else if (upStatus != null) {
536 log.error("Subscriber with vlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000537 "on port {} failed upstream uninstallation: {}",
538 subscriberVlan, deviceId, subscriberPort, upStatus);
539 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED;
alshabibbf23a1f2016-01-14 17:27:11 -0800540 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000541 Port port = deviceService.getPort(deviceId, subscriberPort);
542 post(new AccessDeviceEvent(type, deviceId, port, deviceVlan, subscriberVlan,
543 uniTag.getTechnologyProfileId()));
alshabibbf23a1f2016-01-14 17:27:11 -0800544 }, oltInstallers);
Jonathan Harte533a422015-10-20 17:31:24 -0700545 }
546
Gamze Abaka838d8142019-02-21 07:06:55 +0000547 /**
Gamze Abaka33feef52019-02-27 08:16:47 +0000548 * Adds subscriber vlan flows, dhcp, eapol and igmp trap flows for the related uni port.
Gamze Abaka838d8142019-02-21 07:06:55 +0000549 *
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000550 * @param connectPoint the connection point of the subscriber
551 * @param uplinkPort uplink port of the OLT (the nni port)
552 * @param sub subscriber information that includes s, c tags, tech profile and bandwidth profile references
Gamze Abaka838d8142019-02-21 07:06:55 +0000553 */
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000554 private void provisionUniTagList(ConnectPoint connectPoint, PortNumber uplinkPort,
555 SubscriberAndDeviceInformation sub) {
Gamze Abaka641fc072018-09-04 09:16:27 +0000556
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000557 log.info("Provisioning vlans for subscriber {} on dev/port: {}", sub, connectPoint);
Gamze Abaka641fc072018-09-04 09:16:27 +0000558
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000559 if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) {
560 log.warn("Unitaglist doesn't exist for the subscriber {}", sub.id());
561 return;
562 }
Gamze Abaka641fc072018-09-04 09:16:27 +0000563
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000564 DeviceId deviceId = connectPoint.deviceId();
565 PortNumber subscriberPort = connectPoint.port();
Gamze Abaka641fc072018-09-04 09:16:27 +0000566
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000567 for (UniTagInformation uniTag : sub.uniTagList()) {
568 handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, uniTag);
569 }
570 }
alshabib3ea82642016-01-12 18:06:53 -0800571
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000572 /**
573 * Finds the uni tag information and provisions the found information.
574 * If the uni tag information is not found, returns
575 *
576 * @param deviceId the access device id
577 * @param uplinkPort the nni port
578 * @param subscriberPort the uni port
579 * @param innerVlan the pon c tag
580 * @param outerVlan the pon s tag
581 * @param tpId the technology profile id
582 */
583 private void provisionUniTagInformation(DeviceId deviceId, PortNumber uplinkPort,
584 PortNumber subscriberPort,
585 VlanId innerVlan,
586 VlanId outerVlan,
587 Integer tpId) {
Jonathan Harte533a422015-10-20 17:31:24 -0700588
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000589 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
590 Optional<UniTagInformation> gotTagInformation = getUniTagInformation(cp, innerVlan, outerVlan, tpId);
591 if (!gotTagInformation.isPresent()) {
592 return;
593 }
594 UniTagInformation tagInformation = gotTagInformation.get();
595 handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, tagInformation);
596 }
alshabib3ea82642016-01-12 18:06:53 -0800597
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000598 private void updateProgrammedSubscriber(ConnectPoint connectPoint, UniTagInformation tagInformation, Boolean add) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800599 if (add) {
600 programmedSubs.put(connectPoint, tagInformation);
601 } else {
602 programmedSubs.remove(connectPoint, tagInformation);
603 }
Jonathan Harte533a422015-10-20 17:31:24 -0700604 }
605
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000606 /**
607 * Installs a uni tag information flow.
608 *
609 * @param deviceId the access device id
610 * @param uplinkPort the nni port
611 * @param subscriberPort the uni port
612 * @param tagInfo the uni tag information
613 */
614 private void handleSubscriberFlows(DeviceId deviceId, PortNumber uplinkPort, PortNumber subscriberPort,
615 UniTagInformation tagInfo) {
616
617 log.info("Provisioning vlan-based flows for the uniTagInformation {}", tagInfo);
618
619 Port port = deviceService.getPort(deviceId, subscriberPort);
620
621 if (multicastServiceName.equals(tagInfo.getServiceName())) {
622 // IGMP flows are taken care of along with VOD service
623 // Please note that for each service, Subscriber Registered event will be sent
624 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED,
625 deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(),
626 tagInfo.getTechnologyProfileId()));
627 return;
Gamze Abaka641fc072018-09-04 09:16:27 +0000628 }
629
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100630 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
631
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000632 BandwidthProfileInformation upstreamBpInfo =
633 getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile());
634 BandwidthProfileInformation downstreamBpInfo =
635 getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile());
Gamze Abakaf59c0912019-04-19 08:24:28 +0000636
637 CompletableFuture<Object> upstreamMeterFuture = new CompletableFuture<>();
638 CompletableFuture<Object> downsteamMeterFuture = new CompletableFuture<>();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000639 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>();
640 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>();
Gamze Abakaf59c0912019-04-19 08:24:28 +0000641
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000642 MeterId upstreamMeterId = oltMeterService.createMeter(deviceId, upstreamBpInfo, upstreamMeterFuture);
643
644 MeterId downstreamMeterId = oltMeterService.createMeter(deviceId, downstreamBpInfo, downsteamMeterFuture);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000645
646 upstreamMeterFuture.thenAcceptAsync(result -> {
647 if (result == null) {
648 log.info("Upstream Meter {} is sent to the device {}. " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000649 "Sending subscriber flows.", upstreamMeterId, deviceId);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000650
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000651 ForwardingObjective.Builder upFwd =
652 oltFlowService.createUpBuilder(uplinkPort, subscriberPort, upstreamMeterId, tagInfo);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000653
654 flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() {
655 @Override
656 public void onSuccess(Objective objective) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000657 log.info("Upstream flow installed successfully");
Gamze Abakaf59c0912019-04-19 08:24:28 +0000658 upFuture.complete(null);
659 }
660
661 @Override
662 public void onError(Objective objective, ObjectiveError error) {
663 upFuture.complete(error);
664 }
665 }));
666
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000667 } else if (upstreamBpInfo == null) {
668 log.warn("No meter installed since no Upstream BW Profile definition found for " +
669 "ctag {} stag {} tpId {} and Device/port: {}:{}",
670 tagInfo.getPonCTag(), tagInfo.getPonSTag(),
671 tagInfo.getTechnologyProfileId(),
672 deviceId, subscriberPort);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000673 } else {
674 log.warn("Meter installation error while sending upstream flows. " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000675 "Result {} and MeterId {}", result, upstreamMeterId);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000676 }
Daniele Moro7cbf4312020-03-06 17:24:12 -0800677 }).exceptionally(ex -> {
678 log.error("Upstream flow failed: " + ex.getMessage());
679 upFuture.complete(ObjectiveError.UNKNOWN);
680 return null;
Gamze Abakaf59c0912019-04-19 08:24:28 +0000681 });
682
683 downsteamMeterFuture.thenAcceptAsync(result -> {
684 if (result == null) {
685 log.info("Downstream Meter {} is sent to the device {}. " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000686 "Sending subscriber flows.", downstreamMeterId, deviceId);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000687
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000688 ForwardingObjective.Builder downFwd =
689 oltFlowService.createDownBuilder(uplinkPort, subscriberPort, downstreamMeterId, tagInfo);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000690
691 flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() {
692 @Override
693 public void onSuccess(Objective objective) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000694 log.info("Downstream flow installed successfully");
Gamze Abakaf59c0912019-04-19 08:24:28 +0000695 downFuture.complete(null);
696 }
697
698 @Override
699 public void onError(Objective objective, ObjectiveError error) {
700 downFuture.complete(error);
701 }
702 }));
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000703
704 } else if (downstreamBpInfo == null) {
705 log.warn("No meter installed since no Downstream BW Profile definition found for " +
706 "ctag {} stag {} tpId {} and Device/port: {}:{}",
707 tagInfo.getPonCTag(), tagInfo.getPonSTag(),
708 tagInfo.getTechnologyProfileId(),
709 deviceId, subscriberPort);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000710 } else {
711 log.warn("Meter installation error while sending upstream flows. " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000712 "Result {} and MeterId {}", result, downstreamMeterId);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000713 }
Daniele Moro7cbf4312020-03-06 17:24:12 -0800714 }).exceptionally(ex -> {
715 log.error("Downstream flow failed: " + ex.getMessage());
716 downFuture.complete(ObjectiveError.UNKNOWN);
717 return null;
Gamze Abakaf59c0912019-04-19 08:24:28 +0000718 });
719
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100720 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000721 AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED;
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100722 if (downStatus != null) {
723 log.error("Flow with innervlan {} and outerVlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000724 "on port {} failed downstream installation: {}",
725 tagInfo.getPonCTag(), tagInfo.getPonSTag(), deviceId, cp, downStatus);
726 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED;
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100727 } else if (upStatus != null) {
728 log.error("Flow with innerVlan {} and outerVlan {} on device {} " +
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000729 "on port {} failed upstream installation: {}",
730 tagInfo.getPonCTag(), tagInfo.getPonSTag(), deviceId, cp, upStatus);
731 type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED;
Gamze Abakaf59c0912019-04-19 08:24:28 +0000732 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000733 log.info("Upstream and downstream data plane flows are installed successfully.");
734 oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPort,
735 tagInfo.getUpstreamBandwidthProfile(),
736 null, tagInfo.getPonCTag(), true);
737 if (tagInfo.getIsDhcpRequired()) {
738 oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort,
739 upstreamMeterId, tagInfo, true, true);
740 }
Gamze Abakaf59c0912019-04-19 08:24:28 +0000741
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000742 if (tagInfo.getIsIgmpRequired()) {
743 oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort, upstreamMeterId, tagInfo,
744 true, true);
745 }
746 updateProgrammedSubscriber(cp, tagInfo, true);
747 post(new AccessDeviceEvent(type, deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(),
748 tagInfo.getTechnologyProfileId()));
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100749 }
750 }, oltInstallers);
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100751 }
752
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000753 /**
754 * Checks the subscriber uni tag list and find the uni tag information.
755 * using the pon c tag, pon s tag and the technology profile id
756 * May return Optional<null>
757 *
758 * @param cp the connection point of the subscriber
759 * @param innerVlan pon c tag
760 * @param outerVlan pon s tag
761 * @param tpId the technology profile id
762 * @return the found uni tag information
763 */
764 private Optional<UniTagInformation> getUniTagInformation(ConnectPoint cp, VlanId innerVlan, VlanId outerVlan,
765 int tpId) {
766 log.info("Getting uni tag information for cp: {}, innerVlan: {}, outerVlan: {}, tpId: {}", cp, innerVlan,
767 outerVlan, tpId);
768 SubscriberAndDeviceInformation subInfo = getSubscriber(cp);
Gamze Abakaf59c0912019-04-19 08:24:28 +0000769 if (subInfo == null) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000770 log.warn("Subscriber information doesn't exist for the connect point {}", cp);
771 return Optional.empty();
Gamze Abakaf59c0912019-04-19 08:24:28 +0000772 }
773
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000774 List<UniTagInformation> uniTagList = subInfo.uniTagList();
775 if (uniTagList == null) {
776 log.warn("Uni tag list is not found for the subscriber {}", subInfo.id());
777 return Optional.empty();
778 }
Amit Ghoshe1d3f092018-10-09 19:44:33 +0100779
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000780 UniTagInformation service = null;
781 for (UniTagInformation tagInfo : subInfo.uniTagList()) {
782 if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag())
783 && tpId == tagInfo.getTechnologyProfileId()) {
784 service = tagInfo;
785 break;
Andy Bavier160e8682019-05-07 18:32:22 -0700786 }
Gamze Abaka1efc80c2019-02-15 12:10:54 +0000787 }
Gamze Abaka1efc80c2019-02-15 12:10:54 +0000788
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000789 if (service == null) {
790 log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {}",
791 innerVlan, outerVlan, tpId);
792 return Optional.empty();
Gamze Abaka33feef52019-02-27 08:16:47 +0000793 }
794
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000795 return Optional.of(service);
Amit Ghosh95e2f652017-08-23 12:49:46 +0100796 }
797
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100798 /**
Jonathan Hart403372d2018-08-22 11:44:13 -0700799 * Creates trap flows for device, including DHCP and LLDP trap on NNI and
800 * EAPOL trap on the UNIs, if device is present in Sadis config.
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100801 *
802 * @param dev Device to look for
803 */
Jonathan Hart403372d2018-08-22 11:44:13 -0700804 private void checkAndCreateDeviceFlows(Device dev) {
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100805 // check if this device is provisioned in Sadis
Gamze Abaka641fc072018-09-04 09:16:27 +0000806 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000807 log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100808
809 if (deviceInfo != null) {
Jonathan Hart403372d2018-08-22 11:44:13 -0700810 // This is an OLT device as per Sadis, we create flows for UNI and NNI ports
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100811 for (Port p : deviceService.getPorts(dev.id())) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800812 if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000813 continue;
814 }
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100815 if (isUniPort(dev, p)) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000816 log.info("Creating Eapol for the uni {}", p);
817 oltFlowService.processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null,
818 VlanId.vlanId(EAPOL_DEFAULT_VLAN), true);
Jonathan Hart403372d2018-08-22 11:44:13 -0700819 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000820 oltFlowService.processNniFilteringObjectives(dev.id(), p.number(), true);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100821 }
822 }
823 }
824 }
825
Jonathan Hart403372d2018-08-22 11:44:13 -0700826
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100827 /**
828 * Get the uplink for of the OLT device.
Gamze Abakaad329652018-12-20 10:12:21 +0000829 * <p>
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100830 * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported
831 * this logic needs to be changed
832 *
833 * @param dev Device to look for
834 * @return The uplink Port of the OLT
835 */
836 private Port getUplinkPort(Device dev) {
837 // check if this device is provisioned in Sadis
Gamze Abaka641fc072018-09-04 09:16:27 +0000838 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
Saurav Daseae48de2019-06-19 13:26:15 -0700839 log.trace("getUplinkPort: deviceInfo {}", deviceInfo);
Saurav Das82b8e6d2018-10-04 15:25:12 -0700840 if (deviceInfo == null) {
841 log.warn("Device {} is not configured in SADIS .. cannot fetch device"
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000842 + " info", dev.id());
Saurav Das82b8e6d2018-10-04 15:25:12 -0700843 return null;
844 }
845 // Return the port that has been configured as the uplink port of this OLT in Sadis
Gamze Abakaad329652018-12-20 10:12:21 +0000846 for (Port p : deviceService.getPorts(dev.id())) {
Saurav Das82b8e6d2018-10-04 15:25:12 -0700847 if (p.number().toLong() == deviceInfo.uplinkPort()) {
Saurav Daseae48de2019-06-19 13:26:15 -0700848 log.trace("getUplinkPort: Found port {}", p);
Saurav Das82b8e6d2018-10-04 15:25:12 -0700849 return p;
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100850 }
851 }
852
Saurav Daseae48de2019-06-19 13:26:15 -0700853 log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id());
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100854 return null;
855 }
856
857 /**
858 * Return the subscriber on a port.
859 *
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800860 * @param cp ConnectPoint on which to find the subscriber
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100861 * @return subscriber if found else null
862 */
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800863 SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) {
864 Port port = deviceService.getPort(cp);
865 checkNotNull(port, "Invalid connect point");
866 String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100867 return subsService.get(portName);
868 }
869
Gamze Abakaad329652018-12-20 10:12:21 +0000870 /**
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000871 * Checks whether the given port of the device is a uni port or not.
872 *
873 * @param d the access device
874 * @param p the port of the device
875 * @return true if the given port is a uni port
Gamze Abakaad329652018-12-20 10:12:21 +0000876 */
Amit Ghosh1ed9aef2018-07-17 17:08:16 +0100877 private boolean isUniPort(Device d, Port p) {
878 Port ulPort = getUplinkPort(d);
879 if (ulPort != null) {
880 return (ulPort.number().toLong() != p.number().toLong());
881 }
Thomas Lee Sd7735f92020-02-20 19:21:47 +0530882 //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null
883 //checks whether the port name starts with nni- which is the signature of an NNI Port
884 if (p.annotations().value(AnnotationKeys.PORT_NAME) != null &&
885 p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) {
886 log.error("NNI port number {} is not matching with configured value", p.number().toLong());
887 return false;
888 }
889 return true;
Jonathan Hart1d34c8b2018-05-05 15:37:28 -0700890 }
891
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000892 /**
893 * Gets the given device details from SADIS.
894 * If the device is not found, returns null
895 *
896 * @param dev the access device
897 * @return the olt information
898 */
Jonathan Hart4c538002018-08-23 10:11:54 -0700899 private SubscriberAndDeviceInformation getOltInfo(Device dev) {
900 String devSerialNo = dev.serialNumber();
Gamze Abaka641fc072018-09-04 09:16:27 +0000901 return subsService.get(devSerialNo);
Jonathan Hart4c538002018-08-23 10:11:54 -0700902 }
903
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800904 /**
905 * Determines if this instance should handle this device based on
906 * consistent hashing.
907 *
908 * @param id device ID
909 * @return true if this instance should handle the device, otherwise false
910 */
911 private boolean isDeviceMine(DeviceId id) {
912 NodeId nodeId = hasher.hash(id.toString());
913 if (log.isDebugEnabled()) {
914 log.debug("Node that will handle {} is {}", id, nodeId);
915 }
916 return nodeId.equals(clusterService.getLocalNode().id());
917 }
918
alshabibf0e7e702015-05-30 18:22:36 -0700919 private class InternalDeviceListener implements DeviceListener {
Saurav Dasa9d5f442019-03-06 19:32:48 -0800920 private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet();
921
alshabibf0e7e702015-05-30 18:22:36 -0700922 @Override
923 public void event(DeviceEvent event) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700924 eventExecutor.execute(() -> {
925 DeviceId devId = event.subject().id();
926 Device dev = event.subject();
Gamze Abaka838d8142019-02-21 07:06:55 +0000927 Port port = event.port();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000928 DeviceEvent.Type eventType = event.type();
Jonathan Hart4c538002018-08-23 10:11:54 -0700929
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000930 if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) ||
931 DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) ||
932 DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700933 return;
934 }
Jonathan Hart4c538002018-08-23 10:11:54 -0700935
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800936 // Only handle the event if the device belongs to us
937 if (!isDeviceMine(event.subject().id())) {
938 return;
939 }
940
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000941 log.debug("OLT got {} event for {} {}", eventType, event.subject(), event.port());
942
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700943 if (getOltInfo(dev) == null) {
Saurav Dasa9d5f442019-03-06 19:32:48 -0800944 // it's possible that we got an event for a previously
945 // programmed OLT that is no longer available in SADIS
946 // we let such events go through
947 if (!programmedDevices.contains(devId)) {
948 log.warn("No device info found for {}, this is either "
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000949 + "not an OLT or not known to sadis", dev);
Saurav Dasa9d5f442019-03-06 19:32:48 -0800950 return;
951 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700952 }
Jonathan Hart4c538002018-08-23 10:11:54 -0700953
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700954 switch (event.type()) {
955 //TODO: Port handling and bookkeeping should be improved once
956 // olt firmware handles correct behaviour.
957 case PORT_ADDED:
Gamze Abaka838d8142019-02-21 07:06:55 +0000958 if (isUniPort(dev, port)) {
959 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port));
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000960
961 if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) {
962 log.info("eapol will be sent for port added {}", port);
963 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
964 null,
965 VlanId.vlanId(EAPOL_DEFAULT_VLAN), true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700966 }
967 } else {
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000968 SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev);
969 if (deviceInfo != null) {
970 oltFlowService.processNniFilteringObjectives(dev.id(), port.number(), true);
971 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700972 }
973 break;
974 case PORT_REMOVED:
Gamze Abaka838d8142019-02-21 07:06:55 +0000975 if (isUniPort(dev, port)) {
Gamze Abaka853bf252019-03-25 10:27:06 +0000976 removeSubscriber(new ConnectPoint(devId, port.number()));
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000977 log.info("eapol will be send for port removed", port);
978 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
979 null,
980 VlanId.vlanId(EAPOL_DEFAULT_VLAN), false);
Andy Bavier160e8682019-05-07 18:32:22 -0700981
Gamze Abaka838d8142019-02-21 07:06:55 +0000982 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port));
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700983 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700984 break;
985 case PORT_UPDATED:
Gamze Abaka838d8142019-02-21 07:06:55 +0000986 if (!isUniPort(dev, port)) {
Matteo Scandolo632f0fc2018-09-07 12:21:45 -0700987 break;
988 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -0800989 ConnectPoint cp = new ConnectPoint(devId, port.number());
990 Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value();
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000991 if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) {
Saurav Dasb776aef2020-03-09 14:29:46 -0700992 if (!port.number().equals(PortNumber.LOCAL)) {
993 log.info("eapol will be {} for dev/port updated {}/{}",
994 (port.isEnabled()) ? "added" : "removed",
995 devId, port.number());
Matteo Scandolo27c471c2020-02-11 16:41:53 -0800996 oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000997 null,
998 VlanId.vlanId(EAPOL_DEFAULT_VLAN),
999 port.isEnabled());
1000 }
1001 } else {
Saurav Dasb776aef2020-03-09 14:29:46 -07001002 log.info("eapol will be {} for dev/port updated {}/{}",
1003 (port.isEnabled()) ? "added" : "removed",
1004 devId, port.number());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001005 uniTagInformationSet.forEach(uniTag ->
1006 oltFlowService.processEapolFilteringObjectives(devId, port.number(),
1007 uniTag.getUpstreamBandwidthProfile(), null,
1008 uniTag.getPonCTag(), port.isEnabled()));
1009 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001010 if (port.isEnabled()) {
Gamze Abaka838d8142019-02-21 07:06:55 +00001011 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port));
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001012 } else {
Gamze Abaka838d8142019-02-21 07:06:55 +00001013 post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port));
Jonathan Hart1d34c8b2018-05-05 15:37:28 -07001014 }
alshabibbb83aa22016-02-10 15:08:23 -08001015 break;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001016 case DEVICE_ADDED:
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001017 handleDeviceConnection(dev, true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001018 break;
1019 case DEVICE_REMOVED:
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001020 handleDeviceDisconnection(dev, true);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001021 break;
1022 case DEVICE_AVAILABILITY_CHANGED:
1023 if (deviceService.isAvailable(devId)) {
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001024 handleDeviceConnection(dev, false);
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001025 } else {
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301026 if (deviceService.getPorts(devId).isEmpty()) {
1027 handleDeviceDisconnection(dev, false);
1028 }
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001029 }
1030 break;
Matteo Scandolo632f0fc2018-09-07 12:21:45 -07001031 default:
1032 return;
1033 }
1034 });
alshabibf0e7e702015-05-30 18:22:36 -07001035 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001036
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001037 private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) {
1038 deviceService.getPorts(device.id()).stream()
1039 .filter(p -> !PortNumber.LOCAL.equals(p.number()))
1040 .filter(p -> isUniPort(device, p))
1041 .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p)));
1042 }
1043
1044 private void handleDeviceDisconnection(Device device, boolean sendUniEvent) {
1045 programmedDevices.remove(device.id());
1046 removeAllSubscribers(device.id());
Hardik Windlassa58fbee2020-03-12 18:33:55 +05301047 flowRuleService.purgeFlowRules(device.id());
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001048 oltMeterService.clearMeters(device.id());
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001049 post(new AccessDeviceEvent(
1050 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(),
1051 null, null, null));
1052 if (sendUniEvent) {
1053 sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED);
Gamze Abaka838d8142019-02-21 07:06:55 +00001054 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001055 }
1056
1057 private void handleDeviceConnection(Device dev, boolean sendUniEvent) {
1058 post(new AccessDeviceEvent(
1059 AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(),
1060 null, null, null));
1061 programmedDevices.add(dev.id());
1062 checkAndCreateDeviceFlows(dev);
1063 if (sendUniEvent) {
1064 sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED);
1065 }
Gamze Abaka838d8142019-02-21 07:06:55 +00001066 }
Gamze Abakada282b42019-03-11 13:16:48 +00001067
1068 private void removeAllSubscribers(DeviceId deviceId) {
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001069 List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream()
1070 .filter(e -> e.getKey().deviceId().equals(deviceId))
1071 .collect(toList());
Gamze Abakada282b42019-03-11 13:16:48 +00001072
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001073 subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue()));
Gamze Abakada282b42019-03-11 13:16:48 +00001074 }
Gamze Abaka641fc072018-09-04 09:16:27 +00001075
Gamze Abaka641fc072018-09-04 09:16:27 +00001076 }
Jonathan Hart4f178fa2020-02-03 10:46:01 -08001077
1078 private class InternalClusterListener implements ClusterEventListener {
1079
1080 @Override
1081 public void event(ClusterEvent event) {
1082 if (event.type() == ClusterEvent.Type.INSTANCE_READY) {
1083 hasher.addServer(event.subject().id());
1084 }
1085 if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
1086 hasher.removeServer(event.subject().id());
1087 }
1088 }
1089 }
Hardik Windlass395ff372019-06-13 05:16:00 +00001090}