blob: fa9c2a4f823253c560bc9ff74637c249321ad5ae [file] [log] [blame]
alshabibf0e7e702015-05-30 18:22:36 -07001/*
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 */
Srikanth Vavilapalli2e684912016-01-16 19:21:59 -080016package org.onosproject.olt.impl;
alshabibf0e7e702015-05-30 18:22:36 -070017
alshabibbf23a1f2016-01-14 17:27:11 -080018import com.google.common.collect.Maps;
19import com.google.common.collect.Sets;
alshabibf0e7e702015-05-30 18:22:36 -070020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
alshabibf0e7e702015-05-30 18:22:36 -070023import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
Jonathan Harte533a422015-10-20 17:31:24 -070025import org.apache.felix.scr.annotations.Service;
alshabibdec2e252016-01-15 12:20:25 -080026import org.onlab.packet.EthType;
alshabibf0e7e702015-05-30 18:22:36 -070027import org.onlab.packet.VlanId;
alshabibf0e7e702015-05-30 18:22:36 -070028import org.onosproject.core.ApplicationId;
29import org.onosproject.core.CoreService;
alshabib8e4fd2f2016-01-12 15:55:53 -080030import org.onosproject.event.AbstractListenerManager;
Jonathan Harte533a422015-10-20 17:31:24 -070031import org.onosproject.net.ConnectPoint;
alshabibf0e7e702015-05-30 18:22:36 -070032import org.onosproject.net.DeviceId;
alshabibdec2e252016-01-15 12:20:25 -080033import org.onosproject.net.Port;
alshabibf0e7e702015-05-30 18:22:36 -070034import org.onosproject.net.PortNumber;
Jonathan Harte533a422015-10-20 17:31:24 -070035import org.onosproject.net.config.ConfigFactory;
36import org.onosproject.net.config.NetworkConfigEvent;
37import org.onosproject.net.config.NetworkConfigListener;
38import org.onosproject.net.config.NetworkConfigRegistry;
39import org.onosproject.net.config.basics.SubjectFactories;
alshabibf0e7e702015-05-30 18:22:36 -070040import org.onosproject.net.device.DeviceEvent;
41import org.onosproject.net.device.DeviceListener;
42import org.onosproject.net.device.DeviceService;
43import org.onosproject.net.flow.DefaultTrafficSelector;
44import org.onosproject.net.flow.DefaultTrafficTreatment;
45import org.onosproject.net.flow.TrafficSelector;
46import org.onosproject.net.flow.TrafficTreatment;
alshabibdec2e252016-01-15 12:20:25 -080047import org.onosproject.net.flow.criteria.Criteria;
48import org.onosproject.net.flowobjective.DefaultFilteringObjective;
alshabibf0e7e702015-05-30 18:22:36 -070049import org.onosproject.net.flowobjective.DefaultForwardingObjective;
alshabibdec2e252016-01-15 12:20:25 -080050import org.onosproject.net.flowobjective.FilteringObjective;
alshabibf0e7e702015-05-30 18:22:36 -070051import org.onosproject.net.flowobjective.FlowObjectiveService;
52import org.onosproject.net.flowobjective.ForwardingObjective;
alshabib3ea82642016-01-12 18:06:53 -080053import org.onosproject.net.flowobjective.Objective;
54import org.onosproject.net.flowobjective.ObjectiveContext;
55import org.onosproject.net.flowobjective.ObjectiveError;
alshabib000b6fc2016-02-01 17:25:00 -080056import org.onosproject.olt.AccessDeviceConfig;
57import org.onosproject.olt.AccessDeviceData;
Srikanth Vavilapalli2e684912016-01-16 19:21:59 -080058import org.onosproject.olt.AccessDeviceEvent;
59import org.onosproject.olt.AccessDeviceListener;
60import org.onosproject.olt.AccessDeviceService;
alshabibf0e7e702015-05-30 18:22:36 -070061import org.slf4j.Logger;
62
alshabibbb83aa22016-02-10 15:08:23 -080063import java.util.List;
Jonathan Harte533a422015-10-20 17:31:24 -070064import java.util.Map;
Jonathan Hart52998382015-11-10 16:09:22 -080065import java.util.Optional;
alshabibbf23a1f2016-01-14 17:27:11 -080066import java.util.Set;
alshabib3ea82642016-01-12 18:06:53 -080067import java.util.concurrent.CompletableFuture;
Jonathan Harte533a422015-10-20 17:31:24 -070068import java.util.concurrent.ConcurrentHashMap;
alshabib3ea82642016-01-12 18:06:53 -080069import java.util.concurrent.ExecutorService;
70import java.util.concurrent.Executors;
alshabibf0e7e702015-05-30 18:22:36 -070071
alshabib3ea82642016-01-12 18:06:53 -080072import static org.onlab.util.Tools.groupedThreads;
alshabibf0e7e702015-05-30 18:22:36 -070073import static org.slf4j.LoggerFactory.getLogger;
74
75/**
Jonathan Harte533a422015-10-20 17:31:24 -070076 * Provisions rules on access devices.
alshabibf0e7e702015-05-30 18:22:36 -070077 */
Jonathan Harte533a422015-10-20 17:31:24 -070078@Service
alshabibf0e7e702015-05-30 18:22:36 -070079@Component(immediate = true)
alshabib8e4fd2f2016-01-12 15:55:53 -080080public class Olt
81 extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener>
82 implements AccessDeviceService {
alshabibf0e7e702015-05-30 18:22:36 -070083 private final Logger log = getLogger(getClass());
84
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
86 protected FlowObjectiveService flowObjectiveService;
87
88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 protected DeviceService deviceService;
90
91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 protected CoreService coreService;
93
Jonathan Harte533a422015-10-20 17:31:24 -070094 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
95 protected NetworkConfigRegistry networkConfig;
96
alshabibf0e7e702015-05-30 18:22:36 -070097 private final DeviceListener deviceListener = new InternalDeviceListener();
98
99 private ApplicationId appId;
100
Jonathan Harte533a422015-10-20 17:31:24 -0700101 private static final VlanId DEFAULT_VLAN = VlanId.vlanId((short) 0);
alshabibcf3eb952015-06-01 10:57:31 -0700102
alshabib3ea82642016-01-12 18:06:53 -0800103 private ExecutorService oltInstallers = Executors.newFixedThreadPool(4,
alshabibbf23a1f2016-01-14 17:27:11 -0800104 groupedThreads("onos/olt-service",
105 "olt-installer-%d"));
alshabib4ae2b402015-06-05 14:55:24 -0700106
Jonathan Harte533a422015-10-20 17:31:24 -0700107 private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
108
alshabibbf23a1f2016-01-14 17:27:11 -0800109 private Map<ConnectPoint, Set<ForwardingObjective.Builder>> objectives =
110 Maps.newConcurrentMap();
111
112 private Map<ConnectPoint, VlanId> subscribers = Maps.newConcurrentMap();
113
Jonathan Harte533a422015-10-20 17:31:24 -0700114 private InternalNetworkConfigListener configListener =
115 new InternalNetworkConfigListener();
116 private static final Class<AccessDeviceConfig> CONFIG_CLASS =
117 AccessDeviceConfig.class;
118
119 private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory =
120 new ConfigFactory<DeviceId, AccessDeviceConfig>(
121 SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") {
alshabibbf23a1f2016-01-14 17:27:11 -0800122 @Override
123 public AccessDeviceConfig createConfig() {
124 return new AccessDeviceConfig();
125 }
126 };
127
alshabibf0e7e702015-05-30 18:22:36 -0700128
129 @Activate
130 public void activate() {
alshabib4ae2b402015-06-05 14:55:24 -0700131 appId = coreService.registerApplication("org.onosproject.olt");
alshabibc4dfe852015-06-05 13:35:13 -0700132
alshabib8e4fd2f2016-01-12 15:55:53 -0800133 eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry);
134
Jonathan Harte533a422015-10-20 17:31:24 -0700135 networkConfig.registerConfigFactory(configFactory);
136 networkConfig.addListener(configListener);
137
alshabibdec2e252016-01-15 12:20:25 -0800138
Jonathan Harte533a422015-10-20 17:31:24 -0700139 networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach(
140 subject -> {
141 AccessDeviceConfig config = networkConfig.getConfig(subject, AccessDeviceConfig.class);
142 if (config != null) {
143 AccessDeviceData data = config.getOlt();
144 oltData.put(data.deviceId(), data);
145 }
146 }
147 );
148
alshabibdec2e252016-01-15 12:20:25 -0800149 oltData.keySet().stream()
150 .flatMap(did -> deviceService.getPorts(did).stream())
alshabib62e9ce72016-02-11 17:31:36 -0800151 .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number()))
alshabibdec2e252016-01-15 12:20:25 -0800152 .filter(p -> p.isEnabled())
alshabib50d9fc52016-02-12 15:47:20 -0800153 .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(),
154 p.number(), true));
alshabibdec2e252016-01-15 12:20:25 -0800155
alshabibba357492016-01-27 13:49:46 -0800156 deviceService.addListener(deviceListener);
157
alshabibf0e7e702015-05-30 18:22:36 -0700158 log.info("Started with Application ID {}", appId.id());
159 }
160
161 @Deactivate
162 public void deactivate() {
alshabib62e9ce72016-02-11 17:31:36 -0800163 deviceService.removeListener(deviceListener);
Jonathan Harte533a422015-10-20 17:31:24 -0700164 networkConfig.removeListener(configListener);
165 networkConfig.unregisterConfigFactory(configFactory);
alshabibf0e7e702015-05-30 18:22:36 -0700166 log.info("Stopped");
167 }
168
Jonathan Harte533a422015-10-20 17:31:24 -0700169 @Override
170 public void provisionSubscriber(ConnectPoint port, VlanId vlan) {
171 AccessDeviceData olt = oltData.get(port.deviceId());
172
173 if (olt == null) {
174 log.warn("No data found for OLT device {}", port.deviceId());
175 return;
176 }
177
Jonathan Hart52998382015-11-10 16:09:22 -0800178 provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(),
alshabibb7a9e172016-01-13 11:23:53 -0800179 olt.defaultVlan());
180 }
181
182 @Override
183 public void removeSubscriber(ConnectPoint port) {
alshabibbf23a1f2016-01-14 17:27:11 -0800184 AccessDeviceData olt = oltData.get(port.deviceId());
185
186 if (olt == null) {
187 log.warn("No data found for OLT device {}", port.deviceId());
188 return;
189 }
190
191 unprovisionSubscriber(olt.deviceId(), olt.uplink(), port.port(), olt.vlan());
192
193 }
194
195 private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink,
196 PortNumber subscriberPort, VlanId deviceVlan) {
197
198 //FIXME: This method is slightly ugly but it'll do until we have a better
199 // way to remove flows from the flow store.
200
201 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
202 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
203
204 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
205
206 VlanId subscriberVlan = subscribers.remove(cp);
207
208 Set<ForwardingObjective.Builder> fwds = objectives.remove(cp);
209
210 if (fwds == null || fwds.size() != 2) {
211 log.warn("Unknown or incomplete subscriber at {}", cp);
212 return;
213 }
214
215
216 fwds.stream().forEach(
217 fwd -> flowObjectiveService.forward(deviceId,
alshabibdec2e252016-01-15 12:20:25 -0800218 fwd.remove(new ObjectiveContext() {
219 @Override
220 public void onSuccess(Objective objective) {
221 upFuture.complete(null);
222 }
alshabibbf23a1f2016-01-14 17:27:11 -0800223
alshabibdec2e252016-01-15 12:20:25 -0800224 @Override
225 public void onError(Objective objective, ObjectiveError error) {
226 upFuture.complete(error);
227 }
228 })));
alshabibbf23a1f2016-01-14 17:27:11 -0800229
230 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
231 if (upStatus == null && downStatus == null) {
232 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED,
233 deviceId,
234 deviceVlan,
235 subscriberVlan));
236 } else if (downStatus != null) {
237 log.error("Subscriber with vlan {} on device {} " +
238 "on port {} failed downstream uninstallation: {}",
239 subscriberVlan, deviceId, subscriberPort, downStatus);
240 } else if (upStatus != null) {
241 log.error("Subscriber with vlan {} on device {} " +
242 "on port {} failed upstream uninstallation: {}",
243 subscriberVlan, deviceId, subscriberPort, upStatus);
244 }
245 }, oltInstallers);
alshabibb7a9e172016-01-13 11:23:53 -0800246
Jonathan Harte533a422015-10-20 17:31:24 -0700247 }
248
249 private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort,
250 PortNumber subscriberPort,
Jonathan Hart52998382015-11-10 16:09:22 -0800251 VlanId subscriberVlan, VlanId deviceVlan,
252 Optional<VlanId> defaultVlan) {
Jonathan Harte533a422015-10-20 17:31:24 -0700253
alshabib3ea82642016-01-12 18:06:53 -0800254 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
255 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
256
Jonathan Harte533a422015-10-20 17:31:24 -0700257 TrafficSelector upstream = DefaultTrafficSelector.builder()
Sho SHIMIZU004776c2016-02-12 18:38:29 -0800258 .matchVlanId(defaultVlan.orElse(DEFAULT_VLAN))
Jonathan Harte533a422015-10-20 17:31:24 -0700259 .matchInPort(subscriberPort)
260 .build();
261
262 TrafficSelector downstream = DefaultTrafficSelector.builder()
263 .matchVlanId(deviceVlan)
264 .matchInPort(uplinkPort)
alshabibb7a9e172016-01-13 11:23:53 -0800265 .matchInnerVlanId(subscriberVlan)
Jonathan Harte533a422015-10-20 17:31:24 -0700266 .build();
267
268 TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
alshabib3ea82642016-01-12 18:06:53 -0800269 .pushVlan()
Jonathan Harte533a422015-10-20 17:31:24 -0700270 .setVlanId(subscriberVlan)
271 .pushVlan()
272 .setVlanId(deviceVlan)
273 .setOutput(uplinkPort)
274 .build();
275
276 TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
277 .popVlan()
Sho SHIMIZU004776c2016-02-12 18:38:29 -0800278 .setVlanId(defaultVlan.orElse(DEFAULT_VLAN))
Jonathan Harte533a422015-10-20 17:31:24 -0700279 .setOutput(subscriberPort)
280 .build();
281
282
alshabibbf23a1f2016-01-14 17:27:11 -0800283 ForwardingObjective.Builder upFwd = DefaultForwardingObjective.builder()
Jonathan Harte533a422015-10-20 17:31:24 -0700284 .withFlag(ForwardingObjective.Flag.VERSATILE)
285 .withPriority(1000)
286 .makePermanent()
287 .withSelector(upstream)
288 .fromApp(appId)
alshabibbf23a1f2016-01-14 17:27:11 -0800289 .withTreatment(upstreamTreatment);
alshabib3ea82642016-01-12 18:06:53 -0800290
Jonathan Harte533a422015-10-20 17:31:24 -0700291
alshabibbf23a1f2016-01-14 17:27:11 -0800292 ForwardingObjective.Builder downFwd = DefaultForwardingObjective.builder()
Jonathan Harte533a422015-10-20 17:31:24 -0700293 .withFlag(ForwardingObjective.Flag.VERSATILE)
294 .withPriority(1000)
295 .makePermanent()
296 .withSelector(downstream)
297 .fromApp(appId)
alshabibbf23a1f2016-01-14 17:27:11 -0800298 .withTreatment(downstreamTreatment);
alshabib3ea82642016-01-12 18:06:53 -0800299
alshabibbf23a1f2016-01-14 17:27:11 -0800300 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
Jonathan Harte533a422015-10-20 17:31:24 -0700301
alshabibbf23a1f2016-01-14 17:27:11 -0800302 subscribers.put(cp, subscriberVlan);
303 objectives.put(cp, Sets.newHashSet(upFwd, downFwd));
304
305
306 flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() {
307 @Override
308 public void onSuccess(Objective objective) {
309 upFuture.complete(null);
310 }
311
312 @Override
313 public void onError(Objective objective, ObjectiveError error) {
314 upFuture.complete(error);
315 }
316 }));
317
318
319 flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() {
320 @Override
321 public void onSuccess(Objective objective) {
322 downFuture.complete(null);
323 }
324
325 @Override
326 public void onError(Objective objective, ObjectiveError error) {
327 downFuture.complete(error);
328 }
329 }));
alshabib3ea82642016-01-12 18:06:53 -0800330
331 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
332 if (upStatus == null && downStatus == null) {
333 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED,
334 deviceId,
335 deviceVlan,
336 subscriberVlan));
alshabib50d9fc52016-02-12 15:47:20 -0800337
alshabib3ea82642016-01-12 18:06:53 -0800338 } else if (downStatus != null) {
339 log.error("Subscriber with vlan {} on device {} " +
340 "on port {} failed downstream installation: {}",
341 subscriberVlan, deviceId, subscriberPort, downStatus);
342 } else if (upStatus != null) {
343 log.error("Subscriber with vlan {} on device {} " +
344 "on port {} failed upstream installation: {}",
345 subscriberVlan, deviceId, subscriberPort, upStatus);
346 }
347 }, oltInstallers);
348
Jonathan Harte533a422015-10-20 17:31:24 -0700349 }
350
alshabib50d9fc52016-02-12 15:47:20 -0800351 private void processFilteringObjectives(DeviceId devId, PortNumber port, boolean install) {
alshabibbb83aa22016-02-10 15:08:23 -0800352 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
353
354 FilteringObjective eapol = (install ? builder.permit() : builder.deny())
alshabib50d9fc52016-02-12 15:47:20 -0800355 .withKey(Criteria.matchInPort(port))
alshabibdec2e252016-01-15 12:20:25 -0800356 .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType()))
357 .withMeta(DefaultTrafficTreatment.builder()
358 .setOutput(PortNumber.CONTROLLER).build())
359 .fromApp(appId)
360 .withPriority(1000)
361 .add(new ObjectiveContext() {
362 @Override
363 public void onSuccess(Objective objective) {
364 log.info("Eapol filter for {} on {} installed.",
365 devId, port);
366 }
367
368 @Override
369 public void onError(Objective objective, ObjectiveError error) {
370 log.info("Eapol filter for {} on {} failed because {}",
371 devId, port, error);
372 }
373 });
374
alshabibdec2e252016-01-15 12:20:25 -0800375 flowObjectiveService.filter(devId, eapol);
alshabib000b6fc2016-02-01 17:25:00 -0800376
alshabibdec2e252016-01-15 12:20:25 -0800377 }
378
alshabibf0e7e702015-05-30 18:22:36 -0700379 private class InternalDeviceListener implements DeviceListener {
380 @Override
381 public void event(DeviceEvent event) {
alshabib3ea82642016-01-12 18:06:53 -0800382 DeviceId devId = event.subject().id();
383 if (!oltData.containsKey(devId)) {
384 log.debug("Device {} is not an OLT", devId);
alshabib8e4fd2f2016-01-12 15:55:53 -0800385 return;
386 }
alshabibf0e7e702015-05-30 18:22:36 -0700387 switch (event.type()) {
alshabibdec2e252016-01-15 12:20:25 -0800388 //TODO: Port handling and bookkeeping should be inproved once
389 // olt firmware handles correct behaviour.
alshabibf0e7e702015-05-30 18:22:36 -0700390 case PORT_ADDED:
alshabibbb83aa22016-02-10 15:08:23 -0800391 if (!oltData.get(devId).uplink().equals(event.port().number()) &&
392 event.port().isEnabled()) {
alshabib50d9fc52016-02-12 15:47:20 -0800393 processFilteringObjectives(devId, event.port().number(), true);
alshabibdec2e252016-01-15 12:20:25 -0800394 }
395 break;
396 case PORT_REMOVED:
397 AccessDeviceData olt = oltData.get(devId);
398 unprovisionSubscriber(devId, olt.uplink(),
399 event.port().number(),
400 olt.vlan());
alshabibbb83aa22016-02-10 15:08:23 -0800401 if (!oltData.get(devId).uplink().equals(event.port().number()) &&
402 event.port().isEnabled()) {
alshabib50d9fc52016-02-12 15:47:20 -0800403 processFilteringObjectives(devId, event.port().number(), false);
alshabibbb83aa22016-02-10 15:08:23 -0800404 }
alshabibdec2e252016-01-15 12:20:25 -0800405 break;
alshabibf0e7e702015-05-30 18:22:36 -0700406 case PORT_UPDATED:
alshabibbb83aa22016-02-10 15:08:23 -0800407 if (oltData.get(devId).uplink().equals(event.port().number())) {
408 break;
409 }
410 if (event.port().isEnabled()) {
alshabib50d9fc52016-02-12 15:47:20 -0800411 processFilteringObjectives(devId, event.port().number(), true);
alshabibbb83aa22016-02-10 15:08:23 -0800412 } else {
alshabib50d9fc52016-02-12 15:47:20 -0800413 processFilteringObjectives(devId, event.port().number(), false);
alshabibbb83aa22016-02-10 15:08:23 -0800414 }
alshabibf0e7e702015-05-30 18:22:36 -0700415 break;
416 case DEVICE_ADDED:
alshabib8e4fd2f2016-01-12 15:55:53 -0800417 post(new AccessDeviceEvent(
418 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
419 null, null));
420 break;
alshabibf0e7e702015-05-30 18:22:36 -0700421 case DEVICE_REMOVED:
alshabib8e4fd2f2016-01-12 15:55:53 -0800422 post(new AccessDeviceEvent(
423 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
424 null, null));
425 break;
alshabib7c190012016-02-09 18:22:33 -0800426 case DEVICE_AVAILABILITY_CHANGED:
427 if (deviceService.isAvailable(devId)) {
428 post(new AccessDeviceEvent(
429 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
430 null, null));
431 } else {
432 post(new AccessDeviceEvent(
433 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
434 null, null));
435 }
436 break;
alshabib8e4fd2f2016-01-12 15:55:53 -0800437 case DEVICE_UPDATED:
alshabibf0e7e702015-05-30 18:22:36 -0700438 case DEVICE_SUSPENDED:
alshabibf0e7e702015-05-30 18:22:36 -0700439 case PORT_STATS_UPDATED:
440 default:
441 return;
442 }
443 }
444 }
445
Jonathan Harte533a422015-10-20 17:31:24 -0700446 private class InternalNetworkConfigListener implements NetworkConfigListener {
447 @Override
448 public void event(NetworkConfigEvent event) {
449 switch (event.type()) {
450
alshabibbf23a1f2016-01-14 17:27:11 -0800451 case CONFIG_ADDED:
452 case CONFIG_UPDATED:
453 if (event.configClass().equals(CONFIG_CLASS)) {
454 AccessDeviceConfig config =
455 networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
456 if (config != null) {
457 oltData.put(config.getOlt().deviceId(), config.getOlt());
alshabibbb83aa22016-02-10 15:08:23 -0800458 provisionDefaultFlows((DeviceId) event.subject());
alshabibbf23a1f2016-01-14 17:27:11 -0800459 }
Jonathan Harte533a422015-10-20 17:31:24 -0700460 }
alshabibbf23a1f2016-01-14 17:27:11 -0800461 break;
462 case CONFIG_UNREGISTERED:
463 case CONFIG_REMOVED:
464 default:
465 break;
Jonathan Harte533a422015-10-20 17:31:24 -0700466 }
467 }
468 }
alshabibf0e7e702015-05-30 18:22:36 -0700469
alshabibbb83aa22016-02-10 15:08:23 -0800470 private void provisionDefaultFlows(DeviceId deviceId) {
471 List<Port> ports = deviceService.getPorts(deviceId);
472
473 ports.stream()
474 .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number()))
475 .filter(p -> p.isEnabled())
alshabib50d9fc52016-02-12 15:47:20 -0800476 .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(),
477 p.number(), true));
alshabibbb83aa22016-02-10 15:08:23 -0800478
479 }
480
alshabibf0e7e702015-05-30 18:22:36 -0700481}