Refactor connectivity intent creation to use builders

- Each connectivity intent now has only one constructor
- Intent constructors are now private for leaf classes and
  protected for classes that can be derived from
- Each intent class has a Builder class that accumulates
  parameters for intent creation
- Each intent class has a public static builder() method
  to create a builder
- Each Builder class has a build() method to create the
  intent from the accumulated parameters
- Added keys to a few intent types that were missing them
- Tightened up usage of checkNotNull(), taking advantage of
  the return value to save some lines of code
- Modified callers to use the builders instead of directly
  calling the constructors

Change-Id: I713185d5ecbadbf51f87ef7f68fec41102106c78
This commit is contained in:
Ray Milkey 2015-03-18 15:45:36 -07:00 committed by Gerrit Code Review
parent 0d18df3f35
commit ebc5d22159
48 changed files with 1301 additions and 652 deletions

View File

@ -15,7 +15,19 @@
*/ */
package org.onosproject.sdnip; 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.Ethernet;
import org.onlab.packet.IpAddress; import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix; import org.onlab.packet.IpPrefix;
@ -43,19 +55,7 @@ import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Collection; import com.google.common.util.concurrent.ThreadFactoryBuilder;
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 static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@ -340,11 +340,15 @@ public class IntentSynchronizer implements FibListener {
int priority = int priority =
prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
Key key = Key.of(prefix.toString(), appId); Key key = Key.of(prefix.toString(), appId);
return new MultiPointToSinglePointIntent(appId, key, selector.build(), return MultiPointToSinglePointIntent.builder()
treatment.build(), .appId(appId)
ingressPorts, egressPort, .key(key)
Collections.emptyList(), .selector(selector.build())
priority); .treatment(treatment.build())
.ingressPoints(ingressPorts)
.egressPoint(egressPort)
.priority(priority)
.build();
} }
@Override @Override

View File

@ -233,9 +233,13 @@ public class IntentSyncTest extends AbstractIntentTest {
ingressPoints.add(SW4_ETH1); ingressPoints.add(SW4_ETH1);
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(APPID, MultiPointToSinglePointIntent.builder()
selectorBuilder.build(), treatmentBuilder.build(), .appId(APPID)
ingressPoints, SW1_ETH1); .selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
.egressPoint(SW1_ETH1)
.build();
// Setup the expected intents // Setup the expected intents
intentService.submit(eqExceptId(intent)); intentService.submit(eqExceptId(intent));
@ -291,9 +295,13 @@ public class IntentSyncTest extends AbstractIntentTest {
ingressPoints.add(SW3_ETH1); ingressPoints.add(SW3_ETH1);
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(APPID, MultiPointToSinglePointIntent.builder()
selectorBuilder.build(), treatmentBuilder.build(), .appId(APPID)
ingressPoints, SW4_ETH1); .selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
.egressPoint(SW4_ETH1)
.build();
// Setup the expected intents // Setup the expected intents
intentService.submit(eqExceptId(intent)); intentService.submit(eqExceptId(intent));
@ -357,10 +365,13 @@ public class IntentSyncTest extends AbstractIntentTest {
ingressPointsNew.add(SW4_ETH1); ingressPointsNew.add(SW4_ETH1);
MultiPointToSinglePointIntent intentNew = MultiPointToSinglePointIntent intentNew =
new MultiPointToSinglePointIntent(APPID, MultiPointToSinglePointIntent.builder()
selectorBuilderNew.build(), .appId(APPID)
treatmentBuilderNew.build(), .selector(selectorBuilderNew.build())
ingressPointsNew, SW2_ETH1); .treatment(treatmentBuilderNew.build())
.ingressPoints(ingressPointsNew)
.egressPoint(SW2_ETH1)
.build();
// Set up test expectation // Set up test expectation
reset(intentService); reset(intentService);
@ -592,9 +603,13 @@ public class IntentSyncTest extends AbstractIntentTest {
} }
} }
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(APPID, MultiPointToSinglePointIntent.builder()
selectorBuilder.build(), treatmentBuilder.build(), .appId(APPID)
ingressPoints, egressPoint); .selector(selectorBuilder.build())
.treatment(treatmentBuilder.build())
.ingressPoints(ingressPoints)
.egressPoint(egressPoint)
.build();
return intent; return intent;
} }

View File

@ -15,19 +15,15 @@
*/ */
package org.onosproject.cli.net; package org.onosproject.cli.net;
import java.util.List;
import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Command;
import org.onosproject.net.HostId; 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.Constraint;
import org.onosproject.net.intent.HostToHostIntent; import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.IntentService; import org.onosproject.net.intent.IntentService;
import java.util.List;
/** /**
* Installs host-to-host connectivity intent. * Installs host-to-host connectivity intent.
*/ */
@ -50,14 +46,16 @@ public class AddHostToHostIntentCommand extends ConnectivityIntentCommand {
HostId oneId = HostId.hostId(one); HostId oneId = HostId.hostId(one);
HostId twoId = HostId.hostId(two); HostId twoId = HostId.hostId(two);
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Constraint> constraints = buildConstraints(); List<Constraint> constraints = buildConstraints();
HostToHostIntent intent = new HostToHostIntent(appId(), key(), HostToHostIntent intent = HostToHostIntent.builder()
oneId, twoId, .appId(appId())
selector, treatment, .key(key())
constraints, priority()); .one(oneId)
.two(twoId)
.constraints(constraints)
.priority(priority())
.build();
service.submit(intent); service.submit(intent);
print("Host to Host intent submitted:\n%s", intent.toString()); print("Host to Host intent submitted:\n%s", intent.toString());
} }

View File

@ -75,10 +75,17 @@ public class AddMplsIntent extends ConnectivityIntentCommand {
List<Constraint> constraints = buildConstraints(); List<Constraint> constraints = buildConstraints();
MplsIntent intent = new MplsIntent(appId(), selector, treatment, MplsIntent intent = MplsIntent.builder()
ingress, ingressLabel, egress, .appId(appId())
egressLabel, constraints, .selector(selector)
priority()); .treatment(treatment)
.ingressPoint(ingress)
.ingressLabel(ingressLabel)
.egressPoint(egress)
.egressLabel(egressLabel)
.constraints(constraints)
.priority(priority())
.build();
service.submit(intent); service.submit(intent);
} }

View File

