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