Adding skeletal REST API for DHCP app.
Change-Id: I9c3ceed5f12f8b293287562bcb1dd7699b676376
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>