Search in sources :

Example 86 with IpAddress

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

the class VbngConfigurationManager method recycleAssignedPublicIpAddress.

@Override
public synchronized IpAddress recycleAssignedPublicIpAddress(IpAddress privateIpAddress) {
    IpAddress publicIpAddress = ipAddressMap.remove(privateIpAddress);
    if (publicIpAddress == null) {
        return null;
    }
    Iterator<Entry<IpPrefix, Boolean>> prefixes = localPublicIpPrefixes.entrySet().iterator();
    while (prefixes.hasNext()) {
        Entry<IpPrefix, Boolean> prefixEntry = prefixes.next();
        if (prefixEntry.getKey().contains(publicIpAddress) && !prefixEntry.getValue()) {
            updateIpPrefixStatus(prefixEntry.getKey(), true);
        }
    }
    log.info("[DELETE] Private IP to Public IP mapping: {} --> {}", privateIpAddress, publicIpAddress);
    return publicIpAddress;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Entry(java.util.Map.Entry) IpAddress(org.onlab.packet.IpAddress)

Example 87 with IpAddress

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

the class VbngConfigurationManager method assignSpecifiedPublicIp.

@Override
public synchronized boolean assignSpecifiedPublicIp(IpAddress publicIpAddress, IpAddress privateIpAddress) {
    // Judge whether this public IP address is in our public IP
    // prefix/address list.
    boolean isPublicIpExist = false;
    for (Entry<IpPrefix, Boolean> prefix : localPublicIpPrefixes.entrySet()) {
        if (prefix.getKey().contains(publicIpAddress)) {
            isPublicIpExist = true;
            // Judge whether this public IP address is already assigned
            if (!prefix.getValue() || isAssignedPublicIpAddress(publicIpAddress)) {
                log.info("The public IP address {} is already assigned, " + "and not available.", publicIpAddress);
                return false;
            }
            // The public IP address is still available
            // Store the mapping from private IP address to public IP address
            ipAddressMap.put(privateIpAddress, publicIpAddress);
            // Update the prefix status
            if (prefix.getKey().prefixLength() == 32) {
                updateIpPrefixStatus(prefix.getKey(), false);
                return true;
            }
            // Judge whether the prefix of this public IP address is used
            // up, if so, update the IP prefix status.
            double prefixLen = prefix.getKey().prefixLength();
            int availableIpNum = (int) Math.pow(2, IpPrefix.MAX_INET_MASK_LENGTH - prefixLen) - 1;
            int usedIpNum = 0;
            for (Entry<IpAddress, IpAddress> ipAddressMapEntry : ipAddressMap.entrySet()) {
                if (prefix.getKey().contains(ipAddressMapEntry.getValue())) {
                    usedIpNum = usedIpNum + 1;
                }
            }
            if (usedIpNum == availableIpNum) {
                updateIpPrefixStatus(prefix.getKey(), false);
            }
            return true;
        }
    }
    log.info("The public IP address {} retrieved from XOS mapping does " + "not exist", publicIpAddress);
    return false;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 88 with IpAddress

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

the class VbngManager method createVbngAgain.

/**
 * Tries to create vBNG again after receiving a host event if the IP
 * address of the host is the next hop IP address.
 *
 * @param privateIpAddress the private IP address
 */
private void createVbngAgain(IpAddress privateIpAddress) {
    IpAddress publicIpAddress = vbngConfigurationService.getAssignedPublicIpAddress(privateIpAddress);
    if (publicIpAddress == null) {
        // We only need to handle the private IP addresses for which we
        // already returned the REST replies with assigned public IP
        // addresses. If a private IP addresses does not have an assigned
        // public IP address, we should not get it an available public IP
        // address here, and we should delete it in the unhandled private
        // IP address map.
        privateIpAddressMap.remove(privateIpAddress);
        return;
    }
    VcpeHost vcpeHost = privateIpAddressMap.get(privateIpAddress);
    if (setupForwardingPaths(privateIpAddress, publicIpAddress, vcpeHost.macAddress, vcpeHost.hostName)) {
        privateIpAddressMap.remove(privateIpAddress);
    }
}
Also used : IpAddress(org.onlab.packet.IpAddress)

Example 89 with IpAddress

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

the class VbngManager method createVbng.

@Override
public IpAddress createVbng(IpAddress privateIpAddress, MacAddress hostMacAddress, String hostName) {
    IpAddress publicIpAddress = vbngConfigurationService.getAvailablePublicIpAddress(privateIpAddress);
    if (publicIpAddress == null) {
        log.info("Did not find an available public IP address to use.");
        return null;
    }
    log.info("[ADD] Private IP to Public IP mapping: {} --> {}", privateIpAddress, publicIpAddress);
    // next hop
    if (!setupForwardingPaths(privateIpAddress, publicIpAddress, hostMacAddress, hostName)) {
        privateIpAddressMap.put(privateIpAddress, new VcpeHost(hostMacAddress, hostName));
    }
    return publicIpAddress;
}
Also used : IpAddress(org.onlab.packet.IpAddress)

Example 90 with IpAddress

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

the class VbngManager method statusRecovery.

/**
 * Recovers from XOS record. Re-sets up the mapping between private IP
 * address and public IP address, re-calculates intents and re-installs
 * those intents.
 */
private void statusRecovery() {
    log.info("vBNG starts to recover from XOS record......");
    ObjectNode map;
    try {
        RestClient restClient = new RestClient(vbngConfigurationService.getXosIpAddress(), vbngConfigurationService.getXosRestPort());
        map = restClient.getRest();
    } catch (Exception e) {
        log.warn("Could not contact XOS {}", e.getMessage());
        return;
    }
    if (map == null) {
        log.info("Stop to recover vBNG status due to the vBNG map " + "is null!");
        return;
    }
    log.info("Get record from XOS: {}", map);
    ArrayNode array = (ArrayNode) map.get(VBNG_MAP_NAME);
    Iterator<JsonNode> entries = array.elements();
    while (entries.hasNext()) {
        ObjectNode entry = (ObjectNode) entries.next();
        IpAddress hostIpAdddress = IpAddress.valueOf(entry.get("private_ip").asText());
        IpAddress publicIpAddress = IpAddress.valueOf(entry.get("routeable_subnet").asText());
        MacAddress macAddress = MacAddress.valueOf(entry.get("mac").asText());
        String hostName = entry.get("hostname").asText();
        // Create vBNG
        createVbng(hostIpAdddress, publicIpAddress, macAddress, hostName);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MacAddress(org.onlab.packet.MacAddress)

Aggregations

IpAddress (org.onlab.packet.IpAddress)288 MacAddress (org.onlab.packet.MacAddress)63 VlanId (org.onlab.packet.VlanId)52 ConnectPoint (org.onosproject.net.ConnectPoint)48 Set (java.util.Set)46 DeviceId (org.onosproject.net.DeviceId)44 Logger (org.slf4j.Logger)40 Test (org.junit.Test)37 Collectors (java.util.stream.Collectors)36 Ethernet (org.onlab.packet.Ethernet)36 IpPrefix (org.onlab.packet.IpPrefix)36 HostId (org.onosproject.net.HostId)33 Host (org.onosproject.net.Host)32 Optional (java.util.Optional)30 HostLocation (org.onosproject.net.HostLocation)30 LoggerFactory (org.slf4j.LoggerFactory)30 ApplicationId (org.onosproject.core.ApplicationId)29 CoreService (org.onosproject.core.CoreService)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28