alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | d6a135a | 2017-08-03 22:46:05 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 16 | package org.opencord.olt.impl; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 17 | |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
Andrea Campanella | 971d5b9 | 2020-05-07 11:20:43 +0200 | [diff] [blame] | 19 | import static com.google.common.base.Strings.isNullOrEmpty; |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 20 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 21 | import static java.util.stream.Collectors.collectingAndThen; |
| 22 | import static java.util.stream.Collectors.groupingBy; |
| 23 | import static java.util.stream.Collectors.mapping; |
| 24 | import static java.util.stream.Collectors.toList; |
| 25 | import static java.util.stream.Collectors.toSet; |
| 26 | import static org.onlab.util.Tools.get; |
| 27 | import static org.onlab.util.Tools.groupedThreads; |
| 28 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID; |
| 29 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID_DEFAULT; |
| 30 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME; |
| 31 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME_DEFAULT; |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 32 | import static org.opencord.olt.impl.OsgiPropertyConstants.EAPOL_DELETE_RETRY_MAX_ATTEMPS; |
| 33 | import static org.opencord.olt.impl.OsgiPropertyConstants.EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT; |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 34 | import static org.slf4j.LoggerFactory.getLogger; |
| 35 | |
| 36 | import java.util.ArrayList; |
| 37 | import java.util.Collection; |
| 38 | import java.util.Dictionary; |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 39 | import java.util.Iterator; |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 40 | import java.util.List; |
| 41 | import java.util.Map; |
| 42 | import java.util.Optional; |
| 43 | import java.util.Properties; |
| 44 | import java.util.Set; |
| 45 | import java.util.concurrent.CompletableFuture; |
| 46 | import java.util.concurrent.ExecutorService; |
| 47 | import java.util.concurrent.Executors; |
| 48 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 49 | import org.onlab.packet.VlanId; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 50 | import org.onlab.util.KryoNamespace; |
Gamze Abaka | 1f62dd9 | 2020-05-07 08:58:13 +0000 | [diff] [blame] | 51 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 52 | import org.onosproject.cluster.ClusterEvent; |
| 53 | import org.onosproject.cluster.ClusterEventListener; |
| 54 | import org.onosproject.cluster.ClusterService; |
| 55 | import org.onosproject.cluster.ControllerNode; |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 56 | import org.onosproject.cluster.LeadershipService; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 57 | import org.onosproject.cluster.NodeId; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 58 | import org.onosproject.core.ApplicationId; |
| 59 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 60 | import org.onosproject.event.AbstractListenerManager; |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 61 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 62 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 63 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 64 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 65 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 66 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 67 | import org.onosproject.net.PortNumber; |
| 68 | import org.onosproject.net.device.DeviceEvent; |
| 69 | import org.onosproject.net.device.DeviceListener; |
| 70 | import org.onosproject.net.device.DeviceService; |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 71 | import org.onosproject.net.flow.FlowRuleService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 72 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 73 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 74 | import org.onosproject.net.flowobjective.Objective; |
| 75 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 76 | import org.onosproject.net.flowobjective.ObjectiveError; |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 77 | import org.onosproject.net.meter.MeterId; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 78 | import org.onosproject.store.serializers.KryoNamespaces; |
| 79 | import org.onosproject.store.service.ConsistentMultimap; |
| 80 | import org.onosproject.store.service.Serializer; |
| 81 | import org.onosproject.store.service.StorageService; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 82 | import org.opencord.olt.AccessDeviceEvent; |
| 83 | import org.opencord.olt.AccessDeviceListener; |
| 84 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 85 | import org.opencord.olt.AccessSubscriberId; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 86 | import org.opencord.olt.internalapi.AccessDeviceFlowService; |
| 87 | import org.opencord.olt.internalapi.AccessDeviceMeterService; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 88 | import org.opencord.sadis.BandwidthProfileInformation; |
| 89 | import org.opencord.sadis.BaseInformationService; |
| 90 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 91 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 92 | import org.opencord.sadis.UniTagInformation; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 93 | import org.osgi.service.component.ComponentContext; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 94 | import org.osgi.service.component.annotations.Activate; |
| 95 | import org.osgi.service.component.annotations.Component; |
| 96 | import org.osgi.service.component.annotations.Deactivate; |
| 97 | import org.osgi.service.component.annotations.Modified; |
| 98 | import org.osgi.service.component.annotations.Reference; |
| 99 | import org.osgi.service.component.annotations.ReferenceCardinality; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 100 | import org.slf4j.Logger; |
| 101 | |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 102 | import com.google.common.collect.ImmutableMap; |
| 103 | import com.google.common.collect.Sets; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 106 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 107 | */ |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 108 | @Component(immediate = true, |
| 109 | property = { |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 110 | DEFAULT_BP_ID + ":String=" + DEFAULT_BP_ID_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 111 | DEFAULT_MCAST_SERVICE_NAME + ":String=" + DEFAULT_MCAST_SERVICE_NAME_DEFAULT, |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 112 | EAPOL_DELETE_RETRY_MAX_ATTEMPS + ":Integer=" + |
| 113 | EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT, |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 114 | }) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 115 | public class Olt |
| 116 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 117 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 118 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 119 | |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 120 | private static final short EAPOL_DEFAULT_VLAN = 4091; |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 121 | private static final String NO_UPLINK_PORT = "No uplink port found for OLT device {}"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 122 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 123 | public static final int HASH_WEIGHT = 10; |
| 124 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 125 | private final Logger log = getLogger(getClass()); |
| 126 | |
Thomas Lee S | d7735f9 | 2020-02-20 19:21:47 +0530 | [diff] [blame] | 127 | private static final String NNI = "nni-"; |
| 128 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 130 | protected FlowObjectiveService flowObjectiveService; |
| 131 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 132 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 133 | protected DeviceService deviceService; |
| 134 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 135 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 136 | protected CoreService coreService; |
| 137 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 139 | protected SadisService sadisService; |
| 140 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 142 | protected AccessDeviceFlowService oltFlowService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 143 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 144 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 145 | protected AccessDeviceMeterService oltMeterService; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 146 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 147 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 148 | protected StorageService storageService; |
| 149 | |
| 150 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 151 | protected ClusterService clusterService; |
| 152 | |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 153 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 154 | protected MastershipService mastershipService; |
| 155 | |
| 156 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 157 | protected LeadershipService leadershipService; |
| 158 | |
| 159 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 160 | protected FlowRuleService flowRuleService; |
| 161 | |
Gamze Abaka | 1f62dd9 | 2020-05-07 08:58:13 +0000 | [diff] [blame] | 162 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 163 | protected ComponentConfigService componentConfigService; |
| 164 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 165 | /** |
Carmelo Cascone | 95ff512 | 2019-11-14 14:19:13 -0800 | [diff] [blame] | 166 | * Default bandwidth profile id that is used for authentication trap flows. |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 167 | **/ |
| 168 | protected String defaultBpId = DEFAULT_BP_ID_DEFAULT; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 169 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 170 | /** |
Gamze Abaka | 51a34e8 | 2020-05-08 13:03:14 +0000 | [diff] [blame] | 171 | * Default multicast service name. |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 172 | **/ |
Gamze Abaka | 51a34e8 | 2020-05-08 13:03:14 +0000 | [diff] [blame] | 173 | protected String multicastServiceName = DEFAULT_MCAST_SERVICE_NAME_DEFAULT; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 174 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Default amounts of eapol retry. |
| 177 | **/ |
| 178 | protected int eapolDeleteRetryMaxAttempts = EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT; |
| 179 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 180 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 181 | private final ClusterEventListener clusterListener = new InternalClusterListener(); |
| 182 | |
| 183 | private ConsistentHasher hasher; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 184 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 185 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
| 186 | private BaseInformationService<BandwidthProfileInformation> bpService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 187 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 188 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 189 | groupedThreads("onos/olt-service", |
| 190 | "olt-installer-%d")); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 191 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 192 | protected ExecutorService eventExecutor; |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 193 | protected ExecutorService retryExecutor; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 194 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 195 | private ConsistentMultimap<ConnectPoint, UniTagInformation> programmedSubs; |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 196 | private ConsistentMultimap<ConnectPoint, UniTagInformation> failedSubs; |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 197 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 198 | private Set<SubscriberFlowInfo> pendingSubscribers; |
| 199 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 200 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 201 | public void activate(ComponentContext context) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 202 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt", |
| 203 | "events-%d", log)); |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 204 | retryExecutor = Executors.newCachedThreadPool(); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 205 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 206 | modified(context); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 207 | ApplicationId appId = coreService.registerApplication(APP_NAME); |
Gamze Abaka | 1f62dd9 | 2020-05-07 08:58:13 +0000 | [diff] [blame] | 208 | componentConfigService.registerProperties(getClass()); |
Saurav Das | 62ad75e | 2019-03-05 12:22:22 -0800 | [diff] [blame] | 209 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 210 | KryoNamespace serializer = KryoNamespace.newBuilder() |
| 211 | .register(KryoNamespaces.API) |
| 212 | .register(UniTagInformation.class) |
| 213 | .build(); |
| 214 | |
| 215 | programmedSubs = storageService.<ConnectPoint, UniTagInformation>consistentMultimapBuilder() |
| 216 | .withName("volt-programmed-subs") |
| 217 | .withSerializer(Serializer.using(serializer)) |
| 218 | .withApplicationId(appId) |
| 219 | .build(); |
alshabib | c4dfe85 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 220 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 221 | failedSubs = storageService.<ConnectPoint, UniTagInformation>consistentMultimapBuilder() |
| 222 | .withName("volt-failed-subs") |
| 223 | .withSerializer(Serializer.using(serializer)) |
| 224 | .withApplicationId(appId) |
| 225 | .build(); |
| 226 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 227 | pendingSubscribers = Sets.newConcurrentHashSet(); |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 228 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 229 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 230 | subsService = sadisService.getSubscriberInfoService(); |
| 231 | bpService = sadisService.getBandwidthProfileService(); |
| 232 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 233 | List<NodeId> readyNodes = clusterService.getNodes().stream() |
| 234 | .filter(c -> clusterService.getState(c.id()) == ControllerNode.State.READY) |
| 235 | .map(ControllerNode::id) |
| 236 | .collect(toList()); |
| 237 | hasher = new ConsistentHasher(readyNodes, HASH_WEIGHT); |
| 238 | clusterService.addListener(clusterListener); |
| 239 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 240 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 241 | // UNI ports |
| 242 | Iterable<Device> devices = deviceService.getDevices(); |
| 243 | for (Device d : devices) { |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 244 | if (isLocalLeader(d.id())) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 245 | checkAndCreateDeviceFlows(d); |
| 246 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 247 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 248 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 249 | deviceService.addListener(deviceListener); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 250 | log.info("Started with Application ID {}", appId.id()); |
| 251 | } |
| 252 | |
| 253 | @Deactivate |
| 254 | public void deactivate() { |
Gamze Abaka | 1f62dd9 | 2020-05-07 08:58:13 +0000 | [diff] [blame] | 255 | componentConfigService.unregisterProperties(getClass(), false); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 256 | clusterService.removeListener(clusterListener); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 257 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 258 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 259 | eventExecutor.shutdown(); |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 260 | retryExecutor.shutdown(); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 261 | log.info("Stopped"); |
| 262 | } |
| 263 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 264 | @Modified |
| 265 | public void modified(ComponentContext context) { |
| 266 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 267 | |
| 268 | try { |
Andrea Campanella | 971d5b9 | 2020-05-07 11:20:43 +0200 | [diff] [blame] | 269 | String bpId = get(properties, DEFAULT_BP_ID); |
| 270 | defaultBpId = isNullOrEmpty(bpId) ? defaultBpId : bpId; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 271 | |
Andrea Campanella | 971d5b9 | 2020-05-07 11:20:43 +0200 | [diff] [blame] | 272 | String mcastSN = get(properties, DEFAULT_MCAST_SERVICE_NAME); |
| 273 | multicastServiceName = isNullOrEmpty(mcastSN) ? multicastServiceName : mcastSN; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 274 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 275 | String eapolDeleteRetryNew = get(properties, EAPOL_DELETE_RETRY_MAX_ATTEMPS); |
| 276 | eapolDeleteRetryMaxAttempts = isNullOrEmpty(eapolDeleteRetryNew) ? EAPOL_DELETE_RETRY_MAX_ATTEMPS_DEFAULT : |
| 277 | Integer.parseInt(eapolDeleteRetryNew.trim()); |
| 278 | |
| 279 | log.debug("OLT properties: DefaultBpId: {}, MulticastServiceName: {}, EapolDeleteRetryMaxAttempts: {}", |
| 280 | defaultBpId, multicastServiceName, eapolDeleteRetryMaxAttempts); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 281 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 282 | } catch (Exception e) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 283 | log.error("Error while modifying the properties", e); |
Andrea Campanella | 971d5b9 | 2020-05-07 11:20:43 +0200 | [diff] [blame] | 284 | defaultBpId = DEFAULT_BP_ID_DEFAULT; |
| 285 | multicastServiceName = DEFAULT_MCAST_SERVICE_NAME_DEFAULT; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 289 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 290 | public boolean provisionSubscriber(ConnectPoint connectPoint) { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 291 | log.info("Call to provision subscriber at {}", connectPoint); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 292 | DeviceId deviceId = connectPoint.deviceId(); |
| 293 | PortNumber subscriberPortNo = connectPoint.port(); |
| 294 | |
| 295 | checkNotNull(deviceService.getPort(deviceId, subscriberPortNo), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 296 | "Invalid connect point:" + connectPoint); |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 297 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 298 | // Find the subscriber on this connect point |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 299 | SubscriberAndDeviceInformation sub = getSubscriber(connectPoint); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 300 | if (sub == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 301 | log.warn("No subscriber found for {}", connectPoint); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 302 | return false; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 303 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 304 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 305 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 306 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 307 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 308 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 309 | return false; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 312 | // delete Eapol authentication flow with default bandwidth |
| 313 | // wait until Eapol rule with defaultBpId is removed to install subscriber-based rules |
| 314 | // retry deletion if it fails/times-out |
| 315 | retryExecutor.execute(new DeleteEapolInstallSub(connectPoint, |
| 316 | uplinkPort, sub, 1)); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 317 | return true; |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 320 | private class DeleteEapolInstallSub implements Runnable { |
| 321 | ConnectPoint cp; |
| 322 | Port uplinkPort; |
| 323 | SubscriberAndDeviceInformation sub; |
| 324 | private int attemptNumber; |
| 325 | |
| 326 | DeleteEapolInstallSub(ConnectPoint cp, Port uplinkPort, |
| 327 | SubscriberAndDeviceInformation sub, |
| 328 | int attemptNumber) { |
| 329 | this.cp = cp; |
| 330 | this.uplinkPort = uplinkPort; |
| 331 | this.sub = sub; |
| 332 | this.attemptNumber = attemptNumber; |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void run() { |
| 337 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 338 | oltFlowService.processEapolFilteringObjectives(cp.deviceId(), cp.port(), |
| 339 | defaultBpId, filterFuture, |
| 340 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 341 | false); |
| 342 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 343 | if (filterStatus == null) { |
| 344 | log.info("Default eapol flow deleted in attempt {} of {}" |
| 345 | + "... provisioning subscriber flows {}", |
| 346 | attemptNumber, eapolDeleteRetryMaxAttempts, cp); |
| 347 | provisionUniTagList(cp, uplinkPort.number(), sub); |
| 348 | } else { |
| 349 | if (attemptNumber <= eapolDeleteRetryMaxAttempts) { |
| 350 | log.warn("The filtering future failed {} for subscriber {}" |
| 351 | + "... retrying {} of {} attempts", |
| 352 | filterStatus, cp, attemptNumber, eapolDeleteRetryMaxAttempts); |
| 353 | retryExecutor.execute( |
| 354 | new DeleteEapolInstallSub(cp, uplinkPort, sub, |
| 355 | attemptNumber + 1)); |
| 356 | } else { |
| 357 | log.error("The filtering future failed {} for subscriber {}" |
| 358 | + "after {} attempts. Subscriber provisioning failed", |
| 359 | filterStatus, cp, eapolDeleteRetryMaxAttempts); |
| 360 | sub.uniTagList().forEach(ut -> failedSubs.put(cp, ut)); |
| 361 | } |
| 362 | } |
| 363 | }); |
| 364 | } |
| 365 | |
| 366 | } |
| 367 | |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 368 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 369 | public boolean removeSubscriber(ConnectPoint connectPoint) { |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 370 | log.info("Call to un-provision subscriber at {}", connectPoint); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 371 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 372 | // Get the subscriber connected to this port from the local cache |
| 373 | // If we don't know about the subscriber there's no need to remove it |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 374 | DeviceId deviceId = connectPoint.deviceId(); |
| 375 | PortNumber subscriberPortNo = connectPoint.port(); |
| 376 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 377 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(connectPoint).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 378 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 379 | log.warn("Subscriber on connectionPoint {} was not previously programmed, " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 380 | "no need to remove it", connectPoint); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 381 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 384 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 385 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 386 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 387 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 388 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 391 | for (UniTagInformation uniTag : uniTagInformationSet) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 392 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 393 | if (multicastServiceName.equals(uniTag.getServiceName())) { |
| 394 | continue; |
| 395 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 396 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 397 | unprovisionVlans(deviceId, uplinkPort.number(), subscriberPortNo, uniTag); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 398 | |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 399 | // remove eapol with subscriber bandwidth profile |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 400 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, |
| 401 | uniTag.getUpstreamBandwidthProfile(), |
| 402 | null, uniTag.getPonCTag(), false); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 403 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 404 | Port port = deviceService.getPort(deviceId, subscriberPortNo); |
| 405 | if (port != null && port.isEnabled()) { |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 406 | // reinstall eapol with default bandwidth profile |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 407 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, |
| 408 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 409 | } else { |
| 410 | log.debug("Port {} is no longer enabled or it's unavailable. Not " |
| 411 | + "reprogramming default eapol flow", connectPoint); |
| 412 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 413 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 414 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 417 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 418 | @Override |
| 419 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 420 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
| 421 | |
| 422 | log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}, tpId {}" + |
| 423 | "", subscriberId, sTag, cTag, tpId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 424 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 425 | // Check if we can find the connect point to which this subscriber is connected |
| 426 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 427 | if (subsPort == null) { |
| 428 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 429 | return false; |
| 430 | } |
| 431 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 432 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 433 | return provisionSubscriber(subsPort); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 434 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 435 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 436 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 437 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 438 | return false; |
| 439 | } |
| 440 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 441 | //delete Eapol authentication flow with default bandwidth |
| 442 | //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 443 | //install subscriber flows |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 444 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 445 | oltFlowService.processEapolFilteringObjectives(subsPort.deviceId(), subsPort.port(), defaultBpId, |
| 446 | filterFuture, VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 447 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 448 | if (filterStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 449 | provisionUniTagInformation(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 450 | cTag.get(), sTag.get(), tpId.get()); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 451 | } |
| 452 | }); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 453 | return true; |
| 454 | } else { |
| 455 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 456 | return false; |
| 457 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 458 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 459 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 460 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 461 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 462 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 463 | // Check if we can find the connect point to which this subscriber is connected |
| 464 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 465 | if (subsPort == null) { |
| 466 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 467 | return false; |
| 468 | } |
| 469 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 470 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 471 | return removeSubscriber(subsPort); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 472 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 473 | // Get the uplink port |
| 474 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 475 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 476 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 477 | return false; |
| 478 | } |
| 479 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 480 | Optional<UniTagInformation> tagInfo = getUniTagInformation(subsPort, cTag.get(), sTag.get(), tpId.get()); |
| 481 | if (!tagInfo.isPresent()) { |
| 482 | log.warn("UniTagInformation does not exist for Device/Port {}, cTag {}, sTag {}, tpId {}", |
| 483 | subsPort, cTag, sTag, tpId); |
| 484 | return false; |
| 485 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 486 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 487 | unprovisionVlans(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), tagInfo.get()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 488 | return true; |
| 489 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 490 | log.warn("Removing subscriber is not possible - please check the provided information" + |
| 491 | "for the subscriber: {}", subscriberId); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 492 | return false; |
| 493 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 497 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getProgSubs() { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 498 | return programmedSubs.stream() |
| 499 | .collect(collectingAndThen( |
| 500 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 501 | ImmutableMap::copyOf)); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | @Override |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 505 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getFailedSubs() { |
| 506 | return failedSubs.stream() |
| 507 | .collect(collectingAndThen( |
| 508 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 509 | ImmutableMap::copyOf)); |
| 510 | } |
| 511 | |
| 512 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 513 | public List<DeviceId> fetchOlts() { |
| 514 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 515 | List<DeviceId> olts = new ArrayList<>(); |
| 516 | Iterable<Device> devices = deviceService.getDevices(); |
| 517 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 518 | if (getOltInfo(d) != null) { |
| 519 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 520 | olts.add(d.id()); |
| 521 | } |
| 522 | } |
| 523 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 526 | /** |
| 527 | * Finds the connect point to which a subscriber is connected. |
| 528 | * |
| 529 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 530 | * @return Subscribers ConnectPoint if found else null |
| 531 | */ |
| 532 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 533 | |
| 534 | Iterable<Device> devices = deviceService.getDevices(); |
| 535 | for (Device d : devices) { |
| 536 | for (Port p : deviceService.getPorts(d.id())) { |
| 537 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 538 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 539 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 540 | return new ConnectPoint(d.id(), p.number()); |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | return null; |
| 545 | } |
| 546 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 547 | /** |
| 548 | * Gets the context of the bandwidth profile information for the given parameter. |
| 549 | * |
| 550 | * @param bandwidthProfile the bandwidth profile id |
| 551 | * @return the context of the bandwidth profile information |
| 552 | */ |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 553 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
| 554 | if (bandwidthProfile == null) { |
| 555 | return null; |
| 556 | } |
| 557 | return bpService.get(bandwidthProfile); |
| 558 | } |
| 559 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 560 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 561 | * Removes subscriber vlan flows. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 562 | * |
| 563 | * @param deviceId the device identifier |
| 564 | * @param uplink uplink port of the OLT |
| 565 | * @param subscriberPort uni port |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 566 | * @param uniTag uni tag information |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 567 | */ |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 568 | private void unprovisionVlans(DeviceId deviceId, PortNumber uplink, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 569 | PortNumber subscriberPort, UniTagInformation uniTag) { |
| 570 | |
| 571 | log.info("Unprovisioning vlans for {} at {}/{}", uniTag, deviceId, subscriberPort); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 572 | |
| 573 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 574 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 575 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 576 | VlanId deviceVlan = uniTag.getPonSTag(); |
| 577 | VlanId subscriberVlan = uniTag.getPonCTag(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 578 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 579 | MeterId upstreamMeterId = oltMeterService |
| 580 | .getMeterIdFromBpMapping(deviceId, uniTag.getUpstreamBandwidthProfile()); |
| 581 | MeterId downstreamMeterId = oltMeterService |
| 582 | .getMeterIdFromBpMapping(deviceId, uniTag.getDownstreamBandwidthProfile()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 583 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 584 | ForwardingObjective.Builder upFwd = |
| 585 | oltFlowService.createUpBuilder(uplink, subscriberPort, upstreamMeterId, uniTag); |
| 586 | ForwardingObjective.Builder downFwd = |
| 587 | oltFlowService.createDownBuilder(uplink, subscriberPort, downstreamMeterId, uniTag); |
| 588 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 589 | oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort, |
| 590 | upstreamMeterId, uniTag, false, true); |
| 591 | oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort, |
| 592 | upstreamMeterId, uniTag, false, true); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 593 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 594 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 595 | @Override |
| 596 | public void onSuccess(Objective objective) { |
| 597 | upFuture.complete(null); |
| 598 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 599 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 600 | @Override |
| 601 | public void onError(Objective objective, ObjectiveError error) { |
| 602 | upFuture.complete(error); |
| 603 | } |
| 604 | })); |
| 605 | |
| 606 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 607 | @Override |
| 608 | public void onSuccess(Objective objective) { |
| 609 | downFuture.complete(null); |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public void onError(Objective objective, ObjectiveError error) { |
| 614 | downFuture.complete(error); |
| 615 | } |
| 616 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 617 | |
| 618 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 619 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 620 | if (upStatus == null && downStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 621 | log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {}, and" + |
| 622 | "Device/Port{}", uniTag.getPonCTag(), uniTag.getPonSTag(), |
| 623 | uniTag.getTechnologyProfileId(), subscriberPort); |
| 624 | updateProgrammedSubscriber(new ConnectPoint(deviceId, subscriberPort), uniTag, false); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 625 | } else if (downStatus != null) { |
| 626 | log.error("Subscriber with vlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 627 | "on port {} failed downstream uninstallation: {}", |
| 628 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 629 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 630 | } else if (upStatus != null) { |
| 631 | log.error("Subscriber with vlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 632 | "on port {} failed upstream uninstallation: {}", |
| 633 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 634 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 635 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 636 | Port port = deviceService.getPort(deviceId, subscriberPort); |
| 637 | post(new AccessDeviceEvent(type, deviceId, port, deviceVlan, subscriberVlan, |
| 638 | uniTag.getTechnologyProfileId())); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 639 | }, oltInstallers); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 642 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 643 | * Adds subscriber vlan flows, dhcp, eapol and igmp trap flows for the related uni port. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 644 | * |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 645 | * @param connectPoint the connection point of the subscriber |
| 646 | * @param uplinkPort uplink port of the OLT (the nni port) |
| 647 | * @param sub subscriber information that includes s, c tags, tech profile and bandwidth profile references |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 648 | */ |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 649 | private void provisionUniTagList(ConnectPoint connectPoint, PortNumber uplinkPort, |
| 650 | SubscriberAndDeviceInformation sub) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 651 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 652 | log.debug("Provisioning vlans for subscriber {} on dev/port: {}", sub, connectPoint); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 653 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 654 | if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) { |
| 655 | log.warn("Unitaglist doesn't exist for the subscriber {}", sub.id()); |
| 656 | return; |
| 657 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 658 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 659 | DeviceId deviceId = connectPoint.deviceId(); |
| 660 | PortNumber subscriberPort = connectPoint.port(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 661 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 662 | for (UniTagInformation uniTag : sub.uniTagList()) { |
| 663 | handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, uniTag); |
| 664 | } |
| 665 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 666 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 667 | /** |
| 668 | * Finds the uni tag information and provisions the found information. |
| 669 | * If the uni tag information is not found, returns |
| 670 | * |
| 671 | * @param deviceId the access device id |
| 672 | * @param uplinkPort the nni port |
| 673 | * @param subscriberPort the uni port |
| 674 | * @param innerVlan the pon c tag |
| 675 | * @param outerVlan the pon s tag |
| 676 | * @param tpId the technology profile id |
| 677 | */ |
| 678 | private void provisionUniTagInformation(DeviceId deviceId, PortNumber uplinkPort, |
| 679 | PortNumber subscriberPort, |
| 680 | VlanId innerVlan, |
| 681 | VlanId outerVlan, |
| 682 | Integer tpId) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 683 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 684 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 685 | Optional<UniTagInformation> gotTagInformation = getUniTagInformation(cp, innerVlan, outerVlan, tpId); |
| 686 | if (!gotTagInformation.isPresent()) { |
| 687 | return; |
| 688 | } |
| 689 | UniTagInformation tagInformation = gotTagInformation.get(); |
| 690 | handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, tagInformation); |
| 691 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 692 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 693 | private void updateProgrammedSubscriber(ConnectPoint connectPoint, UniTagInformation tagInformation, Boolean add) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 694 | if (add) { |
| 695 | programmedSubs.put(connectPoint, tagInformation); |
| 696 | } else { |
| 697 | programmedSubs.remove(connectPoint, tagInformation); |
| 698 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 701 | /** |
| 702 | * Installs a uni tag information flow. |
| 703 | * |
| 704 | * @param deviceId the access device id |
| 705 | * @param uplinkPort the nni port |
| 706 | * @param subscriberPort the uni port |
| 707 | * @param tagInfo the uni tag information |
| 708 | */ |
| 709 | private void handleSubscriberFlows(DeviceId deviceId, PortNumber uplinkPort, PortNumber subscriberPort, |
| 710 | UniTagInformation tagInfo) { |
| 711 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 712 | log.debug("Provisioning vlan-based flows for the uniTagInformation {}", tagInfo); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 713 | |
| 714 | Port port = deviceService.getPort(deviceId, subscriberPort); |
| 715 | |
| 716 | if (multicastServiceName.equals(tagInfo.getServiceName())) { |
| 717 | // IGMP flows are taken care of along with VOD service |
| 718 | // Please note that for each service, Subscriber Registered event will be sent |
| 719 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED, |
| 720 | deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 721 | tagInfo.getTechnologyProfileId())); |
| 722 | return; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 725 | BandwidthProfileInformation upstreamBpInfo = |
| 726 | getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile()); |
| 727 | BandwidthProfileInformation downstreamBpInfo = |
| 728 | getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 729 | if (upstreamBpInfo == null) { |
| 730 | log.warn("No meter installed since no Upstream BW Profile definition found for " |
| 731 | + "ctag {} stag {} tpId {} and Device/port: {}:{}", |
| 732 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
| 733 | tagInfo.getTechnologyProfileId(), deviceId, |
| 734 | subscriberPort); |
| 735 | return; |
| 736 | } |
| 737 | if (downstreamBpInfo == null) { |
| 738 | log.warn("No meter installed since no Downstream BW Profile definition found for " |
| 739 | + "ctag {} stag {} tpId {} and Device/port: {}:{}", |
| 740 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
| 741 | tagInfo.getTechnologyProfileId(), deviceId, |
| 742 | subscriberPort); |
| 743 | return; |
| 744 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 745 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 746 | // check for meterIds for the upstream and downstream bandwidth profiles |
| 747 | MeterId upMeterId = oltMeterService |
| 748 | .getMeterIdFromBpMapping(deviceId, upstreamBpInfo.id()); |
| 749 | MeterId downMeterId = oltMeterService |
| 750 | .getMeterIdFromBpMapping(deviceId, downstreamBpInfo.id()); |
| 751 | SubscriberFlowInfo fi = new SubscriberFlowInfo(deviceId, uplinkPort, subscriberPort, |
| 752 | tagInfo, downMeterId, upMeterId, |
| 753 | downstreamBpInfo.id(), upstreamBpInfo.id()); |
| 754 | |
| 755 | if (upMeterId != null && downMeterId != null) { |
| 756 | log.debug("Meters are existing for upstream {} and downstream {}", |
| 757 | upstreamBpInfo.id(), downstreamBpInfo.id()); |
| 758 | handleSubFlowsWithMeters(fi); |
| 759 | } else { |
| 760 | log.debug("Adding {} to pending subs", fi); |
| 761 | // one or both meters are not ready. It's possible they are in the process of being |
| 762 | // created for other subscribers that share the same bandwidth profile. |
| 763 | pendingSubscribers.add(fi); |
| 764 | |
| 765 | // queue up the meters to be created |
| 766 | if (upMeterId == null) { |
| 767 | log.debug("Missing meter for upstream {}", upstreamBpInfo.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 768 | checkAndCreateDevMeter(deviceId, upstreamBpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 769 | } |
| 770 | if (downMeterId == null) { |
| 771 | log.debug("Missing meter for downstream {}", downstreamBpInfo.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 772 | checkAndCreateDevMeter(deviceId, downstreamBpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 776 | private void checkAndCreateDevMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 777 | if (oltMeterService.isMeterPending(deviceId, bwpInfo)) { |
| 778 | log.debug("Meter is already pending {} on device {}", bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 779 | return; |
| 780 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 781 | oltMeterService.addToPendingMeters(deviceId, bwpInfo); |
| 782 | createMeter(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 785 | private void createMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 786 | log.debug("Creating Meter with {} on {} for subscriber", bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 787 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 788 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 789 | MeterId meterId = oltMeterService.createMeter(deviceId, bwpInfo, |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 790 | meterFuture); |
| 791 | |
| 792 | meterFuture.thenAcceptAsync(result -> { |
| 793 | // iterate through the subscribers on hold |
| 794 | Iterator<SubscriberFlowInfo> subsIterator = pendingSubscribers.iterator(); |
| 795 | while (subsIterator.hasNext()) { |
| 796 | SubscriberFlowInfo fi = subsIterator.next(); |
| 797 | if (result == null) { |
| 798 | // meter install sent to device |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 799 | log.debug("Meter {} installed for bw {} on {}", meterId, bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 800 | |
| 801 | MeterId upMeterId = oltMeterService |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 802 | .getMeterIdFromBpMapping(deviceId, fi.getUpBpInfo()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 803 | MeterId downMeterId = oltMeterService |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 804 | .getMeterIdFromBpMapping(deviceId, fi.getDownBpInfo()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 805 | if (upMeterId != null && downMeterId != null) { |
| 806 | log.debug("Provisioning subscriber after meter {}" + |
| 807 | "installation and both meters are present " + |
| 808 | "upstream {} and downstream {}", |
| 809 | meterId, upMeterId, downMeterId); |
| 810 | // put in the meterIds because when fi was first |
| 811 | // created there may or may not have been a meterId |
| 812 | // depending on whether the meter was created or |
| 813 | // not at that time. |
| 814 | fi.setUpMeterId(upMeterId); |
| 815 | fi.setDownMeterId(downMeterId); |
| 816 | handleSubFlowsWithMeters(fi); |
| 817 | subsIterator.remove(); |
| 818 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 819 | oltMeterService.removeFromPendingMeters(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 820 | } else { |
| 821 | // meter install failed |
| 822 | log.error("Addition of subscriber {} failed due to meter " + |
| 823 | "{} with result {}", fi, meterId, result); |
| 824 | subsIterator.remove(); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 825 | oltMeterService.removeFromPendingMeters(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | }); |
| 829 | } |
| 830 | /** |
| 831 | * Add subscriber flows given meter information for both upstream and |
| 832 | * downstream directions. |
| 833 | * |
| 834 | * @param subscriberFlowInfo relevant information for subscriber |
| 835 | */ |
| 836 | private void handleSubFlowsWithMeters(SubscriberFlowInfo subscriberFlowInfo) { |
| 837 | log.debug("Provisioning subscriber flows based on {}", subscriberFlowInfo); |
| 838 | UniTagInformation tagInfo = subscriberFlowInfo.getTagInfo(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 839 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>(); |
| 840 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 841 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 842 | ForwardingObjective.Builder upFwd = |
| 843 | oltFlowService.createUpBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(), |
| 844 | subscriberFlowInfo.getUpId(), subscriberFlowInfo.getTagInfo()); |
| 845 | flowObjectiveService.forward(subscriberFlowInfo.getDevId(), upFwd.add(new ObjectiveContext() { |
| 846 | @Override |
| 847 | public void onSuccess(Objective objective) { |
| 848 | log.debug("Upstream flow installed successfully {}", subscriberFlowInfo); |
| 849 | upFuture.complete(null); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 850 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 851 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 852 | @Override |
| 853 | public void onError(Objective objective, ObjectiveError error) { |
| 854 | upFuture.complete(error); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 855 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 856 | })); |
| 857 | |
| 858 | ForwardingObjective.Builder downFwd = |
| 859 | oltFlowService.createDownBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(), |
| 860 | subscriberFlowInfo.getDownId(), subscriberFlowInfo.getTagInfo()); |
| 861 | flowObjectiveService.forward(subscriberFlowInfo.getDevId(), downFwd.add(new ObjectiveContext() { |
| 862 | @Override |
| 863 | public void onSuccess(Objective objective) { |
| 864 | log.debug("Downstream flow installed successfully {}", subscriberFlowInfo); |
| 865 | downFuture.complete(null); |
| 866 | } |
| 867 | |
| 868 | @Override |
| 869 | public void onError(Objective objective, ObjectiveError error) { |
| 870 | downFuture.complete(error); |
| 871 | } |
| 872 | })); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 873 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 874 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 875 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 876 | if (downStatus != null) { |
| 877 | log.error("Flow with innervlan {} and outerVlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 878 | "on port {} failed downstream installation: {}", |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 879 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(), |
| 880 | subscriberFlowInfo.getUniPort(), downStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 881 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 882 | } else if (upStatus != null) { |
| 883 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 884 | "on port {} failed upstream installation: {}", |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 885 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(), |
| 886 | subscriberFlowInfo.getUniPort(), upStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 887 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 888 | } else { |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 889 | log.debug("Upstream and downstream data plane flows are installed successfully " + |
| 890 | "for {}", subscriberFlowInfo); |
| 891 | oltFlowService.processEapolFilteringObjectives(subscriberFlowInfo.getDevId(), |
| 892 | subscriberFlowInfo.getUniPort(), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 893 | tagInfo.getUpstreamBandwidthProfile(), |
| 894 | null, tagInfo.getPonCTag(), true); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 895 | oltFlowService.processDhcpFilteringObjectives(subscriberFlowInfo.getDevId(), |
| 896 | subscriberFlowInfo.getUniPort(), |
| 897 | subscriberFlowInfo.getUpId(), |
| 898 | tagInfo, true, true); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 899 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 900 | oltFlowService.processIgmpFilteringObjectives(subscriberFlowInfo.getDevId(), |
| 901 | subscriberFlowInfo.getUniPort(), |
| 902 | subscriberFlowInfo.getUpId(), |
| 903 | tagInfo, true, true); |
| 904 | updateProgrammedSubscriber(new ConnectPoint(subscriberFlowInfo.getDevId(), |
| 905 | subscriberFlowInfo.getUniPort()), |
| 906 | tagInfo, true); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 907 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 908 | post(new AccessDeviceEvent(type, subscriberFlowInfo.getDevId(), |
| 909 | deviceService.getPort(subscriberFlowInfo.getDevId(), |
| 910 | subscriberFlowInfo.getUniPort()), |
| 911 | tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 912 | tagInfo.getTechnologyProfileId())); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 913 | }, oltInstallers); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 916 | /** |
| 917 | * Checks the subscriber uni tag list and find the uni tag information. |
| 918 | * using the pon c tag, pon s tag and the technology profile id |
| 919 | * May return Optional<null> |
| 920 | * |
| 921 | * @param cp the connection point of the subscriber |
| 922 | * @param innerVlan pon c tag |
| 923 | * @param outerVlan pon s tag |
| 924 | * @param tpId the technology profile id |
| 925 | * @return the found uni tag information |
| 926 | */ |
| 927 | private Optional<UniTagInformation> getUniTagInformation(ConnectPoint cp, VlanId innerVlan, VlanId outerVlan, |
| 928 | int tpId) { |
| 929 | log.info("Getting uni tag information for cp: {}, innerVlan: {}, outerVlan: {}, tpId: {}", cp, innerVlan, |
| 930 | outerVlan, tpId); |
| 931 | SubscriberAndDeviceInformation subInfo = getSubscriber(cp); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 932 | if (subInfo == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 933 | log.warn("Subscriber information doesn't exist for the connect point {}", cp); |
| 934 | return Optional.empty(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 937 | List<UniTagInformation> uniTagList = subInfo.uniTagList(); |
| 938 | if (uniTagList == null) { |
| 939 | log.warn("Uni tag list is not found for the subscriber {}", subInfo.id()); |
| 940 | return Optional.empty(); |
| 941 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 942 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 943 | UniTagInformation service = null; |
| 944 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 945 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 946 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 947 | service = tagInfo; |
| 948 | break; |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 949 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 950 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 951 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 952 | if (service == null) { |
| 953 | log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {}", |
| 954 | innerVlan, outerVlan, tpId); |
| 955 | return Optional.empty(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 958 | return Optional.of(service); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 959 | } |
| 960 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 961 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 962 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 963 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 964 | * |
| 965 | * @param dev Device to look for |
| 966 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 967 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 968 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 969 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 970 | log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 971 | |
| 972 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 973 | // This is an OLT device as per Sadis, we create flows for UNI and NNI ports |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 974 | for (Port p : deviceService.getPorts(dev.id())) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 975 | if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 976 | continue; |
| 977 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 978 | if (isUniPort(dev, p)) { |
Andrea Campanella | a249178 | 2020-03-13 18:09:31 +0100 | [diff] [blame] | 979 | if (!programmedSubs.containsKey(new ConnectPoint(dev.id(), p.number()))) { |
| 980 | log.info("Creating Eapol for the uni {}", p); |
| 981 | oltFlowService.processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null, |
| 982 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 983 | } else { |
| 984 | log.debug("Subscriber Eapol for UNI port {} on device {} is already " + |
| 985 | "provisioned, not installing default", p.number(), dev.id()); |
| 986 | } |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 987 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 988 | oltFlowService.processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 994 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 995 | /** |
| 996 | * Get the uplink for of the OLT device. |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 997 | * <p> |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 998 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 999 | * this logic needs to be changed |
| 1000 | * |
| 1001 | * @param dev Device to look for |
| 1002 | * @return The uplink Port of the OLT |
| 1003 | */ |
| 1004 | private Port getUplinkPort(Device dev) { |
| 1005 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1006 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 1007 | log.trace("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1008 | if (deviceInfo == null) { |
| 1009 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1010 | + " info", dev.id()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1011 | return null; |
| 1012 | } |
| 1013 | // Return the port that has been configured as the uplink port of this OLT in Sadis |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1014 | Optional<Port> optionalPort = deviceService.getPorts(dev.id()).stream() |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1015 | .filter(port -> isNniPort(port) || |
| 1016 | (port.number().toLong() == deviceInfo.uplinkPort())) |
| 1017 | .findFirst(); |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1018 | if (optionalPort.isPresent()) { |
| 1019 | log.trace("getUplinkPort: Found port {}", optionalPort.get()); |
| 1020 | return optionalPort.get(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 1023 | log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1024 | return null; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * Return the subscriber on a port. |
| 1029 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1030 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1031 | * @return subscriber if found else null |
| 1032 | */ |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1033 | SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 1034 | Port port = deviceService.getPort(cp); |
| 1035 | checkNotNull(port, "Invalid connect point"); |
| 1036 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1037 | return subsService.get(portName); |
| 1038 | } |
| 1039 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1040 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1041 | * Checks whether the given port of the device is a uni port or not. |
| 1042 | * |
| 1043 | * @param d the access device |
| 1044 | * @param p the port of the device |
| 1045 | * @return true if the given port is a uni port |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1046 | */ |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1047 | private boolean isUniPort(Device d, Port p) { |
| 1048 | Port ulPort = getUplinkPort(d); |
| 1049 | if (ulPort != null) { |
| 1050 | return (ulPort.number().toLong() != p.number().toLong()); |
| 1051 | } |
Thomas Lee S | d7735f9 | 2020-02-20 19:21:47 +0530 | [diff] [blame] | 1052 | //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null |
| 1053 | //checks whether the port name starts with nni- which is the signature of an NNI Port |
| 1054 | if (p.annotations().value(AnnotationKeys.PORT_NAME) != null && |
| 1055 | p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) { |
| 1056 | log.error("NNI port number {} is not matching with configured value", p.number().toLong()); |
| 1057 | return false; |
| 1058 | } |
| 1059 | return true; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1062 | /** |
| 1063 | * Gets the given device details from SADIS. |
| 1064 | * If the device is not found, returns null |
| 1065 | * |
| 1066 | * @param dev the access device |
| 1067 | * @return the olt information |
| 1068 | */ |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1069 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 1070 | String devSerialNo = dev.serialNumber(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1071 | return subsService.get(devSerialNo); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1074 | // Custom-built function, when the device is not available we need a fallback mechanism |
| 1075 | private boolean isLocalLeader(DeviceId deviceId) { |
| 1076 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 1077 | // When the device is available we just check the mastership |
| 1078 | if (deviceService.isAvailable(deviceId)) { |
| 1079 | return false; |
| 1080 | } |
| 1081 | // Fallback with Leadership service - device id is used as topic |
| 1082 | NodeId leader = leadershipService.runForLeadership( |
| 1083 | deviceId.toString()).leaderNodeId(); |
| 1084 | // Verify if this node is the leader |
| 1085 | return clusterService.getLocalNode().id().equals(leader); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1086 | } |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1087 | return true; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1090 | private boolean isNniPort(Port port) { |
| 1091 | if (port.annotations().keys().contains(AnnotationKeys.PORT_NAME)) { |
| 1092 | return port.annotations().value(AnnotationKeys.PORT_NAME).contains(NNI); |
| 1093 | } |
| 1094 | return false; |
| 1095 | } |
| 1096 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1097 | private class InternalDeviceListener implements DeviceListener { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1098 | private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet(); |
| 1099 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1100 | @Override |
| 1101 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1102 | eventExecutor.execute(() -> { |
| 1103 | DeviceId devId = event.subject().id(); |
| 1104 | Device dev = event.subject(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1105 | Port port = event.port(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1106 | DeviceEvent.Type eventType = event.type(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1107 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1108 | if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) || |
| 1109 | DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) || |
| 1110 | DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1111 | return; |
| 1112 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1113 | |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1114 | boolean isLocalLeader = isLocalLeader(devId); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1115 | // Only handle the event if the device belongs to us |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1116 | if (!isLocalLeader && event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) |
| 1117 | && !deviceService.isAvailable(devId) && deviceService.getPorts(devId).isEmpty()) { |
| 1118 | log.info("Cleaning local state for non master instance upon " + |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1119 | "device disconnection {}", devId); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1120 | // Since no mastership of the device is present upon disconnection |
| 1121 | // the method in the FlowRuleManager only empties the local copy |
| 1122 | // of the DeviceFlowTable thus this method needs to get called |
| 1123 | // on every instance, see how it's done in the InternalDeviceListener |
| 1124 | // in FlowRuleManager: no mastership check for purgeOnDisconnection |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1125 | handleDeviceDisconnection(dev, false, false); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1126 | return; |
| 1127 | } else if (!isLocalLeader) { |
Andrea Campanella | 506df20 | 2020-05-21 10:26:12 +0200 | [diff] [blame] | 1128 | log.debug("Not handling event because instance is not leader for {}", devId); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1129 | return; |
| 1130 | } |
| 1131 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1132 | log.debug("OLT got {} event for {} {}", eventType, event.subject(), event.port()); |
| 1133 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1134 | if (getOltInfo(dev) == null) { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1135 | // it's possible that we got an event for a previously |
| 1136 | // programmed OLT that is no longer available in SADIS |
| 1137 | // we let such events go through |
| 1138 | if (!programmedDevices.contains(devId)) { |
| 1139 | log.warn("No device info found for {}, this is either " |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1140 | + "not an OLT or not known to sadis", dev); |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1141 | return; |
| 1142 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1143 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1144 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1145 | switch (event.type()) { |
| 1146 | //TODO: Port handling and bookkeeping should be improved once |
| 1147 | // olt firmware handles correct behaviour. |
| 1148 | case PORT_ADDED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1149 | if (!deviceService.isAvailable(devId)) { |
| 1150 | log.warn("Received {} for disconnected device {}, ignoring", event, devId); |
| 1151 | return; |
| 1152 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1153 | if (isUniPort(dev, port)) { |
| 1154 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1155 | |
| 1156 | if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) { |
| 1157 | log.info("eapol will be sent for port added {}", port); |
| 1158 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
| 1159 | null, |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1160 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1161 | true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1162 | } |
| 1163 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1164 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 1165 | if (deviceInfo != null) { |
| 1166 | oltFlowService.processNniFilteringObjectives(dev.id(), port.number(), true); |
| 1167 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1168 | } |
| 1169 | break; |
| 1170 | case PORT_REMOVED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1171 | if (isUniPort(dev, port)) { |
Gamze Abaka | 853bf25 | 2019-03-25 10:27:06 +0000 | [diff] [blame] | 1172 | removeSubscriber(new ConnectPoint(devId, port.number())); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1173 | log.info("eapol will be send for port {} removed", port); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1174 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
| 1175 | null, |
| 1176 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 1177 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1178 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1179 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | case PORT_UPDATED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1182 | if (!deviceService.isAvailable(devId)) { |
| 1183 | log.warn("Received {} for disconnected device {}, ignoring", event, devId); |
| 1184 | return; |
| 1185 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1186 | if (!isUniPort(dev, port)) { |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 1187 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 1188 | if (deviceInfo != null && port.isEnabled()) { |
| 1189 | log.debug("NNI dev/port {}/{} enabled", dev.id(), |
| 1190 | port.number()); |
| 1191 | oltFlowService.processNniFilteringObjectives(dev.id(), |
| 1192 | port.number(), true); |
| 1193 | } |
| 1194 | return; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1195 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1196 | ConnectPoint cp = new ConnectPoint(devId, port.number()); |
| 1197 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1198 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1199 | if (!port.number().equals(PortNumber.LOCAL)) { |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 1200 | log.info("eapol will be {} for dev/port updated {}/{} with default vlan {}", |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1201 | (port.isEnabled()) ? "added" : "removed", |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 1202 | devId, port.number(), EAPOL_DEFAULT_VLAN); |
Matteo Scandolo | 27c471c | 2020-02-11 16:41:53 -0800 | [diff] [blame] | 1203 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1204 | null, |
| 1205 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1206 | port.isEnabled()); |
| 1207 | } |
| 1208 | } else { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1209 | log.info("eapol will be {} for dev/port updated {}/{}", |
| 1210 | (port.isEnabled()) ? "added" : "removed", |
| 1211 | devId, port.number()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1212 | uniTagInformationSet.forEach(uniTag -> |
| 1213 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), |
| 1214 | uniTag.getUpstreamBandwidthProfile(), null, |
| 1215 | uniTag.getPonCTag(), port.isEnabled())); |
| 1216 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1217 | if (port.isEnabled()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1218 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1219 | } else { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1220 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1221 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1222 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1223 | case DEVICE_ADDED: |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1224 | handleDeviceConnection(dev, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1225 | break; |
| 1226 | case DEVICE_REMOVED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1227 | handleDeviceDisconnection(dev, true, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1228 | break; |
| 1229 | case DEVICE_AVAILABILITY_CHANGED: |
| 1230 | if (deviceService.isAvailable(devId)) { |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1231 | log.info("Handling available device: {}", dev.id()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1232 | handleDeviceConnection(dev, false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1233 | } else { |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1234 | if (deviceService.getPorts(devId).isEmpty()) { |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1235 | log.info("Handling controlled device disconnection .. " |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1236 | + "flushing all state for dev:{}", devId); |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1237 | handleDeviceDisconnection(dev, true, false); |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1238 | } else { |
| 1239 | log.info("Disconnected device has available ports .. " |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1240 | + "assuming temporary disconnection, " |
| 1241 | + "retaining state for device {}", devId); |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1242 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1243 | } |
| 1244 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1245 | default: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1246 | log.debug("Not handling event {}", event); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1247 | return; |
| 1248 | } |
| 1249 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1250 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1251 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1252 | private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) { |
| 1253 | deviceService.getPorts(device.id()).stream() |
| 1254 | .filter(p -> !PortNumber.LOCAL.equals(p.number())) |
| 1255 | .filter(p -> isUniPort(device, p)) |
| 1256 | .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p))); |
| 1257 | } |
| 1258 | |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1259 | private void handleDeviceDisconnection(Device device, boolean sendDisconnectedEvent, boolean sendUniEvent) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1260 | programmedDevices.remove(device.id()); |
| 1261 | removeAllSubscribers(device.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 1262 | //Handle case where OLT disconnects during subscriber provisioning |
| 1263 | pendingSubscribers.removeIf(fi -> fi.getDevId().equals(device.id())); |
| 1264 | oltFlowService.clearDeviceState(device.id()); |
| 1265 | |
| 1266 | //Complete meter and flow purge |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1267 | flowRuleService.purgeFlowRules(device.id()); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1268 | oltMeterService.clearMeters(device.id()); |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1269 | if (sendDisconnectedEvent) { |
| 1270 | post(new AccessDeviceEvent( |
| 1271 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(), |
| 1272 | null, null, null)); |
| 1273 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1274 | if (sendUniEvent) { |
| 1275 | sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1276 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | private void handleDeviceConnection(Device dev, boolean sendUniEvent) { |
| 1280 | post(new AccessDeviceEvent( |
| 1281 | AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(), |
| 1282 | null, null, null)); |
| 1283 | programmedDevices.add(dev.id()); |
| 1284 | checkAndCreateDeviceFlows(dev); |
| 1285 | if (sendUniEvent) { |
| 1286 | sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED); |
| 1287 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1288 | } |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1289 | |
| 1290 | private void removeAllSubscribers(DeviceId deviceId) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1291 | List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream() |
| 1292 | .filter(e -> e.getKey().deviceId().equals(deviceId)) |
| 1293 | .collect(toList()); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1294 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1295 | subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue())); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1296 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1297 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1298 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1299 | |
| 1300 | private class InternalClusterListener implements ClusterEventListener { |
| 1301 | |
| 1302 | @Override |
| 1303 | public void event(ClusterEvent event) { |
| 1304 | if (event.type() == ClusterEvent.Type.INSTANCE_READY) { |
| 1305 | hasher.addServer(event.subject().id()); |
| 1306 | } |
| 1307 | if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) { |
| 1308 | hasher.removeServer(event.subject().id()); |
| 1309 | } |
| 1310 | } |
| 1311 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1312 | |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 1313 | } |