@ -72,11 +72,16 @@ public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentC
TrafficTreatment treatment = buildTrafficTreatment(); TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints(); List<Constraint> constraints = buildConstraints();
Intent intent = new MultiPointToSinglePointIntent(appId(), key(), Intent intent = MultiPointToSinglePointIntent.builder()
selector, treatment, .appId(appId())
ingressPoints, egress, .key(key())
constraints, .selector(selector)
priority()); .treatment(treatment)
.ingressPoints(ingressPoints)
.egressPoint(egress)
.constraints(constraints)
.priority(priority())
.build();
service.submit(intent); service.submit(intent);
print("Multipoint to single point intent submitted:\n%s", intent.toString()); print("Multipoint to single point intent submitted:\n%s", intent.toString());
} }

View File

@ -72,15 +72,16 @@ public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentC
List<Constraint> constraints = buildConstraints(); List<Constraint> constraints = buildConstraints();
SinglePointToMultiPointIntent intent = SinglePointToMultiPointIntent intent =
new SinglePointToMultiPointIntent( SinglePointToMultiPointIntent.builder()
appId(), .appId(appId())
key(), .key(key())
selector, .selector(selector)
treatment, .treatment(treatment)
ingressPoint, .ingressPoint(ingressPoint)
egressPoints, .egressPoints(egressPoints)
constraints, .constraints(constraints)
priority()); .priority(priority())
.build();
service.submit(intent); service.submit(intent);
print("Single point to multipoint intent submitted:\n%s", intent.toString()); print("Single point to multipoint intent submitted:\n%s", intent.toString());
} }

View File

@ -15,25 +15,22 @@
*/ */
package org.onosproject.cli.net; 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.Argument;
import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand; import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService; import org.onosproject.core.CoreService;
import org.onosproject.net.Host; 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.host.HostService;
import org.onosproject.net.intent.HostToHostIntent; import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService; import org.onosproject.net.intent.IntentService;
import java.util.Collection; import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
/** /**
* Installs point-to-point connectivity intents. * Installs point-to-point connectivity intents.
@ -67,17 +64,16 @@ public class RandomIntentCommand extends AbstractShellCommand {
} }
private Collection<Intent> generateIntents() { private Collection<Intent> generateIntents() {
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Host> hosts = Lists.newArrayList(hostService.getHosts()); List<Host> hosts = Lists.newArrayList(hostService.getHosts());
List<Intent> fullMesh = Lists.newArrayList(); List<Intent> fullMesh = Lists.newArrayList();
for (int i = 0; i < hosts.size(); i++) { for (int i = 0; i < hosts.size(); i++) {
for (int j = i + 1; j < hosts.size(); j++) { for (int j = i + 1; j < hosts.size(); j++) {
fullMesh.add(new HostToHostIntent(appId(), fullMesh.add(HostToHostIntent.builder()
hosts.get(i).id(), .appId(appId())
hosts.get(j).id(), .one(hosts.get(i).id())
selector, treatment)); .two(hosts.get(j).id())
.build());
} }
} }
Collections.shuffle(fullMesh); Collections.shuffle(fullMesh);

View File

@ -76,34 +76,6 @@ public abstract class ConnectivityIntent extends Intent {
this.constraints = checkNotNull(constraints); this.constraints = checkNotNull(constraints);
} }
/**
* Creates a connectivity intent that matches on the specified selector
* and applies the specified treatment.
* <p>
* Path will be optimized based on the first constraint if one is given.
* </p>
*
* @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<NetworkResource> resources,
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints,
int priority) {
super(appId, null, resources, priority);
this.selector = checkNotNull(selector);
this.treatment = checkNotNull(treatment);
this.constraints = checkNotNull(constraints);
}
/** /**
* Constructor for serializer. * Constructor for serializer.
*/ */

View File

