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(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 294 | checkNotNull(deviceService.getPort(deviceId, subscriberPortNo), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 295 | "Invalid connect point:" + connectPoint); |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 296 | |
Saurav Das | 4d8030c | 2020-09-21 18:56:35 -0700 | [diff] [blame^] | 297 | if (isSubscriberInstalled(connectPoint)) { |
| 298 | log.warn("Subscriber at {} already provisioned or in the process .." |
| 299 | + " not taking any more action", connectPoint); |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | // Find the subscriber config at this connect point |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 304 | SubscriberAndDeviceInformation sub = getSubscriber(connectPoint); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 305 | if (sub == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 306 | log.warn("No subscriber found for {}", connectPoint); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 307 | return false; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 308 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 309 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 310 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 311 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 312 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 313 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 314 | return false; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 317 | // delete Eapol authentication flow with default bandwidth |
| 318 | // wait until Eapol rule with defaultBpId is removed to install subscriber-based rules |
| 319 | // retry deletion if it fails/times-out |
| 320 | retryExecutor.execute(new DeleteEapolInstallSub(connectPoint, |
| 321 | uplinkPort, sub, 1)); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 322 | return true; |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Saurav Das | 4d8030c | 2020-09-21 18:56:35 -0700 | [diff] [blame^] | 325 | // returns true if subscriber is programmed or in the process of being programmed |
| 326 | private boolean isSubscriberInstalled(ConnectPoint connectPoint) { |
| 327 | Collection<? extends UniTagInformation> uniTagInformationSet = |
| 328 | programmedSubs.get(connectPoint).value(); |
| 329 | if (!uniTagInformationSet.isEmpty()) { |
| 330 | return true; |
| 331 | } |
| 332 | |
| 333 | for (SubscriberFlowInfo fi : pendingSubscribers) { |
| 334 | if (fi.getDevId().equals(connectPoint.deviceId()) |
| 335 | && fi.getUniPort().equals(connectPoint.port())) { |
| 336 | return true; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | return false; |
| 341 | } |
| 342 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 343 | private class DeleteEapolInstallSub implements Runnable { |
| 344 | ConnectPoint cp; |
| 345 | Port uplinkPort; |
| 346 | SubscriberAndDeviceInformation sub; |
| 347 | private int attemptNumber; |
| 348 | |
| 349 | DeleteEapolInstallSub(ConnectPoint cp, Port uplinkPort, |
| 350 | SubscriberAndDeviceInformation sub, |
| 351 | int attemptNumber) { |
| 352 | this.cp = cp; |
| 353 | this.uplinkPort = uplinkPort; |
| 354 | this.sub = sub; |
| 355 | this.attemptNumber = attemptNumber; |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void run() { |
| 360 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 361 | oltFlowService.processEapolFilteringObjectives(cp.deviceId(), cp.port(), |
| 362 | defaultBpId, filterFuture, |
| 363 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 364 | false); |
| 365 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 366 | if (filterStatus == null) { |
| 367 | log.info("Default eapol flow deleted in attempt {} of {}" |
| 368 | + "... provisioning subscriber flows {}", |
| 369 | attemptNumber, eapolDeleteRetryMaxAttempts, cp); |
| 370 | provisionUniTagList(cp, uplinkPort.number(), sub); |
| 371 | } else { |
| 372 | if (attemptNumber <= eapolDeleteRetryMaxAttempts) { |
| 373 | log.warn("The filtering future failed {} for subscriber {}" |
| 374 | + "... retrying {} of {} attempts", |
| 375 | filterStatus, cp, attemptNumber, eapolDeleteRetryMaxAttempts); |
| 376 | retryExecutor.execute( |
| 377 | new DeleteEapolInstallSub(cp, uplinkPort, sub, |
| 378 | attemptNumber + 1)); |
| 379 | } else { |
| 380 | log.error("The filtering future failed {} for subscriber {}" |
| 381 | + "after {} attempts. Subscriber provisioning failed", |
| 382 | filterStatus, cp, eapolDeleteRetryMaxAttempts); |
| 383 | sub.uniTagList().forEach(ut -> failedSubs.put(cp, ut)); |
| 384 | } |
| 385 | } |
| 386 | }); |
| 387 | } |
| 388 | |
| 389 | } |
| 390 | |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 391 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 392 | public boolean removeSubscriber(ConnectPoint connectPoint) { |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 393 | log.info("Call to un-provision subscriber at {}", connectPoint); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 394 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 395 | // Get the subscriber connected to this port from the local cache |
| 396 | // 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] | 397 | DeviceId deviceId = connectPoint.deviceId(); |
| 398 | PortNumber subscriberPortNo = connectPoint.port(); |
| 399 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 400 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(connectPoint).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 401 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 402 | log.warn("Subscriber on connectionPoint {} was not previously programmed, " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 403 | "no need to remove it", connectPoint); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 404 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 407 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 408 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 409 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 410 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 411 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 414 | for (UniTagInformation uniTag : uniTagInformationSet) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 415 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 416 | if (multicastServiceName.equals(uniTag.getServiceName())) { |
| 417 | continue; |
| 418 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 419 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 420 | unprovisionVlans(deviceId, uplinkPort.number(), subscriberPortNo, uniTag); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 421 | |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 422 | // remove eapol with subscriber bandwidth profile |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 423 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, |
| 424 | uniTag.getUpstreamBandwidthProfile(), |
| 425 | null, uniTag.getPonCTag(), false); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 426 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 427 | Port port = deviceService.getPort(deviceId, subscriberPortNo); |
| 428 | if (port != null && port.isEnabled()) { |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 429 | // reinstall eapol with default bandwidth profile |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 430 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, |
| 431 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 432 | } else { |
| 433 | log.debug("Port {} is no longer enabled or it's unavailable. Not " |
| 434 | + "reprogramming default eapol flow", connectPoint); |
| 435 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 436 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 437 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 440 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 441 | @Override |
| 442 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 443 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
| 444 | |
| 445 | log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}, tpId {}" + |
| 446 | "", subscriberId, sTag, cTag, tpId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 447 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 448 | // Check if we can find the connect point to which this subscriber is connected |
| 449 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 450 | if (subsPort == null) { |
| 451 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 452 | return false; |
| 453 | } |
| 454 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 455 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 456 | return provisionSubscriber(subsPort); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 457 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 458 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 459 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 460 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 461 | return false; |
| 462 | } |
| 463 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 464 | //delete Eapol authentication flow with default bandwidth |
| 465 | //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] | 466 | //install subscriber flows |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 467 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 468 | oltFlowService.processEapolFilteringObjectives(subsPort.deviceId(), subsPort.port(), defaultBpId, |
| 469 | filterFuture, VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 470 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 471 | if (filterStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 472 | provisionUniTagInformation(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 473 | cTag.get(), sTag.get(), tpId.get()); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 474 | } |
| 475 | }); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 476 | return true; |
| 477 | } else { |
| 478 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 479 | return false; |
| 480 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 481 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 482 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 483 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 484 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 485 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 486 | // Check if we can find the connect point to which this subscriber is connected |
| 487 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 488 | if (subsPort == null) { |
| 489 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 490 | return false; |
| 491 | } |
| 492 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 493 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 494 | return removeSubscriber(subsPort); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 495 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 496 | // Get the uplink port |
| 497 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 498 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 499 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 500 | return false; |
| 501 | } |
| 502 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 503 | Optional<UniTagInformation> tagInfo = getUniTagInformation(subsPort, cTag.get(), sTag.get(), tpId.get()); |
| 504 | if (!tagInfo.isPresent()) { |
| 505 | log.warn("UniTagInformation does not exist for Device/Port {}, cTag {}, sTag {}, tpId {}", |
| 506 | subsPort, cTag, sTag, tpId); |
| 507 | return false; |
| 508 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 509 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 510 | unprovisionVlans(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), tagInfo.get()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 511 | return true; |
| 512 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 513 | log.warn("Removing subscriber is not possible - please check the provided information" + |
| 514 | "for the subscriber: {}", subscriberId); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 515 | return false; |
| 516 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 520 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getProgSubs() { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 521 | return programmedSubs.stream() |
| 522 | .collect(collectingAndThen( |
| 523 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 524 | ImmutableMap::copyOf)); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | @Override |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 528 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getFailedSubs() { |
| 529 | return failedSubs.stream() |
| 530 | .collect(collectingAndThen( |
| 531 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 532 | ImmutableMap::copyOf)); |
| 533 | } |
| 534 | |
| 535 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 536 | public List<DeviceId> fetchOlts() { |
| 537 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 538 | List<DeviceId> olts = new ArrayList<>(); |
| 539 | Iterable<Device> devices = deviceService.getDevices(); |
| 540 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 541 | if (getOltInfo(d) != null) { |
| 542 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 543 | olts.add(d.id()); |
| 544 | } |
| 545 | } |
| 546 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 549 | /** |
| 550 | * Finds the connect point to which a subscriber is connected. |
| 551 | * |
| 552 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 553 | * @return Subscribers ConnectPoint if found else null |
| 554 | */ |
| 555 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 556 | |
| 557 | Iterable<Device> devices = deviceService.getDevices(); |
| 558 | for (Device d : devices) { |
| 559 | for (Port p : deviceService.getPorts(d.id())) { |
| 560 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 561 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 562 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 563 | return new ConnectPoint(d.id(), p.number()); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | return null; |
| 568 | } |
| 569 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 570 | /** |
| 571 | * Gets the context of the bandwidth profile information for the given parameter. |
| 572 | * |
| 573 | * @param bandwidthProfile the bandwidth profile id |
| 574 | * @return the context of the bandwidth profile information |
| 575 | */ |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 576 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
| 577 | if (bandwidthProfile == null) { |
| 578 | return null; |
| 579 | } |
| 580 | return bpService.get(bandwidthProfile); |
| 581 | } |
| 582 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 583 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 584 | * Removes subscriber vlan flows. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 585 | * |
| 586 | * @param deviceId the device identifier |
| 587 | * @param uplink uplink port of the OLT |
| 588 | * @param subscriberPort uni port |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 589 | * @param uniTag uni tag information |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 590 | */ |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 591 | private void unprovisionVlans(DeviceId deviceId, PortNumber uplink, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 592 | PortNumber subscriberPort, UniTagInformation uniTag) { |
| 593 | |
| 594 | log.info("Unprovisioning vlans for {} at {}/{}", uniTag, deviceId, subscriberPort); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 595 | |
| 596 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 597 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 598 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 599 | VlanId deviceVlan = uniTag.getPonSTag(); |
| 600 | VlanId subscriberVlan = uniTag.getPonCTag(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 601 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 602 | MeterId upstreamMeterId = oltMeterService |
| 603 | .getMeterIdFromBpMapping(deviceId, uniTag.getUpstreamBandwidthProfile()); |
| 604 | MeterId downstreamMeterId = oltMeterService |
| 605 | .getMeterIdFromBpMapping(deviceId, uniTag.getDownstreamBandwidthProfile()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 606 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 607 | ForwardingObjective.Builder upFwd = |
| 608 | oltFlowService.createUpBuilder(uplink, subscriberPort, upstreamMeterId, uniTag); |
| 609 | ForwardingObjective.Builder downFwd = |
| 610 | oltFlowService.createDownBuilder(uplink, subscriberPort, downstreamMeterId, uniTag); |
| 611 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 612 | oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort, |
| 613 | upstreamMeterId, uniTag, false, true); |
| 614 | oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort, |
| 615 | upstreamMeterId, uniTag, false, true); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 616 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 617 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 618 | @Override |
| 619 | public void onSuccess(Objective objective) { |
| 620 | upFuture.complete(null); |
| 621 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 622 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 623 | @Override |
| 624 | public void onError(Objective objective, ObjectiveError error) { |
| 625 | upFuture.complete(error); |
| 626 | } |
| 627 | })); |
| 628 | |
| 629 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 630 | @Override |
| 631 | public void onSuccess(Objective objective) { |
| 632 | downFuture.complete(null); |
| 633 | } |
| 634 | |
| 635 | @Override |
| 636 | public void onError(Objective objective, ObjectiveError error) { |
| 637 | downFuture.complete(error); |
| 638 | } |
| 639 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 640 | |
| 641 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 642 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 643 | if (upStatus == null && downStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 644 | log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {}, and" + |
| 645 | "Device/Port{}", uniTag.getPonCTag(), uniTag.getPonSTag(), |
| 646 | uniTag.getTechnologyProfileId(), subscriberPort); |
| 647 | updateProgrammedSubscriber(new ConnectPoint(deviceId, subscriberPort), uniTag, false); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 648 | } else if (downStatus != null) { |
| 649 | log.error("Subscriber with vlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 650 | "on port {} failed downstream uninstallation: {}", |
| 651 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 652 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 653 | } else if (upStatus != null) { |
| 654 | log.error("Subscriber with vlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 655 | "on port {} failed upstream uninstallation: {}", |
| 656 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 657 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 658 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 659 | Port port = deviceService.getPort(deviceId, subscriberPort); |
| 660 | post(new AccessDeviceEvent(type, deviceId, port, deviceVlan, subscriberVlan, |
| 661 | uniTag.getTechnologyProfileId())); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 662 | }, oltInstallers); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 665 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 666 | * 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] | 667 | * |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 668 | * @param connectPoint the connection point of the subscriber |
| 669 | * @param uplinkPort uplink port of the OLT (the nni port) |
| 670 | * @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] | 671 | */ |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 672 | private void provisionUniTagList(ConnectPoint connectPoint, PortNumber uplinkPort, |
| 673 | SubscriberAndDeviceInformation sub) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 674 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 675 | log.debug("Provisioning vlans for subscriber {} on dev/port: {}", sub, connectPoint); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 676 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 677 | if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) { |
| 678 | log.warn("Unitaglist doesn't exist for the subscriber {}", sub.id()); |
| 679 | return; |
| 680 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 681 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 682 | DeviceId deviceId = connectPoint.deviceId(); |
| 683 | PortNumber subscriberPort = connectPoint.port(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 684 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 685 | for (UniTagInformation uniTag : sub.uniTagList()) { |
| 686 | handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, uniTag); |
| 687 | } |
| 688 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 689 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 690 | /** |
| 691 | * Finds the uni tag information and provisions the found information. |
| 692 | * If the uni tag information is not found, returns |
| 693 | * |
| 694 | * @param deviceId the access device id |
| 695 | * @param uplinkPort the nni port |
| 696 | * @param subscriberPort the uni port |
| 697 | * @param innerVlan the pon c tag |
| 698 | * @param outerVlan the pon s tag |
| 699 | * @param tpId the technology profile id |
| 700 | */ |
| 701 | private void provisionUniTagInformation(DeviceId deviceId, PortNumber uplinkPort, |
| 702 | PortNumber subscriberPort, |
| 703 | VlanId innerVlan, |
| 704 | VlanId outerVlan, |
| 705 | Integer tpId) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 706 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 707 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 708 | Optional<UniTagInformation> gotTagInformation = getUniTagInformation(cp, innerVlan, outerVlan, tpId); |
| 709 | if (!gotTagInformation.isPresent()) { |
| 710 | return; |
| 711 | } |
| 712 | UniTagInformation tagInformation = gotTagInformation.get(); |
| 713 | handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, tagInformation); |
| 714 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 715 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 716 | private void updateProgrammedSubscriber(ConnectPoint connectPoint, UniTagInformation tagInformation, Boolean add) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 717 | if (add) { |
| 718 | programmedSubs.put(connectPoint, tagInformation); |
| 719 | } else { |
| 720 | programmedSubs.remove(connectPoint, tagInformation); |
| 721 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 724 | /** |
| 725 | * Installs a uni tag information flow. |
| 726 | * |
| 727 | * @param deviceId the access device id |
| 728 | * @param uplinkPort the nni port |
| 729 | * @param subscriberPort the uni port |
| 730 | * @param tagInfo the uni tag information |
| 731 | */ |
| 732 | private void handleSubscriberFlows(DeviceId deviceId, PortNumber uplinkPort, PortNumber subscriberPort, |
| 733 | UniTagInformation tagInfo) { |
| 734 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 735 | log.debug("Provisioning vlan-based flows for the uniTagInformation {}", tagInfo); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 736 | |
| 737 | Port port = deviceService.getPort(deviceId, subscriberPort); |
| 738 | |
| 739 | if (multicastServiceName.equals(tagInfo.getServiceName())) { |
| 740 | // IGMP flows are taken care of along with VOD service |
| 741 | // Please note that for each service, Subscriber Registered event will be sent |
| 742 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED, |
| 743 | deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 744 | tagInfo.getTechnologyProfileId())); |
| 745 | return; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 748 | BandwidthProfileInformation upstreamBpInfo = |
| 749 | getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile()); |
| 750 | BandwidthProfileInformation downstreamBpInfo = |
| 751 | getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 752 | if (upstreamBpInfo == null) { |
| 753 | log.warn("No meter installed since no Upstream BW Profile definition found for " |
| 754 | + "ctag {} stag {} tpId {} and Device/port: {}:{}", |
| 755 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
| 756 | tagInfo.getTechnologyProfileId(), deviceId, |
| 757 | subscriberPort); |
| 758 | return; |
| 759 | } |
| 760 | if (downstreamBpInfo == null) { |
| 761 | log.warn("No meter installed since no Downstream BW Profile definition found for " |
| 762 | + "ctag {} stag {} tpId {} and Device/port: {}:{}", |
| 763 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
| 764 | tagInfo.getTechnologyProfileId(), deviceId, |
| 765 | subscriberPort); |
| 766 | return; |
| 767 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 768 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 769 | // check for meterIds for the upstream and downstream bandwidth profiles |
| 770 | MeterId upMeterId = oltMeterService |
| 771 | .getMeterIdFromBpMapping(deviceId, upstreamBpInfo.id()); |
| 772 | MeterId downMeterId = oltMeterService |
| 773 | .getMeterIdFromBpMapping(deviceId, downstreamBpInfo.id()); |
| 774 | SubscriberFlowInfo fi = new SubscriberFlowInfo(deviceId, uplinkPort, subscriberPort, |
| 775 | tagInfo, downMeterId, upMeterId, |
| 776 | downstreamBpInfo.id(), upstreamBpInfo.id()); |
| 777 | |
| 778 | if (upMeterId != null && downMeterId != null) { |
| 779 | log.debug("Meters are existing for upstream {} and downstream {}", |
| 780 | upstreamBpInfo.id(), downstreamBpInfo.id()); |
| 781 | handleSubFlowsWithMeters(fi); |
| 782 | } else { |
| 783 | log.debug("Adding {} to pending subs", fi); |
| 784 | // one or both meters are not ready. It's possible they are in the process of being |
| 785 | // created for other subscribers that share the same bandwidth profile. |
| 786 | pendingSubscribers.add(fi); |
| 787 | |
| 788 | // queue up the meters to be created |
| 789 | if (upMeterId == null) { |
| 790 | log.debug("Missing meter for upstream {}", upstreamBpInfo.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 791 | checkAndCreateDevMeter(deviceId, upstreamBpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 792 | } |
| 793 | if (downMeterId == null) { |
| 794 | log.debug("Missing meter for downstream {}", downstreamBpInfo.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 795 | checkAndCreateDevMeter(deviceId, downstreamBpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 799 | private void checkAndCreateDevMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 800 | if (oltMeterService.isMeterPending(deviceId, bwpInfo)) { |
| 801 | log.debug("Meter is already pending {} on device {}", bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 802 | return; |
| 803 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 804 | oltMeterService.addToPendingMeters(deviceId, bwpInfo); |
| 805 | createMeter(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 808 | private void createMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
| 809 | log.debug("Creating Meter with {} on {} for subscriber", bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 810 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 811 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 812 | MeterId meterId = oltMeterService.createMeter(deviceId, bwpInfo, |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 813 | meterFuture); |
| 814 | |
| 815 | meterFuture.thenAcceptAsync(result -> { |
| 816 | // iterate through the subscribers on hold |
| 817 | Iterator<SubscriberFlowInfo> subsIterator = pendingSubscribers.iterator(); |
| 818 | while (subsIterator.hasNext()) { |
| 819 | SubscriberFlowInfo fi = subsIterator.next(); |
| 820 | if (result == null) { |
| 821 | // meter install sent to device |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 822 | log.debug("Meter {} installed for bw {} on {}", meterId, bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 823 | |
| 824 | MeterId upMeterId = oltMeterService |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 825 | .getMeterIdFromBpMapping(deviceId, fi.getUpBpInfo()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 826 | MeterId downMeterId = oltMeterService |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 827 | .getMeterIdFromBpMapping(deviceId, fi.getDownBpInfo()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 828 | if (upMeterId != null && downMeterId != null) { |
| 829 | log.debug("Provisioning subscriber after meter {}" + |
| 830 | "installation and both meters are present " + |
| 831 | "upstream {} and downstream {}", |
| 832 | meterId, upMeterId, downMeterId); |
| 833 | // put in the meterIds because when fi was first |
| 834 | // created there may or may not have been a meterId |
| 835 | // depending on whether the meter was created or |
| 836 | // not at that time. |
| 837 | fi.setUpMeterId(upMeterId); |
| 838 | fi.setDownMeterId(downMeterId); |
| 839 | handleSubFlowsWithMeters(fi); |
| 840 | subsIterator.remove(); |
| 841 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 842 | oltMeterService.removeFromPendingMeters(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 843 | } else { |
| 844 | // meter install failed |
| 845 | log.error("Addition of subscriber {} failed due to meter " + |
| 846 | "{} with result {}", fi, meterId, result); |
| 847 | subsIterator.remove(); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 848 | oltMeterService.removeFromPendingMeters(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | }); |
| 852 | } |
| 853 | /** |
| 854 | * Add subscriber flows given meter information for both upstream and |
| 855 | * downstream directions. |
| 856 | * |
| 857 | * @param subscriberFlowInfo relevant information for subscriber |
| 858 | */ |
| 859 | private void handleSubFlowsWithMeters(SubscriberFlowInfo subscriberFlowInfo) { |
| 860 | log.debug("Provisioning subscriber flows based on {}", subscriberFlowInfo); |
| 861 | UniTagInformation tagInfo = subscriberFlowInfo.getTagInfo(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 862 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>(); |
| 863 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 864 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 865 | ForwardingObjective.Builder upFwd = |
| 866 | oltFlowService.createUpBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(), |
| 867 | subscriberFlowInfo.getUpId(), subscriberFlowInfo.getTagInfo()); |
| 868 | flowObjectiveService.forward(subscriberFlowInfo.getDevId(), upFwd.add(new ObjectiveContext() { |
| 869 | @Override |
| 870 | public void onSuccess(Objective objective) { |
| 871 | log.debug("Upstream flow installed successfully {}", subscriberFlowInfo); |
| 872 | upFuture.complete(null); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 873 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 874 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 875 | @Override |
| 876 | public void onError(Objective objective, ObjectiveError error) { |
| 877 | upFuture.complete(error); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 878 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 879 | })); |
| 880 | |
| 881 | ForwardingObjective.Builder downFwd = |
| 882 | oltFlowService.createDownBuilder(subscriberFlowInfo.getNniPort(), subscriberFlowInfo.getUniPort(), |
| 883 | subscriberFlowInfo.getDownId(), subscriberFlowInfo.getTagInfo()); |
| 884 | flowObjectiveService.forward(subscriberFlowInfo.getDevId(), downFwd.add(new ObjectiveContext() { |
| 885 | @Override |
| 886 | public void onSuccess(Objective objective) { |
| 887 | log.debug("Downstream flow installed successfully {}", subscriberFlowInfo); |
| 888 | downFuture.complete(null); |
| 889 | } |
| 890 | |
| 891 | @Override |
| 892 | public void onError(Objective objective, ObjectiveError error) { |
| 893 | downFuture.complete(error); |
| 894 | } |
| 895 | })); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 896 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 897 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 898 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 899 | if (downStatus != null) { |
| 900 | log.error("Flow with innervlan {} and outerVlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 901 | "on port {} failed downstream installation: {}", |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 902 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(), |
| 903 | subscriberFlowInfo.getUniPort(), downStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 904 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 905 | } else if (upStatus != null) { |
| 906 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 907 | "on port {} failed upstream installation: {}", |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 908 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), subscriberFlowInfo.getDevId(), |
| 909 | subscriberFlowInfo.getUniPort(), upStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 910 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 911 | } else { |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 912 | log.debug("Upstream and downstream data plane flows are installed successfully " + |
| 913 | "for {}", subscriberFlowInfo); |
| 914 | oltFlowService.processEapolFilteringObjectives(subscriberFlowInfo.getDevId(), |
| 915 | subscriberFlowInfo.getUniPort(), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 916 | tagInfo.getUpstreamBandwidthProfile(), |
| 917 | null, tagInfo.getPonCTag(), true); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 918 | oltFlowService.processDhcpFilteringObjectives(subscriberFlowInfo.getDevId(), |
| 919 | subscriberFlowInfo.getUniPort(), |
| 920 | subscriberFlowInfo.getUpId(), |
| 921 | tagInfo, true, true); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 922 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 923 | oltFlowService.processIgmpFilteringObjectives(subscriberFlowInfo.getDevId(), |
| 924 | subscriberFlowInfo.getUniPort(), |
| 925 | subscriberFlowInfo.getUpId(), |
| 926 | tagInfo, true, true); |
| 927 | updateProgrammedSubscriber(new ConnectPoint(subscriberFlowInfo.getDevId(), |
| 928 | subscriberFlowInfo.getUniPort()), |
| 929 | tagInfo, true); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 930 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 931 | post(new AccessDeviceEvent(type, subscriberFlowInfo.getDevId(), |
| 932 | deviceService.getPort(subscriberFlowInfo.getDevId(), |
| 933 | subscriberFlowInfo.getUniPort()), |
| 934 | tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 935 | tagInfo.getTechnologyProfileId())); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 936 | }, oltInstallers); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 939 | /** |
| 940 | * Checks the subscriber uni tag list and find the uni tag information. |
| 941 | * using the pon c tag, pon s tag and the technology profile id |
| 942 | * May return Optional<null> |
| 943 | * |
| 944 | * @param cp the connection point of the subscriber |
| 945 | * @param innerVlan pon c tag |
| 946 | * @param outerVlan pon s tag |
| 947 | * @param tpId the technology profile id |
| 948 | * @return the found uni tag information |
| 949 | */ |
| 950 | private Optional<UniTagInformation> getUniTagInformation(ConnectPoint cp, VlanId innerVlan, VlanId outerVlan, |
| 951 | int tpId) { |
| 952 | log.info("Getting uni tag information for cp: {}, innerVlan: {}, outerVlan: {}, tpId: {}", cp, innerVlan, |
| 953 | outerVlan, tpId); |
| 954 | SubscriberAndDeviceInformation subInfo = getSubscriber(cp); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 955 | if (subInfo == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 956 | log.warn("Subscriber information doesn't exist for the connect point {}", cp); |
| 957 | return Optional.empty(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 960 | List<UniTagInformation> uniTagList = subInfo.uniTagList(); |
| 961 | if (uniTagList == null) { |
| 962 | log.warn("Uni tag list is not found for the subscriber {}", subInfo.id()); |
| 963 | return Optional.empty(); |
| 964 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 965 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 966 | UniTagInformation service = null; |
| 967 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 968 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 969 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 970 | service = tagInfo; |
| 971 | break; |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 972 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 973 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 974 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 975 | if (service == null) { |
| 976 | log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {}", |
| 977 | innerVlan, outerVlan, tpId); |
| 978 | return Optional.empty(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 981 | return Optional.of(service); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 984 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 985 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 986 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 987 | * |
| 988 | * @param dev Device to look for |
| 989 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 990 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 991 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 992 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 993 | log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 994 | |
| 995 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 996 | // 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] | 997 | for (Port p : deviceService.getPorts(dev.id())) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 998 | if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 999 | continue; |
| 1000 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1001 | if (isUniPort(dev, p)) { |
Andrea Campanella | a249178 | 2020-03-13 18:09:31 +0100 | [diff] [blame] | 1002 | if (!programmedSubs.containsKey(new ConnectPoint(dev.id(), p.number()))) { |
| 1003 | log.info("Creating Eapol for the uni {}", p); |
| 1004 | oltFlowService.processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null, |
| 1005 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 1006 | } else { |
| 1007 | log.debug("Subscriber Eapol for UNI port {} on device {} is already " + |
| 1008 | "provisioned, not installing default", p.number(), dev.id()); |
| 1009 | } |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1010 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1011 | oltFlowService.processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1017 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1018 | /** |
| 1019 | * Get the uplink for of the OLT device. |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1020 | * <p> |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1021 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 1022 | * this logic needs to be changed |
| 1023 | * |
| 1024 | * @param dev Device to look for |
| 1025 | * @return The uplink Port of the OLT |
| 1026 | */ |
| 1027 | private Port getUplinkPort(Device dev) { |
| 1028 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1029 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 1030 | log.trace("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1031 | if (deviceInfo == null) { |
| 1032 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1033 | + " info", dev.id()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1034 | return null; |
| 1035 | } |
| 1036 | // 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] | 1037 | Optional<Port> optionalPort = deviceService.getPorts(dev.id()).stream() |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1038 | .filter(port -> isNniPort(port) || |
| 1039 | (port.number().toLong() == deviceInfo.uplinkPort())) |
| 1040 | .findFirst(); |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1041 | if (optionalPort.isPresent()) { |
| 1042 | log.trace("getUplinkPort: Found port {}", optionalPort.get()); |
| 1043 | return optionalPort.get(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 1046 | log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1047 | return null; |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * Return the subscriber on a port. |
| 1052 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1053 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1054 | * @return subscriber if found else null |
| 1055 | */ |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1056 | SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 1057 | Port port = deviceService.getPort(cp); |
| 1058 | checkNotNull(port, "Invalid connect point"); |
| 1059 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1060 | return subsService.get(portName); |
| 1061 | } |
| 1062 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1063 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1064 | * Checks whether the given port of the device is a uni port or not. |
| 1065 | * |
| 1066 | * @param d the access device |
| 1067 | * @param p the port of the device |
| 1068 | * @return true if the given port is a uni port |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1069 | */ |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1070 | private boolean isUniPort(Device d, Port p) { |
| 1071 | Port ulPort = getUplinkPort(d); |
| 1072 | if (ulPort != null) { |
| 1073 | return (ulPort.number().toLong() != p.number().toLong()); |
| 1074 | } |
Thomas Lee S | d7735f9 | 2020-02-20 19:21:47 +0530 | [diff] [blame] | 1075 | //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null |
| 1076 | //checks whether the port name starts with nni- which is the signature of an NNI Port |
| 1077 | if (p.annotations().value(AnnotationKeys.PORT_NAME) != null && |
| 1078 | p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) { |
| 1079 | log.error("NNI port number {} is not matching with configured value", p.number().toLong()); |
| 1080 | return false; |
| 1081 | } |
| 1082 | return true; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1085 | /** |
| 1086 | * Gets the given device details from SADIS. |
| 1087 | * If the device is not found, returns null |
| 1088 | * |
| 1089 | * @param dev the access device |
| 1090 | * @return the olt information |
| 1091 | */ |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1092 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 1093 | String devSerialNo = dev.serialNumber(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1094 | return subsService.get(devSerialNo); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1097 | // Custom-built function, when the device is not available we need a fallback mechanism |
| 1098 | private boolean isLocalLeader(DeviceId deviceId) { |
| 1099 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 1100 | // When the device is available we just check the mastership |
| 1101 | if (deviceService.isAvailable(deviceId)) { |
| 1102 | return false; |
| 1103 | } |
| 1104 | // Fallback with Leadership service - device id is used as topic |
| 1105 | NodeId leader = leadershipService.runForLeadership( |
| 1106 | deviceId.toString()).leaderNodeId(); |
| 1107 | // Verify if this node is the leader |
| 1108 | return clusterService.getLocalNode().id().equals(leader); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1109 | } |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1110 | return true; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1113 | private boolean isNniPort(Port port) { |
| 1114 | if (port.annotations().keys().contains(AnnotationKeys.PORT_NAME)) { |
| 1115 | return port.annotations().value(AnnotationKeys.PORT_NAME).contains(NNI); |
| 1116 | } |
| 1117 | return false; |
| 1118 | } |
| 1119 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1120 | private class InternalDeviceListener implements DeviceListener { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1121 | private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet(); |
| 1122 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1123 | @Override |
| 1124 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1125 | eventExecutor.execute(() -> { |
| 1126 | DeviceId devId = event.subject().id(); |
| 1127 | Device dev = event.subject(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1128 | Port port = event.port(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1129 | DeviceEvent.Type eventType = event.type(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1130 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1131 | if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) || |
| 1132 | DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) || |
| 1133 | DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1134 | return; |
| 1135 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1136 | |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1137 | boolean isLocalLeader = isLocalLeader(devId); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1138 | // Only handle the event if the device belongs to us |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1139 | if (!isLocalLeader && event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) |
| 1140 | && !deviceService.isAvailable(devId) && deviceService.getPorts(devId).isEmpty()) { |
| 1141 | log.info("Cleaning local state for non master instance upon " + |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1142 | "device disconnection {}", devId); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1143 | // Since no mastership of the device is present upon disconnection |
| 1144 | // the method in the FlowRuleManager only empties the local copy |
| 1145 | // of the DeviceFlowTable thus this method needs to get called |
| 1146 | // on every instance, see how it's done in the InternalDeviceListener |
| 1147 | // in FlowRuleManager: no mastership check for purgeOnDisconnection |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1148 | handleDeviceDisconnection(dev, false, false); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1149 | return; |
| 1150 | } else if (!isLocalLeader) { |
Andrea Campanella | 506df20 | 2020-05-21 10:26:12 +0200 | [diff] [blame] | 1151 | log.debug("Not handling event because instance is not leader for {}", devId); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1152 | return; |
| 1153 | } |
| 1154 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1155 | log.debug("OLT got {} event for {} {}", eventType, event.subject(), event.port()); |
| 1156 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1157 | if (getOltInfo(dev) == null) { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1158 | // it's possible that we got an event for a previously |
| 1159 | // programmed OLT that is no longer available in SADIS |
| 1160 | // we let such events go through |
| 1161 | if (!programmedDevices.contains(devId)) { |
| 1162 | log.warn("No device info found for {}, this is either " |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1163 | + "not an OLT or not known to sadis", dev); |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1164 | return; |
| 1165 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1166 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1167 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1168 | switch (event.type()) { |
| 1169 | //TODO: Port handling and bookkeeping should be improved once |
| 1170 | // olt firmware handles correct behaviour. |
| 1171 | case PORT_ADDED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1172 | if (!deviceService.isAvailable(devId)) { |
| 1173 | log.warn("Received {} for disconnected device {}, ignoring", event, devId); |
| 1174 | return; |
| 1175 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1176 | if (isUniPort(dev, port)) { |
| 1177 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1178 | |
| 1179 | if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) { |
| 1180 | log.info("eapol will be sent for port added {}", port); |
| 1181 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
| 1182 | null, |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1183 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1184 | true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1185 | } |
| 1186 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1187 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 1188 | if (deviceInfo != null) { |
| 1189 | oltFlowService.processNniFilteringObjectives(dev.id(), port.number(), true); |
| 1190 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1191 | } |
| 1192 | break; |
| 1193 | case PORT_REMOVED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1194 | if (isUniPort(dev, port)) { |
Andrea Campanella | cf0e305 | 2020-08-27 11:05:39 +0200 | [diff] [blame] | 1195 | // if no subscriber is provisioned we need to remove the default EAPOL |
| 1196 | // if a subscriber was provisioned the default EAPOL will not be there and we can skip. |
| 1197 | // The EAPOL with subscriber tag will be removed by removeSubscriber call. |
| 1198 | Collection<? extends UniTagInformation> uniTagInformationSet = |
| 1199 | programmedSubs.get(new ConnectPoint(port.element().id(), port.number())).value(); |
| 1200 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
| 1201 | log.info("No subscriber provisioned on port {} in PORT_REMOVED event, " + |
| 1202 | "removing default EAPOL flow", port); |
| 1203 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
| 1204 | null, |
| 1205 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1206 | false); |
| 1207 | } else { |
| 1208 | removeSubscriber(new ConnectPoint(devId, port.number())); |
| 1209 | } |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 1210 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1211 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1212 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1213 | break; |
| 1214 | case PORT_UPDATED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1215 | if (!deviceService.isAvailable(devId)) { |
| 1216 | log.warn("Received {} for disconnected device {}, ignoring", event, devId); |
| 1217 | return; |
| 1218 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1219 | if (!isUniPort(dev, port)) { |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 1220 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 1221 | if (deviceInfo != null && port.isEnabled()) { |
| 1222 | log.debug("NNI dev/port {}/{} enabled", dev.id(), |
| 1223 | port.number()); |
| 1224 | oltFlowService.processNniFilteringObjectives(dev.id(), |
| 1225 | port.number(), true); |
| 1226 | } |
| 1227 | return; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1228 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1229 | ConnectPoint cp = new ConnectPoint(devId, port.number()); |
| 1230 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1231 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1232 | if (!port.number().equals(PortNumber.LOCAL)) { |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 1233 | log.info("eapol will be {} for dev/port updated {}/{} with default vlan {}", |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1234 | (port.isEnabled()) ? "added" : "removed", |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 1235 | devId, port.number(), EAPOL_DEFAULT_VLAN); |
Matteo Scandolo | 27c471c | 2020-02-11 16:41:53 -0800 | [diff] [blame] | 1236 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1237 | null, |
| 1238 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1239 | port.isEnabled()); |
| 1240 | } |
| 1241 | } else { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1242 | log.info("eapol will be {} for dev/port updated {}/{}", |
| 1243 | (port.isEnabled()) ? "added" : "removed", |
| 1244 | devId, port.number()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1245 | uniTagInformationSet.forEach(uniTag -> |
| 1246 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), |
| 1247 | uniTag.getUpstreamBandwidthProfile(), null, |
| 1248 | uniTag.getPonCTag(), port.isEnabled())); |
| 1249 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1250 | if (port.isEnabled()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1251 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1252 | } else { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1253 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1254 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1255 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1256 | case DEVICE_ADDED: |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1257 | handleDeviceConnection(dev, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1258 | break; |
| 1259 | case DEVICE_REMOVED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1260 | handleDeviceDisconnection(dev, true, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1261 | break; |
| 1262 | case DEVICE_AVAILABILITY_CHANGED: |
| 1263 | if (deviceService.isAvailable(devId)) { |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1264 | log.info("Handling available device: {}", dev.id()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1265 | handleDeviceConnection(dev, false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1266 | } else { |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1267 | if (deviceService.getPorts(devId).isEmpty()) { |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1268 | log.info("Handling controlled device disconnection .. " |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1269 | + "flushing all state for dev:{}", devId); |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1270 | handleDeviceDisconnection(dev, true, false); |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1271 | } else { |
| 1272 | log.info("Disconnected device has available ports .. " |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1273 | + "assuming temporary disconnection, " |
| 1274 | + "retaining state for device {}", devId); |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1275 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1276 | } |
| 1277 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1278 | default: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1279 | log.debug("Not handling event {}", event); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1280 | return; |
| 1281 | } |
| 1282 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1283 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1284 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1285 | private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) { |
| 1286 | deviceService.getPorts(device.id()).stream() |
| 1287 | .filter(p -> !PortNumber.LOCAL.equals(p.number())) |
| 1288 | .filter(p -> isUniPort(device, p)) |
| 1289 | .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p))); |
| 1290 | } |
| 1291 | |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1292 | private void handleDeviceDisconnection(Device device, boolean sendDisconnectedEvent, boolean sendUniEvent) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1293 | programmedDevices.remove(device.id()); |
| 1294 | removeAllSubscribers(device.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 1295 | //Handle case where OLT disconnects during subscriber provisioning |
| 1296 | pendingSubscribers.removeIf(fi -> fi.getDevId().equals(device.id())); |
| 1297 | oltFlowService.clearDeviceState(device.id()); |
| 1298 | |
| 1299 | //Complete meter and flow purge |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1300 | flowRuleService.purgeFlowRules(device.id()); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1301 | oltMeterService.clearMeters(device.id()); |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1302 | if (sendDisconnectedEvent) { |
| 1303 | post(new AccessDeviceEvent( |
| 1304 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(), |
| 1305 | null, null, null)); |
| 1306 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1307 | if (sendUniEvent) { |
| 1308 | sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1309 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | private void handleDeviceConnection(Device dev, boolean sendUniEvent) { |
| 1313 | post(new AccessDeviceEvent( |
| 1314 | AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(), |
| 1315 | null, null, null)); |
| 1316 | programmedDevices.add(dev.id()); |
| 1317 | checkAndCreateDeviceFlows(dev); |
| 1318 | if (sendUniEvent) { |
| 1319 | sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED); |
| 1320 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1321 | } |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1322 | |
| 1323 | private void removeAllSubscribers(DeviceId deviceId) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1324 | List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream() |
| 1325 | .filter(e -> e.getKey().deviceId().equals(deviceId)) |
| 1326 | .collect(toList()); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1327 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1328 | subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue())); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1329 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1330 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1331 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1332 | |
| 1333 | private class InternalClusterListener implements ClusterEventListener { |
| 1334 | |
| 1335 | @Override |
| 1336 | public void event(ClusterEvent event) { |
| 1337 | if (event.type() == ClusterEvent.Type.INSTANCE_READY) { |
| 1338 | hasher.addServer(event.subject().id()); |
| 1339 | } |
| 1340 | if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) { |
| 1341 | hasher.removeServer(event.subject().id()); |
| 1342 | } |
| 1343 | } |
| 1344 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1345 | |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 1346 | } |