Modified intent compilers to only chose paths that are appropriate to the type of intent, i.e. packet or optical.
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java
index 1fae0f9..3683e8e 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java
@@ -15,19 +15,12 @@
*/
package org.onlab.onos.net.intent.impl;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.collect.ImmutableList;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onlab.onos.core.CoreService;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
@@ -36,41 +29,26 @@
import org.onlab.onos.net.intent.IntentExtensionService;
import org.onlab.onos.net.intent.OpticalConnectivityIntent;
import org.onlab.onos.net.intent.OpticalPathIntent;
-import org.onlab.onos.net.provider.ProviderId;
-import org.onlab.onos.net.resource.LinkResourceService;
import org.onlab.onos.net.topology.LinkWeight;
-import org.onlab.onos.net.topology.PathService;
import org.onlab.onos.net.topology.Topology;
import org.onlab.onos.net.topology.TopologyEdge;
import org.onlab.onos.net.topology.TopologyService;
-import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Set;
/**
- * Optical compiler for OpticalConnectivityIntent.
- * It firstly computes K-shortest paths in the optical-layer, then choose the optimal one to assign a wavelength.
- * Finally, it generates one or more opticalPathintent(s) with opticalMatchs and opticalActions.
+ * An intent compiler for {@link org.onlab.onos.net.intent.OpticalConnectivityIntent}.
*/
@Component(immediate = true)
public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> {
- private final Logger log = getLogger(getClass());
- private static final ProviderId PID = new ProviderId("core", "org.onlab.onos.core", true);
-
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected IntentExtensionService intentManager;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PathService pathService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkResourceService resourceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
@Activate
public void activate() {
intentManager.registerCompiler(OpticalConnectivityIntent.class, this);
@@ -84,31 +62,12 @@
@Override
public List<Intent> compile(OpticalConnectivityIntent intent) {
// TODO: compute multiple paths using the K-shortest path algorithm
- List<Intent> retList = new ArrayList<>();
- log.info("The system is comipling the OpticalConnectivityIntent:" + intent.toString());
Path path = calculateOpticalPath(intent.getSrcConnectPoint(), intent.getDst());
- if (path == null) {
- return retList;
- } else {
- log.info("the computed lightpath is : {}.", path.toString());
- }
-
- List<Link> links = new ArrayList<>();
- // links.add(DefaultEdgeLink.createEdgeLink(intent.getSrcConnectPoint(), true));
- links.addAll(path.links());
- //links.add(DefaultEdgeLink.createEdgeLink(intent.getDst(), false));
-
- // create a new opticalPathIntent
Intent newIntent = new OpticalPathIntent(intent.appId(),
- intent.getSrcConnectPoint(),
- intent.getDst(),
- path);
-
- log.info("a new OpticalPathIntent was created: " + newIntent.toString());
-
- retList.add(newIntent);
-
- return retList;
+ intent.getSrcConnectPoint(),
+ intent.getDst(),
+ path);
+ return ImmutableList.of(newIntent);
}
private Path calculateOpticalPath(ConnectPoint start, ConnectPoint end) {
@@ -117,36 +76,18 @@
LinkWeight weight = new LinkWeight() {
@Override
public double weight(TopologyEdge edge) {
- Link.Type lt = edge.link().type();
- if (lt == Link.Type.OPTICAL) {
- return 1.0;
- } else {
- return 1000.0;
- }
+ return edge.link().type() == Link.Type.OPTICAL ? +1 : -1;
}
};
- Set<Path> paths = topologyService.getPaths(topology,
- start.deviceId(),
- end.deviceId(),
- weight);
-
- ArrayList<Path> localPaths = new ArrayList<>();
- Iterator<Path> itr = paths.iterator();
- while (itr.hasNext()) {
- Path path = itr.next();
- if (path.cost() >= 1000) {
- continue;
- }
- localPaths.add(path);
- }
-
- if (localPaths.isEmpty()) {
+ Set<Path> paths = topologyService.getPaths(topology, start.deviceId(),
+ end.deviceId(), weight);
+ if (paths.isEmpty()) {
throw new PathNotFoundException("No fiber path from " + start + " to " + end);
- } else {
- return localPaths.iterator().next();
}
+ // TODO: let's be more intelligent about this eventually
+ return paths.iterator().next();
}
}