@ -15,20 +15,16 @@
*/ */
package org.onosproject.net.intent; 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.Collections;
import java.util.List; 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; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
@ -40,59 +36,98 @@ public final class HostToHostIntent extends ConnectivityIntent {
private final HostId two; private final HostId two;
/** /**
* Creates a new host-to-host intent with the supplied host pair and no * Returns a new host to host intent builder.
* other traffic selection or treatment criteria.
* *
* @param appId application identifier * @return host to host intent builder
* @param one first host
* @param two second host
* @throws NullPointerException if {@code one} or {@code two} is null.
*/ */
public HostToHostIntent(ApplicationId appId, HostId one, HostId two) { public static Builder builder() {
this(appId, one, two, return new Builder();
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. * Builder of a host to host intent.
*
* @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 HostToHostIntent(ApplicationId appId, HostId one, HostId two, public static final class Builder extends ConnectivityIntent.Builder {
TrafficSelector selector, HostId one;
TrafficTreatment treatment) { HostId two;
this(appId, one, two, selector, treatment,
ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), private Builder() {
DEFAULT_INTENT_PRIORITY); // 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<Constraint> constraints) {
return (Builder) super.constraints(constraints);
}
@Override
public Builder priority(int priority) {
return (Builder) super.priority(priority);
} }
/** /**
* Creates a new host-to-host intent with the supplied host pair. * Sets the first host of the intent that will be built.
* *
* @param appId application identifier
* @param one first host * @param one first host
* @param two second host * @return this builder
* @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, public Builder one(HostId one) {
TrafficSelector selector, this.one = one;
TrafficTreatment treatment, return this;
List<Constraint> constraints,
int priority) {
this(appId, null, one, two, selector, treatment, constraints, priority);
} }
/**
* 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. * 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 * @param priority priority to use for flows generated by this intent
* @throws NullPointerException if {@code one} or {@code two} is null. * @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, HostId one, HostId two,
TrafficSelector selector, TrafficSelector selector,
TrafficTreatment treatment, 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. * Returns identifier of the first host.
* *

View File

@ -59,17 +59,6 @@ public abstract class Intent {
this.priority = DEFAULT_INTENT_PRIORITY; this.priority = DEFAULT_INTENT_PRIORITY;
} }
/**
* Creates a new intent.
*
* @param appId application identifier
* @param resources required network resources (optional)
*/
protected Intent(ApplicationId appId,
Collection<NetworkResource> resources) {
this(appId, null, resources, DEFAULT_INTENT_PRIORITY);
}
/** /**
* Creates a new intent. * Creates a new intent.
* *

View File

@ -15,8 +15,8 @@
*/ */
package org.onosproject.net.intent; package org.onosproject.net.intent;
import com.google.common.base.MoreObjects; import java.util.List;
import com.google.common.collect.ImmutableSet; import java.util.Set;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint; 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.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import java.util.Collections; import com.google.common.base.MoreObjects;
import java.util.List; import com.google.common.collect.ImmutableSet;
import java.util.Set;
/** /**
* Abstraction of a connectivity intent that is implemented by a set of path * 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<ConnectPoint> ingressPoints; private final Set<ConnectPoint> ingressPoints;
private final Set<ConnectPoint> egressPoints; private final Set<ConnectPoint> 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<Link> 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 * Creates a new actionable intent capable of funneling the selected
* traffic along the specified convergent tree and out the given egress * traffic along the specified convergent tree and out the given egress
* point satisfying the specified constraints. * point satisfying the specified constraints.
* *
* @param appId application identifier * @param appId application identifier
* @param key key to use for the intent
* @param selector traffic match * @param selector traffic match
* @param treatment action * @param treatment action
* @param links traversed links * @param links traversed links
* @param ingressPoint ingress point * @param ingressPoints ingress points
* @param egressPoint egress point * @param egressPoints egress points
* @param constraints optional list of constraints * @param constraints optional list of constraints
* @param priority priority to use for the flows generated by this intent * @param priority priority to use for the flows generated by this intent
* @throws NullPointerException {@code path} is null * @throws NullPointerException {@code path} is null
*/ */
public LinkCollectionIntent(ApplicationId appId, private LinkCollectionIntent(ApplicationId appId,
TrafficSelector selector, Key key,
TrafficTreatment treatment,
Set<Link> links,
ConnectPoint ingressPoint,
ConnectPoint egressPoint,
List<Constraint> 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,
TrafficSelector selector, TrafficSelector selector,
TrafficTreatment treatment, TrafficTreatment treatment,
Set<Link> links, Set<Link> links,
@ -114,11 +63,10 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
Set<ConnectPoint> egressPoints, Set<ConnectPoint> egressPoints,
List<Constraint> constraints, List<Constraint> constraints,
int priority) { int priority) {
super(appId, resources(links), selector, treatment, constraints, priority); super(appId, key, resources(links), selector, treatment, constraints, priority);
this.links = links; this.links = links;
this.ingressPoints = ImmutableSet.copyOf(ingressPoints); this.ingressPoints = ingressPoints;
this.egressPoints = ImmutableSet.copyOf(egressPoints); this.egressPoints = egressPoints;
} }
/** /**
@ -131,6 +79,120 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
this.egressPoints = null; 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<Link> links;
Set<ConnectPoint> ingressPoints;
Set<ConnectPoint> 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<Constraint> 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<ConnectPoint> 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<ConnectPoint> 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<Link> 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 * Returns the set of links that represent the network connections needed
* by this intent. * by this intent.

View File

@ -1,8 +1,5 @@
package org.onosproject.net.intent; 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.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -10,13 +7,13 @@ import java.util.Optional;
import org.onlab.packet.MplsLabel; import org.onlab.packet.MplsLabel;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint; import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import com.google.common.base.MoreObjects; 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 ConnectPoint egressPoint;
private final Optional<MplsLabel> egressLabel; private final Optional<MplsLabel> 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<MplsLabel> ingressLabel,
ConnectPoint egressPoint,
Optional<MplsLabel> 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 * Creates a new point-to-point intent with the supplied ingress/egress
* ports, labels and constraints. * ports, labels and constraints.
@ -68,7 +41,9 @@ public final class MplsIntent extends ConnectivityIntent {
* @param priority priority to use for flows generated by this intent * @param priority priority to use for flows generated by this intent
* @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
*/ */
public MplsIntent(ApplicationId appId, TrafficSelector selector, private MplsIntent(ApplicationId appId,
Key key,
TrafficSelector selector,
TrafficTreatment treatment, TrafficTreatment treatment,
ConnectPoint ingressPoint, ConnectPoint ingressPoint,
Optional<MplsLabel> ingressLabel, Optional<MplsLabel> ingressLabel,
@ -77,22 +52,142 @@ public final class MplsIntent extends ConnectivityIntent {
List<Constraint> constraints, List<Constraint> constraints,
int priority) { int priority) {
super(appId, Collections.emptyList(), selector, treatment, constraints, super(appId, key, Collections.emptyList(), selector, treatment, constraints,
priority); priority);
checkNotNull(ingressPoint); this.ingressPoint = checkNotNull(ingressPoint);
checkNotNull(egressPoint); this.ingressLabel = checkNotNull(ingressLabel);
checkArgument(!ingressPoint.equals(egressPoint), this.egressPoint = checkNotNull(egressPoint);
"ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); this.egressLabel = checkNotNull(egressLabel);
checkNotNull(ingressLabel);
checkNotNull(egressLabel);
this.ingressPoint = ingressPoint;
this.ingressLabel = ingressLabel;
this.egressPoint = egressPoint;
this.egressLabel = 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<MplsLabel> ingressLabel;
Optional<MplsLabel> 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<Constraint> 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<MplsLabel> 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<MplsLabel> 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. * Constructor for serializer.
*/ */
@ -147,6 +242,7 @@ public final class MplsIntent extends ConnectivityIntent {
return MoreObjects.toStringHelper(getClass()) return MoreObjects.toStringHelper(getClass())
.add("id", id()) .add("id", id())
.add("appId", appId()) .add("appId", appId())
.add("key", key())
.add("priority", priority()) .add("priority", priority())
.add("selector", selector()) .add("selector", selector())
.add("treatment", treatment()) .add("treatment", treatment())

View File

@ -1,18 +1,16 @@
package org.onosproject.net.intent; package org.onosproject.net.intent;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.onlab.packet.MplsLabel; import org.onlab.packet.MplsLabel;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.net.Path; import org.onosproject.net.Path;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Abstraction of explicit MPLS label-switched path. * Abstraction of explicit MPLS label-switched path.
@ -23,26 +21,6 @@ public final class MplsPathIntent extends PathIntent {
private final Optional<MplsLabel> ingressLabel; private final Optional<MplsLabel> ingressLabel;
private final Optional<MplsLabel> egressLabel; private final Optional<MplsLabel> 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<MplsLabel> ingressLabel,
Optional<MplsLabel> 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 * Creates a new point-to-point intent with the supplied ingress/egress
* ports and using the specified explicit path. * 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 * @param priority priority to use for flows generated by this intent
* @throws NullPointerException {@code path} is null * @throws NullPointerException {@code path} is null
*/ */
public MplsPathIntent(ApplicationId appId, TrafficSelector selector, private MplsPathIntent(ApplicationId appId, TrafficSelector selector,
TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel, TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel,
Optional<MplsLabel> egressLabel, List<Constraint> constraints, Optional<MplsLabel> egressLabel, List<Constraint> constraints,
int priority) { int priority) {
super(appId, selector, treatment, path, constraints, super(appId, selector, treatment, path, constraints,
priority); priority);
checkNotNull(ingressLabel); this.ingressLabel = checkNotNull(ingressLabel);
checkNotNull(egressLabel); this.egressLabel = checkNotNull(egressLabel);
this.ingressLabel = ingressLabel;
this.egressLabel = 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<MplsLabel> ingressLabel = Optional.empty();
private Optional<MplsLabel> 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<Constraint> 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<MplsLabel> 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<MplsLabel> 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. * Returns the MPLS label which the ingress traffic should tagged.
* *

View File

@ -16,6 +16,7 @@
package org.onosproject.net.intent; package org.onosproject.net.intent;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint; import org.onosproject.net.ConnectPoint;
@ -37,29 +38,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
private final Set<ConnectPoint> ingressPoints; private final Set<ConnectPoint> ingressPoints;
private final ConnectPoint egressPoint; 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<ConnectPoint> 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 * Creates a new multi-to-single point connectivity intent for the specified
* traffic selector and treatment. * traffic selector and treatment.
@ -77,7 +55,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
* @throws IllegalArgumentException if the size of {@code ingressPoints} is * @throws IllegalArgumentException if the size of {@code ingressPoints} is
* not more than 1 * not more than 1
*/ */
public MultiPointToSinglePointIntent(ApplicationId appId, private MultiPointToSinglePointIntent(ApplicationId appId,
Key key, Key key,
TrafficSelector selector, TrafficSelector selector,
TrafficTreatment treatment, TrafficTreatment treatment,
@ -98,33 +76,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
this.egressPoint = egressPoint; 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<ConnectPoint> ingressPoints,
ConnectPoint egressPoint,
List<Constraint> constraints,
int priority) {
this(appId, null, selector, treatment, ingressPoints, egressPoint,
constraints, priority);
}
/** /**
* Constructor for serializer. * Constructor for serializer.
*/ */
@ -134,6 +85,105 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
this.egressPoint = null; 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<ConnectPoint> 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<Constraint> 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<ConnectPoint> 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 * Returns the set of ports on which ingress traffic should be connected to
* the egress port. * the egress port.

View File

@ -24,6 +24,8 @@ import org.onosproject.net.Path;
import java.util.Collection; import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;
public final class OpticalPathIntent extends Intent { public final class OpticalPathIntent extends Intent {
private final ConnectPoint src; private final ConnectPoint src;
@ -35,10 +37,11 @@ public final class OpticalPathIntent extends Intent {
ConnectPoint src, ConnectPoint src,
ConnectPoint dst, ConnectPoint dst,
Path path) { Path path) {
super(appId, ImmutableSet.copyOf(path.links())); super(appId, null, ImmutableSet.copyOf(path.links()),
this.src = src; Intent.DEFAULT_INTENT_PRIORITY);
this.dst = dst; this.src = checkNotNull(src);
this.path = path; this.dst = checkNotNull(dst);
this.path = checkNotNull(path);
} }
protected OpticalPathIntent() { protected OpticalPathIntent() {
@ -69,6 +72,7 @@ public final class OpticalPathIntent extends Intent {
return MoreObjects.toStringHelper(getClass()) return MoreObjects.toStringHelper(getClass())
.add("id", id()) .add("id", id())
.add("appId", appId()) .add("appId", appId())
.add("key", key())
.add("resources", resources()) .add("resources", resources())
.add("ingressPort", src) .add("ingressPort", src)
.add("egressPort", dst) .add("egressPort", dst)

View File

@ -15,17 +15,17 @@
*/ */
package org.onosproject.net.intent; package org.onosproject.net.intent;
import com.google.common.base.MoreObjects; import java.util.List;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationId;
import org.onosproject.net.Link; import org.onosproject.net.Link;
import org.onosproject.net.Path; import org.onosproject.net.Path;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
import java.util.Collections; import com.google.common.base.MoreObjects;
import java.util.List; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
@ -36,22 +36,6 @@ public class PathIntent extends ConnectivityIntent {
private final Path path; 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 * Creates a new point-to-point intent with the supplied ingress/egress
* ports and using the specified explicit path. * 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 * @param priority priority to use for the generated flows
* @throws NullPointerException {@code path} is null * @throws NullPointerException {@code path} is null
*/ */
public PathIntent(ApplicationId appId, TrafficSelector selector, protected PathIntent(ApplicationId appId,
TrafficTreatment treatment, Path path, List<Constraint> constraints, TrafficSelector selector,
TrafficTreatment treatment,
Path path,
List<Constraint> constraints,
int priority) { int priority) {
super(appId, resources(path.links()), selector, treatment, constraints, super(appId, null, resources(path.links()), selector, treatment, constraints,
priority); priority);
PathIntent.validate(path.links()); PathIntent.validate(path.links());
this.path = path; this.path = path;
@ -81,6 +68,86 @@ public class PathIntent extends ConnectivityIntent {
this.path = null; 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<Constraint> 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. // NOTE: This methods takes linear time with the number of links.
/** /**
* Validates that source element ID and destination element ID of a link are * Validates that source element ID and destination element ID of a link are

View File

@ -159,13 +159,11 @@ public final class PointToPointIntent extends ConnectivityIntent {
super(appId, key, Collections.emptyList(), selector, treatment, constraints, super(appId, key, Collections.emptyList(), selector, treatment, constraints,
priority); priority);
checkNotNull(ingressPoint);
checkNotNull(egressPoint);
checkArgument(!ingressPoint.equals(egressPoint), checkArgument(!ingressPoint.equals(egressPoint),
"ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
this.ingressPoint = ingressPoint; this.ingressPoint = checkNotNull(ingressPoint);
this.egressPoint = egressPoint; this.egressPoint = checkNotNull(egressPoint);
} }
/** /**

View File

@ -16,7 +16,7 @@
package org.onosproject.net.intent; package org.onosproject.net.intent;
import com.google.common.base.MoreObjects; 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.core.ApplicationId;
import org.onosproject.net.ConnectPoint; import org.onosproject.net.ConnectPoint;
@ -38,27 +38,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
private final ConnectPoint ingressPoint; private final ConnectPoint ingressPoint;
private final Set<ConnectPoint> egressPoints; private final Set<ConnectPoint> 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<ConnectPoint> egressPoints) {
this(appId, null, selector, treatment, ingressPoint, egressPoints,
Collections.emptyList(),
DEFAULT_INTENT_PRIORITY);
}
/** /**
* Creates a new single-to-multi point connectivity intent. * 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 * @throws IllegalArgumentException if the size of {@code egressPoints} is
* not more than 1 * not more than 1
*/ */
public SinglePointToMultiPointIntent(ApplicationId appId, private SinglePointToMultiPointIntent(ApplicationId appId,
Key key, Key key,
TrafficSelector selector, TrafficTreatment treatment, TrafficSelector selector, TrafficTreatment treatment,
ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints, ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
@ -90,7 +69,105 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
"Set of egresses should not contain ingress (ingress: %s)", ingressPoint); "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
this.ingressPoint = checkNotNull(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<ConnectPoint> 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<Constraint> 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<ConnectPoint> 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
);
}
} }
/** /**

View File

@ -15,21 +15,16 @@
*/ */
package org.onosproject.net.intent; 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.Collections;
import java.util.List; 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; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
@ -40,60 +35,7 @@ public final class TwoWayP2PIntent extends ConnectivityIntent {
private final ConnectPoint one; private final ConnectPoint one;
private final ConnectPoint two; 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 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, ConnectPoint one, ConnectPoint two,
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints,
int priority) {
this(appId, null, one, two, selector, treatment, constraints, priority);
}
/** /**
* Creates a new host-to-host intent with the supplied host pair. * Creates a new host-to-host intent with the supplied host pair.
* *
@ -107,7 +49,7 @@ public final class TwoWayP2PIntent extends ConnectivityIntent {
* @param priority priority to use for flows generated by this intent * @param priority priority to use for flows generated by this intent
* @throws NullPointerException if {@code one} or {@code two} is null. * @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, ConnectPoint one, ConnectPoint two,
TrafficSelector selector, TrafficSelector selector,
TrafficTreatment treatment, 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<Constraint> 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
);
}
} }
/** /**

View File

@ -27,7 +27,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.hid; 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 static final ApplicationId APPID = new TestApplicationId("foo");
private HostToHostIntent makeHostToHost(HostId one, HostId two) { 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 @Test
public void testEquals() { public void testEquals() {
final HostToHostIntent intent1 = new HostToHostIntent(APP_ID, final HostToHostIntent intent1 = HostToHostIntent.builder()
id1, .appId(APPID)
id2, .one(id1)
selector, .two(id2)
treatment); .selector(selector)
.treatment(treatment)
.build();
final HostToHostIntent intent2 = new HostToHostIntent(APP_ID, final HostToHostIntent intent2 = HostToHostIntent.builder()
id2, .appId(APPID)
id3, .one(id2)
selector, .two(id3)
treatment); .selector(selector)
.treatment(treatment)
.build();
new EqualsTester() new EqualsTester()
.addEqualityGroup(intent1) .addEqualityGroup(intent1)
@ -95,11 +104,23 @@ public class HostToHostIntentTest extends IntentTest {
@Override @Override
protected Intent createOne() { 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 @Override
protected Intent createAnother() { 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();
} }
} }

View File

@ -419,12 +419,13 @@ public class IntentTestsMocks {
private final Long number; private final Long number;
public MockIntent(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; this.number = number;
} }
public MockIntent(Long number, Collection<NetworkResource> resources) { public MockIntent(Long number, Collection<NetworkResource> resources) {
super(NetTestTools.APP_ID, resources); super(NetTestTools.APP_ID, null, resources, Intent.DEFAULT_INTENT_PRIORITY);
this.number = number; this.number = number;
} }

View File

@ -67,22 +67,26 @@ public class LinkCollectionIntentTest extends IntentTest {
final HashSet<Link> links1 = new HashSet<>(); final HashSet<Link> links1 = new HashSet<>();
links1.add(link("src", 1, "dst", 2)); links1.add(link("src", 1, "dst", 2));
final LinkCollectionIntent collectionIntent1 = final LinkCollectionIntent collectionIntent1 =
new LinkCollectionIntent(APP_ID, LinkCollectionIntent.builder()
selector, .appId(APP_ID)
treatment, .selector(selector)
links1, .treatment(treatment)
ingress, .links(links1)
egress); .ingressPoints(ImmutableSet.of(ingress))
.egressPoints(ImmutableSet.of(egress))
.build();
final HashSet<Link> links2 = new HashSet<>(); final HashSet<Link> links2 = new HashSet<>();
links2.add(link("src", 1, "dst", 3)); links2.add(link("src", 1, "dst", 3));
final LinkCollectionIntent collectionIntent2 = final LinkCollectionIntent collectionIntent2 =
new LinkCollectionIntent(APP_ID, LinkCollectionIntent.builder()
selector, .appId(APP_ID)
treatment, .selector(selector)
links2, .treatment(treatment)
ingress, .links(links2)
egress); .ingressPoints(ImmutableSet.of(ingress))
.egressPoints(ImmutableSet.of(egress))
.build();
new EqualsTester() new EqualsTester()
.addEqualityGroup(collectionIntent1) .addEqualityGroup(collectionIntent1)
@ -98,12 +102,14 @@ public class LinkCollectionIntentTest extends IntentTest {
final HashSet<Link> links1 = new HashSet<>(); final HashSet<Link> links1 = new HashSet<>();
links1.add(link("src", 1, "dst", 2)); links1.add(link("src", 1, "dst", 2));
final LinkCollectionIntent collectionIntent = final LinkCollectionIntent collectionIntent =
new LinkCollectionIntent(APP_ID, LinkCollectionIntent.builder()
selector, .appId(APP_ID)
treatment, .selector(selector)
links1, .treatment(treatment)
ingress, .links(links1)
egress); .ingressPoints(ImmutableSet.of(ingress))
.egressPoints(ImmutableSet.of(egress))
.build();
final Set<Link> createdLinks = collectionIntent.links(); final Set<Link> createdLinks = collectionIntent.links();
assertThat(createdLinks, hasSize(1)); assertThat(createdLinks, hasSize(1));
@ -128,14 +134,16 @@ public class LinkCollectionIntentTest extends IntentTest {
links1.add(link("src", 1, "dst", 2)); links1.add(link("src", 1, "dst", 2));
constraints.add(new LambdaConstraint(Lambda.valueOf(23))); constraints.add(new LambdaConstraint(Lambda.valueOf(23)));
final LinkCollectionIntent collectionIntent = final LinkCollectionIntent collectionIntent =
new LinkCollectionIntent(APP_ID, LinkCollectionIntent.builder()
selector, .appId(APP_ID)
treatment, .selector(selector)
links1, .treatment(treatment)
ingress, .links(links1)
egress, .ingressPoints(ImmutableSet.of(ingress))
constraints, .egressPoints(ImmutableSet.of(egress))
8888); .constraints(constraints)
.priority(8888)
.build();
final Set<Link> createdLinks = collectionIntent.links(); final Set<Link> createdLinks = collectionIntent.links();
assertThat(createdLinks, hasSize(1)); assertThat(createdLinks, hasSize(1));
@ -175,23 +183,27 @@ public class LinkCollectionIntentTest extends IntentTest {
protected Intent createOne() { protected Intent createOne() {
HashSet<Link> links1 = new HashSet<>(); HashSet<Link> links1 = new HashSet<>();
links1.add(link("src", 1, "dst", 2)); links1.add(link("src", 1, "dst", 2));
return new LinkCollectionIntent(APP_ID, return LinkCollectionIntent.builder()
selector, .appId(APP_ID)
treatment, .selector(selector)
links1, .treatment(treatment)
ingress, .links(links1)
egress); .ingressPoints(ImmutableSet.of(ingress))
.egressPoints(ImmutableSet.of(egress))
.build();
} }
@Override @Override
protected Intent createAnother() { protected Intent createAnother() {
HashSet<Link> links2 = new HashSet<>(); HashSet<Link> links2 = new HashSet<>();
links2.add(link("src", 1, "dst", 3)); links2.add(link("src", 1, "dst", 3));
return new LinkCollectionIntent(APP_ID, return LinkCollectionIntent.builder()
selector, .appId(APP_ID)
treatment, .selector(selector)
links2, .treatment(treatment)
ingress, .links(links2)
egress); .ingressPoints(ImmutableSet.of(ingress))
.egressPoints(ImmutableSet.of(egress))
.build();
} }
} }

View File

@ -44,11 +44,23 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
@Override @Override
protected MultiPointToSinglePointIntent createOne() { 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 @Override
protected MultiPointToSinglePointIntent createAnother() { 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();
} }
} }

View File

@ -15,6 +15,8 @@
*/ */
package org.onosproject.net.intent; package org.onosproject.net.intent;
import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
import org.onosproject.net.ConnectPoint; import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultLink; import org.onosproject.net.DefaultLink;
@ -25,8 +27,6 @@ import org.onosproject.net.Path;
import org.onosproject.net.PortNumber; import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId; import org.onosproject.net.provider.ProviderId;
import java.util.Arrays;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.onosproject.net.DeviceId.deviceId; import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.Link.Type.DIRECT; import static org.onosproject.net.Link.Type.DIRECT;
@ -65,12 +65,22 @@ public class PathIntentTest extends ConnectivityIntentTest {
@Override @Override
protected PathIntent createOne() { protected PathIntent createOne() {
return new PathIntent(APPID, MATCH, NOP, PATH1); return PathIntent.builder()
.appId(APPID)
.selector(MATCH)
.treatment(NOP)
.path(PATH1)
.build();
} }
@Override @Override
protected PathIntent createAnother() { 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) @Test(expected = IllegalArgumentException.class)
public void testRaiseExceptionWhenSameDevices() { 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) @Test(expected = IllegalArgumentException.class)
public void testRaiseExceptionWhenDifferentDevice() { 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();
} }
} }

View File

@ -44,11 +44,23 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
@Override @Override
protected SinglePointToMultiPointIntent createOne() { 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 @Override
protected SinglePointToMultiPointIntent createAnother() { 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();
} }
} }

View File

@ -32,7 +32,8 @@ public class TestInstallableIntent extends Intent {
* @param value intent ID * @param value intent ID
*/ */
public TestInstallableIntent(int value) { // FIXME 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; this.value = value;
} }

View File

@ -32,7 +32,8 @@ public class TestIntent extends Intent {
* @param value intent ID * @param value intent ID
*/ */
public TestIntent(int value) { // FIXME 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; this.value = value;
} }

View File

@ -78,7 +78,11 @@ public class IntentCodecTest extends AbstractIntentTest {
@Test @Test
public void hostToHostIntent() { public void hostToHostIntent() {
final HostToHostIntent intent = final HostToHostIntent intent =
new HostToHostIntent(appId, id1, id2); HostToHostIntent.builder()
.appId(appId)
.one(id1)
.two(id2)
.build();
final JsonCodec<HostToHostIntent> intentCodec = final JsonCodec<HostToHostIntent> intentCodec =
context.codec(HostToHostIntent.class); context.codec(HostToHostIntent.class);

View File

@ -97,9 +97,14 @@ public class HostToHostIntentCompiler
HostToHostIntent intent) { HostToHostIntent intent) {
TrafficSelector selector = builder(intent.selector()) TrafficSelector selector = builder(intent.selector())
.matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
return new PathIntent(intent.appId(), selector, intent.treatment(), return PathIntent.builder()
path, intent.constraints(), .appId(intent.appId())
intent.priority()); .selector(selector)
.treatment(intent.treatment())
.path(path)
.constraints(intent.constraints())
.priority(intent.priority())
.build();
} }
} }

View File

@ -75,11 +75,16 @@ public class MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent>
*/ */
private Intent createPathIntent(Path path, private Intent createPathIntent(Path path,
MplsIntent intent) { MplsIntent intent) {
return new MplsPathIntent(intent.appId(), return MplsPathIntent.builder()
intent.selector(), intent.treatment(), path, .appId(intent.appId())
intent.ingressLabel(), intent.egressLabel(), .selector(intent.selector())
intent.constraints(), .treatment(intent.treatment())
intent.priority()); .path(path)
.ingressLabel(intent.ingressLabel())
.egressLabel(intent.egressLabel())
.constraints(intent.constraints())
.priority(intent.priority())
.build();
} }

View File

@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl.compiler; package org.onosproject.net.intent.impl.compiler;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -89,14 +88,16 @@ public class MultiPointToSinglePointIntentCompiler
} }
} }
Set<ConnectPoint> egress = ImmutableSet.of(intent.egressPoint()); Intent result = LinkCollectionIntent.builder()
Intent result = new LinkCollectionIntent(intent.appId(), .appId(intent.appId())
intent.selector(), intent.treatment(), .selector(intent.selector())
Sets.newHashSet(links.values()), .treatment(intent.treatment())
intent.ingressPoints(), .links(Sets.newHashSet(links.values()))
ImmutableSet.of(intent.egressPoint()), .ingressPoints(intent.ingressPoints())
Collections.emptyList(), .egressPoints(ImmutableSet.of(intent.egressPoint()))
intent.priority()); .priority(intent.priority())
.build();
return Arrays.asList(result); return Arrays.asList(result);
} }

View File

@ -91,10 +91,14 @@ public class PointToPointIntentCompiler
*/ */
private Intent createPathIntent(Path path, private Intent createPathIntent(Path path,
PointToPointIntent intent) { PointToPointIntent intent) {
return new PathIntent(intent.appId(), return PathIntent.builder()
intent.selector(), intent.treatment(), path, .appId(intent.appId())
intent.constraints(), .selector(intent.selector())
intent.priority()); .treatment(intent.treatment())
.path(path)
.constraints(intent.constraints())
.priority(intent.priority())
.build();
} }
} }

View File

@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl.compiler; package org.onosproject.net.intent.impl.compiler;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -66,13 +65,16 @@ public class SinglePointToMultiPointIntentCompiler
links.addAll(path.links()); links.addAll(path.links());
} }
Intent result = new LinkCollectionIntent(intent.appId(), Intent result = LinkCollectionIntent.builder()
intent.selector(), .appId(intent.appId())
intent.treatment(), links, .key(intent.key())
ImmutableSet.of(intent.ingressPoint()), .selector(intent.selector())
intent.egressPoints(), .treatment(intent.treatment())
Collections.emptyList(), .links(links)
intent.priority()); .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
.egressPoints(intent.egressPoints())
.priority(intent.priority())
.build();
return Arrays.asList(result); return Arrays.asList(result);
} }

View File

@ -502,7 +502,8 @@ public class IntentManagerTest {
public void intentWithoutCompiler() { public void intentWithoutCompiler() {
class IntentNoCompiler extends Intent { class IntentNoCompiler extends Intent {
IntentNoCompiler() { IntentNoCompiler() {
super(APPID, Collections.emptyList()); super(APPID, null, Collections.emptyList(),
Intent.DEFAULT_INTENT_PRIORITY);
} }
} }

View File

@ -90,8 +90,13 @@ public class HostToHostIntentCompilerTest extends AbstractIntentTest {
* @return HostToHostIntent for the two hosts * @return HostToHostIntent for the two hosts
*/ */
private HostToHostIntent makeIntent(String oneIdString, String twoIdString) { private HostToHostIntent makeIntent(String oneIdString, String twoIdString) {
return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString), return HostToHostIntent.builder()
selector, treatment); .appId(APPID)
.one(hid(oneIdString))
.two(hid(twoIdString))
.selector(selector)
.treatment(treatment)
.build();
} }
/** /**

View File

@ -55,11 +55,14 @@ public class MplsIntentCompilerTest extends AbstractIntentTest {
private MplsIntent makeIntent(String ingressIdString, Optional<MplsLabel> ingressLabel, private MplsIntent makeIntent(String ingressIdString, Optional<MplsLabel> ingressLabel,
String egressIdString, Optional<MplsLabel> egressLabel) { String egressIdString, Optional<MplsLabel> egressLabel) {
return new MplsIntent(APPID, selector, treatment, return MplsIntent.builder()
connectPoint(ingressIdString, 1), .appId(APPID)
ingressLabel, .selector(selector)
connectPoint(egressIdString, 1), .treatment(treatment)
egressLabel); .ingressPoint(connectPoint(ingressIdString, 1))
.ingressLabel(ingressLabel)
.egressPoint(connectPoint(egressIdString, 1))
.egressLabel(egressLabel).build();
} }
/** /**
* Creates a compiler for HostToHost intents. * Creates a compiler for HostToHost intents.
@ -157,7 +160,15 @@ public class MplsIntentCompilerTest extends AbstractIntentTest {
public void testSameSwitchDifferentPortsIntentCompilation() { public void testSameSwitchDifferentPortsIntentCompilation() {
ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1)); ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1));
ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2)); 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"}; String[] hops = {"1"};
MplsIntentCompiler sut = makeCompiler(hops); MplsIntentCompiler sut = makeCompiler(hops);

View File

@ -104,8 +104,13 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
ingressPoints.add(connectPoint(ingressId, 1)); ingressPoints.add(connectPoint(ingressId, 1));
} }
return new MultiPointToSinglePointIntent(APPID, selector, treatment, return MultiPointToSinglePointIntent.builder()
ingressPoints, egressPoint); .appId(APPID)
.selector(selector)
.treatment(treatment)
.ingressPoints(ingressPoints)
.egressPoint(egressPoint)
.build();
} }
/** /**

View File

@ -56,7 +56,14 @@ public class LinkCollectionIntentInstallerTest extends IntentInstallerTest {
installer.coreService = testCoreService; installer.coreService = testCoreService;
installer.intentManager = installer.intentManager =
new IntentInstallerTest.MockIntentManager(LinkCollectionIntent.class); 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<FlowRuleOperation> ops, private FlowRuleOperation findOperation(Collection<FlowRuleOperation> ops,

View File

@ -31,8 +31,6 @@ import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.MplsPathIntent; import org.onosproject.net.intent.MplsPathIntent;
import org.onosproject.store.trivial.impl.SimpleLinkStore; import org.onosproject.store.trivial.impl.SimpleLinkStore;
import com.google.common.collect.ImmutableList;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@ -70,12 +68,15 @@ public class MplsPathIntentInstallerTest extends IntentInstallerTest {
installer.linkStore = new SimpleLinkStore(); installer.linkStore = new SimpleLinkStore();
installer.resourceService = new IntentTestsMocks.MockResourceService(); installer.resourceService = new IntentTestsMocks.MockResourceService();
intent = new MplsPathIntent(APP_ID, selector, treatment, intent = MplsPathIntent.builder()
new DefaultPath(PID, links, hops), .appId(APP_ID)
ingressLabel, .selector(selector)
egressLabel, .treatment(treatment)
ImmutableList.of(), .path(new DefaultPath(PID, links, hops))
55); .ingressLabel(ingressLabel)
.egressLabel(egressLabel)
.priority(55)
.build();
} }
/** /**

View File

@ -73,8 +73,14 @@ public class PathConstraintCalculationTest extends AbstractIntentTest {
private PathIntent createPathIntent(List<Link> links, List<Constraint> constraints) { private PathIntent createPathIntent(List<Link> links, List<Constraint> constraints) {
int hops = links.size() - 1; int hops = links.size() - 1;
return new PathIntent(APP_ID, selector, treatment, return PathIntent.builder()
new DefaultPath(PID, links, hops), constraints, 333); .appId(APP_ID)
.selector(selector)
.treatment(treatment)
.path(new DefaultPath(PID, links, hops))
.constraints(constraints)
.priority(333)
.build();
} }
/** /**

View File

@ -27,8 +27,6 @@ import org.onosproject.net.Link;
import org.onosproject.net.flow.FlowRuleOperation; import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.intent.PathIntent; import org.onosproject.net.intent.PathIntent;
import com.google.common.collect.ImmutableList;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@ -61,9 +59,13 @@ public class PathIntentInstallerTest extends IntentInstallerTest {
installer = new PathIntentInstaller(); installer = new PathIntentInstaller();
installer.coreService = testCoreService; installer.coreService = testCoreService;
installer.intentManager = new MockIntentManager(PathIntent.class); installer.intentManager = new MockIntentManager(PathIntent.class);
intent = new PathIntent(APP_ID, selector, treatment, intent = PathIntent.builder()
new DefaultPath(PID, links, hops), ImmutableList.of(), .appId(APP_ID)
77); .selector(selector)
.treatment(treatment)
.path(new DefaultPath(PID, links, hops))
.priority(77)
.build();
} }
/** /**

View File

@ -97,7 +97,12 @@ public class CompilingTest {
.ingressPoint(cp1) .ingressPoint(cp1)
.egressPoint(cp3) .egressPoint(cp3)
.build(); .build();
compiled = new PathIntent(appId, selector, treatment, path); compiled = PathIntent.builder()
.appId(appId)
.selector(selector)
.treatment(treatment)
.path(path)
.build();
} }

View File

@ -98,7 +98,12 @@ public class InstallCoordinatingTest {
.ingressPoint(cp1) .ingressPoint(cp1)
.egressPoint(cp3) .egressPoint(cp3)
.build(); .build();
compiled = new PathIntent(appId, selector, treatment, path); compiled = PathIntent.builder()
.appId(appId)
.selector(selector)
.treatment(treatment)
.path(path)
.build();
} }

View File

@ -98,7 +98,12 @@ public class InstallingTest {
.ingressPoint(cp1) .ingressPoint(cp1)
.egressPoint(cp3) .egressPoint(cp3)
.build(); .build();
compiled = new PathIntent(appId, selector, treatment, path); compiled = PathIntent.builder()
.appId(appId)
.selector(selector)
.treatment(treatment)
.path(path)
.build();
} }

View File

@ -99,7 +99,12 @@ public class WithdrawCoordinatingTest {
.ingressPoint(cp1) .ingressPoint(cp1)
.egressPoint(cp3) .egressPoint(cp3)
.build(); .build();
compiled = new PathIntent(appId, selector, treatment, path); compiled = PathIntent.builder()
.appId(appId)
.selector(selector)
.treatment(treatment)
.path(path)
.build();
} }

View File

@ -97,7 +97,12 @@ public class WithdrawingTest {
.ingressPoint(cp1) .ingressPoint(cp1)
.egressPoint(cp3) .egressPoint(cp3)
.build(); .build();
compiled = new PathIntent(appId, selector, treatment, path); compiled = PathIntent.builder()
.appId(appId)
.selector(selector)
.treatment(treatment)
.path(path)
.build();
} }

View File

@ -311,9 +311,11 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
HostId two = hostId(string(payload, "two")); HostId two = hostId(string(payload, "two"));
HostToHostIntent intent = HostToHostIntent intent =
new HostToHostIntent(appId, one, two, HostToHostIntent.builder()
DefaultTrafficSelector.emptySelector(), .appId(appId)
DefaultTrafficTreatment.emptyTreatment()); .one(one)
.two(two)
.build();
intentService.submit(intent); intentService.submit(intent);
startMonitoringIntent(event, intent); startMonitoringIntent(event, intent);
@ -336,8 +338,13 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(appId, selector, treatment, MultiPointToSinglePointIntent.builder()
ingressPoints, dstHost.location()); .appId(appId)
.selector(selector)
.treatment(treatment)
.ingressPoints(ingressPoints)
.egressPoint(dstHost.location())
.build();
intentService.submit(intent); intentService.submit(intent);
startMonitoringIntent(event, intent); startMonitoringIntent(event, intent);

View File

@ -15,9 +15,16 @@
*/ */
package org.onosproject.ui.impl; package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.JsonNode; import java.io.IOException;
import com.fasterxml.jackson.databind.node.ArrayNode; import java.util.ArrayList;
import com.fasterxml.jackson.databind.node.ObjectNode; 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.eclipse.jetty.websocket.WebSocket;
import org.onlab.osgi.ServiceDirectory; import org.onlab.osgi.ServiceDirectory;
import org.onlab.util.AbstractAccumulator; 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.LinkEvent;
import org.onosproject.net.link.LinkListener; import org.onosproject.net.link.LinkListener;
import java.io.IOException; import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList; import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.Collections; import com.fasterxml.jackson.databind.node.ObjectNode;
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 static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ADDED; import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ADDED;
@ -349,9 +350,12 @@ public class TopologyViewWebSocket
HostId two = hostId(string(payload, "two")); HostId two = hostId(string(payload, "two"));
HostToHostIntent intent = HostToHostIntent intent =
new HostToHostIntent(appId, one, two, HostToHostIntent.builder()
DefaultTrafficSelector.emptySelector(), .appId(appId)
DefaultTrafficTreatment.emptyTreatment()); .one(one)
.two(two)
.build();
intentService.submit(intent); intentService.submit(intent);
startMonitoringIntent(event, intent); startMonitoringIntent(event, intent);
@ -374,8 +378,13 @@ public class TopologyViewWebSocket
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(appId, selector, treatment, MultiPointToSinglePointIntent.builder()
ingressPoints, dstHost.location()); .appId(appId)
.selector(selector)
.treatment(treatment)
.ingressPoints(ingressPoints)
.egressPoint(dstHost.location())
.build();
intentService.submit(intent); intentService.submit(intent);
startMonitoringIntent(event, intent); startMonitoringIntent(event, intent);