alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | d6a135a | 2017-08-03 22:46:05 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 16 | package org.opencord.olt.impl; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 17 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 20 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 21 | import static org.onlab.util.Tools.get; |
| 22 | import static org.onlab.util.Tools.groupedThreads; |
| 23 | import static org.slf4j.LoggerFactory.getLogger; |
| 24 | |
| 25 | import java.util.AbstractMap; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 26 | import java.util.Arrays; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | import java.util.Collection; |
| 29 | import java.util.Dictionary; |
| 30 | import java.util.List; |
| 31 | import java.util.Map; |
| 32 | import java.util.Optional; |
| 33 | import java.util.Properties; |
| 34 | import java.util.concurrent.CompletableFuture; |
| 35 | import java.util.concurrent.ExecutorService; |
| 36 | import java.util.concurrent.Executors; |
| 37 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 38 | import org.apache.felix.scr.annotations.Activate; |
| 39 | import org.apache.felix.scr.annotations.Component; |
| 40 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 41 | import org.apache.felix.scr.annotations.Modified; |
| 42 | import org.apache.felix.scr.annotations.Property; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 43 | import org.apache.felix.scr.annotations.Reference; |
| 44 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 45 | import org.apache.felix.scr.annotations.Service; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 46 | import org.onlab.packet.EthType; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 47 | import org.onlab.packet.IPv4; |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 48 | import org.onlab.packet.IPv6; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 49 | import org.onlab.packet.TpPort; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 50 | import org.onlab.packet.VlanId; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 51 | import org.onlab.util.Tools; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 52 | import org.onosproject.cfg.ComponentConfigService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 53 | import org.onosproject.core.ApplicationId; |
| 54 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 55 | import org.onosproject.event.AbstractListenerManager; |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 56 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 57 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 58 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 59 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 60 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 61 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 62 | import org.onosproject.net.PortNumber; |
| 63 | import org.onosproject.net.device.DeviceEvent; |
| 64 | import org.onosproject.net.device.DeviceListener; |
| 65 | import org.onosproject.net.device.DeviceService; |
| 66 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 67 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 68 | import org.onosproject.net.flow.TrafficSelector; |
| 69 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 70 | import org.onosproject.net.flow.criteria.Criteria; |
| 71 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 72 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 73 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 74 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 75 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 76 | import org.onosproject.net.flowobjective.Objective; |
| 77 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 78 | import org.onosproject.net.flowobjective.ObjectiveError; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 79 | import org.onosproject.store.serializers.KryoNamespaces; |
| 80 | import org.onosproject.store.service.ConsistentMultimap; |
| 81 | import org.onosproject.store.service.Serializer; |
| 82 | import org.onosproject.store.service.StorageService; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 83 | import org.opencord.olt.AccessDeviceEvent; |
| 84 | import org.opencord.olt.AccessDeviceListener; |
| 85 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 86 | import org.opencord.olt.AccessSubscriberId; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 87 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 88 | import org.opencord.sadis.SubscriberAndDeviceInformationService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 89 | import org.osgi.service.component.ComponentContext; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 90 | import org.slf4j.Logger; |
| 91 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 92 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 93 | import com.google.common.collect.ImmutableMap; |
| 94 | import com.google.common.collect.Maps; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 97 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 98 | */ |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 99 | @Service |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 100 | @Component(immediate = true) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 101 | public class Olt |
| 102 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 103 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 104 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 105 | |
| 106 | private static final short DEFAULT_VLAN = 0; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 107 | private static final String ADDITIONAL_VLANS = "additional-vlans"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 108 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 109 | private final Logger log = getLogger(getClass()); |
| 110 | |
| 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 112 | protected FlowObjectiveService flowObjectiveService; |
| 113 | |
| 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 115 | protected MastershipService mastershipService; |
| 116 | |
| 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 118 | protected DeviceService deviceService; |
| 119 | |
| 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 121 | protected CoreService coreService; |
| 122 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 124 | protected ComponentConfigService componentConfigService; |
| 125 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 127 | protected SubscriberAndDeviceInformationService subsService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 128 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 130 | protected StorageService storageService; |
| 131 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 132 | @Property(name = "defaultVlan", intValue = DEFAULT_VLAN, |
| 133 | label = "Default VLAN RG<->ONU traffic") |
| 134 | private int defaultVlan = DEFAULT_VLAN; |
| 135 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 136 | @Property(name = "enableDhcpOnProvisioning", boolValue = true, |
| 137 | label = "Create the DHCP Flow rules when a subscriber is provisioned") |
| 138 | protected boolean enableDhcpOnProvisioning = false; |
| 139 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 140 | @Property(name = "enableDhcpV4", boolValue = true, |
| 141 | label = "Enable flows for DHCP v4") |
| 142 | protected boolean enableDhcpV4 = true; |
| 143 | |
| 144 | @Property(name = "enableDhcpV6", boolValue = true, |
| 145 | label = "Enable flows for DHCP v6") |
| 146 | protected boolean enableDhcpV6 = false; |
| 147 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 148 | @Property(name = "enableIgmpOnProvisioning", boolValue = false, |
| 149 | label = "Create IGMP Flow rules when a subscriber is provisioned") |
| 150 | protected boolean enableIgmpOnProvisioning = false; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 151 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 152 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 153 | |
| 154 | private ApplicationId appId; |
| 155 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 156 | private ExecutorService oltInstallers = Executors |
| 157 | .newFixedThreadPool(4, groupedThreads("onos/olt-service", |
| 158 | "olt-installer-%d")); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 159 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 160 | private ConsistentMultimap<ConnectPoint, Map.Entry<VlanId, VlanId>> additionalVlans; |
| 161 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 162 | protected ExecutorService eventExecutor; |
| 163 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 164 | private Map<ConnectPoint, SubscriberAndDeviceInformation> programmedSubs; |
| 165 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 166 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 167 | public void activate(ComponentContext context) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 168 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt", "events-%d", log)); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 169 | modified(context); |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 170 | appId = coreService.registerApplication(APP_NAME); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 171 | componentConfigService.registerProperties(getClass()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 172 | programmedSubs = Maps.newConcurrentMap(); |
alshabib | c4dfe85 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 173 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 174 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 175 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 176 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 177 | // UNI ports |
| 178 | Iterable<Device> devices = deviceService.getDevices(); |
| 179 | for (Device d : devices) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 180 | checkAndCreateDeviceFlows(d); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 181 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 182 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 183 | additionalVlans = storageService.<ConnectPoint, Map.Entry<VlanId, VlanId>>consistentMultimapBuilder() |
| 184 | .withName(ADDITIONAL_VLANS) |
| 185 | .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), |
| 186 | AbstractMap.SimpleEntry.class)) |
| 187 | .build(); |
| 188 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 189 | deviceService.addListener(deviceListener); |
| 190 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 191 | log.info("Started with Application ID {}", appId.id()); |
| 192 | } |
| 193 | |
| 194 | @Deactivate |
| 195 | public void deactivate() { |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 196 | componentConfigService.unregisterProperties(getClass(), false); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 197 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 198 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 199 | log.info("Stopped"); |
| 200 | } |
| 201 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 202 | @Modified |
| 203 | public void modified(ComponentContext context) { |
| 204 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 205 | |
| 206 | try { |
| 207 | String s = get(properties, "defaultVlan"); |
| 208 | defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 209 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 210 | Boolean o = Tools.isPropertyEnabled(properties, "enableDhcpOnProvisioning"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 211 | if (o != null) { |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 212 | enableDhcpOnProvisioning = o; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 213 | } |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 214 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 215 | Boolean v4 = Tools.isPropertyEnabled(properties, "enableDhcpV4"); |
| 216 | if (v4 != null) { |
| 217 | enableDhcpV4 = v4; |
| 218 | } |
| 219 | |
| 220 | Boolean v6 = Tools.isPropertyEnabled(properties, "enableDhcpV6"); |
| 221 | if (v6 != null) { |
| 222 | enableDhcpV6 = v6; |
| 223 | } |
| 224 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 225 | Boolean p = Tools.isPropertyEnabled(properties, "enableIgmpOnProvisioning"); |
| 226 | if (p != null) { |
| 227 | enableIgmpOnProvisioning = p; |
| 228 | } |
| 229 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 230 | log.info("DHCP Settings [enableDhcpOnProvisioning: {}, enableDhcpV4: {}, enableDhcpV6: {}]", |
| 231 | enableDhcpOnProvisioning, enableDhcpV4, enableDhcpV6); |
| 232 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 233 | } catch (Exception e) { |
| 234 | defaultVlan = DEFAULT_VLAN; |
| 235 | } |
| 236 | } |
| 237 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 238 | @Override |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 239 | public boolean provisionSubscriber(ConnectPoint port) { |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 240 | checkNotNull(deviceService.getPort(port.deviceId(), port.port()), |
| 241 | "Invalid connect point"); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 242 | // Find the subscriber on this connect point |
| 243 | SubscriberAndDeviceInformation sub = getSubscriber(port); |
| 244 | if (sub == null) { |
| 245 | log.warn("No subscriber found for {}", port); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 246 | return false; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 247 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 248 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 249 | // Get the uplink port |
| 250 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 251 | if (uplinkPort == null) { |
| 252 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 253 | return false; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 256 | if (enableDhcpOnProvisioning) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 257 | processDhcpFilteringObjectives(port.deviceId(), port.port(), true, |
| 258 | true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 259 | } |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 260 | log.info("Programming vlans for subscriber: {}", sub); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 261 | Optional<VlanId> defaultVlan = Optional.empty(); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 262 | provisionVlans(port.deviceId(), uplinkPort.number(), port.port(), |
| 263 | sub.cTag(), sub.sTag(), defaultVlan); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 264 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 265 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 266 | processIgmpFilteringObjectives(port.deviceId(), port.port(), true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 267 | } |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 268 | // cache subscriber info |
| 269 | programmedSubs.put(port, sub); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 270 | return true; |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 274 | public boolean removeSubscriber(ConnectPoint port) { |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 275 | // Get the subscriber connected to this port from the local cache |
| 276 | // as if we don't know about the subscriber there's no need to remove it |
| 277 | SubscriberAndDeviceInformation subscriber = programmedSubs.get(port); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 278 | if (subscriber == null) { |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 279 | log.warn("Subscriber on port {} was not previously programmed, no need to remove it", port); |
| 280 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 283 | // Get the uplink port |
| 284 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 285 | if (uplinkPort == null) { |
| 286 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 287 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 290 | if (enableDhcpOnProvisioning) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 291 | processDhcpFilteringObjectives(port.deviceId(), port.port(), false, |
| 292 | true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 295 | log.info("Removing programmed vlans for subscriber: {}", subscriber); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 296 | Optional<VlanId> defaultVlan = Optional.empty(); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 297 | unprovisionSubscriber(port.deviceId(), uplinkPort.number(), port.port(), |
| 298 | subscriber.cTag(), subscriber.sTag(), defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 299 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 300 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 301 | processIgmpFilteringObjectives(port.deviceId(), port.port(), false); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 302 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 303 | |
| 304 | // Remove if there are any flows for the additional Vlans |
| 305 | Collection<? extends Map.Entry<VlanId, VlanId>> vlansList = additionalVlans.get(port).value(); |
| 306 | |
| 307 | // Remove the flows for the additional vlans for this subscriber |
| 308 | for (Map.Entry<VlanId, VlanId> vlans : vlansList) { |
| 309 | unprovisionTransparentFlows(port.deviceId(), uplinkPort.number(), port.port(), |
| 310 | vlans.getValue(), vlans.getKey()); |
| 311 | |
| 312 | // Remove it from the map also |
| 313 | additionalVlans.remove(port, vlans); |
| 314 | } |
| 315 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 316 | programmedSubs.remove(port); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 317 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 320 | @Override |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 321 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, Optional<VlanId> cTag) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 322 | // Check if we can find the connect point to which this subscriber is connected |
| 323 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 324 | if (subsPort == null) { |
| 325 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 326 | return false; |
| 327 | } |
| 328 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 329 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 330 | return provisionSubscriber(subsPort); |
| 331 | } else if (sTag.isPresent() && cTag.isPresent()) { |
| 332 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 333 | if (uplinkPort == null) { |
| 334 | log.warn("No uplink port found for OLT device {}", subsPort.deviceId()); |
| 335 | return false; |
| 336 | } |
| 337 | |
| 338 | provisionTransparentFlows(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 339 | cTag.get(), sTag.get()); |
| 340 | return true; |
| 341 | } else { |
| 342 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 343 | return false; |
| 344 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 345 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 346 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 347 | @Override |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 348 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, Optional<VlanId> cTag) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 349 | // Check if we can find the connect point to which this subscriber is connected |
| 350 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 351 | if (subsPort == null) { |
| 352 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 353 | return false; |
| 354 | } |
| 355 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 356 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 357 | return removeSubscriber(subsPort); |
| 358 | } else if (sTag.isPresent() && cTag.isPresent()) { |
| 359 | // Get the uplink port |
| 360 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 361 | if (uplinkPort == null) { |
| 362 | log.warn("No uplink port found for OLT device {}", subsPort.deviceId()); |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | unprovisionTransparentFlows(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 367 | cTag.get(), sTag.get()); |
| 368 | return true; |
| 369 | } else { |
| 370 | log.warn("Removing subscriber failed for: {}", subscriberId); |
| 371 | return false; |
| 372 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public Collection<Map.Entry<ConnectPoint, Map.Entry<VlanId, VlanId>>> getSubscribers() { |
| 377 | ArrayList<Map.Entry<ConnectPoint, Map.Entry<VlanId, VlanId>>> subs = new ArrayList<>(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 378 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 379 | // Get the subscribers for all the devices configured in sadis |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 380 | // If the port is UNI, is enabled and exists in Sadis then copy it |
| 381 | for (Device d : deviceService.getDevices()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 382 | if (getOltInfo(d) == null) { |
| 383 | continue; // not an olt, or not configured in sadis |
| 384 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 385 | for (Port p: deviceService.getPorts(d.id())) { |
| 386 | if (isUniPort(d, p) && p.isEnabled()) { |
| 387 | ConnectPoint cp = new ConnectPoint(d.id(), p.number()); |
| 388 | |
| 389 | SubscriberAndDeviceInformation sub = getSubscriber(cp); |
| 390 | if (sub != null) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 391 | Map.Entry<VlanId, VlanId> vlans = new AbstractMap.SimpleEntry(sub.sTag(), sub.cTag()); |
| 392 | subs.add(new AbstractMap.SimpleEntry(cp, vlans)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | return subs; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | @Override |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 402 | public ImmutableMap<ConnectPoint, SubscriberAndDeviceInformation> getProgSubs() { |
| 403 | return ImmutableMap.copyOf(programmedSubs); |
| 404 | } |
| 405 | |
| 406 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 407 | public List<DeviceId> fetchOlts() { |
| 408 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 409 | List<DeviceId> olts = new ArrayList<>(); |
| 410 | Iterable<Device> devices = deviceService.getDevices(); |
| 411 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 412 | if (getOltInfo(d) != null) { |
| 413 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 414 | olts.add(d.id()); |
| 415 | } |
| 416 | } |
| 417 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 420 | /** |
| 421 | * Finds the connect point to which a subscriber is connected. |
| 422 | * |
| 423 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 424 | * @return Subscribers ConnectPoint if found else null |
| 425 | */ |
| 426 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 427 | |
| 428 | Iterable<Device> devices = deviceService.getDevices(); |
| 429 | for (Device d : devices) { |
| 430 | for (Port p : deviceService.getPorts(d.id())) { |
| 431 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 432 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 433 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 434 | return new ConnectPoint(d.id(), p.number()); |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | return null; |
| 439 | } |
| 440 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 441 | private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 442 | PortNumber subscriberPort, VlanId cVlan, |
| 443 | VlanId sVlan, Optional<VlanId> defaultVlan) { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 444 | |
| 445 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 446 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 447 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 448 | ForwardingObjective.Builder upFwd = upBuilder(uplink, subscriberPort, |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 449 | cVlan, sVlan, |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 450 | defaultVlan); |
| 451 | ForwardingObjective.Builder downFwd = downBuilder(uplink, subscriberPort, |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 452 | cVlan, sVlan, |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 453 | defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 454 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 455 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 456 | @Override |
| 457 | public void onSuccess(Objective objective) { |
| 458 | upFuture.complete(null); |
| 459 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 460 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 461 | @Override |
| 462 | public void onError(Objective objective, ObjectiveError error) { |
| 463 | upFuture.complete(error); |
| 464 | } |
| 465 | })); |
| 466 | |
| 467 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 468 | @Override |
| 469 | public void onSuccess(Objective objective) { |
| 470 | downFuture.complete(null); |
| 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public void onError(Objective objective, ObjectiveError error) { |
| 475 | downFuture.complete(error); |
| 476 | } |
| 477 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 478 | |
| 479 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 480 | if (upStatus == null && downStatus == null) { |
| 481 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
| 482 | deviceId, |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 483 | sVlan, |
| 484 | cVlan)); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 485 | } else if (downStatus != null) { |
| 486 | log.error("Subscriber with vlan {} on device {} " + |
| 487 | "on port {} failed downstream uninstallation: {}", |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 488 | cVlan, deviceId, subscriberPort, downStatus); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 489 | } else if (upStatus != null) { |
| 490 | log.error("Subscriber with vlan {} on device {} " + |
| 491 | "on port {} failed upstream uninstallation: {}", |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 492 | cVlan, deviceId, subscriberPort, upStatus); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 493 | } |
| 494 | }, oltInstallers); |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 495 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, |
| 499 | PortNumber subscriberPort, |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 500 | VlanId subscriberVlan, VlanId deviceVlan, |
| 501 | Optional<VlanId> defaultVlan) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 502 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 503 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 504 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 505 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 506 | ForwardingObjective.Builder upFwd = upBuilder(uplinkPort, subscriberPort, |
| 507 | subscriberVlan, deviceVlan, |
| 508 | defaultVlan); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 509 | |
| 510 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 511 | ForwardingObjective.Builder downFwd = downBuilder(uplinkPort, subscriberPort, |
| 512 | subscriberVlan, deviceVlan, |
| 513 | defaultVlan); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 514 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 515 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 516 | @Override |
| 517 | public void onSuccess(Objective objective) { |
| 518 | upFuture.complete(null); |
| 519 | } |
| 520 | |
| 521 | @Override |
| 522 | public void onError(Objective objective, ObjectiveError error) { |
| 523 | upFuture.complete(error); |
| 524 | } |
| 525 | })); |
| 526 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 527 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 528 | @Override |
| 529 | public void onSuccess(Objective objective) { |
| 530 | downFuture.complete(null); |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public void onError(Objective objective, ObjectiveError error) { |
| 535 | downFuture.complete(error); |
| 536 | } |
| 537 | })); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 538 | |
| 539 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 540 | if (upStatus == null && downStatus == null) { |
| 541 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
| 542 | deviceId, |
| 543 | deviceVlan, |
| 544 | subscriberVlan)); |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 545 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 546 | } else if (downStatus != null) { |
| 547 | log.error("Subscriber with vlan {} on device {} " + |
| 548 | "on port {} failed downstream installation: {}", |
| 549 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 550 | } else if (upStatus != null) { |
| 551 | log.error("Subscriber with vlan {} on device {} " + |
| 552 | "on port {} failed upstream installation: {}", |
| 553 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 554 | } |
| 555 | }, oltInstallers); |
| 556 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 557 | } |
| 558 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 559 | private ForwardingObjective.Builder downBuilder(PortNumber uplinkPort, |
| 560 | PortNumber subscriberPort, |
| 561 | VlanId subscriberVlan, |
| 562 | VlanId deviceVlan, |
| 563 | Optional<VlanId> defaultVlan) { |
| 564 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 565 | .matchVlanId(deviceVlan) |
| 566 | .matchInPort(uplinkPort) |
| 567 | .matchInnerVlanId(subscriberVlan) |
| 568 | .build(); |
| 569 | |
| 570 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 571 | .popVlan() |
| 572 | .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 573 | .setOutput(subscriberPort) |
| 574 | .build(); |
| 575 | |
| 576 | return DefaultForwardingObjective.builder() |
| 577 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 578 | .withPriority(1000) |
| 579 | .makePermanent() |
| 580 | .withSelector(downstream) |
| 581 | .fromApp(appId) |
| 582 | .withTreatment(downstreamTreatment); |
| 583 | } |
| 584 | |
| 585 | private ForwardingObjective.Builder upBuilder(PortNumber uplinkPort, |
| 586 | PortNumber subscriberPort, |
| 587 | VlanId subscriberVlan, |
| 588 | VlanId deviceVlan, |
| 589 | Optional<VlanId> defaultVlan) { |
| 590 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 591 | .matchVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 592 | .matchInPort(subscriberPort) |
| 593 | .build(); |
| 594 | |
| 595 | |
| 596 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
| 597 | .pushVlan() |
| 598 | .setVlanId(subscriberVlan) |
| 599 | .pushVlan() |
| 600 | .setVlanId(deviceVlan) |
| 601 | .setOutput(uplinkPort) |
| 602 | .build(); |
| 603 | |
| 604 | return DefaultForwardingObjective.builder() |
| 605 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 606 | .withPriority(1000) |
| 607 | .makePermanent() |
| 608 | .withSelector(upstream) |
| 609 | .fromApp(appId) |
| 610 | .withTreatment(upstreamTreatment); |
| 611 | } |
| 612 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 613 | private void provisionTransparentFlows(DeviceId deviceId, PortNumber uplinkPort, |
| 614 | PortNumber subscriberPort, |
| 615 | VlanId innerVlan, |
| 616 | VlanId outerVlan) { |
| 617 | |
| 618 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 619 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 620 | |
| 621 | ForwardingObjective.Builder upFwd = transparentUpBuilder(uplinkPort, subscriberPort, |
| 622 | innerVlan, outerVlan); |
| 623 | |
| 624 | |
| 625 | ForwardingObjective.Builder downFwd = transparentDownBuilder(uplinkPort, subscriberPort, |
| 626 | innerVlan, outerVlan); |
| 627 | |
| 628 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 629 | |
| 630 | additionalVlans.put(cp, new AbstractMap.SimpleEntry(outerVlan, innerVlan)); |
| 631 | |
| 632 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 633 | @Override |
| 634 | public void onSuccess(Objective objective) { |
| 635 | upFuture.complete(null); |
| 636 | } |
| 637 | |
| 638 | @Override |
| 639 | public void onError(Objective objective, ObjectiveError error) { |
| 640 | upFuture.complete(error); |
| 641 | } |
| 642 | })); |
| 643 | |
| 644 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 645 | @Override |
| 646 | public void onSuccess(Objective objective) { |
| 647 | downFuture.complete(null); |
| 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public void onError(Objective objective, ObjectiveError error) { |
| 652 | downFuture.complete(error); |
| 653 | } |
| 654 | })); |
| 655 | |
| 656 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 657 | if (downStatus != null) { |
| 658 | log.error("Flow with innervlan {} and outerVlan {} on device {} " + |
| 659 | "on port {} failed downstream installation: {}", |
| 660 | innerVlan, outerVlan, deviceId, subscriberPort, downStatus); |
| 661 | } else if (upStatus != null) { |
| 662 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
| 663 | "on port {} failed upstream installation: {}", |
| 664 | innerVlan, outerVlan, deviceId, subscriberPort, upStatus); |
| 665 | } |
| 666 | }, oltInstallers); |
| 667 | |
| 668 | } |
| 669 | |
| 670 | private ForwardingObjective.Builder transparentDownBuilder(PortNumber uplinkPort, |
| 671 | PortNumber subscriberPort, |
| 672 | VlanId innerVlan, |
| 673 | VlanId outerVlan) { |
| 674 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 675 | .matchVlanId(outerVlan) |
| 676 | .matchInPort(uplinkPort) |
| 677 | .matchInnerVlanId(innerVlan) |
| 678 | .build(); |
| 679 | |
| 680 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 681 | .setOutput(subscriberPort) |
| 682 | .build(); |
| 683 | |
| 684 | return DefaultForwardingObjective.builder() |
| 685 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 686 | .withPriority(1000) |
| 687 | .makePermanent() |
| 688 | .withSelector(downstream) |
| 689 | .fromApp(appId) |
| 690 | .withTreatment(downstreamTreatment); |
| 691 | } |
| 692 | |
| 693 | private ForwardingObjective.Builder transparentUpBuilder(PortNumber uplinkPort, |
| 694 | PortNumber subscriberPort, |
| 695 | VlanId innerVlan, |
| 696 | VlanId outerVlan) { |
| 697 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 698 | .matchVlanId(outerVlan) |
| 699 | .matchInPort(subscriberPort) |
| 700 | .matchInnerVlanId(innerVlan) |
| 701 | .build(); |
| 702 | |
| 703 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
| 704 | .setOutput(uplinkPort) |
| 705 | .build(); |
| 706 | |
| 707 | return DefaultForwardingObjective.builder() |
| 708 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 709 | .withPriority(1000) |
| 710 | .makePermanent() |
| 711 | .withSelector(upstream) |
| 712 | .fromApp(appId) |
| 713 | .withTreatment(upstreamTreatment); |
| 714 | } |
| 715 | |
| 716 | private void unprovisionTransparentFlows(DeviceId deviceId, PortNumber uplink, |
| 717 | PortNumber subscriberPort, VlanId innerVlan, |
| 718 | VlanId outerVlan) { |
| 719 | |
| 720 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 721 | |
| 722 | additionalVlans.remove(cp, new AbstractMap.SimpleEntry(outerVlan, innerVlan)); |
| 723 | |
| 724 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 725 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 726 | |
| 727 | ForwardingObjective.Builder upFwd = transparentUpBuilder(uplink, subscriberPort, |
| 728 | innerVlan, outerVlan); |
| 729 | ForwardingObjective.Builder downFwd = transparentDownBuilder(uplink, subscriberPort, |
| 730 | innerVlan, outerVlan); |
| 731 | |
| 732 | |
| 733 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 734 | @Override |
| 735 | public void onSuccess(Objective objective) { |
| 736 | upFuture.complete(null); |
| 737 | } |
| 738 | |
| 739 | @Override |
| 740 | public void onError(Objective objective, ObjectiveError error) { |
| 741 | upFuture.complete(error); |
| 742 | } |
| 743 | })); |
| 744 | |
| 745 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 746 | @Override |
| 747 | public void onSuccess(Objective objective) { |
| 748 | downFuture.complete(null); |
| 749 | } |
| 750 | |
| 751 | @Override |
| 752 | public void onError(Objective objective, ObjectiveError error) { |
| 753 | downFuture.complete(error); |
| 754 | } |
| 755 | })); |
| 756 | |
| 757 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 758 | if (downStatus != null) { |
| 759 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
| 760 | "on port {} failed downstream uninstallation: {}", |
| 761 | innerVlan, outerVlan, deviceId, subscriberPort, downStatus); |
| 762 | } else if (upStatus != null) { |
| 763 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
| 764 | "on port {} failed upstream uninstallation: {}", |
| 765 | innerVlan, outerVlan, deviceId, subscriberPort, upStatus); |
| 766 | } |
| 767 | }, oltInstallers); |
| 768 | |
| 769 | } |
| 770 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 771 | private void processEapolFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 772 | if (!mastershipService.isLocalMaster(devId)) { |
| 773 | return; |
| 774 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 775 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 776 | |
| 777 | FilteringObjective eapol = (install ? builder.permit() : builder.deny()) |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 778 | .withKey(Criteria.matchInPort(port)) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 779 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
| 780 | .withMeta(DefaultTrafficTreatment.builder() |
| 781 | .setOutput(PortNumber.CONTROLLER).build()) |
| 782 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 783 | .withPriority(10000) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 784 | .add(new ObjectiveContext() { |
| 785 | @Override |
| 786 | public void onSuccess(Objective objective) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 787 | log.info("Eapol filter for {} on {} {}.", |
| 788 | devId, port, (install) ? "installed" : "removed"); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public void onError(Objective objective, ObjectiveError error) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 793 | log.info("Eapol filter for {} on {} failed {} because {}", |
| 794 | devId, port, (install) ? "installation" : "removal", |
| 795 | error); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 796 | } |
| 797 | }); |
| 798 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 799 | flowObjectiveService.filter(devId, eapol); |
alshabib | 000b6fc | 2016-02-01 17:25:00 -0800 | [diff] [blame] | 800 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 801 | } |
| 802 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 803 | /** |
| 804 | * Installs trap filtering objectives for particular traffic types on an |
| 805 | * NNI port. |
| 806 | * |
| 807 | * @param devId device ID |
| 808 | * @param port port number |
| 809 | * @param install true to install, false to remove |
| 810 | */ |
| 811 | private void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 812 | processLldpFilteringObjective(devId, port, install); |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 813 | if (enableDhcpOnProvisioning) { |
| 814 | processDhcpFilteringObjectives(devId, port, install, false); |
| 815 | } |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | private void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) { |
| 819 | if (!mastershipService.isLocalMaster(devId)) { |
| 820 | return; |
| 821 | } |
| 822 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 823 | |
| 824 | FilteringObjective lldp = (install ? builder.permit() : builder.deny()) |
| 825 | .withKey(Criteria.matchInPort(port)) |
| 826 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 827 | .withMeta(DefaultTrafficTreatment.builder() |
| 828 | .setOutput(PortNumber.CONTROLLER).build()) |
| 829 | .fromApp(appId) |
| 830 | .withPriority(10000) |
| 831 | .add(new ObjectiveContext() { |
| 832 | @Override |
| 833 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 834 | log.info("LLDP filter for device {} on port {} {}.", |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 835 | devId, port, (install) ? "installed" : "removed"); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | @Override |
| 839 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 840 | log.info("LLDP filter for device {} on port {} failed {} because {}", |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 841 | devId, port, (install) ? "installation" : "removal", |
| 842 | error); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 843 | } |
| 844 | }); |
| 845 | |
| 846 | flowObjectiveService.filter(devId, lldp); |
| 847 | |
| 848 | } |
| 849 | |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 850 | /** |
| 851 | * Trap dhcp packets to the controller. |
| 852 | * |
| 853 | * @param devId the device identifier |
| 854 | * @param port the port for which this trap flow is designated |
| 855 | * @param install true to install the flow, false to remove the flow |
| 856 | * @param upstream true if trapped packets are flowing upstream towards |
| 857 | * server, false if packets are flowing dowstream towards client |
| 858 | */ |
| 859 | private void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, |
| 860 | boolean install, |
| 861 | boolean upstream) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 862 | if (!mastershipService.isLocalMaster(devId)) { |
| 863 | return; |
| 864 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 865 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 866 | if (enableDhcpV4) { |
| 867 | int udpSrc = (upstream) ? 68 : 67; |
| 868 | int udpDst = (upstream) ? 67 : 68; |
| 869 | |
| 870 | EthType ethType = EthType.EtherType.IPV4.ethType(); |
| 871 | byte protocol = IPv4.PROTOCOL_UDP; |
| 872 | |
| 873 | this.addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, protocol, install); |
| 874 | } |
| 875 | |
| 876 | if (enableDhcpV6) { |
| 877 | int udpSrc = (upstream) ? 547 : 546; |
| 878 | int udpDst = (upstream) ? 546 : 547; |
| 879 | |
| 880 | EthType ethType = EthType.EtherType.IPV6.ethType(); |
| 881 | byte protocol = IPv6.PROTOCOL_UDP; |
| 882 | |
| 883 | this.addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, protocol, install); |
| 884 | } |
| 885 | |
| 886 | } |
| 887 | |
| 888 | private void addDhcpFilteringObjectives(DeviceId devId, |
| 889 | PortNumber port, |
| 890 | int udpSrc, |
| 891 | int udpDst, |
| 892 | EthType ethType, |
| 893 | byte protocol, |
| 894 | boolean install) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 895 | |
| 896 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 897 | FilteringObjective dhcpUpstream = (install ? builder.permit() : builder.deny()) |
| 898 | .withKey(Criteria.matchInPort(port)) |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 899 | .addCondition(Criteria.matchEthType(ethType)) |
| 900 | .addCondition(Criteria.matchIPProtocol(protocol)) |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 901 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 902 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 903 | .withMeta(DefaultTrafficTreatment.builder() |
| 904 | .setOutput(PortNumber.CONTROLLER).build()) |
| 905 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 906 | .withPriority(10000) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 907 | .add(new ObjectiveContext() { |
| 908 | @Override |
| 909 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 910 | log.info("DHCP {} filter for device {} on port {} {}.", |
| 911 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? "v4" : "v6", |
| 912 | devId, port, (install) ? "installed" : "removed"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | @Override |
| 916 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 917 | log.info("DHCP {} filter for device {} on port {} failed {} because {}", |
| 918 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? "v4" : "v6", |
| 919 | devId, port, (install) ? "installation" : "removal", |
| 920 | error); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 921 | } |
| 922 | }); |
| 923 | |
| 924 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 925 | } |
| 926 | |
| 927 | private void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 928 | if (!mastershipService.isLocalMaster(devId)) { |
| 929 | return; |
| 930 | } |
| 931 | |
| 932 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 933 | |
| 934 | builder = install ? builder.permit() : builder.deny(); |
| 935 | |
| 936 | FilteringObjective igmp = builder |
| 937 | .withKey(Criteria.matchInPort(port)) |
| 938 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 939 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 940 | .withMeta(DefaultTrafficTreatment.builder() |
| 941 | .setOutput(PortNumber.CONTROLLER).build()) |
| 942 | .fromApp(appId) |
| 943 | .withPriority(10000) |
| 944 | .add(new ObjectiveContext() { |
| 945 | @Override |
| 946 | public void onSuccess(Objective objective) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 947 | log.info("Igmp filter for {} on {} {}.", |
| 948 | devId, port, (install) ? "installed" : "removed"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public void onError(Objective objective, ObjectiveError error) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 953 | log.info("Igmp filter for {} on {} failed {} because {}.", |
| 954 | devId, port, (install) ? "installation" : "removal", |
| 955 | error); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 956 | } |
| 957 | }); |
| 958 | |
| 959 | flowObjectiveService.filter(devId, igmp); |
| 960 | } |
| 961 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 962 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 963 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 964 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 965 | * |
| 966 | * @param dev Device to look for |
| 967 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 968 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 969 | // we create only for the ones we are master of |
| 970 | if (!mastershipService.isLocalMaster(dev.id())) { |
| 971 | return; |
| 972 | } |
| 973 | // check if this device is provisioned in Sadis |
| 974 | String devSerialNo = dev.serialNumber(); |
| 975 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 976 | log.debug("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 977 | |
| 978 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 979 | // 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] | 980 | for (Port p : deviceService.getPorts(dev.id())) { |
| 981 | if (isUniPort(dev, p)) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 982 | processEapolFilteringObjectives(dev.id(), p.number(), true); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 983 | } else { |
| 984 | processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 990 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 991 | /** |
| 992 | * Get the uplink for of the OLT device. |
| 993 | * |
| 994 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 995 | * this logic needs to be changed |
| 996 | * |
| 997 | * @param dev Device to look for |
| 998 | * @return The uplink Port of the OLT |
| 999 | */ |
| 1000 | private Port getUplinkPort(Device dev) { |
| 1001 | // check if this device is provisioned in Sadis |
| 1002 | String devSerialNo = dev.serialNumber(); |
| 1003 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 1004 | log.debug("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1005 | if (deviceInfo == null) { |
| 1006 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
| 1007 | + " info", dev.id()); |
| 1008 | return null; |
| 1009 | } |
| 1010 | // Return the port that has been configured as the uplink port of this OLT in Sadis |
| 1011 | for (Port p: deviceService.getPorts(dev.id())) { |
| 1012 | if (p.number().toLong() == deviceInfo.uplinkPort()) { |
| 1013 | log.debug("getUplinkPort: Found port {}", p); |
| 1014 | return p; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1018 | log.debug("getUplinkPort: No uplink port found for OLT {}", dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1019 | return null; |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Return the subscriber on a port. |
| 1024 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1025 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1026 | * @return subscriber if found else null |
| 1027 | */ |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1028 | SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 1029 | Port port = deviceService.getPort(cp); |
| 1030 | checkNotNull(port, "Invalid connect point"); |
| 1031 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1032 | return subsService.get(portName); |
| 1033 | } |
| 1034 | |
| 1035 | private boolean isUniPort(Device d, Port p) { |
| 1036 | Port ulPort = getUplinkPort(d); |
| 1037 | if (ulPort != null) { |
| 1038 | return (ulPort.number().toLong() != p.number().toLong()); |
| 1039 | } |
| 1040 | return false; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1043 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 1044 | String devSerialNo = dev.serialNumber(); |
| 1045 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 1046 | return deviceInfo; |
| 1047 | } |
| 1048 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1049 | private class InternalDeviceListener implements DeviceListener { |
| 1050 | @Override |
| 1051 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1052 | eventExecutor.execute(() -> { |
| 1053 | DeviceId devId = event.subject().id(); |
| 1054 | Device dev = event.subject(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1055 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1056 | if (event.type() == DeviceEvent.Type.PORT_STATS_UPDATED) { |
| 1057 | return; |
| 1058 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1059 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1060 | if (getOltInfo(dev) == null) { |
| 1061 | log.debug("No device info found, this is not an OLT"); |
| 1062 | return; |
| 1063 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1064 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1065 | log.debug("OLT got {} event for {}", event.type(), event.subject()); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1066 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1067 | switch (event.type()) { |
| 1068 | //TODO: Port handling and bookkeeping should be improved once |
| 1069 | // olt firmware handles correct behaviour. |
| 1070 | case PORT_ADDED: |
| 1071 | if (isUniPort(dev, event.port())) { |
| 1072 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1073 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1074 | if (event.port().isEnabled()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1075 | processEapolFilteringObjectives(devId, event.port().number(), true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1076 | } |
| 1077 | } else { |
| 1078 | checkAndCreateDeviceFlows(dev); |
| 1079 | } |
| 1080 | break; |
| 1081 | case PORT_REMOVED: |
| 1082 | if (isUniPort(dev, event.port())) { |
| 1083 | if (event.port().isEnabled()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1084 | processEapolFilteringObjectives(devId, event.port().number(), false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1085 | removeSubscriber(new ConnectPoint(devId, event.port().number())); |
| 1086 | } |
| 1087 | |
| 1088 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
| 1089 | } |
| 1090 | |
| 1091 | break; |
| 1092 | case PORT_UPDATED: |
| 1093 | if (!isUniPort(dev, event.port())) { |
| 1094 | break; |
| 1095 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1096 | |
| 1097 | if (event.port().isEnabled()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1098 | processEapolFilteringObjectives(devId, event.port().number(), true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1099 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
| 1100 | } else { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1101 | processEapolFilteringObjectives(devId, event.port().number(), false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1102 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1103 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1104 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1105 | case DEVICE_ADDED: |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 1106 | post(new AccessDeviceEvent( |
| 1107 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 1108 | null, null)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1109 | |
| 1110 | // Send UNI_ADDED events for all existing ports |
| 1111 | deviceService.getPorts(devId).stream() |
| 1112 | .filter(p -> isUniPort(dev, p)) |
| 1113 | .filter(Port::isEnabled) |
| 1114 | .forEach(p -> post(new AccessDeviceEvent( |
| 1115 | AccessDeviceEvent.Type.UNI_ADDED, devId, p))); |
| 1116 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1117 | checkAndCreateDeviceFlows(dev); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1118 | break; |
| 1119 | case DEVICE_REMOVED: |
| 1120 | deviceService.getPorts(devId).stream() |
| 1121 | .filter(p -> isUniPort(dev, p)) |
| 1122 | .forEach(p -> post(new AccessDeviceEvent( |
| 1123 | AccessDeviceEvent.Type.UNI_REMOVED, devId, p))); |
| 1124 | |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 1125 | post(new AccessDeviceEvent( |
| 1126 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 1127 | null, null)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1128 | break; |
| 1129 | case DEVICE_AVAILABILITY_CHANGED: |
| 1130 | if (deviceService.isAvailable(devId)) { |
| 1131 | post(new AccessDeviceEvent( |
| 1132 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 1133 | null, null)); |
| 1134 | checkAndCreateDeviceFlows(dev); |
| 1135 | } else { |
| 1136 | post(new AccessDeviceEvent( |
| 1137 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 1138 | null, null)); |
| 1139 | } |
| 1140 | break; |
| 1141 | case DEVICE_UPDATED: |
| 1142 | case DEVICE_SUSPENDED: |
| 1143 | case PORT_STATS_UPDATED: |
| 1144 | default: |
| 1145 | return; |
| 1146 | } |
| 1147 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1148 | } |
| 1149 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1150 | } |