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


Java IpAssignment类代码示例

本文整理汇总了Java中org.onosproject.dhcp.IpAssignment的典型用法代码示例。如果您正苦于以下问题:Java IpAssignment类的具体用法?Java IpAssignment怎么用?Java IpAssignment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IpAssignment类属于org.onosproject.dhcp包,在下文中一共展示了IpAssignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteMapping

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
/**
 * Delete a static MAC/IP binding.
 * Removes a static binding from the DHCP Server, and displays the current set of bindings.
 *
 * @param macID mac address identifier
 * @return 200 OK
 */
@DELETE
@Path("mappings/{macID}")
public Response deleteMapping(@PathParam("macID") String macID) {
    ObjectNode root = mapper().createObjectNode();

    if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
        throw new IllegalArgumentException("Static Mapping Removal Failed.");
    }
    final Map<HostId, IpAssignment> intents = service.listMapping();
    ArrayNode arrayNode = root.putArray("mappings");
    intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
                                                          .put("host", i.getKey().toString())
                                                          .put("ip", i.getValue().ipAddress().toString())));

    return ok(root).build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:DhcpWebResource.java

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

示例3: activate

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
@Activate
protected void activate() {
    allocationMap = storageService.<HostId, IpAssignment>consistentMapBuilder()
            .withName("onos-dhcp-assignedIP")
            .withSerializer(Serializer.using(
                    new KryoNamespace.Builder()
                            .register(KryoNamespaces.API)
                            .register(IpAssignment.class,
                                    IpAssignment.AssignmentStatus.class,
                                    Date.class,
                                    long.class,
                                    Ip4Address.class)
                            .build()))
            .build();

    freeIPPool = storageService.<Ip4Address>setBuilder()
            .withName("onos-dhcp-freeIP")
            .withSerializer(Serializer.using(KryoNamespaces.API))
            .build()
            .asDistributedSet();

    log.info("Started");
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:DistributedDhcpStore.java

示例4: 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

示例5: execute

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
@Override
protected void execute() {
    DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class);

    try {
        MacAddress macID = MacAddress.valueOf(macAddr);
        Ip4Address ipAddress = Ip4Address.valueOf(ipAddr);

        IpAssignment ipAssignment = IpAssignment.builder()
                .ipAddress(ipAddress)
                .leasePeriod(dhcpService.getLeaseTime())
                .timestamp(new Date())
                .assignmentStatus(Option_Requested)
                .build();

        if (dhcpService.setStaticMapping(macID, ipAssignment)) {
            print(DHCP_SUCCESS);
        } else {
            print(DHCP_FAILURE);
        }

    } catch (IllegalArgumentException e) {
        print(e.getMessage());
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:DhcpSetStaticMapping.java

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

示例7: activate

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
@Activate
protected void activate() {
    allocationMap = storageService.<HostId, IpAssignment>consistentMapBuilder()
            .withName("onos-dhcp-assignedIP")
            .withSerializer(Serializer.using(
                    new KryoNamespace.Builder()
                            .register(KryoNamespaces.API)
                            .register(IpAssignment.class,
                                    IpAssignment.AssignmentStatus.class,
                                    Date.class)
                            .build("dhcp")))
            .build();

    freeIPPool = storageService.<Ip4Address>setBuilder()
            .withName("onos-dhcp-freeIP")
            .withSerializer(Serializer.using(KryoNamespaces.API))
            .build()
            .asDistributedSet();

    log.info("Started");
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:22,代码来源:DistributedDhcpStore.java

示例8: 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

示例9: listMappings

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
/**
 * Get all MAC/IP mappings.
 * Shows all MAC/IP mappings held by the DHCP server.
 *
 * @onos.rsModel DhcpConfigGetMappings
 * @return 200 OK
 */
@GET
@Path("mappings")
public Response listMappings() {
    ObjectNode root = mapper().createObjectNode();

    Map<HostId, IpAssignment> intents = service.listMapping();
    ArrayNode arrayNode = root.putArray("mappings");
    intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
                                                          .put("host", i.getKey().toString())
                                                          .put("ip", i.getValue().ipAddress().toString())));

    return ok(root).build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:DhcpWebResource.java

示例10: setMapping

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
/**
 * Post a new static MAC/IP binding.
 * Registers a static binding to the DHCP server, and displays the current set of bindings.
 *
 * @onos.rsModel DhcpConfigPut
 * @param stream JSON stream
 * @return 200 OK
 */
@POST
@Path("mappings")
@Consumes(MediaType.APPLICATION_JSON)
public Response setMapping(InputStream stream) {
    ObjectNode root = mapper().createObjectNode();
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        JsonNode macID = jsonTree.get("mac");
        JsonNode ip = jsonTree.get("ip");
        if (macID != null && ip != null) {
            IpAssignment ipAssignment = IpAssignment.builder()
                    .ipAddress(Ip4Address.valueOf(ip.asText()))
                    .leasePeriod(service.getLeaseTime())
                    .timestamp(new Date())
                    .assignmentStatus(Option_Requested)
                    .build();

            if (!service.setStaticMapping(MacAddress.valueOf(macID.asText()),
                                          ipAssignment)) {
                throw new IllegalArgumentException("Static Mapping Failed. " +
                                                           "The IP maybe unavailable.");
            }
        }

        final Map<HostId, IpAssignment> intents = service.listMapping();
        ArrayNode arrayNode = root.putArray("mappings");
        intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
                                                              .put("host", i.getKey().toString())
                                                              .put("ip", i.getValue().ipAddress().toString())));
    } catch (IOException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
    return ok(root).build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:43,代码来源:DhcpWebResource.java

示例11: 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

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

示例13: listAllMapping

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
@Override
public Map<HostId, IpAssignment> listAllMapping() {
    Map<HostId, IpAssignment> validMapping = new HashMap<>();
    for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
        validMapping.put(entry.getKey(), entry.getValue().value());
    }
    return validMapping;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:9,代码来源:DistributedDhcpStore.java

示例14: getIpAssignmentFromAllocationMap

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
@Override
public IpAssignment getIpAssignmentFromAllocationMap(HostId hostId) {
    if (allocationMap.get(hostId) != null) {
        return allocationMap.get(hostId).value();
    } else {
        return null;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:9,代码来源:DistributedDhcpStore.java

示例15: populateTable

import org.onosproject.dhcp.IpAssignment; //导入依赖的package包/类
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
    DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class);
    Map<HostId, IpAssignment> allocationMap = dhcpService.listMapping();

    for (Map.Entry<HostId, IpAssignment> entry : allocationMap.entrySet()) {
        populateRow(tm.addRow(), entry);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:10,代码来源:DhcpViewMessageHandler.java


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