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 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Modified; |
| 22 | import org.apache.felix.scr.annotations.Property; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Service; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 26 | import org.onlab.packet.EthType; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 27 | import org.onlab.packet.IPv4; |
| 28 | import org.onlab.packet.TpPort; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 30 | import org.onlab.util.Tools; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 31 | import org.onosproject.cfg.ComponentConfigService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 32 | import org.onosproject.core.ApplicationId; |
| 33 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 34 | import org.onosproject.event.AbstractListenerManager; |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 35 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 36 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 38 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 39 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 40 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 41 | import org.onosproject.net.PortNumber; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 42 | import org.onosproject.net.config.ConfigFactory; |
| 43 | import org.onosproject.net.config.NetworkConfigEvent; |
| 44 | import org.onosproject.net.config.NetworkConfigListener; |
| 45 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 46 | import org.onosproject.net.config.basics.SubjectFactories; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 47 | import org.onosproject.net.device.DeviceEvent; |
| 48 | import org.onosproject.net.device.DeviceListener; |
| 49 | import org.onosproject.net.device.DeviceService; |
| 50 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 51 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 52 | import org.onosproject.net.flow.TrafficSelector; |
| 53 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flow.criteria.Criteria; |
| 55 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 56 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 57 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 58 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 59 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 60 | import org.onosproject.net.flowobjective.Objective; |
| 61 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 62 | import org.onosproject.net.flowobjective.ObjectiveError; |
alshabib | f3a573e | 2016-06-01 17:39:10 -0700 | [diff] [blame] | 63 | import org.opencord.cordconfig.access.AccessDeviceConfig; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 64 | import org.opencord.olt.AccessDeviceEvent; |
| 65 | import org.opencord.olt.AccessDeviceListener; |
| 66 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 67 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 68 | import org.opencord.sadis.SubscriberAndDeviceInformationService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 69 | import org.osgi.service.component.ComponentContext; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 70 | import org.slf4j.Logger; |
| 71 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 72 | import java.util.AbstractMap; |
| 73 | import java.util.ArrayList; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 74 | import java.util.Collection; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 75 | import java.util.Dictionary; |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 76 | import java.util.List; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 77 | import java.util.Map; |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 78 | import java.util.Optional; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 79 | import java.util.Properties; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 80 | import java.util.concurrent.CompletableFuture; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 81 | import java.util.concurrent.ExecutorService; |
| 82 | import java.util.concurrent.Executors; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 83 | |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 84 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 85 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 86 | import static org.onlab.util.Tools.get; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 87 | import static org.onlab.util.Tools.groupedThreads; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 88 | import static org.slf4j.LoggerFactory.getLogger; |
| 89 | |
| 90 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 91 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 92 | */ |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 93 | @Service |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 94 | @Component(immediate = true) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 95 | public class Olt |
| 96 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 97 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 98 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 99 | |
| 100 | private static final short DEFAULT_VLAN = 0; |
| 101 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 102 | private final Logger log = getLogger(getClass()); |
| 103 | |
| 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 105 | protected FlowObjectiveService flowObjectiveService; |
| 106 | |
| 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 108 | protected MastershipService mastershipService; |
| 109 | |
| 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 111 | protected DeviceService deviceService; |
| 112 | |
| 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 114 | protected CoreService coreService; |
| 115 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 117 | protected NetworkConfigRegistry networkConfig; |
| 118 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 120 | protected ComponentConfigService componentConfigService; |
| 121 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 123 | protected SubscriberAndDeviceInformationService subsService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 124 | |
| 125 | @Property(name = "defaultVlan", intValue = DEFAULT_VLAN, |
| 126 | label = "Default VLAN RG<->ONU traffic") |
| 127 | private int defaultVlan = DEFAULT_VLAN; |
| 128 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 129 | @Property(name = "enableDhcpOnProvisioning", boolValue = true, |
| 130 | label = "Create the DHCP Flow rules when a subscriber is provisioned") |
| 131 | protected boolean enableDhcpOnProvisioning = false; |
| 132 | |
| 133 | @Property(name = "enableIgmpOnProvisioning", boolValue = false, |
| 134 | label = "Create IGMP Flow rules when a subscriber is provisioned") |
| 135 | protected boolean enableIgmpOnProvisioning = false; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 136 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 137 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 138 | |
| 139 | private ApplicationId appId; |
| 140 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 141 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 142 | groupedThreads("onos/olt-service", |
| 143 | "olt-installer-%d")); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 144 | private InternalNetworkConfigListener configListener = |
| 145 | new InternalNetworkConfigListener(); |
| 146 | private static final Class<AccessDeviceConfig> CONFIG_CLASS = |
| 147 | AccessDeviceConfig.class; |
| 148 | |
| 149 | private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory = |
| 150 | new ConfigFactory<DeviceId, AccessDeviceConfig>( |
| 151 | SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 152 | @Override |
| 153 | public AccessDeviceConfig createConfig() { |
| 154 | return new AccessDeviceConfig(); |
| 155 | } |
| 156 | }; |
| 157 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 158 | |
| 159 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 160 | public void activate(ComponentContext context) { |
| 161 | modified(context); |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 162 | appId = coreService.registerApplication(APP_NAME); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 163 | componentConfigService.registerProperties(getClass()); |
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 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 167 | networkConfig.registerConfigFactory(configFactory); |
| 168 | networkConfig.addListener(configListener); |
| 169 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 170 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 171 | // UNI ports |
| 172 | Iterable<Device> devices = deviceService.getDevices(); |
| 173 | for (Device d : devices) { |
| 174 | checkAndCreateEapolFlows(d); |
| 175 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 176 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 177 | deviceService.addListener(deviceListener); |
| 178 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 179 | log.info("Started with Application ID {}", appId.id()); |
| 180 | } |
| 181 | |
| 182 | @Deactivate |
| 183 | public void deactivate() { |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 184 | componentConfigService.unregisterProperties(getClass(), false); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 185 | deviceService.removeListener(deviceListener); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 186 | networkConfig.removeListener(configListener); |
| 187 | networkConfig.unregisterConfigFactory(configFactory); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 188 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 189 | log.info("Stopped"); |
| 190 | } |
| 191 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 192 | @Modified |
| 193 | public void modified(ComponentContext context) { |
| 194 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 195 | |
| 196 | try { |
| 197 | String s = get(properties, "defaultVlan"); |
| 198 | defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 199 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 200 | Boolean o = Tools.isPropertyEnabled(properties, "enableDhcpOnProvisioning"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 201 | if (o != null) { |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 202 | enableDhcpOnProvisioning = o; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 203 | } |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 204 | |
| 205 | Boolean p = Tools.isPropertyEnabled(properties, "enableIgmpOnProvisioning"); |
| 206 | if (p != null) { |
| 207 | enableIgmpOnProvisioning = p; |
| 208 | } |
| 209 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 210 | } catch (Exception e) { |
| 211 | defaultVlan = DEFAULT_VLAN; |
| 212 | } |
| 213 | } |
| 214 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 215 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 216 | public void provisionSubscriber(ConnectPoint port) { |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 217 | checkNotNull(deviceService.getPort(port.deviceId(), port.port()), |
| 218 | "Invalid connect point"); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 219 | // Find the subscriber on this connect point |
| 220 | SubscriberAndDeviceInformation sub = getSubscriber(port); |
| 221 | if (sub == null) { |
| 222 | log.warn("No subscriber found for {}", port); |
| 223 | return; |
| 224 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 225 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 226 | // Get the uplink port |
| 227 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 228 | if (uplinkPort == null) { |
| 229 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
| 230 | return; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 233 | if (enableDhcpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 234 | processDhcpFilteringObjectives(port.deviceId(), port.port(), true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 237 | Optional<VlanId> defaultVlan = Optional.empty(); |
| 238 | provisionVlans(port.deviceId(), uplinkPort.number(), port.port(), sub.cTag(), sub.sTag(), |
| 239 | defaultVlan); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 240 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 241 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 242 | processIgmpFilteringObjectives(port.deviceId(), port.port(), true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 243 | } |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public void removeSubscriber(ConnectPoint port) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 248 | // Get the subscriber connected to this port from Sadis |
| 249 | SubscriberAndDeviceInformation subscriber = getSubscriber(port); |
| 250 | if (subscriber == null) { |
| 251 | log.warn("Subscriber on port {} not found", port); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 255 | // Get the uplink port |
| 256 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 257 | if (uplinkPort == null) { |
| 258 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 262 | if (enableDhcpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 263 | processDhcpFilteringObjectives(port.deviceId(), port.port(), false); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 266 | Optional<VlanId> defaultVlan = Optional.empty(); |
| 267 | unprovisionSubscriber(port.deviceId(), uplinkPort.number(), port.port(), subscriber.cTag(), |
| 268 | subscriber.sTag(), defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 269 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 270 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 271 | processIgmpFilteringObjectives(port.deviceId(), port.port(), false); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 272 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 275 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 276 | @Override |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 277 | public Collection<Map.Entry<ConnectPoint, VlanId>> getSubscribers() { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 278 | ArrayList<Map.Entry<ConnectPoint, VlanId>> subs = new ArrayList<>(); |
| 279 | |
| 280 | // Get the subscribers for all the devices |
| 281 | // If the port is UNI, is enabled and exists in Sadis then copy it |
| 282 | for (Device d : deviceService.getDevices()) { |
| 283 | for (Port p: deviceService.getPorts(d.id())) { |
| 284 | if (isUniPort(d, p) && p.isEnabled()) { |
| 285 | ConnectPoint cp = new ConnectPoint(d.id(), p.number()); |
| 286 | |
| 287 | SubscriberAndDeviceInformation sub = getSubscriber(cp); |
| 288 | if (sub != null) { |
| 289 | subs.add(new AbstractMap.SimpleEntry(cp, sub.cTag())); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return subs; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 299 | public List<DeviceId> fetchOlts() { |
| 300 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 301 | List<DeviceId> olts = new ArrayList<>(); |
| 302 | Iterable<Device> devices = deviceService.getDevices(); |
| 303 | for (Device d : devices) { |
| 304 | String devSerialNo = d.serialNumber(); |
| 305 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 306 | |
| 307 | if (deviceInfo != null) { |
| 308 | // So this is indeed a OLT device |
| 309 | olts.add(d.id()); |
| 310 | } |
| 311 | } |
| 312 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 315 | private void initializeUni(Port port) { |
| 316 | DeviceId deviceId = (DeviceId) port.element().id(); |
| 317 | |
| 318 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, deviceId, port)); |
| 319 | |
| 320 | if (port.isEnabled()) { |
| 321 | processFilteringObjectives(deviceId, port.number(), true); |
| 322 | } |
| 323 | } |
| 324 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 325 | private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 326 | PortNumber subscriberPort, VlanId subscriberVlan, |
| 327 | VlanId deviceVlan, Optional<VlanId> defaultVlan) { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 328 | |
| 329 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 330 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 331 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 332 | ForwardingObjective.Builder upFwd = upBuilder(uplink, subscriberPort, |
| 333 | subscriberVlan, deviceVlan, |
| 334 | defaultVlan); |
| 335 | ForwardingObjective.Builder downFwd = downBuilder(uplink, subscriberPort, |
| 336 | subscriberVlan, deviceVlan, |
| 337 | defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 338 | |
| 339 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 340 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 341 | @Override |
| 342 | public void onSuccess(Objective objective) { |
| 343 | upFuture.complete(null); |
| 344 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 345 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 346 | @Override |
| 347 | public void onError(Objective objective, ObjectiveError error) { |
| 348 | upFuture.complete(error); |
| 349 | } |
| 350 | })); |
| 351 | |
| 352 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 353 | @Override |
| 354 | public void onSuccess(Objective objective) { |
| 355 | downFuture.complete(null); |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void onError(Objective objective, ObjectiveError error) { |
| 360 | downFuture.complete(error); |
| 361 | } |
| 362 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 363 | |
| 364 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 365 | if (upStatus == null && downStatus == null) { |
| 366 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
| 367 | deviceId, |
| 368 | deviceVlan, |
| 369 | subscriberVlan)); |
| 370 | } else if (downStatus != null) { |
| 371 | log.error("Subscriber with vlan {} on device {} " + |
| 372 | "on port {} failed downstream uninstallation: {}", |
| 373 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 374 | } else if (upStatus != null) { |
| 375 | log.error("Subscriber with vlan {} on device {} " + |
| 376 | "on port {} failed upstream uninstallation: {}", |
| 377 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 378 | } |
| 379 | }, oltInstallers); |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 380 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, |
| 384 | PortNumber subscriberPort, |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 385 | VlanId subscriberVlan, VlanId deviceVlan, |
| 386 | Optional<VlanId> defaultVlan) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 387 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 388 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 389 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 390 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 391 | ForwardingObjective.Builder upFwd = upBuilder(uplinkPort, subscriberPort, |
| 392 | subscriberVlan, deviceVlan, |
| 393 | defaultVlan); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 394 | |
| 395 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 396 | ForwardingObjective.Builder downFwd = downBuilder(uplinkPort, subscriberPort, |
| 397 | subscriberVlan, deviceVlan, |
| 398 | defaultVlan); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 399 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 400 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 401 | @Override |
| 402 | public void onSuccess(Objective objective) { |
| 403 | upFuture.complete(null); |
| 404 | } |
| 405 | |
| 406 | @Override |
| 407 | public void onError(Objective objective, ObjectiveError error) { |
| 408 | upFuture.complete(error); |
| 409 | } |
| 410 | })); |
| 411 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 412 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 413 | @Override |
| 414 | public void onSuccess(Objective objective) { |
| 415 | downFuture.complete(null); |
| 416 | } |
| 417 | |
| 418 | @Override |
| 419 | public void onError(Objective objective, ObjectiveError error) { |
| 420 | downFuture.complete(error); |
| 421 | } |
| 422 | })); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 423 | |
| 424 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 425 | if (upStatus == null && downStatus == null) { |
| 426 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
| 427 | deviceId, |
| 428 | deviceVlan, |
| 429 | subscriberVlan)); |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 430 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 431 | } else if (downStatus != null) { |
| 432 | log.error("Subscriber with vlan {} on device {} " + |
| 433 | "on port {} failed downstream installation: {}", |
| 434 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 435 | } else if (upStatus != null) { |
| 436 | log.error("Subscriber with vlan {} on device {} " + |
| 437 | "on port {} failed upstream installation: {}", |
| 438 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 439 | } |
| 440 | }, oltInstallers); |
| 441 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 442 | } |
| 443 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 444 | private ForwardingObjective.Builder downBuilder(PortNumber uplinkPort, |
| 445 | PortNumber subscriberPort, |
| 446 | VlanId subscriberVlan, |
| 447 | VlanId deviceVlan, |
| 448 | Optional<VlanId> defaultVlan) { |
| 449 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 450 | .matchVlanId(deviceVlan) |
| 451 | .matchInPort(uplinkPort) |
| 452 | .matchInnerVlanId(subscriberVlan) |
| 453 | .build(); |
| 454 | |
| 455 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 456 | .popVlan() |
| 457 | .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 458 | .setOutput(subscriberPort) |
| 459 | .build(); |
| 460 | |
| 461 | return DefaultForwardingObjective.builder() |
| 462 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 463 | .withPriority(1000) |
| 464 | .makePermanent() |
| 465 | .withSelector(downstream) |
| 466 | .fromApp(appId) |
| 467 | .withTreatment(downstreamTreatment); |
| 468 | } |
| 469 | |
| 470 | private ForwardingObjective.Builder upBuilder(PortNumber uplinkPort, |
| 471 | PortNumber subscriberPort, |
| 472 | VlanId subscriberVlan, |
| 473 | VlanId deviceVlan, |
| 474 | Optional<VlanId> defaultVlan) { |
| 475 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 476 | .matchVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 477 | .matchInPort(subscriberPort) |
| 478 | .build(); |
| 479 | |
| 480 | |
| 481 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
| 482 | .pushVlan() |
| 483 | .setVlanId(subscriberVlan) |
| 484 | .pushVlan() |
| 485 | .setVlanId(deviceVlan) |
| 486 | .setOutput(uplinkPort) |
| 487 | .build(); |
| 488 | |
| 489 | return DefaultForwardingObjective.builder() |
| 490 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 491 | .withPriority(1000) |
| 492 | .makePermanent() |
| 493 | .withSelector(upstream) |
| 494 | .fromApp(appId) |
| 495 | .withTreatment(upstreamTreatment); |
| 496 | } |
| 497 | |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 498 | private void processFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 499 | if (!mastershipService.isLocalMaster(devId)) { |
| 500 | return; |
| 501 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 502 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 503 | |
| 504 | FilteringObjective eapol = (install ? builder.permit() : builder.deny()) |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 505 | .withKey(Criteria.matchInPort(port)) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 506 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
| 507 | .withMeta(DefaultTrafficTreatment.builder() |
| 508 | .setOutput(PortNumber.CONTROLLER).build()) |
| 509 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 510 | .withPriority(10000) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 511 | .add(new ObjectiveContext() { |
| 512 | @Override |
| 513 | public void onSuccess(Objective objective) { |
| 514 | log.info("Eapol filter for {} on {} installed.", |
| 515 | devId, port); |
| 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public void onError(Objective objective, ObjectiveError error) { |
| 520 | log.info("Eapol filter for {} on {} failed because {}", |
| 521 | devId, port, error); |
| 522 | } |
| 523 | }); |
| 524 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 525 | flowObjectiveService.filter(devId, eapol); |
alshabib | 000b6fc | 2016-02-01 17:25:00 -0800 | [diff] [blame] | 526 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 529 | private void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 530 | if (!mastershipService.isLocalMaster(devId)) { |
| 531 | return; |
| 532 | } |
| 533 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 534 | |
| 535 | FilteringObjective dhcpUpstream = (install ? builder.permit() : builder.deny()) |
| 536 | .withKey(Criteria.matchInPort(port)) |
| 537 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 538 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP)) |
| 539 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(68))) |
| 540 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(67))) |
| 541 | .withMeta(DefaultTrafficTreatment.builder() |
| 542 | .setOutput(PortNumber.CONTROLLER).build()) |
| 543 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 544 | .withPriority(10000) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 545 | .add(new ObjectiveContext() { |
| 546 | @Override |
| 547 | public void onSuccess(Objective objective) { |
| 548 | log.info("DHCP filter for {} on {} installed.", |
| 549 | devId, port); |
| 550 | } |
| 551 | |
| 552 | @Override |
| 553 | public void onError(Objective objective, ObjectiveError error) { |
| 554 | log.info("DHCP filter for {} on {} failed because {}", |
| 555 | devId, port, error); |
| 556 | } |
| 557 | }); |
| 558 | |
| 559 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 560 | } |
| 561 | |
| 562 | private void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 563 | if (!mastershipService.isLocalMaster(devId)) { |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 568 | |
| 569 | builder = install ? builder.permit() : builder.deny(); |
| 570 | |
| 571 | FilteringObjective igmp = builder |
| 572 | .withKey(Criteria.matchInPort(port)) |
| 573 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 574 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 575 | .withMeta(DefaultTrafficTreatment.builder() |
| 576 | .setOutput(PortNumber.CONTROLLER).build()) |
| 577 | .fromApp(appId) |
| 578 | .withPriority(10000) |
| 579 | .add(new ObjectiveContext() { |
| 580 | @Override |
| 581 | public void onSuccess(Objective objective) { |
| 582 | log.info("Igmp filter for {} on {} installed.", |
| 583 | devId, port); |
| 584 | } |
| 585 | |
| 586 | @Override |
| 587 | public void onError(Objective objective, ObjectiveError error) { |
| 588 | log.info("Igmp filter for {} on {} failed because {}.", |
| 589 | devId, port, error); |
| 590 | } |
| 591 | }); |
| 592 | |
| 593 | flowObjectiveService.filter(devId, igmp); |
| 594 | } |
| 595 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 596 | /** |
| 597 | * Creates EAPOL flows on the UNIs, if device is |
| 598 | * present in Sadis config. |
| 599 | * |
| 600 | * @param dev Device to look for |
| 601 | */ |
| 602 | private void checkAndCreateEapolFlows(Device dev) { |
| 603 | // we create only for the ones we are master of |
| 604 | if (!mastershipService.isLocalMaster(dev.id())) { |
| 605 | return; |
| 606 | } |
| 607 | // check if this device is provisioned in Sadis |
| 608 | String devSerialNo = dev.serialNumber(); |
| 609 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 610 | log.debug("checkAndCreateEapolFlows: deviceInfo {}", deviceInfo); |
| 611 | |
| 612 | if (deviceInfo != null) { |
| 613 | // This is an OLT device as per Sadis, we need to create EAPOL flows |
| 614 | // on all it's UNIs |
| 615 | for (Port p : deviceService.getPorts(dev.id())) { |
| 616 | if (isUniPort(dev, p)) { |
| 617 | processFilteringObjectives(dev.id(), p.number(), true); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Get the uplink for of the OLT device. |
| 625 | * |
| 626 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 627 | * this logic needs to be changed |
| 628 | * |
| 629 | * @param dev Device to look for |
| 630 | * @return The uplink Port of the OLT |
| 631 | */ |
| 632 | private Port getUplinkPort(Device dev) { |
| 633 | // check if this device is provisioned in Sadis |
| 634 | String devSerialNo = dev.serialNumber(); |
| 635 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 636 | log.debug("getUplinkPort: deviceInfo {}", deviceInfo); |
| 637 | |
| 638 | if (deviceInfo != null) { |
| 639 | // Return the port that has been configured as the uplink port of this OLT in Sadis |
| 640 | for (Port p: deviceService.getPorts(dev.id())) { |
| 641 | if (p.number().toLong() == deviceInfo.uplinkPort()) { |
| 642 | log.debug("getUplinkPort: Found port {}", p); |
| 643 | return p; |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | log.debug("getUplinkPort: No uplink port found for OLT {}", dev); |
| 649 | return null; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Return the subscriber on a port. |
| 654 | * |
| 655 | * @param port On which to find the subscriber |
| 656 | * @return subscriber if found else null |
| 657 | */ |
| 658 | private SubscriberAndDeviceInformation getSubscriber(ConnectPoint port) { |
| 659 | String portName = deviceService.getPort(port).annotations() |
| 660 | .value(AnnotationKeys.PORT_NAME); |
| 661 | |
| 662 | return subsService.get(portName); |
| 663 | } |
| 664 | |
| 665 | private boolean isUniPort(Device d, Port p) { |
| 666 | Port ulPort = getUplinkPort(d); |
| 667 | if (ulPort != null) { |
| 668 | return (ulPort.number().toLong() != p.number().toLong()); |
| 669 | } |
| 670 | return false; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 671 | } |
| 672 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 673 | private class InternalDeviceListener implements DeviceListener { |
| 674 | @Override |
| 675 | public void event(DeviceEvent event) { |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 676 | DeviceId devId = event.subject().id(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 677 | Device dev = event.subject(); |
Jonathan Hart | 6960f82 | 2018-07-02 15:19:14 -0700 | [diff] [blame] | 678 | if (event.type() != DeviceEvent.Type.PORT_STATS_UPDATED) { |
| 679 | log.debug("Olt got {} event for {}", event.type(), event.subject()); |
| 680 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 681 | switch (event.type()) { |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 682 | //TODO: Port handling and bookkeeping should be improved once |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 683 | // olt firmware handles correct behaviour. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 684 | case PORT_ADDED: |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 685 | if (isUniPort(dev, event.port())) { |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 686 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
| 687 | |
| 688 | if (event.port().isEnabled()) { |
| 689 | processFilteringObjectives(devId, event.port().number(), true); |
| 690 | } |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 691 | } |
| 692 | break; |
| 693 | case PORT_REMOVED: |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 694 | String portName = event.port().annotations().value(AnnotationKeys.PORT_NAME); |
| 695 | SubscriberAndDeviceInformation subscriber = subsService.get(portName); |
| 696 | if (subscriber == null) { |
| 697 | log.warn("Subscriber {} not found", portName); |
| 698 | break; |
dvaddire | c63dc82 | 2017-10-05 22:25:13 +0530 | [diff] [blame] | 699 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 700 | |
| 701 | Port uplinkPort = getUplinkPort(dev); |
| 702 | if (uplinkPort == null) { |
| 703 | log.warn("No uplink port found for device {}", dev); |
| 704 | break; |
| 705 | } |
| 706 | |
| 707 | Optional<VlanId> defaultVlan = Optional.empty(); |
| 708 | unprovisionSubscriber(devId, uplinkPort.number(), |
| 709 | event.port().number(), |
| 710 | subscriber.cTag(), subscriber.sTag(), defaultVlan); |
| 711 | |
| 712 | if (isUniPort(dev, event.port())) { |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 713 | if (event.port().isEnabled()) { |
| 714 | processFilteringObjectives(devId, event.port().number(), false); |
| 715 | } |
| 716 | |
| 717 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 718 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 719 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 720 | break; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 721 | case PORT_UPDATED: |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 722 | if (!isUniPort(dev, event.port())) { |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 723 | break; |
| 724 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 725 | |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 726 | if (event.port().isEnabled()) { |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 727 | processFilteringObjectives(devId, event.port().number(), true); |
Jonathan Hart | 6960f82 | 2018-07-02 15:19:14 -0700 | [diff] [blame] | 728 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 729 | } else { |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 730 | processFilteringObjectives(devId, event.port().number(), false); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 731 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 732 | break; |
| 733 | case DEVICE_ADDED: |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 734 | post(new AccessDeviceEvent( |
| 735 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 736 | null, null)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 737 | |
| 738 | // Send UNI_ADDED events for all existing ports |
| 739 | deviceService.getPorts(devId).stream() |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 740 | .filter(p -> isUniPort(dev, p)) |
Jonathan Hart | 98de8a7 | 2018-05-30 17:47:01 -0700 | [diff] [blame] | 741 | .filter(Port::isEnabled) |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 742 | .forEach(p -> post(new AccessDeviceEvent( |
| 743 | AccessDeviceEvent.Type.UNI_ADDED, devId, p))); |
| 744 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 745 | checkAndCreateEapolFlows(dev); |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 746 | break; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 747 | case DEVICE_REMOVED: |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 748 | deviceService.getPorts(devId).stream() |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame^] | 749 | .filter(p -> isUniPort(dev, p)) |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 750 | .forEach(p -> post(new AccessDeviceEvent( |
| 751 | AccessDeviceEvent.Type.UNI_REMOVED, devId, p))); |
| 752 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 753 | post(new AccessDeviceEvent( |
| 754 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 755 | null, null)); |
| 756 | break; |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 757 | case DEVICE_AVAILABILITY_CHANGED: |
| 758 | if (deviceService.isAvailable(devId)) { |
| 759 | post(new AccessDeviceEvent( |
| 760 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 761 | null, null)); |
| 762 | } else { |
| 763 | post(new AccessDeviceEvent( |
| 764 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 765 | null, null)); |
| 766 | } |
| 767 | break; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 768 | case DEVICE_UPDATED: |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 769 | case DEVICE_SUSPENDED: |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 770 | case PORT_STATS_UPDATED: |
| 771 | default: |
| 772 | return; |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 777 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 778 | @Override |
| 779 | public void event(NetworkConfigEvent event) { |
| 780 | switch (event.type()) { |
| 781 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 782 | case CONFIG_ADDED: |
| 783 | case CONFIG_UPDATED: |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 784 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 785 | break; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 786 | case CONFIG_REGISTERED: |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 787 | case CONFIG_UNREGISTERED: |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 788 | break; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 789 | case CONFIG_REMOVED: |
| 790 | default: |
| 791 | break; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 792 | } |
| 793 | } |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 794 | |
| 795 | @Override |
| 796 | public boolean isRelevant(NetworkConfigEvent event) { |
| 797 | return event.configClass().equals(CONFIG_CLASS); |
| 798 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 799 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 800 | } |