blob: 944d3b609f4366782c6ceb905aee2ecc180e172d [file] [log] [blame]
Naoki Shiota5a056062016-05-05 18:43:59 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Naoki Shiota5a056062016-05-05 18:43:59 -07003 *
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 */
16package org.onosproject.newoptical;
17
18import com.google.common.annotations.Beta;
19import com.google.common.collect.ImmutableList;
Naoki Shiota5a056062016-05-05 18:43:59 -070020import org.apache.commons.lang3.tuple.Pair;
21import org.apache.felix.scr.annotations.Activate;
22import org.apache.felix.scr.annotations.Component;
23import org.apache.felix.scr.annotations.Deactivate;
24import org.apache.felix.scr.annotations.Reference;
25import org.apache.felix.scr.annotations.ReferenceCardinality;
26import org.apache.felix.scr.annotations.Service;
27import org.onlab.util.Bandwidth;
Yuta HIGUCHIf167bf92017-03-08 13:19:04 -080028import org.onlab.util.GuavaCollectors;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070029import org.onlab.util.KryoNamespace;
Naoki Shiota5a056062016-05-05 18:43:59 -070030import org.onosproject.cluster.ClusterService;
Naoki Shiota5a056062016-05-05 18:43:59 -070031import org.onosproject.core.ApplicationId;
32import org.onosproject.core.CoreService;
Naoki Shiota0d2943e2016-05-13 18:53:21 -070033import org.onosproject.event.ListenerTracker;
34import org.onosproject.net.optical.OchPort;
35import org.onosproject.net.optical.OduCltPort;
Naoki Shiota5a056062016-05-05 18:43:59 -070036import org.onosproject.newoptical.api.OpticalConnectivityId;
37import org.onosproject.newoptical.api.OpticalPathEvent;
38import org.onosproject.newoptical.api.OpticalPathListener;
39import org.onosproject.newoptical.api.OpticalPathService;
40import org.onosproject.event.AbstractListenerManager;
41import org.onosproject.mastership.MastershipService;
Naoki Shiota5a056062016-05-05 18:43:59 -070042import org.onosproject.net.ConnectPoint;
43import org.onosproject.net.Device;
44import org.onosproject.net.DeviceId;
45import org.onosproject.net.Link;
Naoki Shiota5a056062016-05-05 18:43:59 -070046import org.onosproject.net.Path;
47import org.onosproject.net.Port;
48import org.onosproject.net.config.NetworkConfigService;
49import org.onosproject.net.device.DeviceService;
50import org.onosproject.net.intent.Intent;
51import org.onosproject.net.intent.IntentEvent;
Naoki Shiota5a056062016-05-05 18:43:59 -070052import org.onosproject.net.intent.IntentListener;
53import org.onosproject.net.intent.IntentService;
Yuta HIGUCHI8ac05092017-03-15 00:41:22 -070054import org.onosproject.net.intent.Key;
Naoki Shiota5a056062016-05-05 18:43:59 -070055import org.onosproject.net.intent.OpticalCircuitIntent;
56import org.onosproject.net.intent.OpticalConnectivityIntent;
Naoki Shiota5a056062016-05-05 18:43:59 -070057import org.onosproject.net.link.LinkEvent;
58import org.onosproject.net.link.LinkListener;
59import org.onosproject.net.link.LinkService;
Sho SHIMIZUb6c63a32016-05-26 12:07:19 -070060import org.onosproject.net.config.basics.BandwidthCapacity;
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -080061import org.onosproject.net.config.basics.BasicLinkConfig;
Naoki Shiota5a056062016-05-05 18:43:59 -070062import org.onosproject.net.resource.ContinuousResource;
63import org.onosproject.net.resource.Resource;
64import org.onosproject.net.resource.ResourceAllocation;
65import org.onosproject.net.resource.ResourceService;
66import org.onosproject.net.resource.Resources;
67import org.onosproject.net.topology.LinkWeight;
68import org.onosproject.net.topology.PathService;
69import org.onosproject.net.topology.TopologyEdge;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070070import org.onosproject.store.serializers.KryoNamespaces;
Naoki Shiota5a056062016-05-05 18:43:59 -070071import org.onosproject.store.service.AtomicCounter;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070072import org.onosproject.store.service.ConsistentMap;
73import org.onosproject.store.service.DistributedSet;
74import org.onosproject.store.service.MapEvent;
75import org.onosproject.store.service.MapEventListener;
76import org.onosproject.store.service.Serializer;
Naoki Shiota5a056062016-05-05 18:43:59 -070077import org.onosproject.store.service.StorageService;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070078import org.onosproject.store.service.Versioned;
Naoki Shiota5a056062016-05-05 18:43:59 -070079import org.slf4j.Logger;
80import org.slf4j.LoggerFactory;
81
82import java.time.Duration;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070083import java.util.ArrayList;
Yuta HIGUCHIf167bf92017-03-08 13:19:04 -080084import java.util.Collection;
Naoki Shiota5a056062016-05-05 18:43:59 -070085import java.util.Collections;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070086import java.util.HashMap;
87import java.util.HashSet;
Naoki Shiota5a056062016-05-05 18:43:59 -070088import java.util.Iterator;
89import java.util.LinkedList;
90import java.util.List;
91import java.util.Map;
Yuta HIGUCHI8ac05092017-03-15 00:41:22 -070092import java.util.Map.Entry;
Naoki Shiota5a056062016-05-05 18:43:59 -070093import java.util.Optional;
94import java.util.Set;
Naoki Shiota5a056062016-05-05 18:43:59 -070095import java.util.stream.Collectors;
96import java.util.stream.Stream;
97
98import static com.google.common.base.Preconditions.checkArgument;
99import static com.google.common.base.Preconditions.checkNotNull;
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800100import static org.onosproject.net.LinkKey.linkKey;
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700101import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
Naoki Shiota5a056062016-05-05 18:43:59 -0700102
103/**
104 * Main component to configure optical connectivity.
105 */
106@Beta
107@Service
108@Component(immediate = true)
109public class OpticalPathProvisioner
110 extends AbstractListenerManager<OpticalPathEvent, OpticalPathListener>
111 implements OpticalPathService {
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800112
Naoki Shiota5a056062016-05-05 18:43:59 -0700113 protected static final Logger log = LoggerFactory.getLogger(OpticalPathProvisioner.class);
114
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800115 /**
116 * Bandwidth representing no bandwidth requirement specified.
117 */
118 private static final Bandwidth NO_BW_REQUIREMENT = Bandwidth.bps(0);
119
Naoki Shiota5a056062016-05-05 18:43:59 -0700120 private static final String OPTICAL_CONNECTIVITY_ID_COUNTER = "optical-connectivity-id";
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700121 private static final String LINKPATH_MAP_NAME = "newoptical-linkpath";
122 private static final String CONNECTIVITY_MAP_NAME = "newoptical-connectivity";
123 private static final String CROSSCONNECTLINK_SET_NAME = "newoptical-crossconnectlink";
Naoki Shiota5a056062016-05-05 18:43:59 -0700124
125 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
126 protected IntentService intentService;
127
128 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
129 protected PathService pathService;
130
131 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
132 protected CoreService coreService;
133
134 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
135 protected LinkService linkService;
136
137 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
138 protected MastershipService mastershipService;
139
140 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
141 protected ClusterService clusterService;
142
143 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
144 protected DeviceService deviceService;
145
146 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
147 protected StorageService storageService;
148
149 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
150 protected NetworkConfigService networkConfigService;
151
152 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
153 protected ResourceService resourceService;
154
155
156 private ApplicationId appId;
157
158 private AtomicCounter idCounter;
159
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700160 private ListenerTracker listeners;
Naoki Shiota5a056062016-05-05 18:43:59 -0700161
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700162 private InternalStoreListener storeListener = new InternalStoreListener();
Naoki Shiota5a056062016-05-05 18:43:59 -0700163
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800164 /**
165 * Map from packet-layer link expected to be realized by some optical Intent to
166 * OpticalConnectivity (~=top level intent over multi-layer topology).
167 */
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700168 private ConsistentMap<PacketLinkRealizedByOptical, OpticalConnectivity> linkPathMap;
Naoki Shiota5a056062016-05-05 18:43:59 -0700169
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700170 private ConsistentMap<OpticalConnectivityId, OpticalConnectivity> connectivityMap;
171
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800172 // FIXME in the long run. This is effectively app's own resource subsystem
173 /**
174 * Set of cross connect link currently used.
175 */
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700176 private DistributedSet<Link> usedCrossConnectLinkSet;
177
178 private static final KryoNamespace.Builder LINKPATH_SERIALIZER = KryoNamespace.newBuilder()
179 .register(KryoNamespaces.API)
180 .register(PacketLinkRealizedByOptical.class)
181 .register(OpticalConnectivityId.class)
182 .register(OpticalConnectivity.class);
183
184 private static final KryoNamespace.Builder CONNECTIVITY_SERIALIZER = KryoNamespace.newBuilder()
185 .register(KryoNamespaces.API)
Yuta HIGUCHI0086cf82016-07-18 22:49:45 -0700186 .register(PacketLinkRealizedByOptical.class)
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700187 .register(OpticalConnectivityId.class)
188 .register(OpticalConnectivity.class);
189
190 private static final KryoNamespace.Builder CROSSCONNECTLINKS_SERIALIZER = KryoNamespace.newBuilder()
191 .register(KryoNamespaces.API);
Naoki Shiota5a056062016-05-05 18:43:59 -0700192
193 @Activate
194 protected void activate() {
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700195 deviceService = opticalView(deviceService);
Naoki Shiota5a056062016-05-05 18:43:59 -0700196 appId = coreService.registerApplication("org.onosproject.newoptical");
197
Naoki Shiota03c29e12016-05-16 16:58:07 -0700198 idCounter = storageService.getAtomicCounter(OPTICAL_CONNECTIVITY_ID_COUNTER);
Naoki Shiota5a056062016-05-05 18:43:59 -0700199
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700200 linkPathMap = storageService.<PacketLinkRealizedByOptical, OpticalConnectivity>consistentMapBuilder()
201 .withSerializer(Serializer.using(LINKPATH_SERIALIZER.build()))
202 .withName(LINKPATH_MAP_NAME)
203 .withApplicationId(appId)
204 .build();
205
206 connectivityMap = storageService.<OpticalConnectivityId, OpticalConnectivity>consistentMapBuilder()
207 .withSerializer(Serializer.using(CONNECTIVITY_SERIALIZER.build()))
208 .withName(CONNECTIVITY_MAP_NAME)
209 .withApplicationId(appId)
210 .build();
211
212 usedCrossConnectLinkSet = storageService.<Link>setBuilder()
213 .withSerializer(Serializer.using(CROSSCONNECTLINKS_SERIALIZER.build()))
214 .withName(CROSSCONNECTLINK_SET_NAME)
215 .withApplicationId(appId)
216 .build()
217 .asDistributedSet();
218
Naoki Shiota5a056062016-05-05 18:43:59 -0700219 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry);
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700220
221 listeners = new ListenerTracker();
222 listeners.addListener(linkService, new InternalLinkListener())
223 .addListener(intentService, new InternalIntentListener());
Naoki Shiota5a056062016-05-05 18:43:59 -0700224
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700225 linkPathMap.addListener(storeListener);
226
Naoki Shiota5a056062016-05-05 18:43:59 -0700227 log.info("Started");
228 }
229
230 @Deactivate
231 protected void deactivate() {
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700232 linkPathMap.removeListener(storeListener);
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700233 listeners.removeListeners();
234 eventDispatcher.removeSink(OpticalPathEvent.class);
Naoki Shiota5a056062016-05-05 18:43:59 -0700235
236 log.info("Stopped");
237 }
238
Yuta HIGUCHIf167bf92017-03-08 13:19:04 -0800239 @Override
240 public Collection<OpticalConnectivity> listConnectivity() {
241 return connectivityMap.values().stream()
242 .map(Versioned::value)
243 .collect(GuavaCollectors.toImmutableList());
244 }
Yuta HIGUCHI8ac05092017-03-15 00:41:22 -0700245
246 public Set<Key> listIntents(OpticalConnectivityId id) {
247 return linkPathMap.entrySet().stream()
248 .filter(ent -> id.equals(ent.getValue().value().id()))
249 .map(Entry::getKey)
250 .map(PacketLinkRealizedByOptical::realizingIntentKey)
251 .collect(Collectors.toSet());
252 }
253
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800254 /*
255 * Request packet-layer connectivity between specified ports,
256 * over packet-optical multi-layer infrastructure.
257 *
258 * Functionality-wise this is effectively submitting Packet-Optical
259 * multi-layer P2P Intent.
260 *
261 * It computes multi-layer path meeting specified constraint,
262 * and calls setupPath.
263 */
Naoki Shiota5a056062016-05-05 18:43:59 -0700264 @Override
265 public OpticalConnectivityId setupConnectivity(ConnectPoint ingress, ConnectPoint egress,
266 Bandwidth bandwidth, Duration latency) {
267 checkNotNull(ingress);
268 checkNotNull(egress);
269 log.info("setupConnectivity({}, {}, {}, {})", ingress, egress, bandwidth, latency);
270
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800271 bandwidth = (bandwidth == null) ? NO_BW_REQUIREMENT : bandwidth;
Naoki Shiota5a056062016-05-05 18:43:59 -0700272
273 Set<Path> paths = pathService.getPaths(ingress.deviceId(), egress.deviceId(),
274 new BandwidthLinkWeight(bandwidth));
275 if (paths.isEmpty()) {
276 log.warn("Unable to find multi-layer path.");
277 return null;
278 }
279
280 // Search path with available cross connect points
281 for (Path path : paths) {
282 OpticalConnectivityId id = setupPath(path, bandwidth, latency);
283 if (id != null) {
284 log.info("Assigned OpticalConnectivityId: {}", id);
285 return id;
286 }
287 }
288
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800289 log.error("setupConnectivity({}, {}, {}, {}) failed.", ingress, egress, bandwidth, latency);
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700290
Naoki Shiota5a056062016-05-05 18:43:59 -0700291 return null;
292 }
293
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800294 /*
295 * Given a multi-layer path,
296 * compute a set of segments which requires
297 * OpticalConnectivity(~=OpticalConnectivityIntent or OpticalCircuitPath)
298 * to provide packet-layer connectivity.
299 */
Naoki Shiota5a056062016-05-05 18:43:59 -0700300 @Override
301 public OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency) {
302 checkNotNull(path);
Yuta HIGUCHI8fc32f82017-03-14 22:12:42 -0700303 log.debug("setupPath({}, {}, {})", path, bandwidth, latency);
Naoki Shiota5a056062016-05-05 18:43:59 -0700304
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700305 // map of cross connect points (optical port -> packet port)
306 Map<ConnectPoint, ConnectPoint> crossConnectPointMap = new HashMap<>();
307
308 // list of (src, dst) pair of optical ports between which optical path should be installed
309 List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints = new ArrayList<>();
310
311 // Scan path to find pairs of connect points between which optical intent is installed
312 // opticalSrcPort works as a flag parameter to show scanning status
313 ConnectPoint opticalSrcPort = null;
314 for (Link link : path.links()) {
315 if (!isCrossConnectLink(link)) {
316 continue;
317 }
318
319 if (opticalSrcPort != null) {
320 // opticalSrcPort!=null means src port was already found
321 // in this case link.src() is optical layer, and link.dst() is packet layer
322
323 // Check if types of src port and dst port matches
324 Device srcDevice = checkNotNull(deviceService.getDevice(opticalSrcPort.deviceId()),
325 "Unknown device ID");
326 Device dstDevice = checkNotNull(deviceService.getDevice(link.src().deviceId()),
327 "Unknown device ID");
328 if (srcDevice.type() != dstDevice.type()) {
329 log.error("Unsupported mix of cross connect points : {}, {}",
330 srcDevice.type(), dstDevice.type());
331 return null;
332 }
333
334 // Update cross connect points map
335 crossConnectPointMap.put(link.src(), link.dst());
336
337 // Add optical ports pair to list
338 crossConnectPoints.add(Pair.of(opticalSrcPort, link.src()));
339
340 // Reset flag parameter
341 opticalSrcPort = null;
342 } else {
343 // opticalSrcPort==null means src port was not found yet
344 // in this case link.src() is packet layer, and link.dst() is optical layer
345
346 // Update cross connect points map
347 crossConnectPointMap.put(link.dst(), link.src());
348 // Set opticalSrcPort to src of link (optical port)
349 opticalSrcPort = link.dst();
350 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700351 }
352
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700353 // create intents from cross connect points
354 List<Intent> intents = createIntents(crossConnectPoints);
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -0800355 if (intents.isEmpty()) {
356 log.error("No intents produced from {}", crossConnectPoints);
357 return null;
358 }
359
Naoki Shiota5a056062016-05-05 18:43:59 -0700360
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700361 // create set of PacketLinkRealizedByOptical
362 Set<PacketLinkRealizedByOptical> packetLinks = createPacketLinkSet(crossConnectPoints,
363 intents, crossConnectPointMap);
364
365 // create OpticalConnectivity object and store information to distributed store
366 OpticalConnectivity connectivity = createConnectivity(path, bandwidth, latency, packetLinks);
Naoki Shiota5a056062016-05-05 18:43:59 -0700367
368 // store cross connect port usage
369 path.links().stream().filter(this::isCrossConnectLink)
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700370 .forEach(usedCrossConnectLinkSet::add);
Naoki Shiota5a056062016-05-05 18:43:59 -0700371
372 // Submit the intents
373 for (Intent i : intents) {
374 intentService.submit(i);
375 log.debug("Submitted an intent: {}", i);
376 }
377
378 return connectivity.id();
379 }
380
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700381 private OpticalConnectivity createConnectivity(Path path, Bandwidth bandwidth, Duration latency,
382 Set<PacketLinkRealizedByOptical> links) {
Naoki Shiota5a056062016-05-05 18:43:59 -0700383 OpticalConnectivityId id = OpticalConnectivityId.of(idCounter.getAndIncrement());
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700384 OpticalConnectivity connectivity = new OpticalConnectivity(id, path.links(), bandwidth, latency,
385 links, Collections.emptySet());
386
387 links.forEach(l -> linkPathMap.put(l, connectivity));
Naoki Shiota5a056062016-05-05 18:43:59 -0700388
Naoki Shiota5a056062016-05-05 18:43:59 -0700389 // store connectivity information
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700390 connectivityMap.put(connectivity.id(), connectivity);
Naoki Shiota5a056062016-05-05 18:43:59 -0700391
392 return connectivity;
393 }
394
395 @Override
396 public boolean removeConnectivity(OpticalConnectivityId id) {
397 log.info("removeConnectivity({})", id);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700398 Versioned<OpticalConnectivity> connectivity = connectivityMap.remove(id);
Naoki Shiota5a056062016-05-05 18:43:59 -0700399
400 if (connectivity == null) {
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700401 log.info("OpticalConnectivity with id {} not found.", id);
Naoki Shiota5a056062016-05-05 18:43:59 -0700402 return false;
403 }
404
405 // TODO withdraw intent only if all of connectivities that use the optical path are withdrawn
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700406 connectivity.value().getRealizingLinks().forEach(l -> {
Naoki Shiota5a056062016-05-05 18:43:59 -0700407 Intent intent = intentService.getIntent(l.realizingIntentKey());
408 intentService.withdraw(intent);
409 });
410
411 return true;
412 }
413
414 @Override
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700415 public Optional<List<Link>> getPath(OpticalConnectivityId id) {
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700416 Versioned<OpticalConnectivity> connectivity = connectivityMap.get(id);
Naoki Shiota5a056062016-05-05 18:43:59 -0700417 if (connectivity == null) {
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700418 log.info("OpticalConnectivity with id {} not found.", id);
419 return Optional.empty();
Naoki Shiota5a056062016-05-05 18:43:59 -0700420 }
421
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700422 return Optional.of(ImmutableList.copyOf(connectivity.value().links()));
Naoki Shiota5a056062016-05-05 18:43:59 -0700423 }
424
425 /**
426 * Scans the list of cross connection points and returns a list of optical connectivity intents.
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700427 * During the process, save information about packet links to given set.
Naoki Shiota5a056062016-05-05 18:43:59 -0700428 *
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700429 * @param crossConnectPoints list of (src, dst) pair between which optical path will be set up
Naoki Shiota5a056062016-05-05 18:43:59 -0700430 * @return list of optical connectivity intents
431 */
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700432 private List<Intent> createIntents(List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints) {
Naoki Shiota5a056062016-05-05 18:43:59 -0700433 List<Intent> intents = new LinkedList<>();
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700434 Iterator<Pair<ConnectPoint, ConnectPoint>> itr = crossConnectPoints.iterator();
Naoki Shiota5a056062016-05-05 18:43:59 -0700435
436 while (itr.hasNext()) {
437 // checkArgument at start ensures we'll always have pairs of connect points
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700438 Pair<ConnectPoint, ConnectPoint> next = itr.next();
439 ConnectPoint src = next.getLeft();
440 ConnectPoint dst = next.getRight();
Naoki Shiota5a056062016-05-05 18:43:59 -0700441
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700442 Port srcPort = deviceService.getPort(src.deviceId(), src.port());
443 Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
Naoki Shiota5a056062016-05-05 18:43:59 -0700444
445 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700446 OduCltPort srcOCPort = (OduCltPort) srcPort;
447 OduCltPort dstOCPort = (OduCltPort) dstPort;
448 if (!srcOCPort.signalType().equals(dstOCPort.signalType())) {
449 continue;
450 }
451
Naoki Shiota5a056062016-05-05 18:43:59 -0700452 // Create OTN circuit
453 OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder()
454 .appId(appId)
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700455 .src(src)
456 .dst(dst)
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700457 .signalType(srcOCPort.signalType())
Naoki Shiota5a056062016-05-05 18:43:59 -0700458 .bidirectional(true)
459 .build();
460 intents.add(circuitIntent);
Naoki Shiota5a056062016-05-05 18:43:59 -0700461 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700462 OchPort srcOchPort = (OchPort) srcPort;
463 OchPort dstOchPort = (OchPort) dstPort;
464 if (!srcOchPort.signalType().equals(dstOchPort.signalType())) {
465 continue;
466 }
467
Naoki Shiota5a056062016-05-05 18:43:59 -0700468 // Create lightpath
Naoki Shiota5a056062016-05-05 18:43:59 -0700469 OpticalConnectivityIntent opticalIntent = OpticalConnectivityIntent.builder()
470 .appId(appId)
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700471 .src(src)
472 .dst(dst)
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700473 .signalType(srcOchPort.signalType())
Naoki Shiota5a056062016-05-05 18:43:59 -0700474 .bidirectional(true)
475 .build();
476 intents.add(opticalIntent);
Naoki Shiota5a056062016-05-05 18:43:59 -0700477 } else {
478 log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type());
479 return Collections.emptyList();
480 }
481 }
482
483 return intents;
484 }
485
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700486 private Set<PacketLinkRealizedByOptical> createPacketLinkSet(List<Pair<ConnectPoint, ConnectPoint>> connectPoints,
487 List<Intent> intents,
488 Map<ConnectPoint, ConnectPoint> crossConnectPoints) {
489 checkArgument(connectPoints.size() == intents.size());
490
491 Set<PacketLinkRealizedByOptical> pLinks = new HashSet<>();
492
493 Iterator<Pair<ConnectPoint, ConnectPoint>> xcPointsItr = connectPoints.iterator();
494 Iterator<Intent> intentItr = intents.iterator();
495 while (xcPointsItr.hasNext()) {
496 Pair<ConnectPoint, ConnectPoint> xcPoints = xcPointsItr.next();
497 Intent intent = intentItr.next();
498
499 ConnectPoint packetSrc = checkNotNull(crossConnectPoints.get(xcPoints.getLeft()));
500 ConnectPoint packetDst = checkNotNull(crossConnectPoints.get(xcPoints.getRight()));
501
502 if (intent instanceof OpticalConnectivityIntent) {
503 pLinks.add(PacketLinkRealizedByOptical.create(packetSrc, packetDst,
504 (OpticalConnectivityIntent) intent));
505 } else if (intent instanceof OpticalCircuitIntent) {
506 pLinks.add(PacketLinkRealizedByOptical.create(packetSrc, packetDst,
507 (OpticalCircuitIntent) intent));
508 } else {
509 log.warn("Unexpected intent type: {}", intent.getClass());
510 }
511 }
512
513 return pLinks;
514 }
515
Naoki Shiota5a056062016-05-05 18:43:59 -0700516 /**
517 * Verifies if given device type is in packet layer, i.e., ROADM, OTN or ROADM_OTN device.
518 *
519 * @param type device type
520 * @return true if in packet layer, false otherwise
521 */
522 private boolean isPacketLayer(Device.Type type) {
523 return type == Device.Type.SWITCH || type == Device.Type.ROUTER || type == Device.Type.VIRTUAL;
524 }
525
526 /**
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -0800527 * Verifies if given device type is NOT in packet layer, i.e., switch or router device.
Naoki Shiota5a056062016-05-05 18:43:59 -0700528 *
529 * @param type device type
530 * @return true if in packet layer, false otherwise
531 */
532 private boolean isTransportLayer(Device.Type type) {
533 return type == Device.Type.ROADM || type == Device.Type.OTN || type == Device.Type.ROADM_OTN;
534 }
535
536 /**
537 * Verifies if given link forms a cross-connection between packet and optical layer.
538 *
539 * @param link the link
540 * @return true if the link is a cross-connect link, false otherwise
541 */
542 private boolean isCrossConnectLink(Link link) {
543 if (link.type() != Link.Type.OPTICAL) {
544 return false;
545 }
546
547 Device.Type src = deviceService.getDevice(link.src().deviceId()).type();
548 Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type();
549
550 return src != dst &&
551 ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src)));
552 }
553
554 /**
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800555 * Updates bandwidth resource of given connect point to specified value.
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700556 *
Naoki Shiota5a056062016-05-05 18:43:59 -0700557 * @param cp Connect point
558 * @param bandwidth New bandwidth
559 */
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800560 private void setPortBandwidth(ConnectPoint cp, Bandwidth bandwidth) {
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700561 log.debug("update Port {} Bandwidth {}", cp, bandwidth);
562 BandwidthCapacity bwCapacity = networkConfigService.addConfig(cp, BandwidthCapacity.class);
563 bwCapacity.capacity(bandwidth).apply();
Naoki Shiota5a056062016-05-05 18:43:59 -0700564 }
565
566 /**
567 * Updates usage information of bandwidth based on connectivity which is established.
568 * @param connectivity Optical connectivity
569 */
570 private void updateBandwidthUsage(OpticalConnectivity connectivity) {
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800571 if (NO_BW_REQUIREMENT.equals(connectivity.bandwidth())) {
572 // no bandwidth requirement, nothing to allocate.
573 return;
574 }
575
Naoki Shiotacb744db2016-05-13 19:32:35 -0700576 OpticalConnectivityId connectivityId = connectivity.id();
Naoki Shiota5a056062016-05-05 18:43:59 -0700577
578 List<Link> links = connectivity.links();
579
580 List<Resource> resources = links.stream().flatMap(l -> Stream.of(l.src(), l.dst()))
581 .filter(cp -> !isTransportLayer(deviceService.getDevice(cp.deviceId()).type()))
582 .map(cp -> Resources.continuous(cp.deviceId(), cp.port(),
583 Bandwidth.class).resource(connectivity.bandwidth().bps()))
584 .collect(Collectors.toList());
585
Naoki Shiotacb744db2016-05-13 19:32:35 -0700586 log.debug("allocating bandwidth for {} : {}", connectivityId, resources);
587 List<ResourceAllocation> allocations = resourceService.allocate(connectivityId, resources);
Naoki Shiota5a056062016-05-05 18:43:59 -0700588 if (allocations.isEmpty()) {
589 log.warn("Failed to allocate bandwidth {} to {}",
590 connectivity.bandwidth().bps(), resources);
591 // TODO any recovery?
592 }
Naoki Shiotacb744db2016-05-13 19:32:35 -0700593 log.debug("Done allocating bandwidth for {}", connectivityId);
Naoki Shiota5a056062016-05-05 18:43:59 -0700594 }
595
596 /**
597 * Release bandwidth allocated by given connectivity.
598 * @param connectivity Optical connectivity
599 */
600 private void releaseBandwidthUsage(OpticalConnectivity connectivity) {
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700601 if (connectivity.links().isEmpty()) {
602 return;
Naoki Shiota5a056062016-05-05 18:43:59 -0700603 }
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800604 if (NO_BW_REQUIREMENT.equals(connectivity.bandwidth())) {
605 // no bandwidth requirement, nothing to release.
606 return;
607 }
608
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700609
610 // release resource only if this node is the master for link head device
611 if (mastershipService.isLocalMaster(connectivity.links().get(0).src().deviceId())) {
612 OpticalConnectivityId connectivityId = connectivity.id();
613
614 log.debug("releasing bandwidth allocated to {}", connectivityId);
615 if (!resourceService.release(connectivityId)) {
616 log.warn("Failed to release bandwidth allocated to {}",
617 connectivityId);
618 // TODO any recovery?
619 }
620 log.debug("DONE releasing bandwidth for {}", connectivityId);
621 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700622 }
623
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800624 private boolean linkDiscoveryEnabled(ConnectPoint cp) {
625 // FIXME should check Device feature and configuration state.
626
627 // short-term hack for ONS'17 time-frame,
628 // only expect OF device to have link discovery.
629 return cp.deviceId().uri().getScheme().equals("of");
630 }
631
632 /**
633 * Returns true if both connect point support for link discovery & enabled.
634 *
635 * @param cp1 port 1
636 * @param cp2 port 2
637 * @return true if both connect point support for link discovery & enabled.
638 */
639 private boolean linkDiscoveryEnabled(ConnectPoint cp1, ConnectPoint cp2) {
640 return linkDiscoveryEnabled(cp1) && linkDiscoveryEnabled(cp2);
641 }
642
Naoki Shiota5a056062016-05-05 18:43:59 -0700643 private class BandwidthLinkWeight implements LinkWeight {
644 private Bandwidth bandwidth = null;
645
646 public BandwidthLinkWeight(Bandwidth bandwidth) {
647 this.bandwidth = bandwidth;
648 }
649
650 @Override
651 public double weight(TopologyEdge edge) {
652 Link l = edge.link();
653
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700654 // Avoid inactive links
Naoki Shiota5a056062016-05-05 18:43:59 -0700655 if (l.state() == Link.State.INACTIVE) {
Yuta HIGUCHI806113f2017-03-07 22:46:20 -0800656 log.trace("{} is not active", l);
Naoki Shiota5a056062016-05-05 18:43:59 -0700657 return -1.0;
658 }
659
Naoki Shiota0d2943e2016-05-13 18:53:21 -0700660 // Avoid cross connect links with used ports
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700661 if (isCrossConnectLink(l) && usedCrossConnectLinkSet.contains(l)) {
Yuta HIGUCHI806113f2017-03-07 22:46:20 -0800662 log.trace("Cross connect {} in use", l);
Naoki Shiota5a056062016-05-05 18:43:59 -0700663 return -1.0;
664 }
665
666 // Check availability of bandwidth
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800667 if (bandwidth != null && !NO_BW_REQUIREMENT.equals(bandwidth)) {
Naoki Shiota5a056062016-05-05 18:43:59 -0700668 if (hasEnoughBandwidth(l.src()) && hasEnoughBandwidth(l.dst())) {
669 return 1.0;
670 } else {
Yuta HIGUCHI806113f2017-03-07 22:46:20 -0800671 log.trace("Not enought bandwidth on {}", l);
Naoki Shiota5a056062016-05-05 18:43:59 -0700672 return -1.0;
673 }
674 } else {
675 // TODO needs to differentiate optical and packet?
676 if (l.type() == Link.Type.OPTICAL) {
677 // Transport links
678 return 1.0;
679 } else {
680 // Packet links
681 return 1.0;
682 }
683 }
684 }
685
686 private boolean hasEnoughBandwidth(ConnectPoint cp) {
687 if (cp.elementId() instanceof DeviceId) {
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700688 Device device = deviceService.getDevice(cp.deviceId());
689 Device.Type type = device.type();
690
Naoki Shiota5a056062016-05-05 18:43:59 -0700691 if (isTransportLayer(type)) {
Naoki Shiotae1366ad2016-05-11 19:24:11 -0700692 // Check if the port has enough capacity
693 Port port = deviceService.getPort(cp.deviceId(), cp.port());
694 if (port instanceof OduCltPort || port instanceof OchPort) {
695 // Port with capacity
696 return bandwidth.bps() < port.portSpeed() * 1000000.0;
697 } else {
698 // Port without valid capacity (OMS port, etc.)
699 return true;
700 }
701 } else {
702 // Check if enough amount of bandwidth resource remains
703 ContinuousResource resource = Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class)
704 .resource(bandwidth.bps());
Yuta HIGUCHI806113f2017-03-07 22:46:20 -0800705 try {
706 return resourceService.isAvailable(resource);
707 } catch (Exception e) {
708 log.error("Resource service failed checking availability of {}",
709 resource, e);
710 throw e;
711 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700712 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700713 }
714 return false;
715 }
716 }
717
718
719 public class InternalIntentListener implements IntentListener {
720 @Override
721 public void event(IntentEvent event) {
722 switch (event.type()) {
723 case INSTALLED:
724 log.info("Intent {} installed.", event.subject());
725 updateCrossConnectLink(event.subject());
726 break;
727 case WITHDRAWN:
728 log.info("Intent {} withdrawn.", event.subject());
729 removeCrossConnectLinks(event.subject());
730 break;
731 case FAILED:
732 log.info("Intent {} failed.", event.subject());
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800733 // TODO If it was one of it's own optical Intent,
734 // update link state
735 // TODO If it was packet P2P Intent, call setupConnectivity
Naoki Shiota5a056062016-05-05 18:43:59 -0700736 break;
737 default:
738 break;
739 }
740 }
741
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800742 // TODO rename "CrossConnectLink"?
743 /**
744 * Update packet-layer link/port state once Intent is installed.
745 *
746 * @param intent which reached installed state
747 */
Naoki Shiota5a056062016-05-05 18:43:59 -0700748 private void updateCrossConnectLink(Intent intent) {
749 linkPathMap.entrySet().stream()
750 .filter(e -> e.getKey().realizingIntentKey().equals(intent.key()))
751 .forEach(e -> {
752 ConnectPoint packetSrc = e.getKey().src();
753 ConnectPoint packetDst = e.getKey().dst();
754 Bandwidth bw = e.getKey().bandwidth();
Naoki Shiota5a056062016-05-05 18:43:59 -0700755
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700756 // reflect modification only if packetSrc is local_
757 if (mastershipService.isLocalMaster(packetSrc.deviceId())) {
758 // Updates bandwidth of packet ports
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800759 setPortBandwidth(packetSrc, bw);
760 setPortBandwidth(packetDst, bw);
Naoki Shiota5a056062016-05-05 18:43:59 -0700761
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700762 // Updates link status in distributed map
763 linkPathMap.computeIfPresent(e.getKey(), (link, connectivity) ->
764 e.getValue().value().setLinkEstablished(packetSrc, packetDst, true));
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800765
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800766
767 if (!linkDiscoveryEnabled(packetSrc, packetDst)) {
768 injectLink(packetSrc, packetDst);
769 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700770 }
771 });
772 }
773
774 private void removeCrossConnectLinks(Intent intent) {
775 ConnectPoint src, dst;
776
777 if (intent instanceof OpticalCircuitIntent) {
778 OpticalCircuitIntent circuit = (OpticalCircuitIntent) intent;
779 src = circuit.getSrc();
780 dst = circuit.getDst();
781 } else if (intent instanceof OpticalConnectivityIntent) {
782 OpticalConnectivityIntent conn = (OpticalConnectivityIntent) intent;
783 src = conn.getSrc();
784 dst = conn.getDst();
785 } else {
786 return;
787 }
788
789 removeXcLinkUsage(src);
790 removeXcLinkUsage(dst);
791
792 // Set bandwidth of 0 to cross connect ports
793 Bandwidth bw = Bandwidth.bps(0);
794 linkPathMap.entrySet().stream()
795 .filter(e -> e.getKey().realizingIntentKey().equals(intent.key()))
796 .forEach(e -> {
797 ConnectPoint packetSrc = e.getKey().src();
798 ConnectPoint packetDst = e.getKey().dst();
Naoki Shiota5a056062016-05-05 18:43:59 -0700799
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700800 // reflect modification only if packetSrc is local_
801 if (mastershipService.isLocalMaster(packetSrc.deviceId())) {
802 // Updates bandwidth of packet ports
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800803 setPortBandwidth(packetSrc, bw);
804 setPortBandwidth(packetDst, bw);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700805
806 // Updates link status in distributed map
807 linkPathMap.computeIfPresent(e.getKey(), (link, connectivity) ->
808 e.getValue().value().setLinkEstablished(packetSrc, packetDst, false));
Yuta HIGUCHIe80ec2c2017-03-06 14:16:13 -0800809
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800810
811 if (!linkDiscoveryEnabled(packetSrc, packetDst)) {
812 removeInjectedLink(packetSrc, packetDst);
813 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700814 }
815 });
816 }
817
818 private void removeXcLinkUsage(ConnectPoint cp) {
819 Optional<Link> link = linkService.getLinks(cp).stream()
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700820 .filter(usedCrossConnectLinkSet::contains)
Naoki Shiota5a056062016-05-05 18:43:59 -0700821 .findAny();
822
823 if (!link.isPresent()) {
824 log.warn("Cross connect point {} has no cross connect link.", cp);
825 return;
826 }
827
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700828 usedCrossConnectLinkSet.remove(link.get());
Naoki Shiota5a056062016-05-05 18:43:59 -0700829 }
Yuta HIGUCHI9b9c7292017-03-07 22:50:04 -0800830
831 /**
832 * Injects link between specified packet port.
833 *
834 * @param packetSrc port 1
835 * @param packetDst port 2
836 */
837 private void injectLink(ConnectPoint packetSrc,
838 ConnectPoint packetDst) {
839 // inject expected link or durable link
840 // if packet device cannot advertise packet link
841 try {
842 BasicLinkConfig lnkCfg = networkConfigService
843 .addConfig(linkKey(packetSrc, packetDst),
844 BasicLinkConfig.class);
845 lnkCfg.isAllowed(true);
846 lnkCfg.isDurable(true);
847 lnkCfg.type(Link.Type.DIRECT);
848 lnkCfg.apply();
849 } catch (Exception ex) {
850 log.error("Applying BasicLinkConfig failed", ex);
851 }
852 }
853
854 /**
855 * Removes link injected between specified packet port.
856 *
857 * @param packetSrc port 1
858 * @param packetDst port 2
859 */
860 private void removeInjectedLink(ConnectPoint packetSrc,
861 ConnectPoint packetDst) {
862 // remove expected link or durable link
863 // if packet device cannot monitor packet link
864
865 try {
866 // hack to mark link off-line
867 BasicLinkConfig lnkCfg = networkConfigService
868 .getConfig(linkKey(packetSrc, packetDst),
869 BasicLinkConfig.class);
870 lnkCfg.isAllowed(false);
871 lnkCfg.apply();
872 } catch (Exception ex) {
873 log.error("Applying BasicLinkConfig failed", ex);
874 }
875
876 networkConfigService
877 .removeConfig(linkKey(packetSrc, packetDst),
878 BasicLinkConfig.class);
879 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700880 }
881
882
883 private class InternalLinkListener implements LinkListener {
884
885 @Override
886 public void event(LinkEvent event) {
887 switch (event.type()) {
888 case LINK_REMOVED:
889 Link link = event.subject();
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700890 // updates linkPathMap only if src device of link is local
891 if (!mastershipService.isLocalMaster(link.src().deviceId())) {
892 return;
893 }
894
895 // find all packet links that correspond to removed link
Naoki Shiota5a056062016-05-05 18:43:59 -0700896 Set<PacketLinkRealizedByOptical> pLinks = linkPathMap.keySet().stream()
897 .filter(l -> l.isBetween(link.src(), link.dst()) || l.isBetween(link.dst(), link.src()))
898 .collect(Collectors.toSet());
899
900 pLinks.forEach(l -> {
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700901 // remove found packet links from distributed store
902 linkPathMap.computeIfPresent(l, (plink, conn) -> {
903 // Notifies listeners if all packet links are gone
904 if (conn.isAllRealizingLinkNotEstablished()) {
905 post(new OpticalPathEvent(OpticalPathEvent.Type.PATH_REMOVED, conn.id()));
906 }
907 return null;
908 });
Naoki Shiota5a056062016-05-05 18:43:59 -0700909 });
910 default:
911 break;
912 }
913 }
914 }
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700915
916 private class InternalStoreListener
917 implements MapEventListener<PacketLinkRealizedByOptical, OpticalConnectivity> {
918
919 @Override
920 public void event(MapEvent<PacketLinkRealizedByOptical, OpticalConnectivity> event) {
921 switch (event.type()) {
922 case UPDATE:
923 OpticalConnectivity oldConnectivity = event.oldValue().value();
924 OpticalConnectivity newConnectivity = event.newValue().value();
925
926 if (!oldConnectivity.isAllRealizingLinkEstablished() &&
927 newConnectivity.isAllRealizingLinkEstablished()) {
928 // Notifies listeners if all links are established
929 updateBandwidthUsage(newConnectivity);
930 post(new OpticalPathEvent(OpticalPathEvent.Type.PATH_INSTALLED, newConnectivity.id()));
931 } else if (!oldConnectivity.isAllRealizingLinkNotEstablished() &&
932 newConnectivity.isAllRealizingLinkNotEstablished()) {
933 // Notifies listeners if all links are gone
934 releaseBandwidthUsage(newConnectivity);
935 post(new OpticalPathEvent(OpticalPathEvent.Type.PATH_REMOVED, newConnectivity.id()));
936 }
937
938 break;
939 default:
940 break;
941 }
942 }
943
944 }
Naoki Shiota5a056062016-05-05 18:43:59 -0700945}
946