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