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