Route Type Addition REST API

Change-Id: If521a97f68a12ef54feda656c499335fc58f3b98
diff --git a/apps/route-service/api/src/main/java/org/onosproject/routeservice/Route.java b/apps/route-service/api/src/main/java/org/onosproject/routeservice/Route.java
index 19407de..5bd0b94 100644
--- a/apps/route-service/api/src/main/java/org/onosproject/routeservice/Route.java
+++ b/apps/route-service/api/src/main/java/org/onosproject/routeservice/Route.java
@@ -68,7 +68,12 @@
         /**
          * Route source was not defined.
          */
-        UNDEFINED
+        UNDEFINED,
+
+        /**
+         * Route can from the DHCP-LQ route source.
+         */
+        DHCPLQ
     }
 
     private final Source source;
diff --git a/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteCodec.java b/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteCodec.java
index 3ea9f07..b33dca1 100644
--- a/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteCodec.java
+++ b/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteCodec.java
@@ -52,11 +52,14 @@
 
         IpPrefix prefix = IpPrefix.valueOf(json.path(PREFIX).asText());
         IpAddress nextHop = IpAddress.valueOf(json.path(NEXT_HOP).asText());
+        String source = json.path(SOURCE).asText();
 
-        // Routes through the REST API are created as STATIC, so we ignore
-        // the source parameter if it is specified in the JSON.
-        Route route = new Route(Route.Source.STATIC, prefix, nextHop);
+        // Routes through the REST API without mentioning source in the json are created as STATIC,
+        // otherwise routes are created with corresponding source.
 
+        Route route = source.isEmpty() ?
+                new Route(Route.Source.STATIC, prefix, nextHop) :
+                new Route(Route.Source.valueOf(source), prefix, nextHop);
         return route;
     }
 }
diff --git a/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java b/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java
index fc1a09a..a1c0296 100644
--- a/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java
+++ b/apps/route-service/app/src/main/java/org/onosproject/routeservice/rest/RouteServiceWebResource.java
@@ -74,14 +74,13 @@
 
     /**
      * Create new unicast route.
-     * Creates a new route in the unicast RIB. Routes created through the REST
-     * API are always created as STATIC routes, so there is no need to specify
-     * the type.
+     * Creates a new route in the unicast RIB. Source field is kept optional.
+     * Without Source field routes are created as STATIC routes. Otherwise as per the mentioned Source
      *
      * @param route unicast route JSON
      * @return status of the request - CREATED if the JSON is correct,
      * BAD_REQUEST if the JSON is invalid, NO_CONTENT otherwise
-     * @onos.rsModel RoutePost
+     * @onos.rsModel RouteTypePost
      */
     @POST
     @Consumes(MediaType.APPLICATION_JSON)
@@ -103,14 +102,13 @@
 
     /**
      * Creates new unicast routes.
-     * Creates new routes in the unicast RIB. Routes created through the REST
-     * API are always created as STATIC routes, so there is no need to specify
-     * the type.
+     * Creates a new route in the unicast RIB. Source field is kept optional.
+     * Without Source field routes are created as STATIC routes. Otherwise as per the mentioned Source
      *
      * @param routesStream unicast routes JSON array
      * @return status of the request - CREATED if the JSON is correct,
      * BAD_REQUEST if the JSON is invalid, NO_CONTENT otherwise
-     * @onos.rsModel RoutesPost
+     * @onos.rsModel RoutesTypePost
      */
     @POST
     @Consumes(MediaType.APPLICATION_JSON)
diff --git a/apps/route-service/app/src/main/resources/definitions/RouteTypePost.json b/apps/route-service/app/src/main/resources/definitions/RouteTypePost.json
new file mode 100644
index 0000000..6cb91ed
--- /dev/null
+++ b/apps/route-service/app/src/main/resources/definitions/RouteTypePost.json
@@ -0,0 +1,25 @@
+{
+  "type": "object",
+  "title": "route",
+  "required": [
+    "prefix",
+    "nextHop"
+  ],
+  "properties": {
+    "source": {
+      "type": "string",
+      "example": "STATIC",
+      "description": "Route type"
+    },
+    "prefix": {
+      "type": "string",
+      "example": "10.1.1.0/24",
+      "description": "Route prefix"
+    },
+    "nextHop": {
+      "type": "string",
+      "example": "1.1.1.1",
+      "description": "Next hop IP address"
+    }
+  }
+}
\ No newline at end of file
diff --git a/apps/route-service/app/src/main/resources/definitions/RoutesTypePost.json b/apps/route-service/app/src/main/resources/definitions/RoutesTypePost.json
new file mode 100644
index 0000000..91514e0
--- /dev/null
+++ b/apps/route-service/app/src/main/resources/definitions/RoutesTypePost.json
@@ -0,0 +1,42 @@
+{
+  "type": "object",
+  "title": "routes",
+  "required": [
+    "routes"
+  ],
+  "properties": {
+    "routes": {
+      "type": "array",
+      "xml": {
+        "name": "routes",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "route",
+        "required": [
+          "source",
+          "prefix",
+          "nextHop"
+        ],
+        "properties": {
+          "source": {
+            "type": "string",
+            "example": "STATIC",
+            "description": "Route type"
+          },
+          "prefix": {
+            "type": "string",
+            "example": "10.1.1.0/24",
+            "description": "Route prefix"
+          },
+          "nextHop": {
+            "type": "string",
+            "example": "1.1.1.1",
+            "description": "Next hop IP address"
+          }
+        }
+      }
+    }
+  }
+}