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