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