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