Committed by
Brian O'Connor
[Cardinal] Add builders for Intents and remove extra constructors.
Starting with PointToPoint intent to see how it looks Change-Id: I5366a05d657ceaad18c03b95cd71f5d1107200e2
Showing
18 changed files
with
437 additions
and
163 deletions
| ... | @@ -324,11 +324,15 @@ public class IntentPerfInstaller { | ... | @@ -324,11 +324,15 @@ public class IntentPerfInstaller { |
| 324 | ConnectPoint ingress = new ConnectPoint(device.id(), PortNumber.portNumber(1)); | 324 | ConnectPoint ingress = new ConnectPoint(device.id(), PortNumber.portNumber(1)); |
| 325 | ConnectPoint egress = new ConnectPoint(device.id(), PortNumber.portNumber(2)); | 325 | ConnectPoint egress = new ConnectPoint(device.id(), PortNumber.portNumber(2)); |
| 326 | 326 | ||
| 327 | - return new PointToPointIntent(appId, key, | 327 | + return PointToPointIntent.builder() |
| 328 | - selector, treatment, | 328 | + .appId(appId) |
| 329 | - ingress, egress, | 329 | + .key(key) |
| 330 | - Collections.emptyList(), | 330 | + .selector(selector) |
| 331 | - Intent.DEFAULT_INTENT_PRIORITY); | 331 | + .treatment(treatment) |
| 332 | + .ingressPoint(ingress) | ||
| 333 | + .egressPoint(egress) | ||
| 334 | + .build(); | ||
| 335 | + | ||
| 332 | } | 336 | } |
| 333 | 337 | ||
| 334 | /** | 338 | /** | ... | ... |
| ... | @@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory; |
| 37 | 37 | ||
| 38 | import java.util.ArrayList; | 38 | import java.util.ArrayList; |
| 39 | import java.util.Collection; | 39 | import java.util.Collection; |
| 40 | -import java.util.Collections; | ||
| 41 | import java.util.List; | 40 | import java.util.List; |
| 42 | 41 | ||
| 43 | /** | 42 | /** |
| ... | @@ -192,11 +191,14 @@ public class PeerConnectivityManager { | ... | @@ -192,11 +191,14 @@ public class PeerConnectivityManager { |
| 192 | 191 | ||
| 193 | int priority = PRIORITY_OFFSET; | 192 | int priority = PRIORITY_OFFSET; |
| 194 | 193 | ||
| 195 | - intents.add(new PointToPointIntent(appId, selector, treatment, | 194 | + intents.add(PointToPointIntent.builder() |
| 196 | - bgpdConnectPoint, | 195 | + .appId(appId) |
| 197 | - bgpdPeerConnectPoint, | 196 | + .selector(selector) |
| 198 | - Collections.emptyList(), | 197 | + .treatment(treatment) |
| 199 | - priority)); | 198 | + .ingressPoint(bgpdConnectPoint) |
| 199 | + .egressPoint(bgpdPeerConnectPoint) | ||
| 200 | + .priority(priority) | ||
| 201 | + .build()); | ||
| 200 | 202 | ||
| 201 | // Path from BGP speaker to BGP peer matching source TCP port 179 | 203 | // Path from BGP speaker to BGP peer matching source TCP port 179 |
| 202 | selector = buildSelector(tcpProtocol, | 204 | selector = buildSelector(tcpProtocol, |
| ... | @@ -205,11 +207,14 @@ public class PeerConnectivityManager { | ... | @@ -205,11 +207,14 @@ public class PeerConnectivityManager { |
| 205 | BGP_PORT, | 207 | BGP_PORT, |
| 206 | null); | 208 | null); |
| 207 | 209 | ||
| 208 | - intents.add(new PointToPointIntent(appId, selector, treatment, | 210 | + intents.add(PointToPointIntent.builder() |
| 209 | - bgpdConnectPoint, | 211 | + .appId(appId) |
| 210 | - bgpdPeerConnectPoint, | 212 | + .selector(selector) |
| 211 | - Collections.emptyList(), | 213 | + .treatment(treatment) |
| 212 | - priority)); | 214 | + .ingressPoint(bgpdConnectPoint) |
| 215 | + .egressPoint(bgpdPeerConnectPoint) | ||
| 216 | + .priority(priority) | ||
| 217 | + .build()); | ||
| 213 | 218 | ||
| 214 | // Path from BGP peer to BGP speaker matching destination TCP port 179 | 219 | // Path from BGP peer to BGP speaker matching destination TCP port 179 |
| 215 | selector = buildSelector(tcpProtocol, | 220 | selector = buildSelector(tcpProtocol, |
| ... | @@ -218,11 +223,14 @@ public class PeerConnectivityManager { | ... | @@ -218,11 +223,14 @@ public class PeerConnectivityManager { |
| 218 | null, | 223 | null, |
| 219 | BGP_PORT); | 224 | BGP_PORT); |
| 220 | 225 | ||
| 221 | - intents.add(new PointToPointIntent(appId, selector, treatment, | 226 | + intents.add(PointToPointIntent.builder() |
| 222 | - bgpdPeerConnectPoint, | 227 | + .appId(appId) |
| 223 | - bgpdConnectPoint, | 228 | + .selector(selector) |
| 224 | - Collections.emptyList(), | 229 | + .treatment(treatment) |
| 225 | - priority)); | 230 | + .ingressPoint(bgpdPeerConnectPoint) |
| 231 | + .egressPoint(bgpdConnectPoint) | ||
| 232 | + .priority(priority) | ||
| 233 | + .build()); | ||
| 226 | 234 | ||
| 227 | // Path from BGP peer to BGP speaker matching source TCP port 179 | 235 | // Path from BGP peer to BGP speaker matching source TCP port 179 |
| 228 | selector = buildSelector(tcpProtocol, | 236 | selector = buildSelector(tcpProtocol, |
| ... | @@ -231,11 +239,14 @@ public class PeerConnectivityManager { | ... | @@ -231,11 +239,14 @@ public class PeerConnectivityManager { |
| 231 | BGP_PORT, | 239 | BGP_PORT, |
| 232 | null); | 240 | null); |
| 233 | 241 | ||
| 234 | - intents.add(new PointToPointIntent(appId, selector, treatment, | 242 | + intents.add(PointToPointIntent.builder() |
| 235 | - bgpdPeerConnectPoint, | 243 | + .appId(appId) |
| 236 | - bgpdConnectPoint, | 244 | + .selector(selector) |
| 237 | - Collections.emptyList(), | 245 | + .treatment(treatment) |
| 238 | - priority)); | 246 | + .ingressPoint(bgpdPeerConnectPoint) |
| 247 | + .egressPoint(bgpdConnectPoint) | ||
| 248 | + .priority(priority) | ||
| 249 | + .build()); | ||
| 239 | 250 | ||
| 240 | // ICMP path from BGP speaker to BGP peer | 251 | // ICMP path from BGP speaker to BGP peer |
| 241 | selector = buildSelector(icmpProtocol, | 252 | selector = buildSelector(icmpProtocol, |
| ... | @@ -244,11 +255,14 @@ public class PeerConnectivityManager { | ... | @@ -244,11 +255,14 @@ public class PeerConnectivityManager { |
| 244 | null, | 255 | null, |
| 245 | null); | 256 | null); |
| 246 | 257 | ||
| 247 | - intents.add(new PointToPointIntent(appId, selector, treatment, | 258 | + intents.add(PointToPointIntent.builder() |
| 248 | - bgpdConnectPoint, | 259 | + .appId(appId) |
| 249 | - bgpdPeerConnectPoint, | 260 | + .selector(selector) |
| 250 | - Collections.emptyList(), | 261 | + .treatment(treatment) |
| 251 | - priority)); | 262 | + .ingressPoint(bgpdConnectPoint) |
| 263 | + .egressPoint(bgpdPeerConnectPoint) | ||
| 264 | + .priority(priority) | ||
| 265 | + .build()); | ||
| 252 | 266 | ||
| 253 | // ICMP path from BGP peer to BGP speaker | 267 | // ICMP path from BGP peer to BGP speaker |
| 254 | selector = buildSelector(icmpProtocol, | 268 | selector = buildSelector(icmpProtocol, |
| ... | @@ -257,11 +271,14 @@ public class PeerConnectivityManager { | ... | @@ -257,11 +271,14 @@ public class PeerConnectivityManager { |
| 257 | null, | 271 | null, |
| 258 | null); | 272 | null); |
| 259 | 273 | ||
| 260 | - intents.add(new PointToPointIntent(appId, selector, treatment, | 274 | + intents.add(PointToPointIntent.builder() |
| 261 | - bgpdPeerConnectPoint, | 275 | + .appId(appId) |
| 262 | - bgpdConnectPoint, | 276 | + .selector(selector) |
| 263 | - Collections.emptyList(), | 277 | + .treatment(treatment) |
| 264 | - priority)); | 278 | + .ingressPoint(bgpdPeerConnectPoint) |
| 279 | + .egressPoint(bgpdConnectPoint) | ||
| 280 | + .priority(priority) | ||
| 281 | + .build()); | ||
| 265 | 282 | ||
| 266 | return intents; | 283 | return intents; |
| 267 | } | 284 | } | ... | ... |
| ... | @@ -15,7 +15,13 @@ | ... | @@ -15,7 +15,13 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.Sets; | 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Collections; | ||
| 20 | +import java.util.HashMap; | ||
| 21 | +import java.util.LinkedList; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Map; | ||
| 24 | + | ||
| 19 | import org.junit.Before; | 25 | import org.junit.Before; |
| 20 | import org.junit.Ignore; | 26 | import org.junit.Ignore; |
| 21 | import org.junit.Test; | 27 | import org.junit.Test; |
| ... | @@ -46,14 +52,13 @@ import org.onosproject.routing.config.Interface; | ... | @@ -46,14 +52,13 @@ import org.onosproject.routing.config.Interface; |
| 46 | import org.onosproject.routing.config.InterfaceAddress; | 52 | import org.onosproject.routing.config.InterfaceAddress; |
| 47 | import org.onosproject.routing.config.RoutingConfigurationService; | 53 | import org.onosproject.routing.config.RoutingConfigurationService; |
| 48 | 54 | ||
| 49 | -import java.util.ArrayList; | 55 | +import com.google.common.collect.Sets; |
| 50 | -import java.util.Collections; | ||
| 51 | -import java.util.HashMap; | ||
| 52 | -import java.util.LinkedList; | ||
| 53 | -import java.util.List; | ||
| 54 | -import java.util.Map; | ||
| 55 | 56 | ||
| 56 | -import static org.easymock.EasyMock.*; | 57 | +import static org.easymock.EasyMock.createMock; |
| 58 | +import static org.easymock.EasyMock.expect; | ||
| 59 | +import static org.easymock.EasyMock.replay; | ||
| 60 | +import static org.easymock.EasyMock.reset; | ||
| 61 | +import static org.easymock.EasyMock.verify; | ||
| 57 | import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId; | 62 | import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId; |
| 58 | 63 | ||
| 59 | /** | 64 | /** |
| ... | @@ -285,9 +290,13 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -285,9 +290,13 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 285 | builder.matchTcpDst(dstTcpPort); | 290 | builder.matchTcpDst(dstTcpPort); |
| 286 | } | 291 | } |
| 287 | 292 | ||
| 288 | - PointToPointIntent intent = new PointToPointIntent( | 293 | + PointToPointIntent intent = PointToPointIntent.builder() |
| 289 | - APPID, builder.build(), noTreatment, | 294 | + .appId(APPID) |
| 290 | - srcConnectPoint, dstConnectPoint); | 295 | + .selector(builder.build()) |
| 296 | + .treatment(noTreatment) | ||
| 297 | + .ingressPoint(srcConnectPoint) | ||
| 298 | + .egressPoint(dstConnectPoint) | ||
| 299 | + .build(); | ||
| 291 | 300 | ||
| 292 | intentList.add(intent); | 301 | intentList.add(intent); |
| 293 | } | 302 | } |
| ... | @@ -457,9 +466,13 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -457,9 +466,13 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 457 | .matchIPDst(IpPrefix.valueOf(dstPrefix)) | 466 | .matchIPDst(IpPrefix.valueOf(dstPrefix)) |
| 458 | .build(); | 467 | .build(); |
| 459 | 468 | ||
| 460 | - PointToPointIntent intent = new PointToPointIntent( | 469 | + PointToPointIntent intent = PointToPointIntent.builder() |
| 461 | - APPID, selector, noTreatment, | 470 | + .appId(APPID) |
| 462 | - srcConnectPoint, dstConnectPoint); | 471 | + .selector(selector) |
| 472 | + .treatment(noTreatment) | ||
| 473 | + .ingressPoint(srcConnectPoint) | ||
| 474 | + .egressPoint(dstConnectPoint) | ||
| 475 | + .build(); | ||
| 463 | 476 | ||
| 464 | intentList.add(intent); | 477 | intentList.add(intent); |
| 465 | } | 478 | } | ... | ... |
| ... | @@ -67,11 +67,16 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { | ... | @@ -67,11 +67,16 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
| 67 | 67 | ||
| 68 | List<Constraint> constraints = buildConstraints(); | 68 | List<Constraint> constraints = buildConstraints(); |
| 69 | 69 | ||
| 70 | - Intent intent = new PointToPointIntent(appId(), | 70 | + Intent intent = PointToPointIntent.builder() |
| 71 | - key(), | 71 | + .appId(appId()) |
| 72 | - selector, treatment, | 72 | + .key(key()) |
| 73 | - ingress, egress, constraints, | 73 | + .selector(selector) |
| 74 | - priority()); | 74 | + .treatment(treatment) |
| 75 | + .ingressPoint(ingress) | ||
| 76 | + .egressPoint(egress) | ||
| 77 | + .constraints(constraints) | ||
| 78 | + .priority(priority()) | ||
| 79 | + .build(); | ||
| 75 | service.submit(intent); | 80 | service.submit(intent); |
| 76 | print("Point to point intent submitted:\n%s", intent.toString()); | 81 | print("Point to point intent submitted:\n%s", intent.toString()); |
| 77 | } | 82 | } | ... | ... |
| ... | @@ -15,7 +15,11 @@ | ... | @@ -15,7 +15,11 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.cli.net; | 16 | package org.onosproject.cli.net; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.Lists; | 18 | +import java.util.EnumSet; |
| 19 | +import java.util.List; | ||
| 20 | +import java.util.concurrent.CountDownLatch; | ||
| 21 | +import java.util.concurrent.atomic.AtomicLong; | ||
| 22 | + | ||
| 19 | import org.apache.karaf.shell.commands.Argument; | 23 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; | 24 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
| ... | @@ -36,11 +40,7 @@ import org.onosproject.net.intent.IntentService; | ... | @@ -36,11 +40,7 @@ import org.onosproject.net.intent.IntentService; |
| 36 | import org.onosproject.net.intent.Key; | 40 | import org.onosproject.net.intent.Key; |
| 37 | import org.onosproject.net.intent.PointToPointIntent; | 41 | import org.onosproject.net.intent.PointToPointIntent; |
| 38 | 42 | ||
| 39 | -import java.util.Collections; | 43 | +import com.google.common.collect.Lists; |
| 40 | -import java.util.EnumSet; | ||
| 41 | -import java.util.List; | ||
| 42 | -import java.util.concurrent.CountDownLatch; | ||
| 43 | -import java.util.concurrent.atomic.AtomicLong; | ||
| 44 | 44 | ||
| 45 | import static org.onlab.util.Tools.delay; | 45 | import static org.onlab.util.Tools.delay; |
| 46 | import static org.onosproject.net.DeviceId.deviceId; | 46 | import static org.onosproject.net.DeviceId.deviceId; |
| ... | @@ -127,11 +127,16 @@ public class IntentCycleCommand extends AbstractShellCommand | ... | @@ -127,11 +127,16 @@ public class IntentCycleCommand extends AbstractShellCommand |
| 127 | TrafficSelector selector = selectorBldr | 127 | TrafficSelector selector = selectorBldr |
| 128 | .matchEthSrc(MacAddress.valueOf(i + keyOffset)) | 128 | .matchEthSrc(MacAddress.valueOf(i + keyOffset)) |
| 129 | .build(); | 129 | .build(); |
| 130 | - intents.add(new PointToPointIntent(appId(), Key.of(i + keyOffset, appId()), | 130 | + intents.add( |
| 131 | - selector, treatment, | 131 | + PointToPointIntent.builder() |
| 132 | - ingress, egress, | 132 | + .appId(appId()) |
| 133 | - Collections.emptyList(), | 133 | + .key(Key.of(i + keyOffset, appId())) |
| 134 | - Intent.DEFAULT_INTENT_PRIORITY)); | 134 | + .selector(selector) |
| 135 | + .treatment(treatment) | ||
| 136 | + .ingressPoint(ingress) | ||
| 137 | + .egressPoint(egress) | ||
| 138 | + .build()); | ||
| 139 | + | ||
| 135 | 140 | ||
| 136 | } | 141 | } |
| 137 | return intents; | 142 | return intents; | ... | ... |
| ... | @@ -15,7 +15,11 @@ | ... | @@ -15,7 +15,11 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.cli.net; | 16 | package org.onosproject.cli.net; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.Lists; | 18 | +import java.util.EnumSet; |
| 19 | +import java.util.List; | ||
| 20 | +import java.util.concurrent.CountDownLatch; | ||
| 21 | +import java.util.concurrent.TimeUnit; | ||
| 22 | + | ||
| 19 | import org.apache.karaf.shell.commands.Argument; | 23 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; | 24 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.apache.karaf.shell.commands.Option; | 25 | import org.apache.karaf.shell.commands.Option; |
| ... | @@ -37,11 +41,7 @@ import org.onosproject.net.intent.IntentService; | ... | @@ -37,11 +41,7 @@ import org.onosproject.net.intent.IntentService; |
| 37 | import org.onosproject.net.intent.Key; | 41 | import org.onosproject.net.intent.Key; |
| 38 | import org.onosproject.net.intent.PointToPointIntent; | 42 | import org.onosproject.net.intent.PointToPointIntent; |
| 39 | 43 | ||
| 40 | -import java.util.Collections; | 44 | +import com.google.common.collect.Lists; |
| 41 | -import java.util.EnumSet; | ||
| 42 | -import java.util.List; | ||
| 43 | -import java.util.concurrent.CountDownLatch; | ||
| 44 | -import java.util.concurrent.TimeUnit; | ||
| 45 | 45 | ||
| 46 | import static org.onosproject.net.DeviceId.deviceId; | 46 | import static org.onosproject.net.DeviceId.deviceId; |
| 47 | import static org.onosproject.net.PortNumber.portNumber; | 47 | import static org.onosproject.net.PortNumber.portNumber; |
| ... | @@ -136,11 +136,15 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -136,11 +136,15 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 136 | TrafficSelector selector = selectorBldr | 136 | TrafficSelector selector = selectorBldr |
| 137 | .matchEthSrc(MacAddress.valueOf(i + keyOffset)) | 137 | .matchEthSrc(MacAddress.valueOf(i + keyOffset)) |
| 138 | .build(); | 138 | .build(); |
| 139 | - intents.add(new PointToPointIntent(appId(), Key.of(i + keyOffset, appId()), | 139 | + intents.add(PointToPointIntent.builder() |
| 140 | - selector, treatment, | 140 | + .appId(appId()) |
| 141 | - ingress, egress, | 141 | + .key(Key.of(i + keyOffset, appId())) |
| 142 | - Collections.emptyList(), | 142 | + .selector(selector) |
| 143 | - Intent.DEFAULT_INTENT_PRIORITY)); | 143 | + .treatment(treatment) |
| 144 | + .ingressPoint(ingress) | ||
| 145 | + .egressPoint(egress) | ||
| 146 | + .build()); | ||
| 147 | + | ||
| 144 | 148 | ||
| 145 | } | 149 | } |
| 146 | return intents; | 150 | return intents; | ... | ... |
| ... | @@ -15,10 +15,13 @@ | ... | @@ -15,10 +15,13 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | +import com.google.common.collect.ImmutableList; | ||
| 18 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 19 | import org.onosproject.core.ApplicationId; | 20 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.Link; | 21 | import org.onosproject.net.Link; |
| 21 | import org.onosproject.net.NetworkResource; | 22 | import org.onosproject.net.NetworkResource; |
| 23 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 24 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 22 | import org.onosproject.net.flow.TrafficSelector; | 25 | import org.onosproject.net.flow.TrafficSelector; |
| 23 | import org.onosproject.net.flow.TrafficTreatment; | 26 | import org.onosproject.net.flow.TrafficTreatment; |
| 24 | 27 | ||
| ... | @@ -112,6 +115,65 @@ public abstract class ConnectivityIntent extends Intent { | ... | @@ -112,6 +115,65 @@ public abstract class ConnectivityIntent extends Intent { |
| 112 | } | 115 | } |
| 113 | 116 | ||
| 114 | /** | 117 | /** |
| 118 | + * Abstract builder for connectivity intents. | ||
| 119 | + */ | ||
| 120 | + public abstract static class Builder extends Intent.Builder { | ||
| 121 | + protected TrafficSelector selector = DefaultTrafficSelector.emptySelector(); | ||
| 122 | + protected TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | ||
| 123 | + protected List<Constraint> constraints = ImmutableList.of(); | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public Builder appId(ApplicationId appId) { | ||
| 127 | + return (Builder) super.appId(appId); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + @Override | ||
| 131 | + public Builder key(Key key) { | ||
| 132 | + return (Builder) super.key(key); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + @Override | ||
| 136 | + public Builder priority(int priority) { | ||
| 137 | + return (Builder) super.priority(priority); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * Sets the traffic selector for the intent that will be built. | ||
| 143 | + * | ||
| 144 | + * @param selector selector to use for built intent | ||
| 145 | + * @return this builder | ||
| 146 | + */ | ||
| 147 | + public Builder selector(TrafficSelector selector) { | ||
| 148 | + this.selector = selector; | ||
| 149 | + return this; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * Sets the traffic treatment for the intent that will be built. | ||
| 154 | + * | ||
| 155 | + * @param treatment treatment to use for built intent | ||
| 156 | + * @return this builder | ||
| 157 | + */ | ||
| 158 | + public Builder treatment(TrafficTreatment treatment) { | ||
| 159 | + this.treatment = treatment; | ||
| 160 | + return this; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * Sets the constraints for the intent that will be built. | ||
| 165 | + * | ||
| 166 | + * @param constraints constraints to use for built intent | ||
| 167 | + * @return this builder | ||
| 168 | + */ | ||
| 169 | + public Builder constraints(List<Constraint> constraints) { | ||
| 170 | + this.constraints = ImmutableList.copyOf(constraints); | ||
| 171 | + return this; | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + | ||
| 176 | + /** | ||
| 115 | * Returns the match specifying the type of traffic. | 177 | * Returns the match specifying the type of traffic. |
| 116 | * | 178 | * |
| 117 | * @return traffic match | 179 | * @return traffic match | ... | ... |
| ... | @@ -15,13 +15,13 @@ | ... | @@ -15,13 +15,13 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | +import java.util.Collection; | ||
| 19 | +import java.util.Objects; | ||
| 20 | + | ||
| 18 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.core.IdGenerator; | 22 | import org.onosproject.core.IdGenerator; |
| 20 | import org.onosproject.net.NetworkResource; | 23 | import org.onosproject.net.NetworkResource; |
| 21 | 24 | ||
| 22 | -import java.util.Collection; | ||
| 23 | -import java.util.Objects; | ||
| 24 | - | ||
| 25 | import static com.google.common.base.Preconditions.checkArgument; | 25 | import static com.google.common.base.Preconditions.checkArgument; |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; | 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | import static com.google.common.base.Preconditions.checkState; | 27 | import static com.google.common.base.Preconditions.checkState; |
| ... | @@ -92,6 +92,49 @@ public abstract class Intent { | ... | @@ -92,6 +92,49 @@ public abstract class Intent { |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | /** | 94 | /** |
| 95 | + * Abstract builder for intents. | ||
| 96 | + */ | ||
| 97 | + public abstract static class Builder { | ||
| 98 | + protected ApplicationId appId; | ||
| 99 | + protected Key key; | ||
| 100 | + protected int priority = Intent.DEFAULT_INTENT_PRIORITY; | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Sets the application id for the intent that will be built. | ||
| 104 | + * | ||
| 105 | + * @param appId application id to use for built intent | ||
| 106 | + * @return this builder | ||
| 107 | + */ | ||
| 108 | + public Builder appId(ApplicationId appId) { | ||
| 109 | + this.appId = appId; | ||
| 110 | + return this; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * Sets the key for the intent that will be built. | ||
| 115 | + * | ||
| 116 | + * @param key key to use for built intent | ||
| 117 | + * @return this builder | ||
| 118 | + */ | ||
| 119 | + public Builder key(Key key) { | ||
| 120 | + this.key = key; | ||
| 121 | + return this; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * Sets the priority for the intent that will be built. | ||
| 126 | + * | ||
| 127 | + * @param priority priority to use for built intent | ||
| 128 | + * @return this builder | ||
| 129 | + */ | ||
| 130 | + public Builder priority(int priority) { | ||
| 131 | + this.priority = priority; | ||
| 132 | + return this; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + /** | ||
| 95 | * Returns the intent identifier. | 138 | * Returns the intent identifier. |
| 96 | * | 139 | * |
| 97 | * @return intent fingerprint | 140 | * @return intent fingerprint | ... | ... |
| ... | @@ -15,17 +15,15 @@ | ... | @@ -15,17 +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.Collections; |
| 19 | -import com.google.common.collect.ImmutableList; | 19 | +import java.util.List; |
| 20 | + | ||
| 20 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.ConnectPoint; | 22 | import org.onosproject.net.ConnectPoint; |
| 22 | -import org.onosproject.net.Link; | ||
| 23 | import org.onosproject.net.flow.TrafficSelector; | 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; | 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | -import org.onosproject.net.intent.constraint.LinkTypeConstraint; | ||
| 26 | 25 | ||
| 27 | -import java.util.Collections; | 26 | +import com.google.common.base.MoreObjects; |
| 28 | -import java.util.List; | ||
| 29 | 27 | ||
| 30 | import static com.google.common.base.Preconditions.checkArgument; | 28 | import static com.google.common.base.Preconditions.checkArgument; |
| 31 | import static com.google.common.base.Preconditions.checkNotNull; | 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| ... | @@ -39,80 +37,127 @@ public final class PointToPointIntent extends ConnectivityIntent { | ... | @@ -39,80 +37,127 @@ public final class PointToPointIntent extends ConnectivityIntent { |
| 39 | private final ConnectPoint egressPoint; | 37 | private final ConnectPoint egressPoint; |
| 40 | 38 | ||
| 41 | /** | 39 | /** |
| 42 | - * Creates a new point-to-point intent with the supplied ingress/egress | 40 | + * Returns a new point to point intent builder. The application id, |
| 43 | - * ports and constraints. | 41 | + * ingress point and egress point are required fields. If they are |
| 42 | + * not set by calls to the appropriate methods, an exception will | ||
| 43 | + * be thrown. | ||
| 44 | * | 44 | * |
| 45 | - * @param appId application identifier | 45 | + * @return point to point builder |
| 46 | - * @param key key of the intent | ||
| 47 | - * @param selector traffic selector | ||
| 48 | - * @param treatment treatment | ||
| 49 | - * @param ingressPoint ingress port | ||
| 50 | - * @param egressPoint egress port | ||
| 51 | - * @param constraints optional list of constraints | ||
| 52 | - * @param priority priority to use for flows generated by this intent | ||
| 53 | - * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. | ||
| 54 | */ | 46 | */ |
| 55 | - public PointToPointIntent(ApplicationId appId, | 47 | + public static PointToPointIntent.Builder builder() { |
| 56 | - Key key, | 48 | + return new Builder(); |
| 57 | - TrafficSelector selector, | 49 | + } |
| 58 | - TrafficTreatment treatment, | ||
| 59 | - ConnectPoint ingressPoint, | ||
| 60 | - ConnectPoint egressPoint, | ||
| 61 | - List<Constraint> constraints, | ||
| 62 | - int priority) { | ||
| 63 | - super(appId, key, Collections.emptyList(), selector, treatment, constraints, | ||
| 64 | - priority); | ||
| 65 | 50 | ||
| 66 | - checkNotNull(ingressPoint); | 51 | + /** |
| 67 | - checkNotNull(egressPoint); | 52 | + * Builder of a point to point intent. |
| 68 | - checkArgument(!ingressPoint.equals(egressPoint), | 53 | + */ |
| 69 | - "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); | 54 | + public static final class Builder extends ConnectivityIntent.Builder { |
| 55 | + ConnectPoint ingressPoint; | ||
| 56 | + ConnectPoint egressPoint; | ||
| 57 | + | ||
| 58 | + private Builder() { | ||
| 59 | + // Hide constructor | ||
| 60 | + } | ||
| 70 | 61 | ||
| 62 | + @Override | ||
| 63 | + public Builder appId(ApplicationId appId) { | ||
| 64 | + return (Builder) super.appId(appId); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public Builder key(Key key) { | ||
| 69 | + return (Builder) super.key(key); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public Builder selector(TrafficSelector selector) { | ||
| 74 | + return (Builder) super.selector(selector); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public Builder treatment(TrafficTreatment treatment) { | ||
| 79 | + return (Builder) super.treatment(treatment); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public Builder constraints(List<Constraint> constraints) { | ||
| 84 | + return (Builder) super.constraints(constraints); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public Builder priority(int priority) { | ||
| 89 | + return (Builder) super.priority(priority); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Sets the ingress point of the point to point intent that will be built. | ||
| 94 | + * | ||
| 95 | + * @param ingressPoint ingress connect point | ||
| 96 | + * @return this builder | ||
| 97 | + */ | ||
| 98 | + public Builder ingressPoint(ConnectPoint ingressPoint) { | ||
| 71 | this.ingressPoint = ingressPoint; | 99 | this.ingressPoint = ingressPoint; |
| 100 | + return this; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Sets the egress point of the point to point intent that will be built. | ||
| 105 | + * | ||
| 106 | + * @param egressPoint egress connect point | ||
| 107 | + * @return this builder | ||
| 108 | + */ | ||
| 109 | + public Builder egressPoint(ConnectPoint egressPoint) { | ||
| 72 | this.egressPoint = egressPoint; | 110 | this.egressPoint = egressPoint; |
| 111 | + return this; | ||
| 73 | } | 112 | } |
| 74 | 113 | ||
| 75 | /** | 114 | /** |
| 76 | - * Creates a new point-to-point intent with the supplied ingress/egress | 115 | + * Builds a point to point intent from the accumulated parameters. |
| 77 | - * ports and with built-in link type constraint to avoid optical links. | ||
| 78 | * | 116 | * |
| 79 | - * @param appId application identifier | 117 | + * @return point to point intent |
| 80 | - * @param selector traffic selector | ||
| 81 | - * @param treatment treatment | ||
| 82 | - * @param ingressPoint ingress port | ||
| 83 | - * @param egressPoint egress port | ||
| 84 | - * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. | ||
| 85 | */ | 118 | */ |
| 86 | - public PointToPointIntent(ApplicationId appId, TrafficSelector selector, | 119 | + public PointToPointIntent build() { |
| 87 | - TrafficTreatment treatment, | 120 | + |
| 88 | - ConnectPoint ingressPoint, | 121 | + return new PointToPointIntent( |
| 89 | - ConnectPoint egressPoint) { | 122 | + appId, |
| 90 | - this(appId, null, selector, treatment, ingressPoint, egressPoint, | 123 | + key, |
| 91 | - ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)), | 124 | + selector, |
| 92 | - DEFAULT_INTENT_PRIORITY); | 125 | + treatment, |
| 126 | + ingressPoint, | ||
| 127 | + egressPoint, | ||
| 128 | + constraints, | ||
| 129 | + priority | ||
| 130 | + ); | ||
| 131 | + } | ||
| 93 | } | 132 | } |
| 94 | 133 | ||
| 134 | + | ||
| 135 | + | ||
| 95 | /** | 136 | /** |
| 96 | * Creates a new point-to-point intent with the supplied ingress/egress | 137 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 97 | * ports and constraints. | 138 | * ports and constraints. |
| 98 | * | 139 | * |
| 99 | * @param appId application identifier | 140 | * @param appId application identifier |
| 141 | + * @param key key of the intent | ||
| 100 | * @param selector traffic selector | 142 | * @param selector traffic selector |
| 101 | * @param treatment treatment | 143 | * @param treatment treatment |
| 102 | * @param ingressPoint ingress port | 144 | * @param ingressPoint ingress port |
| 103 | * @param egressPoint egress port | 145 | * @param egressPoint egress port |
| 104 | * @param constraints optional list of constraints | 146 | * @param constraints optional list of constraints |
| 105 | * @param priority priority to use for flows generated by this intent | 147 | * @param priority priority to use for flows generated by this intent |
| 106 | - * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null. | 148 | + * @throws NullPointerException if {@code ingressPoint} or |
| 149 | + * {@code egressPoints} or {@code appId} is null. | ||
| 107 | */ | 150 | */ |
| 108 | - public PointToPointIntent(ApplicationId appId, TrafficSelector selector, | 151 | + private PointToPointIntent(ApplicationId appId, |
| 152 | + Key key, | ||
| 153 | + TrafficSelector selector, | ||
| 109 | TrafficTreatment treatment, | 154 | TrafficTreatment treatment, |
| 110 | ConnectPoint ingressPoint, | 155 | ConnectPoint ingressPoint, |
| 111 | ConnectPoint egressPoint, | 156 | ConnectPoint egressPoint, |
| 112 | List<Constraint> constraints, | 157 | List<Constraint> constraints, |
| 113 | int priority) { | 158 | int priority) { |
| 114 | - super(appId, null, Collections.emptyList(), selector, treatment, | 159 | + super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
| 115 | - constraints, priority); | 160 | + priority); |
| 116 | 161 | ||
| 117 | checkNotNull(ingressPoint); | 162 | checkNotNull(ingressPoint); |
| 118 | checkNotNull(egressPoint); | 163 | checkNotNull(egressPoint); | ... | ... |
| ... | @@ -44,11 +44,23 @@ public class PointToPointIntentTest extends ConnectivityIntentTest { | ... | @@ -44,11 +44,23 @@ public class PointToPointIntentTest extends ConnectivityIntentTest { |
| 44 | 44 | ||
| 45 | @Override | 45 | @Override |
| 46 | protected PointToPointIntent createOne() { | 46 | protected PointToPointIntent createOne() { |
| 47 | - return new PointToPointIntent(APPID, MATCH, NOP, P1, P2); | 47 | + return PointToPointIntent.builder() |
| 48 | + .appId(APPID) | ||
| 49 | + .selector(MATCH) | ||
| 50 | + .treatment(NOP) | ||
| 51 | + .ingressPoint(P1) | ||
| 52 | + .egressPoint(P2) | ||
| 53 | + .build(); | ||
| 48 | } | 54 | } |
| 49 | 55 | ||
| 50 | @Override | 56 | @Override |
| 51 | protected PointToPointIntent createAnother() { | 57 | protected PointToPointIntent createAnother() { |
| 52 | - return new PointToPointIntent(APPID, MATCH, NOP, P2, P1); | 58 | + return PointToPointIntent.builder() |
| 59 | + .appId(APPID) | ||
| 60 | + .selector(MATCH) | ||
| 61 | + .treatment(NOP) | ||
| 62 | + .ingressPoint(P2) | ||
| 63 | + .egressPoint(P1) | ||
| 64 | + .build(); | ||
| 53 | } | 65 | } |
| 54 | } | 66 | } | ... | ... |
| ... | @@ -48,14 +48,25 @@ public class TwoWayP2PIntentCompiler | ... | @@ -48,14 +48,25 @@ public class TwoWayP2PIntentCompiler |
| 48 | public List<Intent> compile(TwoWayP2PIntent intent, List<Intent> installable, | 48 | public List<Intent> compile(TwoWayP2PIntent intent, List<Intent> installable, |
| 49 | Set<LinkResourceAllocations> resources) { | 49 | Set<LinkResourceAllocations> resources) { |
| 50 | return Lists.newArrayList( | 50 | return Lists.newArrayList( |
| 51 | - new PointToPointIntent(intent.appId(), intent.key(), | 51 | + PointToPointIntent.builder() |
| 52 | - intent.selector(), intent.treatment(), | 52 | + .appId(intent.appId()) |
| 53 | - intent.one(), intent.two(), | 53 | + .key(intent.key()) |
| 54 | - intent.constraints(), intent.priority()), | 54 | + .selector(intent.selector()) |
| 55 | - new PointToPointIntent(intent.appId(), intent.key(), | 55 | + .treatment(intent.treatment()) |
| 56 | - intent.selector(), intent.treatment(), | 56 | + .ingressPoint(intent.one()) |
| 57 | - intent.two(), intent.one(), | 57 | + .egressPoint(intent.two()) |
| 58 | - intent.constraints(), intent.priority())); | 58 | + .constraints(intent.constraints()) |
| 59 | - | 59 | + .priority(intent.priority()) |
| 60 | + .build(), | ||
| 61 | + PointToPointIntent.builder() | ||
| 62 | + .appId(intent.appId()) | ||
| 63 | + .key(intent.key()) | ||
| 64 | + .selector(intent.selector()) | ||
| 65 | + .treatment(intent.treatment()) | ||
| 66 | + .ingressPoint(intent.two()) | ||
| 67 | + .egressPoint(intent.one()) | ||
| 68 | + .constraints(intent.constraints()) | ||
| 69 | + .priority(intent.priority()) | ||
| 70 | + .build()); | ||
| 60 | } | 71 | } |
| 61 | } | 72 | } | ... | ... |
| ... | @@ -72,9 +72,13 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -72,9 +72,13 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
| 72 | */ | 72 | */ |
| 73 | private PointToPointIntent makeIntent(String ingressIdString, | 73 | private PointToPointIntent makeIntent(String ingressIdString, |
| 74 | String egressIdString) { | 74 | String egressIdString) { |
| 75 | - return new PointToPointIntent(APPID, selector, treatment, | 75 | + return PointToPointIntent.builder() |
| 76 | - connectPoint(ingressIdString, 1), | 76 | + .appId(APPID) |
| 77 | - connectPoint(egressIdString, 1)); | 77 | + .selector(selector) |
| 78 | + .treatment(treatment) | ||
| 79 | + .ingressPoint(connectPoint(ingressIdString, 1)) | ||
| 80 | + .egressPoint(connectPoint(egressIdString, 1)) | ||
| 81 | + .build(); | ||
| 78 | } | 82 | } |
| 79 | 83 | ||
| 80 | /** | 84 | /** |
| ... | @@ -87,10 +91,14 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -87,10 +91,14 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
| 87 | */ | 91 | */ |
| 88 | private PointToPointIntent makeIntent(String ingressIdString, | 92 | private PointToPointIntent makeIntent(String ingressIdString, |
| 89 | String egressIdString, List<Constraint> constraints) { | 93 | String egressIdString, List<Constraint> constraints) { |
| 90 | - return new PointToPointIntent(APPID, selector, treatment, | 94 | + return PointToPointIntent.builder() |
| 91 | - connectPoint(ingressIdString, 1), | 95 | + .appId(APPID) |
| 92 | - connectPoint(egressIdString, 1), | 96 | + .selector(selector) |
| 93 | - constraints, Intent.DEFAULT_INTENT_PRIORITY); | 97 | + .treatment(treatment) |
| 98 | + .ingressPoint(connectPoint(ingressIdString, 1)) | ||
| 99 | + .egressPoint(connectPoint(egressIdString, 1)) | ||
| 100 | + .constraints(constraints) | ||
| 101 | + .build(); | ||
| 94 | } | 102 | } |
| 95 | 103 | ||
| 96 | /** | 104 | /** |
| ... | @@ -187,7 +195,13 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -187,7 +195,13 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
| 187 | public void testSameSwitchDifferentPortsIntentCompilation() { | 195 | public void testSameSwitchDifferentPortsIntentCompilation() { |
| 188 | ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1)); | 196 | ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1)); |
| 189 | ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2)); | 197 | ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2)); |
| 190 | - PointToPointIntent intent = new PointToPointIntent(APP_ID, selector, treatment, src, dst); | 198 | + PointToPointIntent intent = PointToPointIntent.builder() |
| 199 | + .appId(APP_ID) | ||
| 200 | + .selector(selector) | ||
| 201 | + .treatment(treatment) | ||
| 202 | + .ingressPoint(src) | ||
| 203 | + .egressPoint(dst) | ||
| 204 | + .build(); | ||
| 191 | 205 | ||
| 192 | String[] hops = {"1"}; | 206 | String[] hops = {"1"}; |
| 193 | PointToPointIntentCompiler sut = makeCompiler(hops); | 207 | PointToPointIntentCompiler sut = makeCompiler(hops); | ... | ... |
| ... | @@ -90,7 +90,13 @@ public class CompilingTest { | ... | @@ -90,7 +90,13 @@ public class CompilingTest { |
| 90 | Intent.bindIdGenerator(idGenerator); | 90 | Intent.bindIdGenerator(idGenerator); |
| 91 | 91 | ||
| 92 | // Intent creation should be placed after binding an ID generator | 92 | // Intent creation should be placed after binding an ID generator |
| 93 | - input = new PointToPointIntent(appId, selector, treatment, cp1, cp3); | 93 | + input = PointToPointIntent.builder() |
| 94 | + .appId(appId) | ||
| 95 | + .selector(selector) | ||
| 96 | + .treatment(treatment) | ||
| 97 | + .ingressPoint(cp1) | ||
| 98 | + .egressPoint(cp3) | ||
| 99 | + .build(); | ||
| 94 | compiled = new PathIntent(appId, selector, treatment, path); | 100 | compiled = new PathIntent(appId, selector, treatment, path); |
| 95 | } | 101 | } |
| 96 | 102 | ... | ... |
| ... | @@ -91,7 +91,13 @@ public class InstallCoordinatingTest { | ... | @@ -91,7 +91,13 @@ public class InstallCoordinatingTest { |
| 91 | Intent.bindIdGenerator(idGenerator); | 91 | Intent.bindIdGenerator(idGenerator); |
| 92 | 92 | ||
| 93 | // Intent creation should be placed after binding an ID generator | 93 | // Intent creation should be placed after binding an ID generator |
| 94 | - input = new PointToPointIntent(appId, selector, treatment, cp1, cp3); | 94 | + input = PointToPointIntent.builder() |
| 95 | + .appId(appId) | ||
| 96 | + .selector(selector) | ||
| 97 | + .treatment(treatment) | ||
| 98 | + .ingressPoint(cp1) | ||
| 99 | + .egressPoint(cp3) | ||
| 100 | + .build(); | ||
| 95 | compiled = new PathIntent(appId, selector, treatment, path); | 101 | compiled = new PathIntent(appId, selector, treatment, path); |
| 96 | } | 102 | } |
| 97 | 103 | ... | ... |
| ... | @@ -91,7 +91,13 @@ public class InstallingTest { | ... | @@ -91,7 +91,13 @@ public class InstallingTest { |
| 91 | Intent.bindIdGenerator(idGenerator); | 91 | Intent.bindIdGenerator(idGenerator); |
| 92 | 92 | ||
| 93 | // Intent creation should be placed after binding an ID generator | 93 | // Intent creation should be placed after binding an ID generator |
| 94 | - input = new PointToPointIntent(appId, selector, treatment, cp1, cp3); | 94 | + input = PointToPointIntent.builder() |
| 95 | + .appId(appId) | ||
| 96 | + .selector(selector) | ||
| 97 | + .treatment(treatment) | ||
| 98 | + .ingressPoint(cp1) | ||
| 99 | + .egressPoint(cp3) | ||
| 100 | + .build(); | ||
| 95 | compiled = new PathIntent(appId, selector, treatment, path); | 101 | compiled = new PathIntent(appId, selector, treatment, path); |
| 96 | } | 102 | } |
| 97 | 103 | ... | ... |
| ... | @@ -92,7 +92,13 @@ public class WithdrawCoordinatingTest { | ... | @@ -92,7 +92,13 @@ public class WithdrawCoordinatingTest { |
| 92 | Intent.bindIdGenerator(idGenerator); | 92 | Intent.bindIdGenerator(idGenerator); |
| 93 | 93 | ||
| 94 | // Intent creation should be placed after binding an ID generator | 94 | // Intent creation should be placed after binding an ID generator |
| 95 | - input = new PointToPointIntent(appId, selector, treatment, cp1, cp3); | 95 | + input = PointToPointIntent.builder() |
| 96 | + .appId(appId) | ||
| 97 | + .selector(selector) | ||
| 98 | + .treatment(treatment) | ||
| 99 | + .ingressPoint(cp1) | ||
| 100 | + .egressPoint(cp3) | ||
| 101 | + .build(); | ||
| 96 | compiled = new PathIntent(appId, selector, treatment, path); | 102 | compiled = new PathIntent(appId, selector, treatment, path); |
| 97 | } | 103 | } |
| 98 | 104 | ... | ... |
| ... | @@ -90,7 +90,13 @@ public class WithdrawingTest { | ... | @@ -90,7 +90,13 @@ public class WithdrawingTest { |
| 90 | Intent.bindIdGenerator(idGenerator); | 90 | Intent.bindIdGenerator(idGenerator); |
| 91 | 91 | ||
| 92 | // Intent creation should be placed after binding an ID generator | 92 | // Intent creation should be placed after binding an ID generator |
| 93 | - input = new PointToPointIntent(appId, selector, treatment, cp1, cp3); | 93 | + input = PointToPointIntent.builder() |
| 94 | + .appId(appId) | ||
| 95 | + .selector(selector) | ||
| 96 | + .treatment(treatment) | ||
| 97 | + .ingressPoint(cp1) | ||
| 98 | + .egressPoint(cp3) | ||
| 99 | + .build(); | ||
| 94 | compiled = new PathIntent(appId, selector, treatment, path); | 100 | compiled = new PathIntent(appId, selector, treatment, path); |
| 95 | } | 101 | } |
| 96 | 102 | ... | ... |
| ... | @@ -35,10 +35,9 @@ import org.onosproject.net.flow.DefaultTrafficSelector; | ... | @@ -35,10 +35,9 @@ import org.onosproject.net.flow.DefaultTrafficSelector; |
| 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 36 | import org.onosproject.net.flow.TrafficSelector; | 36 | import org.onosproject.net.flow.TrafficSelector; |
| 37 | import org.onosproject.net.flow.TrafficTreatment; | 37 | import org.onosproject.net.flow.TrafficTreatment; |
| 38 | +import org.onosproject.net.intent.AbstractIntentTest; | ||
| 38 | import org.onosproject.net.intent.Constraint; | 39 | import org.onosproject.net.intent.Constraint; |
| 39 | import org.onosproject.net.intent.HostToHostIntent; | 40 | import org.onosproject.net.intent.HostToHostIntent; |
| 40 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
| 41 | -import org.onosproject.net.intent.Intent; | ||
| 42 | import org.onosproject.net.intent.PointToPointIntent; | 41 | import org.onosproject.net.intent.PointToPointIntent; |
| 43 | import org.onosproject.net.intent.constraint.AnnotationConstraint; | 42 | import org.onosproject.net.intent.constraint.AnnotationConstraint; |
| 44 | import org.onosproject.net.intent.constraint.AsymmetricPathConstraint; | 43 | import org.onosproject.net.intent.constraint.AsymmetricPathConstraint; |
| ... | @@ -53,11 +52,11 @@ import org.onosproject.net.resource.Lambda; | ... | @@ -53,11 +52,11 @@ import org.onosproject.net.resource.Lambda; |
| 53 | import com.fasterxml.jackson.databind.node.ObjectNode; | 52 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 54 | import com.google.common.collect.ImmutableList; | 53 | import com.google.common.collect.ImmutableList; |
| 55 | 54 | ||
| 55 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 56 | +import static org.hamcrest.Matchers.notNullValue; | ||
| 56 | import static org.onosproject.codec.impl.IntentJsonMatcher.matchesIntent; | 57 | import static org.onosproject.codec.impl.IntentJsonMatcher.matchesIntent; |
| 57 | import static org.onosproject.net.NetTestTools.did; | 58 | import static org.onosproject.net.NetTestTools.did; |
| 58 | import static org.onosproject.net.NetTestTools.hid; | 59 | import static org.onosproject.net.NetTestTools.hid; |
| 59 | -import static org.hamcrest.MatcherAssert.assertThat; | ||
| 60 | -import static org.hamcrest.Matchers.notNullValue; | ||
| 61 | 60 | ||
| 62 | /** | 61 | /** |
| 63 | * Unit tests for the host to host intent class codec. | 62 | * Unit tests for the host to host intent class codec. |
| ... | @@ -98,8 +97,12 @@ public class IntentCodecTest extends AbstractIntentTest { | ... | @@ -98,8 +97,12 @@ public class IntentCodecTest extends AbstractIntentTest { |
| 98 | ConnectPoint egress = NetTestTools.connectPoint("egress", 2); | 97 | ConnectPoint egress = NetTestTools.connectPoint("egress", 2); |
| 99 | 98 | ||
| 100 | final PointToPointIntent intent = | 99 | final PointToPointIntent intent = |
| 101 | - new PointToPointIntent(appId, emptySelector, | 100 | + PointToPointIntent.builder() |
| 102 | - emptyTreatment, ingress, egress); | 101 | + .appId(appId) |
| 102 | + .selector(emptySelector) | ||
| 103 | + .treatment(emptyTreatment) | ||
| 104 | + .ingressPoint(ingress) | ||
| 105 | + .egressPoint(egress).build(); | ||
| 103 | 106 | ||
| 104 | final CodecContext context = new MockCodecContext(); | 107 | final CodecContext context = new MockCodecContext(); |
| 105 | final JsonCodec<PointToPointIntent> intentCodec = | 108 | final JsonCodec<PointToPointIntent> intentCodec = |
| ... | @@ -147,9 +150,15 @@ public class IntentCodecTest extends AbstractIntentTest { | ... | @@ -147,9 +150,15 @@ public class IntentCodecTest extends AbstractIntentTest { |
| 147 | new WaypointConstraint(did3)); | 150 | new WaypointConstraint(did3)); |
| 148 | 151 | ||
| 149 | final PointToPointIntent intent = | 152 | final PointToPointIntent intent = |
| 150 | - new PointToPointIntent(appId, selector, treatment, | 153 | + PointToPointIntent.builder() |
| 151 | - ingress, egress, constraints, | 154 | + .appId(appId) |
| 152 | - Intent.DEFAULT_INTENT_PRIORITY); | 155 | + .selector(selector) |
| 156 | + .treatment(treatment) | ||
| 157 | + .ingressPoint(ingress) | ||
| 158 | + .egressPoint(egress) | ||
| 159 | + .constraints(constraints) | ||
| 160 | + .build(); | ||
| 161 | + | ||
| 153 | 162 | ||
| 154 | final CodecContext context = new MockCodecContext(); | 163 | final CodecContext context = new MockCodecContext(); |
| 155 | final JsonCodec<PointToPointIntent> intentCodec = | 164 | final JsonCodec<PointToPointIntent> intentCodec = | ... | ... |
-
Please register or login to post a comment