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