本文整理汇总了Java中org.onosproject.dhcp.IpAssignment.ipAddress方法的典型用法代码示例。如果您正苦于以下问题:Java IpAssignment.ipAddress方法的具体用法?Java IpAssignment.ipAddress怎么用?Java IpAssignment.ipAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.dhcp.IpAssignment
的用法示例。
在下文中一共展示了IpAssignment.ipAddress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeStaticIP
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public boolean removeStaticIP(MacAddress macID) {
HostId host = HostId.hostId(macID);
if (allocationMap.containsKey(host)) {
IpAssignment assignment = allocationMap.get(host).value();
if (assignment.assignmentStatus().equals(Option_RangeNotEnforced)) {
allocationMap.remove(host);
return true;
}
Ip4Address freeIP = assignment.ipAddress();
if (assignment.leasePeriod() < 0) {
allocationMap.remove(host);
if (ipWithinRange(freeIP)) {
freeIPPool.add(freeIP);
}
return true;
}
}
return false;
}
示例2: releaseIP
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public Ip4Address releaseIP(HostId hostId) {
if (allocationMap.containsKey(hostId)) {
// If the IP has been assigned with Option_RangeNotEnforced,
// we do not release the IP address nor remove the host from HostService.
// Therefore, if the IP is assigned statically, the IP needs to be released statically.
Versioned<IpAssignment> assignmentVersioned = allocationMap.get(hostId);
if (Versioned.valueOrNull(assignmentVersioned) != null &&
assignmentVersioned.value().assignmentStatus().equals(Option_RangeNotEnforced)) {
return null;
}
IpAssignment newAssignment = IpAssignment.builder(allocationMap.get(hostId).value())
.assignmentStatus(IpAssignment.AssignmentStatus.Option_Expired)
.build();
Ip4Address freeIP = newAssignment.ipAddress();
allocationMap.put(hostId, newAssignment);
if (ipWithinRange(freeIP)) {
freeIPPool.add(freeIP);
}
return freeIP;
}
return null;
}
示例3: releaseIP
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public Ip4Address releaseIP(HostId hostId) {
if (allocationMap.containsKey(hostId)) {
IpAssignment newAssignment = IpAssignment.builder(allocationMap.get(hostId).value())
.assignmentStatus(IpAssignment.AssignmentStatus.Option_Expired)
.build();
Ip4Address freeIP = newAssignment.ipAddress();
allocationMap.put(hostId, newAssignment);
if (ipWithinRange(freeIP)) {
freeIPPool.add(freeIP);
}
return freeIP;
}
return null;
}
示例4: suggestIP
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP) {
IpAssignment assignmentInfo;
if (allocationMap.containsKey(hostId)) {
assignmentInfo = allocationMap.get(hostId).value();
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
Ip4Address ipAddr = assignmentInfo.ipAddress();
if (assignmentInfo.assignmentStatus().equals(Option_RangeNotEnforced)) {
return assignmentInfo.ipAddress();
} else if (status == Option_Assigned ||
status == IpAssignment.AssignmentStatus.Option_Requested) {
// Client has a currently Active Binding.
if (ipWithinRange(ipAddr)) {
return ipAddr;
}
} else if (status == IpAssignment.AssignmentStatus.Option_Expired) {
// Client has a Released or Expired Binding.
if (freeIPPool.contains(ipAddr)) {
assignmentInfo = IpAssignment.builder()
.ipAddress(ipAddr)
.timestamp(new Date())
.leasePeriod(timeoutForPendingAssignments)
.assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested)
.build();
if (freeIPPool.remove(ipAddr)) {
allocationMap.put(hostId, assignmentInfo);
return ipAddr;
}
}
}
} else if (requestedIP.toInt() != 0) {
// Client has requested an IP.
if (freeIPPool.contains(requestedIP)) {
assignmentInfo = IpAssignment.builder()
.ipAddress(requestedIP)
.timestamp(new Date())
.leasePeriod(timeoutForPendingAssignments)
.assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested)
.build();
if (freeIPPool.remove(requestedIP)) {
allocationMap.put(hostId, assignmentInfo);
return requestedIP;
}
}
}
// Allocate a new IP from the server's pool of available IP.
Ip4Address nextIPAddr = fetchNextIP();
if (nextIPAddr != null) {
assignmentInfo = IpAssignment.builder()
.ipAddress(nextIPAddr)
.timestamp(new Date())
.leasePeriod(timeoutForPendingAssignments)
.assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested)
.build();
allocationMap.put(hostId, assignmentInfo);
}
return nextIPAddr;
}
示例5: assignIP
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public boolean assignIP(HostId hostId, IpAssignment ipAssignment) {
log.trace("Assign IP Called HostId: {}, ipAssignment: {}",
hostId, ipAssignment);
IpAssignment newAssignment = null;
Versioned<IpAssignment> versionedAssignment = allocationMap.get(hostId);
Ip4Address requestedIp = ipAssignment.ipAddress();
if (versionedAssignment == null) {
// this is new IP assignment of static mapping
// dynamic assignment is done in suggestIP
if (ipAssignment.assignmentStatus().equals(Option_RangeNotEnforced)) {
newAssignment = ipAssignment;
} else if (freeIPPool.remove(requestedIp)) {
newAssignment = IpAssignment.builder(ipAssignment)
.assignmentStatus(Option_Assigned)
.timestamp(new Date())
.build();
} else {
log.trace("Failed to assign IP for {}", ipAssignment);
return false;
}
log.trace("Assigned {}", newAssignment);
return allocationMap.putIfAbsent(hostId, newAssignment) == null;
// TODO: handle the case where map changed.
} else {
// this is lease renew or rebinding
// update assignment status and time stamp, and keep the others
IpAssignment existingAssignment = versionedAssignment.value();
if (!existingAssignment.ipAddress().equals(requestedIp)) {
// return false if existing assignment is not for the
// requested host
log.trace("Failed to assign IP for {}", ipAssignment);
return false;
}
switch (existingAssignment.assignmentStatus()) {
case Option_RangeNotEnforced:
newAssignment = IpAssignment.builder(existingAssignment)
.timestamp(new Date())
.build();
break;
case Option_Expired:
if (!freeIPPool.remove(requestedIp)) {
// requested IP is expired for this host and reserved to the other host
return false;
}
case Option_Assigned:
case Option_Requested:
newAssignment = IpAssignment.builder(existingAssignment)
.timestamp(new Date())
.assignmentStatus(Option_Assigned)
.build();
break;
default:
break;
}
log.trace("Assigned {}", newAssignment);
return allocationMap.replace(hostId, versionedAssignment.version(), newAssignment);
}
}