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