use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Vteps in project netvirt by opendaylight.
the class TransportZoneNotificationUtil method addVtep.
/**
* Tries to add a vtep for a transport zone.
*
* @return Whether a vtep was added or not.
*/
private boolean addVtep(TransportZone zone, String subnetIp, BigInteger dpnId, @Nullable String localIp) {
List<Subnets> zoneSubnets = zone.getSubnets();
if (zoneSubnets == null) {
return false;
}
Subnets subnets = getOrAddSubnet(zoneSubnets, subnetIp);
for (Vteps existingVtep : subnets.getVteps()) {
if (existingVtep.getDpnId().equals(dpnId)) {
return false;
}
}
if (localIp != null) {
IpAddress nodeIp = new IpAddress(localIp.toCharArray());
VtepsBuilder vtepsBuilder = new VtepsBuilder().setDpnId(dpnId).setIpAddress(nodeIp).setPortname(TUNNEL_PORT).setOptionOfTunnel(elanConfig.isUseOfTunnels());
subnets.getVteps().add(vtepsBuilder.build());
return true;
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Vteps in project genius by opendaylight.
the class TepCommandHelperTest method testCreateLocalCacheWithoutcheckExistingSubnet.
@Test
public void testCreateLocalCacheWithoutcheckExistingSubnet() {
IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
IpPrefix subnetMaskObj = ipPrefixTest;
SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<>();
subVtepMapTemp.put(subObCli, vtepsList);
transportZoneNew = new TransportZoneBuilder().setZoneName(transportZone1).setTunnelType(tunnelType2).build();
doReturn(Futures.immediateCheckedFuture(Optional.of(transportZoneNew))).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION, transportZoneIdentifier);
doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION, transportZonesIdentifier);
try {
tepCommandHelper.createLocalCache(dpId1, portName1, vlanId, tepIp1, subnetMask, gwyIp1, transportZone1, null);
tepCommandHelper.createLocalCache(dpId2, portName1, vlanId, tepIp1, subnetMask, gwyIp1, transportZone1, null);
} catch (TepException e) {
LOG.error(e.getMessage());
}
verify(mockReadTx, times(2)).read(LogicalDatastoreType.CONFIGURATION, transportZoneIdentifier);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Vteps 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.rev160406.transport.zones.transport.zone.Vteps 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.rev160406.transport.zones.transport.zone.Vteps in project genius by opendaylight.
the class ItmUtils method getInternalTunnelsofTzone.
public static List<String> getInternalTunnelsofTzone(String tzone, DataBroker dataBroker) {
List<String> tunnels = new ArrayList<>();
LOG.trace("Getting internal tunnels of {}", tzone);
InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(tzone)).build();
Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
if (transportZoneOptional.isPresent()) {
TransportZone transportZone = transportZoneOptional.get();
if (transportZone.getSubnets() != null && !transportZone.getSubnets().isEmpty()) {
for (Subnets sub : transportZone.getSubnets()) {
if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
for (Vteps vtepLocal : sub.getVteps()) {
for (Vteps vtepRemote : sub.getVteps()) {
if (!vtepLocal.equals(vtepRemote)) {
InternalTunnelKey key = new InternalTunnelKey(vtepRemote.getDpnId(), vtepLocal.getDpnId(), transportZone.getTunnelType());
InstanceIdentifier<InternalTunnel> intIID = InstanceIdentifier.builder(TunnelList.class).child(InternalTunnel.class, key).build();
Optional<InternalTunnel> tunnelsOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
if (tunnelsOptional.isPresent()) {
List<String> tunnelInterfaceNames = tunnelsOptional.get().getTunnelInterfaceNames();
if (tunnelInterfaceNames != null && !tunnelInterfaceNames.isEmpty()) {
String tunnelInterfaceName = tunnelInterfaceNames.get(0);
LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
tunnels.add(tunnelInterfaceName);
}
}
}
}
}
}
}
}
}
return tunnels;
}
Aggregations