Committed by
Gerrit Code Review
Implement builders for optical intents
Change-Id: Ide728a943eb0ec3d3ba995f63c016e7d52bff65c
Showing
6 changed files
with
208 additions
and
44 deletions
| ... | @@ -286,12 +286,16 @@ public class OpticalPathProvisioner { | ... | @@ -286,12 +286,16 @@ public class OpticalPathProvisioner { |
| 286 | break; | 286 | break; |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | - Intent opticalIntent = new OpticalConnectivityIntent(appId, | 289 | + Intent opticalIntent = OpticalConnectivityIntent.builder() |
| 290 | - srcWdmPoint, | 290 | + .appId(appId) |
| 291 | - dstWdmPoint); | 291 | + .src(srcWdmPoint) |
| 292 | - Intent opticalIntent2 = new OpticalConnectivityIntent(appId, | 292 | + .dst(dstWdmPoint) |
| 293 | - dstWdmPoint, | 293 | + .build(); |
| 294 | - srcWdmPoint); | 294 | + Intent opticalIntent2 = OpticalConnectivityIntent.builder() |
| 295 | + .appId(appId) | ||
| 296 | + .src(dstWdmPoint) | ||
| 297 | + .dst(srcWdmPoint) | ||
| 298 | + .build(); | ||
| 295 | log.info("Creating optical intent from {} to {}", srcWdmPoint, dstWdmPoint); | 299 | log.info("Creating optical intent from {} to {}", srcWdmPoint, dstWdmPoint); |
| 296 | log.info("Creating optical intent from {} to {}", dstWdmPoint, srcWdmPoint); | 300 | log.info("Creating optical intent from {} to {}", dstWdmPoint, srcWdmPoint); |
| 297 | connectionList.add(opticalIntent); | 301 | connectionList.add(opticalIntent); | ... | ... |
| ... | @@ -56,7 +56,12 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { | ... | @@ -56,7 +56,12 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { |
| 56 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); | 56 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
| 57 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 57 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 58 | 58 | ||
| 59 | - Intent intent = new OpticalConnectivityIntent(appId(), key(), ingress, egress); | 59 | + Intent intent = OpticalConnectivityIntent.builder() |
| 60 | + .appId(appId()) | ||
| 61 | + .key(key()) | ||
| 62 | + .src(ingress) | ||
| 63 | + .dst(egress) | ||
| 64 | + .build(); | ||
| 60 | service.submit(intent); | 65 | service.submit(intent); |
| 61 | print("Optical intent submitted:\n%s", intent.toString()); | 66 | print("Optical intent submitted:\n%s", intent.toString()); |
| 62 | } | 67 | } | ... | ... |
| ... | @@ -15,10 +15,12 @@ | ... | @@ -15,10 +15,12 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | +import java.util.Collections; | ||
| 19 | + | ||
| 18 | import org.onosproject.core.ApplicationId; | 20 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.ConnectPoint; | 21 | import org.onosproject.net.ConnectPoint; |
| 20 | 22 | ||
| 21 | -import java.util.Collections; | 23 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
| 24 | * An optical layer intent for connectivity from one transponder port to another | 26 | * An optical layer intent for connectivity from one transponder port to another |
| ... | @@ -33,34 +35,92 @@ public final class OpticalConnectivityIntent extends Intent { | ... | @@ -33,34 +35,92 @@ public final class OpticalConnectivityIntent extends Intent { |
| 33 | * connection points. | 35 | * connection points. |
| 34 | * | 36 | * |
| 35 | * @param appId application identification | 37 | * @param appId application identification |
| 38 | + * @param key intent key | ||
| 36 | * @param src the source transponder port | 39 | * @param src the source transponder port |
| 37 | * @param dst the destination transponder port | 40 | * @param dst the destination transponder port |
| 38 | */ | 41 | */ |
| 39 | - public OpticalConnectivityIntent(ApplicationId appId, | 42 | + protected OpticalConnectivityIntent(ApplicationId appId, |
| 40 | - ConnectPoint src, ConnectPoint dst) { | 43 | + Key key, |
| 41 | - | 44 | + ConnectPoint src, |
| 42 | - this(appId, null, src, dst); | 45 | + ConnectPoint dst, |
| 46 | + int priority) { | ||
| 47 | + super(appId, key, Collections.emptyList(), priority); | ||
| 48 | + this.src = checkNotNull(src); | ||
| 49 | + this.dst = checkNotNull(dst); | ||
| 43 | } | 50 | } |
| 44 | 51 | ||
| 45 | /** | 52 | /** |
| 46 | - * Creates an optical connectivity intent between the specified | 53 | + * Returns a new optical connectivity intent builder. |
| 47 | - * connection points. | ||
| 48 | * | 54 | * |
| 49 | - * @param appId application identification | 55 | + * @return host to host intent builder |
| 50 | - * @param key intent key | ||
| 51 | - * @param src the source transponder port | ||
| 52 | - * @param dst the destination transponder port | ||
| 53 | */ | 56 | */ |
| 54 | - public OpticalConnectivityIntent(ApplicationId appId, | 57 | + public static Builder builder() { |
| 55 | - Key key, | 58 | + return new Builder(); |
| 56 | - ConnectPoint src, ConnectPoint dst) { | ||
| 57 | - super(appId, key, Collections.emptyList(), DEFAULT_INTENT_PRIORITY); | ||
| 58 | - this.src = src; | ||
| 59 | - this.dst = dst; | ||
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | 61 | ||
| 63 | /** | 62 | /** |
| 63 | + * Builder for optical connectivity intents. | ||
| 64 | + */ | ||
| 65 | + public static class Builder extends Intent.Builder { | ||
| 66 | + private ConnectPoint src; | ||
| 67 | + private ConnectPoint dst; | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public Builder appId(ApplicationId appId) { | ||
| 71 | + return (Builder) super.appId(appId); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public Builder key(Key key) { | ||
| 76 | + return (Builder) super.key(key); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public Builder priority(int priority) { | ||
| 81 | + return (Builder) super.priority(priority); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * Sets the source for the intent that will be built. | ||
| 86 | + * | ||
| 87 | + * @param src source to use for built intent | ||
| 88 | + * @return this builder | ||
| 89 | + */ | ||
| 90 | + public Builder src(ConnectPoint src) { | ||
| 91 | + this.src = src; | ||
| 92 | + return this; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Sets the destination for the intent that will be built. | ||
| 97 | + * | ||
| 98 | + * @param dst dest to use for built intent | ||
| 99 | + * @return this builder | ||
| 100 | + */ | ||
| 101 | + public Builder dst(ConnectPoint dst) { | ||
| 102 | + this.dst = dst; | ||
| 103 | + return this; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /** | ||
| 107 | + * Builds an optical connectivity intent from the accumulated parameters. | ||
| 108 | + * | ||
| 109 | + * @return point to point intent | ||
| 110 | + */ | ||
| 111 | + public OpticalConnectivityIntent build() { | ||
| 112 | + | ||
| 113 | + return new OpticalConnectivityIntent( | ||
| 114 | + appId, | ||
| 115 | + key, | ||
| 116 | + src, | ||
| 117 | + dst, | ||
| 118 | + priority | ||
| 119 | + ); | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 64 | * Constructor for serializer. | 124 | * Constructor for serializer. |
| 65 | */ | 125 | */ |
| 66 | protected OpticalConnectivityIntent() { | 126 | protected OpticalConnectivityIntent() { | ... | ... |
| ... | @@ -15,14 +15,15 @@ | ... | @@ -15,14 +15,15 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | -import com.google.common.base.MoreObjects; | 18 | +import java.util.Collection; |
| 19 | -import com.google.common.collect.ImmutableSet; | 19 | + |
| 20 | import org.onosproject.core.ApplicationId; | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.ConnectPoint; | 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
| 23 | import org.onosproject.net.Path; | 23 | import org.onosproject.net.Path; |
| 24 | 24 | ||
| 25 | -import java.util.Collection; | 25 | +import com.google.common.base.MoreObjects; |
| 26 | +import com.google.common.collect.ImmutableSet; | ||
| 26 | 27 | ||
| 27 | import static com.google.common.base.Preconditions.checkNotNull; | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | 29 | ||
| ... | @@ -33,12 +34,16 @@ public final class OpticalPathIntent extends Intent { | ... | @@ -33,12 +34,16 @@ public final class OpticalPathIntent extends Intent { |
| 33 | private final Path path; | 34 | private final Path path; |
| 34 | 35 | ||
| 35 | 36 | ||
| 36 | - public OpticalPathIntent(ApplicationId appId, | 37 | + private OpticalPathIntent(ApplicationId appId, |
| 37 | - ConnectPoint src, | 38 | + Key key, |
| 38 | - ConnectPoint dst, | 39 | + ConnectPoint src, |
| 39 | - Path path) { | 40 | + ConnectPoint dst, |
| 40 | - super(appId, null, ImmutableSet.copyOf(path.links()), | 41 | + Path path, |
| 41 | - Intent.DEFAULT_INTENT_PRIORITY); | 42 | + int priority) { |
| 43 | + super(appId, | ||
| 44 | + key, | ||
| 45 | + ImmutableSet.copyOf(path.links()), | ||
| 46 | + priority); | ||
| 42 | this.src = checkNotNull(src); | 47 | this.src = checkNotNull(src); |
| 43 | this.dst = checkNotNull(dst); | 48 | this.dst = checkNotNull(dst); |
| 44 | this.path = checkNotNull(path); | 49 | this.path = checkNotNull(path); |
| ... | @@ -50,6 +55,92 @@ public final class OpticalPathIntent extends Intent { | ... | @@ -50,6 +55,92 @@ public final class OpticalPathIntent extends Intent { |
| 50 | this.path = null; | 55 | this.path = null; |
| 51 | } | 56 | } |
| 52 | 57 | ||
| 58 | + /** | ||
| 59 | + * Returns a new optical connectivity intent builder. | ||
| 60 | + * | ||
| 61 | + * @return host to host intent builder | ||
| 62 | + */ | ||
| 63 | + public static Builder builder() { | ||
| 64 | + return new Builder(); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Builder for optical path intents. | ||
| 70 | + */ | ||
| 71 | + public static class Builder extends Intent.Builder { | ||
| 72 | + private ConnectPoint src; | ||
| 73 | + private ConnectPoint dst; | ||
| 74 | + private Path path; | ||
| 75 | + Key key; | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public Builder appId(ApplicationId appId) { | ||
| 79 | + return (Builder) super.appId(appId); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public Builder key(Key key) { | ||
| 84 | + return (Builder) super.key(key); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public Builder priority(int priority) { | ||
| 89 | + return (Builder) super.priority(priority); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Sets the source for the intent that will be built. | ||
| 94 | + * | ||
| 95 | + * @param src source to use for built intent | ||
| 96 | + * @return this builder | ||
| 97 | + */ | ||
| 98 | + public Builder src(ConnectPoint src) { | ||
| 99 | + this.src = src; | ||
| 100 | + return this; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Sets the destination for the intent that will be built. | ||
| 105 | + * | ||
| 106 | + * @param dst dest to use for built intent | ||
| 107 | + * @return this builder | ||
| 108 | + */ | ||
| 109 | + public Builder dst(ConnectPoint dst) { | ||
| 110 | + this.dst = dst; | ||
| 111 | + return this; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Sets the path for the intent that will be built. | ||
| 116 | + * | ||
| 117 | + * @param path path to use for built intent | ||
| 118 | + * @return this builder | ||
| 119 | + */ | ||
| 120 | + public Builder path(Path path) { | ||
| 121 | + this.path = path; | ||
| 122 | + return this; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * Builds an optical path intent from the accumulated parameters. | ||
| 127 | + * | ||
| 128 | + * @return optical path intent | ||
| 129 | + */ | ||
| 130 | + public OpticalPathIntent build() { | ||
| 131 | + | ||
| 132 | + return new OpticalPathIntent( | ||
| 133 | + appId, | ||
| 134 | + key, | ||
| 135 | + src, | ||
| 136 | + dst, | ||
| 137 | + path, | ||
| 138 | + priority | ||
| 139 | + ); | ||
| 140 | + } | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + | ||
| 53 | public ConnectPoint src() { | 144 | public ConnectPoint src() { |
| 54 | return src; | 145 | return src; |
| 55 | } | 146 | } | ... | ... |
| ... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent.impl.compiler; | 16 | package org.onosproject.net.intent.impl.compiler; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.ImmutableList; | 18 | +import java.util.List; |
| 19 | +import java.util.Set; | ||
| 20 | + | ||
| 19 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -36,8 +38,7 @@ import org.onosproject.net.topology.Topology; | ... | @@ -36,8 +38,7 @@ import org.onosproject.net.topology.Topology; |
| 36 | import org.onosproject.net.topology.TopologyEdge; | 38 | import org.onosproject.net.topology.TopologyEdge; |
| 37 | import org.onosproject.net.topology.TopologyService; | 39 | import org.onosproject.net.topology.TopologyService; |
| 38 | 40 | ||
| 39 | -import java.util.List; | 41 | +import com.google.common.collect.ImmutableList; |
| 40 | -import java.util.Set; | ||
| 41 | 42 | ||
| 42 | /** | 43 | /** |
| 43 | * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. | 44 | * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. |
| ... | @@ -67,10 +68,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -67,10 +68,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
| 67 | Set<LinkResourceAllocations> resources) { | 68 | Set<LinkResourceAllocations> resources) { |
| 68 | // TODO: compute multiple paths using the K-shortest path algorithm | 69 | // TODO: compute multiple paths using the K-shortest path algorithm |
| 69 | Path path = calculateOpticalPath(intent.getSrc(), intent.getDst()); | 70 | Path path = calculateOpticalPath(intent.getSrc(), intent.getDst()); |
| 70 | - Intent newIntent = new OpticalPathIntent(intent.appId(), | 71 | + Intent newIntent = OpticalPathIntent.builder() |
| 71 | - intent.getSrc(), | 72 | + .appId(intent.appId()) |
| 72 | - intent.getDst(), | 73 | + .src(intent.getSrc()) |
| 73 | - path); | 74 | + .dst(intent.getDst()) |
| 75 | + .path(path) | ||
| 76 | + .build(); | ||
| 74 | return ImmutableList.of(newIntent); | 77 | return ImmutableList.of(newIntent); |
| 75 | } | 78 | } |
| 76 | 79 | ... | ... |
core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
| ... | @@ -57,10 +57,11 @@ public class OpticalPathIntentInstallerTest extends IntentInstallerTest { | ... | @@ -57,10 +57,11 @@ public class OpticalPathIntentInstallerTest extends IntentInstallerTest { |
| 57 | new IntentInstallerTest.MockIntentManager(OpticalPathIntent.class); | 57 | new IntentInstallerTest.MockIntentManager(OpticalPathIntent.class); |
| 58 | installer.resourceService = new IntentTestsMocks.MockResourceService(); | 58 | installer.resourceService = new IntentTestsMocks.MockResourceService(); |
| 59 | 59 | ||
| 60 | - intent = new OpticalPathIntent(APP_ID, | 60 | + intent = OpticalPathIntent.builder().appId(APP_ID) |
| 61 | - d1p1, | 61 | + .src(d1p1) |
| 62 | - d3p1, | 62 | + .dst(d3p1) |
| 63 | - new DefaultPath(PID, links, hops)); | 63 | + .path(new DefaultPath(PID, links, hops)) |
| 64 | + .build(); | ||
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | /** | 67 | /** | ... | ... |
-
Please register or login to post a comment