Sho SHIMIZU
Committed by Ray Milkey

Remove dependency on PointToPointIntentCompiler

Create an installable intent, not relying on an IntentCompiler.
This change enables IntentCompilers to be moved to a dedicated package.

Reference: ONOS-1066

Change-Id: Ie5bca33720232afaa4d6642d4f9fda933f6d00e3
...@@ -36,7 +36,7 @@ import org.onosproject.net.resource.Bandwidth; ...@@ -36,7 +36,7 @@ import org.onosproject.net.resource.Bandwidth;
36 import org.onosproject.net.resource.Lambda; 36 import org.onosproject.net.resource.Lambda;
37 import org.onosproject.net.resource.LinkResourceService; 37 import org.onosproject.net.resource.LinkResourceService;
38 38
39 -import java.util.LinkedList; 39 +import java.util.Arrays;
40 import java.util.List; 40 import java.util.List;
41 41
42 import static org.hamcrest.CoreMatchers.instanceOf; 42 import static org.hamcrest.CoreMatchers.instanceOf;
...@@ -77,14 +77,29 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -77,14 +77,29 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
77 } 77 }
78 78
79 /** 79 /**
80 + * Creates a PointToPoint intent based on ingress and egress deviceIds and constraints.
81 + *
82 + * @param ingressIdString string for id of ingress device
83 + * @param egressIdString string for id of egress device
84 + * @param constraints constraints
85 + * @return PointToPointIntent for the two device with constraints
86 + */
87 + private PointToPointIntent makeIntent(String ingressIdString,
88 + String egressIdString, List<Constraint> constraints) {
89 + return new PointToPointIntent(APPID, selector, treatment,
90 + connectPoint(ingressIdString, 1),
91 + connectPoint(egressIdString, 1),
92 + constraints);
93 + }
94 +
95 + /**
80 * Creates a compiler for HostToHost intents. 96 * Creates a compiler for HostToHost intents.
81 * 97 *
82 * @param hops string array describing the path hops to use when compiling 98 * @param hops string array describing the path hops to use when compiling
83 * @return HostToHost intent compiler 99 * @return HostToHost intent compiler
84 */ 100 */
85 private PointToPointIntentCompiler makeCompiler(String[] hops) { 101 private PointToPointIntentCompiler makeCompiler(String[] hops) {
86 - PointToPointIntentCompiler compiler = 102 + PointToPointIntentCompiler compiler = new PointToPointIntentCompiler();
87 - new PointToPointIntentCompiler();
88 compiler.pathService = new IntentTestsMocks.MockPathService(hops); 103 compiler.pathService = new IntentTestsMocks.MockPathService(hops);
89 return compiler; 104 return compiler;
90 } 105 }
...@@ -96,8 +111,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -96,8 +111,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
96 * @param resourceService service to use for resource allocation requests 111 * @param resourceService service to use for resource allocation requests
97 * @return point to point compiler 112 * @return point to point compiler
98 */ 113 */
99 - private PointToPointIntentCompiler makeCompiler(LinkResourceService resourceService) { 114 + private PointToPointIntentCompiler makeCompiler(String[] hops, LinkResourceService resourceService) {
100 - final String[] hops = {"s1", "s2", "s3"};
101 final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); 115 final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler();
102 compiler.resourceService = resourceService; 116 compiler.resourceService = resourceService;
103 compiler.pathService = new IntentTestsMocks.MockPathService(hops); 117 compiler.pathService = new IntentTestsMocks.MockPathService(hops);
...@@ -105,33 +119,6 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -105,33 +119,6 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
105 } 119 }
106 120
107 /** 121 /**
108 - * Creates an intent with a given constraint and compiles it. The compiler
109 - * will throw PathNotFoundException if the allocations cannot be satisfied.
110 - *
111 - * @param constraint constraint to apply to the created intent
112 - * @param resourceService service to use for resource allocation requests
113 - * @return List of compiled intents
114 - */
115 - private List<Intent> compileIntent(Constraint constraint,
116 - LinkResourceService resourceService) {
117 - final List<Constraint> constraints = new LinkedList<>();
118 - constraints.add(constraint);
119 - final TrafficSelector selector = new IntentTestsMocks.MockSelector();
120 - final TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
121 -
122 - final PointToPointIntent intent =
123 - new PointToPointIntent(APP_ID,
124 - selector,
125 - treatment,
126 - connectPoint("s1", 1),
127 - connectPoint("s3", 1),
128 - constraints);
129 - final PointToPointIntentCompiler compiler = makeCompiler(resourceService);
130 -
131 - return compiler.compile(intent, null, null);
132 - }
133 -
134 - /**
135 * Tests a pair of devices in an 8 hop path, forward direction. 122 * Tests a pair of devices in an 8 hop path, forward direction.
136 */ 123 */
137 @Test 124 @Test
...@@ -225,9 +212,15 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -225,9 +212,15 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
225 212
226 final LinkResourceService resourceService = 213 final LinkResourceService resourceService =
227 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); 214 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
228 - final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0)); 215 + final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(Bandwidth.bps(100.0)));
216 +
217 + final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
218 +
219 + String[] hops = {"s1", "s2", "s3"};
220 + final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
221 +
222 + final List<Intent> compiledIntents = compiler.compile(intent, null, null);
229 223
230 - final List<Intent> compiledIntents = compileIntent(constraint, resourceService);
231 assertThat(compiledIntents, Matchers.notNullValue()); 224 assertThat(compiledIntents, Matchers.notNullValue());
232 assertThat(compiledIntents, hasSize(1)); 225 assertThat(compiledIntents, hasSize(1));
233 } 226 }
...@@ -240,10 +233,16 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -240,10 +233,16 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
240 233
241 final LinkResourceService resourceService = 234 final LinkResourceService resourceService =
242 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); 235 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
243 - final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0)); 236 + final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(Bandwidth.bps(100.0)));
244 237
245 try { 238 try {
246 - compileIntent(constraint, resourceService); 239 + final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
240 +
241 + String[] hops = {"s1", "s2", "s3"};
242 + final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
243 +
244 + compiler.compile(intent, null, null);
245 +
247 fail("Point to Point compilation with insufficient bandwidth does " 246 fail("Point to Point compilation with insufficient bandwidth does "
248 + "not throw exception."); 247 + "not throw exception.");
249 } catch (PathNotFoundException noPath) { 248 } catch (PathNotFoundException noPath) {
...@@ -257,12 +256,18 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -257,12 +256,18 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
257 @Test 256 @Test
258 public void testLambdaConstrainedIntentSuccess() { 257 public void testLambdaConstrainedIntentSuccess() {
259 258
260 - final Constraint constraint = new LambdaConstraint(Lambda.valueOf(1)); 259 + final List<Constraint> constraints = Arrays.asList(new LambdaConstraint(Lambda.valueOf(1)));
261 final LinkResourceService resourceService = 260 final LinkResourceService resourceService =
262 IntentTestsMocks.MockResourceService.makeLambdaResourceService(1); 261 IntentTestsMocks.MockResourceService.makeLambdaResourceService(1);
263 262
263 + final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
264 +
265 + String[] hops = {"s1", "s2", "s3"};
266 + final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
267 +
264 final List<Intent> compiledIntents = 268 final List<Intent> compiledIntents =
265 - compileIntent(constraint, resourceService); 269 + compiler.compile(intent, null, null);
270 +
266 assertThat(compiledIntents, Matchers.notNullValue()); 271 assertThat(compiledIntents, Matchers.notNullValue());
267 assertThat(compiledIntents, hasSize(1)); 272 assertThat(compiledIntents, hasSize(1));
268 } 273 }
...@@ -274,11 +279,17 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { ...@@ -274,11 +279,17 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
274 @Test 279 @Test
275 public void testLambdaConstrainedIntentFailure() { 280 public void testLambdaConstrainedIntentFailure() {
276 281
277 - final Constraint constraint = new LambdaConstraint(Lambda.valueOf(1)); 282 + final List<Constraint> constraints = Arrays.asList(new LambdaConstraint(Lambda.valueOf(1)));
278 final LinkResourceService resourceService = 283 final LinkResourceService resourceService =
279 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); 284 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
280 try { 285 try {
281 - compileIntent(constraint, resourceService); 286 + final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
287 +
288 + String[] hops = {"s1", "s2", "s3"};
289 + final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
290 +
291 + compiler.compile(intent, null, null);
292 +
282 fail("Point to Point compilation with no available lambda does " 293 fail("Point to Point compilation with no available lambda does "
283 + "not throw exception."); 294 + "not throw exception.");
284 } catch (PathNotFoundException noPath) { 295 } catch (PathNotFoundException noPath) {
......