use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool in project genius by opendaylight.
the class VtepConfigSchemaListener method deAllocateIpAddresses.
/**
* De-allocate ip addresses.
*
* @param freeIps
* the free ips
* @param subnetCidr
* the subnet cidr
*/
private void deAllocateIpAddresses(List<IpAddress> freeIps, String subnetCidr) {
VtepIpPool vtepIpPool = getVtepIpPool(subnetCidr);
if (freeIps != null && !freeIps.isEmpty() && vtepIpPool != null) {
// Remove from the allocated IP address list and add to available IP
// address list.
VtepIpPoolBuilder builder = new VtepIpPoolBuilder(vtepIpPool);
if (builder.getAllocatedIpaddress() != null) {
builder.getAllocatedIpaddress().removeAll(freeIps);
}
if (builder.getAvailableIpaddress() == null) {
builder.setAvailableIpaddress(freeIps);
} else {
builder.getAvailableIpaddress().addAll(freeIps);
}
MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepIpPoolIdentifier(subnetCidr), builder.build());
LOG.debug("Vtep IP Pool with key:{} updated to config DS", subnetCidr);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool in project genius by opendaylight.
the class VtepConfigSchemaListener method allocateIpAddresses.
/**
* Allocate ip addresses.
*
* @param allocatedIps
* the allocated ips
* @param vtepIpPool
* the vtep ip pool
* @param subnetCidr
* the subnet cidr
*/
private void allocateIpAddresses(List<IpAddress> allocatedIps, VtepIpPool vtepIpPool, String subnetCidr) {
if (allocatedIps != null && !allocatedIps.isEmpty() && vtepIpPool != null) {
// Remove from the available IP address list and add to allocated IP
// address list.
VtepIpPoolBuilder builder = new VtepIpPoolBuilder(vtepIpPool);
if (builder.getAvailableIpaddress() != null) {
builder.getAvailableIpaddress().removeAll(allocatedIps);
}
if (builder.getAllocatedIpaddress() == null) {
builder.setAllocatedIpaddress(allocatedIps);
} else {
builder.getAllocatedIpaddress().addAll(allocatedIps);
}
MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepIpPoolIdentifier(subnetCidr), builder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool in project genius by opendaylight.
the class VtepConfigSchemaListener method handleNewlyAddedDpnsToSchema.
/**
* Handle newly added dpns to schema.
*
* @param original
* the original
* @param originalDpnIds
* the original dpn ids
* @param updatedDpnIds
* the updated dpn ids
*/
private void handleNewlyAddedDpnsToSchema(VtepConfigSchema original, List<DpnIds> originalDpnIds, List<DpnIds> updatedDpnIds) {
LOG.trace("Handle Addition of DPNs from VTEP Original Dpn: {}. Updated Dpn: {}", originalDpnIds, updatedDpnIds);
ArrayList<DpnIds> newlyAddedDpns = new ArrayList<>(updatedDpnIds);
newlyAddedDpns.removeAll(originalDpnIds);
LOG.debug("Newly added DPNs {} to VTEP config schema [{}].", newlyAddedDpns, original.getSchemaName());
if (!newlyAddedDpns.isEmpty()) {
VtepConfigSchema diffSchema = new VtepConfigSchemaBuilder(original).setDpnIds(newlyAddedDpns).build();
String subnetCidr = ItmUtils.getSubnetCidrAsString(original.getSubnet());
VtepIpPool vtepIpPool = getVtepIpPool(subnetCidr);
LOG.debug("Adding of DPNs in Diff Schema: {}", diffSchema);
addVteps(diffSchema, vtepIpPool);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool in project genius by opendaylight.
the class VtepConfigSchemaListener method addVteps.
/**
* Adds the vteps.
*
* @param schema
* the schema
* @param vtepIpPool
* the vtep ip pool
*/
private void addVteps(VtepConfigSchema schema, VtepIpPool vtepIpPool) {
if (schema.getDpnIds() == null || schema.getDpnIds().isEmpty()) {
LOG.debug("DPN list is empty, skipping addVteps for schema: {}", schema);
return;
}
String subnetCidr = ItmUtils.getSubnetCidrAsString(schema.getSubnet());
if (vtepIpPool == null) {
LOG.error("VTEP config pool not found for subnetCidr {}. Failed to add VTEPs for schema {}", subnetCidr, schema);
return;
}
TepCommandHelper tepCommandHelper = new TepCommandHelper(this.dataBroker, itmConfig);
// Check this later
String tunType;
Class<? extends TunnelTypeBase> tunnelType = schema.getTunnelType();
if (tunnelType.equals(TunnelTypeVxlan.class)) {
tunType = ITMConstants.TUNNEL_TYPE_VXLAN;
} else {
tunType = ITMConstants.TUNNEL_TYPE_GRE;
}
tepCommandHelper.configureTunnelType(schema.getTransportZoneName(), StringUtils.upperCase(tunType));
List<IpAddress> availableIps = vtepIpPool.getAvailableIpaddress();
List<IpAddress> newlyAllocatedIps = new ArrayList<>();
List<BigInteger> skippedDpnIds = new ArrayList<>();
String gatewayIp = handleGatewayIp(schema.getGatewayIp());
for (BigInteger dpnId : ItmUtils.getDpnIdList(schema.getDpnIds())) {
IpAddress ipAddress = getAnAvailableIP(availableIps);
if (ipAddress == null) {
skippedDpnIds.add(dpnId);
continue;
}
try {
tepCommandHelper.createLocalCache(dpnId, schema.getPortName(), schema.getVlanId(), String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName(), null);
} catch (TepException e) {
LOG.error("create local cache Failed", e);
}
newlyAllocatedIps.add(ipAddress);
}
if (!skippedDpnIds.isEmpty()) {
LOG.error("No available IP addresses in the VTEP config pool {}, skipping VTEP configurations for DPN's {}", subnetCidr, skippedDpnIds);
}
if (!newlyAllocatedIps.isEmpty()) {
LOG.debug("Delete OnCommit and buildTeps in NewlyAddedDpns");
tepCommandHelper.deleteOnCommit();
tepCommandHelper.buildTeps();
allocateIpAddresses(newlyAllocatedIps, vtepIpPool, subnetCidr);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool in project genius by opendaylight.
the class VtepConfigSchemaListener method add.
@Override
public void add(@Nonnull VtepConfigSchema vtepConfigSchema) {
// Construct the transport zones from the provided schemas and push it to config DS
LOG.trace("Add VtepConfigSchema: {}", vtepConfigSchema);
VtepConfigSchema validatedSchema = ItmUtils.validateForAddVtepConfigSchema(vtepConfigSchema, getAllVtepConfigSchemas());
VtepIpPool vtepIpPool = processAvailableIps(validatedSchema);
addVteps(validatedSchema, vtepIpPool);
}
Aggregations