daniel
Committed by Gerrit Code Review

Fix DhcpService

 - boolean 'fromOpenstack' is changed to 'rangeNotEnforced'
 - rebased with master

Change-Id: Ida2828367339cdb0129f1555df9e1c90e6da6975
...@@ -58,15 +58,15 @@ public interface DhcpService { ...@@ -58,15 +58,15 @@ public interface DhcpService {
58 58
59 /** 59 /**
60 * Registers a static IP mapping with the DHCP Server. 60 * Registers a static IP mapping with the DHCP Server.
61 - * Supports the request from OpenStack 61 + * Supports rangeNotEnforced option
62 * 62 *
63 * @param macID macID of the client 63 * @param macID macID of the client
64 * @param ipAddress IP Address requested for the client 64 * @param ipAddress IP Address requested for the client
65 - * @param fromOpenStack true if the request is from OpenStack 65 + * @param rangeNotEnforced true if rangeNotEnforced was set and the mapping will be eternal
66 - * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack 66 + * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set
67 * @return true if the mapping was successfully added, false otherwise 67 * @return true if the mapping was successfully added, false otherwise
68 */ 68 */
69 - boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack, 69 + boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced,
70 List<Ip4Address> addressList); 70 List<Ip4Address> addressList);
71 71
72 /** 72 /**
......
...@@ -52,12 +52,11 @@ public interface DhcpStore { ...@@ -52,12 +52,11 @@ public interface DhcpStore {
52 * @param hostId Host Id of the client requesting an IP 52 * @param hostId Host Id of the client requesting an IP
53 * @param ipAddr IP Address being requested 53 * @param ipAddr IP Address being requested
54 * @param leaseTime Lease time offered by the server for this mapping 54 * @param leaseTime Lease time offered by the server for this mapping
55 - * @param fromOpenStack true if the request is from Openstack 55 + * @param rangeNotEnforced true if rangeNotEnforced was set
56 - * @param addressList subnetMask, DHCP IP Address, Router IP Address, Domain Server IP Address if the request 56 + * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set
57 - * from OpenStack
58 * @return returns true if the assignment was successful, false otherwise 57 * @return returns true if the assignment was successful, false otherwise
59 */ 58 */
60 - boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack, 59 + boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced,
61 List<Ip4Address> addressList); 60 List<Ip4Address> addressList);
62 61
63 62
...@@ -95,11 +94,11 @@ public interface DhcpStore { ...@@ -95,11 +94,11 @@ public interface DhcpStore {
95 * 94 *
96 * @param macID macID of the client 95 * @param macID macID of the client
97 * @param ipAddr IP Address requested for the client 96 * @param ipAddr IP Address requested for the client
98 - * @param fromOpenStack true if the request is from Openstack 97 + * @param rangeNotEnforced true if rangeNotEnforced was set
99 - * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack 98 + * @param addressList subnetMask, DHCP/Router/DNS IP Addresses rangeNotEnforced was set
100 * @return true if the mapping was successfully registered, false otherwise 99 * @return true if the mapping was successfully registered, false otherwise
101 */ 100 */
102 - boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack, List<Ip4Address> addressList); 101 + boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced, List<Ip4Address> addressList);
103 102
104 /** 103 /**
105 * Removes a static IP mapping associated with the given MAC ID from the DHCP Server. 104 * Removes a static IP mapping associated with the given MAC ID from the DHCP Server.
......
...@@ -41,7 +41,7 @@ public final class IpAssignment { ...@@ -41,7 +41,7 @@ public final class IpAssignment {
41 41
42 private final Ip4Address domainServer; 42 private final Ip4Address domainServer;
43 43
44 - private final boolean fromOpenStack; 44 + private final boolean rangeNotEnforced;
45 45
46 private final AssignmentStatus assignmentStatus; 46 private final AssignmentStatus assignmentStatus;
47 47
...@@ -54,7 +54,7 @@ public final class IpAssignment { ...@@ -54,7 +54,7 @@ public final class IpAssignment {
54 /** 54 /**
55 * IP Assignment has been requested by a OpenStack. 55 * IP Assignment has been requested by a OpenStack.
56 */ 56 */
57 - Option_Requested_From_OpenStack, 57 + Option_RangeNotEnforced,
58 /** 58 /**
59 * IP has been assigned to a host. 59 * IP has been assigned to a host.
60 */ 60 */
...@@ -78,13 +78,13 @@ public final class IpAssignment { ...@@ -78,13 +78,13 @@ public final class IpAssignment {
78 * @param dhcpServer 78 * @param dhcpServer
79 * @param routerAddress 79 * @param routerAddress
80 * @param domainServer 80 * @param domainServer
81 - * @param fromOpenStack 81 + * @param rangeNotEnforced
82 */ 82 */
83 private IpAssignment(Ip4Address ipAddress, 83 private IpAssignment(Ip4Address ipAddress,
84 long leasePeriod, 84 long leasePeriod,
85 Date timestamp, 85 Date timestamp,
86 AssignmentStatus assignmentStatus, Ip4Address subnetMask, Ip4Address dhcpServer, 86 AssignmentStatus assignmentStatus, Ip4Address subnetMask, Ip4Address dhcpServer,
87 - Ip4Address routerAddress, Ip4Address domainServer, boolean fromOpenStack) { 87 + Ip4Address routerAddress, Ip4Address domainServer, boolean rangeNotEnforced) {
88 this.ipAddress = ipAddress; 88 this.ipAddress = ipAddress;
89 this.leasePeriod = leasePeriod; 89 this.leasePeriod = leasePeriod;
90 this.timestamp = timestamp; 90 this.timestamp = timestamp;
...@@ -93,7 +93,7 @@ public final class IpAssignment { ...@@ -93,7 +93,7 @@ public final class IpAssignment {
93 this.dhcpServer = dhcpServer; 93 this.dhcpServer = dhcpServer;
94 this.routerAddress = routerAddress; 94 this.routerAddress = routerAddress;
95 this.domainServer = domainServer; 95 this.domainServer = domainServer;
96 - this.fromOpenStack = fromOpenStack; 96 + this.rangeNotEnforced = rangeNotEnforced;
97 } 97 }
98 98
99 /** 99 /**
...@@ -157,8 +157,8 @@ public final class IpAssignment { ...@@ -157,8 +157,8 @@ public final class IpAssignment {
157 return domainServer; 157 return domainServer;
158 } 158 }
159 159
160 - public boolean fromOpenStack() { 160 + public boolean rangeNotEnforced() {
161 - return fromOpenStack; 161 + return rangeNotEnforced;
162 } 162 }
163 163
164 @Override 164 @Override
...@@ -172,7 +172,7 @@ public final class IpAssignment { ...@@ -172,7 +172,7 @@ public final class IpAssignment {
172 .add("dhcpServer", dhcpServer) 172 .add("dhcpServer", dhcpServer)
173 .add("routerAddress", routerAddress) 173 .add("routerAddress", routerAddress)
174 .add("domainServer", domainServer) 174 .add("domainServer", domainServer)
175 - .add("fromOpenStack", fromOpenStack) 175 + .add("rangeNotEnforced", rangeNotEnforced)
176 .toString(); 176 .toString();
177 } 177 }
178 178
...@@ -216,7 +216,7 @@ public final class IpAssignment { ...@@ -216,7 +216,7 @@ public final class IpAssignment {
216 216
217 private Ip4Address routerAddress; 217 private Ip4Address routerAddress;
218 218
219 - private boolean fromOpenStack = false; 219 + private boolean rangeNotEnforced = false;
220 220
221 private Builder() { 221 private Builder() {
222 222
...@@ -232,7 +232,7 @@ public final class IpAssignment { ...@@ -232,7 +232,7 @@ public final class IpAssignment {
232 public IpAssignment build() { 232 public IpAssignment build() {
233 validateInputs(); 233 validateInputs();
234 return new IpAssignment(ipAddress, leasePeriod, timeStamp, assignmentStatus, subnetMask, 234 return new IpAssignment(ipAddress, leasePeriod, timeStamp, assignmentStatus, subnetMask,
235 - dhcpServer, domainServer, routerAddress, fromOpenStack); 235 + dhcpServer, domainServer, routerAddress, rangeNotEnforced);
236 } 236 }
237 237
238 public Builder ipAddress(Ip4Address addr) { 238 public Builder ipAddress(Ip4Address addr) {
...@@ -275,8 +275,8 @@ public final class IpAssignment { ...@@ -275,8 +275,8 @@ public final class IpAssignment {
275 return this; 275 return this;
276 } 276 }
277 277
278 - public Builder fromOpenStack(boolean fromOpenStack) { 278 + public Builder rangeNotEnforced(boolean rangeNotEnforced) {
279 - this.fromOpenStack = fromOpenStack; 279 + this.rangeNotEnforced = rangeNotEnforced;
280 return this; 280 return this;
281 } 281 }
282 282
...@@ -287,16 +287,16 @@ public final class IpAssignment { ...@@ -287,16 +287,16 @@ public final class IpAssignment {
287 checkNotNull(leasePeriod, "Lease Period must be specified"); 287 checkNotNull(leasePeriod, "Lease Period must be specified");
288 checkNotNull(timeStamp, "Timestamp must be specified"); 288 checkNotNull(timeStamp, "Timestamp must be specified");
289 289
290 - if (fromOpenStack) { 290 + if (rangeNotEnforced) {
291 - checkNotNull(subnetMask, "subnetMask must be specified in case of OpenStack"); 291 + checkNotNull(subnetMask, "subnetMask must be specified in case of rangeNotEnforced");
292 - checkNotNull(dhcpServer, "dhcpServer must be specified in case of OpenStack"); 292 + checkNotNull(dhcpServer, "dhcpServer must be specified in case of rangeNotEnforced");
293 - checkNotNull(domainServer, "domainServer must be specified in case of OpenStack"); 293 + checkNotNull(domainServer, "domainServer must be specified in case of rangeNotEnforced");
294 - checkNotNull(routerAddress, "routerAddress must be specified in case of OpenStack"); 294 + checkNotNull(routerAddress, "routerAddress must be specified in case of rangeNotEnforced");
295 } 295 }
296 296
297 switch (assignmentStatus) { 297 switch (assignmentStatus) {
298 case Option_Requested: 298 case Option_Requested:
299 - case Option_Requested_From_OpenStack: 299 + case Option_RangeNotEnforced:
300 case Option_Assigned: 300 case Option_Assigned:
301 case Option_Expired: 301 case Option_Expired:
302 break; 302 break;
......
...@@ -241,12 +241,12 @@ public class DhcpManager implements DhcpService { ...@@ -241,12 +241,12 @@ public class DhcpManager implements DhcpService {
241 } 241 }
242 242
243 @Override 243 @Override
244 - public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack, 244 + public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced,
245 List<Ip4Address> addressList) { 245 List<Ip4Address> addressList) {
246 log.debug("setStaticMapping is called with Mac: {}, Ip: {} addressList: {}", 246 log.debug("setStaticMapping is called with Mac: {}, Ip: {} addressList: {}",
247 macID.toString(), ipAddress.toString(), addressList.toString()); 247 macID.toString(), ipAddress.toString(), addressList.toString());
248 248
249 - return dhcpStore.assignStaticIP(macID, ipAddress, fromOpenStack, addressList); 249 + return dhcpStore.assignStaticIP(macID, ipAddress, rangeNotEnforced, addressList);
250 } 250 }
251 251
252 @Override 252 @Override
...@@ -279,7 +279,7 @@ public class DhcpManager implements DhcpService { ...@@ -279,7 +279,7 @@ public class DhcpManager implements DhcpService {
279 279
280 ipAssignment = dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(packet.getSourceMAC())); 280 ipAssignment = dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(packet.getSourceMAC()));
281 281
282 - if (ipAssignment != null && ipAssignment.fromOpenStack()) { 282 + if (ipAssignment != null && ipAssignment.rangeNotEnforced()) {
283 subnetMaskReply = ipAssignment.subnetMask(); 283 subnetMaskReply = ipAssignment.subnetMask();
284 dhcpServerReply = ipAssignment.dhcpServer(); 284 dhcpServerReply = ipAssignment.dhcpServer();
285 domainServerReply = ipAssignment.domainServer(); 285 domainServerReply = ipAssignment.domainServer();
...@@ -484,8 +484,9 @@ public class DhcpManager implements DhcpService { ...@@ -484,8 +484,9 @@ public class DhcpManager implements DhcpService {
484 if (flagIfServerIP && flagIfRequestedIP) { 484 if (flagIfServerIP && flagIfRequestedIP) {
485 // SELECTING state 485 // SELECTING state
486 486
487 +
487 if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMac)) 488 if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMac))
488 - .fromOpenStack()) { 489 + .rangeNotEnforced()) {
489 outgoingPacketType = DHCPPacketType.DHCPACK; 490 outgoingPacketType = DHCPPacketType.DHCPACK;
490 Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue()); 491 Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue());
491 sendReply(context, ethReply); 492 sendReply(context, ethReply);
......
...@@ -106,7 +106,7 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -106,7 +106,7 @@ public class DistributedDhcpStore implements DhcpStore {
106 IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus(); 106 IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
107 Ip4Address ipAddr = assignmentInfo.ipAddress(); 107 Ip4Address ipAddr = assignmentInfo.ipAddress();
108 108
109 - if (assignmentInfo.fromOpenStack()) { 109 + if (assignmentInfo.rangeNotEnforced()) {
110 return assignmentInfo.ipAddress(); 110 return assignmentInfo.ipAddress();
111 } else if (status == IpAssignment.AssignmentStatus.Option_Assigned || 111 } else if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
112 status == IpAssignment.AssignmentStatus.Option_Requested) { 112 status == IpAssignment.AssignmentStatus.Option_Requested) {
...@@ -163,12 +163,15 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -163,12 +163,15 @@ public class DistributedDhcpStore implements DhcpStore {
163 } 163 }
164 164
165 @Override 165 @Override
166 - public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack, 166 + public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced,
167 List<Ip4Address> addressList) { 167 List<Ip4Address> addressList) {
168 168
169 IpAssignment assignmentInfo; 169 IpAssignment assignmentInfo;
170 170
171 + log.debug("Assign IP Called w/ Ip4Address: {}, HostId: {}", ipAddr.toString(), hostId.mac().toString());
172 +
171 if (allocationMap.containsKey(hostId)) { 173 if (allocationMap.containsKey(hostId)) {
174 +
172 assignmentInfo = allocationMap.get(hostId).value(); 175 assignmentInfo = allocationMap.get(hostId).value();
173 IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus(); 176 IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
174 177
...@@ -212,17 +215,17 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -212,17 +215,17 @@ public class DistributedDhcpStore implements DhcpStore {
212 allocationMap.put(hostId, assignmentInfo); 215 allocationMap.put(hostId, assignmentInfo);
213 return true; 216 return true;
214 } 217 }
215 - } else if (fromOpenStack) { 218 + } else if (rangeNotEnforced) {
216 assignmentInfo = IpAssignment.builder() 219 assignmentInfo = IpAssignment.builder()
217 .ipAddress(ipAddr) 220 .ipAddress(ipAddr)
218 .timestamp(new Date()) 221 .timestamp(new Date())
219 .leasePeriod(leaseTime) 222 .leasePeriod(leaseTime)
220 - .fromOpenStack(true) 223 + .rangeNotEnforced(true)
221 - .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack) 224 + .assignmentStatus(IpAssignment.AssignmentStatus.Option_RangeNotEnforced)
222 .subnetMask((Ip4Address) addressList.toArray()[0]) 225 .subnetMask((Ip4Address) addressList.toArray()[0])
223 .dhcpServer((Ip4Address) addressList.toArray()[1]) 226 .dhcpServer((Ip4Address) addressList.toArray()[1])
224 - .domainServer((Ip4Address) addressList.toArray()[2]) 227 + .routerAddress((Ip4Address) addressList.toArray()[2])
225 - .routerAddress((Ip4Address) addressList.toArray()[3]) 228 + .domainServer((Ip4Address) addressList.toArray()[3])
226 .build(); 229 .build();
227 allocationMap.put(hostId, assignmentInfo); 230 allocationMap.put(hostId, assignmentInfo);
228 return true; 231 return true;
...@@ -259,7 +262,7 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -259,7 +262,7 @@ public class DistributedDhcpStore implements DhcpStore {
259 for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) { 262 for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
260 assignment = entry.getValue().value(); 263 assignment = entry.getValue().value();
261 if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned 264 if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned
262 - || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack) { 265 + || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_RangeNotEnforced) {
263 validMapping.put(entry.getKey(), assignment); 266 validMapping.put(entry.getKey(), assignment);
264 } 267 }
265 } 268 }
...@@ -276,10 +279,10 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -276,10 +279,10 @@ public class DistributedDhcpStore implements DhcpStore {
276 } 279 }
277 280
278 @Override 281 @Override
279 - public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack, 282 + public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced,
280 List<Ip4Address> addressList) { 283 List<Ip4Address> addressList) {
281 HostId host = HostId.hostId(macID); 284 HostId host = HostId.hostId(macID);
282 - return assignIP(host, ipAddr, -1, fromOpenStack, addressList); 285 + return assignIP(host, ipAddr, -1, rangeNotEnforced, addressList);
283 } 286 }
284 287
285 @Override 288 @Override
...@@ -287,6 +290,12 @@ public class DistributedDhcpStore implements DhcpStore { ...@@ -287,6 +290,12 @@ public class DistributedDhcpStore implements DhcpStore {
287 HostId host = HostId.hostId(macID); 290 HostId host = HostId.hostId(macID);
288 if (allocationMap.containsKey(host)) { 291 if (allocationMap.containsKey(host)) {
289 IpAssignment assignment = allocationMap.get(host).value(); 292 IpAssignment assignment = allocationMap.get(host).value();
293 +
294 + if (assignment.rangeNotEnforced()) {
295 + allocationMap.remove(host);
296 + return true;
297 + }
298 +
290 Ip4Address freeIP = assignment.ipAddress(); 299 Ip4Address freeIP = assignment.ipAddress();
291 if (assignment.leasePeriod() < 0) { 300 if (assignment.leasePeriod() < 0) {
292 allocationMap.remove(host); 301 allocationMap.remove(host);
......