use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema 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.config.schemas.VtepConfigSchema 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.config.schemas.VtepConfigSchema in project genius by opendaylight.
the class VtepConfigSchemaListener method update.
@Override
public void update(@Nonnull VtepConfigSchema original, @Nonnull VtepConfigSchema updated) {
LOG.error("Received DCN for updating VTEP Original schema: {}. Updated schema: {}", original, updated);
VtepConfigSchema originalSchema = ItmUtils.validateVtepConfigSchema(original);
VtepConfigSchema updatedSchema = ItmUtils.validateVtepConfigSchema(updated);
if (doesDeleteAndAddSchemaRequired(original, updated)) {
LOG.error("Failed to handle DCN for updating VTEP schema. Original schema: {}. Updated schema: {}", original, updated);
// TODO: handle updates
return;
}
handleUpdateOfDpnIds(originalSchema, updatedSchema);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema in project genius by opendaylight.
the class VtepConfigSchemaListener method deleteVteps.
/**
* Delete vteps.
*
* @param schema
* the schema
* @param lstDpnIdsToBeDeleted
* the dpn ids list to be deleted
*/
private void deleteVteps(VtepConfigSchema schema, List<BigInteger> lstDpnIdsToBeDeleted) {
TepCommandHelper tepCommandHelper = new TepCommandHelper(this.dataBroker, itmConfig);
List<IpAddress> freeIps = new ArrayList<>();
String subnetCidr = ItmUtils.getSubnetCidrAsString(schema.getSubnet());
String gatewayIp = handleGatewayIp(schema.getGatewayIp());
for (BigInteger dpnId : lstDpnIdsToBeDeleted) {
VtepsKey vtepkey = new VtepsKey(dpnId, schema.getPortName());
InstanceIdentifier<Vteps> vpath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(schema.getTransportZoneName())).child(Subnets.class, new SubnetsKey(schema.getSubnet())).child(Vteps.class, vtepkey).build();
Vteps vtep;
Optional<Vteps> vtepOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, vpath, dataBroker);
if (vtepOptional.isPresent()) {
vtep = vtepOptional.get();
} else {
LOG.warn("VTEP doesn't exist for DPN [{}] and port [{}].", dpnId, schema.getPortName());
continue;
}
IpAddress ipAddress = vtep.getIpAddress();
try {
tepCommandHelper.deleteVtep(dpnId, vtep.getPortname(), schema.getVlanId(), String.valueOf(ipAddress.getValue()), subnetCidr, gatewayIp, schema.getTransportZoneName(), null);
} catch (TepException e) {
LOG.error("delete Vtep Failed", e);
}
freeIps.add(ipAddress);
}
LOG.debug("Delete OnCommit in NewlyAddedDpns");
tepCommandHelper.deleteOnCommit();
deAllocateIpAddresses(freeIps, subnetCidr);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema in project genius by opendaylight.
the class ItmProvider method updateVtepSchema.
@Override
public void updateVtepSchema(String schemaName, List<BigInteger> lstDpnsForAdd, List<BigInteger> lstDpnsForDelete) {
LOG.trace("Updating VTEP schema {} by adding DPN's {} and deleting DPN's {}.", schemaName, lstDpnsForAdd, lstDpnsForDelete);
VtepConfigSchema schema = ItmUtils.validateForUpdateVtepSchema(schemaName, lstDpnsForAdd, lstDpnsForDelete, this);
VtepConfigSchemaBuilder builder = new VtepConfigSchemaBuilder(schema);
/* if (ItmUtils.getDpnIdList(schema.getDpnIds()).isEmpty()) {
builder.setDpnIds(schema.getDpnIds());
} else {*/
if (lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty()) {
List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds());
originalDpnList.addAll(lstDpnsForAdd);
builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
}
if (lstDpnsForDelete != null && !lstDpnsForDelete.isEmpty()) {
List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds());
originalDpnList.removeAll(lstDpnsForDelete);
builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
// schema.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(ItmUtils.getDpnIdList(schema.getDpnIds())
// .removeAll(lstDpnsForAdd)));
}
// }
schema = builder.build();
MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION, ItmUtils.getVtepConfigSchemaIdentifier(schemaName), schema);
LOG.debug("Vtep config schema {} updated to config DS with DPN's {}", schemaName, ItmUtils.getDpnIdList(schema.getDpnIds()));
}
Aggregations