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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations