blob: 5e3d36cd39834df570acb04853edef7832437d5e [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())
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() {
alshabib62e9ce72016-02-11 17:31:36 -0800162 deviceService.removeListener(deviceListener);
Jonathan Harte533a422015-10-20 17:31:24 -0700163 networkConfig.removeListener(configListener);
164 networkConfig.unregisterConfigFactory(configFactory);
alshabibf0e7e702015-05-30 18:22:36 -0700165 log.info("Stopped");
166 }
167
Jonathan Harte533a422015-10-20 17:31:24 -0700168 @Override
169 public void provisionSubscriber(ConnectPoint port, VlanId vlan) {
170 AccessDeviceData olt = oltData.get(port.deviceId());
171
172 if (olt == null) {
173 log.warn("No data found for OLT device {}", port.deviceId());
174 return;
175 }
176
Jonathan Hart52998382015-11-10 16:09:22 -0800177 provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(),
alshabibb7a9e172016-01-13 11:23:53 -0800178 olt.defaultVlan());
179 }
180
181 @Override
182 public void removeSubscriber(ConnectPoint port) {
alshabibbf23a1f2016-01-14 17:27:11 -0800183 AccessDeviceData olt = oltData.get(port.deviceId());
184
185 if (olt == null) {
186 log.warn("No data found for OLT device {}", port.deviceId());
187 return;
188 }
189
190 unprovisionSubscriber(olt.deviceId(), olt.uplink(), port.port(), olt.vlan());
191
192 }
193
194 private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink,
195 PortNumber subscriberPort, VlanId deviceVlan) {
196
197 //FIXME: This method is slightly ugly but it'll do until we have a better
198 // way to remove flows from the flow store.
199
200 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
201 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
202
203 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
204
205 VlanId subscriberVlan = subscribers.remove(cp);
206
207 Set<ForwardingObjective.Builder> fwds = objectives.remove(cp);
208
209 if (fwds == null || fwds.size() != 2) {
210 log.warn("Unknown or incomplete subscriber at {}", cp);
211 return;
212 }
213
214
215 fwds.stream().forEach(
216 fwd -> flowObjectiveService.forward(deviceId,
alshabibdec2e252016-01-15 12:20:25 -0800217 fwd.remove(new ObjectiveContext() {
218 @Override
219 public void onSuccess(Objective objective) {
220 upFuture.complete(null);
221 }
alshabibbf23a1f2016-01-14 17:27:11 -0800222
alshabibdec2e252016-01-15 12:20:25 -0800223 @Override
224 public void onError(Objective objective, ObjectiveError error) {
225 upFuture.complete(error);
226 }
227 })));
alshabibbf23a1f2016-01-14 17:27:11 -0800228
229 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
230 if (upStatus == null && downStatus == null) {
231 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED,
232 deviceId,
233 deviceVlan,
234 subscriberVlan));
235 } else if (downStatus != null) {
236 log.error("Subscriber with vlan {} on device {} " +
237 "on port {} failed downstream uninstallation: {}",
238 subscriberVlan, deviceId, subscriberPort, downStatus);
239 } else if (upStatus != null) {
240 log.error("Subscriber with vlan {} on device {} " +
241 "on port {} failed upstream uninstallation: {}",
242 subscriberVlan, deviceId, subscriberPort, upStatus);
243 }
244 }, oltInstallers);
alshabibb7a9e172016-01-13 11:23:53 -0800245
Jonathan Harte533a422015-10-20 17:31:24 -0700246 }
247
248 private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort,
249 PortNumber subscriberPort,
Jonathan Hart52998382015-11-10 16:09:22 -0800250 VlanId subscriberVlan, VlanId deviceVlan,
251 Optional<VlanId> defaultVlan) {
Jonathan Harte533a422015-10-20 17:31:24 -0700252
alshabib3ea82642016-01-12 18:06:53 -0800253 CompletableFuture<ObjectiveError> downFuture = new CompletableFuture();
254 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
255
Jonathan Harte533a422015-10-20 17:31:24 -0700256 TrafficSelector upstream = DefaultTrafficSelector.builder()
Jonathan Hart52998382015-11-10 16:09:22 -0800257 .matchVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN)
Jonathan Harte533a422015-10-20 17:31:24 -0700258 .matchInPort(subscriberPort)
259 .build();
260
261 TrafficSelector downstream = DefaultTrafficSelector.builder()
262 .matchVlanId(deviceVlan)
263 .matchInPort(uplinkPort)
alshabibb7a9e172016-01-13 11:23:53 -0800264 .matchInnerVlanId(subscriberVlan)
Jonathan Harte533a422015-10-20 17:31:24 -0700265 .build();
266
267 TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
alshabib3ea82642016-01-12 18:06:53 -0800268 .pushVlan()
Jonathan Harte533a422015-10-20 17:31:24 -0700269 .setVlanId(subscriberVlan)
270 .pushVlan()
271 .setVlanId(deviceVlan)
272 .setOutput(uplinkPort)
273 .build();
274
275 TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
276 .popVlan()
Jonathan Hart52998382015-11-10 16:09:22 -0800277 .setVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN)
Jonathan Harte533a422015-10-20 17:31:24 -0700278 .setOutput(subscriberPort)
279 .build();
280
281
alshabibbf23a1f2016-01-14 17:27:11 -0800282 ForwardingObjective.Builder upFwd = DefaultForwardingObjective.builder()
Jonathan Harte533a422015-10-20 17:31:24 -0700283 .withFlag(ForwardingObjective.Flag.VERSATILE)
284 .withPriority(1000)
285 .makePermanent()
286 .withSelector(upstream)
287 .fromApp(appId)
alshabibbf23a1f2016-01-14 17:27:11 -0800288 .withTreatment(upstreamTreatment);
alshabib3ea82642016-01-12 18:06:53 -0800289
Jonathan Harte533a422015-10-20 17:31:24 -0700290
alshabibbf23a1f2016-01-14 17:27:11 -0800291 ForwardingObjective.Builder downFwd = DefaultForwardingObjective.builder()
Jonathan Harte533a422015-10-20 17:31:24 -0700292 .withFlag(ForwardingObjective.Flag.VERSATILE)
293 .withPriority(1000)
294 .makePermanent()
295 .withSelector(downstream)
296 .fromApp(appId)
alshabibbf23a1f2016-01-14 17:27:11 -0800297 .withTreatment(downstreamTreatment);
alshabib3ea82642016-01-12 18:06:53 -0800298
alshabibbf23a1f2016-01-14 17:27:11 -0800299 ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort);
Jonathan Harte533a422015-10-20 17:31:24 -0700300
alshabibbf23a1f2016-01-14 17:27:11 -0800301 subscribers.put(cp, subscriberVlan);
302 objectives.put(cp, Sets.newHashSet(upFwd, downFwd));
303
304
305 flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() {
306 @Override
307 public void onSuccess(Objective objective) {
308 upFuture.complete(null);
309 }
310
311 @Override
312 public void onError(Objective objective, ObjectiveError error) {
313 upFuture.complete(error);
314 }
315 }));
316
317
318 flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() {
319 @Override
320 public void onSuccess(Objective objective) {
321 downFuture.complete(null);
322 }
323
324 @Override
325 public void onError(Objective objective, ObjectiveError error) {
326 downFuture.complete(error);
327 }
328 }));
alshabib3ea82642016-01-12 18:06:53 -0800329
330 upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> {
331 if (upStatus == null && downStatus == null) {
332 post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED,
333 deviceId,
334 deviceVlan,
335 subscriberVlan));
336 } else if (downStatus != null) {
337 log.error("Subscriber with vlan {} on device {} " +
338 "on port {} failed downstream installation: {}",
339 subscriberVlan, deviceId, subscriberPort, downStatus);
340 } else if (upStatus != null) {
341 log.error("Subscriber with vlan {} on device {} " +
342 "on port {} failed upstream installation: {}",
343 subscriberVlan, deviceId, subscriberPort, upStatus);
344 }
345 }, oltInstallers);
346
Jonathan Harte533a422015-10-20 17:31:24 -0700347 }
348
alshabibbb83aa22016-02-10 15:08:23 -0800349 private void processFilteringObjectives(DeviceId devId, Port port, boolean install) {
350 DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
351
352 FilteringObjective eapol = (install ? builder.permit() : builder.deny())
alshabibdec2e252016-01-15 12:20:25 -0800353 .withKey(Criteria.matchInPort(port.number()))
354 .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType()))
355 .withMeta(DefaultTrafficTreatment.builder()
356 .setOutput(PortNumber.CONTROLLER).build())
357 .fromApp(appId)
358 .withPriority(1000)
359 .add(new ObjectiveContext() {
360 @Override
361 public void onSuccess(Objective objective) {
362 log.info("Eapol filter for {} on {} installed.",
363 devId, port);
364 }
365
366 @Override
367 public void onError(Objective objective, ObjectiveError error) {
368 log.info("Eapol filter for {} on {} failed because {}",
369 devId, port, error);
370 }
371 });
372
alshabibdec2e252016-01-15 12:20:25 -0800373 flowObjectiveService.filter(devId, eapol);
alshabib000b6fc2016-02-01 17:25:00 -0800374
alshabibdec2e252016-01-15 12:20:25 -0800375 }
376
alshabibf0e7e702015-05-30 18:22:36 -0700377 private class InternalDeviceListener implements DeviceListener {
378 @Override
379 public void event(DeviceEvent event) {
alshabib3ea82642016-01-12 18:06:53 -0800380 DeviceId devId = event.subject().id();
381 if (!oltData.containsKey(devId)) {
382 log.debug("Device {} is not an OLT", devId);
alshabib8e4fd2f2016-01-12 15:55:53 -0800383 return;
384 }
alshabibf0e7e702015-05-30 18:22:36 -0700385 switch (event.type()) {
alshabibdec2e252016-01-15 12:20:25 -0800386 //TODO: Port handling and bookkeeping should be inproved once
387 // olt firmware handles correct behaviour.
alshabibf0e7e702015-05-30 18:22:36 -0700388 case PORT_ADDED:
alshabibbb83aa22016-02-10 15:08:23 -0800389 if (!oltData.get(devId).uplink().equals(event.port().number()) &&
390 event.port().isEnabled()) {
391 processFilteringObjectives(devId, event.port(), true);
alshabibdec2e252016-01-15 12:20:25 -0800392 }
393 break;
394 case PORT_REMOVED:
395 AccessDeviceData olt = oltData.get(devId);
396 unprovisionSubscriber(devId, olt.uplink(),
397 event.port().number(),
398 olt.vlan());
alshabibbb83aa22016-02-10 15:08:23 -0800399 if (!oltData.get(devId).uplink().equals(event.port().number()) &&
400 event.port().isEnabled()) {
401 processFilteringObjectives(devId, event.port(), false);
402 }
alshabibdec2e252016-01-15 12:20:25 -0800403 break;
alshabibf0e7e702015-05-30 18:22:36 -0700404 case PORT_UPDATED:
alshabibbb83aa22016-02-10 15:08:23 -0800405 if (oltData.get(devId).uplink().equals(event.port().number())) {
406 break;
407 }
408 if (event.port().isEnabled()) {
409 processFilteringObjectives(devId, event.port(), true);
410 } else {
411 processFilteringObjectives(devId, event.port(), false);
412 }
alshabibf0e7e702015-05-30 18:22:36 -0700413 break;
414 case DEVICE_ADDED:
alshabib8e4fd2f2016-01-12 15:55:53 -0800415 post(new AccessDeviceEvent(
416 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
417 null, null));
418 break;
alshabibf0e7e702015-05-30 18:22:36 -0700419 case DEVICE_REMOVED:
alshabib8e4fd2f2016-01-12 15:55:53 -0800420 post(new AccessDeviceEvent(
421 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
422 null, null));
423 break;
alshabib7c190012016-02-09 18:22:33 -0800424 case DEVICE_AVAILABILITY_CHANGED:
425 if (deviceService.isAvailable(devId)) {
426 post(new AccessDeviceEvent(
427 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
428 null, null));
429 } else {
430 post(new AccessDeviceEvent(
431 AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
432 null, null));
433 }
434 break;
alshabib8e4fd2f2016-01-12 15:55:53 -0800435 case DEVICE_UPDATED:
alshabibf0e7e702015-05-30 18:22:36 -0700436 case DEVICE_SUSPENDED:
alshabibf0e7e702015-05-30 18:22:36 -0700437 case PORT_STATS_UPDATED:
438 default:
439 return;
440 }
441 }
442 }
443
Jonathan Harte533a422015-10-20 17:31:24 -0700444 private class InternalNetworkConfigListener implements NetworkConfigListener {
445 @Override
446 public void event(NetworkConfigEvent event) {
447 switch (event.type()) {
448
alshabibbf23a1f2016-01-14 17:27:11 -0800449 case CONFIG_ADDED:
450 case CONFIG_UPDATED:
451 if (event.configClass().equals(CONFIG_CLASS)) {
452 AccessDeviceConfig config =
453 networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
454 if (config != null) {
455 oltData.put(config.getOlt().deviceId(), config.getOlt());
alshabibbb83aa22016-02-10 15:08:23 -0800456 provisionDefaultFlows((DeviceId) event.subject());
alshabibbf23a1f2016-01-14 17:27:11 -0800457 }
Jonathan Harte533a422015-10-20 17:31:24 -0700458 }
alshabibbf23a1f2016-01-14 17:27:11 -0800459 break;
460 case CONFIG_UNREGISTERED:
461 case CONFIG_REMOVED:
462 default:
463 break;
Jonathan Harte533a422015-10-20 17:31:24 -0700464 }
465 }
466 }
alshabibf0e7e702015-05-30 18:22:36 -0700467
alshabibbb83aa22016-02-10 15:08:23 -0800468 private void provisionDefaultFlows(DeviceId deviceId) {
469 List<Port> ports = deviceService.getPorts(deviceId);
470
471 ports.stream()
472 .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number()))
473 .filter(p -> p.isEnabled())
474 .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(), p, true));
475
476 }
477
alshabibf0e7e702015-05-30 18:22:36 -0700478}