Search in sources :

Example 31 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class DistributedDhcpStore method removeStaticIP.

@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;
}
Also used : IpAssignment(org.onosproject.dhcp.IpAssignment) Ip4Address(org.onlab.packet.Ip4Address) HostId(org.onosproject.net.HostId)

Example 32 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class DistributedDhcpStore method assignIP.

@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) {
        // 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);
    }
}
Also used : IpAssignment(org.onosproject.dhcp.IpAssignment) Ip4Address(org.onlab.packet.Ip4Address) Date(java.util.Date)

Example 33 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class DhcpWebResource method listAvailableIPs.

/**
 * Get all available IPs.
 * Shows all the IPs in the free pool of the DHCP Server.
 *
 * @onos.rsModel DhcpConfigGetAvailable
 * @return 200 OK
 */
@GET
@Path("available")
public Response listAvailableIPs() {
    Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
    ObjectNode root = mapper().createObjectNode();
    ArrayNode arrayNode = root.putArray("availableIP");
    availableIPList.forEach(i -> arrayNode.add(i.toString()));
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Ip4Address(org.onlab.packet.Ip4Address) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 34 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class DhcpSetStaticMapping method doExecute.

@Override
protected void doExecute() {
    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());
    }
}
Also used : IpAssignment(org.onosproject.dhcp.IpAssignment) DhcpService(org.onosproject.dhcp.DhcpService) Ip4Address(org.onlab.packet.Ip4Address) MacAddress(org.onlab.packet.MacAddress) Date(java.util.Date)

Example 35 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class FreeIpCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    DhcpService dhcpService = AbstractShellCommand.get(DhcpService.class);
    Iterator<Ip4Address> it = dhcpService.getAvailableIPs().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        strings.add(it.next().toString());
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) DhcpService(org.onosproject.dhcp.DhcpService) Ip4Address(org.onlab.packet.Ip4Address)

Aggregations

Ip4Address (org.onlab.packet.Ip4Address)98 Test (org.junit.Test)29 Ip4Prefix (org.onlab.packet.Ip4Prefix)20 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)15 MacAddress (org.onlab.packet.MacAddress)15 ArrayList (java.util.ArrayList)14 Ip6Address (org.onlab.packet.Ip6Address)14 IpAddress (org.onlab.packet.IpAddress)13 LinkedList (java.util.LinkedList)12 Ethernet (org.onlab.packet.Ethernet)12 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)12 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)12 AsPath (org.onosproject.bgpio.types.AsPath)12 BgpHeader (org.onosproject.bgpio.types.BgpHeader)12 BgpValueType (org.onosproject.bgpio.types.BgpValueType)12 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)12 Med (org.onosproject.bgpio.types.Med)12 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)12 Origin (org.onosproject.bgpio.types.Origin)12 OriginType (org.onosproject.bgpio.types.Origin.OriginType)12