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