[ONOS-4160] PCE REST
Change-Id: Iec0554190876c7363114c03aa5d2b25b42ade071
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
index 012fd28..2f0be92 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.pce.pceservice.api.PceService;
import org.slf4j.Logger;
@@ -41,10 +42,9 @@
PceService service = get(PceService.class);
- //TODO: need to uncomment below lines once releasePath method is added to PceService
- //if (!service.releasePath(PcePathId.of(id))) {
- // error("Path deletion failed.");
- // return;
- //}
+ if (!service.releasePath(TunnelId.valueOf(id))) {
+ error("Path deletion failed.");
+ return;
+ }
}
}
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
index b7dc3a9..32323fa 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.pce.pceservice.api.PceService;
@@ -45,8 +46,7 @@
PceService service = get(PceService.class);
if (null == id) {
- //TODO: need to uncomment below line once queryAllPath method is added to PceService
- Iterable<Tunnel> tunnels = null; // = service.queryAllPath();
+ Iterable<Tunnel> tunnels = service.queryAllPath();
if (tunnels != null) {
for (final Tunnel tunnel : tunnels) {
display(tunnel);
@@ -56,8 +56,7 @@
return;
}
} else {
- //TODO: need to uncomment below line once queryPath method is added to PceService
- Tunnel tunnel = null; // = service.queryPath(PcePathId.of(id));
+ Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
if (tunnel == null) {
print("Path doesnot exists.");
return;
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
index 5bf13ff..497905f 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,9 +86,8 @@
//listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
}
- //TODO: need to uncomment below lines once setupPath method is modified in PceService
- //if (null == service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
- // error("Path creation failed.");
- //}
+ if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
+ error("Path creation failed.");
+ }
}
}
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
index e1dcd65..5ea8686 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java
index d5c85c4..2db38908 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java
index 1331255..e9d3fec 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java
@@ -244,12 +244,14 @@
this.id = TunnelId.valueOf(tunnel.tunnelId().id());
this.source = tunnel.src().toString();
this.destination = tunnel.dst().toString();
- //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys
- this.lspType = null; // = LspType.valueOf(tunnel.annotations().value(AnnotationKeys.LSP_SIG_TYPE));
+ //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys.
+ this.lspType = null; // = LspType.valueOf(tunnel.annotations()
+ //.value(AnnotationKeys.LSP_SIG_TYPE));
this.name = tunnel.tunnelName().toString();
- this.costConstraint = null; //CostConstraint.of(tunnel.path().cost());
- this.bandwidthConstraint = null;
- //LocalBandwidthConstraint.of(tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
+ //TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint classes are ready
+ this.costConstraint = null; // = CostConstraint.of(tunnel.path().cost());
+ this.bandwidthConstraint = null; // = LocalBandwidthConstraint.of(tunnel.annotations()
+ //.value(AnnotationKeys.BANDWIDTH));
return this;
}
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceCodecRegistrator.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceCodecRegistrator.java
similarity index 94%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PceCodecRegistrator.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PceCodecRegistrator.java
index 5554e64..fb4f9ed 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceCodecRegistrator.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceCodecRegistrator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathCodec.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathCodec.java
similarity index 97%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathCodec.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathCodec.java
index 9c16bd0..e0149e7 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathCodec.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathCodec.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import static com.google.common.base.Preconditions.checkNotNull;
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathWebResource.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathWebResource.java
similarity index 84%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathWebResource.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathWebResource.java
index 19244f7..abd7c88 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathWebResource.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathWebResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import static javax.ws.rs.core.Response.Status.OK;
+import static org.onlab.util.Tools.nullIsNotFound;
import java.io.IOException;
import java.io.InputStream;
@@ -34,8 +35,10 @@
import javax.ws.rs.core.Response;
import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.intent.Constraint;
+import org.onosproject.pce.pceservice.api.PceService;
import org.onosproject.pce.pceservice.PcePath;
import org.onosproject.pce.pceservice.DefaultPcePath;
import org.onosproject.pce.pceservice.LspType;
@@ -58,6 +61,7 @@
public static final String PCE_PATH_NOT_FOUND = "Path not found";
public static final String PCE_PATH_ID_EXIST = "Path exists";
public static final String PCE_PATH_ID_NOT_EXIST = "Path does not exist for the identifier";
+ public static final String PCE_SETUP_PATH_FAILED = "PCE Setup path has failed.";
/**
* Retrieve details of all paths created.
@@ -68,8 +72,7 @@
@Produces(MediaType.APPLICATION_JSON)
public Response queryAllPath() {
log.debug("Query all paths.");
- //TODO: need to uncomment below line once queryAllPath method is added to PceService
- Iterable<Tunnel> tunnels = null; // = get(PceService.class).queryAllPath();
+ Iterable<Tunnel> tunnels = get(PceService.class).queryAllPath();
ObjectNode result = mapper().createObjectNode();
ArrayNode pathEntry = result.putArray("paths");
if (tunnels != null) {
@@ -92,9 +95,8 @@
@Produces(MediaType.APPLICATION_JSON)
public Response queryPath(@PathParam("path_id") String id) {
log.debug("Query path by identifier {}.", id);
- //TODO: need to uncomment below lines once queryPath method is added to PceService
- Tunnel tunnel = null; // = nullIsNotFound(get(PceService.class).queryPath(PcePathId.of(id)),
- //PCE_PATH_NOT_FOUND);
+ Tunnel tunnel = nullIsNotFound(get(PceService.class).queryPath(TunnelId.valueOf(id)),
+ PCE_PATH_NOT_FOUND);
PcePath path = DefaultPcePath.builder().of(tunnel).build();
ObjectNode result = mapper().createObjectNode();
result.set("path", codec(PcePath.class).encode(path, this));
@@ -131,9 +133,9 @@
//listConstrnt.add(LocalBandwidthConstraint.of(Double.valueOf(path.constraint().bandwidth()), DataRateUnit
// .valueOf("BPS")));
- //TODO: need to uncomment below lines once setupPath method is modified in PceService
- Boolean issuccess = true; // = (null != get(PceService.class)
- //.setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType)) ? true : false;
+ Boolean issuccess = nullIsNotFound(get(PceService.class)
+ .setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType),
+ PCE_SETUP_PATH_FAILED);
return Response.status(OK).entity(issuccess.toString()).build();
} catch (IOException e) {
log.error("Exception while creating path {}.", e.toString());
@@ -174,9 +176,8 @@
// .of(path.constraint().bandwidth(), DataRateUnit.valueOf("BPS")));
}
- //TODO: need to uncomment below line once updatePath is added to PceService
- Boolean result = true; // = (null != (get(PceService.class).updatePath(PcePathId.of(id), constrntList)))
- //? true : false;
+ Boolean result = nullIsNotFound(get(PceService.class).updatePath(TunnelId.valueOf(id), constrntList),
+ PCE_PATH_NOT_FOUND);
return Response.status(OK).entity(result.toString()).build();
} catch (IOException e) {
log.error("Update path failed because of exception {}.", e.toString());
@@ -195,9 +196,8 @@
public Response releasePath(@PathParam("path_id") String id) {
log.debug("Deletes path by identifier {}.", id);
- //TODO: need to uncomment below lines once releasePath method is added to PceService
- Boolean isSuccess = true; // = nullIsNotFound(get(PceService.class).releasePath(PcePathId.of(id)),
- //PCE_PATH_NOT_FOUND);
+ Boolean isSuccess = nullIsNotFound(get(PceService.class).releasePath(TunnelId.valueOf(id)),
+ PCE_PATH_NOT_FOUND);
if (!isSuccess) {
log.debug("Path identifier {} does not exist", id);
}
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceWebApplication.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceWebApplication.java
similarity index 90%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PceWebApplication.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PceWebApplication.java
index 9cae9b3..3ff2dc3 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceWebApplication.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceWebApplication.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import org.onlab.rest.AbstractWebApplication;
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/package-info.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/package-info.java
similarity index 87%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/package-info.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/package-info.java
index 08a1b6b..a56073c 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/package-info.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,4 +17,4 @@
/**
* PCE rest application.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
diff --git a/apps/pce/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/pce/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 8631bfc..9704c5c 100644
--- a/apps/pce/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/apps/pce/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -1,5 +1,5 @@
<!--
- ~ Copyright 2016 Open Networking Laboratory
+ ~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
diff --git a/apps/pce/app/src/main/webapp/WEB-INF/web.xml b/apps/pce/app/src/main/webapp/WEB-INF/web.xml
index 6f2c47a..53991f5 100644
--- a/apps/pce/app/src/main/webapp/WEB-INF/web.xml
+++ b/apps/pce/app/src/main/webapp/WEB-INF/web.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright 2016 Open Networking Laboratory
+ ~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
- <param-value>org.onosproject.pce.web.PceWebApplication</param-value>
+ <param-value>org.onosproject.pce.rest.PceWebApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/web/MockPceCodecContext.java b/apps/pce/app/src/test/java/org/onosproject/pce/rest/MockPceCodecContext.java
similarity index 95%
rename from apps/pce/app/src/test/java/org/onosproject/pce/web/MockPceCodecContext.java
rename to apps/pce/app/src/test/java/org/onosproject/pce/rest/MockPceCodecContext.java
index 1aa90aa..7bced15 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/web/MockPceCodecContext.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/rest/MockPceCodecContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.CodecService;
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/web/PcePathCodecTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/rest/PcePathCodecTest.java
similarity index 96%
rename from apps/pce/app/src/test/java/org/onosproject/pce/web/PcePathCodecTest.java
rename to apps/pce/app/src/test/java/org/onosproject/pce/rest/PcePathCodecTest.java
index 64f1c48..022058d 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/web/PcePathCodecTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/rest/PcePathCodecTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/rest/PcePathResourceTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/rest/PcePathResourceTest.java
new file mode 100644
index 0000000..d4c79f0
--- /dev/null
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/rest/PcePathResourceTest.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.pce.rest;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+//TODO: below imports needs to be uncommented once TODO in DefaultPcePath class are removed
+//import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import static org.onosproject.net.Link.Type.DIRECT;
+
+//import com.eclipsesource.json.Json;
+//import com.eclipsesource.json.JsonObject;
+
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.LinkedList;
+import java.util.List;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.NotFoundException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.osgi.TestServiceDirectory;
+import org.onlab.packet.IpAddress;
+import org.onlab.rest.BaseResource;
+import org.onosproject.codec.CodecService;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.pce.pceservice.api.PceService;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * Unit tests for pce path REST APIs.
+ */
+public class PcePathResourceTest extends PceResourceTest {
+ private final PceService pceService = createMock(PceService.class);
+ private final TunnelEndPoint src = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(23423));
+ private final TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421));
+ private final DefaultGroupId groupId = new DefaultGroupId(92034);
+ private final TunnelName tunnelName = TunnelName.tunnelName("TunnelName");
+ private final TunnelId tunnelId = TunnelId.valueOf("41654654");
+ private final ProviderId producerName = new ProviderId("producer1", "13");
+ private Path path;
+ private Tunnel tunnel;
+ private DeviceId deviceId1;
+ private DeviceId deviceId2;
+ private DeviceId deviceId3;
+ private DeviceId deviceId4;
+ private DeviceId deviceId5;
+ private PortNumber port1;
+ private PortNumber port2;
+ private PortNumber port3;
+ private PortNumber port4;
+ private PortNumber port5;
+
+ /**
+ * Sets up the global values for all the tests.
+ */
+ @Before
+ public void setUpTest() {
+ // Mock environment setup
+ MockPceCodecContext context = new MockPceCodecContext();
+ ServiceDirectory testDirectory = new TestServiceDirectory().add(PceService.class, pceService)
+ .add(CodecService.class, context.codecManager());
+ BaseResource.setServiceDirectory(testDirectory);
+
+ // Tunnel creation
+ // Links
+ ProviderId providerId = new ProviderId("of", "foo");
+ deviceId1 = DeviceId.deviceId("of:A");
+ deviceId2 = DeviceId.deviceId("of:B");
+ deviceId3 = DeviceId.deviceId("of:C");
+ deviceId4 = DeviceId.deviceId("of:D");
+ deviceId5 = DeviceId.deviceId("of:E");
+ port1 = PortNumber.portNumber(1);
+ port2 = PortNumber.portNumber(2);
+ port3 = PortNumber.portNumber(3);
+ port4 = PortNumber.portNumber(4);
+ port5 = PortNumber.portNumber(5);
+ List<Link> linkList = new LinkedList<>();
+
+ Link l1 = DefaultLink.builder()
+ .providerId(providerId)
+ .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
+ .src(new ConnectPoint(deviceId1, port1))
+ .dst(new ConnectPoint(deviceId2, port2))
+ .type(DIRECT)
+ .state(Link.State.ACTIVE)
+ .build();
+ linkList.add(l1);
+ Link l2 = DefaultLink.builder()
+ .providerId(providerId)
+ .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
+ .src(new ConnectPoint(deviceId2, port2))
+ .dst(new ConnectPoint(deviceId3, port3))
+ .type(DIRECT)
+ .state(Link.State.ACTIVE)
+ .build();
+ linkList.add(l2);
+ Link l3 = DefaultLink.builder()
+ .providerId(providerId)
+ .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
+ .src(new ConnectPoint(deviceId3, port3))
+ .dst(new ConnectPoint(deviceId4, port4))
+ .type(DIRECT)
+ .state(Link.State.ACTIVE)
+ .build();
+ linkList.add(l3);
+ Link l4 = DefaultLink.builder()
+ .providerId(providerId)
+ .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
+ .src(new ConnectPoint(deviceId4, port4))
+ .dst(new ConnectPoint(deviceId5, port5))
+ .type(DIRECT)
+ .state(Link.State.ACTIVE)
+ .build();
+ linkList.add(l4);
+
+ // Path
+ path = new DefaultPath(providerId, linkList, 10);
+
+ // Tunnel
+ tunnel = new DefaultTunnel(producerName, src, dst, Tunnel.Type.VXLAN,
+ Tunnel.State.ACTIVE, groupId, tunnelId,
+ tunnelName, path);
+ }
+
+ /**
+ * Cleans up.
+ */
+ @After
+ public void tearDownTest() {
+ }
+
+ /**
+ * Tests the result of the rest api GET when there are no pce paths.
+ */
+ @Test
+ public void testPcePathsEmpty() {
+ expect(pceService.queryAllPath())
+ .andReturn(null)
+ .anyTimes();
+ replay(pceService);
+ WebTarget wt = target();
+ String response = wt.path("path").request().get(String.class);
+ assertThat(response, is("{\"paths\":[]}"));
+ }
+
+ /**
+ * Tests the result of a rest api GET for pce path id.
+ */
+ @Test
+ public void testGetTunnelId() {
+ //TODO: uncomment below lines once TODO in DefaultPcePath class are removed
+ //expect(pceService.queryPath(anyObject()))
+ // .andReturn(tunnel)
+ // .anyTimes();
+ //replay(pceService);
+
+ //WebTarget wt = target();
+ //String response = wt.path("path/1").request().get(String.class);
+ //JsonObject result = Json.parse(response).asObject();
+ //assertThat(result, notNullValue());
+ }
+
+ /**
+ * Tests that a fetch of a non-existent pce path object throws an exception.
+ */
+ @Test
+ public void testBadGet() {
+ expect(pceService.queryPath(anyObject()))
+ .andReturn(null)
+ .anyTimes();
+ replay(pceService);
+
+ WebTarget wt = target();
+ try {
+ wt.path("path/1").request().get(String.class);
+ fail("Fetch of non-existent pce path did not throw an exception");
+ } catch (NotFoundException ex) {
+ assertThat(ex.getMessage(), containsString("HTTP 404 Not Found"));
+ }
+ }
+
+ /**
+ * Tests creating a pce path with POST.
+ */
+ @Test
+ public void testPost() {
+ expect(pceService.setupPath(anyObject(), anyObject(), anyObject(), anyObject(), anyObject()))
+ .andReturn(true)
+ .anyTimes();
+ replay(pceService);
+
+ WebTarget wt = target();
+ InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
+
+ Response response = wt.path("path")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .post(Entity.json(jsonStream));
+ assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
+ }
+
+ /**
+ * Tests creating a pce path with PUT.
+ */
+ @Test
+ public void testPut() {
+ expect(pceService.updatePath(anyObject(), anyObject()))
+ .andReturn(true)
+ .anyTimes();
+ replay(pceService);
+
+ WebTarget wt = target();
+ InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
+
+ Response response = wt.path("path/1")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .put(Entity.json(jsonStream));
+ assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
+ }
+
+ /**
+ * Tests deleting a pce path.
+ */
+ @Test
+ public void testDelete() {
+ expect(pceService.releasePath(anyObject()))
+ .andReturn(true)
+ .anyTimes();
+ replay(pceService);
+
+ WebTarget wt = target();
+
+ String location = "path/1";
+
+ Response deleteResponse = wt.path(location)
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .delete();
+ assertThat(deleteResponse.getStatus(), is(HttpURLConnection.HTTP_OK));
+ }
+}
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/web/PceResourceTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/rest/PceResourceTest.java
similarity index 91%
rename from apps/pce/app/src/test/java/org/onosproject/pce/web/PceResourceTest.java
rename to apps/pce/app/src/test/java/org/onosproject/pce/rest/PceResourceTest.java
index d7a29f5..5f39c62 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/web/PceResourceTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/rest/PceResourceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/web/PcePathResourceTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/web/PcePathResourceTest.java
deleted file mode 100644
index 181f864..0000000
--- a/apps/pce/app/src/test/java/org/onosproject/pce/web/PcePathResourceTest.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Copyright 2016 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.pce.web;
-
-//import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-//import static org.easymock.EasyMock.expect;
-//import static org.easymock.EasyMock.replay;
-//import static org.hamcrest.Matchers.containsString;
-//import static org.hamcrest.Matchers.is;
-//import static org.hamcrest.Matchers.notNullValue;
-//import static org.junit.Assert.assertThat;
-//import static org.junit.Assert.fail;
-
-//import javax.ws.rs.NotFoundException;
-//import javax.ws.rs.client.Entity;
-//import javax.ws.rs.client.WebTarget;
-//import javax.ws.rs.core.MediaType;
-//import javax.ws.rs.core.Response;
-//import java.io.InputStream;
-//import java.net.HttpURLConnection;
-//import java.util.HashSet;
-//import java.util.List;
-//import java.util.Objects;
-//import java.util.Optional;
-//import java.util.Set;
-
-//import com.eclipsesource.json.Json;
-//import com.eclipsesource.json.JsonObject;
-//import com.google.common.collect.ImmutableList;
-//import com.google.common.collect.Lists;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.osgi.ServiceDirectory;
-import org.onlab.osgi.TestServiceDirectory;
-import org.onlab.rest.BaseResource;
-import org.onosproject.codec.CodecService;
-import org.onosproject.incubator.net.tunnel.TunnelId;
-import org.onosproject.net.intent.Constraint;
-import org.onosproject.pce.pceservice.PcePath;
-import org.onosproject.pce.pceservice.LspType;
-import org.onosproject.pce.pceservice.api.PceService;
-
-/**
- * Unit tests for pce path REST APIs.
- */
-public class PcePathResourceTest extends PceResourceTest {
- final PceService pceService = createMock(PceService.class);
- final TunnelId pcePathId1 = TunnelId.valueOf("1");
- //TODO: will be uncommented below lines once CostConstraint and LocalBandwidthConstraint classes are ready
- final Constraint costConstraint = null; //CostConstraint.of("2");
- final Constraint bandwidthConstraint = null; //LocalBandwidthConstraint.of("200.0");
- final LspType lspType = LspType.WITH_SIGNALLING;
- final MockPcePath pcePath1 = new MockPcePath(pcePathId1, "11.0.0.1", "11.0.0.2", lspType, "pcc2",
- costConstraint, bandwidthConstraint);
-
- /**
- * Mock class for a pce path.
- */
- private static class MockPcePath implements PcePath {
- private TunnelId id;
- private String source;
- private String destination;
- private LspType lspType;
- private String name;
- private Constraint costConstraint;
- private Constraint bandwidthConstraint;
-
- /**
- * Constructor to initialize member variables.
- *
- * @param id pce path id
- * @param src source device
- * @param dst destination device
- * @param type lsp type
- * @param name symbolic path name
- * @param constrnt pce constraint
- */
- public MockPcePath(TunnelId id, String src, String dst, LspType type, String name,
- Constraint costConstrnt, Constraint bandwidthConstrnt) {
- this.id = id;
- this.source = src;
- this.destination = dst;
- this.name = name;
- this.lspType = type;
- this.costConstraint = costConstrnt;
- this.bandwidthConstraint = bandwidthConstrnt;
- }
-
- @Override
- public TunnelId id() {
- return id;
- }
-
- @Override
- public void id(TunnelId id) {
- this.id = id;
- }
-
- @Override
- public String source() {
- return source;
- }
-
- @Override
- public void source(String src) {
- this.source = src;
- }
-
- @Override
- public String destination() {
- return destination;
- }
-
- @Override
- public void destination(String dst) {
- this.destination = dst;
- }
-
- @Override
- public LspType lspType() {
- return lspType;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- @Override
- public Constraint costConstraint() {
- return costConstraint;
- }
-
- @Override
- public Constraint bandwidthConstraint() {
- return bandwidthConstraint;
- }
-
- @Override
- public PcePath copy(PcePath path) {
- if (null != path.source()) {
- this.source = path.source();
- }
- if (null != path.destination()) {
- this.destination = path.destination();
- }
- if (this.lspType != path.lspType()) {
- this.lspType = path.lspType();
- }
- if (null != path.name()) {
- this.name = path.name();
- }
- if (null != path.costConstraint()) {
- this.costConstraint = path.costConstraint();
- }
- if (null != path.bandwidthConstraint()) {
- this.bandwidthConstraint = path.bandwidthConstraint();
- }
- return this;
- }
- }
-
- /**
- * Sets up the global values for all the tests.
- */
- @Before
- public void setUpTest() {
- MockPceCodecContext context = new MockPceCodecContext();
- ServiceDirectory testDirectory = new TestServiceDirectory().add(PceService.class, pceService)
- .add(CodecService.class, context.codecManager());
- BaseResource.setServiceDirectory(testDirectory);
- }
-
- /**
- * Cleans up.
- */
- @After
- public void tearDownTest() {
- }
-
- /**
- * Tests the result of the rest api GET when there are no pce paths.
- */
- @Test
- public void testPcePathsEmpty() {
- //TODO: will be uncommented below code once PceService is ready
- //expect(pceService.queryAllPath()).andReturn(null).anyTimes();
- //replay(pceService);
- //final WebTarget wt = target();
- //final String response = wt.path("path").request().get(String.class);
- //assertThat(response, is("{\"paths\":[]}"));
- }
-
- /**
- * Tests the result of a rest api GET for pce path id.
- */
- @Test
- public void testGetTunnelId() {
- //TODO: will be uncommented below code once PceService is ready
- //final Set<PcePath> pcePaths = new HashSet<>();
- //pcePaths.add(pcePath1);
-
- //expect(pceService.queryPath(anyObject())).andReturn(pcePath1).anyTimes();
- //replay(pceService);
-
- //final WebTarget wt = target();
- //final String response = wt.path("path/1").request().get(String.class);
- //final JsonObject result = Json.parse(response).asObject();
- //assertThat(result, notNullValue());
- }
-
- /**
- * Tests that a fetch of a non-existent pce path object throws an exception.
- */
- @Test
- public void testBadGet() {
- //TODO: will be uncommented below code once PceService is ready
- //expect(pceService.queryPath(anyObject()))
- // .andReturn(null).anyTimes();
- //replay(pceService);
-
- //WebTarget wt = target();
- //try {
- // wt.path("path/1").request().get(String.class);
- // fail("Fetch of non-existent pce path did not throw an exception");
- //} catch (NotFoundException ex) {
- // assertThat(ex.getMessage(),
- // containsString("HTTP 404 Not Found"));
- //}
- }
-
- /**
- * Tests creating a pce path with POST.
- */
- @Test
- public void testPost() {
- //TODO: will be uncommented below code once PceService is ready
- //expect(pceService.setupPath(anyObject()))
- // .andReturn(true).anyTimes();
- //replay(pceService);
-
- //WebTarget wt = target();
- //InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
-
- //Response response = wt.path("path")
- // .request(MediaType.APPLICATION_JSON_TYPE)
- // .post(Entity.json(jsonStream));
- //assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
- }
-
- /**
- * Tests creating a pce path with PUT.
- */
- @Test
- public void testPut() {
- //TODO: will be uncommented below code once PceService is ready
- //expect(pceService.updatePath(anyObject()))
- // .andReturn(true).anyTimes();
- //replay(pceService);
-
- //WebTarget wt = target();
- //InputStream jsonStream = PcePathResourceTest.class.getResourceAsStream("post-PcePath.json");
-
- //Response response = wt.path("path/1")
- // .request(MediaType.APPLICATION_JSON_TYPE)
- // .put(Entity.json(jsonStream));
- //assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
- }
-
- /**
- * Tests deleting a pce path.
- */
- @Test
- public void testDelete() {
- //TODO: will be uncommented below code once PceService is ready
- //expect(pceService.releasePath(anyObject()))
- // .andReturn(true).anyTimes();
- //replay(pceService);
-
- //WebTarget wt = target();
-
- //String location = "path/1";
-
- //Response deleteResponse = wt.path(location)
- // .request(MediaType.APPLICATION_JSON_TYPE)
- // .delete();
- //assertThat(deleteResponse.getStatus(),
- // is(HttpURLConnection.HTTP_OK));
- }
-}
diff --git a/apps/pce/app/src/test/resources/org/onosproject/pce/web/pcePath.json b/apps/pce/app/src/test/resources/org/onosproject/pce/rest/pcePath.json
similarity index 100%
rename from apps/pce/app/src/test/resources/org/onosproject/pce/web/pcePath.json
rename to apps/pce/app/src/test/resources/org/onosproject/pce/rest/pcePath.json
diff --git a/apps/pce/app/src/test/resources/org/onosproject/pce/web/post-PcePath.json b/apps/pce/app/src/test/resources/org/onosproject/pce/rest/post-PcePath.json
similarity index 100%
rename from apps/pce/app/src/test/resources/org/onosproject/pce/web/post-PcePath.json
rename to apps/pce/app/src/test/resources/org/onosproject/pce/rest/post-PcePath.json