Mahesh Poojary S
Committed by Mahesh Poojary Huawei

[ONOS-4160] PCE REST

Change-Id: Iec0554190876c7363114c03aa5d2b25b42ade071
Showing 20 changed files with 337 additions and 362 deletions
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -21,6 +21,7 @@ import org.apache.karaf.shell.commands.Argument; ...@@ -21,6 +21,7 @@ import org.apache.karaf.shell.commands.Argument;
21 import org.apache.karaf.shell.commands.Command; 21 import org.apache.karaf.shell.commands.Command;
22 22
23 import org.onosproject.cli.AbstractShellCommand; 23 import org.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.incubator.net.tunnel.TunnelId;
24 import org.onosproject.pce.pceservice.api.PceService; 25 import org.onosproject.pce.pceservice.api.PceService;
25 26
26 import org.slf4j.Logger; 27 import org.slf4j.Logger;
...@@ -41,10 +42,9 @@ public class PceDeletePathCommand extends AbstractShellCommand { ...@@ -41,10 +42,9 @@ public class PceDeletePathCommand extends AbstractShellCommand {
41 42
42 PceService service = get(PceService.class); 43 PceService service = get(PceService.class);
43 44
44 - //TODO: need to uncomment below lines once releasePath method is added to PceService 45 + if (!service.releasePath(TunnelId.valueOf(id))) {
45 - //if (!service.releasePath(PcePathId.of(id))) { 46 + error("Path deletion failed.");
46 - // error("Path deletion failed."); 47 + return;
47 - // return; 48 + }
48 - //}
49 } 49 }
50 } 50 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -22,6 +22,7 @@ import org.apache.karaf.shell.commands.Option; ...@@ -22,6 +22,7 @@ import org.apache.karaf.shell.commands.Option;
22 22
23 import org.onosproject.cli.AbstractShellCommand; 23 import org.onosproject.cli.AbstractShellCommand;
24 import org.onosproject.incubator.net.tunnel.Tunnel; 24 import org.onosproject.incubator.net.tunnel.Tunnel;
25 +import org.onosproject.incubator.net.tunnel.TunnelId;
25 import org.onosproject.net.AnnotationKeys; 26 import org.onosproject.net.AnnotationKeys;
26 import org.onosproject.pce.pceservice.api.PceService; 27 import org.onosproject.pce.pceservice.api.PceService;
27 28
...@@ -45,8 +46,7 @@ public class PceQueryPathCommand extends AbstractShellCommand { ...@@ -45,8 +46,7 @@ public class PceQueryPathCommand extends AbstractShellCommand {
45 46
46 PceService service = get(PceService.class); 47 PceService service = get(PceService.class);
47 if (null == id) { 48 if (null == id) {
48 - //TODO: need to uncomment below line once queryAllPath method is added to PceService 49 + Iterable<Tunnel> tunnels = service.queryAllPath();
49 - Iterable<Tunnel> tunnels = null; // = service.queryAllPath();
50 if (tunnels != null) { 50 if (tunnels != null) {
51 for (final Tunnel tunnel : tunnels) { 51 for (final Tunnel tunnel : tunnels) {
52 display(tunnel); 52 display(tunnel);
...@@ -56,8 +56,7 @@ public class PceQueryPathCommand extends AbstractShellCommand { ...@@ -56,8 +56,7 @@ public class PceQueryPathCommand extends AbstractShellCommand {
56 return; 56 return;
57 } 57 }
58 } else { 58 } else {
59 - //TODO: need to uncomment below line once queryPath method is added to PceService 59 + Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
60 - Tunnel tunnel = null; // = service.queryPath(PcePathId.of(id));
61 if (tunnel == null) { 60 if (tunnel == null) {
62 print("Path doesnot exists."); 61 print("Path doesnot exists.");
63 return; 62 return;
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -86,9 +86,8 @@ public class PceSetupPathCommand extends AbstractShellCommand { ...@@ -86,9 +86,8 @@ public class PceSetupPathCommand extends AbstractShellCommand {
86 //listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS"))); 86 //listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
87 } 87 }
88 88
89 - //TODO: need to uncomment below lines once setupPath method is modified in PceService 89 + if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
90 - //if (null == service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) { 90 + error("Path creation failed.");
91 - // error("Path creation failed."); 91 + }
92 - //}
93 } 92 }
94 } 93 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
......
...@@ -244,12 +244,14 @@ public final class DefaultPcePath implements PcePath { ...@@ -244,12 +244,14 @@ public final class DefaultPcePath implements PcePath {
244 this.id = TunnelId.valueOf(tunnel.tunnelId().id()); 244 this.id = TunnelId.valueOf(tunnel.tunnelId().id());
245 this.source = tunnel.src().toString(); 245 this.source = tunnel.src().toString();
246 this.destination = tunnel.dst().toString(); 246 this.destination = tunnel.dst().toString();
247 - //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys 247 + //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys.
248 - this.lspType = null; // = LspType.valueOf(tunnel.annotations().value(AnnotationKeys.LSP_SIG_TYPE)); 248 + this.lspType = null; // = LspType.valueOf(tunnel.annotations()
249 + //.value(AnnotationKeys.LSP_SIG_TYPE));
249 this.name = tunnel.tunnelName().toString(); 250 this.name = tunnel.tunnelName().toString();
250 - this.costConstraint = null; //CostConstraint.of(tunnel.path().cost()); 251 + //TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint classes are ready
251 - this.bandwidthConstraint = null; 252 + this.costConstraint = null; // = CostConstraint.of(tunnel.path().cost());
252 - //LocalBandwidthConstraint.of(tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); 253 + this.bandwidthConstraint = null; // = LocalBandwidthConstraint.of(tunnel.annotations()
254 + //.value(AnnotationKeys.BANDWIDTH));
253 return this; 255 return this;
254 } 256 }
255 257
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.pce.web; 16 +package org.onosproject.pce.rest;
17 17
18 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.pce.web; 16 +package org.onosproject.pce.rest;
17 17
18 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 19
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.pce.web; 16 +package org.onosproject.pce.rest;
17 17
18 import static javax.ws.rs.core.Response.Status.OK; 18 import static javax.ws.rs.core.Response.Status.OK;
19 +import static org.onlab.util.Tools.nullIsNotFound;
19 20
20 import java.io.IOException; 21 import java.io.IOException;
21 import java.io.InputStream; 22 import java.io.InputStream;
...@@ -34,8 +35,10 @@ import javax.ws.rs.core.MediaType; ...@@ -34,8 +35,10 @@ import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response; 35 import javax.ws.rs.core.Response;
35 36
36 import org.onosproject.incubator.net.tunnel.Tunnel; 37 import org.onosproject.incubator.net.tunnel.Tunnel;
38 +import org.onosproject.incubator.net.tunnel.TunnelId;
37 import org.onosproject.net.DeviceId; 39 import org.onosproject.net.DeviceId;
38 import org.onosproject.net.intent.Constraint; 40 import org.onosproject.net.intent.Constraint;
41 +import org.onosproject.pce.pceservice.api.PceService;
39 import org.onosproject.pce.pceservice.PcePath; 42 import org.onosproject.pce.pceservice.PcePath;
40 import org.onosproject.pce.pceservice.DefaultPcePath; 43 import org.onosproject.pce.pceservice.DefaultPcePath;
41 import org.onosproject.pce.pceservice.LspType; 44 import org.onosproject.pce.pceservice.LspType;
...@@ -58,6 +61,7 @@ public class PcePathWebResource extends AbstractWebResource { ...@@ -58,6 +61,7 @@ public class PcePathWebResource extends AbstractWebResource {
58 public static final String PCE_PATH_NOT_FOUND = "Path not found"; 61 public static final String PCE_PATH_NOT_FOUND = "Path not found";
59 public static final String PCE_PATH_ID_EXIST = "Path exists"; 62 public static final String PCE_PATH_ID_EXIST = "Path exists";
60 public static final String PCE_PATH_ID_NOT_EXIST = "Path does not exist for the identifier"; 63 public static final String PCE_PATH_ID_NOT_EXIST = "Path does not exist for the identifier";
64 + public static final String PCE_SETUP_PATH_FAILED = "PCE Setup path has failed.";
61 65
62 /** 66 /**
63 * Retrieve details of all paths created. 67 * Retrieve details of all paths created.
...@@ -68,8 +72,7 @@ public class PcePathWebResource extends AbstractWebResource { ...@@ -68,8 +72,7 @@ public class PcePathWebResource extends AbstractWebResource {
68 @Produces(MediaType.APPLICATION_JSON) 72 @Produces(MediaType.APPLICATION_JSON)
69 public Response queryAllPath() { 73 public Response queryAllPath() {
70 log.debug("Query all paths."); 74 log.debug("Query all paths.");
71 - //TODO: need to uncomment below line once queryAllPath method is added to PceService 75 + Iterable<Tunnel> tunnels = get(PceService.class).queryAllPath();
72 - Iterable<Tunnel> tunnels = null; // = get(PceService.class).queryAllPath();
73 ObjectNode result = mapper().createObjectNode(); 76 ObjectNode result = mapper().createObjectNode();
74 ArrayNode pathEntry = result.putArray("paths"); 77 ArrayNode pathEntry = result.putArray("paths");
75 if (tunnels != null) { 78 if (tunnels != null) {
...@@ -92,9 +95,8 @@ public class PcePathWebResource extends AbstractWebResource { ...@@ -92,9 +95,8 @@ public class PcePathWebResource extends AbstractWebResource {
92 @Produces(MediaType.APPLICATION_JSON) 95 @Produces(MediaType.APPLICATION_JSON)
93 public Response queryPath(@PathParam("path_id") String id) { 96 public Response queryPath(@PathParam("path_id") String id) {
94 log.debug("Query path by identifier {}.", id); 97 log.debug("Query path by identifier {}.", id);
95 - //TODO: need to uncomment below lines once queryPath method is added to PceService 98 + Tunnel tunnel = nullIsNotFound(get(PceService.class).queryPath(TunnelId.valueOf(id)),
96 - Tunnel tunnel = null; // = nullIsNotFound(get(PceService.class).queryPath(PcePathId.of(id)), 99 + PCE_PATH_NOT_FOUND);
97 - //PCE_PATH_NOT_FOUND);
98 PcePath path = DefaultPcePath.builder().of(tunnel).build(); 100 PcePath path = DefaultPcePath.builder().of(tunnel).build();
99 ObjectNode result = mapper().createObjectNode(); 101 ObjectNode result = mapper().createObjectNode();
100 result.set("path", codec(PcePath.class).encode(path, this)); 102 result.set("path", codec(PcePath.class).encode(path, this));
...@@ -131,9 +133,9 @@ public class PcePathWebResource extends AbstractWebResource { ...@@ -131,9 +133,9 @@ public class PcePathWebResource extends AbstractWebResource {
131 //listConstrnt.add(LocalBandwidthConstraint.of(Double.valueOf(path.constraint().bandwidth()), DataRateUnit 133 //listConstrnt.add(LocalBandwidthConstraint.of(Double.valueOf(path.constraint().bandwidth()), DataRateUnit
132 // .valueOf("BPS"))); 134 // .valueOf("BPS")));
133 135
134 - //TODO: need to uncomment below lines once setupPath method is modified in PceService 136 + Boolean issuccess = nullIsNotFound(get(PceService.class)
135 - Boolean issuccess = true; // = (null != get(PceService.class) 137 + .setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType),
136 - //.setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType)) ? true : false; 138 + PCE_SETUP_PATH_FAILED);
137 return Response.status(OK).entity(issuccess.toString()).build(); 139 return Response.status(OK).entity(issuccess.toString()).build();
138 } catch (IOException e) { 140 } catch (IOException e) {
139 log.error("Exception while creating path {}.", e.toString()); 141 log.error("Exception while creating path {}.", e.toString());
...@@ -174,9 +176,8 @@ public class PcePathWebResource extends AbstractWebResource { ...@@ -174,9 +176,8 @@ public class PcePathWebResource extends AbstractWebResource {
174 // .of(path.constraint().bandwidth(), DataRateUnit.valueOf("BPS"))); 176 // .of(path.constraint().bandwidth(), DataRateUnit.valueOf("BPS")));
175 } 177 }
176 178
177 - //TODO: need to uncomment below line once updatePath is added to PceService 179 + Boolean result = nullIsNotFound(get(PceService.class).updatePath(TunnelId.valueOf(id), constrntList),
178 - Boolean result = true; // = (null != (get(PceService.class).updatePath(PcePathId.of(id), constrntList))) 180 + PCE_PATH_NOT_FOUND);
179 - //? true : false;
180 return Response.status(OK).entity(result.toString()).build(); 181 return Response.status(OK).entity(result.toString()).build();
181 } catch (IOException e) { 182 } catch (IOException e) {
182 log.error("Update path failed because of exception {}.", e.toString()); 183 log.error("Update path failed because of exception {}.", e.toString());
...@@ -195,9 +196,8 @@ public class PcePathWebResource extends AbstractWebResource { ...@@ -195,9 +196,8 @@ public class PcePathWebResource extends AbstractWebResource {
195 public Response releasePath(@PathParam("path_id") String id) { 196 public Response releasePath(@PathParam("path_id") String id) {
196 log.debug("Deletes path by identifier {}.", id); 197 log.debug("Deletes path by identifier {}.", id);
197 198
198 - //TODO: need to uncomment below lines once releasePath method is added to PceService 199 + Boolean isSuccess = nullIsNotFound(get(PceService.class).releasePath(TunnelId.valueOf(id)),
199 - Boolean isSuccess = true; // = nullIsNotFound(get(PceService.class).releasePath(PcePathId.of(id)), 200 + PCE_PATH_NOT_FOUND);
200 - //PCE_PATH_NOT_FOUND);
201 if (!isSuccess) { 201 if (!isSuccess) {
202 log.debug("Path identifier {} does not exist", id); 202 log.debug("Path identifier {} does not exist", id);
203 } 203 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.pce.web; 17 +package org.onosproject.pce.rest;
18 18
19 import org.onlab.rest.AbstractWebApplication; 19 import org.onlab.rest.AbstractWebApplication;
20 20
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
17 /** 17 /**
18 * PCE rest application. 18 * PCE rest application.
19 */ 19 */
20 -package org.onosproject.pce.web; 20 +package org.onosproject.pce.rest;
......
1 <!-- 1 <!--
2 - ~ Copyright 2016 Open Networking Laboratory 2 + ~ Copyright 2016-present Open Networking Laboratory
3 ~ 3 ~
4 ~ Licensed under the Apache License, Version 2.0 (the "License"); 4 ~ Licensed under the Apache License, Version 2.0 (the "License");
5 ~ you may not use this file except in compliance with the License. 5 ~ you may not use this file except in compliance with the License.
......
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- 2 <!--
3 - ~ Copyright 2016 Open Networking Laboratory 3 + ~ Copyright 2016-present Open Networking Laboratory
4 ~ 4 ~
5 ~ Licensed under the Apache License, Version 2.0 (the "License"); 5 ~ Licensed under the Apache License, Version 2.0 (the "License");
6 ~ you may not use this file except in compliance with the License. 6 ~ you may not use this file except in compliance with the License.
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
25 <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 25 <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
26 <init-param> 26 <init-param>
27 <param-name>javax.ws.rs.Application</param-name> 27 <param-name>javax.ws.rs.Application</param-name>
28 - <param-value>org.onosproject.pce.web.PceWebApplication</param-value> 28 + <param-value>org.onosproject.pce.rest.PceWebApplication</param-value>
29 </init-param> 29 </init-param>
30 <load-on-startup>1</load-on-startup> 30 <load-on-startup>1</load-on-startup>
31 </servlet> 31 </servlet>
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.pce.web; 16 +package org.onosproject.pce.rest;
17 17
18 import org.onosproject.codec.CodecContext; 18 import org.onosproject.codec.CodecContext;
19 import org.onosproject.codec.CodecService; 19 import org.onosproject.codec.CodecService;
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.pce.web; 16 +package org.onosproject.pce.rest;
17 17
18 import static org.hamcrest.MatcherAssert.assertThat; 18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is; 19 import static org.hamcrest.Matchers.is;
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pce.rest;
17 +
18 +import static org.easymock.EasyMock.anyObject;
19 +import static org.easymock.EasyMock.createMock;
20 +import static org.easymock.EasyMock.expect;
21 +import static org.easymock.EasyMock.replay;
22 +import static org.hamcrest.Matchers.containsString;
23 +import static org.hamcrest.Matchers.is;
24 +//TODO: below imports needs to be uncommented once TODO in DefaultPcePath class are removed
25 +//import static org.hamcrest.Matchers.notNullValue;
26 +import static org.junit.Assert.assertThat;
27 +import static org.junit.Assert.fail;
28 +
29 +import static org.onosproject.net.Link.Type.DIRECT;
30 +
31 +//import com.eclipsesource.json.Json;
32 +//import com.eclipsesource.json.JsonObject;
33 +
34 +import java.io.InputStream;
35 +import java.net.HttpURLConnection;
36 +import java.util.LinkedList;
37 +import java.util.List;
38 +import javax.ws.rs.client.Entity;
39 +import javax.ws.rs.client.WebTarget;
40 +import javax.ws.rs.core.MediaType;
41 +import javax.ws.rs.core.Response;
42 +import javax.ws.rs.NotFoundException;
43 +
44 +import org.junit.After;
45 +import org.junit.Before;
46 +import org.junit.Test;
47 +
48 +import org.onlab.osgi.ServiceDirectory;
49 +import org.onlab.osgi.TestServiceDirectory;
50 +import org.onlab.packet.IpAddress;
51 +import org.onlab.rest.BaseResource;
52 +import org.onosproject.codec.CodecService;
53 +import org.onosproject.core.DefaultGroupId;
54 +import org.onosproject.incubator.net.tunnel.DefaultTunnel;
55 +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
56 +import org.onosproject.incubator.net.tunnel.Tunnel;
57 +import org.onosproject.incubator.net.tunnel.TunnelId;
58 +import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
59 +import org.onosproject.incubator.net.tunnel.TunnelName;
60 +import org.onosproject.net.ConnectPoint;
61 +import org.onosproject.net.DefaultAnnotations;
62 +import org.onosproject.net.DefaultLink;
63 +import org.onosproject.net.DefaultPath;
64 +import org.onosproject.net.DeviceId;
65 +import org.onosproject.net.Link;
66 +import org.onosproject.pce.pceservice.api.PceService;
67 +import org.onosproject.net.Path;
68 +import org.onosproject.net.PortNumber;
69 +import org.onosproject.net.provider.ProviderId;
70 +
71 +/**
72 + * Unit tests for pce path REST APIs.
73 + */
74 +public class PcePathResourceTest extends PceResourceTest {
75 + private final PceService pceService = createMock(PceService.class);
76 + private final TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423));
77 + private final TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421));
78 + private final DefaultGroupId groupId = new DefaultGroupId(92034);
79 + private final TunnelName tunnelName = TunnelName.tunnelName("TunnelName");
80 + private final TunnelId tunnelId = TunnelId.valueOf("41654654");
81 + private final ProviderId producerName = new ProviderId("producer1", "13");
82 + private Path path;
83 + private Tunnel tunnel;
84 + private DeviceId deviceId1;
85 + private DeviceId deviceId2;
86 + private DeviceId deviceId3;
87 + private DeviceId deviceId4;
88 + private DeviceId deviceId5;
89 + private PortNumber port1;
90 + private PortNumber port2;
91 + private PortNumber port3;
92 + private PortNumber port4;
93 + private PortNumber port5;
94 +
95 + /**
96 + * Sets up the global values for all the tests.
97 + */
98 + @Before
99 + public void setUpTest() {
100 + // Mock environment setup
101 + MockPceCodecContext context = new MockPceCodecContext();
102 + ServiceDirectory testDirectory = new TestServiceDirectory().add(PceService.class, pceService)
103 + .add(CodecService.class, context.codecManager());
104 + BaseResource.setServiceDirectory(testDirectory);
105 +
106 + // Tunnel creation
107 + // Links
108 + ProviderId providerId = new ProviderId("of", "foo");
109 + deviceId1 = DeviceId.deviceId("of:A");
110 + deviceId2 = DeviceId.deviceId("of:B");
111 + deviceId3 = DeviceId.deviceId("of:C");
112 + deviceId4 = DeviceId.deviceId("of:D");
113 + deviceId5 = DeviceId.deviceId("of:E");
114 + port1 = PortNumber.portNumber(1);
115 + port2 = PortNumber.portNumber(2);
116 + port3 = PortNumber.portNumber(3);
117 + port4 = PortNumber.portNumber(4);
118 + port5 = PortNumber.portNumber(5);
119 + List<Link> linkList = new LinkedList<>();
120 +
121 + Link l1 = DefaultLink.builder()
122 + .providerId(providerId)
123 + .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
124 + .src(new ConnectPoint(deviceId1, port1))
125 + .dst(new ConnectPoint(deviceId2, port2))
126 + .type(DIRECT)
127 + .state(Link.State.ACTIVE)
128 + .build();
129 + linkList.add(l1);
130 + Link l2 = DefaultLink.builder()
131 + .providerId(providerId)
132 + .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
133 + .src(new ConnectPoint(deviceId2, port2))
134 + .dst(new ConnectPoint(deviceId3, port3))
135 + .type(DIRECT)
136 + .state(Link.State.ACTIVE)
137 + .build();
138 + linkList.add(l2);
139 + Link l3 = DefaultLink.builder()
140 + .providerId(providerId)
141 + .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
142 + .src(new ConnectPoint(deviceId3, port3))
143 + .dst(new ConnectPoint(deviceId4, port4))
144 + .type(DIRECT)
145 + .state(Link.State.ACTIVE)
146 + .build();
147 + linkList.add(l3);
148 + Link l4 = DefaultLink.builder()
149 + .providerId(providerId)
150 + .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
151 + .src(new ConnectPoint(deviceId4, port4))
152 + .dst(new ConnectPoint(deviceId5, port5))
153 + .type(DIRECT)
154 + .state(Link.State.ACTIVE)
155 + .build();
156 + linkList.add(l4);
157 +
158 + // Path
159 + path = new DefaultPath(providerId, linkList, 10);
160 +
161 + // Tunnel
162 + tunnel = new DefaultTunnel(producerName, src, dst, Tunnel.Type.VXLAN,
163 + Tunnel.State.ACTIVE, groupId, tunnelId,
164 + tunnelName, path);
165 + }
166 +
167 + /**
168 + * Cleans up.
169 + */
170 + @After
171 + public void tearDownTest() {
172 + }
173 +
174 + /**
175 + * Tests the result of the rest api GET when there are no pce paths.
176 + */
177 + @Test
178 + public void testPcePathsEmpty() {
179 + expect(pceService.queryAllPath())
180 + .andReturn(null)
181 + .anyTimes();
182 + replay(pceService);
183 + WebTarget wt = target();
184 + String response = wt.path("path").request().get(String.class);
185 + assertThat(response, is("{\"paths\":[]}"));
186 + }
187 +
188 + /**
189 + * Tests the result of a rest api GET for pce path id.
190 + */
191 + @Test
192 + public void testGetTunnelId() {
193 + //TODO: uncomment below lines once TODO in DefaultPcePath class are removed
194 + //expect(pceService.queryPath(anyObject()))
195 + // .andReturn(tunnel)
196 + // .anyTimes();
197 + //replay(pceService);
198 +
199 + //WebTarget wt = target();
200 + //String response = wt.path("path/1").request().get(String.class);
201 + //JsonObject result = Json.parse(response).asObject();
202 + //assertThat(result, notNullValue());
203 + }
204 +
205 + /**
206 + * Tests that a fetch of a non-existent pce path object throws an exception.
207 + */
208 + @Test
209 + public void testBadGet() {
210 + expect(pceService.queryPath(anyObject()))
211 + .andReturn(null)
212 + .anyTimes();
213 + replay(pceService);
214 +
215 + WebTarget wt = target();
216 + try {
217 + wt.path("path/1").request().get(String.class);
218 + fail("Fetch of non-existent pce path did not throw an exception");
219 + } catch (NotFoundException ex) {
220 + assertThat(ex.getMessage(), containsString("HTTP 404 Not Found"));
221 + }
222 + }
223 +
224 + /**
225 + * Tests creating a pce path with POST.
226 + */
227 + @Test
228 + public void testPost() {
229 + expect(pceService.setupPath(anyObject(), anyObject(), anyObject(), anyObject(), anyObject()))
230 + .andReturn(true)
231 + .anyTimes();
232 + replay(pceService);
233 +
234 + WebTarget wt = target();
235 + InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
236 +
237 + Response response = wt.path("path")
238 + .request(MediaType.APPLICATION_JSON_TYPE)
239 + .post(Entity.json(jsonStream));
240 + assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
241 + }
242 +
243 + /**
244 + * Tests creating a pce path with PUT.
245 + */
246 + @Test
247 + public void testPut() {
248 + expect(pceService.updatePath(anyObject(), anyObject()))
249 + .andReturn(true)
250 + .anyTimes();
251 + replay(pceService);
252 +
253 + WebTarget wt = target();
254 + InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
255 +
256 + Response response = wt.path("path/1")
257 + .request(MediaType.APPLICATION_JSON_TYPE)
258 + .put(Entity.json(jsonStream));
259 + assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
260 + }
261 +
262 + /**
263 + * Tests deleting a pce path.
264 + */
265 + @Test
266 + public void testDelete() {
267 + expect(pceService.releasePath(anyObject()))
268 + .andReturn(true)
269 + .anyTimes();
270 + replay(pceService);
271 +
272 + WebTarget wt = target();
273 +
274 + String location = "path/1";
275 +
276 + Response deleteResponse = wt.path(location)
277 + .request(MediaType.APPLICATION_JSON_TYPE)
278 + .delete();
279 + assertThat(deleteResponse.getStatus(), is(HttpURLConnection.HTTP_OK));
280 + }
281 +}
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.pce.web; 16 +package org.onosproject.pce.rest;
17 17
18 import org.glassfish.jersey.server.ResourceConfig; 18 import org.glassfish.jersey.server.ResourceConfig;
19 import org.glassfish.jersey.test.JerseyTest; 19 import org.glassfish.jersey.test.JerseyTest;
......
1 -/*
2 - * Copyright 2016 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.pce.web;
17 -
18 -//import static org.easymock.EasyMock.anyObject;
19 -import static org.easymock.EasyMock.createMock;
20 -//import static org.easymock.EasyMock.expect;
21 -//import static org.easymock.EasyMock.replay;
22 -//import static org.hamcrest.Matchers.containsString;
23 -//import static org.hamcrest.Matchers.is;
24 -//import static org.hamcrest.Matchers.notNullValue;
25 -//import static org.junit.Assert.assertThat;
26 -//import static org.junit.Assert.fail;
27 -
28 -//import javax.ws.rs.NotFoundException;
29 -//import javax.ws.rs.client.Entity;
30 -//import javax.ws.rs.client.WebTarget;
31 -//import javax.ws.rs.core.MediaType;
32 -//import javax.ws.rs.core.Response;
33 -//import java.io.InputStream;
34 -//import java.net.HttpURLConnection;
35 -//import java.util.HashSet;
36 -//import java.util.List;
37 -//import java.util.Objects;
38 -//import java.util.Optional;
39 -//import java.util.Set;
40 -
41 -//import com.eclipsesource.json.Json;
42 -//import com.eclipsesource.json.JsonObject;
43 -//import com.google.common.collect.ImmutableList;
44 -//import com.google.common.collect.Lists;
45 -
46 -import org.junit.After;
47 -import org.junit.Before;
48 -import org.junit.Test;
49 -import org.onlab.osgi.ServiceDirectory;
50 -import org.onlab.osgi.TestServiceDirectory;
51 -import org.onlab.rest.BaseResource;
52 -import org.onosproject.codec.CodecService;
53 -import org.onosproject.incubator.net.tunnel.TunnelId;
54 -import org.onosproject.net.intent.Constraint;
55 -import org.onosproject.pce.pceservice.PcePath;
56 -import org.onosproject.pce.pceservice.LspType;
57 -import org.onosproject.pce.pceservice.api.PceService;
58 -
59 -/**
60 - * Unit tests for pce path REST APIs.
61 - */
62 -public class PcePathResourceTest extends PceResourceTest {
63 - final PceService pceService = createMock(PceService.class);
64 - final TunnelId pcePathId1 = TunnelId.valueOf("1");
65 - //TODO: will be uncommented below lines once CostConstraint and LocalBandwidthConstraint classes are ready
66 - final Constraint costConstraint = null; //CostConstraint.of("2");
67 - final Constraint bandwidthConstraint = null; //LocalBandwidthConstraint.of("200.0");
68 - final LspType lspType = LspType.WITH_SIGNALLING;
69 - final MockPcePath pcePath1 = new MockPcePath(pcePathId1, "11.0.0.1", "11.0.0.2", lspType, "pcc2",
70 - costConstraint, bandwidthConstraint);
71 -
72 - /**
73 - * Mock class for a pce path.
74 - */
75 - private static class MockPcePath implements PcePath {
76 - private TunnelId id;
77 - private String source;
78 - private String destination;
79 - private LspType lspType;
80 - private String name;
81 - private Constraint costConstraint;
82 - private Constraint bandwidthConstraint;
83 -
84 - /**
85 - * Constructor to initialize member variables.
86 - *
87 - * @param id pce path id
88 - * @param src source device
89 - * @param dst destination device
90 - * @param type lsp type
91 - * @param name symbolic path name
92 - * @param constrnt pce constraint
93 - */
94 - public MockPcePath(TunnelId id, String src, String dst, LspType type, String name,
95 - Constraint costConstrnt, Constraint bandwidthConstrnt) {
96 - this.id = id;
97 - this.source = src;
98 - this.destination = dst;
99 - this.name = name;
100 - this.lspType = type;
101 - this.costConstraint = costConstrnt;
102 - this.bandwidthConstraint = bandwidthConstrnt;
103 - }
104 -
105 - @Override
106 - public TunnelId id() {
107 - return id;
108 - }
109 -
110 - @Override
111 - public void id(TunnelId id) {
112 - this.id = id;
113 - }
114 -
115 - @Override
116 - public String source() {
117 - return source;
118 - }
119 -
120 - @Override
121 - public void source(String src) {
122 - this.source = src;
123 - }
124 -
125 - @Override
126 - public String destination() {
127 - return destination;
128 - }
129 -
130 - @Override
131 - public void destination(String dst) {
132 - this.destination = dst;
133 - }
134 -
135 - @Override
136 - public LspType lspType() {
137 - return lspType;
138 - }
139 -
140 - @Override
141 - public String name() {
142 - return name;
143 - }
144 -
145 - @Override
146 - public Constraint costConstraint() {
147 - return costConstraint;
148 - }
149 -
150 - @Override
151 - public Constraint bandwidthConstraint() {
152 - return bandwidthConstraint;
153 - }
154 -
155 - @Override
156 - public PcePath copy(PcePath path) {
157 - if (null != path.source()) {
158 - this.source = path.source();
159 - }
160 - if (null != path.destination()) {
161 - this.destination = path.destination();
162 - }
163 - if (this.lspType != path.lspType()) {
164 - this.lspType = path.lspType();
165 - }
166 - if (null != path.name()) {
167 - this.name = path.name();
168 - }
169 - if (null != path.costConstraint()) {
170 - this.costConstraint = path.costConstraint();
171 - }
172 - if (null != path.bandwidthConstraint()) {
173 - this.bandwidthConstraint = path.bandwidthConstraint();
174 - }
175 - return this;
176 - }
177 - }
178 -
179 - /**
180 - * Sets up the global values for all the tests.
181 - */
182 - @Before
183 - public void setUpTest() {
184 - MockPceCodecContext context = new MockPceCodecContext();
185 - ServiceDirectory testDirectory = new TestServiceDirectory().add(PceService.class, pceService)
186 - .add(CodecService.class, context.codecManager());
187 - BaseResource.setServiceDirectory(testDirectory);
188 - }
189 -
190 - /**
191 - * Cleans up.
192 - */
193 - @After
194 - public void tearDownTest() {
195 - }
196 -
197 - /**
198 - * Tests the result of the rest api GET when there are no pce paths.
199 - */
200 - @Test
201 - public void testPcePathsEmpty() {
202 - //TODO: will be uncommented below code once PceService is ready
203 - //expect(pceService.queryAllPath()).andReturn(null).anyTimes();
204 - //replay(pceService);
205 - //final WebTarget wt = target();
206 - //final String response = wt.path("path").request().get(String.class);
207 - //assertThat(response, is("{\"paths\":[]}"));
208 - }
209 -
210 - /**
211 - * Tests the result of a rest api GET for pce path id.
212 - */
213 - @Test
214 - public void testGetTunnelId() {
215 - //TODO: will be uncommented below code once PceService is ready
216 - //final Set<PcePath> pcePaths = new HashSet<>();
217 - //pcePaths.add(pcePath1);
218 -
219 - //expect(pceService.queryPath(anyObject())).andReturn(pcePath1).anyTimes();
220 - //replay(pceService);
221 -
222 - //final WebTarget wt = target();
223 - //final String response = wt.path("path/1").request().get(String.class);
224 - //final JsonObject result = Json.parse(response).asObject();
225 - //assertThat(result, notNullValue());
226 - }
227 -
228 - /**
229 - * Tests that a fetch of a non-existent pce path object throws an exception.
230 - */
231 - @Test
232 - public void testBadGet() {
233 - //TODO: will be uncommented below code once PceService is ready
234 - //expect(pceService.queryPath(anyObject()))
235 - // .andReturn(null).anyTimes();
236 - //replay(pceService);
237 -
238 - //WebTarget wt = target();
239 - //try {
240 - // wt.path("path/1").request().get(String.class);
241 - // fail("Fetch of non-existent pce path did not throw an exception");
242 - //} catch (NotFoundException ex) {
243 - // assertThat(ex.getMessage(),
244 - // containsString("HTTP 404 Not Found"));
245 - //}
246 - }
247 -
248 - /**
249 - * Tests creating a pce path with POST.
250 - */
251 - @Test
252 - public void testPost() {
253 - //TODO: will be uncommented below code once PceService is ready
254 - //expect(pceService.setupPath(anyObject()))
255 - // .andReturn(true).anyTimes();
256 - //replay(pceService);
257 -
258 - //WebTarget wt = target();
259 - //InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
260 -
261 - //Response response = wt.path("path")
262 - // .request(MediaType.APPLICATION_JSON_TYPE)
263 - // .post(Entity.json(jsonStream));
264 - //assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
265 - }
266 -
267 - /**
268 - * Tests creating a pce path with PUT.
269 - */
270 - @Test
271 - public void testPut() {
272 - //TODO: will be uncommented below code once PceService is ready
273 - //expect(pceService.updatePath(anyObject()))
274 - // .andReturn(true).anyTimes();
275 - //replay(pceService);
276 -
277 - //WebTarget wt = target();
278 - //InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
279 -
280 - //Response response = wt.path("path/1")
281 - // .request(MediaType.APPLICATION_JSON_TYPE)
282 - // .put(Entity.json(jsonStream));
283 - //assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
284 - }
285 -
286 - /**
287 - * Tests deleting a pce path.
288 - */
289 - @Test
290 - public void testDelete() {
291 - //TODO: will be uncommented below code once PceService is ready
292 - //expect(pceService.releasePath(anyObject()))
293 - // .andReturn(true).anyTimes();
294 - //replay(pceService);
295 -
296 - //WebTarget wt = target();
297 -
298 - //String location = "path/1";
299 -
300 - //Response deleteResponse = wt.path(location)
301 - // .request(MediaType.APPLICATION_JSON_TYPE)
302 - // .delete();
303 - //assertThat(deleteResponse.getStatus(),
304 - // is(HttpURLConnection.HTTP_OK));
305 - }
306 -}