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())) { |
| 408 | isPending.set(true); |
| 409 | break; |
| 410 | } |
Saurav Das | 026650f | 2020-09-21 18:56:35 -0700 | [diff] [blame] | 411 | } |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 412 | return infos; |
| 413 | }); |
Saurav Das | 026650f | 2020-09-21 18:56:35 -0700 | [diff] [blame] | 414 | |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 415 | return isPending.get(); |
Saurav Das | 026650f | 2020-09-21 18:56:35 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 418 | private class DeleteEapolInstallSub implements Runnable { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 419 | AccessDevicePort subscriberPort; |
| 420 | AccessDevicePort uplinkPort; |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 421 | SubscriberAndDeviceInformation sub; |
| 422 | private int attemptNumber; |
| 423 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 424 | DeleteEapolInstallSub(AccessDevicePort subscriberPort, AccessDevicePort uplinkPort, |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 425 | SubscriberAndDeviceInformation sub, |
| 426 | int attemptNumber) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 427 | this.subscriberPort = subscriberPort; |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 428 | this.uplinkPort = uplinkPort; |
| 429 | this.sub = sub; |
| 430 | this.attemptNumber = attemptNumber; |
| 431 | } |
| 432 | |
| 433 | @Override |
| 434 | public void run() { |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 435 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture<>(); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 436 | oltFlowService.processEapolFilteringObjectives(subscriberPort, |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 437 | defaultBpId, filterFuture, |
| 438 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 439 | false); |
| 440 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 441 | if (filterStatus == null) { |
| 442 | log.info("Default eapol flow deleted in attempt {} of {}" |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 443 | + "... provisioning subscriber flows on {}", |
| 444 | attemptNumber, eapolDeleteRetryMaxAttempts, subscriberPort); |
Matteo Scandolo | a4aaa97 | 2020-10-23 15:24:38 -0700 | [diff] [blame] | 445 | |
| 446 | // FIXME this is needed to prevent that default EAPOL flow removal and |
| 447 | // data plane flows install are received by the device at the same time |
| 448 | provisionExecutor.schedule( |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 449 | () -> provisionUniTagList(subscriberPort, uplinkPort, sub), |
Matteo Scandolo | a4aaa97 | 2020-10-23 15:24:38 -0700 | [diff] [blame] | 450 | provisionDelay, TimeUnit.MILLISECONDS); |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 451 | } else { |
| 452 | if (attemptNumber <= eapolDeleteRetryMaxAttempts) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 453 | log.warn("The filtering future failed {} for subscriber on {}" |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 454 | + "... retrying {} of {} attempts", |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 455 | filterStatus, subscriberPort, attemptNumber, eapolDeleteRetryMaxAttempts); |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 456 | retryExecutor.execute( |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 457 | new DeleteEapolInstallSub(subscriberPort, uplinkPort, sub, |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 458 | attemptNumber + 1)); |
| 459 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 460 | log.error("The filtering future failed {} for subscriber on {}" |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 461 | + "after {} attempts. Subscriber provisioning failed", |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 462 | filterStatus, subscriberPort, eapolDeleteRetryMaxAttempts); |
| 463 | sub.uniTagList().forEach(ut -> |
| 464 | failedSubs.put( |
| 465 | new ConnectPoint(subscriberPort.deviceId(), subscriberPort.number()), ut)); |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | }); |
| 469 | } |
| 470 | |
| 471 | } |
| 472 | |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 473 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 474 | public boolean removeSubscriber(ConnectPoint connectPoint) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 475 | Port subscriberPort = deviceService.getPort(connectPoint); |
| 476 | if (subscriberPort == null) { |
| 477 | log.error("Subscriber port not found at: {}", connectPoint); |
| 478 | return false; |
| 479 | } |
| 480 | return removeSubscriber(new AccessDevicePort(subscriberPort, AccessDevicePort.Type.UNI)); |
| 481 | } |
| 482 | |
| 483 | private boolean removeSubscriber(AccessDevicePort subscriberPort) { |
| 484 | log.info("Call to un-provision subscriber at {}", subscriberPort); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 485 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 486 | // Get the subscriber connected to this port from the local cache |
| 487 | // 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^] | 488 | DeviceId deviceId = subscriberPort.deviceId(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 489 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 490 | ConnectPoint connectPoint = new ConnectPoint(deviceId, subscriberPort.number()); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 491 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(connectPoint).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 492 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 493 | log.warn("Subscriber on connectionPoint {} was not previously programmed, " + |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 494 | "no need to remove it", connectPoint); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 495 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 498 | // Get the uplink port |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 499 | AccessDevicePort uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 500 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 501 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 502 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 505 | for (UniTagInformation uniTag : uniTagInformationSet) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 506 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 507 | if (multicastServiceName.equals(uniTag.getServiceName())) { |
| 508 | continue; |
| 509 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 510 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 511 | unprovisionVlans(uplinkPort, subscriberPort, uniTag); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 512 | |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 513 | // remove eapol with subscriber bandwidth profile |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 514 | oltFlowService.processEapolFilteringObjectives(subscriberPort, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 515 | uniTag.getUpstreamBandwidthProfile(), |
| 516 | null, uniTag.getPonCTag(), false); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 517 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 518 | if (subscriberPort.port() != null && subscriberPort.isEnabled()) { |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 519 | // reinstall eapol with default bandwidth profile |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 520 | oltFlowService.processEapolFilteringObjectives(subscriberPort, defaultBpId, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 521 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 522 | } else { |
| 523 | log.debug("Port {} is no longer enabled or it's unavailable. Not " |
| 524 | + "reprogramming default eapol flow", connectPoint); |
| 525 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 526 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 527 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 530 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 531 | @Override |
| 532 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 533 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
| 534 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 535 | log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}, tpId {}", |
| 536 | subscriberId, sTag, cTag, tpId); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 537 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 538 | // 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^] | 539 | ConnectPoint cp = findSubscriberConnectPoint(subscriberId.toString()); |
| 540 | if (cp == null) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 541 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 542 | return false; |
| 543 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 544 | AccessDevicePort subscriberPort = new AccessDevicePort(deviceService.getPort(cp), AccessDevicePort.Type.UNI); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 545 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 546 | if (!sTag.isPresent() && !cTag.isPresent()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 547 | return provisionSubscriber(cp); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 548 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 549 | AccessDevicePort uplinkPort = getUplinkPort(deviceService.getDevice(cp.deviceId())); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 550 | if (uplinkPort == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 551 | log.warn(NO_UPLINK_PORT, cp.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 552 | return false; |
| 553 | } |
| 554 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 555 | //delete Eapol authentication flow with default bandwidth |
| 556 | //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] | 557 | //install subscriber flows |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 558 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture<>(); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 559 | oltFlowService.processEapolFilteringObjectives(subscriberPort, defaultBpId, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 560 | filterFuture, VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 561 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 562 | if (filterStatus == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 563 | provisionUniTagInformation(uplinkPort, subscriberPort, cTag.get(), sTag.get(), tpId.get()); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 564 | } |
| 565 | }); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 566 | return true; |
| 567 | } else { |
| 568 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 569 | return false; |
| 570 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 571 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 572 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 573 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 574 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, |
| 575 | Optional<VlanId> cTag, Optional<Integer> tpId) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 576 | // 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^] | 577 | ConnectPoint cp = findSubscriberConnectPoint(subscriberId.toString()); |
| 578 | if (cp == null) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 579 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 580 | return false; |
| 581 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 582 | AccessDevicePort subscriberPort = new AccessDevicePort(deviceService.getPort(cp), AccessDevicePort.Type.UNI); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 583 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 584 | if (!sTag.isPresent() && !cTag.isPresent()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 585 | return removeSubscriber(cp); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 586 | } else if (sTag.isPresent() && cTag.isPresent() && tpId.isPresent()) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 587 | // Get the uplink port |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 588 | AccessDevicePort uplinkPort = getUplinkPort(deviceService.getDevice(cp.deviceId())); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 589 | if (uplinkPort == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 590 | log.warn(NO_UPLINK_PORT, cp.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 594 | Optional<UniTagInformation> tagInfo = getUniTagInformation(subscriberPort, cTag.get(), |
| 595 | sTag.get(), tpId.get()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 596 | if (!tagInfo.isPresent()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 597 | log.warn("UniTagInformation does not exist for {}, cTag {}, sTag {}, tpId {}", |
| 598 | subscriberPort, cTag, sTag, tpId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 599 | return false; |
| 600 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 601 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 602 | unprovisionVlans(uplinkPort, subscriberPort, tagInfo.get()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 603 | return true; |
| 604 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 605 | log.warn("Removing subscriber is not possible - please check the provided information" + |
| 606 | "for the subscriber: {}", subscriberId); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 607 | return false; |
| 608 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 612 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getProgSubs() { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 613 | return programmedSubs.stream() |
| 614 | .collect(collectingAndThen( |
| 615 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 616 | ImmutableMap::copyOf)); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | @Override |
Saurav Das | 2d3777a | 2020-08-07 18:48:51 -0700 | [diff] [blame] | 620 | public ImmutableMap<ConnectPoint, Set<UniTagInformation>> getFailedSubs() { |
| 621 | return failedSubs.stream() |
| 622 | .collect(collectingAndThen( |
| 623 | groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())), |
| 624 | ImmutableMap::copyOf)); |
| 625 | } |
| 626 | |
| 627 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 628 | public List<DeviceId> fetchOlts() { |
| 629 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 630 | List<DeviceId> olts = new ArrayList<>(); |
| 631 | Iterable<Device> devices = deviceService.getDevices(); |
| 632 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 633 | if (getOltInfo(d) != null) { |
| 634 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 635 | olts.add(d.id()); |
| 636 | } |
| 637 | } |
| 638 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 641 | /** |
| 642 | * Finds the connect point to which a subscriber is connected. |
| 643 | * |
| 644 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 645 | * @return Subscribers ConnectPoint if found else null |
| 646 | */ |
| 647 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 648 | |
| 649 | Iterable<Device> devices = deviceService.getDevices(); |
| 650 | for (Device d : devices) { |
| 651 | for (Port p : deviceService.getPorts(d.id())) { |
| 652 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 653 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 654 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 655 | return new ConnectPoint(d.id(), p.number()); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | return null; |
| 660 | } |
| 661 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 662 | /** |
| 663 | * Gets the context of the bandwidth profile information for the given parameter. |
| 664 | * |
| 665 | * @param bandwidthProfile the bandwidth profile id |
| 666 | * @return the context of the bandwidth profile information |
| 667 | */ |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 668 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 669 | if (bpService == null) { |
| 670 | log.warn(SADIS_NOT_RUNNING); |
| 671 | return null; |
| 672 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 673 | if (bandwidthProfile == null) { |
| 674 | return null; |
| 675 | } |
| 676 | return bpService.get(bandwidthProfile); |
| 677 | } |
| 678 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 679 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 680 | * Removes subscriber vlan flows. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 681 | * |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 682 | * @param uplink uplink port of the OLT |
| 683 | * @param subscriberPort uni port |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 684 | * @param uniTag uni tag information |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 685 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 686 | private void unprovisionVlans(AccessDevicePort uplink, AccessDevicePort subscriberPort, UniTagInformation uniTag) { |
| 687 | log.info("Unprovisioning vlans for {} at {}", uniTag, subscriberPort); |
| 688 | DeviceId deviceId = subscriberPort.deviceId(); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 689 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 690 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>(); |
| 691 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>(); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 692 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 693 | VlanId deviceVlan = uniTag.getPonSTag(); |
| 694 | VlanId subscriberVlan = uniTag.getPonCTag(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 695 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 696 | MeterId upstreamMeterId = oltMeterService |
| 697 | .getMeterIdFromBpMapping(deviceId, uniTag.getUpstreamBandwidthProfile()); |
| 698 | MeterId downstreamMeterId = oltMeterService |
| 699 | .getMeterIdFromBpMapping(deviceId, uniTag.getDownstreamBandwidthProfile()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 700 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 701 | Optional<SubscriberFlowInfo> waitingMacSubFlowInfo = |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 702 | getAndRemoveWaitingMacSubFlowInfoForCTag(new ConnectPoint(deviceId, subscriberPort.number()), |
| 703 | subscriberVlan); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 704 | if (waitingMacSubFlowInfo.isPresent()) { |
| 705 | // only dhcp objectives applied previously, so only dhcp uninstallation objective will be processed |
| 706 | log.debug("Waiting MAC service removed and dhcp uninstallation objective will be processed. " + |
| 707 | "waitingMacSubFlowInfo:{}", waitingMacSubFlowInfo.get()); |
| 708 | CompletableFuture<ObjectiveError> dhcpFuture = new CompletableFuture<>(); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 709 | oltFlowService.processDhcpFilteringObjectives(subscriberPort, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 710 | upstreamMeterId, uniTag, false, true, Optional.of(dhcpFuture)); |
| 711 | dhcpFuture.thenAcceptAsync(dhcpStatus -> { |
| 712 | AccessDeviceEvent.Type type; |
| 713 | if (dhcpStatus == null) { |
| 714 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED; |
| 715 | log.debug("Dhcp uninstallation objective was processed successfully for cTag {}, sTag {}, " + |
| 716 | "tpId {} and Device/Port:{}", uniTag.getPonCTag(), uniTag.getPonSTag(), |
| 717 | uniTag.getTechnologyProfileId(), subscriberPort); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 718 | updateProgrammedSubscriber(subscriberPort, uniTag, false); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 719 | } else { |
| 720 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
| 721 | log.error("Dhcp uninstallation objective was failed for cTag {}, sTag {}, " + |
| 722 | "tpId {} and Device/Port:{} :{}", uniTag.getPonCTag(), uniTag.getPonSTag(), |
| 723 | uniTag.getTechnologyProfileId(), subscriberPort, dhcpStatus); |
| 724 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 725 | post(new AccessDeviceEvent(type, deviceId, subscriberPort.port(), |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 726 | deviceVlan, subscriberVlan, uniTag.getTechnologyProfileId())); |
| 727 | }); |
| 728 | return; |
| 729 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 730 | 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] | 731 | } |
| 732 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 733 | ForwardingObjective.Builder upFwd = |
| 734 | oltFlowService.createUpBuilder(uplink, subscriberPort, upstreamMeterId, uniTag); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 735 | |
| 736 | Optional<MacAddress> macAddress = getMacAddress(deviceId, subscriberPort, uniTag); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 737 | ForwardingObjective.Builder downFwd = |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 738 | oltFlowService.createDownBuilder(uplink, subscriberPort, downstreamMeterId, uniTag, macAddress); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 739 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 740 | oltFlowService.processIgmpFilteringObjectives(subscriberPort, upstreamMeterId, uniTag, false, true); |
| 741 | oltFlowService.processDhcpFilteringObjectives(subscriberPort, |
| 742 | upstreamMeterId, uniTag, false, true, Optional.empty()); |
| 743 | oltFlowService.processPPPoEDFilteringObjectives(subscriberPort, upstreamMeterId, uniTag, false, true); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 744 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 745 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 746 | @Override |
| 747 | public void onSuccess(Objective objective) { |
| 748 | upFuture.complete(null); |
| 749 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 750 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 751 | @Override |
| 752 | public void onError(Objective objective, ObjectiveError error) { |
| 753 | upFuture.complete(error); |
| 754 | } |
| 755 | })); |
| 756 | |
| 757 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 758 | @Override |
| 759 | public void onSuccess(Objective objective) { |
| 760 | downFuture.complete(null); |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public void onError(Objective objective, ObjectiveError error) { |
| 765 | downFuture.complete(error); |
| 766 | } |
| 767 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 768 | |
| 769 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 770 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTERED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 771 | if (upStatus == null && downStatus == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 772 | log.debug("Uni tag information is unregistered successfully for cTag {}, sTag {}, tpId {} on {}", |
| 773 | uniTag.getPonCTag(), uniTag.getPonSTag(), uniTag.getTechnologyProfileId(), subscriberPort); |
| 774 | updateProgrammedSubscriber(subscriberPort, uniTag, false); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 775 | } else if (downStatus != null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 776 | log.error("Subscriber with vlan {} on {} failed downstream uninstallation: {}", |
| 777 | subscriberVlan, subscriberPort, downStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 778 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 779 | } else if (upStatus != null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 780 | log.error("Subscriber with vlan {} on {} failed upstream uninstallation: {}", |
| 781 | subscriberVlan, subscriberPort, upStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 782 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_UNREGISTRATION_FAILED; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 783 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 784 | post(new AccessDeviceEvent(type, deviceId, subscriberPort.port(), deviceVlan, subscriberVlan, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 785 | uniTag.getTechnologyProfileId())); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 786 | }, oltInstallers); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 789 | private Optional<SubscriberFlowInfo> getAndRemoveWaitingMacSubFlowInfoForCTag(ConnectPoint cp, VlanId cTag) { |
| 790 | SubscriberFlowInfo returnSubFlowInfo = null; |
| 791 | Collection<? extends SubscriberFlowInfo> subFlowInfoSet = waitingMacSubscribers.get(cp).value(); |
| 792 | for (SubscriberFlowInfo subFlowInfo : subFlowInfoSet) { |
| 793 | if (subFlowInfo.getTagInfo().getPonCTag().equals(cTag)) { |
| 794 | returnSubFlowInfo = subFlowInfo; |
| 795 | break; |
| 796 | } |
| 797 | } |
| 798 | if (returnSubFlowInfo != null) { |
| 799 | waitingMacSubscribers.remove(cp, returnSubFlowInfo); |
| 800 | return Optional.of(returnSubFlowInfo); |
| 801 | } |
| 802 | return Optional.empty(); |
| 803 | } |
| 804 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 805 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 806 | * 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] | 807 | * |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 808 | * @param subPort the connection point of the subscriber |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 809 | * @param uplinkPort uplink port of the OLT (the nni port) |
| 810 | * @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] | 811 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 812 | private void provisionUniTagList(AccessDevicePort subPort, AccessDevicePort uplinkPort, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 813 | SubscriberAndDeviceInformation sub) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 814 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 815 | log.debug("Provisioning vlans for subscriber on {}", subPort); |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 816 | if (log.isTraceEnabled()) { |
| 817 | log.trace("Subscriber informations {}", sub); |
| 818 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 819 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 820 | if (sub.uniTagList() == null || sub.uniTagList().isEmpty()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 821 | 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] | 822 | return; |
| 823 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 824 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 825 | for (UniTagInformation uniTag : sub.uniTagList()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 826 | handleSubscriberFlows(uplinkPort, subPort, uniTag); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 827 | } |
| 828 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 829 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 830 | /** |
| 831 | * Finds the uni tag information and provisions the found information. |
| 832 | * If the uni tag information is not found, returns |
| 833 | * |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 834 | * @param uplinkPort the nni port |
| 835 | * @param subscriberPort the uni port |
| 836 | * @param innerVlan the pon c tag |
| 837 | * @param outerVlan the pon s tag |
| 838 | * @param tpId the technology profile id |
| 839 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 840 | private void provisionUniTagInformation(AccessDevicePort uplinkPort, |
| 841 | AccessDevicePort subscriberPort, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 842 | VlanId innerVlan, |
| 843 | VlanId outerVlan, |
| 844 | Integer tpId) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 845 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 846 | Optional<UniTagInformation> gotTagInformation = getUniTagInformation(subscriberPort, innerVlan, |
| 847 | outerVlan, tpId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 848 | if (!gotTagInformation.isPresent()) { |
| 849 | return; |
| 850 | } |
| 851 | UniTagInformation tagInformation = gotTagInformation.get(); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 852 | handleSubscriberFlows(uplinkPort, subscriberPort, tagInformation); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 853 | } |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 854 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 855 | private void updateProgrammedSubscriber(AccessDevicePort port, UniTagInformation tagInformation, boolean add) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 856 | if (add) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 857 | programmedSubs.put(new ConnectPoint(port.deviceId(), port.number()), tagInformation); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 858 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 859 | programmedSubs.remove(new ConnectPoint(port.deviceId(), port.number()), tagInformation); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 860 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 863 | /** |
| 864 | * Installs a uni tag information flow. |
| 865 | * |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 866 | * @param uplinkPort the nni port |
| 867 | * @param subscriberPort the uni port |
| 868 | * @param tagInfo the uni tag information |
| 869 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 870 | private void handleSubscriberFlows(AccessDevicePort uplinkPort, AccessDevicePort subscriberPort, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 871 | UniTagInformation tagInfo) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 872 | log.debug("Provisioning vlan-based flows for the uniTagInformation {} on {}", tagInfo, subscriberPort); |
| 873 | DeviceId deviceId = subscriberPort.deviceId(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 874 | |
| 875 | if (multicastServiceName.equals(tagInfo.getServiceName())) { |
| 876 | // IGMP flows are taken care of along with VOD service |
| 877 | // Please note that for each service, Subscriber Registered event will be sent |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 878 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED, deviceId, |
| 879 | subscriberPort.port(), tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 880 | tagInfo.getTechnologyProfileId())); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 881 | return; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 884 | BandwidthProfileInformation upstreamBpInfo = |
| 885 | getBandwidthProfileInformation(tagInfo.getUpstreamBandwidthProfile()); |
| 886 | BandwidthProfileInformation downstreamBpInfo = |
| 887 | getBandwidthProfileInformation(tagInfo.getDownstreamBandwidthProfile()); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 888 | if (upstreamBpInfo == null) { |
| 889 | 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^] | 890 | + "ctag {} stag {} tpId {} on {}", |
| 891 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), tagInfo.getTechnologyProfileId(), subscriberPort); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 892 | return; |
| 893 | } |
| 894 | if (downstreamBpInfo == null) { |
| 895 | 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^] | 896 | + "ctag {} stag {} tpId {} on {}", |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 897 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 898 | tagInfo.getTechnologyProfileId(), subscriberPort); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 899 | return; |
| 900 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 901 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 902 | // check for meterIds for the upstream and downstream bandwidth profiles |
| 903 | MeterId upMeterId = oltMeterService |
| 904 | .getMeterIdFromBpMapping(deviceId, upstreamBpInfo.id()); |
| 905 | MeterId downMeterId = oltMeterService |
| 906 | .getMeterIdFromBpMapping(deviceId, downstreamBpInfo.id()); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 907 | SubscriberFlowInfo fi = new SubscriberFlowInfo(uplinkPort, subscriberPort, |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 908 | tagInfo, downMeterId, upMeterId, |
| 909 | downstreamBpInfo.id(), upstreamBpInfo.id()); |
| 910 | |
| 911 | if (upMeterId != null && downMeterId != null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 912 | log.debug("Meters are existing for upstream {} and downstream {} on {}", |
| 913 | upstreamBpInfo.id(), downstreamBpInfo.id(), subscriberPort); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 914 | handleSubFlowsWithMeters(fi); |
| 915 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 916 | log.debug("Adding {} on {} to pending subs", fi, subscriberPort); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 917 | // one or both meters are not ready. It's possible they are in the process of being |
| 918 | // created for other subscribers that share the same bandwidth profile. |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 919 | pendingSubscribersForDevice.compute(deviceId, (id, queue) -> { |
| 920 | if (queue == null) { |
| 921 | queue = new LinkedBlockingQueue<>(); |
| 922 | } |
| 923 | queue.add(fi); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 924 | log.info("Added {} to pending subscribers on {}", fi, subscriberPort); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 925 | return queue; |
| 926 | }); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 927 | |
| 928 | // queue up the meters to be created |
| 929 | if (upMeterId == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 930 | log.debug("Missing meter for upstream {} on {}", upstreamBpInfo.id(), subscriberPort); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 931 | checkAndCreateDevMeter(deviceId, upstreamBpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 932 | } |
| 933 | if (downMeterId == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 934 | log.debug("Missing meter for downstream {} on {}", downstreamBpInfo.id(), subscriberPort); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 935 | checkAndCreateDevMeter(deviceId, downstreamBpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | } |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 939 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 940 | private void checkAndCreateDevMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
Andrea Campanella | d1e2664 | 2020-10-23 12:08:32 +0200 | [diff] [blame] | 941 | //If false the meter is already being installed, skipping installation |
| 942 | if (!oltMeterService.checkAndAddPendingMeter(deviceId, bwpInfo)) { |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 943 | return; |
| 944 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 945 | createMeter(deviceId, bwpInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 948 | private void createMeter(DeviceId deviceId, BandwidthProfileInformation bwpInfo) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 949 | log.debug("Creating Meter with {} on {}", bwpInfo, deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 950 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 951 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 952 | MeterId meterId = oltMeterService.createMeter(deviceId, bwpInfo, |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 953 | meterFuture); |
| 954 | |
| 955 | meterFuture.thenAcceptAsync(result -> { |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 956 | BlockingQueue<SubscriberFlowInfo> queue = pendingSubscribersForDevice.get(deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 957 | // iterate through the subscribers on hold |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 958 | if (queue != null) { |
| 959 | while (true) { |
| 960 | //TODO this might return the reference and not the actual object so |
| 961 | // it can be actually swapped underneath us. |
| 962 | SubscriberFlowInfo fi = queue.peek(); |
| 963 | if (fi == null) { |
| 964 | log.debug("No more subscribers pending on {}", deviceId); |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 965 | pendingSubscribersForDevice.replace(deviceId, queue); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 966 | break; |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 967 | } |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 968 | if (result == null) { |
| 969 | // meter install sent to device |
| 970 | log.debug("Meter {} installed for bw {} on {}", meterId, bwpInfo, deviceId); |
| 971 | |
| 972 | MeterId upMeterId = oltMeterService |
| 973 | .getMeterIdFromBpMapping(deviceId, fi.getUpBpInfo()); |
| 974 | MeterId downMeterId = oltMeterService |
| 975 | .getMeterIdFromBpMapping(deviceId, fi.getDownBpInfo()); |
| 976 | if (upMeterId != null && downMeterId != null) { |
| 977 | log.debug("Provisioning subscriber after meter {} " + |
| 978 | "installation and both meters are present " + |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 979 | "upstream {} and downstream {} on {}", |
| 980 | meterId, upMeterId, downMeterId, fi.getUniPort()); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 981 | // put in the meterIds because when fi was first |
| 982 | // created there may or may not have been a meterId |
| 983 | // depending on whether the meter was created or |
| 984 | // not at that time. |
| 985 | fi.setUpMeterId(upMeterId); |
| 986 | fi.setDownMeterId(downMeterId); |
| 987 | handleSubFlowsWithMeters(fi); |
| 988 | queue.remove(fi); |
| 989 | } |
| 990 | oltMeterService.removeFromPendingMeters(deviceId, bwpInfo); |
| 991 | } else { |
| 992 | // meter install failed |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 993 | log.error("Addition of subscriber {} on {} failed due to meter " + |
| 994 | "{} with result {}", fi, fi.getUniPort(), meterId, result); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 995 | queue.remove(fi); |
| 996 | oltMeterService.removeFromPendingMeters(deviceId, bwpInfo); |
| 997 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 998 | } |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 999 | } else { |
| 1000 | log.info("No pending subscribers on {}", deviceId); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1001 | } |
| 1002 | }); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 1003 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1004 | } |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 1005 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1006 | /** |
| 1007 | * Add subscriber flows given meter information for both upstream and |
| 1008 | * downstream directions. |
| 1009 | * |
| 1010 | * @param subscriberFlowInfo relevant information for subscriber |
| 1011 | */ |
| 1012 | private void handleSubFlowsWithMeters(SubscriberFlowInfo subscriberFlowInfo) { |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1013 | log.debug("Provisioning subscriber flows based on {}", subscriberFlowInfo); |
| 1014 | UniTagInformation tagInfo = subscriberFlowInfo.getTagInfo(); |
| 1015 | if (tagInfo.getIsDhcpRequired()) { |
| 1016 | Optional<MacAddress> macAddress = |
| 1017 | getMacAddress(subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort(), tagInfo); |
| 1018 | if (subscriberFlowInfo.getTagInfo().getEnableMacLearning()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1019 | ConnectPoint cp = new ConnectPoint(subscriberFlowInfo.getDevId(), |
| 1020 | subscriberFlowInfo.getUniPort().number()); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1021 | if (macAddress.isPresent()) { |
| 1022 | log.debug("MAC Address {} obtained for {}", macAddress.get(), subscriberFlowInfo); |
| 1023 | } else { |
| 1024 | waitingMacSubscribers.put(cp, subscriberFlowInfo); |
| 1025 | log.debug("Adding sub to waiting mac map: {}", subscriberFlowInfo); |
| 1026 | } |
| 1027 | |
| 1028 | CompletableFuture<ObjectiveError> dhcpFuture = new CompletableFuture<>(); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1029 | oltFlowService.processDhcpFilteringObjectives(subscriberFlowInfo.getUniPort(), |
| 1030 | subscriberFlowInfo.getUpId(), tagInfo, true, true, Optional.of(dhcpFuture)); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1031 | dhcpFuture.thenAcceptAsync(dhcpStatus -> { |
| 1032 | if (dhcpStatus != null) { |
| 1033 | log.error("Dhcp Objective failed for {}: {}", subscriberFlowInfo, dhcpStatus); |
| 1034 | if (macAddress.isEmpty()) { |
| 1035 | waitingMacSubscribers.remove(cp, subscriberFlowInfo); |
| 1036 | } |
| 1037 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED, |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1038 | subscriberFlowInfo.getDevId(), subscriberFlowInfo.getUniPort().port(), |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1039 | tagInfo.getPonSTag(), tagInfo.getPonCTag(), tagInfo.getTechnologyProfileId())); |
| 1040 | } else { |
| 1041 | log.debug("Dhcp Objective success for: {}", subscriberFlowInfo); |
| 1042 | if (macAddress.isPresent()) { |
| 1043 | continueProvisioningSubs(subscriberFlowInfo, macAddress); |
| 1044 | } |
| 1045 | } |
| 1046 | }); |
| 1047 | } else { |
| 1048 | log.debug("Dynamic MAC Learning disabled, so will not learn for: {}", subscriberFlowInfo); |
| 1049 | // dhcp flows will handle after data plane flows |
| 1050 | continueProvisioningSubs(subscriberFlowInfo, macAddress); |
| 1051 | } |
| 1052 | } else { |
| 1053 | // dhcp not required for this service |
| 1054 | continueProvisioningSubs(subscriberFlowInfo, Optional.empty()); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | private void continueProvisioningSubs(SubscriberFlowInfo subscriberFlowInfo, Optional<MacAddress> macAddress) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1059 | AccessDevicePort uniPort = subscriberFlowInfo.getUniPort(); |
| 1060 | log.debug("Provisioning subscriber flows on {} based on {}", uniPort, subscriberFlowInfo); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1061 | UniTagInformation tagInfo = subscriberFlowInfo.getTagInfo(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1062 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture<>(); |
| 1063 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture<>(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1064 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1065 | ForwardingObjective.Builder upFwd = |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1066 | oltFlowService.createUpBuilder(subscriberFlowInfo.getNniPort(), uniPort, |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1067 | subscriberFlowInfo.getUpId(), subscriberFlowInfo.getTagInfo()); |
| 1068 | flowObjectiveService.forward(subscriberFlowInfo.getDevId(), upFwd.add(new ObjectiveContext() { |
| 1069 | @Override |
| 1070 | public void onSuccess(Objective objective) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1071 | log.debug("Upstream HSIA flow {} installed successfully on {}", subscriberFlowInfo, uniPort); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1072 | upFuture.complete(null); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1073 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1074 | |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1075 | @Override |
| 1076 | public void onError(Objective objective, ObjectiveError error) { |
| 1077 | upFuture.complete(error); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1078 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1079 | })); |
| 1080 | |
| 1081 | ForwardingObjective.Builder downFwd = |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1082 | oltFlowService.createDownBuilder(subscriberFlowInfo.getNniPort(), uniPort, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1083 | subscriberFlowInfo.getDownId(), subscriberFlowInfo.getTagInfo(), macAddress); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1084 | flowObjectiveService.forward(subscriberFlowInfo.getDevId(), downFwd.add(new ObjectiveContext() { |
| 1085 | @Override |
| 1086 | public void onSuccess(Objective objective) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1087 | log.debug("Downstream HSIA flow {} installed successfully on {}", subscriberFlowInfo, uniPort); |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1088 | downFuture.complete(null); |
| 1089 | } |
| 1090 | |
| 1091 | @Override |
| 1092 | public void onError(Objective objective, ObjectiveError error) { |
| 1093 | downFuture.complete(error); |
| 1094 | } |
| 1095 | })); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1096 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1097 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1098 | AccessDeviceEvent.Type type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTERED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1099 | if (downStatus != null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1100 | log.error("Flow with innervlan {} and outerVlan {} on {} failed downstream installation: {}", |
| 1101 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), uniPort, downStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1102 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1103 | } else if (upStatus != null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1104 | log.error("Flow with innervlan {} and outerVlan {} on {} failed upstream installation: {}", |
| 1105 | tagInfo.getPonCTag(), tagInfo.getPonSTag(), uniPort, upStatus); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1106 | type = AccessDeviceEvent.Type.SUBSCRIBER_UNI_TAG_REGISTRATION_FAILED; |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1107 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1108 | log.debug("Upstream and downstream data plane flows are installed successfully on {}", uniPort); |
| 1109 | oltFlowService.processEapolFilteringObjectives(uniPort, tagInfo.getUpstreamBandwidthProfile(), |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1110 | null, tagInfo.getPonCTag(), true); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1111 | |
| 1112 | |
| 1113 | if (!tagInfo.getEnableMacLearning()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1114 | oltFlowService.processDhcpFilteringObjectives(uniPort, subscriberFlowInfo.getUpId(), |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1115 | tagInfo, true, true, Optional.empty()); |
| 1116 | } |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1117 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1118 | oltFlowService.processIgmpFilteringObjectives(uniPort, subscriberFlowInfo.getUpId(), |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1119 | tagInfo, true, true); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1120 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1121 | oltFlowService.processPPPoEDFilteringObjectives(uniPort, subscriberFlowInfo.getUpId(), |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1122 | tagInfo, true, true); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1123 | updateProgrammedSubscriber(uniPort, tagInfo, true); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1124 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1125 | post(new AccessDeviceEvent(type, subscriberFlowInfo.getDevId(), uniPort.port(), |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1126 | tagInfo.getPonSTag(), tagInfo.getPonCTag(), |
| 1127 | tagInfo.getTechnologyProfileId())); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1128 | }, oltInstallers); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1129 | } |
| 1130 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1131 | /** |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1132 | * Gets mac address from tag info if present, else checks the host service. |
| 1133 | * |
| 1134 | * @param deviceId device ID |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1135 | * @param port uni port |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1136 | * @param tagInformation tag info |
| 1137 | * @return MAC Address of subscriber |
| 1138 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1139 | private Optional<MacAddress> getMacAddress(DeviceId deviceId, AccessDevicePort port, |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1140 | UniTagInformation tagInformation) { |
| 1141 | if (isMacAddressValid(tagInformation)) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1142 | log.debug("Got MAC Address {} from the uniTagInformation for {} and cTag {}", |
| 1143 | tagInformation.getConfiguredMacAddress(), port, tagInformation.getPonCTag()); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1144 | return Optional.of(MacAddress.valueOf(tagInformation.getConfiguredMacAddress())); |
| 1145 | } else if (tagInformation.getEnableMacLearning()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1146 | Optional<Host> optHost = hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())) |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1147 | .stream().filter(host -> host.vlan().equals(tagInformation.getPonCTag())).findFirst(); |
| 1148 | if (optHost.isPresent()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1149 | log.debug("Got MAC Address {} from the hostService for {} and cTag {}", |
| 1150 | optHost.get().mac(), port, tagInformation.getPonCTag()); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1151 | return Optional.of(optHost.get().mac()); |
| 1152 | } |
| 1153 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1154 | 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] | 1155 | return Optional.empty(); |
| 1156 | } |
| 1157 | |
| 1158 | private boolean isMacAddressValid(UniTagInformation tagInformation) { |
| 1159 | return tagInformation.getConfiguredMacAddress() != null && |
| 1160 | !tagInformation.getConfiguredMacAddress().trim().equals("") && |
| 1161 | !MacAddress.NONE.equals(MacAddress.valueOf(tagInformation.getConfiguredMacAddress())); |
| 1162 | } |
| 1163 | |
| 1164 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1165 | * Checks the subscriber uni tag list and find the uni tag information. |
| 1166 | * using the pon c tag, pon s tag and the technology profile id |
| 1167 | * May return Optional<null> |
| 1168 | * |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1169 | * @param port port of the subscriber |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1170 | * @param innerVlan pon c tag |
| 1171 | * @param outerVlan pon s tag |
| 1172 | * @param tpId the technology profile id |
| 1173 | * @return the found uni tag information |
| 1174 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1175 | private Optional<UniTagInformation> getUniTagInformation(AccessDevicePort port, VlanId innerVlan, |
| 1176 | VlanId outerVlan, int tpId) { |
| 1177 | log.debug("Getting uni tag information for {}, innerVlan: {}, outerVlan: {}, tpId: {}", |
| 1178 | port, innerVlan, outerVlan, tpId); |
| 1179 | SubscriberAndDeviceInformation subInfo = getSubscriber(new ConnectPoint(port.deviceId(), port.number())); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1180 | if (subInfo == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1181 | log.warn("Subscriber information doesn't exist for {}", port); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1182 | return Optional.empty(); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1185 | List<UniTagInformation> uniTagList = subInfo.uniTagList(); |
| 1186 | if (uniTagList == null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1187 | 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] | 1188 | return Optional.empty(); |
| 1189 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1190 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1191 | UniTagInformation service = null; |
| 1192 | for (UniTagInformation tagInfo : subInfo.uniTagList()) { |
| 1193 | if (innerVlan.equals(tagInfo.getPonCTag()) && outerVlan.equals(tagInfo.getPonSTag()) |
| 1194 | && tpId == tagInfo.getTechnologyProfileId()) { |
| 1195 | service = tagInfo; |
| 1196 | break; |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 1197 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 1198 | } |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 1199 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1200 | if (service == null) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 1201 | 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^] | 1202 | innerVlan, outerVlan, tpId, port); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1203 | return Optional.empty(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1206 | return Optional.of(service); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1207 | } |
| 1208 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1209 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1210 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 1211 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1212 | * |
| 1213 | * @param dev Device to look for |
| 1214 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1215 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1216 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1217 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1218 | log.info("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1219 | |
| 1220 | if (deviceInfo != null) { |
Andrea Campanella | 438e1ad | 2021-03-26 11:41:16 +0100 | [diff] [blame] | 1221 | log.debug("Driver for device {} is {}", dev.id(), |
| 1222 | driverService.getDriver(dev.id())); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1223 | for (Port p : deviceService.getPorts(dev.id())) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1224 | if (PortNumber.LOCAL.equals(p.number()) || !p.isEnabled()) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1225 | continue; |
| 1226 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1227 | if (isUniPort(dev, p)) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1228 | AccessDevicePort port = new AccessDevicePort(p, AccessDevicePort.Type.UNI); |
Andrea Campanella | a249178 | 2020-03-13 18:09:31 +0100 | [diff] [blame] | 1229 | if (!programmedSubs.containsKey(new ConnectPoint(dev.id(), p.number()))) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1230 | log.info("Creating Eapol on {}", port); |
| 1231 | oltFlowService.processEapolFilteringObjectives(port, defaultBpId, null, |
Andrea Campanella | a249178 | 2020-03-13 18:09:31 +0100 | [diff] [blame] | 1232 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 1233 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1234 | log.debug("Subscriber Eapol on {} is already provisioned, not installing default", port); |
Andrea Campanella | a249178 | 2020-03-13 18:09:31 +0100 | [diff] [blame] | 1235 | } |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1236 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1237 | AccessDevicePort port = new AccessDevicePort(p, AccessDevicePort.Type.NNI); |
| 1238 | oltFlowService.processNniFilteringObjectives(port, true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1244 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1245 | /** |
| 1246 | * Get the uplink for of the OLT device. |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1247 | * <p> |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1248 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 1249 | * this logic needs to be changed |
| 1250 | * |
| 1251 | * @param dev Device to look for |
| 1252 | * @return The uplink Port of the OLT |
| 1253 | */ |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1254 | private AccessDevicePort getUplinkPort(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1255 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1256 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 1257 | log.trace("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1258 | if (deviceInfo == null) { |
| 1259 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1260 | + " info", dev.id()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1261 | return null; |
| 1262 | } |
| 1263 | // 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] | 1264 | Optional<Port> optionalPort = deviceService.getPorts(dev.id()).stream() |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1265 | .filter(port -> isNniPort(port) || |
| 1266 | (port.number().toLong() == deviceInfo.uplinkPort())) |
| 1267 | .findFirst(); |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1268 | if (optionalPort.isPresent()) { |
| 1269 | log.trace("getUplinkPort: Found port {}", optionalPort.get()); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1270 | return new AccessDevicePort(optionalPort.get(), AccessDevicePort.Type.NNI); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
Saurav Das | eae48de | 2019-06-19 13:26:15 -0700 | [diff] [blame] | 1273 | log.warn("getUplinkPort: " + NO_UPLINK_PORT, dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1274 | return null; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * Return the subscriber on a port. |
| 1279 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1280 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1281 | * @return subscriber if found else null |
| 1282 | */ |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 1283 | protected SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 1284 | if (subsService == null) { |
| 1285 | log.warn(SADIS_NOT_RUNNING); |
| 1286 | return null; |
| 1287 | } |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1288 | Port port = deviceService.getPort(cp); |
| 1289 | checkNotNull(port, "Invalid connect point"); |
| 1290 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1291 | return subsService.get(portName); |
| 1292 | } |
| 1293 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1294 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1295 | * Checks whether the given port of the device is a uni port or not. |
| 1296 | * |
| 1297 | * @param d the access device |
| 1298 | * @param p the port of the device |
| 1299 | * @return true if the given port is a uni port |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1300 | */ |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1301 | private boolean isUniPort(Device d, Port p) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1302 | AccessDevicePort ulPort = getUplinkPort(d); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1303 | if (ulPort != null) { |
| 1304 | return (ulPort.number().toLong() != p.number().toLong()); |
| 1305 | } |
Thomas Lee S | d7735f9 | 2020-02-20 19:21:47 +0530 | [diff] [blame] | 1306 | //handles a special case where NNI port is misconfigured in SADIS and getUplinkPort(d) returns null |
| 1307 | //checks whether the port name starts with nni- which is the signature of an NNI Port |
| 1308 | if (p.annotations().value(AnnotationKeys.PORT_NAME) != null && |
| 1309 | p.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI)) { |
| 1310 | log.error("NNI port number {} is not matching with configured value", p.number().toLong()); |
| 1311 | return false; |
| 1312 | } |
| 1313 | return true; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1316 | /** |
| 1317 | * Gets the given device details from SADIS. |
| 1318 | * If the device is not found, returns null |
| 1319 | * |
| 1320 | * @param dev the access device |
| 1321 | * @return the olt information |
| 1322 | */ |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1323 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 1324 | if (subsService == null) { |
| 1325 | log.warn(SADIS_NOT_RUNNING); |
| 1326 | return null; |
| 1327 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1328 | String devSerialNo = dev.serialNumber(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1329 | return subsService.get(devSerialNo); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Andrea Campanella | 1edf883 | 2021-05-06 12:51:33 +0200 | [diff] [blame] | 1332 | /** |
| 1333 | * Checks for mastership or falls back to leadership on deviceId. |
| 1334 | * If the device is available use mastership, |
| 1335 | * otherwise fallback on leadership. |
| 1336 | * Leadership on the device topic is needed because the master can be NONE |
| 1337 | * in case the device went away, we still need to handle events |
| 1338 | * consistently |
| 1339 | */ |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1340 | private boolean isLocalLeader(DeviceId deviceId) { |
Andrea Campanella | 1edf883 | 2021-05-06 12:51:33 +0200 | [diff] [blame] | 1341 | if (deviceService.isAvailable(deviceId)) { |
| 1342 | return mastershipService.isLocalMaster(deviceId); |
| 1343 | } else { |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1344 | // Fallback with Leadership service - device id is used as topic |
| 1345 | NodeId leader = leadershipService.runForLeadership( |
| 1346 | deviceId.toString()).leaderNodeId(); |
| 1347 | // Verify if this node is the leader |
| 1348 | return clusterService.getLocalNode().id().equals(leader); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1349 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1350 | } |
| 1351 | |
kdarapu | aa5da25 | 2020-04-10 15:58:05 +0530 | [diff] [blame] | 1352 | private boolean isNniPort(Port port) { |
| 1353 | if (port.annotations().keys().contains(AnnotationKeys.PORT_NAME)) { |
| 1354 | return port.annotations().value(AnnotationKeys.PORT_NAME).contains(NNI); |
| 1355 | } |
| 1356 | return false; |
| 1357 | } |
| 1358 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1359 | private class InternalHostListener implements HostListener { |
| 1360 | @Override |
| 1361 | public void event(HostEvent event) { |
| 1362 | hostEventExecutor.execute(() -> { |
| 1363 | Host host = event.subject(); |
| 1364 | switch (event.type()) { |
| 1365 | case HOST_ADDED: |
| 1366 | ConnectPoint cp = new ConnectPoint(host.location().deviceId(), host.location().port()); |
| 1367 | Optional<SubscriberFlowInfo> optSubFlowInfo = |
| 1368 | getAndRemoveWaitingMacSubFlowInfoForCTag(cp, host.vlan()); |
| 1369 | if (optSubFlowInfo.isPresent()) { |
| 1370 | log.debug("Continuing provisioning for waiting mac service. event: {}", event); |
| 1371 | continueProvisioningSubs(optSubFlowInfo.get(), Optional.of(host.mac())); |
| 1372 | } else { |
| 1373 | log.debug("There is no waiting mac sub. event: {}", event); |
| 1374 | } |
| 1375 | break; |
| 1376 | case HOST_UPDATED: |
| 1377 | if (event.prevSubject() != null && !event.prevSubject().mac().equals(event.subject().mac())) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1378 | log.debug("Subscriber's MAC address changed from {} to {}. " + |
| 1379 | "devId/portNumber: {}/{} vlan: {}", event.prevSubject().mac(), |
| 1380 | event.subject().mac(), host.location().deviceId(), host.location().port(), |
| 1381 | host.vlan()); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1382 | // TODO handle subscriber MAC Address changed |
| 1383 | } else { |
| 1384 | log.debug("Unhandled HOST_UPDATED event: {}", event); |
| 1385 | } |
| 1386 | break; |
| 1387 | default: |
| 1388 | log.debug("Unhandled host event received. event: {}", event); |
| 1389 | } |
| 1390 | }); |
| 1391 | } |
| 1392 | |
| 1393 | @Override |
| 1394 | public boolean isRelevant(HostEvent event) { |
| 1395 | return isLocalLeader(event.subject().location().deviceId()); |
| 1396 | } |
| 1397 | } |
| 1398 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1399 | private class InternalDeviceListener implements DeviceListener { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1400 | private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet(); |
| 1401 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1402 | @Override |
| 1403 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1404 | eventExecutor.execute(() -> { |
| 1405 | DeviceId devId = event.subject().id(); |
| 1406 | Device dev = event.subject(); |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1407 | Port p = event.port(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1408 | DeviceEvent.Type eventType = event.type(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1409 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1410 | if (DeviceEvent.Type.PORT_STATS_UPDATED.equals(eventType) || |
| 1411 | DeviceEvent.Type.DEVICE_SUSPENDED.equals(eventType) || |
| 1412 | DeviceEvent.Type.DEVICE_UPDATED.equals(eventType)) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1413 | return; |
| 1414 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1415 | |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1416 | boolean isLocalLeader = isLocalLeader(devId); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1417 | // Only handle the event if the device belongs to us |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1418 | if (!isLocalLeader && event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) |
| 1419 | && !deviceService.isAvailable(devId) && deviceService.getPorts(devId).isEmpty()) { |
| 1420 | log.info("Cleaning local state for non master instance upon " + |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1421 | "device disconnection {}", devId); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1422 | // Since no mastership of the device is present upon disconnection |
| 1423 | // the method in the FlowRuleManager only empties the local copy |
| 1424 | // of the DeviceFlowTable thus this method needs to get called |
| 1425 | // on every instance, see how it's done in the InternalDeviceListener |
| 1426 | // in FlowRuleManager: no mastership check for purgeOnDisconnection |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1427 | handleDeviceDisconnection(dev, false, false); |
Andrea Campanella | af39b4c | 2020-05-13 14:07:44 +0200 | [diff] [blame] | 1428 | return; |
| 1429 | } else if (!isLocalLeader) { |
Andrea Campanella | 506df20 | 2020-05-21 10:26:12 +0200 | [diff] [blame] | 1430 | log.debug("Not handling event because instance is not leader for {}", devId); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1431 | return; |
| 1432 | } |
| 1433 | |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 1434 | log.debug("OLT got {} event for {}/{}", eventType, event.subject(), event.port()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1435 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1436 | if (getOltInfo(dev) == null) { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1437 | // it's possible that we got an event for a previously |
| 1438 | // programmed OLT that is no longer available in SADIS |
| 1439 | // we let such events go through |
| 1440 | if (!programmedDevices.contains(devId)) { |
| 1441 | log.warn("No device info found for {}, this is either " |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1442 | + "not an OLT or not known to sadis", dev); |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1443 | return; |
| 1444 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1445 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1446 | AccessDevicePort port = null; |
| 1447 | if (p != null) { |
| 1448 | if (isUniPort(dev, p)) { |
| 1449 | port = new AccessDevicePort(p, AccessDevicePort.Type.UNI); |
| 1450 | } else { |
| 1451 | port = new AccessDevicePort(p, AccessDevicePort.Type.NNI); |
| 1452 | } |
| 1453 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1454 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1455 | switch (event.type()) { |
| 1456 | //TODO: Port handling and bookkeeping should be improved once |
| 1457 | // olt firmware handles correct behaviour. |
| 1458 | case PORT_ADDED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1459 | if (!deviceService.isAvailable(devId)) { |
| 1460 | log.warn("Received {} for disconnected device {}, ignoring", event, devId); |
| 1461 | return; |
| 1462 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1463 | if (port.type().equals(AccessDevicePort.Type.UNI)) { |
| 1464 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port.port())); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1465 | |
| 1466 | if (port.isEnabled() && !port.number().equals(PortNumber.LOCAL)) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1467 | log.info("eapol will be sent for port added {}", port); |
| 1468 | oltFlowService.processEapolFilteringObjectives(port, defaultBpId, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1469 | null, |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1470 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1471 | true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1472 | } |
| 1473 | } else { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1474 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 1475 | if (deviceInfo != null) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1476 | oltFlowService.processNniFilteringObjectives(port, true); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1477 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1478 | } |
| 1479 | break; |
| 1480 | case PORT_REMOVED: |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1481 | if (port.type().equals(AccessDevicePort.Type.UNI)) { |
Andrea Campanella | cf0e305 | 2020-08-27 11:05:39 +0200 | [diff] [blame] | 1482 | // if no subscriber is provisioned we need to remove the default EAPOL |
| 1483 | // if a subscriber was provisioned the default EAPOL will not be there and we can skip. |
| 1484 | // The EAPOL with subscriber tag will be removed by removeSubscriber call. |
| 1485 | Collection<? extends UniTagInformation> uniTagInformationSet = |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1486 | programmedSubs.get(new ConnectPoint(port.deviceId(), port.number())).value(); |
Andrea Campanella | cf0e305 | 2020-08-27 11:05:39 +0200 | [diff] [blame] | 1487 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1488 | log.info("No subscriber provisioned on port {} in PORT_REMOVED event, " + |
| 1489 | "removing default EAPOL flow", port); |
| 1490 | oltFlowService.processEapolFilteringObjectives(port, defaultBpId, null, |
Andrea Campanella | cf0e305 | 2020-08-27 11:05:39 +0200 | [diff] [blame] | 1491 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1492 | false); |
| 1493 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1494 | removeSubscriber(port); |
Andrea Campanella | cf0e305 | 2020-08-27 11:05:39 +0200 | [diff] [blame] | 1495 | } |
Andy Bavier | 160e868 | 2019-05-07 18:32:22 -0700 | [diff] [blame] | 1496 | |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1497 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port.port())); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1498 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | case PORT_UPDATED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1501 | if (!deviceService.isAvailable(devId)) { |
| 1502 | log.warn("Received {} for disconnected device {}, ignoring", event, devId); |
| 1503 | return; |
| 1504 | } |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1505 | if (port.type().equals(AccessDevicePort.Type.NNI)) { |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 1506 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
| 1507 | if (deviceInfo != null && port.isEnabled()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1508 | log.debug("NNI {} enabled", port); |
| 1509 | oltFlowService.processNniFilteringObjectives(port, true); |
Saurav Das | 9da7d52 | 2020-03-23 19:14:35 -0700 | [diff] [blame] | 1510 | } |
| 1511 | return; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1512 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1513 | ConnectPoint cp = new ConnectPoint(devId, port.number()); |
| 1514 | Collection<? extends UniTagInformation> uniTagInformationSet = programmedSubs.get(cp).value(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1515 | if (uniTagInformationSet == null || uniTagInformationSet.isEmpty()) { |
Saurav Das | b776aef | 2020-03-09 14:29:46 -0700 | [diff] [blame] | 1516 | if (!port.number().equals(PortNumber.LOCAL)) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1517 | log.info("eapol will be {} updated for {} with default vlan {}", |
| 1518 | (port.isEnabled()) ? "added" : "removed", port, EAPOL_DEFAULT_VLAN); |
| 1519 | oltFlowService.processEapolFilteringObjectives(port, defaultBpId, null, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1520 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), |
| 1521 | port.isEnabled()); |
| 1522 | } |
| 1523 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1524 | log.info("eapol will be {} updated for {}", (port.isEnabled()) ? "added" : "removed", |
| 1525 | port); |
| 1526 | for (UniTagInformation uniTag : uniTagInformationSet) { |
| 1527 | oltFlowService.processEapolFilteringObjectives(port, |
| 1528 | uniTag.getUpstreamBandwidthProfile(), null, |
| 1529 | uniTag.getPonCTag(), port.isEnabled()); |
| 1530 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1531 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1532 | if (port.isEnabled()) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1533 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port.port())); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1534 | } else { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame^] | 1535 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port.port())); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1536 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1537 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1538 | case DEVICE_ADDED: |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1539 | handleDeviceConnection(dev, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1540 | break; |
| 1541 | case DEVICE_REMOVED: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1542 | handleDeviceDisconnection(dev, true, true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1543 | break; |
| 1544 | case DEVICE_AVAILABILITY_CHANGED: |
| 1545 | if (deviceService.isAvailable(devId)) { |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1546 | log.info("Handling available device: {}", dev.id()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1547 | handleDeviceConnection(dev, false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1548 | } else { |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1549 | if (deviceService.getPorts(devId).isEmpty()) { |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1550 | log.info("Handling controlled device disconnection .. " |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1551 | + "flushing all state for dev:{}", devId); |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1552 | handleDeviceDisconnection(dev, true, false); |
Saurav Das | bd3b671 | 2020-03-31 23:28:35 -0700 | [diff] [blame] | 1553 | } else { |
| 1554 | log.info("Disconnected device has available ports .. " |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1555 | + "assuming temporary disconnection, " |
| 1556 | + "retaining state for device {}", devId); |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1557 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1558 | } |
| 1559 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1560 | default: |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1561 | log.debug("Not handling event {}", event); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1562 | return; |
| 1563 | } |
| 1564 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1565 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1566 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1567 | private void sendUniEvent(Device device, AccessDeviceEvent.Type eventType) { |
| 1568 | deviceService.getPorts(device.id()).stream() |
| 1569 | .filter(p -> !PortNumber.LOCAL.equals(p.number())) |
| 1570 | .filter(p -> isUniPort(device, p)) |
| 1571 | .forEach(p -> post(new AccessDeviceEvent(eventType, device.id(), p))); |
| 1572 | } |
| 1573 | |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1574 | private void handleDeviceDisconnection(Device device, boolean sendDisconnectedEvent, boolean sendUniEvent) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1575 | programmedDevices.remove(device.id()); |
| 1576 | removeAllSubscribers(device.id()); |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1577 | removeWaitingMacSubs(device.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 1578 | //Handle case where OLT disconnects during subscriber provisioning |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 1579 | pendingSubscribersForDevice.remove(device.id()); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 1580 | oltFlowService.clearDeviceState(device.id()); |
| 1581 | |
| 1582 | //Complete meter and flow purge |
Hardik Windlass | a58fbee | 2020-03-12 18:33:55 +0530 | [diff] [blame] | 1583 | flowRuleService.purgeFlowRules(device.id()); |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1584 | oltMeterService.clearMeters(device.id()); |
Andrea Campanella | 3f34c99 | 2020-07-15 10:54:10 +0200 | [diff] [blame] | 1585 | if (sendDisconnectedEvent) { |
| 1586 | post(new AccessDeviceEvent( |
| 1587 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, device.id(), |
| 1588 | null, null, null)); |
| 1589 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1590 | if (sendUniEvent) { |
| 1591 | sendUniEvent(device, AccessDeviceEvent.Type.UNI_REMOVED); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1592 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | private void handleDeviceConnection(Device dev, boolean sendUniEvent) { |
| 1596 | post(new AccessDeviceEvent( |
| 1597 | AccessDeviceEvent.Type.DEVICE_CONNECTED, dev.id(), |
| 1598 | null, null, null)); |
| 1599 | programmedDevices.add(dev.id()); |
| 1600 | checkAndCreateDeviceFlows(dev); |
| 1601 | if (sendUniEvent) { |
| 1602 | sendUniEvent(dev, AccessDeviceEvent.Type.UNI_ADDED); |
| 1603 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1604 | } |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1605 | |
| 1606 | private void removeAllSubscribers(DeviceId deviceId) { |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1607 | List<Map.Entry<ConnectPoint, UniTagInformation>> subs = programmedSubs.stream() |
| 1608 | .filter(e -> e.getKey().deviceId().equals(deviceId)) |
| 1609 | .collect(toList()); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1610 | |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1611 | subs.forEach(e -> programmedSubs.remove(e.getKey(), e.getValue())); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1612 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1613 | |
Tunahan Sezen | a07fe96 | 2021-02-24 08:24:24 +0000 | [diff] [blame] | 1614 | private void removeWaitingMacSubs(DeviceId deviceId) { |
| 1615 | List<ConnectPoint> waitingMacKeys = waitingMacSubscribers.stream() |
| 1616 | .filter(cp -> cp.getKey().deviceId().equals(deviceId)) |
| 1617 | .map(Map.Entry::getKey) |
| 1618 | .collect(toList()); |
| 1619 | waitingMacKeys.forEach(cp -> waitingMacSubscribers.removeAll(cp)); |
| 1620 | } |
| 1621 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1622 | } |
Jonathan Hart | 4f178fa | 2020-02-03 10:46:01 -0800 | [diff] [blame] | 1623 | |
| 1624 | private class InternalClusterListener implements ClusterEventListener { |
| 1625 | |
| 1626 | @Override |
| 1627 | public void event(ClusterEvent event) { |
| 1628 | if (event.type() == ClusterEvent.Type.INSTANCE_READY) { |
| 1629 | hasher.addServer(event.subject().id()); |
| 1630 | } |
| 1631 | if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) { |
| 1632 | hasher.removeServer(event.subject().id()); |
| 1633 | } |
| 1634 | } |
| 1635 | } |
Andrea Campanella | 0c3309d | 2020-05-29 01:51:18 -0700 | [diff] [blame] | 1636 | |
Hardik Windlass | 395ff37 | 2019-06-13 05:16:00 +0000 | [diff] [blame] | 1637 | } |