Ray Milkey
Committed by Gerrit Code Review

Add a builder for DefaultLink to hide multiplying constructors

Change-Id: Iaf073d07989c398a8f44541ffdb8dd93e5715162
Showing 30 changed files with 363 additions and 88 deletions
...@@ -342,8 +342,13 @@ public class EcmpShortestPathGraph { ...@@ -342,8 +342,13 @@ public class EcmpShortestPathGraph {
342 342
343 private Link copyDefaultLink(Link link) { 343 private Link copyDefaultLink(Link link) {
344 DefaultLink src = (DefaultLink) link; 344 DefaultLink src = (DefaultLink) link;
345 - DefaultLink defaultLink = new DefaultLink(src.providerId(), src.src(), 345 + DefaultLink defaultLink = DefaultLink.builder()
346 - src.dst(), src.type(), src.annotations()); 346 + .providerId(src.providerId())
347 + .src(src.src())
348 + .dst(src.dst())
349 + .type(src.type())
350 + .annotations(src.annotations())
351 + .build();
347 352
348 return defaultLink; 353 return defaultLink;
349 } 354 }
......
...@@ -21,6 +21,9 @@ import java.util.Objects; ...@@ -21,6 +21,9 @@ import java.util.Objects;
21 21
22 import static com.google.common.base.MoreObjects.toStringHelper; 22 import static com.google.common.base.MoreObjects.toStringHelper;
23 import static org.onosproject.net.Link.State.ACTIVE; 23 import static org.onosproject.net.Link.State.ACTIVE;
24 +import static org.onosproject.net.DefaultAnnotations.EMPTY;
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
24 27
25 /** 28 /**
26 * Default infrastructure link model implementation. 29 * Default infrastructure link model implementation.
...@@ -42,7 +45,7 @@ public class DefaultLink extends AbstractModel implements Link { ...@@ -42,7 +45,7 @@ public class DefaultLink extends AbstractModel implements Link {
42 * @param type link type 45 * @param type link type
43 * @param annotations optional key/value annotations 46 * @param annotations optional key/value annotations
44 */ 47 */
45 - public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, 48 + protected DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
46 Type type, Annotations... annotations) { 49 Type type, Annotations... annotations) {
47 this(providerId, src, dst, type, ACTIVE, false, annotations); 50 this(providerId, src, dst, type, ACTIVE, false, annotations);
48 } 51 }
...@@ -60,7 +63,7 @@ public class DefaultLink extends AbstractModel implements Link { ...@@ -60,7 +63,7 @@ public class DefaultLink extends AbstractModel implements Link {
60 * @param isExpected indicates if the link is preconfigured 63 * @param isExpected indicates if the link is preconfigured
61 * @param annotations optional key/value annotations 64 * @param annotations optional key/value annotations
62 */ 65 */
63 - public DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, 66 + private DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst,
64 Type type, State state, 67 Type type, State state,
65 boolean isExpected, Annotations... annotations) { 68 boolean isExpected, Annotations... annotations) {
66 super(providerId, annotations); 69 super(providerId, annotations);
...@@ -129,8 +132,130 @@ public class DefaultLink extends AbstractModel implements Link { ...@@ -129,8 +132,130 @@ public class DefaultLink extends AbstractModel implements Link {
129 .add("dst", dst) 132 .add("dst", dst)
130 .add("type", type) 133 .add("type", type)
131 .add("state", state) 134 .add("state", state)
132 - .add("configured", isExpected) 135 + .add("expected", isExpected)
133 .toString(); 136 .toString();
134 } 137 }
135 138
139 + /**
140 + * Creates a new default link builder.
141 + *
142 + * @return default link builder
143 + */
144 + public static Builder builder() {
145 + return new Builder();
146 + }
147 +
148 + /**
149 + * Builder for DefaultLink objects.
150 + */
151 + public static final class Builder {
152 + private ProviderId providerId;
153 + private Annotations annotations = EMPTY;
154 + private ConnectPoint src;
155 + private ConnectPoint dst;
156 + private Type type;
157 + private State state = ACTIVE;
158 + private boolean isExpected = false;
159 +
160 + private Builder() {
161 + // Hide constructor
162 + }
163 +
164 + /**
165 + * Sets the providerId to be used by the builder.
166 + *
167 + * @param providerId new provider id
168 + * @return self
169 + */
170 + public Builder providerId(ProviderId providerId) {
171 + this.providerId = providerId;
172 + return this;
173 + }
174 +
175 + /**
176 + * Sets the annotations to be used by the builder.
177 + *
178 + * @param annotations new annotations
179 + * @return self
180 + */
181 + public Builder annotations(Annotations annotations) {
182 + this.annotations = annotations;
183 + return this;
184 + }
185 +
186 + /**
187 + * Sets the source connect point to be used by the builder.
188 + *
189 + * @param src source connect point
190 + * @return self
191 + */
192 + public Builder src(ConnectPoint src) {
193 + this.src = src;
194 + return this;
195 + }
196 +
197 + /**
198 + * Sets the destination connect point to be used by the builder.
199 + *
200 + * @param dst new destination connect point
201 + * @return self
202 + */
203 + public Builder dst(ConnectPoint dst) {
204 + this.dst = dst;
205 + return this;
206 + }
207 +
208 + /**
209 + * Sets the link type to be used by the builder.
210 + *
211 + * @param type new link type
212 + * @return self
213 + */
214 + public Builder type(Type type) {
215 + this.type = type;
216 + return this;
217 + }
218 +
219 + /**
220 + * Sets the link state to be used by the builder.
221 + *
222 + * @param state new link state
223 + * @return self
224 + */
225 + public Builder state(State state) {
226 + this.state = state;
227 + return this;
228 + }
229 +
230 + /**
231 + * Sets the expected flag to be used by the builder.
232 + *
233 + * @param isExpected new expected flag
234 + * @return self
235 + */
236 + public Builder isExpected(boolean isExpected) {
237 + this.isExpected = isExpected;
238 + return this;
239 + }
240 +
241 + /**
242 + * Builds a default link object from the accumulated parameters.
243 + *
244 + * @return default link object
245 + */
246 + public DefaultLink build() {
247 + checkNotNull(src, "Source connect point cannot be null");
248 + checkNotNull(dst, "Destination connect point cannot be null");
249 + checkNotNull(type, "Type cannot be null");
250 + checkNotNull(providerId, "Provider Id cannot be null");
251 +
252 + return new DefaultLink(providerId, src, dst,
253 + type, state,
254 + isExpected, annotations);
255 + }
256 +
257 + }
258 +
259 +
260 +
136 } 261 }
......
...@@ -51,8 +51,18 @@ public class PathIntentTest extends ConnectivityIntentTest { ...@@ -51,8 +51,18 @@ public class PathIntentTest extends ConnectivityIntentTest {
51 private final ConnectPoint cp2 = new ConnectPoint(device1, port2); 51 private final ConnectPoint cp2 = new ConnectPoint(device1, port2);
52 private final ConnectPoint cp3 = new ConnectPoint(device2, port3); 52 private final ConnectPoint cp3 = new ConnectPoint(device2, port3);
53 private final ConnectPoint cp4 = new ConnectPoint(device2, port4); 53 private final ConnectPoint cp4 = new ConnectPoint(device2, port4);
54 - private final DefaultLink link1 = new DefaultLink(provider1, cp1, cp2, DIRECT); 54 + private final DefaultLink link1 = DefaultLink.builder()
55 - private final DefaultLink link2 = new DefaultLink(provider1, cp1, cp2, DIRECT); 55 + .providerId(provider1)
56 + .src(cp1)
57 + .dst(cp2)
58 + .type(DIRECT)
59 + .build();
60 + private final DefaultLink link2 = DefaultLink.builder()
61 + .providerId(provider1)
62 + .src(cp1)
63 + .dst(cp2)
64 + .type(DIRECT)
65 + .build();
56 private final double cost = 1; 66 private final double cost = 1;
57 67
58 @Test 68 @Test
......
...@@ -59,7 +59,12 @@ public class AnnotationConstraintTest { ...@@ -59,7 +59,12 @@ public class AnnotationConstraintTest {
59 59
60 DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build(); 60 DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build();
61 61
62 - link = new DefaultLink(PID, cp(DID1, PID1), cp(DID2, PID2), DIRECT, annotations); 62 + link = DefaultLink.builder()
63 + .providerId(PID)
64 + .src(cp(DID1, PID1))
65 + .dst(cp(DID2, PID2))
66 + .type(DIRECT)
67 + .annotations(annotations).build();
63 } 68 }
64 69
65 /** 70 /**
......
...@@ -69,8 +69,20 @@ public class LatencyConstraintTest { ...@@ -69,8 +69,20 @@ public class LatencyConstraintTest {
69 Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build(); 69 Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
70 Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build(); 70 Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
71 71
72 - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1); 72 + link1 = DefaultLink.builder()
73 - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2); 73 + .providerId(PROVIDER_ID)
74 + .src(cp(DID1, PN1))
75 + .dst(cp(DID2, PN2))
76 + .type(DIRECT)
77 + .annotations(annotations1)
78 + .build();
79 + link2 = DefaultLink.builder()
80 + .providerId(PROVIDER_ID)
81 + .src(cp(DID2, PN3))
82 + .dst(cp(DID3, PN4))
83 + .type(DIRECT)
84 + .annotations(annotations2)
85 + .build();
74 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); 86 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
75 } 87 }
76 88
......
...@@ -62,8 +62,18 @@ public class ObstacleConstraintTest { ...@@ -62,8 +62,18 @@ public class ObstacleConstraintTest {
62 public void setUp() { 62 public void setUp() {
63 linkResourceService = createMock(LinkResourceService.class); 63 linkResourceService = createMock(LinkResourceService.class);
64 64
65 - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); 65 + link1 = DefaultLink.builder()
66 - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); 66 + .providerId(PROVIDER_ID)
67 + .src(cp(DID1, PN1))
68 + .dst(cp(DID2, PN2))
69 + .type(DIRECT)
70 + .build();
71 + link2 = DefaultLink.builder()
72 + .providerId(PROVIDER_ID)
73 + .src(cp(DID2, PN3))
74 + .dst(cp(DID3, PN4))
75 + .type(DIRECT)
76 + .build();
67 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); 77 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
68 } 78 }
69 79
......
...@@ -62,8 +62,19 @@ public class WaypointConstraintTest { ...@@ -62,8 +62,19 @@ public class WaypointConstraintTest {
62 public void setUp() { 62 public void setUp() {
63 linkResourceService = createMock(LinkResourceService.class); 63 linkResourceService = createMock(LinkResourceService.class);
64 64
65 - link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT); 65 + link1 = DefaultLink.builder()
66 - link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT); 66 + .providerId(PROVIDER_ID)
67 + .src(cp(DID1, PN1))
68 + .dst(cp(DID2, PN2))
69 + .type(DIRECT)
70 + .build();
71 + link2 = DefaultLink.builder()
72 + .providerId(PROVIDER_ID)
73 + .src(cp(DID2, PN3))
74 + .dst(cp(DID3, PN4))
75 + .type(DIRECT)
76 + .build();
77 +
67 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10); 78 path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), 10);
68 } 79 }
69 80
......
...@@ -31,10 +31,12 @@ import static org.onosproject.net.PortNumber.portNumber; ...@@ -31,10 +31,12 @@ import static org.onosproject.net.PortNumber.portNumber;
31 public class LinkEventTest extends AbstractEventTest { 31 public class LinkEventTest extends AbstractEventTest {
32 32
33 private Link createLink() { 33 private Link createLink() {
34 - return new DefaultLink(new ProviderId("of", "foo"), 34 + return DefaultLink.builder()
35 - new ConnectPoint(deviceId("of:foo"), portNumber(1)), 35 + .providerId(new ProviderId("of", "foo"))
36 - new ConnectPoint(deviceId("of:bar"), portNumber(2)), 36 + .src(new ConnectPoint(deviceId("of:foo"), portNumber(1)))
37 - Link.Type.INDIRECT); 37 + .dst(new ConnectPoint(deviceId("of:bar"), portNumber(2)))
38 + .type(Link.Type.INDIRECT)
39 + .build();
38 } 40 }
39 41
40 @Test 42 @Test
......
...@@ -49,9 +49,19 @@ public class DefaultTopologyEdgeTest { ...@@ -49,9 +49,19 @@ public class DefaultTopologyEdgeTest {
49 static final ProviderId PID = new ProviderId("foo", "bar"); 49 static final ProviderId PID = new ProviderId("foo", "bar");
50 50
51 /** D1:P1 -> D2:P1. */ 51 /** D1:P1 -> D2:P1. */
52 - static final Link L1 = new DefaultLink(PID, CP1, CP2, Link.Type.INDIRECT); 52 + static final Link L1 = DefaultLink.builder()
53 + .providerId(PID)
54 + .src(CP1)
55 + .dst(CP2)
56 + .type(Link.Type.INDIRECT)
57 + .build();
53 /** D2:P1 -> D1:P2. */ 58 /** D2:P1 -> D1:P2. */
54 - static final Link L2 = new DefaultLink(PID, CP3, CP4, Link.Type.INDIRECT); 59 + static final Link L2 = DefaultLink.builder()
60 + .providerId(PID)
61 + .src(CP3)
62 + .dst(CP4)
63 + .type(Link.Type.INDIRECT)
64 + .build();
55 65
56 @Test 66 @Test
57 public void basics() { 67 public void basics() {
......
...@@ -75,6 +75,13 @@ public final class LinkCodec extends AnnotatedCodec<Link> { ...@@ -75,6 +75,13 @@ public final class LinkCodec extends AnnotatedCodec<Link> {
75 Type type = Type.valueOf(json.get(TYPE).asText()); 75 Type type = Type.valueOf(json.get(TYPE).asText());
76 Annotations annotations = extractAnnotations(json, context); 76 Annotations annotations = extractAnnotations(json, context);
77 77
78 - return new DefaultLink(pid, src, dst, type, annotations); 78 + return DefaultLink
79 + .builder()
80 + .providerId(pid)
81 + .src(src)
82 + .dst(dst)
83 + .type(type)
84 + .annotations(annotations)
85 + .build();
79 } 86 }
80 } 87 }
......
...@@ -33,13 +33,15 @@ import org.onosproject.net.device.DeviceServiceAdapter; ...@@ -33,13 +33,15 @@ import org.onosproject.net.device.DeviceServiceAdapter;
33 */ 33 */
34 public class LinkCodecTest { 34 public class LinkCodecTest {
35 35
36 - private final Link link = new DefaultLink(JsonCodecUtils.PID, 36 + private final Link link = DefaultLink.builder()
37 - JsonCodecUtils.CP1, 37 + .providerId(JsonCodecUtils.PID)
38 - JsonCodecUtils.CP2, 38 + .src(JsonCodecUtils.CP1)
39 - Link.Type.DIRECT, 39 + .dst(JsonCodecUtils.CP2)
40 - Link.State.ACTIVE, 40 + .type(Link.Type.DIRECT)
41 - false, 41 + .state(Link.State.ACTIVE)
42 - JsonCodecUtils.A1); 42 + .isExpected(false)
43 + .annotations(JsonCodecUtils.A1)
44 + .build();
43 45
44 @Test 46 @Test
45 public void linkCodecTest() { 47 public void linkCodecTest() {
......
...@@ -122,9 +122,11 @@ public class DefaultTopologyTest { ...@@ -122,9 +122,11 @@ public class DefaultTopologyTest {
122 122
123 // Short-hand for creating a link. 123 // Short-hand for creating a link.
124 public static Link link(String src, int sp, String dst, int dp) { 124 public static Link link(String src, int sp, String dst, int dp) {
125 - return new DefaultLink(PID, new ConnectPoint(did(src), portNumber(sp)), 125 + return DefaultLink.builder().providerId(PID)
126 - new ConnectPoint(did(dst), portNumber(dp)), 126 + .src(new ConnectPoint(did(src), portNumber(sp)))
127 - Link.Type.DIRECT); 127 + .dst(new ConnectPoint(did(dst), portNumber(dp)))
128 + .type(Link.Type.DIRECT)
129 + .build();
128 } 130 }
129 131
130 // Crates a new device with the specified id 132 // Crates a new device with the specified id
......
...@@ -76,11 +76,13 @@ public class SimpleLinkResourceStoreTest { ...@@ -76,11 +76,13 @@ public class SimpleLinkResourceStoreTest {
76 .set(AnnotationKeys.OPTICAL_WAVES, "80") 76 .set(AnnotationKeys.OPTICAL_WAVES, "80")
77 .set(AnnotationKeys.BANDWIDTH, "1000") 77 .set(AnnotationKeys.BANDWIDTH, "1000")
78 .build(); 78 .build();
79 - return new DefaultLink( 79 + return DefaultLink.builder()
80 - new ProviderId("of", "foo"), 80 + .providerId(new ProviderId("of", "foo"))
81 - new ConnectPoint(deviceId(dev1), portNumber(port1)), 81 + .src(new ConnectPoint(deviceId(dev1), portNumber(port1)))
82 - new ConnectPoint(deviceId(dev2), portNumber(port2)), 82 + .dst(new ConnectPoint(deviceId(dev2), portNumber(port2)))
83 - DIRECT, annotations); 83 + .type(DIRECT)
84 + .annotations(annotations)
85 + .build();
84 } 86 }
85 87
86 @Before 88 @Before
......
...@@ -196,11 +196,14 @@ public class SimpleLinkStore ...@@ -196,11 +196,14 @@ public class SimpleLinkStore
196 if (link.isDurable()) { 196 if (link.isDurable()) {
197 return link.state() == INACTIVE ? null : 197 return link.state() == INACTIVE ? null :
198 updateLink(linkKey(link.src(), link.dst()), link, 198 updateLink(linkKey(link.src(), link.dst()), link,
199 - new DefaultLink(link.providerId(), 199 + DefaultLink.builder()
200 - link.src(), link.dst(), 200 + .providerId(link.providerId())
201 - link.type(), INACTIVE, 201 + .src(link.src())
202 - link.isDurable(), 202 + .dst(link.dst())
203 - link.annotations())); 203 + .type(link.type())
204 + .state(INACTIVE)
205 + .isExpected(link.isExpected())
206 + .annotations(link.annotations()).build());
204 } 207 }
205 return removeLink(src, dst); 208 return removeLink(src, dst);
206 } 209 }
...@@ -327,7 +330,15 @@ public class SimpleLinkStore ...@@ -327,7 +330,15 @@ public class SimpleLinkStore
327 } 330 }
328 331
329 boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true"); 332 boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
330 - return new DefaultLink(primary, src, dst, type, ACTIVE, isDurable, annotations); 333 + return DefaultLink.builder()
334 + .providerId(primary)
335 + .src(src)
336 + .dst(dst)
337 + .type(type)
338 + .state(ACTIVE)
339 + .isExpected(isDurable)
340 + .annotations(annotations)
341 + .build();
331 } 342 }
332 343
333 private Map<ProviderId, LinkDescription> getOrCreateLinkDescriptions(LinkKey key) { 344 private Map<ProviderId, LinkDescription> getOrCreateLinkDescriptions(LinkKey key) {
......
...@@ -88,8 +88,13 @@ public class HostToHostIntentCompiler ...@@ -88,8 +88,13 @@ public class HostToHostIntentCompiler
88 88
89 // Produces a reverse variant of the specified link. 89 // Produces a reverse variant of the specified link.
90 private Link reverseLink(Link link) { 90 private Link reverseLink(Link link) {
91 - return new DefaultLink(link.providerId(), link.dst(), link.src(), 91 + return DefaultLink.builder().providerId(link.providerId())
92 - link.type(), link.state(), link.isDurable()); 92 + .src(link.dst())
93 + .dst(link.src())
94 + .type(link.type())
95 + .state(link.state())
96 + .isExpected(link.isExpected())
97 + .build();
93 } 98 }
94 99
95 // Creates a path intent from the specified path and original connectivity intent. 100 // Creates a path intent from the specified path and original connectivity intent.
......
...@@ -65,9 +65,9 @@ public class LinkCollectionIntentCompilerTest { ...@@ -65,9 +65,9 @@ public class LinkCollectionIntentCompilerTest {
65 private final ConnectPoint d1p0 = connectPoint("s1", 10); 65 private final ConnectPoint d1p0 = connectPoint("s1", 10);
66 66
67 private final Set<Link> links = ImmutableSet.of( 67 private final Set<Link> links = ImmutableSet.of(
68 - new DefaultLink(PID, d1p1, d2p0, DIRECT), 68 + DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
69 - new DefaultLink(PID, d2p1, d3p1, DIRECT), 69 + DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
70 - new DefaultLink(PID, d1p1, d3p1, DIRECT)); 70 + DefaultLink.builder().providerId(PID).src(d1p1).dst(d3p1).type(DIRECT).build());
71 71
72 private final TrafficSelector selector = DefaultTrafficSelector.builder().build(); 72 private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
73 private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); 73 private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
......
...@@ -77,8 +77,8 @@ public class MplsPathIntentCompilerTest { ...@@ -77,8 +77,8 @@ public class MplsPathIntentCompilerTest {
77 77
78 private final List<Link> links = Arrays.asList( 78 private final List<Link> links = Arrays.asList(
79 createEdgeLink(d1pi, true), 79 createEdgeLink(d1pi, true),
80 - new DefaultLink(PID, d1p1, d2p0, DIRECT), 80 + DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
81 - new DefaultLink(PID, d2p1, d3p1, DIRECT), 81 + DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
82 createEdgeLink(d3pe, false) 82 createEdgeLink(d3pe, false)
83 ); 83 );
84 84
......
...@@ -64,8 +64,8 @@ public class OpticalPathIntentCompilerTest { ...@@ -64,8 +64,8 @@ public class OpticalPathIntentCompilerTest {
64 private final ConnectPoint d3p1 = connectPoint("s3", 1); 64 private final ConnectPoint d3p1 = connectPoint("s3", 1);
65 65
66 private final List<Link> links = Arrays.asList( 66 private final List<Link> links = Arrays.asList(
67 - new DefaultLink(PID, d1p1, d2p0, DIRECT), 67 + DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
68 - new DefaultLink(PID, d2p1, d3p1, DIRECT) 68 + DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build()
69 ); 69 );
70 private final int hops = links.size() + 1; 70 private final int hops = links.size() + 1;
71 private OpticalPathIntent intent; 71 private OpticalPathIntent intent;
......
...@@ -84,8 +84,8 @@ public class PathIntentCompilerTest { ...@@ -84,8 +84,8 @@ public class PathIntentCompilerTest {
84 84
85 private final List<Link> links = Arrays.asList( 85 private final List<Link> links = Arrays.asList(
86 createEdgeLink(d1p0, true), 86 createEdgeLink(d1p0, true),
87 - new DefaultLink(PID, d1p1, d2p0, DIRECT), 87 + DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
88 - new DefaultLink(PID, d2p1, d3p1, DIRECT), 88 + DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
89 createEdgeLink(d3p0, false) 89 createEdgeLink(d3p0, false)
90 ); 90 );
91 private final int hops = links.size() - 1; 91 private final int hops = links.size() - 1;
......
...@@ -70,7 +70,8 @@ public class CompilingTest { ...@@ -70,7 +70,8 @@ public class CompilingTest {
70 private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1)); 70 private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
71 private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2)); 71 private final ConnectPoint cp4 = new ConnectPoint(deviceId("2"), portNumber(2));
72 72
73 - private final List<Link> links = Collections.singletonList(new DefaultLink(pid, cp2, cp4, DIRECT)); 73 + private final List<Link> links = Collections.singletonList(
74 + DefaultLink.builder().providerId(pid).src(cp2).dst(cp4).type(DIRECT).build());
74 private final Path path = new DefaultPath(pid, links, 10); 75 private final Path path = new DefaultPath(pid, links, 10);
75 76
76 private PointToPointIntent input; 77 private PointToPointIntent input;
......
...@@ -317,7 +317,15 @@ public class ECLinkStore ...@@ -317,7 +317,15 @@ public class ECLinkStore
317 }); 317 });
318 318
319 boolean isDurable = Objects.equals(annotations.get().value(AnnotationKeys.DURABLE), "true"); 319 boolean isDurable = Objects.equals(annotations.get().value(AnnotationKeys.DURABLE), "true");
320 - return new DefaultLink(baseProviderId, src, dst, type, ACTIVE, isDurable, annotations.get()); 320 + return DefaultLink.builder()
321 + .providerId(baseProviderId)
322 + .src(src)
323 + .dst(dst)
324 + .type(type)
325 + .state(ACTIVE)
326 + .isExpected(isDurable)
327 + .annotations(annotations.get())
328 + .build();
321 } 329 }
322 330
323 // Updates, if necessary the specified link and returns the appropriate event. 331 // Updates, if necessary the specified link and returns the appropriate event.
...@@ -346,11 +354,15 @@ public class ECLinkStore ...@@ -346,11 +354,15 @@ public class ECLinkStore
346 // FIXME: this will not sync link state!!! 354 // FIXME: this will not sync link state!!!
347 return link.state() == INACTIVE ? null : 355 return link.state() == INACTIVE ? null :
348 updateLink(linkKey(link.src(), link.dst()), link, 356 updateLink(linkKey(link.src(), link.dst()), link,
349 - new DefaultLink(link.providerId(), 357 + DefaultLink.builder()
350 - link.src(), link.dst(), 358 + .providerId(link.providerId())
351 - link.type(), INACTIVE, 359 + .src(link.src())
352 - link.isDurable(), 360 + .dst(link.dst())
353 - link.annotations())); 361 + .type(link.type())
362 + .state(INACTIVE)
363 + .isExpected(link.isExpected())
364 + .annotations(link.annotations())
365 + .build());
354 } 366 }
355 return removeLink(src, dst); 367 return removeLink(src, dst);
356 } 368 }
......
...@@ -361,11 +361,15 @@ public class GossipLinkStore ...@@ -361,11 +361,15 @@ public class GossipLinkStore
361 // FIXME: this is not the right thing to call for the gossip store; will not sync link state!!! 361 // FIXME: this is not the right thing to call for the gossip store; will not sync link state!!!
362 return link.state() == INACTIVE ? null : 362 return link.state() == INACTIVE ? null :
363 updateLink(linkKey(link.src(), link.dst()), link, 363 updateLink(linkKey(link.src(), link.dst()), link,
364 - new DefaultLink(link.providerId(), 364 + DefaultLink.builder()
365 - link.src(), link.dst(), 365 + .providerId(link.providerId())
366 - link.type(), INACTIVE, 366 + .src(link.src())
367 - link.isDurable(), 367 + .dst(link.dst())
368 - link.annotations())); 368 + .type(link.type())
369 + .state(INACTIVE)
370 + .isExpected(link.isExpected())
371 + .annotations(link.annotations())
372 + .build());
369 } 373 }
370 return removeLink(src, dst); 374 return removeLink(src, dst);
371 } 375 }
...@@ -605,7 +609,15 @@ public class GossipLinkStore ...@@ -605,7 +609,15 @@ public class GossipLinkStore
605 } 609 }
606 610
607 boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true"); 611 boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
608 - return new DefaultLink(baseProviderId, src, dst, type, ACTIVE, isDurable, annotations); 612 + return DefaultLink.builder()
613 + .providerId(baseProviderId)
614 + .src(src)
615 + .dst(dst)
616 + .type(type)
617 + .state(ACTIVE)
618 + .isExpected(isDurable)
619 + .annotations(annotations)
620 + .build();
609 } 621 }
610 622
611 private Map<ProviderId, Timestamped<LinkDescription>> getOrCreateLinkDescriptions(LinkKey key) { 623 private Map<ProviderId, Timestamped<LinkDescription>> getOrCreateLinkDescriptions(LinkKey key) {
......
...@@ -56,6 +56,13 @@ public class DefaultLinkSerializer extends Serializer<DefaultLink> { ...@@ -56,6 +56,13 @@ public class DefaultLinkSerializer extends Serializer<DefaultLink> {
56 Type linkType = (Type) kryo.readClassAndObject(input); 56 Type linkType = (Type) kryo.readClassAndObject(input);
57 State state = (State) kryo.readClassAndObject(input); 57 State state = (State) kryo.readClassAndObject(input);
58 boolean isDurable = input.readBoolean(); 58 boolean isDurable = input.readBoolean();
59 - return new DefaultLink(providerId, src, dst, linkType, state, isDurable); 59 + return DefaultLink.builder()
60 + .providerId(providerId)
61 + .src(src)
62 + .dst(dst)
63 + .type(linkType)
64 + .state(state)
65 + .isExpected(isDurable)
66 + .build();
60 } 67 }
61 } 68 }
......
...@@ -183,8 +183,19 @@ public class KryoSerializerTest { ...@@ -183,8 +183,19 @@ public class KryoSerializerTest {
183 183
184 @Test 184 @Test
185 public void testDefaultLink() { 185 public void testDefaultLink() {
186 - testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT)); 186 + testSerializedEquals(DefaultLink.builder()
187 - testSerializedEquals(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT, A1)); 187 + .providerId(PID)
188 + .src(CP1)
189 + .dst(CP2)
190 + .type(Link.Type.DIRECT)
191 + .build());
192 + testSerializedEquals(DefaultLink.builder()
193 + .providerId(PID)
194 + .src(CP1)
195 + .dst(CP2)
196 + .type(Link.Type.DIRECT)
197 + .annotations(A1)
198 + .build());
188 } 199 }
189 200
190 @Test 201 @Test
...@@ -367,7 +378,9 @@ public class KryoSerializerTest { ...@@ -367,7 +378,9 @@ public class KryoSerializerTest {
367 .addBandwidthRequest(32.195) 378 .addBandwidthRequest(32.195)
368 .build(); 379 .build();
369 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); 380 Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
370 - allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT), 381 + allocations.put(DefaultLink.builder()
382 + .providerId(PID)
383 + .src(CP1).dst(CP2).type(Type.DIRECT).build(),
371 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))), 384 ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))),
372 new LambdaResourceAllocation(LambdaResource.valueOf(1)))); 385 new LambdaResourceAllocation(LambdaResource.valueOf(1))));
373 testSerializable(new DefaultLinkResourceAllocations(request, allocations)); 386 testSerializable(new DefaultLinkResourceAllocations(request, allocations));
......
...@@ -55,6 +55,13 @@ public class OvsdbTunnelProviderTest { ...@@ -55,6 +55,13 @@ public class OvsdbTunnelProviderTest {
55 private final TestTunnelRegistry tunnelRegistry = new TestTunnelRegistry(); 55 private final TestTunnelRegistry tunnelRegistry = new TestTunnelRegistry();
56 private TestTunnelProviderService providerService; 56 private TestTunnelProviderService providerService;
57 57
58 + Link link = DefaultLink.builder()
59 + .providerId(this.provider.id())
60 + .src(ConnectPoint.deviceConnectPoint("192.168.2.3/20"))
61 + .dst(ConnectPoint.deviceConnectPoint("192.168.2.4/30"))
62 + .type(Link.Type.DIRECT)
63 + .build();
64 +
58 @Before 65 @Before
59 public void setUp() { 66 public void setUp() {
60 provider.providerRegistry = tunnelRegistry; 67 provider.providerRegistry = tunnelRegistry;
...@@ -75,11 +82,7 @@ public class OvsdbTunnelProviderTest { ...@@ -75,11 +82,7 @@ public class OvsdbTunnelProviderTest {
75 .valueOf("192.168.1.3")); 82 .valueOf("192.168.1.3"));
76 SparseAnnotations annotations = DefaultAnnotations.builder() 83 SparseAnnotations annotations = DefaultAnnotations.builder()
77 .set("bandwidth", "1024").build(); 84 .set("bandwidth", "1024").build();
78 - Link link = new DefaultLink( 85 +
79 - this.provider.id(),
80 - ConnectPoint.deviceConnectPoint("192.168.2.3/20"),
81 - ConnectPoint.deviceConnectPoint("192.168.2.4/30"),
82 - Link.Type.DIRECT);
83 List<Link> links = new ArrayList<Link>(); 86 List<Link> links = new ArrayList<Link>();
84 links.add(link); 87 links.add(link);
85 TunnelDescription tunnel = new DefaultTunnelDescription( 88 TunnelDescription tunnel = new DefaultTunnelDescription(
...@@ -104,11 +107,7 @@ public class OvsdbTunnelProviderTest { ...@@ -104,11 +107,7 @@ public class OvsdbTunnelProviderTest {
104 .valueOf("192.168.1.3")); 107 .valueOf("192.168.1.3"));
105 SparseAnnotations annotations = DefaultAnnotations.builder() 108 SparseAnnotations annotations = DefaultAnnotations.builder()
106 .set("bandwidth", "1024").build(); 109 .set("bandwidth", "1024").build();
107 - Link link = new DefaultLink( 110 +
108 - this.provider.id(),
109 - ConnectPoint.deviceConnectPoint("192.168.2.3/20"),
110 - ConnectPoint.deviceConnectPoint("192.168.2.4/30"),
111 - Link.Type.DIRECT);
112 List<Link> links = new ArrayList<Link>(); 111 List<Link> links = new ArrayList<Link>();
113 links.add(link); 112 links.add(link);
114 TunnelDescription tunnel = new DefaultTunnelDescription( 113 TunnelDescription tunnel = new DefaultTunnelDescription(
......
...@@ -480,9 +480,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -480,9 +480,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
480 480
481 // Short-hand for creating a link. 481 // Short-hand for creating a link.
482 private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) { 482 private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) {
483 - return new DefaultLink(id(), connectPoint(src, sp), connectPoint(dst, 483 + return DefaultLink.builder()
484 - dp), 484 + .providerId(id())
485 - Link.Type.TUNNEL); 485 + .src(connectPoint(src, sp))
486 + .dst(connectPoint(dst, dp))
487 + .type(Link.Type.TUNNEL)
488 + .build();
486 } 489 }
487 490
488 // Creates a path that leads through the given devices. 491 // Creates a path that leads through the given devices.
...@@ -1132,7 +1135,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1132,7 +1135,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1132 } else { 1135 } else {
1133 IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); 1136 IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress());
1134 dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0)); 1137 dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0));
1135 - Link link = new DefaultLink(providerId, src, dst, Link.Type.DIRECT, EMPTY); 1138 + Link link = DefaultLink.builder()
1139 + .providerId(providerId)
1140 + .src(src)
1141 + .dst(dst)
1142 + .type(Link.Type.DIRECT)
1143 + .build();
1136 links.add(link); 1144 links.add(link);
1137 src = dst; 1145 src = dst;
1138 } 1146 }
......
...@@ -84,7 +84,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -84,7 +84,8 @@ public class PcepReleaseTunnelProviderTest {
84 84
85 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 85 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
86 86
87 - Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); 87 + Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
88 + .type(Link.Type.DIRECT).build();
88 links.add(link); 89 links.add(link);
89 90
90 path = new DefaultPath(pid, links, 20, EMPTY); 91 path = new DefaultPath(pid, links, 20, EMPTY);
......
...@@ -80,7 +80,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -80,7 +80,8 @@ public class PcepSetupTunnelProviderTest {
80 80
81 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 81 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
82 82
83 - Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); 83 + Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
84 + .type(Link.Type.DIRECT).build();
84 links.add(link); 85 links.add(link);
85 86
86 path = new DefaultPath(pid, links, 10, EMPTY); 87 path = new DefaultPath(pid, links, 10, EMPTY);
......
...@@ -79,7 +79,8 @@ public class PcepTunnelProviderTest { ...@@ -79,7 +79,8 @@ public class PcepTunnelProviderTest {
79 79
80 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 80 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
81 81
82 - Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); 82 + Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
83 + .type(Link.Type.DIRECT).build();
83 links.add(link); 84 links.add(link);
84 85
85 path = new DefaultPath(pid, links, 10, EMPTY); 86 path = new DefaultPath(pid, links, 10, EMPTY);
......
...@@ -83,7 +83,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -83,7 +83,8 @@ public class PcepUpdateTunnelProviderTest {
83 83
84 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 84 ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
85 85
86 - Link link = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY); 86 + Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
87 + .type(Link.Type.DIRECT).build();
87 links.add(link); 88 links.add(link);
88 89
89 path = new DefaultPath(pid, links, 20, EMPTY); 90 path = new DefaultPath(pid, links, 20, EMPTY);
......