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