Implemented REST API for multicast RIB.

Change-Id: I5de6fe0aae412083597113e355ba0e8c984be5f1
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java b/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java
index 8d02f54..f5312f8 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/CoreWebApplication.java
@@ -44,7 +44,8 @@
                 PathsWebResource.class,
                 StatisticsWebResource.class,
                 MetricsWebResource.class,
-                FlowObjectiveWebResource.class
+                FlowObjectiveWebResource.class,
+                MulticastRouteWebResource.class
         );
     }
-}
\ No newline at end of file
+}
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java
new file mode 100644
index 0000000..ed26824
--- /dev/null
+++ b/web/api/src/main/java/org/onosproject/rest/resources/MulticastRouteWebResource.java
@@ -0,0 +1,105 @@
+/*
+ * 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.rest.resources;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.net.mcast.McastRoute;
+import org.onosproject.net.mcast.MulticastRouteService;
+import org.onosproject.rest.AbstractWebResource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Set;
+
+/**
+ * Manage the multicast routing information.
+ */
+@Path("mcast")
+public class MulticastRouteWebResource extends AbstractWebResource {
+
+    /**
+     * Get all multicast routes.
+     * Returns array of all known multicast routes.
+     *
+     * @return 200 OK
+     * @onos.rsModel McastRoutesGet
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getRoutes() {
+        Set<McastRoute> routes = get(MulticastRouteService.class).getRoutes();
+        ObjectNode root = encodeArray(McastRoute.class, "routes", routes);
+        return ok(root).build();
+    }
+
+    /**
+     * Create new multicast route.
+     * Creates a new route in the multicast RIB.
+     *
+     * @onos.rsModel McastRoutePost
+     * @param stream multicast route JSON
+     * @return status of the request - CREATED if the JSON is correct,
+     * BAD_REQUEST if the JSON is invalid
+     */
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response createRoute(InputStream stream) {
+        MulticastRouteService service = get(MulticastRouteService.class);
+        try {
+            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+            McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
+            service.add(route);
+        } catch (IOException ex) {
+            throw new IllegalArgumentException(ex);
+        }
+
+        return Response
+                .created(URI.create(""))
+                .build();
+    }
+
+    /**
+     * Remove a multicast route.
+     * Removes a route from the multicast RIB.
+     *
+     * @param stream multicast route JSON
+     * @onos.rsModel McastRoutePost
+     */
+    @DELETE
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public void deleteRoute(InputStream stream) {
+        MulticastRouteService service = get(MulticastRouteService.class);
+        try {
+            ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+            McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
+            service.remove(route);
+        } catch (IOException ex) {
+            throw new IllegalArgumentException(ex);
+        }
+    }
+}
diff --git a/web/api/src/main/resources/definitions/McastRoutePost.json b/web/api/src/main/resources/definitions/McastRoutePost.json
new file mode 100644
index 0000000..3a73adb
--- /dev/null
+++ b/web/api/src/main/resources/definitions/McastRoutePost.json
@@ -0,0 +1,20 @@
+{
+  "type": "object",
+  "title": "route",
+  "required": [
+    "source",
+    "group"
+  ],
+  "properties": {
+    "source": {
+      "type": "string",
+      "example": "10.1.1.0",
+      "description": "Multicast source IP address"
+    },
+    "group": {
+      "type": "string",
+      "example": "10.1.1.0",
+      "description": "Multicast group IP address"
+    }
+  }
+}
diff --git a/web/api/src/main/resources/definitions/McastRoutesGet.json b/web/api/src/main/resources/definitions/McastRoutesGet.json
new file mode 100644
index 0000000..652c2ee
--- /dev/null
+++ b/web/api/src/main/resources/definitions/McastRoutesGet.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",
+          "group",
+          "type"
+        ],
+        "properties": {
+          "source": {
+            "type": "string",
+            "example": "10.1.1.0",
+            "description": "Multicast source IP address"
+          },
+          "group": {
+            "type": "string",
+            "example": "10.1.1.0",
+            "description": "Multicast group IP address"
+          },
+          "type": {
+            "type": "string",
+            "example": "STATIC",
+            "description": "Type of the multicast route"
+          }
+        }
+      }
+    }
+  }
+}