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