alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1 | /* |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 2 | * Copyright 2021-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 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 18 | import org.onlab.packet.VlanId; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 19 | import org.onlab.util.KryoNamespace; |
Gamze Abaka | 1f62dd9 | 2020-05-07 08:58:13 +0000 | [diff] [blame] | 20 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 21 | import org.onosproject.cluster.ClusterService; |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 22 | import org.onosproject.cluster.LeadershipService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 25 | import org.onosproject.event.AbstractListenerManager; |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 26 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 27 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 28 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 29 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 31 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 32 | import org.onosproject.net.PortNumber; |
| 33 | import org.onosproject.net.device.DeviceEvent; |
| 34 | import org.onosproject.net.device.DeviceListener; |
| 35 | import org.onosproject.net.device.DeviceService; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 36 | import org.onosproject.store.serializers.KryoNamespaces; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 37 | import org.onosproject.store.service.Serializer; |
| 38 | import org.onosproject.store.service.StorageService; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 39 | import org.opencord.olt.AccessDeviceEvent; |
| 40 | import org.opencord.olt.AccessDeviceListener; |
| 41 | import org.opencord.olt.AccessDeviceService; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 42 | import org.opencord.sadis.BaseInformationService; |
| 43 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 44 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 45 | import org.opencord.sadis.UniTagInformation; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 46 | import org.osgi.service.component.ComponentContext; |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 47 | import org.osgi.service.component.annotations.Activate; |
| 48 | import org.osgi.service.component.annotations.Component; |
| 49 | import org.osgi.service.component.annotations.Deactivate; |
| 50 | import org.osgi.service.component.annotations.Modified; |
| 51 | import org.osgi.service.component.annotations.Reference; |
| 52 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 53 | import org.osgi.service.component.annotations.ReferencePolicy; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 54 | import org.slf4j.Logger; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 55 | import org.slf4j.LoggerFactory; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 56 | |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 57 | import java.util.ArrayList; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 58 | import java.util.Dictionary; |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 59 | import java.util.HashSet; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 60 | import java.util.Iterator; |
| 61 | import java.util.LinkedList; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 62 | import java.util.List; |
| 63 | import java.util.Map; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 64 | import java.util.Properties; |
| 65 | import java.util.Set; |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 66 | import java.util.concurrent.ArrayBlockingQueue; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 67 | import java.util.concurrent.ExecutorService; |
| 68 | import java.util.concurrent.Executors; |
| 69 | import java.util.concurrent.LinkedBlockingQueue; |
| 70 | import java.util.concurrent.ScheduledExecutorService; |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 71 | import java.util.concurrent.ThreadPoolExecutor; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 72 | import java.util.concurrent.TimeUnit; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 73 | import java.util.concurrent.locks.Lock; |
| 74 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 75 | |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 76 | import static com.google.common.base.Strings.isNullOrEmpty; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 77 | import static org.onlab.util.Tools.get; |
| 78 | import static org.onlab.util.Tools.groupedThreads; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 79 | import static org.opencord.olt.impl.OltUtils.getPortName; |
| 80 | import static org.opencord.olt.impl.OltUtils.portWithName; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 81 | import static org.opencord.olt.impl.OsgiPropertyConstants.*; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 84 | * OLT Application. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 85 | */ |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 86 | @Component(immediate = true, |
| 87 | property = { |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 88 | DEFAULT_BP_ID + ":String=" + DEFAULT_BP_ID_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 89 | DEFAULT_MCAST_SERVICE_NAME + ":String=" + DEFAULT_MCAST_SERVICE_NAME_DEFAULT, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 90 | FLOW_PROCESSING_THREADS + ":Integer=" + FLOW_PROCESSING_THREADS_DEFAULT, |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 91 | FLOW_EXECUTOR_QUEUE_SIZE + ":Integer=" + FLOW_EXECUTOR_QUEUE_SIZE_DEFAULT, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 92 | SUBSCRIBER_PROCESSING_THREADS + ":Integer=" + SUBSCRIBER_PROCESSING_THREADS_DEFAULT, |
| 93 | REQUEUE_DELAY + ":Integer=" + REQUEUE_DELAY_DEFAULT |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 94 | }) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 95 | public class Olt |
| 96 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 97 | implements AccessDeviceService { |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 98 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 99 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 100 | protected DeviceService deviceService; |
| 101 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 102 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 103 | protected ComponentConfigService cfgService; |
Andrea Campanella | 438e1ad | 2021-03-26 11:41:16 +0100 | [diff] [blame] | 104 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 106 | protected MastershipService mastershipService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 107 | |
Andrea Campanella | 438e1ad | 2021-03-26 11:41:16 +0100 | [diff] [blame] | 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 109 | protected ClusterService clusterService; |
| 110 | |
| 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 112 | protected LeadershipService leadershipService; |
Andrea Campanella | 438e1ad | 2021-03-26 11:41:16 +0100 | [diff] [blame] | 113 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 114 | @Reference(cardinality = ReferenceCardinality.OPTIONAL, |
| 115 | bind = "bindSadisService", |
| 116 | unbind = "unbindSadisService", |
| 117 | policy = ReferencePolicy.DYNAMIC) |
| 118 | protected volatile SadisService sadisService; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 119 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 121 | protected OltDeviceServiceInterface oltDeviceService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 122 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 124 | protected OltFlowServiceInterface oltFlowService; |
| 125 | |
| 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 127 | protected OltMeterServiceInterface oltMeterService; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 128 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 130 | protected StorageService storageService; |
| 131 | |
| 132 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 133 | protected CoreService coreService; |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 134 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 135 | protected ApplicationId appId; |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 136 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 137 | private static final String ONOS_OLT_SERVICE = "onos/olt-service"; |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 138 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 139 | /** |
Carmelo Cascone | 95ff512 | 2019-11-14 14:19:13 -0800 | [diff] [blame] | 140 | * Default bandwidth profile id that is used for authentication trap flows. |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 141 | **/ |
| 142 | protected String defaultBpId = DEFAULT_BP_ID_DEFAULT; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 143 | |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 144 | /** |
Gamze Abaka | 51a34e8 | 2020-05-08 13:03:14 +0000 | [diff] [blame] | 145 | * Default multicast service name. |
Carmelo Cascone | ca93116 | 2019-07-15 18:22:24 -0700 | [diff] [blame] | 146 | **/ |
Gamze Abaka | 51a34e8 | 2020-05-08 13:03:14 +0000 | [diff] [blame] | 147 | protected String multicastServiceName = DEFAULT_MCAST_SERVICE_NAME_DEFAULT; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 148 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 149 | /** |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 150 | * Number of threads used to process flows. |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 151 | **/ |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 152 | protected int flowProcessingThreads = FLOW_PROCESSING_THREADS_DEFAULT; |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 153 | |
Matteo Scandolo | a4aaa97 | 2020-10-23 15:24:38 -0700 | [diff] [blame] | 154 | /** |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 155 | * Number of threads used to process flows. |
| 156 | **/ |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 157 | protected int flowExecutorQueueSize = FLOW_EXECUTOR_QUEUE_SIZE_DEFAULT; |
| 158 | |
| 159 | /** |
| 160 | * Number of threads used to process flows. |
| 161 | **/ |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 162 | protected int subscriberProcessingThreads = SUBSCRIBER_PROCESSING_THREADS_DEFAULT; |
| 163 | |
| 164 | /** |
| 165 | * Delay in ms to put an event back in the queue, used to avoid retrying things to often if conditions are not met. |
| 166 | **/ |
| 167 | protected int requeueDelay = REQUEUE_DELAY_DEFAULT; |
| 168 | |
| 169 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 170 | |
| 171 | /** |
| 172 | * A queue to asynchronously process events. |
Matteo Scandolo | a4aaa97 | 2020-10-23 15:24:38 -0700 | [diff] [blame] | 173 | */ |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 174 | protected Map<ConnectPoint, LinkedBlockingQueue<DiscoveredSubscriber>> eventsQueues; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 175 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 176 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 177 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 178 | /** |
| 179 | * Listener for OLT devices events. |
| 180 | */ |
| 181 | protected OltDeviceListener deviceListener = new OltDeviceListener(); |
| 182 | protected ScheduledExecutorService discoveredSubscriberExecutor = |
| 183 | Executors.newSingleThreadScheduledExecutor(groupedThreads("onos/olt", |
| 184 | "discovered-cp-%d", log)); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 185 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 186 | protected ScheduledExecutorService queueExecutor = |
| 187 | Executors.newSingleThreadScheduledExecutor(groupedThreads("onos/olt", |
| 188 | "discovered-cp-restore-%d", log)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 189 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 190 | /** |
| 191 | * Executor used to defer flow provisioning to a different thread pool. |
| 192 | */ |
| 193 | protected ExecutorService flowsExecutor; |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 194 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 195 | /** |
| 196 | * Executor used to defer subscriber handling from API call to a different thread pool. |
| 197 | */ |
| 198 | protected ExecutorService subscriberExecutor; |
| 199 | |
| 200 | private static final String APP_NAME = "org.opencord.olt"; |
| 201 | |
| 202 | private final ReentrantReadWriteLock queueLock = new ReentrantReadWriteLock(); |
| 203 | private final Lock queueWriteLock = queueLock.writeLock(); |
| 204 | private final Lock queueReadLock = queueLock.readLock(); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 205 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 206 | @Activate |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 207 | protected void activate(ComponentContext context) { |
| 208 | cfgService.registerProperties(getClass()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 209 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 210 | modified(context); |
Saurav Das | 62ad75e | 2019-03-05 12:22:22 -0800 | [diff] [blame] | 211 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 212 | appId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 213 | KryoNamespace serializer = KryoNamespace.newBuilder() |
| 214 | .register(KryoNamespaces.API) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 215 | .register(ConnectPoint.class) |
| 216 | .register(DiscoveredSubscriber.class) |
| 217 | .register(DiscoveredSubscriber.Status.class) |
| 218 | .register(SubscriberAndDeviceInformation.class) |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 219 | .register(UniTagInformation.class) |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 220 | .register(LinkedBlockingQueue.class) |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 221 | .build(); |
| 222 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 223 | eventsQueues = storageService.<ConnectPoint, LinkedBlockingQueue<DiscoveredSubscriber>>consistentMapBuilder() |
| 224 | .withName("volt-subscriber-queues") |
| 225 | .withApplicationId(appId) |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 226 | .withSerializer(Serializer.using(serializer)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 227 | .build().asJavaMap(); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 228 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 229 | deviceService.addListener(deviceListener); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 230 | |
| 231 | discoveredSubscriberExecutor.execute(this::processDiscoveredSubscribers); |
| 232 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 233 | log.info("Started"); |
| 234 | |
| 235 | deviceListener.handleExistingPorts(); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Deactivate |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 239 | protected void deactivate(ComponentContext context) { |
| 240 | cfgService.unregisterProperties(getClass(), false); |
| 241 | discoveredSubscriberExecutor.shutdown(); |
Andrea Campanella | eaf2395 | 2021-12-30 15:58:54 +0100 | [diff] [blame] | 242 | deviceService.removeListener(deviceListener); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 243 | flowsExecutor.shutdown(); |
| 244 | subscriberExecutor.shutdown(); |
| 245 | deviceListener.deactivate(); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 246 | log.info("Stopped"); |
| 247 | } |
| 248 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 249 | @Modified |
| 250 | public void modified(ComponentContext context) { |
| 251 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 252 | if (context != null) { |
Andrea Campanella | 971d5b9 | 2020-05-07 11:20:43 +0200 | [diff] [blame] | 253 | String bpId = get(properties, DEFAULT_BP_ID); |
| 254 | defaultBpId = isNullOrEmpty(bpId) ? defaultBpId : bpId; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 255 | |
Andrea Campanella | 971d5b9 | 2020-05-07 11:20:43 +0200 | [diff] [blame] | 256 | String mcastSN = get(properties, DEFAULT_MCAST_SERVICE_NAME); |
| 257 | multicastServiceName = isNullOrEmpty(mcastSN) ? multicastServiceName : mcastSN; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 258 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 259 | String flowThreads = get(properties, FLOW_PROCESSING_THREADS); |
| 260 | int oldFlowProcessingThreads = flowProcessingThreads; |
| 261 | flowProcessingThreads = isNullOrEmpty(flowThreads) ? |
| 262 | oldFlowProcessingThreads : Integer.parseInt(flowThreads.trim()); |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 263 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 264 | String executorQueueSize = get(properties, FLOW_EXECUTOR_QUEUE_SIZE); |
| 265 | int oldExecutorQueueSize = flowExecutorQueueSize; |
| 266 | flowExecutorQueueSize = isNullOrEmpty(executorQueueSize) ? |
| 267 | oldExecutorQueueSize : Integer.parseInt(executorQueueSize.trim()); |
| 268 | |
| 269 | if (flowsExecutor == null || oldFlowProcessingThreads != flowProcessingThreads |
| 270 | || oldExecutorQueueSize != flowExecutorQueueSize) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 271 | if (flowsExecutor != null) { |
| 272 | flowsExecutor.shutdown(); |
| 273 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 274 | |
| 275 | flowsExecutor = new ThreadPoolExecutor(0, flowProcessingThreads, 30, |
| 276 | TimeUnit.SECONDS, new ThreadPoolQueue(flowExecutorQueueSize), |
| 277 | new ThreadPoolExecutor.DiscardPolicy()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 278 | } |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 279 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 280 | String subscriberThreads = get(properties, SUBSCRIBER_PROCESSING_THREADS); |
| 281 | int oldSubscriberProcessingThreads = subscriberProcessingThreads; |
| 282 | subscriberProcessingThreads = isNullOrEmpty(subscriberThreads) ? |
| 283 | oldSubscriberProcessingThreads : Integer.parseInt(subscriberThreads.trim()); |
| 284 | |
| 285 | if (subscriberExecutor == null || oldSubscriberProcessingThreads != subscriberProcessingThreads) { |
| 286 | if (subscriberExecutor != null) { |
| 287 | subscriberExecutor.shutdown(); |
| 288 | } |
| 289 | subscriberExecutor = Executors.newFixedThreadPool(subscriberProcessingThreads, |
| 290 | groupedThreads(ONOS_OLT_SERVICE, |
| 291 | "subscriber-installer-%d")); |
| 292 | } |
| 293 | |
| 294 | String queueDelay = get(properties, REQUEUE_DELAY); |
| 295 | requeueDelay = isNullOrEmpty(queueDelay) ? |
| 296 | REQUEUE_DELAY_DEFAULT : Integer.parseInt(queueDelay.trim()); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 297 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 298 | log.info("Modified. Values = {}: {}, {}:{}, {}:{}," + |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 299 | "{}:{}, {}:{}, {}:{}", |
| 300 | DEFAULT_BP_ID, defaultBpId, |
| 301 | DEFAULT_MCAST_SERVICE_NAME, multicastServiceName, |
| 302 | FLOW_PROCESSING_THREADS, flowProcessingThreads, |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 303 | FLOW_EXECUTOR_QUEUE_SIZE, flowExecutorQueueSize, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 304 | SUBSCRIBER_PROCESSING_THREADS, subscriberProcessingThreads, |
| 305 | REQUEUE_DELAY, requeueDelay); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 308 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 309 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 310 | public boolean provisionSubscriber(ConnectPoint cp) { |
| 311 | subscriberExecutor.submit(() -> { |
| 312 | Device device = deviceService.getDevice(cp.deviceId()); |
| 313 | Port port = deviceService.getPort(device.id(), cp.port()); |
| 314 | AccessDevicePort accessDevicePort = new AccessDevicePort(port); |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 315 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 316 | if (oltDeviceService.isNniPort(device, port.number())) { |
| 317 | log.warn("will not provision a subscriber on the NNI {}", accessDevicePort); |
| 318 | return false; |
Saurav Das | 026650f | 2020-09-21 18:56:35 -0700 | [diff] [blame] | 319 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 320 | |
| 321 | log.info("Provisioning subscriber on {}", accessDevicePort); |
| 322 | |
| 323 | if (oltFlowService.isSubscriberServiceProvisioned(accessDevicePort)) { |
| 324 | log.error("Subscriber on {} is already provisioned", accessDevicePort); |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | SubscriberAndDeviceInformation si = subsService.get(getPortName(port)); |
| 329 | if (si == null) { |
| 330 | log.error("Subscriber information not found in sadis for port {}", accessDevicePort); |
| 331 | return false; |
| 332 | } |
| 333 | DiscoveredSubscriber sub = new DiscoveredSubscriber(device, port, |
| 334 | DiscoveredSubscriber.Status.ADDED, true, si); |
| 335 | |
| 336 | // NOTE we need to keep a list of the subscribers that are provisioned on a port, |
| 337 | // regardless of the flow status |
| 338 | si.uniTagList().forEach(uti -> { |
| 339 | ServiceKey sk = new ServiceKey(accessDevicePort, uti); |
| 340 | oltFlowService.updateProvisionedSubscriberStatus(sk, true); |
| 341 | }); |
| 342 | |
| 343 | addSubscriberToQueue(sub); |
| 344 | return true; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 345 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 346 | //NOTE this only means we have taken the request in, nothing more. |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 347 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 350 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 351 | public boolean removeSubscriber(ConnectPoint cp) { |
| 352 | subscriberExecutor.submit(() -> { |
| 353 | Device device = deviceService.getDevice(DeviceId.deviceId(cp.deviceId().toString())); |
| 354 | Port port = deviceService.getPort(device.id(), cp.port()); |
| 355 | AccessDevicePort accessDevicePort = new AccessDevicePort(port); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 356 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 357 | if (oltDeviceService.isNniPort(device, port.number())) { |
| 358 | log.warn("will not un-provision a subscriber on the NNI {}", |
| 359 | accessDevicePort); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 363 | log.info("Un-provisioning subscriber on {}", accessDevicePort); |
| 364 | |
| 365 | if (!oltFlowService.isSubscriberServiceProvisioned(accessDevicePort)) { |
| 366 | log.error("Subscriber on {} is not provisioned", accessDevicePort); |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | SubscriberAndDeviceInformation si = subsService.get(getPortName(port)); |
| 371 | if (si == null) { |
| 372 | log.error("Subscriber information not found in sadis for port {}", |
| 373 | accessDevicePort); |
| 374 | // NOTE that we are returning true so that the subscriber is removed from the queue |
| 375 | // and we can move on provisioning others |
| 376 | return false; |
| 377 | } |
| 378 | DiscoveredSubscriber sub = new DiscoveredSubscriber(device, port, |
| 379 | DiscoveredSubscriber.Status.REMOVED, true, si); |
| 380 | |
| 381 | // NOTE we need to keep a list of the subscribers that are provisioned on a port, |
| 382 | // regardless of the flow status |
| 383 | si.uniTagList().forEach(uti -> { |
| 384 | ServiceKey sk = new ServiceKey(accessDevicePort, uti); |
| 385 | oltFlowService.updateProvisionedSubscriberStatus(sk, false); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 386 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 387 | |
| 388 | addSubscriberToQueue(sub); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 389 | return true; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 390 | }); |
| 391 | //NOTE this only means we have taken the request in, nothing more. |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public boolean provisionSubscriber(ConnectPoint cp, VlanId cTag, VlanId sTag, Integer tpId) { |
| 397 | log.debug("Provisioning subscriber on {}, with cTag {}, stag {}, tpId {}", |
| 398 | cp, cTag, sTag, tpId); |
| 399 | Device device = deviceService.getDevice(cp.deviceId()); |
| 400 | Port port = deviceService.getPort(device.id(), cp.port()); |
| 401 | AccessDevicePort accessDevicePort = new AccessDevicePort(port); |
| 402 | |
| 403 | if (oltDeviceService.isNniPort(device, port.number())) { |
| 404 | log.warn("will not provision a subscriber on the NNI {}", accessDevicePort); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 405 | return false; |
| 406 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 407 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 408 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 409 | UniTagInformation specificService = getUniTagInformation(getPortName(port), cTag, sTag, tpId); |
| 410 | if (specificService == null) { |
| 411 | log.error("Can't find Information for subscriber on {}, with cTag {}, " + |
| 412 | "stag {}, tpId {}", cp, cTag, sTag, tpId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 413 | return false; |
| 414 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 415 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 416 | uniTagInformationList.add(specificService); |
| 417 | si.setUniTagList(uniTagInformationList); |
| 418 | DiscoveredSubscriber sub = new DiscoveredSubscriber(device, port, |
| 419 | DiscoveredSubscriber.Status.ADDED, true, si); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 420 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 421 | // NOTE we need to keep a list of the subscribers that are provisioned on a port, |
| 422 | // regardless of the flow status |
| 423 | ServiceKey sk = new ServiceKey(accessDevicePort, specificService); |
| 424 | if (oltFlowService.isSubscriberServiceProvisioned(sk)) { |
| 425 | log.error("Subscriber on {} is already provisioned", sk); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 426 | return false; |
| 427 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 428 | oltFlowService.updateProvisionedSubscriberStatus(sk, true); |
| 429 | |
| 430 | addSubscriberToQueue(sub); |
| 431 | return true; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 435 | public boolean removeSubscriber(ConnectPoint cp, VlanId cTag, VlanId sTag, Integer tpId) { |
| 436 | log.debug("Un-provisioning subscriber on {} with cTag {}, stag {}, tpId {}", |
| 437 | cp, cTag, sTag, tpId); |
| 438 | Device device = deviceService.getDevice(cp.deviceId()); |
| 439 | Port port = deviceService.getPort(device.id(), cp.port()); |
| 440 | AccessDevicePort accessDevicePort = new AccessDevicePort(port); |
| 441 | |
| 442 | if (oltDeviceService.isNniPort(device, port.number())) { |
| 443 | log.warn("will not un-provision a subscriber on the NNI {}", |
| 444 | accessDevicePort); |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 449 | UniTagInformation specificService = getUniTagInformation(getPortName(port), cTag, sTag, tpId); |
| 450 | if (specificService == null) { |
| 451 | log.error("Can't find Information for subscriber on {}, with cTag {}, " + |
| 452 | "stag {}, tpId {}", cp, cTag, sTag, tpId); |
| 453 | return false; |
| 454 | } |
| 455 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 456 | uniTagInformationList.add(specificService); |
| 457 | si.setUniTagList(uniTagInformationList); |
| 458 | DiscoveredSubscriber sub = new DiscoveredSubscriber(device, port, |
Andrea Campanella | 982fd33 | 2022-01-19 09:14:12 +0100 | [diff] [blame] | 459 | DiscoveredSubscriber.Status.REMOVED, true, si); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 460 | |
| 461 | // NOTE we need to keep a list of the subscribers that are provisioned on a port, |
| 462 | // regardless of the flow status |
| 463 | ServiceKey sk = new ServiceKey(accessDevicePort, specificService); |
| 464 | if (!oltFlowService.isSubscriberServiceProvisioned(sk)) { |
| 465 | log.error("Subscriber on {} is not provisioned", sk); |
| 466 | return false; |
| 467 | } |
| 468 | oltFlowService.updateProvisionedSubscriberStatus(sk, false); |
| 469 | |
| 470 | addSubscriberToQueue(sub); |
| 471 | return true; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 475 | public List<DeviceId> getConnectedOlts() { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 476 | List<DeviceId> olts = new ArrayList<>(); |
| 477 | Iterable<Device> devices = deviceService.getDevices(); |
| 478 | for (Device d : devices) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 479 | if (oltDeviceService.isOlt(d)) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 480 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 481 | olts.add(d.id()); |
| 482 | } |
| 483 | } |
| 484 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 487 | /** |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 488 | * Finds the connect-point to which a subscriber is connected. |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 489 | * |
| 490 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 491 | * @return Subscribers ConnectPoint if found else null |
| 492 | */ |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 493 | @Override |
| 494 | public ConnectPoint findSubscriberConnectPoint(String id) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 495 | |
| 496 | Iterable<Device> devices = deviceService.getDevices(); |
| 497 | for (Device d : devices) { |
| 498 | for (Port p : deviceService.getPorts(d.id())) { |
| 499 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 500 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 501 | log.debug("Found on {}", portWithName(p)); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 502 | return new ConnectPoint(d.id(), p.number()); |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | return null; |
| 507 | } |
| 508 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 509 | protected void processDiscoveredSubscribers() { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 510 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 511 | log.info("Started processDiscoveredSubscribers loop"); |
| 512 | while (true) { |
| 513 | Set<ConnectPoint> discoveredCps; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 514 | try { |
| 515 | queueReadLock.lock(); |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 516 | discoveredCps = new HashSet<>(eventsQueues.keySet()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 517 | } catch (Exception e) { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 518 | log.error("Cannot read keys from queue map", e); |
| 519 | continue; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 520 | } finally { |
| 521 | queueReadLock.unlock(); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 522 | } |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 523 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 524 | discoveredCps.forEach(cp -> { |
| 525 | LinkedBlockingQueue<DiscoveredSubscriber> eventsQueue; |
| 526 | |
| 527 | try { |
| 528 | queueReadLock.lock(); |
| 529 | eventsQueue = eventsQueues.get(cp); |
| 530 | } catch (Exception e) { |
| 531 | log.error("Cannot get key from queue map", e); |
| 532 | return; |
| 533 | } finally { |
| 534 | queueReadLock.unlock(); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 535 | } |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 536 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 537 | if (!oltDeviceService.isLocalLeader(cp.deviceId())) { |
| 538 | // if we're not local leader for this device, ignore this queue |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 539 | if (log.isTraceEnabled()) { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 540 | log.trace("Ignoring queue on CP {} as not master of the device", cp); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 541 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 542 | return; |
| 543 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 544 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 545 | try { |
| 546 | flowsExecutor.execute(() -> { |
| 547 | if (!eventsQueue.isEmpty()) { |
| 548 | // we do not remove the event from the queue until it has been processed |
| 549 | // in that way we guarantee that events are processed in order |
| 550 | DiscoveredSubscriber sub = eventsQueue.peek(); |
| 551 | if (sub == null) { |
| 552 | // the queue is empty |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 553 | return; |
| 554 | } |
| 555 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 556 | if (log.isTraceEnabled()) { |
| 557 | log.trace("Processing subscriber {} on port {} with status {}, has subscriber {}", |
| 558 | sub, portWithName(sub.port), sub.status, sub.hasSubscriber); |
| 559 | } |
| 560 | |
| 561 | if (sub.hasSubscriber) { |
| 562 | // this is a provision subscriber call |
| 563 | if (oltFlowService.handleSubscriberFlows(sub, defaultBpId, multicastServiceName)) { |
| 564 | removeSubscriberFromQueue(sub); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 565 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 566 | } else { |
| 567 | // this is a port event (ENABLED/DISABLED) |
| 568 | // means no subscriber was provisioned on that port |
| 569 | |
| 570 | if (!deviceService.isAvailable(sub.device.id()) || |
| 571 | deviceService.getPort(sub.device.id(), sub.port.number()) == null) { |
| 572 | // If the device is not connected or the port is not available do nothing |
| 573 | // This can happen when we disable and then immediately delete the device, |
| 574 | // the queue is populated but the meters and flows are already gone |
| 575 | // thus there is nothing left to do |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | if (oltFlowService.handleBasicPortFlows(sub, defaultBpId, defaultBpId)) { |
| 580 | if (log.isTraceEnabled()) { |
| 581 | log.trace("Processing of port {} completed", |
| 582 | portWithName(sub.port)); |
| 583 | } |
| 584 | removeSubscriberFromQueue(sub); |
| 585 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 586 | } |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 587 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 588 | }); |
| 589 | } catch (Exception e) { |
| 590 | log.error("Exception processing subscriber", e); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 591 | } |
| 592 | }); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 593 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 594 | try { |
| 595 | TimeUnit.MILLISECONDS.sleep(requeueDelay); |
| 596 | } catch (InterruptedException e) { |
| 597 | log.debug("Interrupted while waiting to requeue", e); |
| 598 | } |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 599 | } |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 600 | } |
| 601 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 602 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 603 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 604 | * Checks the subscriber uni tag list and find the uni tag information. |
| 605 | * using the pon c tag, pon s tag and the technology profile id |
| 606 | * May return Optional<null> |
| 607 | * |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 608 | * @param portName port of the subscriber |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 609 | * @param innerVlan pon c tag |
| 610 | * @param outerVlan pon s tag |
| 611 | * @param tpId the technology profile id |
| 612 | * @return the found uni tag information |
| 613 | */ |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 614 | private UniTagInformation getUniTagInformation(String portName, VlanId innerVlan, |
| 615 | VlanId outerVlan, int tpId) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 616 | log.debug("Getting uni tag information for {}, innerVlan: {}, outerVlan: {}, tpId: {}", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 617 | portName, innerVlan, outerVlan, tpId); |
| 618 | SubscriberAndDeviceInformation subInfo = subsService.get(portName); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 619 | if (subInfo == null) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 620 | log.warn("Subscriber information doesn't exist for {}", portName); |
| 621 | return null; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 624 | List<UniTagInformation> uniTagList = subInfo.uniTagList(); |
| 625 | if (uniTagList == null) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 626 | log.warn("Uni tag list is not found for the subscriber {} on {}", subInfo.id(), portName); |
| 627 | return null; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 628 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 629 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 630 | UniTagInformation service = null; |
| 631 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 632 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 633 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 634 | service = tagInfo; |
| 635 | break; |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 636 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 637 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 638 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 639 | if (service == null) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 640 | log.warn("SADIS doesn't include the service with ponCtag {} ponStag {} and tpId {} on {}", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 641 | innerVlan, outerVlan, tpId, portName); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 642 | return null; |
| 643 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 644 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 645 | return service; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 646 | } |
| 647 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 648 | protected void bindSadisService(SadisService service) { |
| 649 | sadisService = service; |
| 650 | subsService = sadisService.getSubscriberInfoService(); |
| 651 | |
| 652 | log.info("Sadis-service binds to onos."); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 653 | } |
| 654 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 655 | protected void unbindSadisService(SadisService service) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 656 | deviceListener = null; |
| 657 | sadisService = null; |
| 658 | subsService = null; |
| 659 | log.info("Sadis-service unbinds from onos."); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 662 | protected void addSubscriberToQueue(DiscoveredSubscriber sub) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 663 | try { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 664 | ConnectPoint cp = new ConnectPoint(sub.device.id(), sub.port.number()); |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 665 | |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 666 | try { |
| 667 | queueWriteLock.lock(); |
| 668 | eventsQueues.compute(cp, (subcp, queue) -> { |
| 669 | queue = queue == null ? new LinkedBlockingQueue<>() : queue; |
| 670 | log.info("Adding subscriber {} to queue: {} with existing {}", |
| 671 | sub, portWithName(sub.port), queue); |
| 672 | queue.add(sub); |
| 673 | return queue; |
| 674 | }); |
| 675 | } catch (UnsupportedOperationException | ClassCastException | |
| 676 | NullPointerException | IllegalArgumentException e) { |
| 677 | log.error("Cannot add subscriber {} to queue: {}", portWithName(sub.port), e.getMessage()); |
| 678 | } finally { |
| 679 | queueWriteLock.unlock(); |
| 680 | } |
| 681 | } catch (Exception e) { |
| 682 | log.error("Can't add {} to queue", sub, e); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 683 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 684 | } |
| 685 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 686 | protected void removeSubscriberFromQueue(DiscoveredSubscriber sub) { |
| 687 | ConnectPoint cp = new ConnectPoint(sub.device.id(), sub.port.number()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 688 | try { |
| 689 | queueWriteLock.lock(); |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 690 | eventsQueues.compute(cp, (subcp, queue) -> { |
| 691 | if (log.isTraceEnabled()) { |
| 692 | log.trace("Removing subscriber {} from queue : {} " + |
| 693 | "with existing {}", sub, |
| 694 | portWithName(sub.port), queue); |
| 695 | } |
| 696 | if (queue == null) { |
| 697 | log.warn("Cannot find queue for connectPoint {}", cp); |
| 698 | return queue; |
| 699 | } |
| 700 | boolean removed = queue.remove(sub); |
| 701 | if (!removed) { |
| 702 | log.warn("Subscriber {} has not been removed from queue, " + |
| 703 | "is it still there? {}", sub, queue); |
| 704 | return queue; |
| 705 | } else { |
| 706 | log.debug("Subscriber {} has been removed from the queue {}", |
| 707 | sub, queue); |
| 708 | } |
| 709 | |
| 710 | return queue; |
| 711 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 712 | } catch (UnsupportedOperationException | ClassCastException | |
| 713 | NullPointerException | IllegalArgumentException e) { |
| 714 | log.error("Cannot remove subscriber {} from queue: {}", sub, e.getMessage()); |
| 715 | } finally { |
| 716 | queueWriteLock.unlock(); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 720 | protected class OltDeviceListener |
| 721 | implements DeviceListener { |
| 722 | |
| 723 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 724 | protected ExecutorService eventExecutor; |
| 725 | |
| 726 | /** |
| 727 | * Builds the listener with all the proper services and information needed. |
| 728 | */ |
| 729 | public OltDeviceListener() { |
| 730 | this.eventExecutor = Executors.newFixedThreadPool(flowProcessingThreads, |
| 731 | groupedThreads("onos/olt-device-listener-event", "event-%d", log)); |
| 732 | } |
| 733 | |
| 734 | public void deactivate() { |
| 735 | this.eventExecutor.shutdown(); |
| 736 | } |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 737 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 738 | @Override |
| 739 | public void event(DeviceEvent event) { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 740 | if (log.isTraceEnabled()) { |
| 741 | log.trace("OltListener receives event {} for: {}/{}", event.type(), event.subject().id(), |
| 742 | event.port() != null ? event.port().number() : null); |
| 743 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 744 | eventExecutor.execute(() -> { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 745 | if (log.isTraceEnabled()) { |
| 746 | log.trace("OltListener Executor receives event {} for: {}/{}", |
| 747 | event.type(), event.subject().id(), |
| 748 | event.port() != null ? event.port().number() : null); |
| 749 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 750 | boolean isOlt = oltDeviceService.isOlt(event.subject()); |
| 751 | DeviceId deviceId = event.subject().id(); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 752 | switch (event.type()) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 753 | case PORT_STATS_UPDATED: |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 754 | case DEVICE_ADDED: |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 755 | return; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 756 | case PORT_ADDED: |
| 757 | case PORT_UPDATED: |
| 758 | case PORT_REMOVED: |
| 759 | if (!isOlt) { |
| 760 | log.trace("Ignoring event {}, this is not an OLT device", deviceId); |
| 761 | return; |
| 762 | } |
| 763 | if (!oltDeviceService.isLocalLeader(deviceId)) { |
| 764 | log.trace("Device {} is not local to this node", deviceId); |
| 765 | return; |
| 766 | } |
| 767 | // port added, updated and removed are treated in the same way as we only care whether the port |
| 768 | // is enabled or not |
| 769 | handleOltPort(event.type(), event.subject(), event.port()); |
| 770 | return; |
| 771 | case DEVICE_AVAILABILITY_CHANGED: |
| 772 | if (!isOlt) { |
| 773 | log.trace("Ignoring event {}, this is not an OLT device", deviceId); |
| 774 | return; |
| 775 | } |
| 776 | if (deviceService.isAvailable(deviceId)) { |
| 777 | if (!oltDeviceService.isLocalLeader(deviceId)) { |
| 778 | if (log.isTraceEnabled()) { |
| 779 | log.trace("Device {} is not local to this node, not handling available device", |
| 780 | deviceId); |
| 781 | } |
| 782 | } else { |
| 783 | log.info("Handling available device: {}", deviceId); |
| 784 | handleExistingPorts(); |
| 785 | } |
| 786 | } else if (!deviceService.isAvailable(deviceId) && deviceService.getPorts(deviceId).isEmpty()) { |
| 787 | // NOTE that upon disconnection there is no mastership on the device, |
| 788 | // and we should anyway clear the local cache of the flows/meters across instances. |
| 789 | // We're only clearing the device if there are no available ports, |
| 790 | // otherwise we assume it's a temporary disconnection |
| 791 | log.info("Device {} availability changed to false and ports are empty, " + |
| 792 | "purging meters and flows", deviceId); |
| 793 | //NOTE all the instances will call these methods |
| 794 | oltFlowService.purgeDeviceFlows(deviceId); |
| 795 | oltMeterService.purgeDeviceMeters(deviceId); |
| 796 | clearQueueForDevice(deviceId); |
| 797 | } else { |
| 798 | log.info("Device {} availability changed to false, but ports are still available, " + |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 799 | "assuming temporary disconnection.", |
| 800 | deviceId); |
| 801 | if (log.isTraceEnabled()) { |
| 802 | log.trace("Available ports: {}", deviceService.getPorts(deviceId)); |
| 803 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 804 | } |
| 805 | return; |
| 806 | case DEVICE_REMOVED: |
| 807 | if (!isOlt) { |
| 808 | log.trace("Ignoring event {}, this is not an OLT device", deviceId); |
| 809 | return; |
| 810 | } |
| 811 | log.info("Device {} Removed, purging meters and flows", deviceId); |
| 812 | oltFlowService.purgeDeviceFlows(deviceId); |
| 813 | oltMeterService.purgeDeviceMeters(deviceId); |
| 814 | clearQueueForDevice(deviceId); |
| 815 | return; |
| 816 | default: |
| 817 | if (log.isTraceEnabled()) { |
| 818 | log.trace("Not handling event: {}, ", event); |
| 819 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 820 | } |
| 821 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 822 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 823 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 824 | protected void clearQueueForDevice(DeviceId devId) { |
| 825 | try { |
| 826 | queueWriteLock.lock(); |
| 827 | Iterator<Map.Entry<ConnectPoint, LinkedBlockingQueue<DiscoveredSubscriber>>> iter = |
| 828 | eventsQueues.entrySet().iterator(); |
| 829 | while (iter.hasNext()) { |
| 830 | Map.Entry<ConnectPoint, LinkedBlockingQueue<DiscoveredSubscriber>> entry = iter.next(); |
| 831 | if (entry.getKey().deviceId().equals(devId)) { |
| 832 | eventsQueues.remove(entry.getKey()); |
| 833 | } |
| 834 | } |
| 835 | } finally { |
| 836 | queueWriteLock.unlock(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 837 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 840 | protected void handleOltPort(DeviceEvent.Type type, Device device, Port port) { |
| 841 | log.info("OltDeviceListener receives event {} for port {} with status {} on device {}", type, |
| 842 | portWithName(port), port.isEnabled() ? "ENABLED" : "DISABLED", device.id()); |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 843 | boolean isNni = oltDeviceService.isNniPort(device, port.number()); |
| 844 | |
| 845 | if (!isNni && type == DeviceEvent.Type.PORT_ADDED) { |
| 846 | log.debug("Ignoring PORT_ADD on UNI port {}", portWithName(port)); |
| 847 | return; |
| 848 | } |
| 849 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 850 | if (port.isEnabled()) { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 851 | if (isNni) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 852 | OltFlowService.FlowOperation action = OltFlowService.FlowOperation.ADD; |
Matteo Scandolo | 1f8de33 | 2021-12-06 12:18:24 -0800 | [diff] [blame] | 853 | // NOTE the NNI is only disabled if the OLT shuts down (reboot or failure). |
| 854 | // In that case the flows are purged anyway, so there's no need to deal with them, |
| 855 | // it would actually be counter-productive as the openflow connection is severed and they won't |
| 856 | // be correctly processed |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 857 | if (type == DeviceEvent.Type.PORT_REMOVED) { |
Matteo Scandolo | 1f8de33 | 2021-12-06 12:18:24 -0800 | [diff] [blame] | 858 | log.debug("NNI port went down, " + |
| 859 | "ignoring event as flows will be removed in the generic device cleanup"); |
| 860 | return; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 861 | } |
| 862 | oltFlowService.handleNniFlows(device, port, action); |
| 863 | } else { |
| 864 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, device.id(), port)); |
| 865 | // NOTE if the subscriber was previously provisioned, |
| 866 | // then add it back to the queue to be re-provisioned |
| 867 | boolean provisionSubscriber = oltFlowService. |
| 868 | isSubscriberServiceProvisioned(new AccessDevicePort(port)); |
| 869 | SubscriberAndDeviceInformation si = subsService.get(getPortName(port)); |
| 870 | if (si == null) { |
| 871 | //NOTE this should not happen given that the subscriber was provisioned before |
| 872 | log.error("Subscriber information not found in sadis for port {}", |
| 873 | portWithName(port)); |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | DiscoveredSubscriber.Status status = DiscoveredSubscriber.Status.ADDED; |
| 878 | if (type == DeviceEvent.Type.PORT_REMOVED) { |
| 879 | status = DiscoveredSubscriber.Status.REMOVED; |
| 880 | } |
| 881 | |
| 882 | DiscoveredSubscriber sub = |
| 883 | new DiscoveredSubscriber(device, port, |
| 884 | status, provisionSubscriber, si); |
| 885 | addSubscriberToQueue(sub); |
| 886 | } |
| 887 | } else { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 888 | if (isNni) { |
Matteo Scandolo | b6981dc | 2021-12-02 16:31:44 -0800 | [diff] [blame] | 889 | // NOTE the NNI is only disabled if the OLT shuts down (reboot or failure). |
| 890 | // In that case the flows are purged anyway, so there's no need to deal with them, |
| 891 | // it would actually be counter-productive as the openflow connection is severed and they won't |
| 892 | // be correctly processed |
| 893 | log.debug("NNI port went down, " + |
| 894 | "ignoring event as flows will be removed in the generic device cleanup"); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 895 | } else { |
| 896 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, device.id(), port)); |
| 897 | // NOTE we are assuming that if a subscriber has default eapol |
| 898 | // it does not have subscriber flows |
| 899 | if (oltFlowService.hasDefaultEapol(port)) { |
| 900 | SubscriberAndDeviceInformation si = subsService.get(getPortName(port)); |
| 901 | if (si == null) { |
| 902 | //NOTE this should not happen given that the subscriber was provisioned before |
| 903 | log.error("Subscriber information not found in sadis for port {}", |
| 904 | portWithName(port)); |
| 905 | return; |
| 906 | } |
| 907 | DiscoveredSubscriber sub = |
| 908 | new DiscoveredSubscriber(device, port, |
| 909 | DiscoveredSubscriber.Status.REMOVED, false, si); |
| 910 | |
| 911 | addSubscriberToQueue(sub); |
| 912 | |
| 913 | } else if (oltFlowService.isSubscriberServiceProvisioned(new AccessDevicePort(port))) { |
| 914 | SubscriberAndDeviceInformation si = subsService.get(getPortName(port)); |
| 915 | if (si == null) { |
| 916 | //NOTE this should not happen given that the subscriber was provisioned before |
| 917 | log.error("Subscriber information not found in sadis for port {}", |
| 918 | portWithName(port)); |
| 919 | return; |
| 920 | } |
| 921 | DiscoveredSubscriber sub = |
| 922 | new DiscoveredSubscriber(device, port, |
| 923 | DiscoveredSubscriber.Status.REMOVED, true, si); |
| 924 | addSubscriberToQueue(sub); |
| 925 | } |
| 926 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 927 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 928 | } |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 929 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 930 | /** |
| 931 | * This method is invoked on app activation in order to deal |
| 932 | * with devices and ports that are already existing in the system |
| 933 | * and thus won't trigger an event. |
| 934 | * It is also needed on instance reboot and device reconnect |
| 935 | */ |
| 936 | protected void handleExistingPorts() { |
| 937 | Iterable<DeviceId> devices = getConnectedOlts(); |
| 938 | for (DeviceId deviceId : devices) { |
| 939 | log.info("Handling existing OLT Ports for device {}", deviceId); |
| 940 | if (oltDeviceService.isLocalLeader(deviceId)) { |
| 941 | List<Port> ports = deviceService.getPorts(deviceId); |
| 942 | for (Port p : ports) { |
| 943 | if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) { |
| 944 | continue; |
| 945 | } |
| 946 | Device device = deviceService.getDevice(deviceId); |
| 947 | deviceListener.handleOltPort(DeviceEvent.Type.PORT_UPDATED, device, p); |
| 948 | } |
| 949 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame^] | 953 | |
| 954 | protected final class ThreadPoolQueue extends ArrayBlockingQueue<Runnable> { |
| 955 | |
| 956 | public ThreadPoolQueue(int capacity) { |
| 957 | super(capacity); |
| 958 | } |
| 959 | |
| 960 | @Override |
| 961 | public boolean offer(Runnable runnable) { |
| 962 | if (runnable == null) { |
| 963 | return false; |
| 964 | } |
| 965 | try { |
| 966 | put(runnable); |
| 967 | } catch (InterruptedException e1) { |
| 968 | Thread.currentThread().interrupt(); |
| 969 | return false; |
| 970 | } |
| 971 | return true; |
| 972 | } |
| 973 | |
| 974 | } |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 975 | } |