Nikhil Cheerla
Committed by Thomas Vachuska

Disjoint Path Utils Exposed

- to TopologyStores
- to TopologyServices
- to PathServices
- to REST API

Change-Id: Ib2b5840df0f8e94f327ec8f91827d3d850634562

Change-Id: I03e59210e9c79c4f92dcfa8c7983642572708429

Change-Id: Ia5c17d1ded374ef688990bd30e7f99184aaca95b

Change-Id: Ibebae50bc722701e8212263587727ad8abd79805
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
15 */ 15 */
16 package org.onosproject.net.topology; 16 package org.onosproject.net.topology;
17 17
18 +import org.onosproject.net.DisjointPath;
18 import org.onosproject.net.ElementId; 19 import org.onosproject.net.ElementId;
20 +import org.onosproject.net.Link;
19 import org.onosproject.net.Path; 21 import org.onosproject.net.Path;
20 22
23 +import java.util.Map;
21 import java.util.Set; 24 import java.util.Set;
22 25
23 /** 26 /**
...@@ -48,4 +51,51 @@ public interface PathService { ...@@ -48,4 +51,51 @@ public interface PathService {
48 */ 51 */
49 Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight); 52 Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight);
50 53
54 + /**
55 + * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
56 + * between the specified source and destination devices.
57 + *
58 + * @param src source device
59 + * @param dst destination device
60 + * @return set of all shortest paths between the two devices
61 + */
62 + Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst);
63 +
64 + /**
65 + * Returns the set of all disjoint shortest path pairs, computed using the supplied
66 + * edge-weight entity, between the specified source and destination devices.
67 + *
68 + * @param src source device
69 + * @param dst destination device
70 + * @param weight edge-weight entity
71 + * @return set of all shortest paths between the two devices
72 + */
73 + Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst,
74 + LinkWeight weight);
75 +
76 + /**
77 + * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
78 + * between the specified source and destination devices.
79 + *
80 + * @param src source device
81 + * @param dst destination device
82 + * @param riskProfile map of edges to risk profiles
83 + * @return set of all shortest paths between the two devices
84 + */
85 + Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst,
86 + Map<Link, Object> riskProfile);
87 +
88 + /**
89 + * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
90 + * between the specified source and destination devices.
91 + *
92 + * @param src source device
93 + * @param dst destination device
94 + * @param weight edge-weight entity
95 + * @param riskProfile map of edges to risk profiles
96 + * @return set of all shortest paths between the two devices
97 + */
98 + Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst,
99 + LinkWeight weight, Map<Link, Object> riskProfile);
100 +
51 } 101 }
......
...@@ -18,9 +18,11 @@ package org.onosproject.net.topology; ...@@ -18,9 +18,11 @@ package org.onosproject.net.topology;
18 import org.onosproject.event.ListenerService; 18 import org.onosproject.event.ListenerService;
19 import org.onosproject.net.ConnectPoint; 19 import org.onosproject.net.ConnectPoint;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
21 +import org.onosproject.net.DisjointPath;
21 import org.onosproject.net.Link; 22 import org.onosproject.net.Link;
22 import org.onosproject.net.Path; 23 import org.onosproject.net.Path;
23 24
25 +import java.util.Map;
24 import java.util.Set; 26 import java.util.Set;
25 27
26 /** 28 /**
...@@ -112,6 +114,56 @@ public interface TopologyService ...@@ -112,6 +114,56 @@ public interface TopologyService
112 LinkWeight weight); 114 LinkWeight weight);
113 115
114 /** 116 /**
117 + * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
118 + * between the specified source and destination devices.
119 + *
120 + * @param topology topology descriptor
121 + * @param src source device
122 + * @param dst destination device
123 + * @return set of all shortest paths between the two devices
124 + */
125 + Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst);
126 +
127 + /**
128 + * Returns the set of all disjoint shortest path pairs, computed using the supplied
129 + * edge-weight entity, between the specified source and destination devices.
130 + *
131 + * @param topology topology descriptor
132 + * @param src source device
133 + * @param dst destination device
134 + * @param weight edge-weight entity
135 + * @return set of all shortest paths between the two devices
136 + */
137 + Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
138 + LinkWeight weight);
139 +
140 + /**
141 + * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
142 + * between the specified source and destination devices.
143 + *
144 + * @param topology topology descriptor
145 + * @param src source device
146 + * @param dst destination device
147 + * @param riskProfile map of edges to risk profiles
148 + * @return set of all shortest paths between the two devices
149 + */
150 + Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
151 + Map<Link, Object> riskProfile);
152 +
153 + /**
154 + * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count,
155 + * between the specified source and destination devices.
156 + *
157 + * @param topology topology descriptor
158 + * @param src source device
159 + * @param dst destination device
160 + * @param weight edge-weight entity
161 + * @param riskProfile map of edges to risk profiles
162 + * @return set of all shortest paths between the two devices
163 + */
164 + Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
165 + LinkWeight weight, Map<Link, Object> riskProfile);
166 + /**
115 * Indicates whether the specified connection point is part of the network 167 * Indicates whether the specified connection point is part of the network
116 * infrastructure or part of network edge. 168 * infrastructure or part of network edge.
117 * 169 *
......
...@@ -20,11 +20,13 @@ import org.onosproject.net.ConnectPoint; ...@@ -20,11 +20,13 @@ import org.onosproject.net.ConnectPoint;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
21 import org.onosproject.net.Link; 21 import org.onosproject.net.Link;
22 import org.onosproject.net.Path; 22 import org.onosproject.net.Path;
23 +import org.onosproject.net.DisjointPath;
23 import org.onosproject.net.provider.ProviderId; 24 import org.onosproject.net.provider.ProviderId;
24 import org.onosproject.store.Store; 25 import org.onosproject.store.Store;
25 26
26 import java.util.List; 27 import java.util.List;
27 import java.util.Set; 28 import java.util.Set;
29 +import java.util.Map;
28 30
29 /** 31 /**
30 * Manages inventory of topology snapshots; not intended for direct use. 32 * Manages inventory of topology snapshots; not intended for direct use.
...@@ -112,6 +114,59 @@ public interface TopologyStore extends Store<TopologyEvent, TopologyStoreDelegat ...@@ -112,6 +114,59 @@ public interface TopologyStore extends Store<TopologyEvent, TopologyStoreDelegat
112 LinkWeight weight); 114 LinkWeight weight);
113 115
114 /** 116 /**
117 + * Computes and returns the set of disjoint shortest path pairs
118 + * between src and dst.
119 + *
120 + * @param topology topology descriptor
121 + * @param src source device
122 + * @param dst destination device
123 + * @param weight link weight function
124 + * @return set of shortest paths
125 + */
126 + Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
127 + LinkWeight weight);
128 +
129 + /**
130 + * Computes and returns the set of disjoint shortest path pairs
131 + * between src and dst.
132 + *
133 + * @param topology topology descriptor
134 + * @param src source device
135 + * @param dst destination device
136 + * @return set of shortest paths
137 + */
138 + Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst);
139 +
140 + /**
141 + * Computes and returns the set of SRLG disjoint shortest path pairs between source
142 + * and dst, given a mapping of edges to SRLG risk groups.
143 + *
144 + * @param topology topology descriptor
145 + * @param src source device
146 + * @param dst destination device
147 + * @param weight link weight function
148 + * @param riskProfile map of edges to objects. Edges that map to the same object will
149 + * be treated as if they were in the same risk group.
150 + * @return set of shortest paths
151 + */
152 + Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
153 + LinkWeight weight, Map<Link, Object> riskProfile);
154 +
155 + /**
156 + * Returns the set of pre-computed SRLG shortest paths between src and dest.
157 + *
158 + * @param topology topology descriptor
159 + * @param src source device
160 + * @param dst destination device
161 + * @param riskProfile map of edges to objects. Edges that map to the same object will
162 + * be treated as if they were in the same risk group.
163 + * @return set of shortest paths
164 + */
165 + Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
166 + Map<Link, Object> riskProfile);
167 +
168 +
169 + /**
115 * Indicates whether the given connect point is part of the network fabric. 170 * Indicates whether the given connect point is part of the network fabric.
116 * 171 *
117 * @param topology topology descriptor 172 * @param topology topology descriptor
......
...@@ -22,6 +22,7 @@ import org.onlab.util.Bandwidth; ...@@ -22,6 +22,7 @@ import org.onlab.util.Bandwidth;
22 import org.onosproject.core.DefaultGroupId; 22 import org.onosproject.core.DefaultGroupId;
23 import org.onosproject.core.GroupId; 23 import org.onosproject.core.GroupId;
24 import org.onosproject.net.DeviceId; 24 import org.onosproject.net.DeviceId;
25 +import org.onosproject.net.DisjointPath;
25 import org.onosproject.net.ElementId; 26 import org.onosproject.net.ElementId;
26 import org.onosproject.net.Link; 27 import org.onosproject.net.Link;
27 import org.onosproject.net.NetTestTools; 28 import org.onosproject.net.NetTestTools;
...@@ -64,6 +65,7 @@ import java.util.Collections; ...@@ -64,6 +65,7 @@ import java.util.Collections;
64 import java.util.HashSet; 65 import java.util.HashSet;
65 import java.util.LinkedList; 66 import java.util.LinkedList;
66 import java.util.List; 67 import java.util.List;
68 +import java.util.Map;
67 import java.util.Objects; 69 import java.util.Objects;
68 import java.util.Set; 70 import java.util.Set;
69 import java.util.concurrent.atomic.AtomicLong; 71 import java.util.concurrent.atomic.AtomicLong;
...@@ -185,6 +187,28 @@ public class IntentTestsMocks { ...@@ -185,6 +187,28 @@ public class IntentTestsMocks {
185 } 187 }
186 return paths; 188 return paths;
187 } 189 }
190 +
191 + @Override
192 + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) {
193 + return null;
194 + }
195 +
196 + @Override
197 + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) {
198 + return null;
199 + }
200 +
201 + @Override
202 + public Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst,
203 + Map<Link, Object> riskProfile) {
204 + return null;
205 + }
206 +
207 + @Override
208 + public Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst, LinkWeight weight,
209 + Map<Link, Object> riskProfile) {
210 + return null;
211 + }
188 } 212 }
189 213
190 public static class MockLinkResourceAllocations implements LinkResourceAllocations { 214 public static class MockLinkResourceAllocations implements LinkResourceAllocations {
......
...@@ -17,9 +17,11 @@ package org.onosproject.net.topology; ...@@ -17,9 +17,11 @@ package org.onosproject.net.topology;
17 17
18 import org.onosproject.net.ConnectPoint; 18 import org.onosproject.net.ConnectPoint;
19 import org.onosproject.net.DeviceId; 19 import org.onosproject.net.DeviceId;
20 +import org.onosproject.net.DisjointPath;
20 import org.onosproject.net.Link; 21 import org.onosproject.net.Link;
21 import org.onosproject.net.Path; 22 import org.onosproject.net.Path;
22 23
24 +import java.util.Map;
23 import java.util.Set; 25 import java.util.Set;
24 26
25 /** 27 /**
...@@ -88,5 +90,26 @@ public class TopologyServiceAdapter implements TopologyService { ...@@ -88,5 +90,26 @@ public class TopologyServiceAdapter implements TopologyService {
88 @Override 90 @Override
89 public void removeListener(TopologyListener listener) { 91 public void removeListener(TopologyListener listener) {
90 } 92 }
93 + @Override
94 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
95 + return null;
96 + }
97 +
98 + @Override
99 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
100 + return null;
101 + }
102 +
103 + @Override
104 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
105 + Map<Link, Object> riskProfile) {
106 + return null;
107 + }
108 +
109 + @Override
110 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight,
111 + Map<Link, Object> riskProfile) {
112 + return null;
113 + }
91 114
92 } 115 }
......
...@@ -322,8 +322,9 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -322,8 +322,9 @@ public class DefaultTopology extends AbstractModel implements Topology {
322 } 322 }
323 return builder.build(); 323 return builder.build();
324 } 324 }
325 +
325 /** 326 /**
326 - /** 327 + * /**
327 * Returns the set of pre-computed shortest disjoint path pairs between source and 328 * Returns the set of pre-computed shortest disjoint path pairs between source and
328 * destination devices. 329 * destination devices.
329 * 330 *
...@@ -331,7 +332,7 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -331,7 +332,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
331 * @param dst destination device 332 * @param dst destination device
332 * @return set of shortest disjoint path pairs 333 * @return set of shortest disjoint path pairs
333 */ 334 */
334 - Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst) { 335 + public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst) {
335 return getDisjointPaths(src, dst, null); 336 return getDisjointPaths(src, dst, null);
336 } 337 }
337 338
...@@ -344,7 +345,7 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -344,7 +345,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
344 * @param weight link weight function 345 * @param weight link weight function
345 * @return set of disjoint shortest path pairs 346 * @return set of disjoint shortest path pairs
346 */ 347 */
347 - Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight) { 348 + public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
348 final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); 349 final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
349 final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); 350 final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
350 Set<TopologyVertex> vertices = graph.getVertexes(); 351 Set<TopologyVertex> vertices = graph.getVertexes();
...@@ -371,7 +372,7 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -371,7 +372,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
371 * @param riskProfile map representing risk groups for each edge 372 * @param riskProfile map representing risk groups for each edge
372 * @return set of shortest disjoint paths 373 * @return set of shortest disjoint paths
373 */ 374 */
374 - Set<DisjointPath> getSRLGDisjointPathsD(DeviceId src, DeviceId dst, Map<TopologyEdge, Object> riskProfile) { 375 + public Set<DisjointPath> getSRLGDisjointPathsD(DeviceId src, DeviceId dst, Map<TopologyEdge, Object> riskProfile) {
375 return getSRLGDisjointPathsD(src, dst, null, riskProfile); 376 return getSRLGDisjointPathsD(src, dst, null, riskProfile);
376 } 377 }
377 378
...@@ -385,7 +386,7 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -385,7 +386,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
385 * @param riskProfile map representing risk groups for each edge 386 * @param riskProfile map representing risk groups for each edge
386 * @return set of shortest disjoint paths 387 * @return set of shortest disjoint paths
387 */ 388 */
388 - Set<DisjointPath> getSRLGDisjointPathsD(DeviceId src, DeviceId dst, LinkWeight weight, Map<TopologyEdge, 389 + public Set<DisjointPath> getSRLGDisjointPathsD(DeviceId src, DeviceId dst, LinkWeight weight, Map<TopologyEdge,
389 Object> riskProfile) { 390 Object> riskProfile) {
390 final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); 391 final DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
391 final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst); 392 final DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
...@@ -415,7 +416,7 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -415,7 +416,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
415 * @param riskProfile map representing risk groups for each link 416 * @param riskProfile map representing risk groups for each link
416 * @return set of shortest disjoint paths 417 * @return set of shortest disjoint paths
417 */ 418 */
418 - Set<DisjointPath> getSRLGDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight, 419 + public Set<DisjointPath> getSRLGDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight,
419 Map<Link, Object> riskProfile) { 420 Map<Link, Object> riskProfile) {
420 Map<TopologyEdge, Object> riskProfile2 = new HashMap<>(); 421 Map<TopologyEdge, Object> riskProfile2 = new HashMap<>();
421 for (Link l : riskProfile.keySet()) { 422 for (Link l : riskProfile.keySet()) {
...@@ -455,7 +456,7 @@ public class DefaultTopology extends AbstractModel implements Topology { ...@@ -455,7 +456,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
455 * @param riskProfile map representing risk groups for each link 456 * @param riskProfile map representing risk groups for each link
456 * @return set of shortest disjoint paths 457 * @return set of shortest disjoint paths
457 */ 458 */
458 - Set<DisjointPath> getSRLGDisjointPaths(DeviceId src, DeviceId dst, Map<Link, Object> riskProfile) { 459 + public Set<DisjointPath> getSRLGDisjointPaths(DeviceId src, DeviceId dst, Map<Link, Object> riskProfile) {
459 return getSRLGDisjointPaths(src, dst, null, riskProfile); 460 return getSRLGDisjointPaths(src, dst, null, riskProfile);
460 } 461 }
461 462
......
...@@ -23,6 +23,7 @@ import org.onosproject.common.DefaultTopology; ...@@ -23,6 +23,7 @@ import org.onosproject.common.DefaultTopology;
23 import org.onosproject.event.Event; 23 import org.onosproject.event.Event;
24 import org.onosproject.net.ConnectPoint; 24 import org.onosproject.net.ConnectPoint;
25 import org.onosproject.net.DeviceId; 25 import org.onosproject.net.DeviceId;
26 +import org.onosproject.net.DisjointPath;
26 import org.onosproject.net.Link; 27 import org.onosproject.net.Link;
27 import org.onosproject.net.Path; 28 import org.onosproject.net.Path;
28 import org.onosproject.net.provider.ProviderId; 29 import org.onosproject.net.provider.ProviderId;
...@@ -39,6 +40,7 @@ import org.onosproject.store.AbstractStore; ...@@ -39,6 +40,7 @@ import org.onosproject.store.AbstractStore;
39 import org.slf4j.Logger; 40 import org.slf4j.Logger;
40 41
41 import java.util.List; 42 import java.util.List;
43 +import java.util.Map;
42 import java.util.Set; 44 import java.util.Set;
43 45
44 import static org.slf4j.LoggerFactory.getLogger; 46 import static org.slf4j.LoggerFactory.getLogger;
...@@ -114,6 +116,29 @@ public class SimpleTopologyStore ...@@ -114,6 +116,29 @@ public class SimpleTopologyStore
114 } 116 }
115 117
116 @Override 118 @Override
119 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
120 + return defaultTopology(topology).getDisjointPaths(src, dst);
121 + }
122 +
123 + @Override
124 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
125 + LinkWeight weight) {
126 + return defaultTopology(topology).getDisjointPaths(src, dst, weight);
127 + }
128 +
129 + @Override
130 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
131 + Map<Link, Object> riskProfile) {
132 + return defaultTopology(topology).getSRLGDisjointPaths(src, dst, riskProfile);
133 + }
134 +
135 + @Override
136 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
137 + LinkWeight weight, Map<Link, Object> riskProfile) {
138 + return defaultTopology(topology).getSRLGDisjointPaths(src, dst, weight, riskProfile);
139 + }
140 +
141 + @Override
117 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { 142 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
118 return defaultTopology(topology).isInfrastructure(connectPoint); 143 return defaultTopology(topology).isInfrastructure(connectPoint);
119 } 144 }
......
...@@ -27,6 +27,8 @@ import org.apache.felix.scr.annotations.Service; ...@@ -27,6 +27,8 @@ import org.apache.felix.scr.annotations.Service;
27 import org.onosproject.net.ConnectPoint; 27 import org.onosproject.net.ConnectPoint;
28 import org.onosproject.net.DefaultEdgeLink; 28 import org.onosproject.net.DefaultEdgeLink;
29 import org.onosproject.net.DefaultPath; 29 import org.onosproject.net.DefaultPath;
30 +import org.onosproject.net.DisjointPath;
31 +import org.onosproject.net.DefaultDisjointPath;
30 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
31 import org.onosproject.net.EdgeLink; 33 import org.onosproject.net.EdgeLink;
32 import org.onosproject.net.ElementId; 34 import org.onosproject.net.ElementId;
...@@ -46,6 +48,8 @@ import org.slf4j.Logger; ...@@ -46,6 +48,8 @@ import org.slf4j.Logger;
46 48
47 import java.util.List; 49 import java.util.List;
48 import java.util.Set; 50 import java.util.Set;
51 +import java.util.Map;
52 +
49 53
50 import static com.google.common.base.Preconditions.checkNotNull; 54 import static com.google.common.base.Preconditions.checkNotNull;
51 import static org.slf4j.LoggerFactory.getLogger; 55 import static org.slf4j.LoggerFactory.getLogger;
...@@ -128,6 +132,84 @@ public class PathManager implements PathService { ...@@ -128,6 +132,84 @@ public class PathManager implements PathService {
128 return edgeToEdgePaths(srcEdge, dstEdge, paths); 132 return edgeToEdgePaths(srcEdge, dstEdge, paths);
129 } 133 }
130 134
135 + @Override
136 + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) {
137 + return getDisjointPaths(src, dst, null);
138 + }
139 +
140 + @Override
141 + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) {
142 + checkNotNull(src, ELEMENT_ID_NULL);
143 + checkNotNull(dst, ELEMENT_ID_NULL);
144 +
145 + // Get the source and destination edge locations
146 + EdgeLink srcEdge = getEdgeLink(src, true);
147 + EdgeLink dstEdge = getEdgeLink(dst, false);
148 +
149 + // If either edge is null, bail with no paths.
150 + if (srcEdge == null || dstEdge == null) {
151 + return ImmutableSet.of();
152 + }
153 +
154 + DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
155 + DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
156 +
157 + // If the source and destination are on the same edge device, there
158 + // is just one path, so build it and return it.
159 + if (srcDevice.equals(dstDevice)) {
160 + return edgeToEdgePathsDisjoint(srcEdge, dstEdge);
161 + }
162 +
163 + // Otherwise get all paths between the source and destination edge
164 + // devices.
165 + Topology topology = topologyService.currentTopology();
166 + Set<DisjointPath> paths = weight == null ?
167 + topologyService.getDisjointPaths(topology, srcDevice, dstDevice) :
168 + topologyService.getDisjointPaths(topology, srcDevice, dstDevice, weight);
169 +
170 + return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths);
171 + }
172 +
173 + @Override
174 + public Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst,
175 + Map<Link, Object> riskProfile) {
176 + return getSRLGDisjointPaths(src, dst, null, riskProfile);
177 + }
178 +
179 + @Override
180 + public Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst, LinkWeight weight,
181 + Map<Link, Object> riskProfile) {
182 + checkNotNull(src, ELEMENT_ID_NULL);
183 + checkNotNull(dst, ELEMENT_ID_NULL);
184 +
185 + // Get the source and destination edge locations
186 + EdgeLink srcEdge = getEdgeLink(src, true);
187 + EdgeLink dstEdge = getEdgeLink(dst, false);
188 +
189 + // If either edge is null, bail with no paths.
190 + if (srcEdge == null || dstEdge == null) {
191 + return ImmutableSet.of();
192 + }
193 +
194 + DeviceId srcDevice = srcEdge != NOT_HOST ? srcEdge.dst().deviceId() : (DeviceId) src;
195 + DeviceId dstDevice = dstEdge != NOT_HOST ? dstEdge.src().deviceId() : (DeviceId) dst;
196 +
197 + // If the source and destination are on the same edge device, there
198 + // is just one path, so build it and return it.
199 + if (srcDevice.equals(dstDevice)) {
200 + return edgeToEdgePathsDisjoint(srcEdge, dstEdge);
201 + }
202 +
203 + // Otherwise get all paths between the source and destination edge
204 + // devices.
205 + Topology topology = topologyService.currentTopology();
206 + Set<DisjointPath> paths = weight == null ?
207 + topologyService.getSRLGDisjointPaths(topology, srcDevice, dstDevice, riskProfile) :
208 + topologyService.getSRLGDisjointPaths(topology, srcDevice, dstDevice, weight, riskProfile);
209 +
210 + return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths);
211 + }
212 +
131 // Finds the host edge link if the element ID is a host id of an existing 213 // Finds the host edge link if the element ID is a host id of an existing
132 // host. Otherwise, if the host does not exist, it returns null and if 214 // host. Otherwise, if the host does not exist, it returns null and if
133 // the element ID is not a host ID, returns NOT_HOST edge link. 215 // the element ID is not a host ID, returns NOT_HOST edge link.
...@@ -162,6 +244,19 @@ public class PathManager implements PathService { ...@@ -162,6 +244,19 @@ public class PathManager implements PathService {
162 return endToEndPaths; 244 return endToEndPaths;
163 } 245 }
164 246
247 + private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink) {
248 + Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(1);
249 + endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, null));
250 + return endToEndPaths;
251 + }
252 + private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink, Set<DisjointPath> paths) {
253 + Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(paths.size());
254 + for (DisjointPath path : paths) {
255 + endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, path));
256 + }
257 + return endToEndPaths;
258 + }
259 +
165 // Produces a direct edge-to-edge path. 260 // Produces a direct edge-to-edge path.
166 private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path) { 261 private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path) {
167 List<Link> links = Lists.newArrayListWithCapacity(2); 262 List<Link> links = Lists.newArrayListWithCapacity(2);
...@@ -179,6 +274,13 @@ public class PathManager implements PathService { ...@@ -179,6 +274,13 @@ public class PathManager implements PathService {
179 return new DefaultPath(PID, links, 2); 274 return new DefaultPath(PID, links, 2);
180 } 275 }
181 276
277 + // Produces a direct edge-to-edge path.
278 + private DisjointPath edgeToEdgePathD(EdgeLink srcLink, EdgeLink dstLink, DisjointPath path) {
279 + return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, path.primary()),
280 + (DefaultPath) edgeToEdgePath(srcLink, dstLink, path.backup()));
281 + }
282 +
283 +
182 // Special value for edge link to represent that this is really not an 284 // Special value for edge link to represent that this is really not an
183 // edge link since the src or dst are really an infrastructure device. 285 // edge link since the src or dst are really an infrastructure device.
184 private static class NotHost extends DefaultEdgeLink implements EdgeLink { 286 private static class NotHost extends DefaultEdgeLink implements EdgeLink {
......
...@@ -21,6 +21,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -21,6 +21,7 @@ import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
24 +import org.onosproject.net.DisjointPath;
24 import org.onosproject.net.provider.AbstractListenerProviderRegistry; 25 import org.onosproject.net.provider.AbstractListenerProviderRegistry;
25 import org.onosproject.event.Event; 26 import org.onosproject.event.Event;
26 import org.onosproject.net.ConnectPoint; 27 import org.onosproject.net.ConnectPoint;
...@@ -46,6 +47,7 @@ import org.slf4j.Logger; ...@@ -46,6 +47,7 @@ import org.slf4j.Logger;
46 47
47 import java.util.List; 48 import java.util.List;
48 import java.util.Set; 49 import java.util.Set;
50 +import java.util.Map;
49 51
50 import static com.google.common.base.Preconditions.checkNotNull; 52 import static com.google.common.base.Preconditions.checkNotNull;
51 import static org.onosproject.security.AppGuard.checkPermission; 53 import static org.onosproject.security.AppGuard.checkPermission;
...@@ -162,6 +164,42 @@ public class TopologyManager ...@@ -162,6 +164,42 @@ public class TopologyManager
162 } 164 }
163 165
164 @Override 166 @Override
167 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
168 + checkNotNull(topology, TOPOLOGY_NULL);
169 + checkNotNull(src, DEVICE_ID_NULL);
170 + checkNotNull(dst, DEVICE_ID_NULL);
171 + return store.getDisjointPaths(topology, src, dst);
172 + }
173 +
174 + @Override
175 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
176 + checkNotNull(topology, TOPOLOGY_NULL);
177 + checkNotNull(src, DEVICE_ID_NULL);
178 + checkNotNull(dst, DEVICE_ID_NULL);
179 + checkNotNull(weight, "Link weight cannot be null");
180 + return store.getDisjointPaths(topology, src, dst, weight);
181 + }
182 +
183 + @Override
184 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
185 + Map<Link, Object> riskProfile) {
186 + checkNotNull(topology, TOPOLOGY_NULL);
187 + checkNotNull(src, DEVICE_ID_NULL);
188 + checkNotNull(dst, DEVICE_ID_NULL);
189 + return store.getSRLGDisjointPaths(topology, src, dst, riskProfile);
190 + }
191 +
192 + @Override
193 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight,
194 + Map<Link, Object> riskProfile) {
195 + checkNotNull(topology, TOPOLOGY_NULL);
196 + checkNotNull(src, DEVICE_ID_NULL);
197 + checkNotNull(dst, DEVICE_ID_NULL);
198 + checkNotNull(weight, "Link weight cannot be null");
199 + return store.getSRLGDisjointPaths(topology, src, dst, weight, riskProfile);
200 + }
201 +
202 + @Override
165 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { 203 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
166 checkPermission(TOPOLOGY_READ); 204 checkPermission(TOPOLOGY_READ);
167 checkNotNull(topology, TOPOLOGY_NULL); 205 checkNotNull(topology, TOPOLOGY_NULL);
......
...@@ -21,7 +21,9 @@ import org.onosproject.TestApplicationId; ...@@ -21,7 +21,9 @@ import org.onosproject.TestApplicationId;
21 import org.onosproject.core.ApplicationId; 21 import org.onosproject.core.ApplicationId;
22 import org.onosproject.net.ConnectPoint; 22 import org.onosproject.net.ConnectPoint;
23 import org.onosproject.net.DeviceId; 23 import org.onosproject.net.DeviceId;
24 +import org.onosproject.net.DisjointPath;
24 import org.onosproject.net.ElementId; 25 import org.onosproject.net.ElementId;
26 +import org.onosproject.net.Link;
25 import org.onosproject.net.Path; 27 import org.onosproject.net.Path;
26 import org.onosproject.net.device.DeviceServiceAdapter; 28 import org.onosproject.net.device.DeviceServiceAdapter;
27 import org.onosproject.net.flow.TrafficSelector; 29 import org.onosproject.net.flow.TrafficSelector;
...@@ -36,6 +38,7 @@ import org.onosproject.net.topology.PathService; ...@@ -36,6 +38,7 @@ import org.onosproject.net.topology.PathService;
36 38
37 import java.util.HashSet; 39 import java.util.HashSet;
38 import java.util.List; 40 import java.util.List;
41 +import java.util.Map;
39 import java.util.Set; 42 import java.util.Set;
40 43
41 import static org.hamcrest.CoreMatchers.instanceOf; 44 import static org.hamcrest.CoreMatchers.instanceOf;
...@@ -91,6 +94,28 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes ...@@ -91,6 +94,28 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
91 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { 94 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
92 return null; 95 return null;
93 } 96 }
97 +
98 + @Override
99 + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) {
100 + return null;
101 + }
102 +
103 + @Override
104 + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) {
105 + return null;
106 + }
107 +
108 + @Override
109 + public Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst,
110 + Map<Link, Object> riskProfile) {
111 + return null;
112 + }
113 +
114 + @Override
115 + public Set<DisjointPath> getSRLGDisjointPaths(ElementId src, ElementId dst, LinkWeight weight,
116 + Map<Link, Object> riskProfile) {
117 + return null;
118 + }
94 } 119 }
95 120
96 /** 121 /**
......
...@@ -19,9 +19,11 @@ import org.junit.After; ...@@ -19,9 +19,11 @@ import org.junit.After;
19 import org.junit.Before; 19 import org.junit.Before;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
22 +import org.onosproject.net.DisjointPath;
22 import org.onosproject.net.ElementId; 23 import org.onosproject.net.ElementId;
23 import org.onosproject.net.Host; 24 import org.onosproject.net.Host;
24 import org.onosproject.net.HostId; 25 import org.onosproject.net.HostId;
26 +import org.onosproject.net.Link;
25 import org.onosproject.net.Path; 27 import org.onosproject.net.Path;
26 import org.onosproject.net.host.HostService; 28 import org.onosproject.net.host.HostService;
27 import org.onosproject.net.host.HostServiceAdapter; 29 import org.onosproject.net.host.HostServiceAdapter;
...@@ -149,6 +151,28 @@ public class PathManagerTest { ...@@ -149,6 +151,28 @@ public class PathManagerTest {
149 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) { 151 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
150 return paths; 152 return paths;
151 } 153 }
154 +
155 + @Override
156 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
157 + return null;
158 + }
159 +
160 + @Override
161 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
162 + return null;
163 + }
164 +
165 + @Override
166 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
167 + Map<Link, Object> riskProfile) {
168 + return null;
169 + }
170 +
171 + @Override
172 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight,
173 + Map<Link, Object> riskProfile) {
174 + return null;
175 + }
152 } 176 }
153 177
154 // Fake entity to give out hosts. 178 // Fake entity to give out hosts.
......
...@@ -21,6 +21,7 @@ import static org.onosproject.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED; ...@@ -21,6 +21,7 @@ import static org.onosproject.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED;
21 import static org.slf4j.LoggerFactory.getLogger; 21 import static org.slf4j.LoggerFactory.getLogger;
22 22
23 import java.util.Collections; 23 import java.util.Collections;
24 +import java.util.Map;
24 import java.util.List; 25 import java.util.List;
25 import java.util.Set; 26 import java.util.Set;
26 import java.util.stream.Collectors; 27 import java.util.stream.Collectors;
...@@ -40,6 +41,7 @@ import org.onosproject.net.Device; ...@@ -40,6 +41,7 @@ import org.onosproject.net.Device;
40 import org.onosproject.net.DeviceId; 41 import org.onosproject.net.DeviceId;
41 import org.onosproject.net.Link; 42 import org.onosproject.net.Link;
42 import org.onosproject.net.Path; 43 import org.onosproject.net.Path;
44 +import org.onosproject.net.DisjointPath;
43 import org.onosproject.net.provider.ProviderId; 45 import org.onosproject.net.provider.ProviderId;
44 import org.onosproject.net.topology.ClusterId; 46 import org.onosproject.net.topology.ClusterId;
45 import org.onosproject.net.topology.DefaultGraphDescription; 47 import org.onosproject.net.topology.DefaultGraphDescription;
...@@ -74,7 +76,6 @@ public class DistributedTopologyStore ...@@ -74,7 +76,6 @@ public class DistributedTopologyStore
74 implements TopologyStore { 76 implements TopologyStore {
75 77
76 private final Logger log = getLogger(getClass()); 78 private final Logger log = getLogger(getClass());
77 -
78 private volatile DefaultTopology current = 79 private volatile DefaultTopology current =
79 new DefaultTopology(ProviderId.NONE, 80 new DefaultTopology(ProviderId.NONE,
80 new DefaultGraphDescription(0L, System.currentTimeMillis(), 81 new DefaultGraphDescription(0L, System.currentTimeMillis(),
...@@ -167,6 +168,29 @@ public class DistributedTopologyStore ...@@ -167,6 +168,29 @@ public class DistributedTopologyStore
167 } 168 }
168 169
169 @Override 170 @Override
171 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst) {
172 + return defaultTopology(topology).getDisjointPaths(src, dst);
173 + }
174 +
175 + @Override
176 + public Set<DisjointPath> getDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
177 + LinkWeight weight) {
178 + return defaultTopology(topology).getDisjointPaths(src, dst, weight);
179 + }
180 +
181 + @Override
182 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
183 + Map<Link, Object> riskProfile) {
184 + return defaultTopology(topology).getSRLGDisjointPaths(src, dst, riskProfile);
185 + }
186 +
187 + @Override
188 + public Set<DisjointPath> getSRLGDisjointPaths(Topology topology, DeviceId src, DeviceId dst,
189 + LinkWeight weight, Map<Link, Object> riskProfile) {
190 + return defaultTopology(topology).getSRLGDisjointPaths(src, dst, weight, riskProfile);
191 + }
192 +
193 + @Override
170 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { 194 public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
171 return defaultTopology(topology).isInfrastructure(connectPoint); 195 return defaultTopology(topology).isInfrastructure(connectPoint);
172 } 196 }
......
...@@ -82,4 +82,30 @@ public class PathsWebResource extends AbstractWebResource { ...@@ -82,4 +82,30 @@ public class PathsWebResource extends AbstractWebResource {
82 return ok(root).build(); 82 return ok(root).build();
83 } 83 }
84 84
85 + @GET
86 + @Produces(MediaType.APPLICATION_JSON)
87 + @Path("{src}/{dst}/disjoint")
88 +
89 + public Response getDisjointPath(@PathParam("src") String src,
90 + @PathParam("dst") String dst) {
91 + PathService pathService = get(PathService.class);
92 +
93 + ElementId srcElement = isHostId(src);
94 + ElementId dstElement = isHostId(dst);
95 +
96 + if (srcElement == null) {
97 + // Doesn't look like a host, assume it is a device
98 + srcElement = DeviceId.deviceId(src);
99 + }
100 +
101 + if (dstElement == null) {
102 + // Doesn't look like a host, assume it is a device
103 + dstElement = DeviceId.deviceId(dst);
104 + }
105 + Set<org.onosproject.net.DisjointPath> paths =
106 + pathService.getDisjointPaths(srcElement, dstElement);
107 + ObjectNode root =
108 + encodeArray(org.onosproject.net.DisjointPath.class, "paths", paths);
109 + return ok(root).build();
110 + }
85 } 111 }
......