aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java')
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java48
1 files changed, 42 insertions, 6 deletions
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 63f69d40..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
@@ -38,8 +38,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
-import java.util.HashMap;
import java.util.Map;
+import java.util.List;
+import java.util.HashMap;
import java.util.Objects;
/**
@@ -105,7 +106,9 @@ public class DistributedDhcpStore implements DhcpStore {
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
Ip4Address ipAddr = assignmentInfo.ipAddress();
- if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
+ if (assignmentInfo.rangeNotEnforced()) {
+ return assignmentInfo.ipAddress();
+ } else if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
status == IpAssignment.AssignmentStatus.Option_Requested) {
// Client has a currently Active Binding.
if (ipWithinRange(ipAddr)) {
@@ -160,10 +163,15 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) {
+ 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();
@@ -207,6 +215,20 @@ public class DistributedDhcpStore implements DhcpStore {
allocationMap.put(hostId, assignmentInfo);
return true;
}
+ } else if (rangeNotEnforced) {
+ assignmentInfo = IpAssignment.builder()
+ .ipAddress(ipAddr)
+ .timestamp(new Date())
+ .leasePeriod(leaseTime)
+ .rangeNotEnforced(true)
+ .assignmentStatus(IpAssignment.AssignmentStatus.Option_RangeNotEnforced)
+ .subnetMask((Ip4Address) addressList.toArray()[0])
+ .dhcpServer((Ip4Address) addressList.toArray()[1])
+ .routerAddress((Ip4Address) addressList.toArray()[2])
+ .domainServer((Ip4Address) addressList.toArray()[3])
+ .build();
+ allocationMap.put(hostId, assignmentInfo);
+ return true;
}
return false;
}
@@ -239,7 +261,8 @@ public class DistributedDhcpStore implements DhcpStore {
IpAssignment assignment;
for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
assignment = entry.getValue().value();
- if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned) {
+ if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned
+ || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_RangeNotEnforced) {
validMapping.put(entry.getKey(), assignment);
}
}
@@ -256,9 +279,10 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) {
+ public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced,
+ List<Ip4Address> addressList) {
HostId host = HostId.hostId(macID);
- return assignIP(host, ipAddr, -1);
+ return assignIP(host, ipAddr, -1, rangeNotEnforced, addressList);
}
@Override
@@ -266,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);
@@ -299,6 +329,11 @@ public class DistributedDhcpStore implements DhcpStore {
}
}
+ @Override
+ public IpAssignment getIpAssignmentFromAllocationMap(HostId hostId) {
+ return allocationMap.get(hostId).value();
+ }
+
/**
* Fetches the next available IP from the free pool pf IPs.
*
@@ -326,3 +361,4 @@ public class DistributedDhcpStore implements DhcpStore {
return false;
}
}
+