Search in sources :

Example 1 with VtepIpPoolBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder 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);
    }
}
Also used : VtepIpPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder) VtepIpPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool)

Example 2 with VtepIpPoolBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder 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());
    }
}
Also used : VtepIpPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder)

Example 3 with VtepIpPoolBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder in project genius by opendaylight.

the class VtepConfigSchemaListener method processAvailableIps.

/**
 * Calculate available IPs from the subnet mask specified in the schema.
 * Pushes the available and allocated IP address to config DS.
 *
 * @param schema
 *            the schema
 */
private VtepIpPool processAvailableIps(final VtepConfigSchema schema) {
    String subnetCidr = ItmUtils.getSubnetCidrAsString(schema.getSubnet());
    SubnetUtils subnetUtils = new SubnetUtils(subnetCidr);
    List<IpAddress> availableIps = calculateAvailableIps(subnetUtils, schema.getExcludeIpFilter(), schema.getGatewayIp());
    VtepIpPool vtepIpPool = new VtepIpPoolBuilder().setSubnetCidr(subnetCidr).setAvailableIpaddress(availableIps).setAllocatedIpaddress(new ArrayList<>()).build();
    MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepIpPoolIdentifier(subnetCidr), vtepIpPool);
    LOG.info("Vtep IP Pool with key:{} added to config DS", subnetCidr);
    return vtepIpPool;
}
Also used : VtepIpPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder) SubnetUtils(org.apache.commons.net.util.SubnetUtils) ArrayList(java.util.ArrayList) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) VtepIpPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool)

Aggregations

VtepIpPoolBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPoolBuilder)3 VtepIpPool (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.ip.pools.VtepIpPool)2 ArrayList (java.util.ArrayList)1 SubnetUtils (org.apache.commons.net.util.SubnetUtils)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1