Naoki Shiota
Committed by Yuta HIGUCHI

bug fixes and cosmetic changes about OpticalPathProvisioner:

- removeSink() at deactivate
- added log messages
- wrapped null return value with Optional

Change-Id: Ic5361df3cf82f99af315b2551d33bb84aed241ed
...@@ -31,6 +31,9 @@ import org.onosproject.cluster.ClusterService; ...@@ -31,6 +31,9 @@ import org.onosproject.cluster.ClusterService;
31 import org.onosproject.cluster.NodeId; 31 import org.onosproject.cluster.NodeId;
32 import org.onosproject.core.ApplicationId; 32 import org.onosproject.core.ApplicationId;
33 import org.onosproject.core.CoreService; 33 import org.onosproject.core.CoreService;
34 +import org.onosproject.event.ListenerTracker;
35 +import org.onosproject.net.optical.OchPort;
36 +import org.onosproject.net.optical.OduCltPort;
34 import org.onosproject.newoptical.api.OpticalConnectivityId; 37 import org.onosproject.newoptical.api.OpticalConnectivityId;
35 import org.onosproject.newoptical.api.OpticalPathEvent; 38 import org.onosproject.newoptical.api.OpticalPathEvent;
36 import org.onosproject.newoptical.api.OpticalPathListener; 39 import org.onosproject.newoptical.api.OpticalPathListener;
...@@ -42,8 +45,6 @@ import org.onosproject.net.ConnectPoint; ...@@ -42,8 +45,6 @@ import org.onosproject.net.ConnectPoint;
42 import org.onosproject.net.Device; 45 import org.onosproject.net.Device;
43 import org.onosproject.net.DeviceId; 46 import org.onosproject.net.DeviceId;
44 import org.onosproject.net.Link; 47 import org.onosproject.net.Link;
45 -import org.onosproject.net.OchPort;
46 -import org.onosproject.net.OduCltPort;
47 import org.onosproject.net.OduSignalType; 48 import org.onosproject.net.OduSignalType;
48 import org.onosproject.net.Path; 49 import org.onosproject.net.Path;
49 import org.onosproject.net.Port; 50 import org.onosproject.net.Port;
...@@ -138,8 +139,7 @@ public class OpticalPathProvisioner ...@@ -138,8 +139,7 @@ public class OpticalPathProvisioner
138 139
139 private AtomicCounter idCounter; 140 private AtomicCounter idCounter;
140 141
141 - private LinkListener linkListener = new InternalLinkListener(); 142 + private ListenerTracker listeners;
142 - private IntentListener intentListener = new InternalIntentListener();
143 143
144 private Map<PacketLinkRealizedByOptical, OpticalConnectivity> linkPathMap = new ConcurrentHashMap<>(); 144 private Map<PacketLinkRealizedByOptical, OpticalConnectivity> linkPathMap = new ConcurrentHashMap<>();
145 145
...@@ -161,16 +161,18 @@ public class OpticalPathProvisioner ...@@ -161,16 +161,18 @@ public class OpticalPathProvisioner
161 .asAtomicCounter(); 161 .asAtomicCounter();
162 162
163 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry); 163 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry);
164 - linkService.addListener(linkListener); 164 +
165 - intentService.addListener(intentListener); 165 + listeners = new ListenerTracker();
166 + listeners.addListener(linkService, new InternalLinkListener())
167 + .addListener(intentService, new InternalIntentListener());
166 168
167 log.info("Started"); 169 log.info("Started");
168 } 170 }
169 171
170 @Deactivate 172 @Deactivate
171 protected void deactivate() { 173 protected void deactivate() {
172 - intentService.removeListener(intentListener); 174 + listeners.removeListeners();
173 - linkService.removeListener(linkListener); 175 + eventDispatcher.removeSink(OpticalPathEvent.class);
174 176
175 log.info("Stopped"); 177 log.info("Stopped");
176 } 178 }
...@@ -200,6 +202,8 @@ public class OpticalPathProvisioner ...@@ -200,6 +202,8 @@ public class OpticalPathProvisioner
200 } 202 }
201 } 203 }
202 204
205 + log.info("setupConnectivity({}, {}, {}, {}) failed.", ingress, egress, bandwidth, latency);
206 +
203 return null; 207 return null;
204 } 208 }
205 209
...@@ -212,6 +216,7 @@ public class OpticalPathProvisioner ...@@ -212,6 +216,7 @@ public class OpticalPathProvisioner
212 List<Pair<ConnectPoint, ConnectPoint>> xcPointPairs = getCrossConnectPoints(path); 216 List<Pair<ConnectPoint, ConnectPoint>> xcPointPairs = getCrossConnectPoints(path);
213 if (!checkXcPoints(xcPointPairs)) { 217 if (!checkXcPoints(xcPointPairs)) {
214 // Can't setup path if cross connect points are mismatched 218 // Can't setup path if cross connect points are mismatched
219 + log.error("Failed to setup path because of mismatched cross connect points.");
215 return null; 220 return null;
216 } 221 }
217 222
...@@ -261,6 +266,7 @@ public class OpticalPathProvisioner ...@@ -261,6 +266,7 @@ public class OpticalPathProvisioner
261 OpticalConnectivity connectivity = connectivities.remove(id); 266 OpticalConnectivity connectivity = connectivities.remove(id);
262 267
263 if (connectivity == null) { 268 if (connectivity == null) {
269 + log.info("OpticalConnectivity with id {} not found.", id);
264 return false; 270 return false;
265 } 271 }
266 272
...@@ -274,13 +280,14 @@ public class OpticalPathProvisioner ...@@ -274,13 +280,14 @@ public class OpticalPathProvisioner
274 } 280 }
275 281
276 @Override 282 @Override
277 - public List<Link> getPath(OpticalConnectivityId id) { 283 + public Optional<List<Link>> getPath(OpticalConnectivityId id) {
278 OpticalConnectivity connectivity = connectivities.get(id); 284 OpticalConnectivity connectivity = connectivities.get(id);
279 if (connectivity == null) { 285 if (connectivity == null) {
280 - return null; 286 + log.info("OpticalConnectivity with id {} not found.", id);
287 + return Optional.empty();
281 } 288 }
282 289
283 - return ImmutableList.copyOf(connectivity.links()); 290 + return Optional.of(ImmutableList.copyOf(connectivity.links()));
284 } 291 }
285 292
286 /** 293 /**
...@@ -337,7 +344,7 @@ public class OpticalPathProvisioner ...@@ -337,7 +344,7 @@ public class OpticalPathProvisioner
337 344
338 // Only support connections between identical port types 345 // Only support connections between identical port types
339 if (srcType != dstType) { 346 if (srcType != dstType) {
340 - log.warn("Unsupported mix of cross connect points"); 347 + log.warn("Unsupported mix of cross connect points : {}, {}", srcType, dstType);
341 return false; 348 return false;
342 } 349 }
343 } 350 }
...@@ -516,12 +523,12 @@ public class OpticalPathProvisioner ...@@ -516,12 +523,12 @@ public class OpticalPathProvisioner
516 public double weight(TopologyEdge edge) { 523 public double weight(TopologyEdge edge) {
517 Link l = edge.link(); 524 Link l = edge.link();
518 525
519 - // Ignore inactive links 526 + // Avoid inactive links
520 if (l.state() == Link.State.INACTIVE) { 527 if (l.state() == Link.State.INACTIVE) {
521 return -1.0; 528 return -1.0;
522 } 529 }
523 530
524 - // Ignore cross connect links with used ports 531 + // Avoid cross connect links with used ports
525 if (isCrossConnectLink(l) && usedCrossConnectLinks.contains(l)) { 532 if (isCrossConnectLink(l) && usedCrossConnectLinks.contains(l)) {
526 return -1.0; 533 return -1.0;
527 } 534 }
......
...@@ -24,6 +24,7 @@ import org.onosproject.net.Path; ...@@ -24,6 +24,7 @@ import org.onosproject.net.Path;
24 24
25 import java.time.Duration; 25 import java.time.Duration;
26 import java.util.List; 26 import java.util.List;
27 +import java.util.Optional;
27 28
28 /** 29 /**
29 * Service to setup optical domain connectivity. 30 * Service to setup optical domain connectivity.
...@@ -64,7 +65,7 @@ public interface OpticalPathService extends ListenerService<OpticalPathEvent, Op ...@@ -64,7 +65,7 @@ public interface OpticalPathService extends ListenerService<OpticalPathEvent, Op
64 /** 65 /**
65 * Returns path assigned to given ID. 66 * Returns path assigned to given ID.
66 * @param id ID of connectivity 67 * @param id ID of connectivity
67 - * @return list of link that compose a path. null if ID is invalid. 68 + * @return list of link that compose a path. empty if ID is invalid.
68 */ 69 */
69 - List<Link> getPath(OpticalConnectivityId id); 70 + Optional<List<Link>> getPath(OpticalConnectivityId id);
70 } 71 }
......