a4ee525472e8364629a3fcf19fdb52f16af63dfc
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / test / java / jtest / org / onap / ccsdk / sli / adaptors / ra / TestReserve.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                         reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package jtest.org.onap.ccsdk.sli.adaptors.ra;
23
24 import org.junit.Assert;
25 import org.junit.FixMethodOrder;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.MethodSorters;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
32 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.test.context.ContextConfiguration;
37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38
39 @RunWith(SpringJUnit4ClassRunner.class)
40 @ContextConfiguration(locations = { "classpath:test-context.xml" })
41 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
42 public class TestReserve {
43
44     private static final Logger log = LoggerFactory.getLogger(TestReserve.class);
45
46     @Autowired(required = true)
47     private ResourceAllocator resourceAllocator;
48
49     @Autowired(required = true)
50     private DataSetup dataSetup;
51
52     @Test
53     public void test001() throws Exception {
54         String t = "001";
55         log.info("============== reserve " + t + " ================================");
56         log.info("=== Test successful response - new start - all resources available");
57
58         String service1 = "reserve" + t + "/service1";
59
60         dataSetup.cleanup();
61         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
62         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
63         dataSetup.setupPserver("server1", "MTSNJA4LCP1");
64
65         SvcLogicContext ctx = new SvcLogicContext();
66         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
67         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
68         ctx.setAttribute("tmp.resource-allocator.speed", "300");
69         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
70         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
71
72         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
73
74         log.info("Result: " + st);
75         log.info("  tmp.resource-allocator-output.max-available-speed: " +
76                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
77         log.info("  tmp.resource-allocator-output.speed-unit: " +
78                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
79
80         Assert.assertTrue(st == QueryStatus.SUCCESS);
81         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 1, 300000));
82     }
83
84     @Test
85     public void test002() throws Exception {
86         String t = "002";
87         log.info("============== reserve " + t + " ================================");
88         log.info("=== Test successful response - new start supp - all resources available");
89
90         String service1 = "reserve" + t + "/service1";
91
92         dataSetup.cleanup();
93         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
94         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
95         dataSetup.setupService(service1, "Pending", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
96
97         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 2, 200000));
98
99         SvcLogicContext ctx = new SvcLogicContext();
100         // ctx.setAttribute("tmp.resource-allocator.request-type", "New"); - Default is New
101         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
102         ctx.setAttribute("tmp.resource-allocator.speed", "400");
103         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
104         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
105
106         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
107
108         log.info("Result: " + st);
109         log.info("  tmp.resource-allocator-output.max-available-speed: " +
110                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
111         log.info("  tmp.resource-allocator-output.speed-unit: " +
112                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
113
114         Assert.assertTrue(st == QueryStatus.SUCCESS);
115         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 400000));
116         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 2));
117     }
118
119     @Test
120     public void test003() throws Exception {
121         String t = "003";
122         log.info("============== reserve " + t + " ================================");
123         log.info("=== Test successful response - change - all resources available");
124
125         String service1 = "reserve" + t + "/service1";
126
127         dataSetup.cleanup();
128         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
129         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
130         dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
131
132         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
133
134         SvcLogicContext ctx = new SvcLogicContext();
135         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
136         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
137         ctx.setAttribute("tmp.resource-allocator.speed", "400");
138         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
139         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
140
141         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
142
143         log.info("Result: " + st);
144         log.info("  tmp.resource-allocator-output.max-available-speed: " +
145                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
146         log.info("  tmp.resource-allocator-output.speed-unit: " +
147                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
148
149         Assert.assertTrue(st == QueryStatus.SUCCESS);
150         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
151         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 400000));
152     }
153
154     @Test
155     public void test004() throws Exception {
156         String t = "004";
157         log.info("============== reserve " + t + " ================================");
158         log.info("=== Test successful response - change supp - all resources available");
159
160         String service1 = "reserve" + t + "/service1";
161
162         dataSetup.cleanup();
163         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
164         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
165         dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
166         dataSetup.setupService(service1, "Pending", 3, 400000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
167
168         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
169         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 400000));
170
171         SvcLogicContext ctx = new SvcLogicContext();
172         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
173         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
174         ctx.setAttribute("tmp.resource-allocator.speed", "500");
175         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
176         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
177
178         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
179
180         log.info("Result: " + st);
181         log.info("  tmp.resource-allocator-output.max-available-speed: " +
182                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
183         log.info("  tmp.resource-allocator-output.speed-unit: " +
184                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
185
186         Assert.assertTrue(st == QueryStatus.SUCCESS);
187         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
188         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 4, 500000));
189         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 3));
190     }
191
192     @Test
193     public void test005() throws Exception {
194         String t = "005";
195         log.info("============== reserve " + t + " ================================");
196         log.info("=== Test successful response - change - check that hard limits are applied, not soft for change");
197
198         String service1 = "reserve" + t + "/service1";
199
200         dataSetup.cleanup();
201         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
202         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
203         dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
204
205         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
206
207         SvcLogicContext ctx = new SvcLogicContext();
208         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
209         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
210         ctx.setAttribute("tmp.resource-allocator.speed", "1200000");
211         ctx.setAttribute("tmp.resource-allocator.speed-unit", "kbps");
212         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
213
214         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
215
216         log.info("Result: " + st);
217         log.info("  tmp.resource-allocator-output.max-available-speed: " +
218                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
219         log.info("  tmp.resource-allocator-output.speed-unit: " +
220                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
221
222         Assert.assertTrue(st == QueryStatus.SUCCESS);
223         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
224         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 1200000));
225     }
226
227     @Test
228     public void test006() throws Exception {
229         String t = "006";
230         log.info("============== reserve " + t + " ================================");
231         log.info("=== Test capacity not found - new start");
232
233         String service1 = "reserve" + t + "/service1";
234
235         dataSetup.cleanup();
236         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
237         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
238
239         SvcLogicContext ctx = new SvcLogicContext();
240         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
241         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
242         ctx.setAttribute("tmp.resource-allocator.speed", "300");
243         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps");
244         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
245
246         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
247
248         log.info("Result: " + st);
249
250         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
251         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
252     }
253
254     @Test
255     public void test007() throws Exception {
256         String t = "007";
257         log.info("============== reserve " + t + " ================================");
258         log.info("=== Test capacity not found - new start supp");
259
260         String service1 = "reserve" + t + "/service1";
261
262         dataSetup.cleanup();
263         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
264         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
265         dataSetup.setupService(service1, "Pending", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
266
267         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 2, 200000));
268
269         SvcLogicContext ctx = new SvcLogicContext();
270         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
271         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
272         ctx.setAttribute("tmp.resource-allocator.speed", "2000");
273         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
274         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
275
276         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
277
278         log.info("Result: " + st);
279
280         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
281         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 2, 200000));
282         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 3));
283     }
284
285     @Test
286     public void test008() throws Exception {
287         String t = "008";
288         log.info("============== reserve " + t + " ================================");
289         log.info("=== Test capacity not found - change");
290
291         String service1 = "reserve" + t + "/service1";
292
293         dataSetup.cleanup();
294         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
295         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
296         dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
297
298         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
299
300         SvcLogicContext ctx = new SvcLogicContext();
301         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
302         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
303         ctx.setAttribute("tmp.resource-allocator.speed", "2000");
304         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
305         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
306
307         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
308
309         log.info("Result: " + st);
310
311         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
312         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
313         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 3));
314     }
315
316     @Test
317     public void test009() throws Exception {
318         String t = "009";
319         log.info("============== reserve " + t + " ================================");
320         log.info("=== Test capacity not found - change supp");
321
322         String service1 = "reserve" + t + "/service1";
323
324         dataSetup.cleanup();
325         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
326         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
327         dataSetup.setupService(service1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
328         dataSetup.setupService(service1, "Pending", 3, 400000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
329
330         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
331         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 400000));
332
333         SvcLogicContext ctx = new SvcLogicContext();
334         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
335         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
336         ctx.setAttribute("tmp.resource-allocator.speed", "2000");
337         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
338         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
339
340         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
341
342         log.info("Result: " + st);
343
344         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
345         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 200000));
346         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 400000));
347         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 4));
348     }
349
350     @Test
351     public void test010() throws Exception {
352         String t = "010";
353         log.info("============== reserve " + t + " ================================");
354         log.info("=== Test border condition - connection limit - new start - adding connection " +
355                 "when we are on the limit should fail");
356
357         String service1 = "reserve" + t + "/service1";
358
359         dataSetup.cleanup();
360         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
361         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
362         for (int i = 1; i <= 40; i++)
363             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Active", 2, 1000, "mtanjrsv126",
364                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
365         for (int i = 1; i <= 40; i += 4)
366             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Pending", 3, 1000, "mtanjrsv126",
367                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
368
369         SvcLogicContext ctx = new SvcLogicContext();
370         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
371         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
372         ctx.setAttribute("tmp.resource-allocator.speed", "1");
373         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
374         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
375
376         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
377
378         log.info("Result: " + st);
379
380         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
381         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
382     }
383
384     @Test
385     public void test011() throws Exception {
386         String t = "011";
387         log.info("============== reserve " + t + " ================================");
388         log.info(
389                 "=== Test border condition - connection limit - new start supp should succeed as no new connection being added");
390
391         String service1 = "reserve" + t + "/service1";
392
393         dataSetup.cleanup();
394         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
395         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
396         for (int i = 1; i <= 39; i++)
397             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Active", 2, 1000, "mtanjrsv126",
398                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
399         for (int i = 1; i <= 39; i += 4)
400             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Pending", 3, 1000, "mtanjrsv126",
401                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
402
403         dataSetup.setupService(service1, "Pending", 2, 1000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
404
405         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 2, 1000));
406
407         SvcLogicContext ctx = new SvcLogicContext();
408         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
409         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
410         ctx.setAttribute("tmp.resource-allocator.speed", "5");
411         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
412         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
413
414         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
415
416         log.info("Result: " + st);
417
418         Assert.assertTrue(st == QueryStatus.SUCCESS);
419         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 5000));
420         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 2));
421     }
422
423     @Test
424     public void test012() throws Exception {
425         String t = "012";
426         log.info("============== reserve " + t + " ================================");
427         log.info(
428                 "=== Test border condition - connection limit - change should succeed as no new connection being added");
429
430         String service1 = "reserve" + t + "/service1";
431
432         dataSetup.cleanup();
433         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
434         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
435         for (int i = 1; i <= 39; i++)
436             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Active", 2, 1000, "mtanjrsv126",
437                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
438         for (int i = 1; i <= 39; i += 4)
439             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Pending", 3, 1000, "mtanjrsv126",
440                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
441
442         dataSetup.setupService(service1, "Active", 2, 1000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
443
444         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 1000));
445
446         SvcLogicContext ctx = new SvcLogicContext();
447         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
448         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
449         ctx.setAttribute("tmp.resource-allocator.speed", "5");
450         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
451         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
452
453         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
454
455         log.info("Result: " + st);
456
457         Assert.assertTrue(st == QueryStatus.SUCCESS);
458         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 1000));
459         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 5000));
460     }
461
462     @Test
463     public void test013() throws Exception {
464         String t = "013";
465         log.info("============== reserve " + t + " ================================");
466         log.info(
467                 "=== Test border condition - connection limit - change supp should succeed as no new connection being added");
468
469         String service1 = "reserve" + t + "/service1";
470
471         dataSetup.cleanup();
472         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
473         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
474         for (int i = 1; i <= 39; i++)
475             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Active", 2, 1000, "mtanjrsv126",
476                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
477         for (int i = 1; i <= 39; i += 4)
478             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Pending", 3, 1000, "mtanjrsv126",
479                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
480
481         dataSetup.setupService(service1, "Active", 2, 1000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
482         dataSetup.setupService(service1, "Pending", 3, 5000, "mtanjrsv126", "mtsnj303vr1", "MTSNJA4LCP1/Server1");
483
484         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 1000));
485         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 3, 5000));
486
487         SvcLogicContext ctx = new SvcLogicContext();
488         ctx.setAttribute("tmp.resource-allocator.request-type", "Change");
489         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
490         ctx.setAttribute("tmp.resource-allocator.speed", "10");
491         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
492         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
493
494         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
495
496         log.info("Result: " + st);
497
498         Assert.assertTrue(st == QueryStatus.SUCCESS);
499         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Active", 2, 1000));
500         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 4, 10000));
501         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, 3));
502     }
503
504     @Test
505     public void test014() throws Exception {
506         String t = "014";
507         log.info("============== reserve " + t + " ================================");
508         log.info("=== Test input validations - invalid request-type in input");
509
510         String service1 = "reserve" + t + "/service1";
511
512         SvcLogicContext ctx = new SvcLogicContext();
513         ctx.setAttribute("tmp.resource-allocator.request-type", "xxxxx");
514         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
515         ctx.setAttribute("tmp.resource-allocator.speed", "10");
516         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
517         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
518
519         try {
520             resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
521         } catch (SvcLogicException e) {
522             Assert.assertTrue(e.getMessage().equals(
523                     "Invalid tmp.resource-allocator.request-type: xxxxx. Supported values are New, Change."));
524             return;
525         }
526         Assert.fail("SvcLogicException expected");
527     }
528
529     @Test
530     public void test015() throws Exception {
531         String t = "015";
532         log.info("============== reserve " + t + " ================================");
533         log.info("=== Test server bw limit depends on number of servers - limit is 960Mbps for 1 server, 1920 for 2");
534
535         String service1 = "reserve" + t + "/service1";
536
537         dataSetup.cleanup();
538         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
539         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
540         dataSetup.setupPserver("server1", "MTSNJA4LCP1");
541         dataSetup.setupPserver("server2", "MTSNJA4LCP1");
542         dataSetup.setupPserver("server3", "MTSNJA4LCP1");
543         dataSetup.setupPserver("server4", "MTSNJA4LCP1");
544
545         SvcLogicContext ctx = new SvcLogicContext();
546         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
547         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
548         ctx.setAttribute("tmp.resource-allocator.speed", "1200");
549         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
550         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
551
552         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
553
554         log.info("Result: " + st);
555         log.info("  tmp.resource-allocator-output.max-available-speed: " +
556                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
557         log.info("  tmp.resource-allocator-output.speed-unit: " +
558                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
559
560         Assert.assertTrue(st == QueryStatus.SUCCESS);
561         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 1, 1200000));
562     }
563
564     @Test
565     public void test016() throws Exception {
566         String t = "016";
567         log.info("============== reserve " + t + " ================================");
568         log.info("=== Test resource threshold output");
569
570         String service1 = "reserve" + t + "/service1";
571
572         dataSetup.cleanup();
573         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
574         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
575         dataSetup.setupPserver("server1", "MTSNJA4LCP1");
576         dataSetup.setupPserver("server2", "MTSNJA4LCP1");
577         dataSetup.setupPserver("server3", "MTSNJA4LCP1");
578         dataSetup.setupPserver("server4", "MTSNJA4LCP1");
579
580         SvcLogicContext ctx = new SvcLogicContext();
581         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
582         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
583         ctx.setAttribute("tmp.resource-allocator.speed", "1605");
584         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
585         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
586
587         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
588
589         log.info("Result: " + st);
590         for (String key : ctx.getAttributeKeySet())
591             if (key.startsWith("tmp.resource-allocator-output"))
592                 log.info("  " + key + ": " + ctx.getAttribute(key));
593
594         Assert.assertTrue(st == QueryStatus.SUCCESS);
595         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 1, 1605000));
596     }
597
598     @Test
599     public void test017() throws Exception {
600         String t = "017";
601         log.info("============== reserve " + t + " ================================");
602         log.info("=== Test if evc_count lookup in MAX_SERVER_SPEED depends on the number of primary servers.");
603         log.info("=== For 10 existing EVC, it should take the first row, not the second (see data.sql).");
604         log.info("=== Applied limit should be 1920Mbps, not 1680Mbps.");
605
606         String service1 = "reserve" + t + "/service1";
607
608         dataSetup.cleanup();
609         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
610         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
611         dataSetup.setupPserver("server1", "MTSNJA4LCP1");
612         dataSetup.setupPserver("server2", "MTSNJA4LCP1");
613         dataSetup.setupPserver("server3", "MTSNJA4LCP1");
614         dataSetup.setupPserver("server4", "MTSNJA4LCP1");
615
616         for (int i = 1; i <= 10; i++)
617             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Active", 2, 100000, "mtanjrsv126",
618                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
619
620         SvcLogicContext ctx = new SvcLogicContext();
621         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
622         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
623         ctx.setAttribute("tmp.resource-allocator.speed", "800"); // 10*100Mbps existing + 800 = 1800
624         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
625         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
626
627         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
628
629         log.info("Result: " + st);
630         log.info("  tmp.resource-allocator-output.max-available-speed: " +
631                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
632         log.info("  tmp.resource-allocator-output.speed-unit: " +
633                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
634
635         Assert.assertTrue(st == QueryStatus.SUCCESS);
636         Assert.assertTrue(dataSetup.serviceCorrectInDb("mtanjrsv126", "MTSNJA4LCP1", service1, "Pending", 1, 800000));
637     }
638
639     @Test
640     public void test018() throws Exception {
641         String t = "018";
642         log.info("============== reserve " + t + " ================================");
643         log.info("=== Test if evc_count lookup in MAX_SERVER_SPEED depends on the number of primary servers.");
644         log.info("=== For 11 existing EVC, it should take the second row (see data.sql).");
645         log.info("=== Applied limit should be 1680Mbps. We have 11*100 + 700, so this should fail.");
646
647         String service1 = "reserve" + t + "/service1";
648
649         dataSetup.cleanup();
650         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
651         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
652         dataSetup.setupPserver("server1", "MTSNJA4LCP1");
653         dataSetup.setupPserver("server2", "MTSNJA4LCP1");
654         dataSetup.setupPserver("server3", "MTSNJA4LCP1");
655         dataSetup.setupPserver("server4", "MTSNJA4LCP1");
656
657         for (int i = 1; i <= 11; i++)
658             dataSetup.setupService("reserve" + t + "/existing-service" + i, "Active", 2, 100000, "mtanjrsv126",
659                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
660
661         SvcLogicContext ctx = new SvcLogicContext();
662         ctx.setAttribute("tmp.resource-allocator.request-type", "New");
663         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
664         ctx.setAttribute("tmp.resource-allocator.speed", "700"); // 11*100Mbps existing + 700 = 1800
665         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
666         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
667
668         QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
669
670         log.info("Result: " + st);
671         log.info("  tmp.resource-allocator-output.max-available-speed: " +
672                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
673         log.info("  tmp.resource-allocator-output.speed-unit: " +
674                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
675
676         log.info("Result: " + st);
677
678         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
679         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
680     }
681 }