当前位置: 首页>>代码示例>>Java>>正文


Java IpAssignment.ipAddress方法代码示例

本文整理汇总了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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:DistributedDhcpStore.java

示例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;
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:25,代码来源:DistributedDhcpStore.java

示例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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:DistributedDhcpStore.java

示例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;

}
 
开发者ID:shlee89,项目名称:athena,代码行数:65,代码来源:DistributedDhcpStore.java

示例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);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:63,代码来源:DistributedDhcpStore.java


注:本文中的org.onosproject.dhcp.IpAssignment.ipAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。