Northbound cleanup for static routing 11/1011/1
authorPrasanth Pallamreddy <ppallamr@cisco.com>
Mon, 26 Aug 2013 23:45:45 +0000 (16:45 -0700)
committerPrasanth Pallamreddy <ppallamr@cisco.com>
Mon, 26 Aug 2013 23:50:34 +0000 (16:50 -0700)
Change-Id: I252c0338780be7eb80d577bbcdfe8455aa171c8c
Signed-off-by: Prasanth Pallamreddy <ppallamr@cisco.com>
opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoute.java
opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutes.java
opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java

index ffa80f6496135ded21866f18c5b7f10e17bafdd1..573a08189f109fc36286bad60a13c1537606a9e3 100644 (file)
@@ -14,21 +14,32 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.NONE)
 /**
 /**
- * This class contains static route data  that is returned as a response to the NorthBound GET request.
- *
- *
+ * StaticRoute represents the static route data that is returned as a response to
+ * the NorthBound GET request.
  *
  */
  *
  */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
 public class StaticRoute {
 public class StaticRoute {
+    /**
+     * The name of the static route.
+     */
     @XmlElement
     private String name;
     @XmlElement
     private String name;
+
+    /**
+     * The prefix for the route.
+     * Format: A.B.C.D/MM  Where A.B.C.D is the Default Gateway IP (L3) or ARP Querier IP (L2)
+     */
     @XmlElement
     @XmlElement
-    private String prefix; // A.B.C.D/MM  Where A.B.C.D is the Default Gateway IP (L3) or ARP Querier IP (L2)
+    private String prefix;
+
+    /**
+     * NextHop IP-Address (or) datapath ID/port list: xx:xx:xx:xx:xx:xx:xx:xx/a,b,c-m,r-t,y
+     */
     @XmlElement
     @XmlElement
-    private String nextHop; // NextHop IP-Address (or) datapath ID/port list: xx:xx:xx:xx:xx:xx:xx:xx/a,b,c-m,r-t,y
+    private String nextHop;
 
     public StaticRoute() {
     }
 
     public StaticRoute() {
     }
index 683a9a2d906a285b37dab19bdb4b36b528aa8b57..27aa0ed3f91b2f5ad6d9c54921fd83d5f9a748b8 100644 (file)
@@ -17,9 +17,11 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
 
 
 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
 
-@XmlRootElement
+/**
+ * This class represents a list of static routes.
+ */
+@XmlRootElement(name = "list")
 @XmlAccessorType(XmlAccessType.NONE)
 @XmlAccessorType(XmlAccessType.NONE)
-
 public class StaticRoutes {
         @XmlElement
         List<StaticRoute> staticRoute;
 public class StaticRoutes {
         @XmlElement
         List<StaticRoute> staticRoute;
index 3deb8dfa7b59766fab862b6151e3b2f00e4fc6d3..dceafac4abeb48facf3270a58322b1a5a1acc433 100644 (file)
@@ -23,6 +23,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.JAXBElement;
 
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import javax.xml.bind.JAXBElement;
 
 import org.codehaus.enunciate.jaxrs.ResponseCode;
@@ -44,16 +45,26 @@ import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
 
 /**
 import org.opendaylight.controller.sal.utils.Status;
 
 /**
- * Static Routing Northbound APIs
+ * <p>Static Routing Northbound API allows for the management of the static
+ * routes.</p>
+ * </br>
+ * An example request/response for retrieving the static routes may look like this: </br>
+ * <pre>
+ * GET http://localhost:8080/controller/nb/v2/staticroute/default HTTP/1.1
+ * Accept: application/json
+ *
+ * HTTP/1.1 200 OK
+ * Content-Type: application/json
+ *
+ * {"staticRoute":{"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}}
+ *
+ * </pre>
  *
  * <br><br>
  * Authentication scheme : <b>HTTP Basic</b><br>
  * Authentication realm : <b>opendaylight</b><br>
  * Transport : <b>HTTP and HTTPS</b><br>
  * <br>
  *
  * <br><br>
  * Authentication scheme : <b>HTTP Basic</b><br>
  * Authentication realm : <b>opendaylight</b><br>
  * Transport : <b>HTTP and HTTPS</b><br>
  * <br>
- * HTTPS Authentication is disabled by default. Administrator can enable it in tomcat-server.xml after adding
- * a proper keystore / SSL certificate from a trusted authority.<br>
- * More info : http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
  */
 @Path("/")
 public class StaticRoutingNorthbound {
  */
 @Path("/")
 public class StaticRoutingNorthbound {
@@ -93,10 +104,30 @@ public class StaticRoutingNorthbound {
     }
 
     /**
     }
 
     /**
-     * Returns a list of static routes present on the given container
+     * Get a list of static routes present on the given container.
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
      * @return List of configured static routes on the given container
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
      * @return List of configured static routes on the given container
+     *
+     * <pre>
+     * Example:
+     *
+     * Request URL:
+     * GET http://localhost:8080/controller/nb/v2/staticroute/default
+     *
+     * Response in XML:
+     *  &lt;list&gt;
+     *   &lt;staticRoute&gt;
+     *     &lt;name&gt;route-1&lt;/name&gt;
+     *     &lt;prefix&gt;10.10.1.0/24&lt;/prefix&gt;
+     *     &lt;nextHop&gt;1.1.1.1&lt;/nextHop&gt;
+     *   &lt;/staticRoute&gt;
+     *  &lt;/list&gt;
+     *
+     * Response in JSON:
+     * {"staticRoute":{"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}}
+     *
+     * </pre>
      */
     @Path("/{containerName}")
     @GET
      */
     @Path("/{containerName}")
     @GET
@@ -121,10 +152,29 @@ public class StaticRoutingNorthbound {
      * Returns the static route for the provided configuration name on a given container
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
      * Returns the static route for the provided configuration name on a given container
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
-     * @param name Name of the Static Route configuration
+     * @param route Name of the Static Route configuration
      * @return Static route configured with the supplied Name.
      * @return Static route configured with the supplied Name.
+     *
+     * <pre>
+     * Example:
+     *
+     * Request URL:
+     * GET http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1
+     *
+     * Response in XML:
+     *
+     *   &lt;staticRoute&gt;
+     *     &lt;name&gt;route-1&lt;/name&gt;
+     *     &lt;prefix&gt;10.10.1.0/24&lt;/prefix&gt;
+     *     &lt;nextHop&gt;1.1.1.1&lt;/nextHop&gt;
+     *   &lt;/staticRoute&gt;
+     *
+     * Response in JSON:
+     * {"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}
+     *
+     * </pre>
      */
      */
-    @Path("/{containerName}/{name}")
+    @Path("/{containerName}/route/{route}")
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
     @TypeHint(StaticRoute.class)
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
     @TypeHint(StaticRoute.class)
@@ -133,7 +183,7 @@ public class StaticRoutingNorthbound {
             @ResponseCode(code = 404, condition = "The Container Name or Static Route Configuration name passed was not found") })
     public StaticRoute getStaticRoute(
             @PathParam("containerName") String containerName,
             @ResponseCode(code = 404, condition = "The Container Name or Static Route Configuration name passed was not found") })
     public StaticRoute getStaticRoute(
             @PathParam("containerName") String containerName,
-            @PathParam("name") String name) {
+            @PathParam("route") String route) {
 
         if(!NorthboundUtils.isAuthorized(getUserName(), containerName,
                 Privilege.WRITE, this)){
 
         if(!NorthboundUtils.isAuthorized(getUserName(), containerName,
                 Privilege.WRITE, this)){
@@ -142,9 +192,9 @@ public class StaticRoutingNorthbound {
                             + containerName);
         }
         List<StaticRoute> routes = this.getStaticRoutesInternal(containerName);
                             + containerName);
         }
         List<StaticRoute> routes = this.getStaticRoutesInternal(containerName);
-        for (StaticRoute route : routes) {
-            if (route.getName().equalsIgnoreCase(name)) {
-                return route;
+        for (StaticRoute r : routes) {
+            if (r.getName().equalsIgnoreCase(route)) {
+                return r;
             }
         }
 
             }
         }
 
@@ -157,10 +207,21 @@ public class StaticRoutingNorthbound {
      * Add a new Static Route
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
      * Add a new Static Route
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
-     * @param name Name of the Static Route configuration
+     * @param route Name of the Static Route configuration
      * @return Response as dictated by the HTTP Response code
      * @return Response as dictated by the HTTP Response code
+     *
+     * <pre>
+     * Example:
+     *
+     * Request URL:
+     * POST http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1
+     *
+     * Request payload in JSON:
+     * {"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}
+     *
+     * </pre>
      */
      */
-    @Path("/{containerName}/{name}")
+    @Path("/{containerName}/route/{route}")
     @POST
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
     @StatusCodes( {
     @POST
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
     @StatusCodes( {
@@ -169,8 +230,9 @@ public class StaticRoutingNorthbound {
             @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"),
             @ResponseCode(code = 409, condition = "Failed to create Static Route entry due to Conflicting Name or Prefix."), })
     public Response addStaticRoute(
             @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"),
             @ResponseCode(code = 409, condition = "Failed to create Static Route entry due to Conflicting Name or Prefix."), })
     public Response addStaticRoute(
+            @Context UriInfo uriInfo,
             @PathParam(value = "containerName") String containerName,
             @PathParam(value = "containerName") String containerName,
-            @PathParam(value = "name") String name,
+            @PathParam(value = "route") String route,
             @TypeHint(StaticRoute.class) JAXBElement<StaticRoute> staticRouteData) {
 
 
             @TypeHint(StaticRoute.class) JAXBElement<StaticRoute> staticRouteData) {
 
 
@@ -196,8 +258,8 @@ public class StaticRoutingNorthbound {
                 sRoute.getPrefix(), sRoute.getNextHop());
         Status response = staticRouting.addStaticRoute(cfgObject);
         if (response.isSuccess()) {
                 sRoute.getPrefix(), sRoute.getNextHop());
         Status response = staticRouting.addStaticRoute(cfgObject);
         if (response.isSuccess()) {
-            NorthboundUtils.auditlog("Static Route", username, "added", name, containerName);
-            return Response.status(Response.Status.CREATED).build();
+            NorthboundUtils.auditlog("Static Route", username, "added", route, containerName);
+            return Response.created(uriInfo.getRequestUri()).build();
         }
         throw new ResourceConflictException(response.getDescription());
     }
         }
         throw new ResourceConflictException(response.getDescription());
     }
@@ -207,12 +269,19 @@ public class StaticRoutingNorthbound {
      * Delete a Static Route
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
      * Delete a Static Route
      *
      * @param containerName Name of the Container. The Container name for the base controller is "default".
-     * @param name Name of the Static Route configuration to be removed
+     * @param route Name of the Static Route configuration to be removed
      *
      * @return Response as dictated by the HTTP Response code
      *
      * @return Response as dictated by the HTTP Response code
+     *
+     * <pre>
+     * Example:
+     *
+     * Request URL:
+     * DELETE http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1
+     *
+     * </pre>
      */
      */
-
-    @Path("/{containerName}/{name}")
+    @Path("/{containerName}/route/{route}")
     @DELETE
     @StatusCodes( {
             @ResponseCode(code = 200, condition = "Operation successful"),
     @DELETE
     @StatusCodes( {
             @ResponseCode(code = 200, condition = "Operation successful"),
@@ -220,7 +289,7 @@ public class StaticRoutingNorthbound {
             @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active") })
     public Response removeStaticRoute(
             @PathParam(value = "containerName") String containerName,
             @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active") })
     public Response removeStaticRoute(
             @PathParam(value = "containerName") String containerName,
-            @PathParam(value = "name") String name) {
+            @PathParam(value = "route") String route) {
 
         if(!NorthboundUtils.isAuthorized(getUserName(), containerName,
                 Privilege.WRITE, this)){
 
         if(!NorthboundUtils.isAuthorized(getUserName(), containerName,
                 Privilege.WRITE, this)){
@@ -239,9 +308,9 @@ public class StaticRoutingNorthbound {
                     .toString());
         }
 
                     .toString());
         }
 
-        Status status = staticRouting.removeStaticRoute(name);
+        Status status = staticRouting.removeStaticRoute(route);
         if (status.isSuccess()) {
         if (status.isSuccess()) {
-            NorthboundUtils.auditlog("Static Route", username, "removed", name, containerName);
+            NorthboundUtils.auditlog("Static Route", username, "removed", route, containerName);
             return Response.ok().build();
         }
         throw new ResourceNotFoundException(status.getDescription());
             return Response.ok().build();
         }
         throw new ResourceNotFoundException(status.getDescription());