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 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 20 | import org.onlab.packet.VlanId; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 21 | import org.onlab.util.KryoNamespace; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 22 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 23 | import org.onosproject.cluster.ClusterEvent; |
| 24 | import org.onosproject.cluster.ClusterEventListener; |
| 25 | import org.onosproject.cluster.ClusterService; |
| 26 | import org.onosproject.cluster.ControllerNode; |
| 27 | import org.onosproject.cluster.NodeId; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 30 | import org.onosproject.event.AbstractListenerManager; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 31 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 32 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 33 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 34 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 35 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 36 | import org.onosproject.net.PortNumber; |
| 37 | import org.onosproject.net.device.DeviceEvent; |
| 38 | import org.onosproject.net.device.DeviceListener; |
| 39 | import org.onosproject.net.device.DeviceService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 40 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 41 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 42 | import org.onosproject.net.flowobjective.Objective; |
| 43 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 44 | import org.onosproject.net.flowobjective.ObjectiveError; |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 45 | import org.onosproject.net.meter.MeterId; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 46 | import org.onosproject.store.serializers.KryoNamespaces; |
| 47 | import org.onosproject.store.service.ConsistentMultimap; |
| 48 | import org.onosproject.store.service.Serializer; |
| 49 | import org.onosproject.store.service.StorageService; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 50 | import org.opencord.olt.AccessDeviceEvent; |
| 51 | import org.opencord.olt.AccessDeviceListener; |
| 52 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 53 | import org.opencord.olt.AccessSubscriberId; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 54 | import org.opencord.olt.internalapi.AccessDeviceFlowService; |
| 55 | import org.opencord.olt.internalapi.AccessDeviceMeterService; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 56 | import org.opencord.sadis.BandwidthProfileInformation; |
| 57 | import org.opencord.sadis.BaseInformationService; |
| 58 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 59 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 60 | import org.opencord.sadis.UniTagInformation; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 61 | import org.osgi.service.component.ComponentContext; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 62 | import org.osgi.service.component.annotations.Activate; |
| 63 | import org.osgi.service.component.annotations.Component; |
| 64 | import org.osgi.service.component.annotations.Deactivate; |
| 65 | import org.osgi.service.component.annotations.Modified; |
| 66 | import org.osgi.service.component.annotations.Reference; |
| 67 | import org.osgi.service.component.annotations.ReferenceCardinality; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 68 | import org.slf4j.Logger; |
| 69 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 70 | import java.util.ArrayList; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 71 | import java.util.Collection; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 72 | import java.util.Dictionary; |
| 73 | import java.util.List; |
| 74 | import java.util.Map; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 75 | import java.util.Optional; |
| 76 | import java.util.Properties; |
| 77 | import java.util.Set; |
| 78 | import java.util.concurrent.CompletableFuture; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 79 | import java.util.concurrent.ExecutorService; |
| 80 | import java.util.concurrent.Executors; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 81 | |
| 82 | import static com.google.common.base.Preconditions.checkNotNull; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 83 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 84 | import static java.util.stream.Collectors.collectingAndThen; |
| 85 | import static java.util.stream.Collectors.groupingBy; |
| 86 | import static java.util.stream.Collectors.mapping; |
| 87 | import static java.util.stream.Collectors.toList; |
| 88 | import static java.util.stream.Collectors.toSet; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 89 | import static org.onlab.util.Tools.get; |
| 90 | import static org.onlab.util.Tools.groupedThreads; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 91 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID; |
| 92 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID_DEFAULT; |
| 93 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME; |
| 94 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME_DEFAULT; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 95 | import static org.slf4j.LoggerFactory.getLogger; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 98 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 99 | */ |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 100 | @Component(immediate = true, |
| 101 | property = { |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 102 | DEFAULT_BP_ID + ":String=" + DEFAULT_BP_ID_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 103 | DEFAULT_MCAST_SERVICE_NAME + ":String=" + DEFAULT_MCAST_SERVICE_NAME_DEFAULT, |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 104 | }) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 105 | public class Olt |
| 106 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 107 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 108 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 109 | |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 110 | private static final short EAPOL_DEFAULT_VLAN = 4091; |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 111 | 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] | 112 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 113 | public static final int HASH_WEIGHT = 10; |
| 114 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 115 | private final Logger log = getLogger(getClass()); |
| 116 | |
Thomas Lee S | d7735f9 | 2020-02-20 19:21:47 +0530 | [diff] [blame] | 117 | private static final String NNI = "nni-"; |
| 118 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 120 | protected FlowObjectiveService flowObjectiveService; |
| 121 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 123 | protected DeviceService deviceService; |
| 124 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 126 | protected CoreService coreService; |
| 127 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 129 | protected ComponentConfigService componentConfigService; |
| 130 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 131 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 132 | protected SadisService sadisService; |
| 133 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 135 | protected AccessDeviceFlowService oltFlowService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 136 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 138 | protected AccessDeviceMeterService oltMeterService; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 139 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 141 | protected StorageService storageService; |
| 142 | |
| 143 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 144 | protected ClusterService clusterService; |
| 145 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 146 | /** |
Carmelo Cascone | 95ff512 | 2019-11-14 14:19:13 -0800 | [diff] [blame] | 147 | * Default bandwidth profile id that is used for authentication trap flows. |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 148 | **/ |
| 149 | protected String defaultBpId = DEFAULT_BP_ID_DEFAULT; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 150 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 151 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 152 | * Deleting Meters based on flow count statistics. |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 153 | **/ |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 154 | protected String multicastServiceName = DEFAULT_MCAST_SERVICE_NAME; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 155 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 156 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 157 | private final ClusterEventListener clusterListener = new InternalClusterListener(); |
| 158 | |
| 159 | private ConsistentHasher hasher; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 160 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 161 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
| 162 | private BaseInformationService<BandwidthProfileInformation> bpService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 163 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 164 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 165 | groupedThreads("onos/olt-service", |
| 166 | "olt-installer-%d")); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 167 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 168 | protected ExecutorService eventExecutor; |
| 169 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 170 | private ConsistentMultimap<ConnectPoint, UniTagInformation> programmedSubs; |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 171 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 172 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 173 | public void activate(ComponentContext context) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 174 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt", |
| 175 | "events-%d", log)); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 176 | modified(context); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 177 | ApplicationId appId = coreService.registerApplication(APP_NAME); |
Saurav Das | 62ad75e | 2019-03-05 12:22:22 -0800 | [diff] [blame] | 178 | |
| 179 | // ensure that flow rules are purged from flow-store upon olt-disconnection |
| 180 | // when olt reconnects, the port-numbers may change for the ONUs |
| 181 | // making flows pushed earlier invalid |
| 182 | componentConfigService |
| 183 | .preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 184 | "purgeOnDisconnection", "true"); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 185 | componentConfigService |
| 186 | .preSetProperty("org.onosproject.net.meter.impl.MeterManager", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 187 | "purgeOnDisconnection", "true"); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 188 | componentConfigService.registerProperties(getClass()); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 189 | |
| 190 | KryoNamespace serializer = KryoNamespace.newBuilder() |
| 191 | .register(KryoNamespaces.API) |
| 192 | .register(UniTagInformation.class) |
| 193 | .build(); |
| 194 | |
| 195 | programmedSubs = storageService.<ConnectPoint, UniTagInformation>consistentMultimapBuilder() |
| 196 | .withName("volt-programmed-subs") |
| 197 | .withSerializer(Serializer.using(serializer)) |
| 198 | .withApplicationId(appId) |
| 199 | .build(); |
alshabib | c4dfe85 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 200 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 201 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 202 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 203 | subsService = sadisService.getSubscriberInfoService(); |
| 204 | bpService = sadisService.getBandwidthProfileService(); |
| 205 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 206 | List<NodeId> readyNodes = clusterService.getNodes().stream() |
| 207 | .filter(c -> clusterService.getState(c.id()) == ControllerNode.State.READY) |
| 208 | .map(ControllerNode::id) |
| 209 | .collect(toList()); |
| 210 | hasher = new ConsistentHasher(readyNodes, HASH_WEIGHT); |
| 211 | clusterService.addListener(clusterListener); |
| 212 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 213 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 214 | // UNI ports |
| 215 | Iterable<Device> devices = deviceService.getDevices(); |
| 216 | for (Device d : devices) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 217 | if (isDeviceMine(d.id())) { |
| 218 | checkAndCreateDeviceFlows(d); |
| 219 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 220 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 221 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 222 | deviceService.addListener(deviceListener); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 223 | log.info("Started with Application ID {}", appId.id()); |
| 224 | } |
| 225 | |
| 226 | @Deactivate |
| 227 | public void deactivate() { |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 228 | componentConfigService.unregisterProperties(getClass(), false); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 229 | clusterService.removeListener(clusterListener); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 230 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 231 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 232 | log.info("Stopped"); |
| 233 | } |
| 234 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 235 | @Modified |
| 236 | public void modified(ComponentContext context) { |
| 237 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 238 | |
| 239 | try { |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 240 | String bpId = get(properties, "defaultBpId"); |
| 241 | defaultBpId = bpId; |
| 242 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 243 | String mcastSN = get(properties, "multicastServiceName"); |
| 244 | multicastServiceName = mcastSN; |
| 245 | |
| 246 | log.debug("OLT properties: DefaultBpId: {}, MulticastServiceName: {}", defaultBpId, multicastServiceName); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 247 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 248 | } catch (Exception e) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 249 | log.error("Error while modifying the properties", e); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 253 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 254 | public boolean provisionSubscriber(ConnectPoint connectPoint) { |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 255 | log.info("Call to provision subscriber at {}", connectPoint); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 256 | DeviceId deviceId = connectPoint.deviceId(); |
| 257 | PortNumber subscriberPortNo = connectPoint.port(); |
| 258 | |
| 259 | checkNotNull(deviceService.getPort(deviceId, subscriberPortNo), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 260 | "Invalid connect point:" + connectPoint); |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 261 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 262 | // Find the subscriber on this connect point |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 263 | SubscriberAndDeviceInformation sub = getSubscriber(connectPoint); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 264 | if (sub == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 265 | log.warn("No subscriber found for {}", connectPoint); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 266 | return false; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 267 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 268 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 269 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 270 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 271 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 272 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 273 | return false; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 276 | //delete Eapol authentication flow with default bandwidth |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 277 | //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 278 | //install subscriber flows |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 279 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 280 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, filterFuture, |
| 281 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 282 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 283 | if (filterStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 284 | provisionUniTagList(connectPoint, uplinkPort.number(), sub); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 285 | } |
| 286 | }); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 287 | return true; |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 291 | public boolean removeSubscriber(ConnectPoint connectPoint) { |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 292 | log.info("Call to un-provision subscriber at {}", connectPoint); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 293 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 294 | // Get the subscriber connected to this port from the local cache |
| 295 | // 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] | 296 | DeviceId deviceId = connectPoint.deviceId(); |
| 297 | PortNumber subscriberPortNo = connectPoint.port(); |
| 298 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 299 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(connectPoint).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 300 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 301 | log.warn("Subscriber on connectionPoint {} was not previously programmed, " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 302 | "no need to remove it", connectPoint); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 303 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 306 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 307 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 308 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 309 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 310 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 313 | for (UniTagInformation uniTag : uniTagInformationSet) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 314 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 315 | if (multicastServiceName.equals(uniTag.getServiceName())) { |
| 316 | continue; |
| 317 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 318 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 319 | unprovisionVlans(deviceId, uplinkPort.number(), subscriberPortNo, uniTag); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 320 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 321 | // re-install eapol with default bandwidth profile |
| 322 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, |
| 323 | uniTag.getUpstreamBandwidthProfile(), |
| 324 | null, uniTag.getPonCTag(), false); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 325 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 326 | Port port = deviceService.getPort(deviceId, subscriberPortNo); |
| 327 | if (port != null && port.isEnabled()) { |
| 328 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, |
| 329 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 330 | } else { |
| 331 | log.debug("Port {} is no longer enabled or it's unavailable. Not " |
| 332 | + "reprogramming default eapol flow", connectPoint); |
| 333 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 334 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 335 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 338 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 339 | @Override |
| 340 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 341 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
| 342 | |
| 343 | log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}, tpId {}" + |
| 344 | "", subscriberId, sTag, cTag, tpId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 345 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 346 | // Check if we can find the connect point to which this subscriber is connected |
| 347 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 348 | if (subsPort == null) { |
| 349 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 350 | return false; |
| 351 | } |
| 352 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 353 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 354 | return provisionSubscriber(subsPort); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 355 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 356 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 357 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 358 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 362 | //delete Eapol authentication flow with default bandwidth |
| 363 | //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] | 364 | //install subscriber flows |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 365 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 366 | oltFlowService.processEapolFilteringObjectives(subsPort.deviceId(), subsPort.port(), defaultBpId, |
| 367 | filterFuture, VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 368 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 369 | if (filterStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 370 | provisionUniTagInformation(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 371 | cTag.get(), sTag.get(), tpId.get()); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 372 | } |
| 373 | }); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 374 | return true; |
| 375 | } else { |
| 376 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 377 | return false; |
| 378 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 379 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 380 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 381 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 382 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 383 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 384 | // Check if we can find the connect point to which this subscriber is connected |
| 385 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 386 | if (subsPort == null) { |
| 387 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 388 | return false; |
| 389 | } |
| 390 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 391 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 392 | return removeSubscriber(subsPort); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 393 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 394 | // Get the uplink port |
| 395 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 396 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 397 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 398 | return false; |
| 399 | } |
| 400 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 401 | Optional<UniTagInformation> tagInfo = getUniTagInformation(subsPort, cTag.get(), sTag.get(), tpId.get()); |
| 402 | if (!tagInfo.isPresent()) { |
| 403 | log.warn("UniTagInformation does not exist for Device/Port {}, cTag {}, sTag {}, tpId {}", |
| 404 | subsPort, cTag, sTag, tpId); |
| 405 | return false; |
| 406 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 407 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 408 | unprovisionVlans(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), tagInfo.get()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 409 | return true; |
| 410 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 411 | log.warn("Removing subscriber is not possible - please check the provided information" + |
| 412 | "for the subscriber: {}", subscriberId); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 413 | return false; |
| 414 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 418 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getProgSubs() { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 419 | return programmedSubs.stream() |
| 420 | .collect(collectingAndThen( |
| 421 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 422 | ImmutableMap::copyOf)); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 426 | public List<DeviceId> fetchOlts() { |
| 427 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 428 | List<DeviceId> olts = new ArrayList<>(); |
| 429 | Iterable<Device> devices = deviceService.getDevices(); |
| 430 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 431 | if (getOltInfo(d) != null) { |
| 432 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 433 | olts.add(d.id()); |
| 434 | } |
| 435 | } |
| 436 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 439 | /** |
| 440 | * Finds the connect point to which a subscriber is connected. |
| 441 | * |
| 442 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 443 | * @return Subscribers ConnectPoint if found else null |
| 444 | */ |
| 445 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 446 | |
| 447 | Iterable<Device> devices = deviceService.getDevices(); |
| 448 | for (Device d : devices) { |
| 449 | for (Port p : deviceService.getPorts(d.id())) { |
| 450 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 451 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 452 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 453 | return new ConnectPoint(d.id(), p.number()); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | return null; |
| 458 | } |
| 459 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 460 | /** |
| 461 | * Gets the context of the bandwidth profile information for the given parameter. |
| 462 | * |
| 463 | * @param bandwidthProfile the bandwidth profile id |
| 464 | * @return the context of the bandwidth profile information |
| 465 | */ |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 466 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
| 467 | if (bandwidthProfile == null) { |
| 468 | return null; |
| 469 | } |
| 470 | return bpService.get(bandwidthProfile); |
| 471 | } |
| 472 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 473 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 474 | * Removes subscriber vlan flows. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 475 | * |
| 476 | * @param deviceId the device identifier |
| 477 | * @param uplink uplink port of the OLT |
| 478 | * @param subscriberPort uni port |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 479 | * @param uniTag uni tag information |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 480 | */ |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 481 | private void unprovisionVlans(DeviceId deviceId, PortNumber uplink, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 482 | PortNumber subscriberPort, UniTagInformation uniTag) { |
| 483 | |
| 484 | log.info("Unprovisioning vlans for {} at {}/{}", uniTag, deviceId, subscriberPort); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 485 | |
| 486 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 487 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 488 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 489 | VlanId deviceVlan = uniTag.getPonSTag(); |
| 490 | VlanId subscriberVlan = uniTag.getPonCTag(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 491 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 492 | MeterId upstreamMeterId = oltMeterService |
| 493 | .getMeterIdFromBpMapping(deviceId, uniTag.getUpstreamBandwidthProfile()); |
| 494 | MeterId downstreamMeterId = oltMeterService |
| 495 | .getMeterIdFromBpMapping(deviceId, uniTag.getDownstreamBandwidthProfile()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 496 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 497 | ForwardingObjective.Builder upFwd = |
| 498 | oltFlowService.createUpBuilder(uplink, subscriberPort, upstreamMeterId, uniTag); |
| 499 | ForwardingObjective.Builder downFwd = |
| 500 | oltFlowService.createDownBuilder(uplink, subscriberPort, downstreamMeterId, uniTag); |
| 501 | |
| 502 | if (uniTag.getIsIgmpRequired()) { |
| 503 | oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort, |
| 504 | upstreamMeterId, uniTag, false, true); |
| 505 | } |
| 506 | if (uniTag.getIsDhcpRequired()) { |
| 507 | oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort, |
| 508 | upstreamMeterId, uniTag, false, true); |
| 509 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 510 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 511 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 512 | @Override |
| 513 | public void onSuccess(Objective objective) { |
| 514 | upFuture.complete(null); |
| 515 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 516 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 517 | @Override |
| 518 | public void onError(Objective objective, ObjectiveError error) { |
| 519 | upFuture.complete(error); |
| 520 | } |
| 521 | })); |
| 522 | |
| 523 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 524 | @Override |
| 525 | public void onSuccess(Objective objective) { |
| 526 | downFuture.complete(null); |
| 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public void onError(Objective objective, ObjectiveError error) { |
| 531 | downFuture.complete(error); |
| 532 | } |
| 533 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 534 | |
| 535 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 536 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 537 | if (upStatus == null && downStatus == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 538 | log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {}, and" + |
| 539 | "Device/Port{}", uniTag.getPonCTag(), uniTag.getPonSTag(), |
| 540 | uniTag.getTechnologyProfileId(), subscriberPort); |
| 541 | updateProgrammedSubscriber(new ConnectPoint(deviceId, subscriberPort), uniTag, false); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 542 | } else if (downStatus != null) { |
| 543 | log.error("Subscriber with vlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 544 | "on port {} failed downstream uninstallation: {}", |
| 545 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 546 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 547 | } else if (upStatus != null) { |
| 548 | log.error("Subscriber with vlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 549 | "on port {} failed upstream uninstallation: {}", |
| 550 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 551 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 552 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 553 | Port port = deviceService.getPort(deviceId, subscriberPort); |
| 554 | post(new AccessDeviceEvent(type, deviceId, port, deviceVlan, subscriberVlan, |
| 555 | uniTag.getTechnologyProfileId())); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 556 | }, oltInstallers); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 559 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 560 | * 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] | 561 | * |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 562 | * @param connectPoint the connection point of the subscriber |
| 563 | * @param uplinkPort uplink port of the OLT (the nni port) |
| 564 | * @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] | 565 | */ |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 566 | private void provisionUniTagList(ConnectPoint connectPoint, PortNumber uplinkPort, |
| 567 | SubscriberAndDeviceInformation sub) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 568 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 569 | log.info("Provisioning vlans for subscriber {} on dev/port: {}", sub, connectPoint); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 570 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 571 | if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) { |
| 572 | log.warn("Unitaglist doesn't exist for the subscriber {}", sub.id()); |
| 573 | return; |
| 574 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 575 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 576 | DeviceId deviceId = connectPoint.deviceId(); |
| 577 | PortNumber subscriberPort = connectPoint.port(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 578 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 579 | for (UniTagInformation uniTag : sub.uniTagList()) { |
| 580 | handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, uniTag); |
| 581 | } |
| 582 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 583 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 584 | /** |
| 585 | * Finds the uni tag information and provisions the found information. |
| 586 | * If the uni tag information is not found, returns |
| 587 | * |
| 588 | * @param deviceId the access device id |
| 589 | * @param uplinkPort the nni port |
| 590 | * @param subscriberPort the uni port |
| 591 | * @param innerVlan the pon c tag |
| 592 | * @param outerVlan the pon s tag |
| 593 | * @param tpId the technology profile id |
| 594 | */ |
| 595 | private void provisionUniTagInformation(DeviceId deviceId, PortNumber uplinkPort, |
| 596 | PortNumber subscriberPort, |
| 597 | VlanId innerVlan, |
| 598 | VlanId outerVlan, |
| 599 | Integer tpId) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 600 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 601 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 602 | Optional<UniTagInformation> gotTagInformation = getUniTagInformation(cp, innerVlan, outerVlan, tpId); |
| 603 | if (!gotTagInformation.isPresent()) { |
| 604 | return; |
| 605 | } |
| 606 | UniTagInformation tagInformation = gotTagInformation.get(); |
| 607 | handleSubscriberFlows(deviceId, uplinkPort, subscriberPort, tagInformation); |
| 608 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 609 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 610 | private void updateProgrammedSubscriber(ConnectPoint connectPoint, UniTagInformation tagInformation, Boolean add) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 611 | if (add) { |
| 612 | programmedSubs.put(connectPoint, tagInformation); |
| 613 | } else { |
| 614 | programmedSubs.remove(connectPoint, tagInformation); |
| 615 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 618 | /** |
| 619 | * Installs a uni tag information flow. |
| 620 | * |
| 621 | * @param deviceId the access device id |
| 622 | * @param uplinkPort the nni port |
| 623 | * @param subscriberPort the uni port |
| 624 | * @param tagInfo the uni tag information |
| 625 | */ |
| 626 | private void handleSubscriberFlows(DeviceId deviceId, PortNumber uplinkPort, PortNumber subscriberPort, |
| 627 | UniTagInformation tagInfo) { |
| 628 | |
| 629 | log.info("Provisioning vlan-based flows for the uniTagInformation {}", tagInfo); |
| 630 | |
| 631 | Port port = deviceService.getPort(deviceId, subscriberPort); |
| 632 | |
| 633 | if (multicastServiceName.equals(tagInfo.getServiceName())) { |
| 634 | // IGMP flows are taken care of along with VOD service |
| 635 | // Please note that for each service, Subscriber Registered event will be sent |
| 636 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED, |
| 637 | deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 638 | tagInfo.getTechnologyProfileId())); |
| 639 | return; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 642 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 643 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 644 | BandwidthProfileInformation upstreamBpInfo = |
| 645 | getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile()); |
| 646 | BandwidthProfileInformation downstreamBpInfo = |
| 647 | getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile()); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 648 | |
| 649 | CompletableFuture<Object> upstreamMeterFuture = new CompletableFuture<>(); |
| 650 | CompletableFuture<Object> downsteamMeterFuture = new CompletableFuture<>(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 651 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>(); |
| 652 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 653 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 654 | MeterId upstreamMeterId = oltMeterService.createMeter(deviceId, upstreamBpInfo, upstreamMeterFuture); |
| 655 | |
| 656 | MeterId downstreamMeterId = oltMeterService.createMeter(deviceId, downstreamBpInfo, downsteamMeterFuture); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 657 | |
| 658 | upstreamMeterFuture.thenAcceptAsync(result -> { |
| 659 | if (result == null) { |
| 660 | log.info("Upstream Meter {} is sent to the device {}. " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 661 | "Sending subscriber flows.", upstreamMeterId, deviceId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 662 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 663 | ForwardingObjective.Builder upFwd = |
| 664 | oltFlowService.createUpBuilder(uplinkPort, subscriberPort, upstreamMeterId, tagInfo); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 665 | |
| 666 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 667 | @Override |
| 668 | public void onSuccess(Objective objective) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 669 | log.info("Upstream flow installed successfully"); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 670 | upFuture.complete(null); |
| 671 | } |
| 672 | |
| 673 | @Override |
| 674 | public void onError(Objective objective, ObjectiveError error) { |
| 675 | upFuture.complete(error); |
| 676 | } |
| 677 | })); |
| 678 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 679 | } else if (upstreamBpInfo == null) { |
| 680 | log.warn("No meter installed since no Upstream BW Profile definition found for " + |
| 681 | "ctag {} stag {} tpId {} and Device/port: {}:{}", |
| 682 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
| 683 | tagInfo.getTechnologyProfileId(), |
| 684 | deviceId, subscriberPort); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 685 | } else { |
| 686 | log.warn("Meter installation error while sending upstream flows. " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 687 | "Result {} and MeterId {}", result, upstreamMeterId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 688 | } |
Daniele Moro | 7cbf431 | 2020-03-06 17:24:12 -0800 | [diff] [blame] | 689 | }).exceptionally(ex -> { |
| 690 | log.error("Upstream flow failed: " + ex.getMessage()); |
| 691 | upFuture.complete(ObjectiveError.UNKNOWN); |
| 692 | return null; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 693 | }); |
| 694 | |
| 695 | downsteamMeterFuture.thenAcceptAsync(result -> { |
| 696 | if (result == null) { |
| 697 | log.info("Downstream Meter {} is sent to the device {}. " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 698 | "Sending subscriber flows.", downstreamMeterId, deviceId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 699 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 700 | ForwardingObjective.Builder downFwd = |
| 701 | oltFlowService.createDownBuilder(uplinkPort, subscriberPort, downstreamMeterId, tagInfo); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 702 | |
| 703 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 704 | @Override |
| 705 | public void onSuccess(Objective objective) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 706 | log.info("Downstream flow installed successfully"); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 707 | downFuture.complete(null); |
| 708 | } |
| 709 | |
| 710 | @Override |
| 711 | public void onError(Objective objective, ObjectiveError error) { |
| 712 | downFuture.complete(error); |
| 713 | } |
| 714 | })); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 715 | |
| 716 | } else if (downstreamBpInfo == null) { |
| 717 | log.warn("No meter installed since no Downstream BW Profile definition found for " + |
| 718 | "ctag {} stag {} tpId {} and Device/port: {}:{}", |
| 719 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
| 720 | tagInfo.getTechnologyProfileId(), |
| 721 | deviceId, subscriberPort); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 722 | } else { |
| 723 | log.warn("Meter installation error while sending upstream flows. " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 724 | "Result {} and MeterId {}", result, downstreamMeterId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 725 | } |
Daniele Moro | 7cbf431 | 2020-03-06 17:24:12 -0800 | [diff] [blame] | 726 | }).exceptionally(ex -> { |
| 727 | log.error("Downstream flow failed: " + ex.getMessage()); |
| 728 | downFuture.complete(ObjectiveError.UNKNOWN); |
| 729 | return null; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 730 | }); |
| 731 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 732 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 733 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 734 | if (downStatus != null) { |
| 735 | log.error("Flow with innervlan {} and outerVlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 736 | "on port {} failed downstream installation: {}", |
| 737 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), deviceId, cp, downStatus); |
| 738 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 739 | } else if (upStatus != null) { |
| 740 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 741 | "on port {} failed upstream installation: {}", |
| 742 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), deviceId, cp, upStatus); |
| 743 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 744 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 745 | log.info("Upstream and downstream data plane flows are installed successfully."); |
| 746 | oltFlowService.processEapolFilteringObjectives(deviceId, subscriberPort, |
| 747 | tagInfo.getUpstreamBandwidthProfile(), |
| 748 | null, tagInfo.getPonCTag(), true); |
| 749 | if (tagInfo.getIsDhcpRequired()) { |
| 750 | oltFlowService.processDhcpFilteringObjectives(deviceId, subscriberPort, |
| 751 | upstreamMeterId, tagInfo, true, true); |
| 752 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 753 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 754 | if (tagInfo.getIsIgmpRequired()) { |
| 755 | oltFlowService.processIgmpFilteringObjectives(deviceId, subscriberPort, upstreamMeterId, tagInfo, |
| 756 | true, true); |
| 757 | } |
| 758 | updateProgrammedSubscriber(cp, tagInfo, true); |
| 759 | post(new AccessDeviceEvent(type, deviceId, port, tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 760 | tagInfo.getTechnologyProfileId())); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 761 | } |
| 762 | }, oltInstallers); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 765 | /** |
| 766 | * Checks the subscriber uni tag list and find the uni tag information. |
| 767 | * using the pon c tag, pon s tag and the technology profile id |
| 768 | * May return Optional<null> |
| 769 | * |
| 770 | * @param cp the connection point of the subscriber |
| 771 | * @param innerVlan pon c tag |
| 772 | * @param outerVlan pon s tag |
| 773 | * @param tpId the technology profile id |
| 774 | * @return the found uni tag information |
| 775 | */ |
| 776 | private Optional<UniTagInformation> getUniTagInformation(ConnectPoint cp, VlanId innerVlan, VlanId outerVlan, |
| 777 | int tpId) { |
| 778 | log.info("Getting uni tag information for cp: {}, innerVlan: {}, outerVlan: {}, tpId: {}", cp, innerVlan, |
| 779 | outerVlan, tpId); |
| 780 | SubscriberAndDeviceInformation subInfo = getSubscriber(cp); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 781 | if (subInfo == null) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 782 | log.warn("Subscriber information doesn't exist for the connect point {}", cp); |
| 783 | return Optional.empty(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 786 | List<UniTagInformation> uniTagList = subInfo.uniTagList(); |
| 787 | if (uniTagList == null) { |
| 788 | log.warn("Uni tag list is not found for the subscriber {}", subInfo.id()); |
| 789 | return Optional.empty(); |
| 790 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 791 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 792 | UniTagInformation service = null; |
| 793 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 794 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 795 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 796 | service = tagInfo; |
| 797 | break; |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 798 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 799 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 800 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 801 | if (service == null) { |
| 802 | log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {}", |
| 803 | innerVlan, outerVlan, tpId); |
| 804 | return Optional.empty(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 807 | return Optional.of(service); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 810 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 811 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 812 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 813 | * |
| 814 | * @param dev Device to look for |
| 815 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 816 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 817 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 818 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 819 | log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 820 | |
| 821 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 822 | // 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] | 823 | for (Port p : deviceService.getPorts(dev.id())) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 824 | if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 825 | continue; |
| 826 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 827 | if (isUniPort(dev, p)) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 828 | log.info("Creating Eapol for the uni {}", p); |
| 829 | oltFlowService.processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null, |
| 830 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 831 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 832 | oltFlowService.processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 838 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 839 | /** |
| 840 | * Get the uplink for of the OLT device. |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 841 | * <p> |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 842 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 843 | * this logic needs to be changed |
| 844 | * |
| 845 | * @param dev Device to look for |
| 846 | * @return The uplink Port of the OLT |
| 847 | */ |
| 848 | private Port getUplinkPort(Device dev) { |
| 849 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 850 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 851 | log.trace("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 852 | if (deviceInfo == null) { |
| 853 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 854 | + " info", dev.id()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 855 | return null; |
| 856 | } |
| 857 | // Return the port that has been configured as the uplink port of this OLT in Sadis |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 858 | for (Port p : deviceService.getPorts(dev.id())) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 859 | if (p.number().toLong() == deviceInfo.uplinkPort()) { |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 860 | log.trace("getUplinkPort: Found port {}", p); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 861 | return p; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 865 | log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 866 | return null; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Return the subscriber on a port. |
| 871 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 872 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 873 | * @return subscriber if found else null |
| 874 | */ |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 875 | SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 876 | Port port = deviceService.getPort(cp); |
| 877 | checkNotNull(port, "Invalid connect point"); |
| 878 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 879 | return subsService.get(portName); |
| 880 | } |
| 881 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 882 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 883 | * Checks whether the given port of the device is a uni port or not. |
| 884 | * |
| 885 | * @param d the access device |
| 886 | * @param p the port of the device |
| 887 | * @return true if the given port is a uni port |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 888 | */ |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 889 | private boolean isUniPort(Device d, Port p) { |
| 890 | Port ulPort = getUplinkPort(d); |
| 891 | if (ulPort != null) { |
| 892 | return (ulPort.number().toLong() != p.number().toLong()); |
| 893 | } |
Thomas Lee S | d7735f9 | 2020-02-20 19:21:47 +0530 | [diff] [blame] | 894 | //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null |
| 895 | //checks whether the port name starts with nni- which is the signature of an NNI Port |
| 896 | if (p.annotations().value(AnnotationKeys.PORT_NAME) != null && |
| 897 | p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) { |
| 898 | log.error("NNI port number {} is not matching with configured value", p.number().toLong()); |
| 899 | return false; |
| 900 | } |
| 901 | return true; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 904 | /** |
| 905 | * Gets the given device details from SADIS. |
| 906 | * If the device is not found, returns null |
| 907 | * |
| 908 | * @param dev the access device |
| 909 | * @return the olt information |
| 910 | */ |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 911 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 912 | String devSerialNo = dev.serialNumber(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 913 | return subsService.get(devSerialNo); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 916 | /** |
| 917 | * Determines if this instance should handle this device based on |
| 918 | * consistent hashing. |
| 919 | * |
| 920 | * @param id device ID |
| 921 | * @return true if this instance should handle the device, otherwise false |
| 922 | */ |
| 923 | private boolean isDeviceMine(DeviceId id) { |
| 924 | NodeId nodeId = hasher.hash(id.toString()); |
| 925 | if (log.isDebugEnabled()) { |
| 926 | log.debug("Node that will handle {} is {}", id, nodeId); |
| 927 | } |
| 928 | return nodeId.equals(clusterService.getLocalNode().id()); |
| 929 | } |
| 930 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 931 | private class InternalDeviceListener implements DeviceListener { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 932 | private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet(); |
| 933 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 934 | @Override |
| 935 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 936 | eventExecutor.execute(() -> { |
| 937 | DeviceId devId = event.subject().id(); |
| 938 | Device dev = event.subject(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 939 | Port port = event.port(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 940 | DeviceEvent.Type eventType = event.type(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 941 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 942 | if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) || |
| 943 | DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) || |
| 944 | DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 945 | return; |
| 946 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 947 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 948 | // Only handle the event if the device belongs to us |
| 949 | if (!isDeviceMine(event.subject().id())) { |
| 950 | return; |
| 951 | } |
| 952 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 953 | log.debug("OLT got {} event for {} {}", eventType, event.subject(), event.port()); |
| 954 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 955 | if (getOltInfo(dev) == null) { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 956 | // it's possible that we got an event for a previously |
| 957 | // programmed OLT that is no longer available in SADIS |
| 958 | // we let such events go through |
| 959 | if (!programmedDevices.contains(devId)) { |
| 960 | log.warn("No device info found for {}, this is either " |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 961 | + "not an OLT or not known to sadis", dev); |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 962 | return; |
| 963 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 964 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 965 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 966 | switch (event.type()) { |
| 967 | //TODO: Port handling and bookkeeping should be improved once |
| 968 | // olt firmware handles correct behaviour. |
| 969 | case PORT_ADDED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 970 | if (isUniPort(dev, port)) { |
| 971 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 972 | |
| 973 | if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) { |
| 974 | log.info("eapol will be sent for port added {}", port); |
| 975 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
| 976 | null, |
| 977 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 978 | } |
| 979 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 980 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 981 | if (deviceInfo != null) { |
| 982 | oltFlowService.processNniFilteringObjectives(dev.id(), port.number(), true); |
| 983 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 984 | } |
| 985 | break; |
| 986 | case PORT_REMOVED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 987 | if (isUniPort(dev, port)) { |
Gamze Abaka | 853bf25 | 2019-03-25 10:27:06 +0000 | [diff] [blame] | 988 | removeSubscriber(new ConnectPoint(devId, port.number())); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 989 | log.info("eapol will be send for port removed", port); |
| 990 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
| 991 | null, |
| 992 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 993 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 994 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 995 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 996 | break; |
| 997 | case PORT_UPDATED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 998 | if (!isUniPort(dev, port)) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 999 | break; |
| 1000 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1001 | ConnectPoint cp = new ConnectPoint(devId, port.number()); |
| 1002 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1003 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame^] | 1004 | if (!port.number().equals(PortNumber.LOCAL)) { |
| 1005 | log.info("eapol will be {} for dev/port updated {}/{}", |
| 1006 | (port.isEnabled()) ? "added" : "removed", |
| 1007 | devId, port.number()); |
Matteo Scandolo | 27c471c | 2020-02-11 16:41:53 -0800 | [diff] [blame] | 1008 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1009 | null, |
| 1010 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1011 | port.isEnabled()); |
| 1012 | } |
| 1013 | } else { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame^] | 1014 | log.info("eapol will be {} for dev/port updated {}/{}", |
| 1015 | (port.isEnabled()) ? "added" : "removed", |
| 1016 | devId, port.number()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1017 | uniTagInformationSet.forEach(uniTag -> |
| 1018 | oltFlowService.processEapolFilteringObjectives(devId, port.number(), |
| 1019 | uniTag.getUpstreamBandwidthProfile(), null, |
| 1020 | uniTag.getPonCTag(), port.isEnabled())); |
| 1021 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1022 | if (port.isEnabled()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1023 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1024 | } else { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1025 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1026 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1027 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1028 | case DEVICE_ADDED: |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1029 | handleDeviceConnection(dev, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1030 | break; |
| 1031 | case DEVICE_REMOVED: |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1032 | handleDeviceDisconnection(dev, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1033 | break; |
| 1034 | case DEVICE_AVAILABILITY_CHANGED: |
| 1035 | if (deviceService.isAvailable(devId)) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1036 | handleDeviceConnection(dev, false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1037 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1038 | handleDeviceDisconnection(dev, false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1039 | } |
| 1040 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1041 | default: |
| 1042 | return; |
| 1043 | } |
| 1044 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1045 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1046 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1047 | private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) { |
| 1048 | deviceService.getPorts(device.id()).stream() |
| 1049 | .filter(p -> !PortNumber.LOCAL.equals(p.number())) |
| 1050 | .filter(p -> isUniPort(device, p)) |
| 1051 | .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p))); |
| 1052 | } |
| 1053 | |
| 1054 | private void handleDeviceDisconnection(Device device, boolean sendUniEvent) { |
| 1055 | programmedDevices.remove(device.id()); |
| 1056 | removeAllSubscribers(device.id()); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1057 | oltMeterService.clearMeters(device.id()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1058 | post(new AccessDeviceEvent( |
| 1059 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(), |
| 1060 | null, null, null)); |
| 1061 | if (sendUniEvent) { |
| 1062 | sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1063 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | private void handleDeviceConnection(Device dev, boolean sendUniEvent) { |
| 1067 | post(new AccessDeviceEvent( |
| 1068 | AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(), |
| 1069 | null, null, null)); |
| 1070 | programmedDevices.add(dev.id()); |
| 1071 | checkAndCreateDeviceFlows(dev); |
| 1072 | if (sendUniEvent) { |
| 1073 | sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED); |
| 1074 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1075 | } |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1076 | |
| 1077 | private void removeAllSubscribers(DeviceId deviceId) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1078 | List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream() |
| 1079 | .filter(e -> e.getKey().deviceId().equals(deviceId)) |
| 1080 | .collect(toList()); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1081 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1082 | subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue())); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1083 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1084 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1085 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1086 | |
| 1087 | private class InternalClusterListener implements ClusterEventListener { |
| 1088 | |
| 1089 | @Override |
| 1090 | public void event(ClusterEvent event) { |
| 1091 | if (event.type() == ClusterEvent.Type.INSTANCE_READY) { |
| 1092 | hasher.addServer(event.subject().id()); |
| 1093 | } |
| 1094 | if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) { |
| 1095 | hasher.removeServer(event.subject().id()); |
| 1096 | } |
| 1097 | } |
| 1098 | } |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 1099 | } |