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