Adding skeletal REST API for DHCP app.

Change-Id: I9c3ceed5f12f8b293287562bcb1dd7699b676376
diff --git a/onos-app-dhcpserver/pom.xml b/onos-app-dhcpserver/pom.xml
index 9a60df2..4797108 100644
--- a/onos-app-dhcpserver/pom.xml
+++ b/onos-app-dhcpserver/pom.xml
@@ -34,6 +34,13 @@
 
     <properties>
         <onos.app.name>org.onosproject.dhcpserver</onos.app.name>
+        <web.context>/onos/dhcp</web.context>
+        <api.version>1.0.0</api.version>
+        <api.title>DHCP Server REST API</api.title>
+        <api.description>
+            APIs for interacting with the DHCP Server application.
+        </api.description>
+        <api.package>org.onosproject.dhcpserver.rest</api.package>
     </properties>
 
     <dependencies>
@@ -51,6 +58,7 @@
         <dependency>
             <groupId>org.apache.karaf.shell</groupId>
             <artifactId>org.apache.karaf.shell.console</artifactId>
+            <scope>compile</scope>
         </dependency>
 
         <dependency>
@@ -76,6 +84,78 @@
             <classifier>tests</classifier>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-rest</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-rest</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>jsr311-api</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-servlet</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-annotations</artifactId>
+        </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <_wab>src/main/webapp/</_wab>
+                        <Include-Resource>
+                            WEB-INF/classes/apidoc/swagger.json=target/swagger.json,
+                            {maven-resources}
+                        </Include-Resource>
+                        <Bundle-SymbolicName>
+                            ${project.groupId}.${project.artifactId}
+                        </Bundle-SymbolicName>
+                        <Import-Package>
+                            org.slf4j,
+                            org.osgi.framework,
+                            javax.ws.rs,
+                            javax.ws.rs.core,
+                            com.sun.jersey.api.core,
+                            com.sun.jersey.spi.container.servlet,
+                            com.sun.jersey.server.impl.container.servlet,
+                            com.fasterxml.jackson.databind,
+                            com.fasterxml.jackson.databind.node,
+                            com.fasterxml.jackson.core,
+                            org.apache.karaf.shell.commands,
+                            org.apache.karaf.shell.console,
+                            com.google.common.*,
+                            org.onlab.packet.*,
+                            org.onlab.rest.*,
+                            org.onosproject.*,
+                            org.onlab.util.*,
+                            org.jboss.netty.util.*
+                        </Import-Package>
+                        <Web-ContextPath>${web.context}</Web-ContextPath>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
 </project>
diff --git a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/DHCPService.java b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/DHCPService.java
index 2bc7724..0afda10 100644
--- a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/DHCPService.java
+++ b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/DHCPService.java
@@ -30,37 +30,37 @@
      *
      * @return collection of mappings.
      */
-    public Map<MacAddress, Ip4Address> listMapping();
+    Map<MacAddress, Ip4Address> listMapping();
 
     /**
      * Returns the default lease time granted by the DHCP Server.
      *
      * @return lease time
      */
-    public int getLeaseTime();
+    int getLeaseTime();
 
     /**
      * Returns the default renewal time granted by the DHCP Server.
      *
      * @return renewal time
      */
-    public int getRenewalTime();
+    int getRenewalTime();
 
     /**
      * Returns the default rebinding time granted by the DHCP Server.
      *
      * @return rebinding time
      */
-    public int getRebindingTime();
+    int getRebindingTime();
 
     /**
      * Registers a static IP mapping with the DHCP Server.
      *
-     * @param macID macID of the client
+     * @param macID     macID of the client
      * @param ipAddress IP Address requested for the client
      * @return true if the mapping was successfully registered, false otherwise
      */
-    public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress);
+    boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress);
 
     /**
      * Removes a static IP mapping with the DHCP Server.
@@ -68,13 +68,13 @@
      * @param macID macID of the client
      * @return true if the mapping was successfully removed, false otherwise
      */
-    public boolean removeStaticMapping(MacAddress macID);
+    boolean removeStaticMapping(MacAddress macID);
 
     /**
      * Returns the list of all the available IPs with the server.
      *
      * @return list of available IPs
      */
-    public Iterable<Ip4Address> getAvailableIPs();
+    Iterable<Ip4Address> getAvailableIPs();
 
 }
diff --git a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/rest/DHCPWebResource.java b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/rest/DHCPWebResource.java
new file mode 100644
index 0000000..639dbf0
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/rest/DHCPWebResource.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 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.dhcpserver.rest;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.dhcpserver.DHCPService;
+import org.onosproject.rest.AbstractWebResource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+/**
+ * Manage DHCP address assignments.
+ */
+@Path("/")
+public class DHCPWebResource extends AbstractWebResource {
+
+    /**
+     * Get DHCP server configuration data.
+     * Shows lease, renewal and rebinding times in seconds.
+     *
+     * @return 200 OK
+     */
+    @GET
+    @Path("config")
+    public Response getConfigs() {
+        DHCPService service = get(DHCPService.class);
+        ObjectNode node = mapper().createObjectNode()
+                .put("leaseTime", service.getLeaseTime())
+                .put("renewalTime", service.getRenewalTime())
+                .put("rebindingTime", service.getRebindingTime());
+        return ok(node.toString()).build();
+    }
+
+
+    // POST should accept a single mac/ip binding with
+    /*
+        {
+            "mac": "00:......00",
+            "ip": "12.34.56.78"
+        }
+     */
+
+    //    @POST
+    //    @Path("mappings")
+
+
+
+    // GET all mappings should look like this:
+    /*
+        {
+            "mappings": [
+                {
+                    "mac": "00:......00",
+                    "ip": "12.34.56.78",
+                    ...
+                }
+            ]
+        }
+     */
+}
diff --git a/onos-app-dhcpserver/src/main/webapp/WEB-INF/web.xml b/onos-app-dhcpserver/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5691f17
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 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.
+  -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         id="ONOS" version="2.5">
+    <display-name>DHCP Server REST API v1.0</display-name>
+
+    <servlet>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
+            <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
+        </init-param>
+        <init-param>
+            <param-name>com.sun.jersey.config.property.classnames</param-name>
+            <param-value>
+                org.onosproject.dhcpserver.rest.DHCPWebResource
+            </param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>