summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/dhcp')
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java8
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java13
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java36
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java17
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java29
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java29
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java165
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml2
-rw-r--r--framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java6
9 files changed, 83 insertions, 222 deletions
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
index e356c38b..ae610239 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
@@ -58,15 +58,15 @@ public interface DhcpService {
/**
* Registers a static IP mapping with the DHCP Server.
- * Supports the request from OpenStack
+ * Supports rangeNotEnforced option
*
* @param macID macID of the client
* @param ipAddress IP Address requested for the client
- * @param fromOpenStack true if the request is from OpenStack
- * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack
+ * @param rangeNotEnforced true if rangeNotEnforced was set and the mapping will be eternal
+ * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set
* @return true if the mapping was successfully added, false otherwise
*/
- boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack,
+ boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced,
List<Ip4Address> addressList);
/**
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
index bd2e16b3..cdfadf7b 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
@@ -52,12 +52,11 @@ public interface DhcpStore {
* @param hostId Host Id of the client requesting an IP
* @param ipAddr IP Address being requested
* @param leaseTime Lease time offered by the server for this mapping
- * @param fromOpenStack true if the request is from Openstack
- * @param addressList subnetMask, DHCP IP Address, Router IP Address, Domain Server IP Address if the request
- * from OpenStack
+ * @param rangeNotEnforced true if rangeNotEnforced was set
+ * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set
* @return returns true if the assignment was successful, false otherwise
*/
- boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced,
List<Ip4Address> addressList);
@@ -95,11 +94,11 @@ public interface DhcpStore {
*
* @param macID macID of the client
* @param ipAddr IP Address requested for the client
- * @param fromOpenStack true if the request is from Openstack
- * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack
+ * @param rangeNotEnforced true if rangeNotEnforced was set
+ * @param addressList subnetMask, DHCP/Router/DNS IP Addresses rangeNotEnforced was set
* @return true if the mapping was successfully registered, false otherwise
*/
- boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack, List<Ip4Address> addressList);
+ boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced, List<Ip4Address> addressList);
/**
* Removes a static IP mapping associated with the given MAC ID from the DHCP Server.
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
index 998579e2..5610fec8 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
@@ -41,7 +41,7 @@ public final class IpAssignment {
private final Ip4Address domainServer;
- private final boolean fromOpenStack;
+ private final boolean rangeNotEnforced;
private final AssignmentStatus assignmentStatus;
@@ -54,7 +54,7 @@ public final class IpAssignment {
/**
* IP Assignment has been requested by a OpenStack.
*/
- Option_Requested_From_OpenStack,
+ Option_RangeNotEnforced,
/**
* IP has been assigned to a host.
*/
@@ -78,13 +78,13 @@ public final class IpAssignment {
* @param dhcpServer
* @param routerAddress
* @param domainServer
- * @param fromOpenStack
+ * @param rangeNotEnforced
*/
private IpAssignment(Ip4Address ipAddress,
long leasePeriod,
Date timestamp,
AssignmentStatus assignmentStatus, Ip4Address subnetMask, Ip4Address dhcpServer,
- Ip4Address routerAddress, Ip4Address domainServer, boolean fromOpenStack) {
+ Ip4Address routerAddress, Ip4Address domainServer, boolean rangeNotEnforced) {
this.ipAddress = ipAddress;
this.leasePeriod = leasePeriod;
this.timestamp = timestamp;
@@ -93,7 +93,7 @@ public final class IpAssignment {
this.dhcpServer = dhcpServer;
this.routerAddress = routerAddress;
this.domainServer = domainServer;
- this.fromOpenStack = fromOpenStack;
+ this.rangeNotEnforced = rangeNotEnforced;
}
/**
@@ -157,8 +157,8 @@ public final class IpAssignment {
return domainServer;
}
- public boolean fromOpenStack() {
- return fromOpenStack;
+ public boolean rangeNotEnforced() {
+ return rangeNotEnforced;
}
@Override
@@ -172,7 +172,7 @@ public final class IpAssignment {
.add("dhcpServer", dhcpServer)
.add("routerAddress", routerAddress)
.add("domainServer", domainServer)
- .add("fromOpenStack", fromOpenStack)
+ .add("rangeNotEnforced", rangeNotEnforced)
.toString();
}
@@ -216,7 +216,7 @@ public final class IpAssignment {
private Ip4Address routerAddress;
- private boolean fromOpenStack = false;
+ private boolean rangeNotEnforced = false;
private Builder() {
@@ -232,7 +232,7 @@ public final class IpAssignment {
public IpAssignment build() {
validateInputs();
return new IpAssignment(ipAddress, leasePeriod, timeStamp, assignmentStatus, subnetMask,
- dhcpServer, domainServer, routerAddress, fromOpenStack);
+ dhcpServer, domainServer, routerAddress, rangeNotEnforced);
}
public Builder ipAddress(Ip4Address addr) {
@@ -275,8 +275,8 @@ public final class IpAssignment {
return this;
}
- public Builder fromOpenStack(boolean fromOpenStack) {
- this.fromOpenStack = fromOpenStack;
+ public Builder rangeNotEnforced(boolean rangeNotEnforced) {
+ this.rangeNotEnforced = rangeNotEnforced;
return this;
}
@@ -287,16 +287,16 @@ public final class IpAssignment {
checkNotNull(leasePeriod, "Lease Period must be specified");
checkNotNull(timeStamp, "Timestamp must be specified");
- if (fromOpenStack) {
- checkNotNull(subnetMask, "subnetMask must be specified in case of OpenStack");
- checkNotNull(dhcpServer, "dhcpServer must be specified in case of OpenStack");
- checkNotNull(domainServer, "domainServer must be specified in case of OpenStack");
- checkNotNull(routerAddress, "routerAddress must be specified in case of OpenStack");
+ if (rangeNotEnforced) {
+ checkNotNull(subnetMask, "subnetMask must be specified in case of rangeNotEnforced");
+ checkNotNull(dhcpServer, "dhcpServer must be specified in case of rangeNotEnforced");
+ checkNotNull(domainServer, "domainServer must be specified in case of rangeNotEnforced");
+ checkNotNull(routerAddress, "routerAddress must be specified in case of rangeNotEnforced");
}
switch (assignmentStatus) {
case Option_Requested:
- case Option_Requested_From_OpenStack:
+ case Option_RangeNotEnforced:
case Option_Assigned:
case Option_Expired:
break;
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java
index 4353d623..1efdd082 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java
@@ -21,6 +21,9 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.basics.BasicElementConfig;
+import static org.onosproject.net.config.Config.FieldPresence.MANDATORY;
+import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL;
+
/**
* DHCP Config class.
*/
@@ -43,6 +46,20 @@ public class DhcpConfig extends Config<ApplicationId> {
public static final int DEFAULT = -1;
+ @Override
+ public boolean isValid() {
+ // FIXME: Sweep through and revisit the validation assertions
+ // For now, this is just a demonstration of potential uses
+ return hasOnlyFields(MY_IP, MY_MAC, SUBNET_MASK, BROADCAST_ADDRESS,
+ ROUTER_ADDRESS, DOMAIN_SERVER, TTL, LEASE_TIME,
+ RENEW_TIME, REBIND_TIME, TIMER_DELAY, DEFAULT_TIMEOUT,
+ START_IP, END_IP) &&
+ isIpAddress(MY_IP, MANDATORY) && isMacAddress(MY_MAC, MANDATORY) &&
+ isIpAddress(START_IP, MANDATORY) && isIpAddress(END_IP, MANDATORY) &&
+ isNumber(LEASE_TIME, OPTIONAL, 1) && isNumber(REBIND_TIME, OPTIONAL, 1) &&
+ isNumber(DEFAULT_TIMEOUT, OPTIONAL, 1, 3600);
+ }
+
/**
* Returns the dhcp server ip.
*
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
index 4093f2d2..a1707e0b 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
@@ -109,7 +109,7 @@ public class DhcpManager implements DhcpService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
- private DHCPPacketProcessor processor = new DHCPPacketProcessor();
+ private DhcpPacketProcessor processor = new DhcpPacketProcessor();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@@ -241,12 +241,12 @@ public class DhcpManager implements DhcpService {
}
@Override
- public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack,
+ public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced,
List<Ip4Address> addressList) {
log.debug("setStaticMapping is called with Mac: {}, Ip: {} addressList: {}",
macID.toString(), ipAddress.toString(), addressList.toString());
- return dhcpStore.assignStaticIP(macID, ipAddress, fromOpenStack, addressList);
+ return dhcpStore.assignStaticIP(macID, ipAddress, rangeNotEnforced, addressList);
}
@Override
@@ -259,7 +259,7 @@ public class DhcpManager implements DhcpService {
return dhcpStore.getAvailableIPs();
}
- private class DHCPPacketProcessor implements PacketProcessor {
+ private class DhcpPacketProcessor implements PacketProcessor {
/**
* Builds the DHCP Reply packet.
@@ -279,7 +279,7 @@ public class DhcpManager implements DhcpService {
ipAssignment = dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(packet.getSourceMAC()));
- if (ipAssignment != null && ipAssignment.fromOpenStack()) {
+ if (ipAssignment != null && ipAssignment.rangeNotEnforced()) {
subnetMaskReply = ipAssignment.subnetMask();
dhcpServerReply = ipAssignment.dhcpServer();
domainServerReply = ipAssignment.domainServer();
@@ -437,7 +437,7 @@ public class DhcpManager implements DhcpService {
* @param context context of the incoming message
* @param dhcpPayload the extracted DHCP payload
*/
- private void processDHCPPacket(PacketContext context, DHCP dhcpPayload) {
+ private void processDhcpPacket(PacketContext context, DHCP dhcpPayload) {
Ethernet packet = context.inPacket().parsed();
boolean flagIfRequestedIP = false;
boolean flagIfServerIP = false;
@@ -464,9 +464,9 @@ public class DhcpManager implements DhcpService {
}
}
DHCPPacketType outgoingPacketType;
- MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress());
+ MacAddress clientMac = new MacAddress(dhcpPayload.getClientHardwareAddress());
VlanId vlanId = VlanId.vlanId(packet.getVlanID());
- HostId hostId = HostId.hostId(clientMAC, vlanId);
+ HostId hostId = HostId.hostId(clientMac, vlanId);
if (incomingPacketType.getValue() == DHCPPacketType.DHCPDISCOVER.getValue()) {
@@ -484,8 +484,9 @@ public class DhcpManager implements DhcpService {
if (flagIfServerIP && flagIfRequestedIP) {
// SELECTING state
- if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMAC))
- .fromOpenStack()) {
+
+ if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMac))
+ .rangeNotEnforced()) {
outgoingPacketType = DHCPPacketType.DHCPACK;
Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue());
sendReply(context, ethReply);
@@ -544,7 +545,7 @@ public class DhcpManager implements DhcpService {
* @param context context of the incoming message
* @param packet the ethernet payload
*/
- private void processARPPacket(PacketContext context, Ethernet packet) {
+ private void processArpPacket(PacketContext context, Ethernet packet) {
ARP arpPacket = (ARP) packet.getPayload();
@@ -605,7 +606,7 @@ public class DhcpManager implements DhcpService {
// This is meant for the dhcp server so process the packet here.
DHCP dhcpPayload = (DHCP) udpPacket.getPayload();
- processDHCPPacket(context, dhcpPayload);
+ processDhcpPacket(context, dhcpPayload);
}
}
} else if (packet.getEtherType() == Ethernet.TYPE_ARP) {
@@ -614,7 +615,7 @@ public class DhcpManager implements DhcpService {
if ((arpPacket.getOpCode() == ARP.OP_REQUEST) &&
Objects.equals(myIP, Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()))) {
- processARPPacket(context, packet);
+ processArpPacket(context, packet);
}
}
@@ -727,4 +728,4 @@ public class DhcpManager implements DhcpService {
timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES);
}
}
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
index 0f25495e..ad4522cb 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
@@ -106,7 +106,7 @@ public class DistributedDhcpStore implements DhcpStore {
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
Ip4Address ipAddr = assignmentInfo.ipAddress();
- if (assignmentInfo.fromOpenStack()) {
+ if (assignmentInfo.rangeNotEnforced()) {
return assignmentInfo.ipAddress();
} else if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
status == IpAssignment.AssignmentStatus.Option_Requested) {
@@ -163,12 +163,15 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced,
List<Ip4Address> addressList) {
IpAssignment assignmentInfo;
+ log.debug("Assign IP Called w/ Ip4Address: {}, HostId: {}", ipAddr.toString(), hostId.mac().toString());
+
if (allocationMap.containsKey(hostId)) {
+
assignmentInfo = allocationMap.get(hostId).value();
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
@@ -212,17 +215,17 @@ public class DistributedDhcpStore implements DhcpStore {
allocationMap.put(hostId, assignmentInfo);
return true;
}
- } else if (fromOpenStack) {
+ } else if (rangeNotEnforced) {
assignmentInfo = IpAssignment.builder()
.ipAddress(ipAddr)
.timestamp(new Date())
.leasePeriod(leaseTime)
- .fromOpenStack(true)
- .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack)
+ .rangeNotEnforced(true)
+ .assignmentStatus(IpAssignment.AssignmentStatus.Option_RangeNotEnforced)
.subnetMask((Ip4Address) addressList.toArray()[0])
.dhcpServer((Ip4Address) addressList.toArray()[1])
- .domainServer((Ip4Address) addressList.toArray()[2])
- .routerAddress((Ip4Address) addressList.toArray()[3])
+ .routerAddress((Ip4Address) addressList.toArray()[2])
+ .domainServer((Ip4Address) addressList.toArray()[3])
.build();
allocationMap.put(hostId, assignmentInfo);
return true;
@@ -259,7 +262,7 @@ public class DistributedDhcpStore implements DhcpStore {
for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
assignment = entry.getValue().value();
if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned
- || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack) {
+ || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_RangeNotEnforced) {
validMapping.put(entry.getKey(), assignment);
}
}
@@ -276,10 +279,10 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack,
+ public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced,
List<Ip4Address> addressList) {
HostId host = HostId.hostId(macID);
- return assignIP(host, ipAddr, -1, fromOpenStack, addressList);
+ return assignIP(host, ipAddr, -1, rangeNotEnforced, addressList);
}
@Override
@@ -287,6 +290,12 @@ public class DistributedDhcpStore implements DhcpStore {
HostId host = HostId.hostId(macID);
if (allocationMap.containsKey(host)) {
IpAssignment assignment = allocationMap.get(host).value();
+
+ if (assignment.rangeNotEnforced()) {
+ allocationMap.remove(host);
+ return true;
+ }
+
Ip4Address freeIP = assignment.ipAddress();
if (assignment.leasePeriod() < 0) {
allocationMap.remove(host);
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
deleted file mode 100644
index 7a078df9..00000000
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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.dhcp.rest;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.Lists;
-import org.onlab.packet.Ip4Address;
-import org.onlab.packet.MacAddress;
-import org.onosproject.dhcp.DhcpService;
-import org.onosproject.dhcp.IpAssignment;
-import org.onosproject.net.HostId;
-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.PathParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-
-/**
- * Manage DHCP address assignments.
- */
-@Path("dhcp")
-public class DHCPWebResource extends AbstractWebResource {
-
- final DhcpService service = get(DhcpService.class);
-
- /**
- * 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();
- }
-
- /**
- * Get all MAC/IP mappings.
- * Shows all MAC/IP mappings held by the DHCP server.
- *
- * @return 200 OK
- */
- @GET
- @Path("mappings")
- public Response listMappings() {
- ObjectNode root = mapper().createObjectNode();
-
- final Map<HostId, IpAssignment> intents = service.listMapping();
- ArrayNode arrayNode = root.putArray("mappings");
- intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
- .put("host", i.getKey().toString())
- .put("ip", i.getValue().ipAddress().toString())));
-
- return ok(root.toString()).build();
- }
-
-
-
- /**
- * Get all available IPs.
- * Shows all the IPs in the free pool of the DHCP Server.
- *
- * @return 200 OK
- */
- @GET
- @Path("available")
- public Response listAvailableIPs() {
- final Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
-
- final ObjectNode root = mapper().createObjectNode();
- ArrayNode arrayNode = root.putArray("availableIP");
- availableIPList.forEach(i -> arrayNode.add(i.toString()));
- return ok(root.toString()).build();
- }
-
- /**
- * Post a new static MAC/IP binding.
- * Registers a static binding to the DHCP server, and displays the current set of bindings.
- *
- * @param stream JSON stream
- * @return 200 OK
- */
- @POST
- @Path("mappings")
- @Consumes(MediaType.APPLICATION_JSON)
- public Response setMapping(InputStream stream) {
- ObjectNode root = mapper().createObjectNode();
-
- try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
- JsonNode macID = jsonTree.get("mac");
- JsonNode ip = jsonTree.get("ip");
- if (macID != null && ip != null) {
-
- if (!service.setStaticMapping(MacAddress.valueOf(macID.asText()),
- Ip4Address.valueOf(ip.asText()), false, Lists.newArrayList())) {
- throw new IllegalArgumentException("Static Mapping Failed. The IP maybe unavailable.");
- }
- }
-
- final Map<HostId, IpAssignment> intents = service.listMapping();
- ArrayNode arrayNode = root.putArray("mappings");
- intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
- .put("host", i.getKey().toString())
- .put("ip", i.getValue().ipAddress().toString())));
- } catch (IOException e) {
- throw new IllegalArgumentException(e.getMessage());
- }
- return ok(root.toString()).build();
- }
-
- /**
- * Delete a static MAC/IP binding.
- * Removes a static binding from the DHCP Server, and displays the current set of bindings.
- *
- * @param macID mac address identifier
- * @return 200 OK
- */
- @DELETE
- @Path("mappings/{macID}")
- public Response deleteMapping(@PathParam("macID") String macID) {
-
- ObjectNode root = mapper().createObjectNode();
-
- if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
- throw new IllegalArgumentException("Static Mapping Removal Failed.");
- }
- final Map<HostId, IpAssignment> intents = service.listMapping();
- ArrayNode arrayNode = root.putArray("mappings");
- intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
- .put("host", i.getKey().toString())
- .put("ip", i.getValue().ipAddress().toString())));
-
- return ok(root.toString()).build();
- }
-}
diff --git a/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
index 27504548..a53110ee 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
+++ b/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
@@ -30,7 +30,7 @@
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>
- org.onosproject.dhcp.rest.DHCPWebResource
+ org.onosproject.dhcp.rest.DhcpWebResource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
diff --git a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
index bb6b74cc..e9b02608 100644
--- a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
+++ b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
@@ -106,7 +106,7 @@ public class DhcpManagerTest {
*/
@Test
public void testDiscover() {
- Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPDISCOVER);
+ Ethernet reply = constructDhcpPacket(DHCPPacketType.DHCPDISCOVER);
sendPacket(reply);
}
@@ -115,7 +115,7 @@ public class DhcpManagerTest {
*/
@Test
public void testRequest() {
- Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPREQUEST);
+ Ethernet reply = constructDhcpPacket(DHCPPacketType.DHCPREQUEST);
sendPacket(reply);
}
@@ -138,7 +138,7 @@ public class DhcpManagerTest {
* @param packetType DHCP Message Type
* @return Ethernet packet
*/
- private Ethernet constructDHCPPacket(DHCPPacketType packetType) {
+ private Ethernet constructDhcpPacket(DHCPPacketType packetType) {
// Ethernet Frame.
Ethernet ethReply = new Ethernet();