[ONOS-4595] Harmonize the sb of the Intent Framework
Changes:
- Moves PointToPointIntent to LinkCollectionIntent;
- Moves PointToPointIntent to the new FilteredConnectPoint API;
- Updates unit tests;
Change-Id: Iade5090b9289c5b2d9f4ee41aa0d2d01b5e3699c
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index ee5f4e2..02b8865 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.intent.impl.compiler;
+import com.google.common.collect.ImmutableSet;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -52,6 +53,7 @@
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentId;
+import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.ProtectionConstraint;
@@ -66,6 +68,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -123,12 +126,12 @@
ConnectPoint egressPoint = intent.egressPoint();
if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- return createZeroHopIntent(ingressPoint, egressPoint, intent);
+ return createZeroHopLinkCollectionIntent(intent);
}
// proceed with no protected paths
if (!ProtectionConstraint.requireProtectedPath(intent)) {
- return createUnprotectedIntent(ingressPoint, egressPoint, intent);
+ return createUnprotectedLinkCollectionIntent(intent);
}
try {
@@ -149,6 +152,11 @@
intent, PathIntent.ProtectionType.PRIMARY));
}
+ private List<Intent> createZeroHopLinkCollectionIntent(PointToPointIntent intent) {
+ return asList(createLinkCollectionIntent(ImmutableSet.of(), DEFAULT_COST,
+ intent));
+ }
+
private List<Intent> createUnprotectedIntent(ConnectPoint ingressPoint,
ConnectPoint egressPoint,
PointToPointIntent intent) {
@@ -165,6 +173,15 @@
PathIntent.ProtectionType.PRIMARY));
}
+ private List<Intent> createUnprotectedLinkCollectionIntent(PointToPointIntent intent) {
+ Path path = getPath(intent, intent.filteredIngressPoint().connectPoint().deviceId(),
+ intent.filteredEgressPoint().connectPoint().deviceId());
+
+ return asList(createLinkCollectionIntent(ImmutableSet.copyOf(path.links()),
+ path.cost(),
+ intent));
+ }
+
//FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint,
ConnectPoint egressPoint,
@@ -276,7 +293,6 @@
links.add(createEdgeLink(ingressPoint, true));
links.addAll(onlyPath.links());
links.add(createEdgeLink(egressPoint, false));
-
return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.cost(),
onlyPath.annotations()),
intent, PathIntent.ProtectionType.PRIMARY));
@@ -305,12 +321,45 @@
.build();
}
+
+ /**
+ * Creates a link collection intent from the specified path and original
+ * point to point intent.
+ *
+ * @param links the links of the packets
+ * @param cost the cost associated to the links
+ * @param intent the point to point intent we are compiling
+ * @return the link collection intent
+ */
+ private Intent createLinkCollectionIntent(Set<Link> links,
+ double cost,
+ PointToPointIntent intent) {
+
+ return LinkCollectionIntent.builder()
+ .key(intent.key())
+ .appId(intent.appId())
+ .selector(intent.selector())
+ .treatment(intent.treatment())
+ .links(ImmutableSet.copyOf(links))
+ .filteredIngressPoints(ImmutableSet.of(
+ intent.filteredIngressPoint()
+ ))
+ .filteredEgressPoints(ImmutableSet.of(
+ intent.filteredEgressPoint()
+ ))
+ .applyTreatmentOnEgress(true)
+ .constraints(intent.constraints())
+ .priority(intent.priority())
+ .cost(cost)
+ .build();
+ }
+
/**
* Gets primary port number through failover group associated
* with this intent.
*/
private PortNumber getPrimaryPort(PointToPointIntent intent) {
- Group group = groupService.getGroup(intent.ingressPoint().deviceId(),
+ Group group = groupService.getGroup(intent.filteredIngressPoint().connectPoint().deviceId(),
makeGroupKey(intent.id()));
PortNumber primaryPort = null;
if (group != null) {
@@ -323,7 +372,7 @@
Instructions.OutputInstruction outInstruction =
(Instructions.OutputInstruction) individualInstruction;
PortNumber tempPortNum = outInstruction.port();
- Port port = deviceService.getPort(intent.ingressPoint().deviceId(),
+ Port port = deviceService.getPort(intent.filteredIngressPoint().connectPoint().deviceId(),
tempPortNum);
if (port != null && port.isEnabled()) {
primaryPort = tempPortNum;
@@ -585,7 +634,7 @@
}
}
// remove buckets whose watchports are disabled if the failover group exists
- Group group = groupService.getGroup(pointIntent.ingressPoint().deviceId(),
+ Group group = groupService.getGroup(pointIntent.filteredIngressPoint().connectPoint().deviceId(),
makeGroupKey(pointIntent.id()));
if (group != null) {
updateFailoverGroup(pointIntent);
@@ -595,7 +644,7 @@
// Removes buckets whose treatments rely on disabled ports from the
// failover group.
private void updateFailoverGroup(PointToPointIntent pointIntent) {
- DeviceId deviceId = pointIntent.ingressPoint().deviceId();
+ DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
GroupKey groupKey = makeGroupKey(pointIntent.id());
Group group = waitForGroup(deviceId, groupKey);
Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();