Add a builder for DefaultLink to hide multiplying constructors
Change-Id: Iaf073d07989c398a8f44541ffdb8dd93e5715162
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/EcmpShortestPathGraph.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/EcmpShortestPathGraph.java
index 4fd5991..a8cb830 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/EcmpShortestPathGraph.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/EcmpShortestPathGraph.java
@@ -342,8 +342,13 @@
private Link copyDefaultLink(Link link) {
DefaultLink src = (DefaultLink) link;
- DefaultLink defaultLink = new DefaultLink(src.providerId(), src.src(),
- src.dst(), src.type(), src.annotations());
+ DefaultLink defaultLink = DefaultLink.builder()
+ .providerId(src.providerId())
+ .src(src.src())
+ .dst(src.dst())
+ .type(src.type())
+ .annotations(src.annotations())
+ .build();
return defaultLink;
}
diff --git a/core/api/src/main/java/org/onosproject/net/DefaultLink.java b/core/api/src/main/java/org/onosproject/net/DefaultLink.java
index e1e48b9..1876db6 100644
--- a/core/api/src/main/java/org/onosproject/net/DefaultLink.java
+++ b/core/api/src/main/java/org/onosproject/net/DefaultLink.java
@@ -21,6 +21,9 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.onosproject.net.Link.State.ACTIVE;
+import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Default infrastructure link model implementation.
@@ -42,7 +45,7 @@
* @param type link type
* @param annotations optional key/value annotations
*/
- public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
+ protected DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
Type type, Annotations... annotations) {
this(providerId, src, dst, type, ACTIVE, false, annotations);
}
@@ -60,7 +63,7 @@
* @param isExpected indicates if the link is preconfigured
* @param annotations optional key/value annotations
*/
- public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
+ private DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
Type type, State state,
boolean isExpected, Annotations... annotations) {
super(providerId, annotations);
@@ -129,8 +132,130 @@
.add("dst", dst)
.add("type", type)
.add("state", state)
- .add("configured", isExpected)
+ .add("expected", isExpected)
.toString();
}
+ /**
+ * Creates a new default link builder.
+ *
+ * @return default link builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder for DefaultLink objects.
+ */
+ public static final class Builder {
+ private ProviderId providerId;
+ private Annotations annotations = EMPTY;
+ private ConnectPoint src;
+ private ConnectPoint dst;
+ private Type type;
+ private State state = ACTIVE;
+ private boolean isExpected = false;
+
+ private Builder() {
+ // Hide constructor
+ }
+
+ /**
+ * Sets the providerId to be used by the builder.
+ *
+ * @param providerId new provider id
+ * @return self
+ */
+ public Builder providerId(ProviderId providerId) {
+ this.providerId = providerId;
+ return this;
+ }
+
+ /**
+ * Sets the annotations to be used by the builder.
+ *
+ * @param annotations new annotations
+ * @return self
+ */
+ public Builder annotations(Annotations annotations) {
+ this.annotations = annotations;
+ return this;
+ }
+
+ /**
+ * Sets the source connect point to be used by the builder.
+ *
+ * @param src source connect point
+ * @return self
+ */
+ public Builder src(ConnectPoint src) {
+ this.src = src;
+ return this;
+ }
+
+ /**
+ * Sets the destination connect point to be used by the builder.
+ *
+ * @param dst new destination connect point
+ * @return self
+ */
+ public Builder dst(ConnectPoint dst) {
+ this.dst = dst;
+ return this;
+ }
+
+ /**
+ * Sets the link type to be used by the builder.
+ *
+ * @param type new link type
+ * @return self
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets the link state to be used by the builder.
+ *
+ * @param state new link state
+ * @return self
+ */
+ public Builder state(State state) {
+ this.state = state;
+ return this;
+ }
+
+ /**
+ * Sets the expected flag to be used by the builder.
+ *
+ * @param isExpected new expected flag
+ * @return self
+ */
+ public Builder isExpected(boolean isExpected) {
+ this.isExpected = isExpected;
+ return this;
+ }
+
+ /**
+ * Builds a default link object from the accumulated parameters.
+ *
+ * @return default link object
+ */
+ public DefaultLink build() {
+ checkNotNull(src, "Source connect point cannot be null");
+ checkNotNull(dst, "Destination connect point cannot be null");
+ checkNotNull(type, "Type cannot be null");
+ checkNotNull(providerId, "Provider Id cannot be null");
+
+ return new DefaultLink(providerId, src, dst,
+ type, state,
+ isExpected, annotations);
+ }
+
+ }
+
+
+
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
index 9e67534..918e3b3 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
@@ -51,8 +51,18 @@
private final ConnectPoint cp2 = new ConnectPoint(device1, port2);
private final ConnectPoint cp3 = new ConnectPoint(device2, port3);
private final ConnectPoint cp4 = new ConnectPoint(device2, port4);
- private final DefaultLink link1 = new DefaultLink(provider1, cp1, cp2, DIRECT);
- private final DefaultLink link2 = new DefaultLink(provider1, cp1, cp2, DIRECT);
+ private final DefaultLink link1 = DefaultLink.builder()
+ .providerId(provider1)
+ .src(cp1)
+ .dst(cp2)
+ .type(DIRECT)
+ .build();
+ private final DefaultLink link2 = DefaultLink.builder()
+ .providerId(provider1)
+ .src(cp1)
+ .dst(cp2)
+ .type(DIRECT)
+ .build();
private final double cost = 1;
@Test
diff --git a/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java b/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java
index b87dc12..299eaef 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/constraint/AnnotationConstraintTest.java
@@ -59,7 +59,12 @@
DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build();
- link = new DefaultLink(PID, cp(DID1, PID1), cp(DID2, PID2), DIRECT, annotations);
+ link = DefaultLink.builder()
+ .providerId(PID)
+ .src(cp(DID1, PID1))
+ .dst(cp(DID2, PID2))
+ .type(DIRECT)
+ .annotations(annotations).build();
}
/**
diff --git a/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java b/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java
index bab1749..a08caab 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/constraint/LatencyConstraintTest.java
@@ -69,8 +69,20 @@
Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
- link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1);
- link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2);
+ link1 = DefaultLink.builder()
+ .providerId(PROVIDER_ID)
+ .src(cp(DID1, PN1))
+ .dst(cp(DID2, PN2))
+ .type(DIRECT)
+ .annotations(annotations1)
+ .build();
+ link2 = DefaultLink.builder()
+ .providerId(PROVIDER_ID)
+ .src(cp(DID2, PN3))
+ .dst(cp(DID3, PN4))
+ .type(DIRECT)
+ .annotations(annotations2)
+ .build();
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java b/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java
index f02787f..99cd338 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/constraint/ObstacleConstraintTest.java
@@ -62,8 +62,18 @@
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
- link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT);
- link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT);
+ link1 = DefaultLink.builder()
+ .providerId(PROVIDER_ID)
+ .src(cp(DID1, PN1))
+ .dst(cp(DID2, PN2))
+ .type(DIRECT)
+ .build();
+ link2 = DefaultLink.builder()
+ .providerId(PROVIDER_ID)
+ .src(cp(DID2, PN3))
+ .dst(cp(DID3, PN4))
+ .type(DIRECT)
+ .build();
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java b/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java
index f7e212a..bbd10a6 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/constraint/WaypointConstraintTest.java
@@ -62,8 +62,19 @@
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
- link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT);
- link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT);
+ link1 = DefaultLink.builder()
+ .providerId(PROVIDER_ID)
+ .src(cp(DID1, PN1))
+ .dst(cp(DID2, PN2))
+ .type(DIRECT)
+ .build();
+ link2 = DefaultLink.builder()
+ .providerId(PROVIDER_ID)
+ .src(cp(DID2, PN3))
+ .dst(cp(DID3, PN4))
+ .type(DIRECT)
+ .build();
+
path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
}
diff --git a/core/api/src/test/java/org/onosproject/net/link/LinkEventTest.java b/core/api/src/test/java/org/onosproject/net/link/LinkEventTest.java
index 307fa69..9e30ee2 100644
--- a/core/api/src/test/java/org/onosproject/net/link/LinkEventTest.java
+++ b/core/api/src/test/java/org/onosproject/net/link/LinkEventTest.java
@@ -31,10 +31,12 @@
public class LinkEventTest extends AbstractEventTest {
private Link createLink() {
- return new DefaultLink(new ProviderId("of", "foo"),
- new ConnectPoint(deviceId("of:foo"), portNumber(1)),
- new ConnectPoint(deviceId("of:bar"), portNumber(2)),
- Link.Type.INDIRECT);
+ return DefaultLink.builder()
+ .providerId(new ProviderId("of", "foo"))
+ .src(new ConnectPoint(deviceId("of:foo"), portNumber(1)))
+ .dst(new ConnectPoint(deviceId("of:bar"), portNumber(2)))
+ .type(Link.Type.INDIRECT)
+ .build();
}
@Test
diff --git a/core/api/src/test/java/org/onosproject/net/topology/DefaultTopologyEdgeTest.java b/core/api/src/test/java/org/onosproject/net/topology/DefaultTopologyEdgeTest.java
index 830e9b9f..a74882f 100644
--- a/core/api/src/test/java/org/onosproject/net/topology/DefaultTopologyEdgeTest.java
+++ b/core/api/src/test/java/org/onosproject/net/topology/DefaultTopologyEdgeTest.java
@@ -49,9 +49,19 @@
static final ProviderId PID = new ProviderId("foo", "bar");
/** D1:P1 -> D2:P1. */
- static final Link L1 = new DefaultLink(PID, CP1, CP2, Link.Type.INDIRECT);
+ static final Link L1 = DefaultLink.builder()
+ .providerId(PID)
+ .src(CP1)
+ .dst(CP2)
+ .type(Link.Type.INDIRECT)
+ .build();
/** D2:P1 -> D1:P2. */
- static final Link L2 = new DefaultLink(PID, CP3, CP4, Link.Type.INDIRECT);
+ static final Link L2 = DefaultLink.builder()
+ .providerId(PID)
+ .src(CP3)
+ .dst(CP4)
+ .type(Link.Type.INDIRECT)
+ .build();
@Test
public void basics() {
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java
index 14ee9b7..6898a8c 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/LinkCodec.java
@@ -75,6 +75,13 @@
Type type = Type.valueOf(json.get(TYPE).asText());
Annotations annotations = extractAnnotations(json, context);
- return new DefaultLink(pid, src, dst, type, annotations);
+ return DefaultLink
+ .builder()
+ .providerId(pid)
+ .src(src)
+ .dst(dst)
+ .type(type)
+ .annotations(annotations)
+ .build();
}
}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/LinkCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/LinkCodecTest.java
index c44b0eb..d04a91c 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/LinkCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/LinkCodecTest.java
@@ -33,13 +33,15 @@
*/
public class LinkCodecTest {
- private final Link link = new DefaultLink(JsonCodecUtils.PID,
- JsonCodecUtils.CP1,
- JsonCodecUtils.CP2,
- Link.Type.DIRECT,
- Link.State.ACTIVE,
- false,
- JsonCodecUtils.A1);
+ private final Link link = DefaultLink.builder()
+ .providerId(JsonCodecUtils.PID)
+ .src(JsonCodecUtils.CP1)
+ .dst(JsonCodecUtils.CP2)
+ .type(Link.Type.DIRECT)
+ .state(Link.State.ACTIVE)
+ .isExpected(false)
+ .annotations(JsonCodecUtils.A1)
+ .build();
@Test
public void linkCodecTest() {
diff --git a/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java b/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
index ef0f332..f12b1fc 100644
--- a/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
+++ b/core/common/src/test/java/org/onosproject/common/DefaultTopologyTest.java
@@ -122,9 +122,11 @@
// Short-hand for creating a link.
public static Link link(String src, int sp, String dst, int dp) {
- return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)),
- new ConnectPoint(did(dst), portNumber(dp)),
- Link.Type.DIRECT);
+ return DefaultLink.builder().providerId(PID)
+ .src(new ConnectPoint(did(src), portNumber(sp)))
+ .dst(new ConnectPoint(did(dst), portNumber(dp)))
+ .type(Link.Type.DIRECT)
+ .build();
}
// Crates a new device with the specified id
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStoreTest.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStoreTest.java
index 238e75d..6f6d853 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStoreTest.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStoreTest.java
@@ -76,11 +76,13 @@
.set(AnnotationKeys.OPTICAL_WAVES, "80")
.set(AnnotationKeys.BANDWIDTH, "1000")
.build();
- return new DefaultLink(
- new ProviderId("of", "foo"),
- new ConnectPoint(deviceId(dev1), portNumber(port1)),
- new ConnectPoint(deviceId(dev2), portNumber(port2)),
- DIRECT, annotations);
+ return DefaultLink.builder()
+ .providerId(new ProviderId("of", "foo"))
+ .src(new ConnectPoint(deviceId(dev1), portNumber(port1)))
+ .dst(new ConnectPoint(deviceId(dev2), portNumber(port2)))
+ .type(DIRECT)
+ .annotations(annotations)
+ .build();
}
@Before
diff --git a/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java
index 92b882a..ad2784d 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkStore.java
@@ -196,11 +196,14 @@
if (link.isDurable()) {
return link.state() == INACTIVE ? null :
updateLink(linkKey(link.src(), link.dst()), link,
- new DefaultLink(link.providerId(),
- link.src(), link.dst(),
- link.type(), INACTIVE,
- link.isDurable(),
- link.annotations()));
+ DefaultLink.builder()
+ .providerId(link.providerId())
+ .src(link.src())
+ .dst(link.dst())
+ .type(link.type())
+ .state(INACTIVE)
+ .isExpected(link.isExpected())
+ .annotations(link.annotations()).build());
}
return removeLink(src, dst);
}
@@ -327,7 +330,15 @@
}
boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
- return new DefaultLink(primary, src, dst, type, ACTIVE, isDurable, annotations);
+ return DefaultLink.builder()
+ .providerId(primary)
+ .src(src)
+ .dst(dst)
+ .type(type)
+ .state(ACTIVE)
+ .isExpected(isDurable)
+ .annotations(annotations)
+ .build();
}
private Map<ProviderId, LinkDescription> getOrCreateLinkDescriptions(LinkKey key) {
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
index 4116825..7e544af 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
@@ -88,8 +88,13 @@
// Produces a reverse variant of the specified link.
private Link reverseLink(Link link) {
- return new DefaultLink(link.providerId(), link.dst(), link.src(),
- link.type(), link.state(), link.isDurable());
+ return DefaultLink.builder().providerId(link.providerId())
+ .src(link.dst())
+ .dst(link.src())
+ .type(link.type())
+ .state(link.state())
+ .isExpected(link.isExpected())
+ .build();
}
// Creates a path intent from the specified path and original connectivity intent.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
index c5fa371..48f0580 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
@@ -65,9 +65,9 @@
private final ConnectPoint d1p0 = connectPoint("s1", 10);
private final Set<Link> links = ImmutableSet.of(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
- new DefaultLink(PID, d1p1, d3p1, DIRECT));
+ DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
+ DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
+ DefaultLink.builder().providerId(PID).src(d1p1).dst(d3p1).type(DIRECT).build());
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
index 6cceee1..922ea42 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
@@ -77,8 +77,8 @@
private final List<Link> links = Arrays.asList(
createEdgeLink(d1pi, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
+ DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
+ DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
createEdgeLink(d3pe, false)
);
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
index 38a116d..0a3f9d2 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompilerTest.java
@@ -64,8 +64,8 @@
private final ConnectPoint d3p1 = connectPoint("s3", 1);
private final List<Link> links = Arrays.asList(
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT)
+ DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
+ DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build()
);
private final int hops = links.size() + 1;
private OpticalPathIntent intent;
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
index dda82c6..4af8ea4 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
@@ -84,8 +84,8 @@
private final List<Link> links = Arrays.asList(
createEdgeLink(d1p0, true),
- new DefaultLink(PID, d1p1, d2p0, DIRECT),
- new DefaultLink(PID, d2p1, d3p1, DIRECT),
+ DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
+ DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
createEdgeLink(d3p0, false)
);
private final int hops = links.size() - 1;
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
index c15ecae..80cc96c 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
@@ -70,7 +70,8 @@
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
- private final List<Link> links = Collections.singletonList(new DefaultLink(pid, cp2, cp4, DIRECT));
+ private final List<Link> links = Collections.singletonList(
+ DefaultLink.builder().providerId(pid).src(cp2).dst(cp4).type(DIRECT).build());
private final Path path = new DefaultPath(pid, links, 10);
private PointToPointIntent input;
diff --git a/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java b/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java
index 48851f7..8e77ac8 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java
@@ -317,7 +317,15 @@
});
boolean isDurable = Objects.equals(annotations.get().value(AnnotationKeys.DURABLE), "true");
- return new DefaultLink(baseProviderId, src, dst, type, ACTIVE, isDurable, annotations.get());
+ return DefaultLink.builder()
+ .providerId(baseProviderId)
+ .src(src)
+ .dst(dst)
+ .type(type)
+ .state(ACTIVE)
+ .isExpected(isDurable)
+ .annotations(annotations.get())
+ .build();
}
// Updates, if necessary the specified link and returns the appropriate event.
@@ -346,11 +354,15 @@
// FIXME: this will not sync link state!!!
return link.state() == INACTIVE ? null :
updateLink(linkKey(link.src(), link.dst()), link,
- new DefaultLink(link.providerId(),
- link.src(), link.dst(),
- link.type(), INACTIVE,
- link.isDurable(),
- link.annotations()));
+ DefaultLink.builder()
+ .providerId(link.providerId())
+ .src(link.src())
+ .dst(link.dst())
+ .type(link.type())
+ .state(INACTIVE)
+ .isExpected(link.isExpected())
+ .annotations(link.annotations())
+ .build());
}
return removeLink(src, dst);
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java b/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
index f24a662..cf46b15 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
@@ -361,11 +361,15 @@
// FIXME: this is not the right thing to call for the gossip store; will not sync link state!!!
return link.state() == INACTIVE ? null :
updateLink(linkKey(link.src(), link.dst()), link,
- new DefaultLink(link.providerId(),
- link.src(), link.dst(),
- link.type(), INACTIVE,
- link.isDurable(),
- link.annotations()));
+ DefaultLink.builder()
+ .providerId(link.providerId())
+ .src(link.src())
+ .dst(link.dst())
+ .type(link.type())
+ .state(INACTIVE)
+ .isExpected(link.isExpected())
+ .annotations(link.annotations())
+ .build());
}
return removeLink(src, dst);
}
@@ -605,7 +609,15 @@
}
boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
- return new DefaultLink(baseProviderId, src, dst, type, ACTIVE, isDurable, annotations);
+ return DefaultLink.builder()
+ .providerId(baseProviderId)
+ .src(src)
+ .dst(dst)
+ .type(type)
+ .state(ACTIVE)
+ .isExpected(isDurable)
+ .annotations(annotations)
+ .build();
}
private Map<ProviderId, Timestamped<LinkDescription>> getOrCreateLinkDescriptions(LinkKey key) {
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java
index 6cc9066..7c9231a 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/DefaultLinkSerializer.java
@@ -56,6 +56,13 @@
Type linkType = (Type) kryo.readClassAndObject(input);
State state = (State) kryo.readClassAndObject(input);
boolean isDurable = input.readBoolean();
- return new DefaultLink(providerId, src, dst, linkType, state, isDurable);
+ return DefaultLink.builder()
+ .providerId(providerId)
+ .src(src)
+ .dst(dst)
+ .type(linkType)
+ .state(state)
+ .isExpected(isDurable)
+ .build();
}
}
diff --git a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
index ec676bd..54690ea 100644
--- a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
+++ b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
@@ -183,8 +183,19 @@
@Test
public void testDefaultLink() {
- testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
- testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1));
+ testSerializedEquals(DefaultLink.builder()
+ .providerId(PID)
+ .src(CP1)
+ .dst(CP2)
+ .type(Link.Type.DIRECT)
+ .build());
+ testSerializedEquals(DefaultLink.builder()
+ .providerId(PID)
+ .src(CP1)
+ .dst(CP2)
+ .type(Link.Type.DIRECT)
+ .annotations(A1)
+ .build());
}
@Test
@@ -367,7 +378,9 @@
.addBandwidthRequest(32.195)
.build();
Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
- allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
+ allocations.put(DefaultLink.builder()
+ .providerId(PID)
+ .src(CP1).dst(CP2).type(Type.DIRECT).build(),
ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
new LambdaResourceAllocation(LambdaResource.valueOf(1))));
testSerializable(new DefaultLinkResourceAllocations(request, allocations));
diff --git a/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java b/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java
index 3d1549e..03642f4 100644
--- a/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java
+++ b/providers/ovsdb/tunnel/src/test/java/org/onosproject/ovsdb/provider/tunnel/OvsdbTunnelProviderTest.java
@@ -55,6 +55,13 @@
private final TestTunnelRegistry tunnelRegistry = new TestTunnelRegistry();
private TestTunnelProviderService providerService;
+ Link link = DefaultLink.builder()
+ .providerId(this.provider.id())
+ .src(ConnectPoint.deviceConnectPoint("192.168.2.3/20"))
+ .dst(ConnectPoint.deviceConnectPoint("192.168.2.4/30"))
+ .type(Link.Type.DIRECT)
+ .build();
+
@Before
public void setUp() {
provider.providerRegistry = tunnelRegistry;
@@ -75,11 +82,7 @@
.valueOf("192.168.1.3"));
SparseAnnotations annotations = DefaultAnnotations.builder()
.set("bandwidth", "1024").build();
- Link link = new DefaultLink(
- this.provider.id(),
- ConnectPoint.deviceConnectPoint("192.168.2.3/20"),
- ConnectPoint.deviceConnectPoint("192.168.2.4/30"),
- Link.Type.DIRECT);
+
List<Link> links = new ArrayList<Link>();
links.add(link);
TunnelDescription tunnel = new DefaultTunnelDescription(
@@ -104,11 +107,7 @@
.valueOf("192.168.1.3"));
SparseAnnotations annotations = DefaultAnnotations.builder()
.set("bandwidth", "1024").build();
- Link link = new DefaultLink(
- this.provider.id(),
- ConnectPoint.deviceConnectPoint("192.168.2.3/20"),
- ConnectPoint.deviceConnectPoint("192.168.2.4/30"),
- Link.Type.DIRECT);
+
List<Link> links = new ArrayList<Link>();
links.add(link);
TunnelDescription tunnel = new DefaultTunnelDescription(
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
index 648e500..d1bae5b 100644
--- a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
@@ -480,9 +480,12 @@
// Short-hand for creating a link.
private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) {
- return new DefaultLink(id(), connectPoint(src, sp), connectPoint(dst,
- dp),
- Link.Type.TUNNEL);
+ return DefaultLink.builder()
+ .providerId(id())
+ .src(connectPoint(src, sp))
+ .dst(connectPoint(dst, dp))
+ .type(Link.Type.TUNNEL)
+ .build();
}
// Creates a path that leads through the given devices.
@@ -1132,7 +1135,12 @@
} else {
IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress());
dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0));
- Link link = new DefaultLink(providerId, src, dst, Link.Type.DIRECT, EMPTY);
+ Link link = DefaultLink.builder()
+ .providerId(providerId)
+ .src(src)
+ .dst(dst)
+ .type(Link.Type.DIRECT)
+ .build();
links.add(link);
src = dst;
}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
index e386138..fe08778 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
@@ -84,7 +84,8 @@
ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
- Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
links.add(link);
path = new DefaultPath(pid, links, 20, EMPTY);
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
index ef4816e..0a84dce 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
@@ -80,7 +80,8 @@
ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
- Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
links.add(link);
path = new DefaultPath(pid, links, 10, EMPTY);
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
index 0fcd144..a4c7098 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
@@ -79,7 +79,8 @@
ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
- Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
links.add(link);
path = new DefaultPath(pid, links, 10, EMPTY);
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
index 1bcf99d..1a0f1b7 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
@@ -83,7 +83,8 @@
ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
- Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
links.add(link);
path = new DefaultPath(pid, links, 20, EMPTY);