Implement builders for optical intents
Change-Id: Ide728a943eb0ec3d3ba995f63c016e7d52bff65c
diff --git a/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java b/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
index d79d191..d150f11 100644
--- a/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
+++ b/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
@@ -286,12 +286,16 @@
break;
}
- Intent opticalIntent = new OpticalConnectivityIntent(appId,
- srcWdmPoint,
- dstWdmPoint);
- Intent opticalIntent2 = new OpticalConnectivityIntent(appId,
- dstWdmPoint,
- srcWdmPoint);
+ Intent opticalIntent = OpticalConnectivityIntent.builder()
+ .appId(appId)
+ .src(srcWdmPoint)
+ .dst(dstWdmPoint)
+ .build();
+ Intent opticalIntent2 = OpticalConnectivityIntent.builder()
+ .appId(appId)
+ .src(dstWdmPoint)
+ .dst(srcWdmPoint)
+ .build();
log.info("Creating optical intent from {} to {}", srcWdmPoint, dstWdmPoint);
log.info("Creating optical intent from {} to {}", dstWdmPoint, srcWdmPoint);
connectionList.add(opticalIntent);
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
index c743575..411ade0 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
@@ -56,7 +56,12 @@
PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
- Intent intent = new OpticalConnectivityIntent(appId(), key(), ingress, egress);
+ Intent intent = OpticalConnectivityIntent.builder()
+ .appId(appId())
+ .key(key())
+ .src(ingress)
+ .dst(egress)
+ .build();
service.submit(intent);
print("Optical intent submitted:\n%s", intent.toString());
}
diff --git a/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java b/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
index 091ebc5..a1dcc1c 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
@@ -15,10 +15,12 @@
*/
package org.onosproject.net.intent;
+import java.util.Collections;
+
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
-import java.util.Collections;
+import static com.google.common.base.Preconditions.checkNotNull;
/**
* An optical layer intent for connectivity from one transponder port to another
@@ -33,32 +35,90 @@
* connection points.
*
* @param appId application identification
- * @param src the source transponder port
- * @param dst the destination transponder port
- */
- public OpticalConnectivityIntent(ApplicationId appId,
- ConnectPoint src, ConnectPoint dst) {
-
- this(appId, null, src, dst);
- }
-
- /**
- * Creates an optical connectivity intent between the specified
- * connection points.
- *
- * @param appId application identification
* @param key intent key
* @param src the source transponder port
* @param dst the destination transponder port
*/
- public OpticalConnectivityIntent(ApplicationId appId,
+ protected OpticalConnectivityIntent(ApplicationId appId,
Key key,
- ConnectPoint src, ConnectPoint dst) {
- super(appId, key, Collections.emptyList(), DEFAULT_INTENT_PRIORITY);
- this.src = src;
- this.dst = dst;
+ ConnectPoint src,
+ ConnectPoint dst,
+ int priority) {
+ super(appId, key, Collections.emptyList(), priority);
+ this.src = checkNotNull(src);
+ this.dst = checkNotNull(dst);
}
+ /**
+ * Returns a new optical connectivity intent builder.
+ *
+ * @return host to host intent builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+
+ /**
+ * Builder for optical connectivity intents.
+ */
+ public static class Builder extends Intent.Builder {
+ private ConnectPoint src;
+ private ConnectPoint dst;
+
+ @Override
+ public Builder appId(ApplicationId appId) {
+ return (Builder) super.appId(appId);
+ }
+
+ @Override
+ public Builder key(Key key) {
+ return (Builder) super.key(key);
+ }
+
+ @Override
+ public Builder priority(int priority) {
+ return (Builder) super.priority(priority);
+ }
+
+ /**
+ * Sets the source for the intent that will be built.
+ *
+ * @param src source to use for built intent
+ * @return this builder
+ */
+ public Builder src(ConnectPoint src) {
+ this.src = src;
+ return this;
+ }
+
+ /**
+ * Sets the destination for the intent that will be built.
+ *
+ * @param dst dest to use for built intent
+ * @return this builder
+ */
+ public Builder dst(ConnectPoint dst) {
+ this.dst = dst;
+ return this;
+ }
+
+ /**
+ * Builds an optical connectivity intent from the accumulated parameters.
+ *
+ * @return point to point intent
+ */
+ public OpticalConnectivityIntent build() {
+
+ return new OpticalConnectivityIntent(
+ appId,
+ key,
+ src,
+ dst,
+ priority
+ );
+ }
+ }
/**
* Constructor for serializer.
diff --git a/core/api/src/main/java/org/onosproject/net/intent/OpticalPathIntent.java b/core/api/src/main/java/org/onosproject/net/intent/OpticalPathIntent.java
index 4843877..754d433 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/OpticalPathIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/OpticalPathIntent.java
@@ -15,14 +15,15 @@
*/
package org.onosproject.net.intent;
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
+
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
-import java.util.Collection;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableSet;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -33,12 +34,16 @@
private final Path path;
- public OpticalPathIntent(ApplicationId appId,
- ConnectPoint src,
- ConnectPoint dst,
- Path path) {
- super(appId, null, ImmutableSet.copyOf(path.links()),
- Intent.DEFAULT_INTENT_PRIORITY);
+ private OpticalPathIntent(ApplicationId appId,
+ Key key,
+ ConnectPoint src,
+ ConnectPoint dst,
+ Path path,
+ int priority) {
+ super(appId,
+ key,
+ ImmutableSet.copyOf(path.links()),
+ priority);
this.src = checkNotNull(src);
this.dst = checkNotNull(dst);
this.path = checkNotNull(path);
@@ -50,6 +55,92 @@
this.path = null;
}
+ /**
+ * Returns a new optical connectivity intent builder.
+ *
+ * @return host to host intent builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+
+ /**
+ * Builder for optical path intents.
+ */
+ public static class Builder extends Intent.Builder {
+ private ConnectPoint src;
+ private ConnectPoint dst;
+ private Path path;
+ Key key;
+
+ @Override
+ public Builder appId(ApplicationId appId) {
+ return (Builder) super.appId(appId);
+ }
+
+ @Override
+ public Builder key(Key key) {
+ return (Builder) super.key(key);
+ }
+
+ @Override
+ public Builder priority(int priority) {
+ return (Builder) super.priority(priority);
+ }
+
+ /**
+ * Sets the source for the intent that will be built.
+ *
+ * @param src source to use for built intent
+ * @return this builder
+ */
+ public Builder src(ConnectPoint src) {
+ this.src = src;
+ return this;
+ }
+
+ /**
+ * Sets the destination for the intent that will be built.
+ *
+ * @param dst dest to use for built intent
+ * @return this builder
+ */
+ public Builder dst(ConnectPoint dst) {
+ this.dst = dst;
+ return this;
+ }
+
+ /**
+ * Sets the path for the intent that will be built.
+ *
+ * @param path path to use for built intent
+ * @return this builder
+ */
+ public Builder path(Path path) {
+ this.path = path;
+ return this;
+ }
+
+ /**
+ * Builds an optical path intent from the accumulated parameters.
+ *
+ * @return optical path intent
+ */
+ public OpticalPathIntent build() {
+
+ return new OpticalPathIntent(
+ appId,
+ key,
+ src,
+ dst,
+ path,
+ priority
+ );
+ }
+ }
+
+
public ConnectPoint src() {
return src;
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index eeb2244..e4bc823 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -15,7 +15,9 @@
*/
package org.onosproject.net.intent.impl.compiler;
-import com.google.common.collect.ImmutableList;
+import java.util.List;
+import java.util.Set;
+
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -36,8 +38,7 @@
import org.onosproject.net.topology.TopologyEdge;
import org.onosproject.net.topology.TopologyService;
-import java.util.List;
-import java.util.Set;
+import com.google.common.collect.ImmutableList;
/**
* An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}.
@@ -67,10 +68,12 @@
Set<LinkResourceAllocations> resources) {
// TODO: compute multiple paths using the K-shortest path algorithm
Path path = calculateOpticalPath(intent.getSrc(), intent.getDst());
- Intent newIntent = new OpticalPathIntent(intent.appId(),
- intent.getSrc(),
- intent.getDst(),
- path);
+ Intent newIntent = OpticalPathIntent.builder()
+ .appId(intent.appId())
+ .src(intent.getSrc())
+ .dst(intent.getDst())
+ .path(path)
+ .build();
return ImmutableList.of(newIntent);
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
index 198341f..4aad8a5 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
@@ -57,10 +57,11 @@
new IntentInstallerTest.MockIntentManager(OpticalPathIntent.class);
installer.resourceService = new IntentTestsMocks.MockResourceService();
- intent = new OpticalPathIntent(APP_ID,
- d1p1,
- d3p1,
- new DefaultPath(PID, links, hops));
+ intent = OpticalPathIntent.builder().appId(APP_ID)
+ .src(d1p1)
+ .dst(d3p1)
+ .path(new DefaultPath(PID, links, hops))
+ .build();
}
/**