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