alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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 | */ |
| 16 | package org.onosproject.olt; |
| 17 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 18 | import com.google.common.collect.Maps; |
| 19 | import com.google.common.collect.Sets; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | 0ccde6d | 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 | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Service; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.core.CoreService; |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 29 | import org.onosproject.event.AbstractListenerManager; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 30 | import org.onosproject.net.ConnectPoint; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.PortNumber; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 33 | import org.onosproject.net.config.ConfigFactory; |
| 34 | import org.onosproject.net.config.NetworkConfigEvent; |
| 35 | import org.onosproject.net.config.NetworkConfigListener; |
| 36 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 37 | import org.onosproject.net.config.basics.SubjectFactories; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 38 | import org.onosproject.net.device.DeviceEvent; |
| 39 | import org.onosproject.net.device.DeviceListener; |
| 40 | import org.onosproject.net.device.DeviceService; |
| 41 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 42 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
| 45 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 46 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 47 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 48 | import org.onosproject.net.flowobjective.Objective; |
| 49 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 50 | import org.onosproject.net.flowobjective.ObjectiveError; |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 51 | import org.onosproject.olt.api.AccessDeviceEvent; |
| 52 | import org.onosproject.olt.api.AccessDeviceListener; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 53 | import org.slf4j.Logger; |
| 54 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 55 | import java.util.Map; |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 56 | import java.util.Optional; |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 57 | import java.util.Set; |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 58 | import java.util.concurrent.CompletableFuture; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 59 | import java.util.concurrent.ConcurrentHashMap; |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 60 | import java.util.concurrent.ExecutorService; |
| 61 | import java.util.concurrent.Executors; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 62 | |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 63 | import static org.onlab.util.Tools.groupedThreads; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 64 | import static org.slf4j.LoggerFactory.getLogger; |
| 65 | |
| 66 | /** |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 67 | * Provisions rules on access devices. |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 68 | */ |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 69 | @Service |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 70 | @Component(immediate = true) |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 71 | public class Olt |
| 72 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 73 | implements AccessDeviceService { |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 74 | private final Logger log = getLogger(getClass()); |
| 75 | |
| 76 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 77 | protected FlowObjectiveService flowObjectiveService; |
| 78 | |
| 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 80 | protected DeviceService deviceService; |
| 81 | |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected CoreService coreService; |
| 84 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected NetworkConfigRegistry networkConfig; |
| 87 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 88 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 89 | |
| 90 | private ApplicationId appId; |
| 91 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 92 | private static final VlanId DEFAULT_VLAN = VlanId.vlanId((short) 0); |
alshabib | 17ff25f | 2015-06-01 10:57:31 -0700 | [diff] [blame] | 93 | |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 94 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 95 | groupedThreads("onos/olt-service", |
| 96 | "olt-installer-%d")); |
alshabib | 1af3b71 | 2015-06-05 14:55:24 -0700 | [diff] [blame] | 97 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 98 | private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>(); |
| 99 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 100 | private Map<ConnectPoint, Set<ForwardingObjective.Builder>> objectives = |
| 101 | Maps.newConcurrentMap(); |
| 102 | |
| 103 | private Map<ConnectPoint, VlanId> subscribers = Maps.newConcurrentMap(); |
| 104 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 105 | private InternalNetworkConfigListener configListener = |
| 106 | new InternalNetworkConfigListener(); |
| 107 | private static final Class<AccessDeviceConfig> CONFIG_CLASS = |
| 108 | AccessDeviceConfig.class; |
| 109 | |
| 110 | private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory = |
| 111 | new ConfigFactory<DeviceId, AccessDeviceConfig>( |
| 112 | SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") { |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 113 | @Override |
| 114 | public AccessDeviceConfig createConfig() { |
| 115 | return new AccessDeviceConfig(); |
| 116 | } |
| 117 | }; |
| 118 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 119 | |
| 120 | @Activate |
| 121 | public void activate() { |
alshabib | 1af3b71 | 2015-06-05 14:55:24 -0700 | [diff] [blame] | 122 | appId = coreService.registerApplication("org.onosproject.olt"); |
alshabib | beb2dc9 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 123 | |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 124 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 125 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 126 | networkConfig.registerConfigFactory(configFactory); |
| 127 | networkConfig.addListener(configListener); |
| 128 | |
| 129 | networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach( |
| 130 | subject -> { |
| 131 | AccessDeviceConfig config = networkConfig.getConfig(subject, AccessDeviceConfig.class); |
| 132 | if (config != null) { |
| 133 | AccessDeviceData data = config.getOlt(); |
| 134 | oltData.put(data.deviceId(), data); |
| 135 | } |
| 136 | } |
| 137 | ); |
| 138 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 139 | log.info("Started with Application ID {}", appId.id()); |
| 140 | } |
| 141 | |
| 142 | @Deactivate |
| 143 | public void deactivate() { |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 144 | networkConfig.removeListener(configListener); |
| 145 | networkConfig.unregisterConfigFactory(configFactory); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 146 | log.info("Stopped"); |
| 147 | } |
| 148 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 149 | @Override |
| 150 | public void provisionSubscriber(ConnectPoint port, VlanId vlan) { |
| 151 | AccessDeviceData olt = oltData.get(port.deviceId()); |
| 152 | |
| 153 | if (olt == null) { |
| 154 | log.warn("No data found for OLT device {}", port.deviceId()); |
| 155 | return; |
| 156 | } |
| 157 | |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 158 | provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(), |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 159 | olt.defaultVlan()); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void removeSubscriber(ConnectPoint port) { |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 164 | AccessDeviceData olt = oltData.get(port.deviceId()); |
| 165 | |
| 166 | if (olt == null) { |
| 167 | log.warn("No data found for OLT device {}", port.deviceId()); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | unprovisionSubscriber(olt.deviceId(), olt.uplink(), port.port(), olt.vlan()); |
| 172 | |
| 173 | } |
| 174 | |
| 175 | private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, |
| 176 | PortNumber subscriberPort, VlanId deviceVlan) { |
| 177 | |
| 178 | //FIXME: This method is slightly ugly but it'll do until we have a better |
| 179 | // way to remove flows from the flow store. |
| 180 | |
| 181 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 182 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 183 | |
| 184 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 185 | |
| 186 | VlanId subscriberVlan = subscribers.remove(cp); |
| 187 | |
| 188 | Set<ForwardingObjective.Builder> fwds = objectives.remove(cp); |
| 189 | |
| 190 | if (fwds == null || fwds.size() != 2) { |
| 191 | log.warn("Unknown or incomplete subscriber at {}", cp); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | fwds.stream().forEach( |
| 197 | fwd -> flowObjectiveService.forward(deviceId, |
| 198 | fwd.remove(new ObjectiveContext() { |
| 199 | @Override |
| 200 | public void onSuccess(Objective objective) { |
| 201 | upFuture.complete(null); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void onError(Objective objective, ObjectiveError error) { |
| 206 | upFuture.complete(error); |
| 207 | } |
| 208 | }))); |
| 209 | |
| 210 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 211 | if (upStatus == null && downStatus == null) { |
| 212 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
| 213 | deviceId, |
| 214 | deviceVlan, |
| 215 | subscriberVlan)); |
| 216 | } else if (downStatus != null) { |
| 217 | log.error("Subscriber with vlan {} on device {} " + |
| 218 | "on port {} failed downstream uninstallation: {}", |
| 219 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 220 | } else if (upStatus != null) { |
| 221 | log.error("Subscriber with vlan {} on device {} " + |
| 222 | "on port {} failed upstream uninstallation: {}", |
| 223 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 224 | } |
| 225 | }, oltInstallers); |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 226 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, |
| 230 | PortNumber subscriberPort, |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 231 | VlanId subscriberVlan, VlanId deviceVlan, |
| 232 | Optional<VlanId> defaultVlan) { |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 233 | |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 234 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 235 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 236 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 237 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 238 | .matchVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN) |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 239 | .matchInPort(subscriberPort) |
| 240 | .build(); |
| 241 | |
| 242 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 243 | .matchVlanId(deviceVlan) |
| 244 | .matchInPort(uplinkPort) |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 245 | .matchInnerVlanId(subscriberVlan) |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 246 | .build(); |
| 247 | |
| 248 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 249 | .pushVlan() |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 250 | .setVlanId(subscriberVlan) |
| 251 | .pushVlan() |
| 252 | .setVlanId(deviceVlan) |
| 253 | .setOutput(uplinkPort) |
| 254 | .build(); |
| 255 | |
| 256 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 257 | .popVlan() |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 258 | .setVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN) |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 259 | .setOutput(subscriberPort) |
| 260 | .build(); |
| 261 | |
| 262 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 263 | ForwardingObjective.Builder upFwd = DefaultForwardingObjective.builder() |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 264 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 265 | .withPriority(1000) |
| 266 | .makePermanent() |
| 267 | .withSelector(upstream) |
| 268 | .fromApp(appId) |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 269 | .withTreatment(upstreamTreatment); |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 270 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 271 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 272 | ForwardingObjective.Builder downFwd = DefaultForwardingObjective.builder() |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 273 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 274 | .withPriority(1000) |
| 275 | .makePermanent() |
| 276 | .withSelector(downstream) |
| 277 | .fromApp(appId) |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 278 | .withTreatment(downstreamTreatment); |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 279 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 280 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 281 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 282 | subscribers.put(cp, subscriberVlan); |
| 283 | objectives.put(cp, Sets.newHashSet(upFwd, downFwd)); |
| 284 | |
| 285 | |
| 286 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 287 | @Override |
| 288 | public void onSuccess(Objective objective) { |
| 289 | upFuture.complete(null); |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void onError(Objective objective, ObjectiveError error) { |
| 294 | upFuture.complete(error); |
| 295 | } |
| 296 | })); |
| 297 | |
| 298 | |
| 299 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 300 | @Override |
| 301 | public void onSuccess(Objective objective) { |
| 302 | downFuture.complete(null); |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public void onError(Objective objective, ObjectiveError error) { |
| 307 | downFuture.complete(error); |
| 308 | } |
| 309 | })); |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 310 | |
| 311 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 312 | if (upStatus == null && downStatus == null) { |
| 313 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
| 314 | deviceId, |
| 315 | deviceVlan, |
| 316 | subscriberVlan)); |
| 317 | } else if (downStatus != null) { |
| 318 | log.error("Subscriber with vlan {} on device {} " + |
| 319 | "on port {} failed downstream installation: {}", |
| 320 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 321 | } else if (upStatus != null) { |
| 322 | log.error("Subscriber with vlan {} on device {} " + |
| 323 | "on port {} failed upstream installation: {}", |
| 324 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 325 | } |
| 326 | }, oltInstallers); |
| 327 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 328 | } |
| 329 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 330 | private class InternalDeviceListener implements DeviceListener { |
| 331 | @Override |
| 332 | public void event(DeviceEvent event) { |
alshabib | 49cadbd | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 333 | DeviceId devId = event.subject().id(); |
| 334 | if (!oltData.containsKey(devId)) { |
| 335 | log.debug("Device {} is not an OLT", devId); |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 336 | return; |
| 337 | } |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 338 | switch (event.type()) { |
| 339 | case PORT_ADDED: |
| 340 | case PORT_UPDATED: |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 341 | break; |
| 342 | case DEVICE_ADDED: |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 343 | post(new AccessDeviceEvent( |
| 344 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 345 | null, null)); |
| 346 | break; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 347 | case DEVICE_REMOVED: |
alshabib | 6b139b4 | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 348 | post(new AccessDeviceEvent( |
| 349 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 350 | null, null)); |
| 351 | break; |
| 352 | case DEVICE_UPDATED: |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 353 | case DEVICE_SUSPENDED: |
| 354 | case DEVICE_AVAILABILITY_CHANGED: |
| 355 | case PORT_REMOVED: |
| 356 | case PORT_STATS_UPDATED: |
| 357 | default: |
| 358 | return; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 363 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 364 | @Override |
| 365 | public void event(NetworkConfigEvent event) { |
| 366 | switch (event.type()) { |
| 367 | |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 368 | case CONFIG_ADDED: |
| 369 | case CONFIG_UPDATED: |
| 370 | if (event.configClass().equals(CONFIG_CLASS)) { |
| 371 | AccessDeviceConfig config = |
| 372 | networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS); |
| 373 | if (config != null) { |
| 374 | oltData.put(config.getOlt().deviceId(), config.getOlt()); |
| 375 | } |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 376 | } |
alshabib | 02cbe6a | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 377 | break; |
| 378 | case CONFIG_UNREGISTERED: |
| 379 | case CONFIG_REMOVED: |
| 380 | default: |
| 381 | break; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | } |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 385 | |
| 386 | } |