use of org.opendaylight.genius.itm.cli.TepException 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.genius.itm.cli.TepException 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);
}
Aggregations