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