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