aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl')
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java7
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java31
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java12
3 files changed, 33 insertions, 17 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
index ebf681a2..ff711a02 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
@@ -34,6 +34,7 @@ import org.onosproject.net.HostId;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.NetworkResource;
+import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
@@ -302,11 +303,11 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
private class InternalResourceListener implements ResourceListener {
@Override
public void event(ResourceEvent event) {
- Optional<Class<?>> linkEvent = event.subject().components().stream()
+ Optional<Class<?>> deviceEvent = event.subject().components().stream()
.map(Object::getClass)
- .filter(x -> x == LinkKey.class)
+ .filter(x -> x == PortNumber.class)
.findFirst();
- if (linkEvent.isPresent()) {
+ if (deviceEvent.isPresent()) {
executorService.execute(() -> {
if (delegate == null) {
return;
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
index 718c7bbf..5549918c 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.intent.impl.compiler;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
@@ -59,9 +60,9 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.LinkKey.linkKey;
@@ -120,11 +121,16 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
return Collections.emptyMap();
}
- List<ResourcePath> resources = labels.entrySet().stream()
- .map(x -> ResourcePath.discrete(linkKey(x.getKey().src(), x.getKey().src()), x.getValue()))
- .collect(Collectors.toList());
+ // for short term solution: same label is used for both directions
+ // TODO: introduce the concept of Tx and Rx resources of a port
+ Set<ResourcePath> resources = labels.entrySet().stream()
+ .flatMap(x -> Stream.of(
+ ResourcePath.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
+ ResourcePath.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
+ ))
+ .collect(Collectors.toSet());
List<org.onosproject.net.newresource.ResourceAllocation> allocations =
- resourceService.allocate(intent.id(), resources);
+ resourceService.allocate(intent.id(), ImmutableList.copyOf(resources));
if (allocations.isEmpty()) {
Collections.emptyMap();
}
@@ -135,20 +141,23 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
private Map<LinkKey, MplsLabel> findMplsLabels(Set<LinkKey> links) {
Map<LinkKey, MplsLabel> labels = new HashMap<>();
for (LinkKey link : links) {
- Optional<MplsLabel> label = findMplsLabel(link);
- if (label.isPresent()) {
- labels.put(link, label.get());
+ Set<MplsLabel> forward = findMplsLabel(link.src());
+ Set<MplsLabel> backward = findMplsLabel(link.dst());
+ Set<MplsLabel> common = Sets.intersection(forward, backward);
+ if (common.isEmpty()) {
+ continue;
}
+ labels.put(link, common.iterator().next());
}
return labels;
}
- private Optional<MplsLabel> findMplsLabel(LinkKey link) {
- return resourceService.getAvailableResources(ResourcePath.discrete(link)).stream()
+ private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
+ return resourceService.getAvailableResources(ResourcePath.discrete(cp.deviceId(), cp.port())).stream()
.filter(x -> x.last() instanceof MplsLabel)
.map(x -> (MplsLabel) x.last())
- .findFirst();
+ .collect(Collectors.toSet());
}
private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) {
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index 2941ddba..e017ac58 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -57,9 +57,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.onosproject.net.LinkKey.linkKey;
/**
* An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}.
@@ -182,7 +182,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
IndexedLambda minLambda = findFirstLambda(lambdas);
List<ResourcePath> lambdaResources = path.links().stream()
- .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst())))
+ .flatMap(x -> Stream.of(
+ ResourcePath.discrete(x.src().deviceId(), x.src().port()),
+ ResourcePath.discrete(x.dst().deviceId(), x.dst().port())
+ ))
.map(x -> x.child(minLambda))
.collect(Collectors.toList());
@@ -197,7 +200,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) {
return links.stream()
- .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst())))
+ .flatMap(x -> Stream.of(
+ ResourcePath.discrete(x.src().deviceId(), x.src().port()),
+ ResourcePath.discrete(x.dst().deviceId(), x.dst().port())
+ ))
.map(resourceService::getAvailableResources)
.map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda))
.map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last()))