diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java index badad7fefd..f08e513e05 100644 --- a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java +++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java @@ -15,7 +15,19 @@ */ package org.onosproject.sdnip; -import com.google.common.util.concurrent.ThreadFactoryBuilder; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Semaphore; + import org.onlab.packet.Ethernet; import org.onlab.packet.IpAddress; import org.onlab.packet.IpPrefix; @@ -43,19 +55,7 @@ import org.onosproject.routing.config.RoutingConfigurationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Semaphore; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import static com.google.common.base.Preconditions.checkArgument; @@ -340,11 +340,15 @@ public class IntentSynchronizer implements FibListener { int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; Key key = Key.of(prefix.toString(), appId); - return new MultiPointToSinglePointIntent(appId, key, selector.build(), - treatment.build(), - ingressPorts, egressPort, - Collections.emptyList(), - priority); + return MultiPointToSinglePointIntent.builder() + .appId(appId) + .key(key) + .selector(selector.build()) + .treatment(treatment.build()) + .ingressPoints(ingressPorts) + .egressPoint(egressPort) + .priority(priority) + .build(); } @Override diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java index 9f29c1b61e..7625af6ebb 100644 --- a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java +++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java @@ -233,9 +233,13 @@ public class IntentSyncTest extends AbstractIntentTest { ingressPoints.add(SW4_ETH1); MultiPointToSinglePointIntent intent = - new MultiPointToSinglePointIntent(APPID, - selectorBuilder.build(), treatmentBuilder.build(), - ingressPoints, SW1_ETH1); + MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(selectorBuilder.build()) + .treatment(treatmentBuilder.build()) + .ingressPoints(ingressPoints) + .egressPoint(SW1_ETH1) + .build(); // Setup the expected intents intentService.submit(eqExceptId(intent)); @@ -291,9 +295,13 @@ public class IntentSyncTest extends AbstractIntentTest { ingressPoints.add(SW3_ETH1); MultiPointToSinglePointIntent intent = - new MultiPointToSinglePointIntent(APPID, - selectorBuilder.build(), treatmentBuilder.build(), - ingressPoints, SW4_ETH1); + MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(selectorBuilder.build()) + .treatment(treatmentBuilder.build()) + .ingressPoints(ingressPoints) + .egressPoint(SW4_ETH1) + .build(); // Setup the expected intents intentService.submit(eqExceptId(intent)); @@ -357,10 +365,13 @@ public class IntentSyncTest extends AbstractIntentTest { ingressPointsNew.add(SW4_ETH1); MultiPointToSinglePointIntent intentNew = - new MultiPointToSinglePointIntent(APPID, - selectorBuilderNew.build(), - treatmentBuilderNew.build(), - ingressPointsNew, SW2_ETH1); + MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(selectorBuilderNew.build()) + .treatment(treatmentBuilderNew.build()) + .ingressPoints(ingressPointsNew) + .egressPoint(SW2_ETH1) + .build(); // Set up test expectation reset(intentService); @@ -592,9 +603,13 @@ public class IntentSyncTest extends AbstractIntentTest { } } MultiPointToSinglePointIntent intent = - new MultiPointToSinglePointIntent(APPID, - selectorBuilder.build(), treatmentBuilder.build(), - ingressPoints, egressPoint); + MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(selectorBuilder.build()) + .treatment(treatmentBuilder.build()) + .ingressPoints(ingressPoints) + .egressPoint(egressPoint) + .build(); return intent; } diff --git a/cli/src/main/java/org/onosproject/cli/net/AddHostToHostIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddHostToHostIntentCommand.java index a4a3a7cec7..f1554b6658 100644 --- a/cli/src/main/java/org/onosproject/cli/net/AddHostToHostIntentCommand.java +++ b/cli/src/main/java/org/onosproject/cli/net/AddHostToHostIntentCommand.java @@ -15,19 +15,15 @@ */ package org.onosproject.cli.net; +import java.util.List; + import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.onosproject.net.HostId; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.intent.Constraint; import org.onosproject.net.intent.HostToHostIntent; import org.onosproject.net.intent.IntentService; -import java.util.List; - /** * Installs host-to-host connectivity intent. */ @@ -50,14 +46,16 @@ public class AddHostToHostIntentCommand extends ConnectivityIntentCommand { HostId oneId = HostId.hostId(one); HostId twoId = HostId.hostId(two); - TrafficSelector selector = DefaultTrafficSelector.emptySelector(); - TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); List constraints = buildConstraints(); - HostToHostIntent intent = new HostToHostIntent(appId(), key(), - oneId, twoId, - selector, treatment, - constraints, priority()); + HostToHostIntent intent = HostToHostIntent.builder() + .appId(appId()) + .key(key()) + .one(oneId) + .two(twoId) + .constraints(constraints) + .priority(priority()) + .build(); service.submit(intent); print("Host to Host intent submitted:\n%s", intent.toString()); } diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java b/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java index 7de49c954d..ebaf89bdb8 100644 --- a/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java +++ b/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java @@ -75,10 +75,17 @@ public class AddMplsIntent extends ConnectivityIntentCommand { List constraints = buildConstraints(); - MplsIntent intent = new MplsIntent(appId(), selector, treatment, - ingress, ingressLabel, egress, - egressLabel, constraints, - priority()); + MplsIntent intent = MplsIntent.builder() + .appId(appId()) + .selector(selector) + .treatment(treatment) + .ingressPoint(ingress) + .ingressLabel(ingressLabel) + .egressPoint(egress) + .egressLabel(egressLabel) + .constraints(constraints) + .priority(priority()) + .build(); service.submit(intent); } diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java index abc0c4ba95..892f819ecd 100644 --- a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java +++ b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java @@ -72,11 +72,16 @@ public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentC TrafficTreatment treatment = buildTrafficTreatment(); List constraints = buildConstraints(); - Intent intent = new MultiPointToSinglePointIntent(appId(), key(), - selector, treatment, - ingressPoints, egress, - constraints, - priority()); + Intent intent = MultiPointToSinglePointIntent.builder() + .appId(appId()) + .key(key()) + .selector(selector) + .treatment(treatment) + .ingressPoints(ingressPoints) + .egressPoint(egress) + .constraints(constraints) + .priority(priority()) + .build(); service.submit(intent); print("Multipoint to single point intent submitted:\n%s", intent.toString()); } diff --git a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java index b6193fa2f0..83ef66f960 100644 --- a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java +++ b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java @@ -72,15 +72,16 @@ public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentC List constraints = buildConstraints(); SinglePointToMultiPointIntent intent = - new SinglePointToMultiPointIntent( - appId(), - key(), - selector, - treatment, - ingressPoint, - egressPoints, - constraints, - priority()); + SinglePointToMultiPointIntent.builder() + .appId(appId()) + .key(key()) + .selector(selector) + .treatment(treatment) + .ingressPoint(ingressPoint) + .egressPoints(egressPoints) + .constraints(constraints) + .priority(priority()) + .build(); service.submit(intent); print("Single point to multipoint intent submitted:\n%s", intent.toString()); } diff --git a/cli/src/main/java/org/onosproject/cli/net/RandomIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/RandomIntentCommand.java index 5eb592a68f..152e6591af 100644 --- a/cli/src/main/java/org/onosproject/cli/net/RandomIntentCommand.java +++ b/cli/src/main/java/org/onosproject/cli/net/RandomIntentCommand.java @@ -15,25 +15,22 @@ */ package org.onosproject.cli.net; -import com.google.common.collect.Lists; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.onosproject.cli.AbstractShellCommand; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; import org.onosproject.net.Host; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.host.HostService; import org.onosproject.net.intent.HostToHostIntent; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.IntentService; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import com.google.common.collect.Lists; /** * Installs point-to-point connectivity intents. @@ -67,17 +64,16 @@ public class RandomIntentCommand extends AbstractShellCommand { } private Collection generateIntents() { - TrafficSelector selector = DefaultTrafficSelector.emptySelector(); - TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); - List hosts = Lists.newArrayList(hostService.getHosts()); List fullMesh = Lists.newArrayList(); for (int i = 0; i < hosts.size(); i++) { for (int j = i + 1; j < hosts.size(); j++) { - fullMesh.add(new HostToHostIntent(appId(), - hosts.get(i).id(), - hosts.get(j).id(), - selector, treatment)); + fullMesh.add(HostToHostIntent.builder() + .appId(appId()) + .one(hosts.get(i).id()) + .two(hosts.get(j).id()) + .build()); + } } Collections.shuffle(fullMesh); diff --git a/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java b/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java index 9d0a228613..94e3b1a980 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java @@ -76,34 +76,6 @@ public abstract class ConnectivityIntent extends Intent { this.constraints = checkNotNull(constraints); } - /** - * Creates a connectivity intent that matches on the specified selector - * and applies the specified treatment. - *

- * Path will be optimized based on the first constraint if one is given. - *

- * - * @param appId application identifier - * @param resources required network resources (optional) - * @param selector traffic selector - * @param treatment treatment - * @param constraints optional prioritized list of constraints - * @param priority priority to use for flows generated by this intent - * @throws NullPointerException if the selector or treatment is null - */ - - protected ConnectivityIntent(ApplicationId appId, - Collection resources, - TrafficSelector selector, - TrafficTreatment treatment, - List constraints, - int priority) { - super(appId, null, resources, priority); - this.selector = checkNotNull(selector); - this.treatment = checkNotNull(treatment); - this.constraints = checkNotNull(constraints); - } - /** * Constructor for serializer. */ diff --git a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java index 9b00512189..157397a4b3 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java @@ -15,20 +15,16 @@ */ package org.onosproject.net.intent; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableList; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.HostId; -import org.onosproject.net.Link; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; - import java.util.Collections; import java.util.List; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.HostId; +import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.TrafficTreatment; + +import com.google.common.base.MoreObjects; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -40,59 +36,98 @@ public final class HostToHostIntent extends ConnectivityIntent { private final HostId two; /** - * Creates a new host-to-host intent with the supplied host pair and no - * other traffic selection or treatment criteria. + * Returns a new host to host intent builder. * - * @param appId application identifier - * @param one first host - * @param two second host - * @throws NullPointerException if {@code one} or {@code two} is null. + * @return host to host intent builder */ - public HostToHostIntent(ApplicationId appId, HostId one, HostId two) { - this(appId, one, two, - DefaultTrafficSelector.emptySelector(), - DefaultTrafficTreatment.emptyTreatment(), - ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), - DEFAULT_INTENT_PRIORITY); + public static Builder builder() { + return new Builder(); } /** - * Creates a new host-to-host intent with the supplied host pair. - * - * @param appId application identifier - * @param one first host - * @param two second host - * @param selector action - * @param treatment ingress port - * @throws NullPointerException if {@code one} or {@code two} is null. + * Builder of a host to host intent. */ - public HostToHostIntent(ApplicationId appId, HostId one, HostId two, - TrafficSelector selector, - TrafficTreatment treatment) { - this(appId, one, two, selector, treatment, - ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), - DEFAULT_INTENT_PRIORITY); + public static final class Builder extends ConnectivityIntent.Builder { + HostId one; + HostId two; + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the first host of the intent that will be built. + * + * @param one first host + * @return this builder + */ + public Builder one(HostId one) { + this.one = one; + return this; + } + + /** + * Sets the second host of the intent that will be built. + * + * @param two second host + * @return this builder + */ + public Builder two(HostId two) { + this.two = two; + return this; + } + + /** + * Builds a host to host intent from the accumulated parameters. + * + * @return point to point intent + */ + public HostToHostIntent build() { + + return new HostToHostIntent( + appId, + key, + one, + two, + selector, + treatment, + constraints, + priority + ); + } } - /** - * Creates a new host-to-host intent with the supplied host pair. - * - * @param appId application identifier - * @param one first host - * @param two second host - * @param selector action - * @param treatment ingress port - * @param constraints optional prioritized list of path selection constraints - * @param priority priority to use for flows generated by this intent - * @throws NullPointerException if {@code one} or {@code two} is null. - */ - public HostToHostIntent(ApplicationId appId, HostId one, HostId two, - TrafficSelector selector, - TrafficTreatment treatment, - List constraints, - int priority) { - this(appId, null, one, two, selector, treatment, constraints, priority); - } + /** * Creates a new host-to-host intent with the supplied host pair. * @@ -106,7 +141,7 @@ public final class HostToHostIntent extends ConnectivityIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException if {@code one} or {@code two} is null. */ - public HostToHostIntent(ApplicationId appId, Key key, + private HostToHostIntent(ApplicationId appId, Key key, HostId one, HostId two, TrafficSelector selector, TrafficTreatment treatment, @@ -121,14 +156,6 @@ public final class HostToHostIntent extends ConnectivityIntent { } - private static HostId min(HostId one, HostId two) { - return one.hashCode() < two.hashCode() ? one : two; - } - - private static HostId max(HostId one, HostId two) { - return one.hashCode() >= two.hashCode() ? one : two; - } - /** * Returns identifier of the first host. * diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java index 725fac42dc..59378f7ddc 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java @@ -59,17 +59,6 @@ public abstract class Intent { this.priority = DEFAULT_INTENT_PRIORITY; } - /** - * Creates a new intent. - * - * @param appId application identifier - * @param resources required network resources (optional) - */ - protected Intent(ApplicationId appId, - Collection resources) { - this(appId, null, resources, DEFAULT_INTENT_PRIORITY); - } - /** * Creates a new intent. * diff --git a/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java b/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java index 17451cbaaa..8cea253f8a 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java @@ -15,8 +15,8 @@ */ package org.onosproject.net.intent; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableSet; +import java.util.List; +import java.util.Set; import org.onosproject.core.ApplicationId; import org.onosproject.net.ConnectPoint; @@ -24,9 +24,8 @@ import org.onosproject.net.Link; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; /** * Abstraction of a connectivity intent that is implemented by a set of path @@ -39,74 +38,24 @@ public final class LinkCollectionIntent extends ConnectivityIntent { private final Set ingressPoints; private final Set egressPoints; - /** - * Creates a new actionable intent capable of funneling the selected - * traffic along the specified convergent tree and out the given egress - * point. - * - * @param appId application identifier - * @param selector traffic match - * @param treatment action - * @param links traversed links - * @param ingressPoint ingress point - * @param egressPoint egress point - * @throws NullPointerException {@code path} is null - */ - public LinkCollectionIntent(ApplicationId appId, - TrafficSelector selector, - TrafficTreatment treatment, - Set links, - ConnectPoint ingressPoint, - ConnectPoint egressPoint) { - this(appId, selector, treatment, links, ingressPoint, egressPoint, - Collections.emptyList(), DEFAULT_INTENT_PRIORITY); - } - /** * Creates a new actionable intent capable of funneling the selected * traffic along the specified convergent tree and out the given egress * point satisfying the specified constraints. * * @param appId application identifier + * @param key key to use for the intent * @param selector traffic match * @param treatment action * @param links traversed links - * @param ingressPoint ingress point - * @param egressPoint egress point + * @param ingressPoints ingress points + * @param egressPoints egress points * @param constraints optional list of constraints * @param priority priority to use for the flows generated by this intent * @throws NullPointerException {@code path} is null */ - public LinkCollectionIntent(ApplicationId appId, - TrafficSelector selector, - TrafficTreatment treatment, - Set links, - ConnectPoint ingressPoint, - ConnectPoint egressPoint, - List constraints, - int priority) { - super(appId, resources(links), selector, treatment, constraints, priority); - this.links = links; - this.ingressPoints = ImmutableSet.of(ingressPoint); - this.egressPoints = ImmutableSet.of(egressPoint); - } - - /** - * Creates a new actionable intent capable of funneling the selected - * traffic along the specified convergent tree and out the given egress - * point. - * - * @param appId application identifier - * @param selector traffic match - * @param treatment action - * @param links traversed links - * @param ingressPoints Set of ingress points - * @param egressPoints Set of egress points - * @param constraints the constraints - * @param priority priority to use for the flows generated by this intent - * @throws NullPointerException {@code path} is null - */ - public LinkCollectionIntent(ApplicationId appId, + private LinkCollectionIntent(ApplicationId appId, + Key key, TrafficSelector selector, TrafficTreatment treatment, Set links, @@ -114,11 +63,10 @@ public final class LinkCollectionIntent extends ConnectivityIntent { Set egressPoints, List constraints, int priority) { - super(appId, resources(links), selector, treatment, constraints, priority); - + super(appId, key, resources(links), selector, treatment, constraints, priority); this.links = links; - this.ingressPoints = ImmutableSet.copyOf(ingressPoints); - this.egressPoints = ImmutableSet.copyOf(egressPoints); + this.ingressPoints = ingressPoints; + this.egressPoints = egressPoints; } /** @@ -131,6 +79,120 @@ public final class LinkCollectionIntent extends ConnectivityIntent { this.egressPoints = null; } + /** + * Returns a new link collection intent builder. The application id, + * ingress point and egress points are required fields. If they are + * not set by calls to the appropriate methods, an exception will + * be thrown. + * + * @return single point to multi point builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder of a single point to multi point intent. + */ + public static final class Builder extends ConnectivityIntent.Builder { + Set links; + Set ingressPoints; + Set egressPoints; + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the ingress point of the single point to multi point intent + * that will be built. + * + * @param ingressPoints ingress connect points + * @return this builder + */ + public Builder ingressPoints(Set ingressPoints) { + this.ingressPoints = ImmutableSet.copyOf(ingressPoints); + return this; + } + + /** + * Sets the egress points of the single point to multi point intent + * that will be built. + * + * @param egressPoints egress connect points + * @return this builder + */ + public Builder egressPoints(Set egressPoints) { + this.egressPoints = ImmutableSet.copyOf(egressPoints); + return this; + } + + /** + * Sets the links of the link collection intent + * that will be built. + * + * @param links links for the intent + * @return this builder + */ + public Builder links(Set links) { + this.links = ImmutableSet.copyOf(links); + return this; + } + + + /** + * Builds a single point to multi point intent from the + * accumulated parameters. + * + * @return point to point intent + */ + public LinkCollectionIntent build() { + + return new LinkCollectionIntent( + appId, + key, + selector, + treatment, + links, + ingressPoints, + egressPoints, + constraints, + priority + ); + } + } + + /** * Returns the set of links that represent the network connections needed * by this intent. diff --git a/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java index 524b231ff2..1625f58be1 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java @@ -1,8 +1,5 @@ package org.onosproject.net.intent; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - import java.util.Collections; import java.util.List; import java.util.Optional; @@ -10,13 +7,13 @@ import java.util.Optional; import org.onlab.packet.MplsLabel; import org.onosproject.core.ApplicationId; import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Link; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableList; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; /** @@ -29,30 +26,6 @@ public final class MplsIntent extends ConnectivityIntent { private final ConnectPoint egressPoint; private final Optional egressLabel; - /** - * Creates a new MPLS intent with the supplied ingress/egress - * ports and labels and with built-in link type constraint to avoid optical links. - * - * @param appId application identifier - * @param selector traffic selector - * @param treatment treatment - * @param ingressPoint ingress port - * @param ingressLabel ingress MPLS label - * @param egressPoint egress port - * @param egressLabel egress MPLS label - * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. - */ - public MplsIntent(ApplicationId appId, TrafficSelector selector, - TrafficTreatment treatment, - ConnectPoint ingressPoint, - Optional ingressLabel, - ConnectPoint egressPoint, - Optional egressLabel) { - this(appId, selector, treatment, ingressPoint, ingressLabel, egressPoint, egressLabel, - ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), - DEFAULT_INTENT_PRIORITY); - } - /** * Creates a new point-to-point intent with the supplied ingress/egress * ports, labels and constraints. @@ -68,31 +41,153 @@ public final class MplsIntent extends ConnectivityIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. */ - public MplsIntent(ApplicationId appId, TrafficSelector selector, - TrafficTreatment treatment, - ConnectPoint ingressPoint, - Optional ingressLabel, - ConnectPoint egressPoint, - Optional egressLabel, - List constraints, - int priority) { + private MplsIntent(ApplicationId appId, + Key key, + TrafficSelector selector, + TrafficTreatment treatment, + ConnectPoint ingressPoint, + Optional ingressLabel, + ConnectPoint egressPoint, + Optional egressLabel, + List constraints, + int priority) { - super(appId, Collections.emptyList(), selector, treatment, constraints, + super(appId, key, Collections.emptyList(), selector, treatment, constraints, priority); - checkNotNull(ingressPoint); - checkNotNull(egressPoint); - checkArgument(!ingressPoint.equals(egressPoint), - "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); - checkNotNull(ingressLabel); - checkNotNull(egressLabel); - this.ingressPoint = ingressPoint; - this.ingressLabel = ingressLabel; - this.egressPoint = egressPoint; - this.egressLabel = egressLabel; + this.ingressPoint = checkNotNull(ingressPoint); + this.ingressLabel = checkNotNull(ingressLabel); + this.egressPoint = checkNotNull(egressPoint); + this.egressLabel = checkNotNull(egressLabel); + checkArgument(!ingressPoint.equals(egressPoint), + "ingress and egress should be different (ingress: %s, egress: %s)", + ingressPoint, egressPoint); } + /** + * Returns a new MPLS intent builder. The application id, + * ingress point, egress point, ingress label and egress label are + * required fields. If they are not set by calls to the appropriate + * methods, an exception will be thrown. + * + * @return point to point builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder of an MPLS intent. + */ + public static final class Builder extends ConnectivityIntent.Builder { + ConnectPoint ingressPoint; + ConnectPoint egressPoint; + Optional ingressLabel; + Optional egressLabel; + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the ingress point of the point to point intent that will be built. + * + * @param ingressPoint ingress connect point + * @return this builder + */ + public Builder ingressPoint(ConnectPoint ingressPoint) { + this.ingressPoint = ingressPoint; + return this; + } + + /** + * Sets the egress point of the point to point intent that will be built. + * + * @param egressPoint egress connect point + * @return this builder + */ + public Builder egressPoint(ConnectPoint egressPoint) { + this.egressPoint = egressPoint; + return this; + } + + /** + * Sets the ingress label of the intent that will be built. + * + * @param ingressLabel ingress label + * @return this builder + */ + public Builder ingressLabel(Optional ingressLabel) { + this.ingressLabel = ingressLabel; + return this; + } + + /** + * Sets the ingress label of the intent that will be built. + * + * @param egressLabel ingress label + * @return this builder + */ + public Builder egressLabel(Optional egressLabel) { + this.egressLabel = egressLabel; + return this; + } + + /** + * Builds a point to point intent from the accumulated parameters. + * + * @return point to point intent + */ + public MplsIntent build() { + + return new MplsIntent( + appId, + key, + selector, + treatment, + ingressPoint, + ingressLabel, + egressPoint, + egressLabel, + constraints, + priority + ); + } + } + + + /** * Constructor for serializer. */ @@ -147,6 +242,7 @@ public final class MplsIntent extends ConnectivityIntent { return MoreObjects.toStringHelper(getClass()) .add("id", id()) .add("appId", appId()) + .add("key", key()) .add("priority", priority()) .add("selector", selector()) .add("treatment", treatment()) diff --git a/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java index 83e9218b52..1ea58295ff 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java @@ -1,18 +1,16 @@ package org.onosproject.net.intent; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Collections; import java.util.List; import java.util.Optional; - import org.onlab.packet.MplsLabel; import org.onosproject.core.ApplicationId; import org.onosproject.net.Path; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Abstraction of explicit MPLS label-switched path. @@ -23,26 +21,6 @@ public final class MplsPathIntent extends PathIntent { private final Optional ingressLabel; private final Optional egressLabel; - /** - * Creates a new point-to-point intent with the supplied ingress/egress - * ports and using the specified explicit path. - * - * @param appId application identifier - * @param selector traffic selector - * @param treatment treatment - * @param path traversed links - * @param ingressLabel MPLS egress label - * @param egressLabel MPLS ingress label - * @throws NullPointerException {@code path} is null - */ - public MplsPathIntent(ApplicationId appId, TrafficSelector selector, - TrafficTreatment treatment, Path path, Optional ingressLabel, - Optional egressLabel) { - this(appId, selector, treatment, path, ingressLabel, egressLabel, - Collections.emptyList(), DEFAULT_INTENT_PRIORITY); - - } - /** * Creates a new point-to-point intent with the supplied ingress/egress * ports and using the specified explicit path. @@ -57,19 +35,116 @@ public final class MplsPathIntent extends PathIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException {@code path} is null */ - public MplsPathIntent(ApplicationId appId, TrafficSelector selector, + private MplsPathIntent(ApplicationId appId, TrafficSelector selector, TrafficTreatment treatment, Path path, Optional ingressLabel, Optional egressLabel, List constraints, int priority) { super(appId, selector, treatment, path, constraints, priority); - checkNotNull(ingressLabel); - checkNotNull(egressLabel); - this.ingressLabel = ingressLabel; - this.egressLabel = egressLabel; + this.ingressLabel = checkNotNull(ingressLabel); + this.egressLabel = checkNotNull(egressLabel); } + /** + * Returns a new host to host intent builder. + * + * @return host to host intent builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder of a host to host intent. + */ + public static final class Builder extends PathIntent.Builder { + private Optional ingressLabel = Optional.empty(); + private Optional egressLabel = Optional.empty(); + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + @Override + public Builder path(Path path) { + return (Builder) super.path(path); + } + + /** + * Sets the ingress label of the intent that will be built. + * + * @param ingressLabel ingress label + * @return this builder + */ + public Builder ingressLabel(Optional ingressLabel) { + this.ingressLabel = ingressLabel; + return this; + } + + /** + * Sets the ingress label of the intent that will be built. + * + * @param egressLabel ingress label + * @return this builder + */ + public Builder egressLabel(Optional egressLabel) { + this.egressLabel = egressLabel; + return this; + } + + + /** + * Builds a host to host intent from the accumulated parameters. + * + * @return point to point intent + */ + public MplsPathIntent build() { + + return new MplsPathIntent( + appId, + selector, + treatment, + path, + ingressLabel, + egressLabel, + constraints, + priority + ); + } + } + + /** * Returns the MPLS label which the ingress traffic should tagged. * diff --git a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java index 721ff176ce..c92898e92a 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java @@ -16,6 +16,7 @@ package org.onosproject.net.intent; import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import org.onosproject.core.ApplicationId; import org.onosproject.net.ConnectPoint; @@ -37,29 +38,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { private final Set ingressPoints; private final ConnectPoint egressPoint; - /** - * Creates a new multi-to-single point connectivity intent for the specified - * traffic selector and treatment. - * - * @param appId application identifier - * @param selector traffic selector - * @param treatment treatment - * @param ingressPoints set of ports from which ingress traffic originates - * @param egressPoint port to which traffic will egress - * @throws NullPointerException if {@code ingressPoints} or - * {@code egressPoint} is null. - * @throws IllegalArgumentException if the size of {@code ingressPoints} is - * not more than 1 - */ - public MultiPointToSinglePointIntent(ApplicationId appId, - TrafficSelector selector, - TrafficTreatment treatment, - Set ingressPoints, - ConnectPoint egressPoint) { - this(appId, selector, treatment, ingressPoints, egressPoint, - Collections.emptyList(), DEFAULT_INTENT_PRIORITY); - } - /** * Creates a new multi-to-single point connectivity intent for the specified * traffic selector and treatment. @@ -77,7 +55,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { * @throws IllegalArgumentException if the size of {@code ingressPoints} is * not more than 1 */ - public MultiPointToSinglePointIntent(ApplicationId appId, + private MultiPointToSinglePointIntent(ApplicationId appId, Key key, TrafficSelector selector, TrafficTreatment treatment, @@ -98,33 +76,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { this.egressPoint = egressPoint; } - /** - * Creates a new multi-to-single point connectivity intent for the specified - * traffic selector and treatment. - * - * @param appId application identifier - * @param selector traffic selector - * @param treatment treatment - * @param ingressPoints set of ports from which ingress traffic originates - * @param egressPoint port to which traffic will egress - * @param constraints constraints to apply to the intent - * @param priority priority to use for flows generated by this intent - * @throws NullPointerException if {@code ingressPoints} or - * {@code egressPoint} is null. - * @throws IllegalArgumentException if the size of {@code ingressPoints} is - * not more than 1 - */ - public MultiPointToSinglePointIntent(ApplicationId appId, - TrafficSelector selector, - TrafficTreatment treatment, - Set ingressPoints, - ConnectPoint egressPoint, - List constraints, - int priority) { - this(appId, null, selector, treatment, ingressPoints, egressPoint, - constraints, priority); - } - /** * Constructor for serializer. */ @@ -134,6 +85,105 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { this.egressPoint = null; } + /** + * Returns a new multi point to single point intent builder. The application id, + * ingress points and egress point are required fields. If they are + * not set by calls to the appropriate methods, an exception will + * be thrown. + * + * @return single point to multi point builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder of a multi point to single point intent. + */ + public static final class Builder extends ConnectivityIntent.Builder { + Set ingressPoints; + ConnectPoint egressPoint; + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the ingress point of the single point to multi point intent + * that will be built. + * + * @param ingressPoints ingress connect points + * @return this builder + */ + public Builder ingressPoints(Set ingressPoints) { + this.ingressPoints = ImmutableSet.copyOf(ingressPoints); + return this; + } + + /** + * Sets the egress point of the multi point to single point intent + * that will be built. + * + * @param egressPoint egress connect point + * @return this builder + */ + public Builder egressPoint(ConnectPoint egressPoint) { + this.egressPoint = egressPoint; + return this; + } + + /** + * Builds a multi point to single point intent from the + * accumulated parameters. + * + * @return point to point intent + */ + public MultiPointToSinglePointIntent build() { + + return new MultiPointToSinglePointIntent( + appId, + key, + selector, + treatment, + ingressPoints, + egressPoint, + constraints, + priority + ); + } + } + + /** * Returns the set of ports on which ingress traffic should be connected to * the egress port. 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 6804c86e6c..4843877d8f 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 @@ -24,6 +24,8 @@ import org.onosproject.net.Path; import java.util.Collection; +import static com.google.common.base.Preconditions.checkNotNull; + public final class OpticalPathIntent extends Intent { private final ConnectPoint src; @@ -35,10 +37,11 @@ public final class OpticalPathIntent extends Intent { ConnectPoint src, ConnectPoint dst, Path path) { - super(appId, ImmutableSet.copyOf(path.links())); - this.src = src; - this.dst = dst; - this.path = path; + super(appId, null, ImmutableSet.copyOf(path.links()), + Intent.DEFAULT_INTENT_PRIORITY); + this.src = checkNotNull(src); + this.dst = checkNotNull(dst); + this.path = checkNotNull(path); } protected OpticalPathIntent() { @@ -69,6 +72,7 @@ public final class OpticalPathIntent extends Intent { return MoreObjects.toStringHelper(getClass()) .add("id", id()) .add("appId", appId()) + .add("key", key()) .add("resources", resources()) .add("ingressPort", src) .add("egressPort", dst) diff --git a/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java b/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java index 13fa61e164..1cb960f733 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java @@ -15,17 +15,17 @@ */ package org.onosproject.net.intent; -import com.google.common.base.MoreObjects; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; +import java.util.List; + import org.onosproject.core.ApplicationId; import org.onosproject.net.Link; import org.onosproject.net.Path; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; -import java.util.Collections; -import java.util.List; +import com.google.common.base.MoreObjects; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import static com.google.common.base.Preconditions.checkArgument; @@ -36,22 +36,6 @@ public class PathIntent extends ConnectivityIntent { private final Path path; - /** - * Creates a new point-to-point intent with the supplied ingress/egress - * ports and using the specified explicit path. - * - * @param appId application identifier - * @param selector traffic selector - * @param treatment treatment - * @param path traversed links - * @throws NullPointerException {@code path} is null - */ - public PathIntent(ApplicationId appId, TrafficSelector selector, - TrafficTreatment treatment, Path path) { - this(appId, selector, treatment, path, Collections.emptyList(), - DEFAULT_INTENT_PRIORITY); - } - /** * Creates a new point-to-point intent with the supplied ingress/egress * ports and using the specified explicit path. @@ -64,10 +48,13 @@ public class PathIntent extends ConnectivityIntent { * @param priority priority to use for the generated flows * @throws NullPointerException {@code path} is null */ - public PathIntent(ApplicationId appId, TrafficSelector selector, - TrafficTreatment treatment, Path path, List constraints, - int priority) { - super(appId, resources(path.links()), selector, treatment, constraints, + protected PathIntent(ApplicationId appId, + TrafficSelector selector, + TrafficTreatment treatment, + Path path, + List constraints, + int priority) { + super(appId, null, resources(path.links()), selector, treatment, constraints, priority); PathIntent.validate(path.links()); this.path = path; @@ -81,6 +68,86 @@ public class PathIntent extends ConnectivityIntent { this.path = null; } + /** + * Returns a new host to host intent builder. + * + * @return host to host intent builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder of a host to host intent. + */ + public static class Builder extends ConnectivityIntent.Builder { + Path path; + + protected Builder() { + // Hide default constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the path of the intent that will be built. + * + * @param path path for the intent + * @return this builder + */ + public Builder path(Path path) { + this.path = path; + return this; + } + + /** + * Builds a path intent from the accumulated parameters. + * + * @return point to point intent + */ + public PathIntent build() { + + return new PathIntent( + appId, + selector, + treatment, + path, + constraints, + priority + ); + } + } + + + // NOTE: This methods takes linear time with the number of links. /** * Validates that source element ID and destination element ID of a link are diff --git a/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java index 5f80d9a988..54391217e2 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java @@ -159,13 +159,11 @@ public final class PointToPointIntent extends ConnectivityIntent { super(appId, key, Collections.emptyList(), selector, treatment, constraints, priority); - checkNotNull(ingressPoint); - checkNotNull(egressPoint); checkArgument(!ingressPoint.equals(egressPoint), "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); - this.ingressPoint = ingressPoint; - this.egressPoint = egressPoint; + this.ingressPoint = checkNotNull(ingressPoint); + this.egressPoint = checkNotNull(egressPoint); } /** diff --git a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java index 129c4a6bd2..a58d3af491 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java @@ -16,7 +16,7 @@ package org.onosproject.net.intent; import com.google.common.base.MoreObjects; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet; import org.onosproject.core.ApplicationId; import org.onosproject.net.ConnectPoint; @@ -38,27 +38,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { private final ConnectPoint ingressPoint; private final Set egressPoints; - /** - * Creates a new single-to-multi point connectivity intent. - * - * @param appId application identifier - * @param selector traffic selector - * @param treatment treatment - * @param ingressPoint port on which traffic will ingress - * @param egressPoints set of ports on which traffic will egress - * @throws NullPointerException if {@code ingressPoint} or - * {@code egressPoints} is null - * @throws IllegalArgumentException if the size of {@code egressPoints} is - * not more than 1 - */ - public SinglePointToMultiPointIntent(ApplicationId appId, - TrafficSelector selector, TrafficTreatment treatment, - ConnectPoint ingressPoint, Set egressPoints) { - this(appId, null, selector, treatment, ingressPoint, egressPoints, - Collections.emptyList(), - DEFAULT_INTENT_PRIORITY); - } - /** * Creates a new single-to-multi point connectivity intent. * @@ -75,7 +54,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { * @throws IllegalArgumentException if the size of {@code egressPoints} is * not more than 1 */ - public SinglePointToMultiPointIntent(ApplicationId appId, + private SinglePointToMultiPointIntent(ApplicationId appId, Key key, TrafficSelector selector, TrafficTreatment treatment, ConnectPoint ingressPoint, Set egressPoints, @@ -90,7 +69,105 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { "Set of egresses should not contain ingress (ingress: %s)", ingressPoint); this.ingressPoint = checkNotNull(ingressPoint); - this.egressPoints = Sets.newHashSet(egressPoints); + this.egressPoints = egressPoints; + } + + /** + * Returns a new single point to multi point intent builder. The application id, + * ingress point and egress points are required fields. If they are + * not set by calls to the appropriate methods, an exception will + * be thrown. + * + * @return single point to multi point builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builder of a single point to multi point intent. + */ + public static final class Builder extends ConnectivityIntent.Builder { + ConnectPoint ingressPoint; + Set egressPoints; + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the ingress point of the single point to multi point intent + * that will be built. + * + * @param ingressPoint ingress connect point + * @return this builder + */ + public Builder ingressPoint(ConnectPoint ingressPoint) { + this.ingressPoint = ingressPoint; + return this; + } + + /** + * Sets the egress points of the single point to multi point intent + * that will be built. + * + * @param egressPoints egress connect points + * @return this builder + */ + public Builder egressPoints(Set egressPoints) { + this.egressPoints = ImmutableSet.copyOf(egressPoints); + return this; + } + + /** + * Builds a single point to multi point intent from the + * accumulated parameters. + * + * @return point to point intent + */ + public SinglePointToMultiPointIntent build() { + + return new SinglePointToMultiPointIntent( + appId, + key, + selector, + treatment, + ingressPoint, + egressPoints, + constraints, + priority + ); + } } /** diff --git a/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java b/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java index ee95255223..a995758be5 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java +++ b/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java @@ -15,21 +15,16 @@ */ package org.onosproject.net.intent; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableList; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.HostId; -import org.onosproject.net.Link; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.intent.constraint.LinkTypeConstraint; - import java.util.Collections; import java.util.List; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.TrafficTreatment; + +import com.google.common.base.MoreObjects; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -40,45 +35,12 @@ public final class TwoWayP2PIntent extends ConnectivityIntent { private final ConnectPoint one; private final ConnectPoint two; - /** - * Creates a new two way host-to-host intent with the supplied host pair and no - * other traffic selection or treatment criteria. - * - * @param appId application identifier - * @param one first host - * @param two second host - * @throws NullPointerException if {@code one} or {@code two} is null. - */ - public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two) { - this(appId, one, two, - DefaultTrafficSelector.emptySelector(), - DefaultTrafficTreatment.emptyTreatment(), - ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), - DEFAULT_INTENT_PRIORITY); - } - - /** - * Creates a new host-to-host intent with the supplied host pair. - * - * @param appId application identifier - * @param one first host - * @param two second host - * @param selector action - * @param treatment ingress port - * @throws NullPointerException if {@code one} or {@code two} is null. - */ - public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two, - TrafficSelector selector, - TrafficTreatment treatment) { - this(appId, one, two, selector, treatment, - ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), - DEFAULT_INTENT_PRIORITY); - } /** * Creates a new host-to-host intent with the supplied host pair. * * @param appId application identifier + * @param key intent key * @param one first host * @param two second host * @param selector action @@ -87,27 +49,7 @@ public final class TwoWayP2PIntent extends ConnectivityIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException if {@code one} or {@code two} is null. */ - public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two, - TrafficSelector selector, - TrafficTreatment treatment, - List constraints, - int priority) { - this(appId, null, one, two, selector, treatment, constraints, priority); - } - /** - * Creates a new host-to-host intent with the supplied host pair. - * - * @param appId application identifier - * @param key intent key - * @param one first host - * @param two second host - * @param selector action - * @param treatment ingress port - * @param constraints optional prioritized list of path selection constraints - * @param priority priority to use for flows generated by this intent - * @throws NullPointerException if {@code one} or {@code two} is null. - */ - public TwoWayP2PIntent(ApplicationId appId, Key key, + private TwoWayP2PIntent(ApplicationId appId, Key key, ConnectPoint one, ConnectPoint two, TrafficSelector selector, TrafficTreatment treatment, @@ -122,12 +64,96 @@ public final class TwoWayP2PIntent extends ConnectivityIntent { } - private static HostId min(HostId one, HostId two) { - return one.hashCode() < two.hashCode() ? one : two; + /** + * Returns a new two way intent builder. + * + * @return two way intent builder + */ + public static Builder builder() { + return new Builder(); } - private static HostId max(HostId one, HostId two) { - return one.hashCode() >= two.hashCode() ? one : two; + /** + * Builder of a point to point intent. + */ + public static final class Builder extends ConnectivityIntent.Builder { + ConnectPoint one; + ConnectPoint two; + + private Builder() { + // Hide constructor + } + + @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 selector(TrafficSelector selector) { + return (Builder) super.selector(selector); + } + + @Override + public Builder treatment(TrafficTreatment treatment) { + return (Builder) super.treatment(treatment); + } + + @Override + public Builder constraints(List constraints) { + return (Builder) super.constraints(constraints); + } + + @Override + public Builder priority(int priority) { + return (Builder) super.priority(priority); + } + + /** + * Sets the first connection point of the two way intent that will be built. + * + * @param one first connect point + * @return this builder + */ + public Builder one(ConnectPoint one) { + this.one = one; + return this; + } + + /** + * Sets the second connection point of the two way intent that will be built. + * + * @param two second connect point + * @return this builder + */ + public Builder two(ConnectPoint two) { + this.two = two; + return this; + } + + /** + * Builds a point to point intent from the accumulated parameters. + * + * @return point to point intent + */ + public TwoWayP2PIntent build() { + + return new TwoWayP2PIntent( + appId, + key, + one, + two, + selector, + treatment, + constraints, + priority + ); + } } /** diff --git a/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java index c476144e50..31d6c4defd 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java +++ b/core/api/src/test/java/org/onosproject/net/intent/HostToHostIntentTest.java @@ -27,7 +27,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; -import static org.onosproject.net.NetTestTools.APP_ID; import static org.onosproject.net.NetTestTools.hid; /** @@ -43,7 +42,13 @@ public class HostToHostIntentTest extends IntentTest { private static final ApplicationId APPID = new TestApplicationId("foo"); private HostToHostIntent makeHostToHost(HostId one, HostId two) { - return new HostToHostIntent(APPID, one, two, selector, treatment); + return HostToHostIntent.builder() + .appId(APPID) + .one(one) + .two(two) + .selector(selector) + .treatment(treatment) + .build(); } /** @@ -75,17 +80,21 @@ public class HostToHostIntentTest extends IntentTest { */ @Test public void testEquals() { - final HostToHostIntent intent1 = new HostToHostIntent(APP_ID, - id1, - id2, - selector, - treatment); + final HostToHostIntent intent1 = HostToHostIntent.builder() + .appId(APPID) + .one(id1) + .two(id2) + .selector(selector) + .treatment(treatment) + .build(); - final HostToHostIntent intent2 = new HostToHostIntent(APP_ID, - id2, - id3, - selector, - treatment); + final HostToHostIntent intent2 = HostToHostIntent.builder() + .appId(APPID) + .one(id2) + .two(id3) + .selector(selector) + .treatment(treatment) + .build(); new EqualsTester() .addEqualityGroup(intent1) @@ -95,11 +104,23 @@ public class HostToHostIntentTest extends IntentTest { @Override protected Intent createOne() { - return new HostToHostIntent(APP_ID, id1, id2, selector, treatment); + return HostToHostIntent.builder() + .appId(APPID) + .one(id1) + .two(id2) + .selector(selector) + .treatment(treatment) + .build(); } @Override protected Intent createAnother() { - return new HostToHostIntent(APP_ID, id1, id3, selector, treatment); + return HostToHostIntent.builder() + .appId(APPID) + .one(id1) + .two(id3) + .selector(selector) + .treatment(treatment) + .build(); } } diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java index dca1906e43..4ae09fb95b 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java +++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java @@ -419,12 +419,13 @@ public class IntentTestsMocks { private final Long number; public MockIntent(Long number) { - super(NetTestTools.APP_ID, Collections.emptyList()); + super(NetTestTools.APP_ID, null, Collections.emptyList(), + Intent.DEFAULT_INTENT_PRIORITY); this.number = number; } public MockIntent(Long number, Collection resources) { - super(NetTestTools.APP_ID, resources); + super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY); this.number = number; } diff --git a/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java index a9ae782fca..4263531609 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java +++ b/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java @@ -67,22 +67,26 @@ public class LinkCollectionIntentTest extends IntentTest { final HashSet links1 = new HashSet<>(); links1.add(link("src", 1, "dst", 2)); final LinkCollectionIntent collectionIntent1 = - new LinkCollectionIntent(APP_ID, - selector, - treatment, - links1, - ingress, - egress); + LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links1) + .ingressPoints(ImmutableSet.of(ingress)) + .egressPoints(ImmutableSet.of(egress)) + .build(); final HashSet links2 = new HashSet<>(); links2.add(link("src", 1, "dst", 3)); final LinkCollectionIntent collectionIntent2 = - new LinkCollectionIntent(APP_ID, - selector, - treatment, - links2, - ingress, - egress); + LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links2) + .ingressPoints(ImmutableSet.of(ingress)) + .egressPoints(ImmutableSet.of(egress)) + .build(); new EqualsTester() .addEqualityGroup(collectionIntent1) @@ -98,12 +102,14 @@ public class LinkCollectionIntentTest extends IntentTest { final HashSet links1 = new HashSet<>(); links1.add(link("src", 1, "dst", 2)); final LinkCollectionIntent collectionIntent = - new LinkCollectionIntent(APP_ID, - selector, - treatment, - links1, - ingress, - egress); + LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links1) + .ingressPoints(ImmutableSet.of(ingress)) + .egressPoints(ImmutableSet.of(egress)) + .build(); final Set createdLinks = collectionIntent.links(); assertThat(createdLinks, hasSize(1)); @@ -128,14 +134,16 @@ public class LinkCollectionIntentTest extends IntentTest { links1.add(link("src", 1, "dst", 2)); constraints.add(new LambdaConstraint(Lambda.valueOf(23))); final LinkCollectionIntent collectionIntent = - new LinkCollectionIntent(APP_ID, - selector, - treatment, - links1, - ingress, - egress, - constraints, - 8888); + LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links1) + .ingressPoints(ImmutableSet.of(ingress)) + .egressPoints(ImmutableSet.of(egress)) + .constraints(constraints) + .priority(8888) + .build(); final Set createdLinks = collectionIntent.links(); assertThat(createdLinks, hasSize(1)); @@ -175,23 +183,27 @@ public class LinkCollectionIntentTest extends IntentTest { protected Intent createOne() { HashSet links1 = new HashSet<>(); links1.add(link("src", 1, "dst", 2)); - return new LinkCollectionIntent(APP_ID, - selector, - treatment, - links1, - ingress, - egress); + return LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links1) + .ingressPoints(ImmutableSet.of(ingress)) + .egressPoints(ImmutableSet.of(egress)) + .build(); } @Override protected Intent createAnother() { HashSet links2 = new HashSet<>(); links2.add(link("src", 1, "dst", 3)); - return new LinkCollectionIntent(APP_ID, - selector, - treatment, - links2, - ingress, - egress); + return LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links2) + .ingressPoints(ImmutableSet.of(ingress)) + .egressPoints(ImmutableSet.of(egress)) + .build(); } } diff --git a/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java index cab6a8d40f..2aac9065b8 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java +++ b/core/api/src/test/java/org/onosproject/net/intent/MultiPointToSinglePointIntentTest.java @@ -44,11 +44,23 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { @Override protected MultiPointToSinglePointIntent createOne() { - return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS1, P2); + return MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .ingressPoints(PS1) + .egressPoint(P2) + .build(); } @Override protected MultiPointToSinglePointIntent createAnother() { - return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS2, P1); + return MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .ingressPoints(PS2) + .egressPoint(P1) + .build(); } } diff --git a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java index 6db1a357cb..2149b26f2e 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java +++ b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java @@ -15,6 +15,8 @@ */ package org.onosproject.net.intent; +import java.util.Arrays; + import org.junit.Test; import org.onosproject.net.ConnectPoint; import org.onosproject.net.DefaultLink; @@ -25,8 +27,6 @@ import org.onosproject.net.Path; import org.onosproject.net.PortNumber; import org.onosproject.net.provider.ProviderId; -import java.util.Arrays; - import static org.junit.Assert.assertEquals; import static org.onosproject.net.DeviceId.deviceId; import static org.onosproject.net.Link.Type.DIRECT; @@ -65,12 +65,22 @@ public class PathIntentTest extends ConnectivityIntentTest { @Override protected PathIntent createOne() { - return new PathIntent(APPID, MATCH, NOP, PATH1); + return PathIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .path(PATH1) + .build(); } @Override protected PathIntent createAnother() { - return new PathIntent(APPID, MATCH, NOP, PATH2); + return PathIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .path(PATH2) + .build(); } /** @@ -79,7 +89,12 @@ public class PathIntentTest extends ConnectivityIntentTest { */ @Test(expected = IllegalArgumentException.class) public void testRaiseExceptionWhenSameDevices() { - new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1), cost)); + PathIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .path(new DefaultPath(provider1, Arrays.asList(link1), cost)) + .build(); } /** @@ -88,7 +103,12 @@ public class PathIntentTest extends ConnectivityIntentTest { */ @Test(expected = IllegalArgumentException.class) public void testRaiseExceptionWhenDifferentDevice() { - new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1, link2), cost)); + PathIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .path(new DefaultPath(provider1, Arrays.asList(link1, link2), cost)) + .build(); } } diff --git a/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java index f0f8ebff31..325c4f2e30 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java +++ b/core/api/src/test/java/org/onosproject/net/intent/SinglePointToMultiPointIntentTest.java @@ -44,11 +44,23 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { @Override protected SinglePointToMultiPointIntent createOne() { - return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P1, PS2); + return SinglePointToMultiPointIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .ingressPoint(P1) + .egressPoints(PS2) + .build(); } @Override protected SinglePointToMultiPointIntent createAnother() { - return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P2, PS1); + return SinglePointToMultiPointIntent.builder() + .appId(APPID) + .selector(MATCH) + .treatment(NOP) + .ingressPoint(P2) + .egressPoints(PS1) + .build(); } } diff --git a/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java b/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java index 32e5c90ffe..bf3176df17 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java +++ b/core/api/src/test/java/org/onosproject/net/intent/TestInstallableIntent.java @@ -32,7 +32,8 @@ public class TestInstallableIntent extends Intent { * @param value intent ID */ public TestInstallableIntent(int value) { // FIXME - super(new TestApplicationId("foo"), Collections.emptyList()); + super(new TestApplicationId("foo"), null, Collections.emptyList(), + Intent.DEFAULT_INTENT_PRIORITY); this.value = value; } diff --git a/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java b/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java index b3a8679b30..af3ea4926a 100644 --- a/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java +++ b/core/api/src/test/java/org/onosproject/net/intent/TestIntent.java @@ -32,7 +32,8 @@ public class TestIntent extends Intent { * @param value intent ID */ public TestIntent(int value) { // FIXME - super(new TestApplicationId("foo"), Collections.emptyList()); + super(new TestApplicationId("foo"), null, Collections.emptyList(), + Intent.DEFAULT_INTENT_PRIORITY); this.value = value; } diff --git a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java index 57274d84cd..afd102506b 100644 --- a/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java +++ b/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java @@ -78,7 +78,11 @@ public class IntentCodecTest extends AbstractIntentTest { @Test public void hostToHostIntent() { final HostToHostIntent intent = - new HostToHostIntent(appId, id1, id2); + HostToHostIntent.builder() + .appId(appId) + .one(id1) + .two(id2) + .build(); final JsonCodec intentCodec = context.codec(HostToHostIntent.class); diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java index 60306b2a2e..feea42fda6 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java @@ -97,9 +97,14 @@ public class HostToHostIntentCompiler HostToHostIntent intent) { TrafficSelector selector = builder(intent.selector()) .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); - return new PathIntent(intent.appId(), selector, intent.treatment(), - path, intent.constraints(), - intent.priority()); + return PathIntent.builder() + .appId(intent.appId()) + .selector(selector) + .treatment(intent.treatment()) + .path(path) + .constraints(intent.constraints()) + .priority(intent.priority()) + .build(); } } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java index 948dbd6610..b59d7eb708 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java @@ -75,11 +75,16 @@ public class MplsIntentCompiler extends ConnectivityIntentCompiler */ private Intent createPathIntent(Path path, MplsIntent intent) { - return new MplsPathIntent(intent.appId(), - intent.selector(), intent.treatment(), path, - intent.ingressLabel(), intent.egressLabel(), - intent.constraints(), - intent.priority()); + return MplsPathIntent.builder() + .appId(intent.appId()) + .selector(intent.selector()) + .treatment(intent.treatment()) + .path(path) + .ingressLabel(intent.ingressLabel()) + .egressLabel(intent.egressLabel()) + .constraints(intent.constraints()) + .priority(intent.priority()) + .build(); } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java index 6403019c12..fbdfa9c02c 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java @@ -16,7 +16,6 @@ package org.onosproject.net.intent.impl.compiler; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -89,14 +88,16 @@ public class MultiPointToSinglePointIntentCompiler } } - Set egress = ImmutableSet.of(intent.egressPoint()); - Intent result = new LinkCollectionIntent(intent.appId(), - intent.selector(), intent.treatment(), - Sets.newHashSet(links.values()), - intent.ingressPoints(), - ImmutableSet.of(intent.egressPoint()), - Collections.emptyList(), - intent.priority()); + Intent result = LinkCollectionIntent.builder() + .appId(intent.appId()) + .selector(intent.selector()) + .treatment(intent.treatment()) + .links(Sets.newHashSet(links.values())) + .ingressPoints(intent.ingressPoints()) + .egressPoints(ImmutableSet.of(intent.egressPoint())) + .priority(intent.priority()) + .build(); + return Arrays.asList(result); } 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 0f897a42e0..208c8e2e13 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 @@ -91,10 +91,14 @@ public class PointToPointIntentCompiler */ private Intent createPathIntent(Path path, PointToPointIntent intent) { - return new PathIntent(intent.appId(), - intent.selector(), intent.treatment(), path, - intent.constraints(), - intent.priority()); + return PathIntent.builder() + .appId(intent.appId()) + .selector(intent.selector()) + .treatment(intent.treatment()) + .path(path) + .constraints(intent.constraints()) + .priority(intent.priority()) + .build(); } } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java index 4b2260e111..8a97b7bc78 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java @@ -16,7 +16,6 @@ package org.onosproject.net.intent.impl.compiler; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -66,13 +65,16 @@ public class SinglePointToMultiPointIntentCompiler links.addAll(path.links()); } - Intent result = new LinkCollectionIntent(intent.appId(), - intent.selector(), - intent.treatment(), links, - ImmutableSet.of(intent.ingressPoint()), - intent.egressPoints(), - Collections.emptyList(), - intent.priority()); + Intent result = LinkCollectionIntent.builder() + .appId(intent.appId()) + .key(intent.key()) + .selector(intent.selector()) + .treatment(intent.treatment()) + .links(links) + .ingressPoints(ImmutableSet.of(intent.ingressPoint())) + .egressPoints(intent.egressPoints()) + .priority(intent.priority()) + .build(); return Arrays.asList(result); } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java index 548100706f..64c963b06a 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentManagerTest.java @@ -502,7 +502,8 @@ public class IntentManagerTest { public void intentWithoutCompiler() { class IntentNoCompiler extends Intent { IntentNoCompiler() { - super(APPID, Collections.emptyList()); + super(APPID, null, Collections.emptyList(), + Intent.DEFAULT_INTENT_PRIORITY); } } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java index b154d227d2..be9ab66d6c 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java @@ -90,8 +90,13 @@ public class HostToHostIntentCompilerTest extends AbstractIntentTest { * @return HostToHostIntent for the two hosts */ private HostToHostIntent makeIntent(String oneIdString, String twoIdString) { - return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString), - selector, treatment); + return HostToHostIntent.builder() + .appId(APPID) + .one(hid(oneIdString)) + .two(hid(twoIdString)) + .selector(selector) + .treatment(treatment) + .build(); } /** diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java index 4890e03944..76b26f4660 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java @@ -55,11 +55,14 @@ public class MplsIntentCompilerTest extends AbstractIntentTest { private MplsIntent makeIntent(String ingressIdString, Optional ingressLabel, String egressIdString, Optional egressLabel) { - return new MplsIntent(APPID, selector, treatment, - connectPoint(ingressIdString, 1), - ingressLabel, - connectPoint(egressIdString, 1), - egressLabel); + return MplsIntent.builder() + .appId(APPID) + .selector(selector) + .treatment(treatment) + .ingressPoint(connectPoint(ingressIdString, 1)) + .ingressLabel(ingressLabel) + .egressPoint(connectPoint(egressIdString, 1)) + .egressLabel(egressLabel).build(); } /** * Creates a compiler for HostToHost intents. @@ -157,7 +160,15 @@ public class MplsIntentCompilerTest extends AbstractIntentTest { public void testSameSwitchDifferentPortsIntentCompilation() { ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1)); ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2)); - MplsIntent intent = new MplsIntent(APP_ID, selector, treatment, src, Optional.empty(), dst, Optional.empty()); + MplsIntent intent = MplsIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .ingressPoint(src) + .ingressLabel(Optional.empty()) + .egressPoint(dst) + .egressLabel(Optional.empty()) + .build(); String[] hops = {"1"}; MplsIntentCompiler sut = makeCompiler(hops); diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java index bbc7ad1234..eb6be577a7 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java @@ -104,8 +104,13 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes ingressPoints.add(connectPoint(ingressId, 1)); } - return new MultiPointToSinglePointIntent(APPID, selector, treatment, - ingressPoints, egressPoint); + return MultiPointToSinglePointIntent.builder() + .appId(APPID) + .selector(selector) + .treatment(treatment) + .ingressPoints(ingressPoints) + .egressPoint(egressPoint) + .build(); } /** diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java index 9f88fa6bbd..00ebedf3cb 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstallerTest.java @@ -56,7 +56,14 @@ public class LinkCollectionIntentInstallerTest extends IntentInstallerTest { installer.coreService = testCoreService; installer.intentManager = new IntentInstallerTest.MockIntentManager(LinkCollectionIntent.class); - intent = new LinkCollectionIntent(APP_ID, selector, treatment, links, d1p1, d3p1); + intent = LinkCollectionIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .links(links) + .ingressPoints(ImmutableSet.of(d1p1)) + .egressPoints(ImmutableSet.of(d3p1)) + .build(); } private FlowRuleOperation findOperation(Collection ops, diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java index 8001eed7a5..e88947cd5e 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstallerTest.java @@ -31,8 +31,6 @@ import org.onosproject.net.intent.IntentTestsMocks; import org.onosproject.net.intent.MplsPathIntent; import org.onosproject.store.trivial.impl.SimpleLinkStore; -import com.google.common.collect.ImmutableList; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; @@ -70,12 +68,15 @@ public class MplsPathIntentInstallerTest extends IntentInstallerTest { installer.linkStore = new SimpleLinkStore(); installer.resourceService = new IntentTestsMocks.MockResourceService(); - intent = new MplsPathIntent(APP_ID, selector, treatment, - new DefaultPath(PID, links, hops), - ingressLabel, - egressLabel, - ImmutableList.of(), - 55); + intent = MplsPathIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .path(new DefaultPath(PID, links, hops)) + .ingressLabel(ingressLabel) + .egressLabel(egressLabel) + .priority(55) + .build(); } /** diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java index d0bb8435b3..6e7606db49 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java @@ -73,8 +73,14 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { private PathIntent createPathIntent(List links, List constraints) { int hops = links.size() - 1; - return new PathIntent(APP_ID, selector, treatment, - new DefaultPath(PID, links, hops), constraints, 333); + return PathIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .path(new DefaultPath(PID, links, hops)) + .constraints(constraints) + .priority(333) + .build(); } /** diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java index 695f115c64..9bbd16cfe1 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java @@ -27,8 +27,6 @@ import org.onosproject.net.Link; import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.intent.PathIntent; -import com.google.common.collect.ImmutableList; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; @@ -61,9 +59,13 @@ public class PathIntentInstallerTest extends IntentInstallerTest { installer = new PathIntentInstaller(); installer.coreService = testCoreService; installer.intentManager = new MockIntentManager(PathIntent.class); - intent = new PathIntent(APP_ID, selector, treatment, - new DefaultPath(PID, links, hops), ImmutableList.of(), - 77); + intent = PathIntent.builder() + .appId(APP_ID) + .selector(selector) + .treatment(treatment) + .path(new DefaultPath(PID, links, hops)) + .priority(77) + .build(); } /** diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java index d450812d0b..a968e4ea79 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java @@ -97,7 +97,12 @@ public class CompilingTest { .ingressPoint(cp1) .egressPoint(cp3) .build(); - compiled = new PathIntent(appId, selector, treatment, path); + compiled = PathIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .path(path) + .build(); } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java index 678bd2d66b..1938425da3 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallCoordinatingTest.java @@ -98,7 +98,12 @@ public class InstallCoordinatingTest { .ingressPoint(cp1) .egressPoint(cp3) .build(); - compiled = new PathIntent(appId, selector, treatment, path); + compiled = PathIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .path(path) + .build(); } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java index b7d063fadc..8d4b3349eb 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/InstallingTest.java @@ -98,7 +98,12 @@ public class InstallingTest { .ingressPoint(cp1) .egressPoint(cp3) .build(); - compiled = new PathIntent(appId, selector, treatment, path); + compiled = PathIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .path(path) + .build(); } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java index 19c3f6f06a..5d40516f3e 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinatingTest.java @@ -99,7 +99,12 @@ public class WithdrawCoordinatingTest { .ingressPoint(cp1) .egressPoint(cp3) .build(); - compiled = new PathIntent(appId, selector, treatment, path); + compiled = PathIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .path(path) + .build(); } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java index a1f08ec65d..6f7f267470 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/WithdrawingTest.java @@ -97,7 +97,12 @@ public class WithdrawingTest { .ingressPoint(cp1) .egressPoint(cp3) .build(); - compiled = new PathIntent(appId, selector, treatment, path); + compiled = PathIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .path(path) + .build(); } diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java index c27772fbdd..13dde08aab 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java @@ -311,9 +311,11 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { HostId two = hostId(string(payload, "two")); HostToHostIntent intent = - new HostToHostIntent(appId, one, two, - DefaultTrafficSelector.emptySelector(), - DefaultTrafficTreatment.emptyTreatment()); + HostToHostIntent.builder() + .appId(appId) + .one(one) + .two(two) + .build(); intentService.submit(intent); startMonitoringIntent(event, intent); @@ -336,8 +338,13 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); MultiPointToSinglePointIntent intent = - new MultiPointToSinglePointIntent(appId, selector, treatment, - ingressPoints, dstHost.location()); + MultiPointToSinglePointIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .ingressPoints(ingressPoints) + .egressPoint(dstHost.location()) + .build(); intentService.submit(intent); startMonitoringIntent(event, intent); diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewWebSocket.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewWebSocket.java index 9ef1329506..c07607885b 100644 --- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewWebSocket.java +++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewWebSocket.java @@ -15,9 +15,16 @@ */ package org.onosproject.ui.impl; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; + import org.eclipse.jetty.websocket.WebSocket; import org.onlab.osgi.ServiceDirectory; import org.onlab.util.AbstractAccumulator; @@ -55,15 +62,9 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; import org.onosproject.net.link.LinkEvent; import org.onosproject.net.link.LinkListener; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import static com.google.common.base.Strings.isNullOrEmpty; import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ADDED; @@ -349,9 +350,12 @@ public class TopologyViewWebSocket HostId two = hostId(string(payload, "two")); HostToHostIntent intent = - new HostToHostIntent(appId, one, two, - DefaultTrafficSelector.emptySelector(), - DefaultTrafficTreatment.emptyTreatment()); + HostToHostIntent.builder() + .appId(appId) + .one(one) + .two(two) + .build(); + intentService.submit(intent); startMonitoringIntent(event, intent); @@ -374,8 +378,13 @@ public class TopologyViewWebSocket TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); MultiPointToSinglePointIntent intent = - new MultiPointToSinglePointIntent(appId, selector, treatment, - ingressPoints, dstHost.location()); + MultiPointToSinglePointIntent.builder() + .appId(appId) + .selector(selector) + .treatment(treatment) + .ingressPoints(ingressPoints) + .egressPoint(dstHost.location()) + .build(); intentService.submit(intent); startMonitoringIntent(event, intent);