blob: 195d64ec1da00382bca012aa0c9ac53a7e0d55ea [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())
151 .filter(p -> oltData.get(p.element().id()).uplink() != p.number())
152 .filter(p -> p.isEnabled())
alshabibbb83aa22016-02-10 15:08:23 -0800153 .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(), p, true));
alshabibdec2e252016-01-15 12:20:25 -0800154
alshabibba357492016-01-27 13:49:46 -0800155 deviceService.addListener(deviceListener);
156
alshabibf0e7e702015-05-30 18:22:36 -0700157 log.info("Started with Application ID {}", appId.id());
158 }
159
160 @Deactivate
161 public void deactivate() {
Jonathan Harte533a422015-10-20 17:31:24 -0700162 networkConfig.removeListener(configListener);
163 networkConfig.unregisterConfigFactory(configFactory);
alshabibf0e7e702015-05-30 18:22:36 -0700164 log.info("Stopped");
165 }
166
Jonathan Harte533a422015-10-20 17:31:24 -0700167 @Override
168 public void provisionSubscriber(ConnectPoint port, VlanId vlan) {
169 AccessDeviceData olt = oltData.get(port.deviceId());
170
171 if (olt == null) {
172 log.warn("No data found for OLT device {}", port.deviceId());
173 return;
174 }
175
Jonathan Hart52998382015-11-10 16:09:22 -0800176 provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(),
alshabibb7a9e172016-01-13 11:23:53 -0800177 olt.defaultVlan());
178 }
179
180 @Override
181 public void removeSubscriber(ConnectPoint port) {
alshabibbf23a1f2016-01-14 17:27:11 -0800182 AccessDeviceData olt = oltData.get(port.deviceId());
183
184 if (olt == null) {
185 log.warn("No data found for OLT device {}", port.deviceId());
186 return;
187 }
188
189 unprovisionSubscriber(olt.deviceId(), olt.uplink(), port.port(), olt.vlan());
190
191 }
192
193 private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink,
194 PortNumber subscriberPort, VlanId deviceVlan) {
195
196 //FIXME: This method is slightly ugly but it'll do until we have a better
197 // way to remove flows from the flow store.
198
199 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
200 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
201
202 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
203
204 VlanId subscriberVlan = subscribers.remove(cp);
205
206 Set<ForwardingObjective.Builder> fwds = objectives.remove(cp);
207
208 if (fwds == null || fwds.size() != 2) {
209 log.warn("Unknown or incomplete subscriber at {}", cp);
210 return;
211 }
212
213
214 fwds.stream().forEach(
215 fwd -> flowObjectiveService.forward(deviceId,
alshabibdec2e252016-01-15 12:20:25 -0800216 fwd.remove(new ObjectiveContext() {
217 @Override
218 public void onSuccess(Objective objective) {
219 upFuture.complete(null);
220 }
alshabibbf23a1f2016-01-14 17:27:11 -0800221
alshabibdec2e252016-01-15 12:20:25 -0800222 @Override
223 public void onError(Objective objective, ObjectiveError error) {
224 upFuture.complete(error);
225 }
226 })));
alshabibbf23a1f2016-01-14 17:27:11 -0800227
228 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
229 if (upStatus == null && downStatus == null) {
230 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED,
231 deviceId,
232 deviceVlan,
233 subscriberVlan));
234 } else if (downStatus != null) {
235 log.error("Subscriber with vlan {} on device {} " +
236 "on port {} failed downstream uninstallation: {}",
237 subscriberVlan, deviceId, subscriberPort, downStatus);
238 } else if (upStatus != null) {
239 log.error("Subscriber with vlan {} on device {} " +
240 "on port {} failed upstream uninstallation: {}",
241 subscriberVlan, deviceId, subscriberPort, upStatus);
242 }
243 }, oltInstallers);
alshabibb7a9e172016-01-13 11:23:53 -0800244
Jonathan Harte533a422015-10-20 17:31:24 -0700245 }
246
247 private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort,
248 PortNumber subscriberPort,
Jonathan Hart52998382015-11-10 16:09:22 -0800249 VlanId subscriberVlan, VlanId deviceVlan,
250 Optional<VlanId> defaultVlan) {
Jonathan Harte533a422015-10-20 17:31:24 -0700251
alshabib3ea82642016-01-12 18:06:53 -0800252 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
253 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
254
Jonathan Harte533a422015-10-20 17:31:24 -0700255 TrafficSelector upstream = DefaultTrafficSelector.builder()
Jonathan Hart52998382015-11-10 16:09:22 -0800256 .matchVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN)
Jonathan Harte533a422015-10-20 17:31:24 -0700257 .matchInPort(subscriberPort)
258 .build();
259
260 TrafficSelector downstream = DefaultTrafficSelector.builder()
261 .matchVlanId(deviceVlan)
262 .matchInPort(uplinkPort)
alshabibb7a9e172016-01-13 11:23:53 -0800263 .matchInnerVlanId(subscriberVlan)
Jonathan Harte533a422015-10-20 17:31:24 -0700264 .build();
265
266 TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
alshabib3ea82642016-01-12 18:06:53 -0800267 .pushVlan()
Jonathan Harte533a422015-10-20 17:31:24 -0700268 .setVlanId(subscriberVlan)
269 .pushVlan()
270 .setVlanId(deviceVlan)
271 .setOutput(uplinkPort)
272 .build();
273
274 TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
275 .popVlan()
Jonathan Hart52998382015-11-10 16:09:22 -0800276 .setVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN)
Jonathan Harte533a422015-10-20 17:31:24 -0700277 .setOutput(subscriberPort)
278 .build();
279
280
alshabibbf23a1f2016-01-14 17:27:11 -0800281 ForwardingObjective.Builder upFwd = DefaultForwardingObjective.builder()
Jonathan Harte533a422015-10-20 17:31:24 -0700282 .withFlag(ForwardingObjective.Flag.VERSATILE)
283 .withPriority(1000)
284 .makePermanent()
285 .withSelector(upstream)
286 .fromApp(appId)
alshabibbf23a1f2016-01-14 17:27:11 -0800287 .withTreatment(upstreamTreatment);
alshabib3ea82642016-01-12 18:06:53 -0800288
Jonathan Harte533a422015-10-20 17:31:24 -0700289
alshabibbf23a1f2016-01-14 17:27:11 -0800290 ForwardingObjective.Builder downFwd = DefaultForwardingObjective.builder()
Jonathan Harte533a422015-10-20 17:31:24 -0700291 .withFlag(ForwardingObjective.Flag.VERSATILE)
292 .withPriority(1000)
293 .makePermanent()
294 .withSelector(downstream)
295 .fromApp(appId)
alshabibbf23a1f2016-01-14 17:27:11 -0800296 .withTreatment(downstreamTreatment);
alshabib3ea82642016-01-12 18:06:53 -0800297
alshabibbf23a1f2016-01-14 17:27:11 -0800298 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
Jonathan Harte533a422015-10-20 17:31:24 -0700299
alshabibbf23a1f2016-01-14 17:27:11 -0800300 subscribers.put(cp, subscriberVlan);
301 objectives.put(cp, Sets.newHashSet(upFwd, downFwd));
302
303
304 flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() {
305 @Override
306 public void onSuccess(Objective objective) {
307 upFuture.complete(null);
308 }
309
310 @Override
311 public void onError(Objective objective, ObjectiveError error) {
312 upFuture.complete(error);
313 }
314 }));
315
316
317 flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() {
318 @Override
319 public void onSuccess(Objective objective) {
320 downFuture.complete(null);
321 }
322
323 @Override
324 public void onError(Objective objective, ObjectiveError error) {
325 downFuture.complete(error);
326 }
327 }));
alshabib3ea82642016-01-12 18:06:53 -0800328
329 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
330 if (upStatus == null && downStatus == null) {
331 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED,
332 deviceId,
333 deviceVlan,
334 subscriberVlan));
335 } else if (downStatus != null) {
336 log.error("Subscriber with vlan {} on device {} " +
337 "on port {} failed downstream installation: {}",
338 subscriberVlan, deviceId, subscriberPort, downStatus);
339 } else if (upStatus != null) {
340 log.error("Subscriber with vlan {} on device {} " +
341 "on port {} failed upstream installation: {}",
342 subscriberVlan, deviceId, subscriberPort, upStatus);
343 }
344 }, oltInstallers);
345
Jonathan Harte533a422015-10-20 17:31:24 -0700346 }
347
alshabibbb83aa22016-02-10 15:08:23 -0800348 private void processFilteringObjectives(DeviceId devId, Port port, boolean install) {
349 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
350
351 FilteringObjective eapol = (install ? builder.permit() : builder.deny())
alshabibdec2e252016-01-15 12:20:25 -0800352 .withKey(Criteria.matchInPort(port.number()))
353 .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType()))
354 .withMeta(DefaultTrafficTreatment.builder()
355 .setOutput(PortNumber.CONTROLLER).build())
356 .fromApp(appId)
357 .withPriority(1000)
358 .add(new ObjectiveContext() {
359 @Override
360 public void onSuccess(Objective objective) {
361 log.info("Eapol filter for {} on {} installed.",
362 devId, port);
363 }
364
365 @Override
366 public void onError(Objective objective, ObjectiveError error) {
367 log.info("Eapol filter for {} on {} failed because {}",
368 devId, port, error);
369 }
370 });
371
alshabibdec2e252016-01-15 12:20:25 -0800372 flowObjectiveService.filter(devId, eapol);
alshabib000b6fc2016-02-01 17:25:00 -0800373
alshabibdec2e252016-01-15 12:20:25 -0800374 }
375
alshabibf0e7e702015-05-30 18:22:36 -0700376 private class InternalDeviceListener implements DeviceListener {
377 @Override
378 public void event(DeviceEvent event) {
alshabib3ea82642016-01-12 18:06:53 -0800379 DeviceId devId = event.subject().id();
380 if (!oltData.containsKey(devId)) {
381 log.debug("Device {} is not an OLT", devId);
alshabib8e4fd2f2016-01-12 15:55:53 -0800382 return;
383 }
alshabibf0e7e702015-05-30 18:22:36 -0700384 switch (event.type()) {
alshabibdec2e252016-01-15 12:20:25 -0800385 //TODO: Port handling and bookkeeping should be inproved once
386 // olt firmware handles correct behaviour.
alshabibf0e7e702015-05-30 18:22:36 -0700387 case PORT_ADDED:
alshabibbb83aa22016-02-10 15:08:23 -0800388 if (!oltData.get(devId).uplink().equals(event.port().number()) &&
389 event.port().isEnabled()) {
390 processFilteringObjectives(devId, event.port(), true);
alshabibdec2e252016-01-15 12:20:25 -0800391 }
392 break;
393 case PORT_REMOVED:
394 AccessDeviceData olt = oltData.get(devId);
395 unprovisionSubscriber(devId, olt.uplink(),
396 event.port().number(),
397 olt.vlan());
alshabibbb83aa22016-02-10 15:08:23 -0800398 if (!oltData.get(devId).uplink().equals(event.port().number()) &&
399 event.port().isEnabled()) {
400 processFilteringObjectives(devId, event.port(), false);
401 }
alshabibdec2e252016-01-15 12:20:25 -0800402 break;
alshabibf0e7e702015-05-30 18:22:36 -0700403 case PORT_UPDATED:
alshabibbb83aa22016-02-10 15:08:23 -0800404 if (oltData.get(devId).uplink().equals(event.port().number())) {
405 break;
406 }
407 if (event.port().isEnabled()) {
408 processFilteringObjectives(devId, event.port(), true);
409 } else {
410 processFilteringObjectives(devId, event.port(), false);
411 }
alshabibf0e7e702015-05-30 18:22:36 -0700412 break;
413 case DEVICE_ADDED:
alshabib8e4fd2f2016-01-12 15:55:53 -0800414 post(new AccessDeviceEvent(
415 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
416 null, null));
417 break;
alshabibf0e7e702015-05-30 18:22:36 -0700418 case DEVICE_REMOVED:
alshabib8e4fd2f2016-01-12 15:55:53 -0800419 post(new AccessDeviceEvent(
420 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
421 null, null));
422 break;
alshabib7c190012016-02-09 18:22:33 -0800423 case DEVICE_AVAILABILITY_CHANGED:
424 if (deviceService.isAvailable(devId)) {
425 post(new AccessDeviceEvent(
426 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
427 null, null));
428 } else {
429 post(new AccessDeviceEvent(
430 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
431 null, null));
432 }
433 break;
alshabib8e4fd2f2016-01-12 15:55:53 -0800434 case DEVICE_UPDATED:
alshabibf0e7e702015-05-30 18:22:36 -0700435 case DEVICE_SUSPENDED:
alshabibf0e7e702015-05-30 18:22:36 -0700436 case PORT_STATS_UPDATED:
437 default:
438 return;
439 }
440 }
441 }
442
Jonathan Harte533a422015-10-20 17:31:24 -0700443 private class InternalNetworkConfigListener implements NetworkConfigListener {
444 @Override
445 public void event(NetworkConfigEvent event) {
446 switch (event.type()) {
447
alshabibbf23a1f2016-01-14 17:27:11 -0800448 case CONFIG_ADDED:
449 case CONFIG_UPDATED:
450 if (event.configClass().equals(CONFIG_CLASS)) {
451 AccessDeviceConfig config =
452 networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
453 if (config != null) {
454 oltData.put(config.getOlt().deviceId(), config.getOlt());
alshabibbb83aa22016-02-10 15:08:23 -0800455 provisionDefaultFlows((DeviceId) event.subject());
alshabibbf23a1f2016-01-14 17:27:11 -0800456 }
Jonathan Harte533a422015-10-20 17:31:24 -0700457 }
alshabibbf23a1f2016-01-14 17:27:11 -0800458 break;
459 case CONFIG_UNREGISTERED:
460 case CONFIG_REMOVED:
461 default:
462 break;
Jonathan Harte533a422015-10-20 17:31:24 -0700463 }
464 }
465 }
alshabibf0e7e702015-05-30 18:22:36 -0700466
alshabibbb83aa22016-02-10 15:08:23 -0800467 private void provisionDefaultFlows(DeviceId deviceId) {
468 List<Port> ports = deviceService.getPorts(deviceId);
469
470 ports.stream()
471 .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number()))
472 .filter(p -> p.isEnabled())
473 .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(), p, true));
474
475 }
476
alshabibf0e7e702015-05-30 18:22:36 -0700477}