Filter paths not satisfying the specified constraints
Change-Id: I683ba7cdfa3b792dda51a0bb45d7b000666c8c54
Showing
1 changed file
with
13 additions
and
3 deletions
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.net.intent.impl; | 16 | package org.onlab.onos.net.intent.impl; |
17 | 17 | ||
18 | +import com.google.common.base.Predicate; | ||
19 | +import com.google.common.collect.FluentIterable; | ||
18 | import com.google.common.collect.ImmutableList; | 20 | import com.google.common.collect.ImmutableList; |
19 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
... | @@ -94,11 +96,19 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> | ... | @@ -94,11 +96,19 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> |
94 | protected Path getPath(ConnectivityIntent intent, | 96 | protected Path getPath(ConnectivityIntent intent, |
95 | ElementId one, ElementId two) { | 97 | ElementId one, ElementId two) { |
96 | Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints())); | 98 | Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints())); |
97 | - if (paths.isEmpty()) { | 99 | + final List<Constraint> constraints = intent.constraints(); |
98 | - throw new PathNotFoundException("No packet path from " + one + " to " + two); | 100 | + ImmutableList<Path> filtered = FluentIterable.from(paths) |
101 | + .filter(new Predicate<Path>() { | ||
102 | + @Override | ||
103 | + public boolean apply(Path path) { | ||
104 | + return checkPath(path, constraints); | ||
105 | + } | ||
106 | + }).toList(); | ||
107 | + if (filtered.isEmpty()) { | ||
108 | + throw new PathNotFoundException("No packet path form " + one + " to " + two); | ||
99 | } | 109 | } |
100 | // TODO: let's be more intelligent about this eventually | 110 | // TODO: let's be more intelligent about this eventually |
101 | - return paths.iterator().next(); | 111 | + return filtered.iterator().next(); |
102 | } | 112 | } |
103 | 113 | ||
104 | /** | 114 | /** | ... | ... |
-
Please register or login to post a comment