本文整理汇总了Java中org.onosproject.dhcp.IpAssignment.assignmentStatus方法的典型用法代码示例。如果您正苦于以下问题:Java IpAssignment.assignmentStatus方法的具体用法?Java IpAssignment.assignmentStatus怎么用?Java IpAssignment.assignmentStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.dhcp.IpAssignment
的用法示例。
在下文中一共展示了IpAssignment.assignmentStatus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public void run(Timeout to) {
IpAssignment ipAssignment;
Date dateNow = new Date();
Map<HostId, IpAssignment> ipAssignmentMap = dhcpStore.listAllMapping();
for (Map.Entry<HostId, IpAssignment> entry: ipAssignmentMap.entrySet()) {
ipAssignment = entry.getValue();
long timeLapsed = dateNow.getTime() - ipAssignment.timestamp().getTime();
if ((ipAssignment.assignmentStatus() != IpAssignment.AssignmentStatus.Option_Expired) &&
(ipAssignment.leasePeriod() > 0) && (timeLapsed > (ipAssignment.leasePeriodMs()))) {
Ip4Address ip4Address = dhcpStore.releaseIP(entry.getKey());
if (ip4Address != null) {
hostProviderService.removeIpFromHost(entry.getKey(), ipAssignment.ipAddress());
}
}
}
timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES);
}
示例2: run
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public void run() {
IpAssignment ipAssignment;
Date dateNow = new Date();
Map<HostId, IpAssignment> ipAssignmentMap = dhcpStore.listAllMapping();
for (Map.Entry<HostId, IpAssignment> entry: ipAssignmentMap.entrySet()) {
ipAssignment = entry.getValue();
long timeLapsed = dateNow.getTime() - ipAssignment.timestamp().getTime();
if ((ipAssignment.assignmentStatus() != IpAssignment.AssignmentStatus.Option_Expired) &&
(ipAssignment.leasePeriod() > 0) && (timeLapsed > (ipAssignment.leasePeriodMs()))) {
Ip4Address ip4Address = dhcpStore.releaseIP(entry.getKey());
if (ip4Address != null) {
hostProviderService.removeIpFromHost(entry.getKey(), ipAssignment.ipAddress());
}
}
}
timeout = SharedScheduledExecutors.newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES);
}
示例3: listAssignedMapping
import org.onosproject.dhcp.IpAssignment; //导入方法依赖的package包/类
@Override
public Map<HostId, IpAssignment> listAssignedMapping() {
Map<HostId, IpAssignment> validMapping = new HashMap<>();
IpAssignment assignment;
for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
assignment = entry.getValue().value();
if (assignment.assignmentStatus() == Option_Assigned
|| assignment.assignmentStatus() == Option_RangeNotEnforced) {
validMapping.put(entry.getKey(), assignment);
}
}
return validMapping;
}
示例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);
}
}