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