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