use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class TepCommandHelper method deleteOnCommit.
@SuppressWarnings("checkstyle:IllegalCatch")
public <T extends DataObject> void deleteOnCommit() {
List<InstanceIdentifier<T>> vtepPaths = new ArrayList<>();
List<InstanceIdentifier<T>> subnetPaths = new ArrayList<>();
List<InstanceIdentifier<T>> tzPaths = new ArrayList<>();
List<Subnets> subDelList = new ArrayList<>();
List<TransportZone> tzDelList = new ArrayList<>();
List<Vteps> vtepDelList = new ArrayList<>();
List<InstanceIdentifier<T>> allPaths = new ArrayList<>();
try {
if (vtepDelCommitList != null && !vtepDelCommitList.isEmpty()) {
InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones transportZones = transportZonesOptional.get();
for (TransportZone tz : transportZones.getTransportZone()) {
if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
continue;
}
for (Subnets sub : tz.getSubnets()) {
vtepDelList.addAll(vtepDelCommitList);
for (Vteps vtep : vtepDelList) {
InstanceIdentifier<T> vpath = (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, tz.getKey()).child(Subnets.class, sub.getKey()).child(Vteps.class, vtep.getKey()).build();
if (sub.getVteps().remove(vtep)) {
vtepPaths.add(vpath);
if (sub.getVteps().size() == 0 || sub.getVteps() == null) {
subDelList.add(sub);
}
}
}
}
}
for (TransportZone tz : transportZones.getTransportZone()) {
if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
continue;
}
for (Subnets sub : subDelList) {
if (tz.getSubnets().remove(sub)) {
InstanceIdentifier<T> spath = (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, tz.getKey()).child(Subnets.class, sub.getKey()).build();
subnetPaths.add(spath);
if (tz.getSubnets() == null || tz.getSubnets().size() == 0) {
tzDelList.add(tz);
}
}
}
}
for (TransportZone tz : tzDelList) {
if (transportZones.getTransportZone().remove(tz)) {
InstanceIdentifier<T> tpath = (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, tz.getKey()).build();
tzPaths.add(tpath);
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().size() == 0) {
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.delete(LogicalDatastoreType.CONFIGURATION, path)), LOG, "Error deleting {}", path);
return;
}
}
}
allPaths.addAll(vtepPaths);
allPaths.addAll(subnetPaths);
allPaths.addAll(tzPaths);
ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.CONFIGURATION, allPaths, ItmUtils.DEFAULT_CALLBACK);
}
vtepPaths.clear();
subnetPaths.clear();
tzPaths.clear();
allPaths.clear();
vtepDelCommitList.clear();
}
} catch (RuntimeException e) {
LOG.error("Unexpected error", e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class TepCommandHelper method configureTunnelType.
public void configureTunnelType(String transportZoneName, String tunnelType) {
LOG.debug("configureTunnelType {} for transportZone {}", tunnelType, transportZoneName);
TransportZone transportZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(transportZoneName, dataBroker);
Class<? extends TunnelTypeBase> tunType;
validateTunnelType(transportZoneName, tunnelType, transportZoneFromConfigDS);
if (transportZoneFromConfigDS != null) {
if (!transportZoneName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
LOG.debug("Transport zone {} with tunnel type {} already exists. No action required.", transportZoneName, tunnelType);
return;
} else {
tunnelType = StringUtils.upperCase(tunnelType);
tunType = ItmUtils.TUNNEL_TYPE_MAP.get(tunnelType);
if (transportZoneFromConfigDS.getTunnelType().equals(tunType)) {
// controller restart, then nothing to do now. Just return.
return;
}
}
}
// get tunnel-type
tunnelType = StringUtils.upperCase(tunnelType);
tunType = ItmUtils.TUNNEL_TYPE_MAP.get(tunnelType);
TransportZones transportZones = null;
List<TransportZone> tzList = null;
InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
Optional<TransportZones> tzones = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
TransportZone tzone = new TransportZoneBuilder().setKey(new TransportZoneKey(transportZoneName)).setTunnelType(tunType).build();
if (tzones.isPresent()) {
tzList = tzones.get().getTransportZone();
if (tzList == null || tzList.isEmpty()) {
tzList = new ArrayList<>();
}
} else {
tzList = new ArrayList<>();
}
tzList.add(tzone);
transportZones = new TransportZonesBuilder().setTransportZone(tzList).build();
ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, path, transportZones, dataBroker);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class TepCommandHelper method deleteVtep.
@SuppressWarnings("checkstyle:IllegalCatch")
public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask, String gatewayIp, String transportZone, CommandSession session) throws TepException {
IpAddress ipAddressObj = null;
IpAddress gatewayIpObj = null;
IpPrefix subnetMaskObj = null;
final VtepsKey vtepkey = new VtepsKey(dpnId, portName);
try {
ipAddressObj = IpAddressBuilder.getDefaultInstance(ipAddress);
gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
if (!("null".equals(gatewayIp)) || ("0.0.0.0".equals(gatewayIp)) && (gatewayIp != null)) {
gatewayIpObj = IpAddressBuilder.getDefaultInstance(gatewayIp);
} else {
LOG.debug("gateway is null");
gatewayIp = null;
}
} catch (RuntimeException e) {
handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
return;
}
try {
subnetMaskObj = IpPrefixBuilder.getDefaultInstance(subnetMask);
} catch (Exception e) {
handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
return;
}
if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
return;
}
SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
Vteps vtepCli = null;
Subnets subCli = null;
InstanceIdentifier<Vteps> vpath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(Vteps.class, vtepkey).build();
// check if present in tzones and delete from cache
boolean existsInCache = isInCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone, session);
if (!existsInCache) {
Optional<Vteps> vtepOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, vpath, dataBroker);
if (vtepOptional.isPresent()) {
vtepCli = vtepOptional.get();
if (vtepCli.getIpAddress().equals(ipAddressObj)) {
InstanceIdentifier<Subnets> spath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).build();
Optional<Subnets> subOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, spath, dataBroker);
if (subOptional.isPresent()) {
subCli = subOptional.get();
if (subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)) {
vtepDelCommitList.add(vtepCli);
} else if (session != null) {
session.getConsole().println("vtep with this vlan or gateway doesnt exist");
}
}
} else if (session != null) {
session.getConsole().println("Vtep with this ipaddress doesnt exist");
}
} else if (session != null) {
session.getConsole().println("Vtep Doesnt exist");
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class ItmExternalTunnelAddWorker method tunnelsFromhWVtep.
private void tunnelsFromhWVtep(List<HwVtep> cfgdHwVteps, WriteTransaction transaction, Integer monitorInterval, Class<? extends TunnelMonitoringTypeBase> monitorProtocol) {
for (HwVtep hwTep : cfgdHwVteps) {
InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(hwTep.getTransportZone())).build();
Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
if (transportZoneOptional.isPresent()) {
TransportZone tzone = transportZoneOptional.get();
// do we need to check tunnel type?
if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
for (Subnets sub : tzone.getSubnets()) {
if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp())) {
// dont mesh with self
continue;
}
LOG.trace("wire up {} and {}", hwTep, hwVtepDS);
if (!wireUp(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), hwTep.getIpPrefix(), hwTep.getGatewayIP(), sub.getPrefix(), tunType, false, monitorInterval, monitorProtocol, transaction)) {
LOG.error("Unable to build tunnel {} -- {}", hwTep.getHwIp(), hwVtepDS.getIpAddress());
}
// TOR2-TOR1
LOG.trace("wire up {} and {}", hwVtepDS, hwTep);
if (!wireUp(hwTep.getTopoId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), hwTep.getNodeId(), hwTep.getHwIp(), sub.getPrefix(), sub.getGatewayIp(), hwTep.getIpPrefix(), tunType, false, monitorInterval, monitorProtocol, transaction)) {
LOG.error("Unable to build tunnel {} -- {}", hwVtepDS.getIpAddress(), hwTep.getHwIp());
}
}
}
if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
for (Vteps vtep : sub.getVteps()) {
if (vtep.getIpAddress().equals(hwTep.getHwIp())) {
continue;
}
// TOR-OVS
String cssID = vtep.getDpnId().toString();
LOG.trace("wire up {} and {}", hwTep, vtep);
if (!wireUp(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(), cssID, vtep.getIpAddress(), hwTep.getIpPrefix(), hwTep.getGatewayIP(), sub.getPrefix(), tunType, false, monitorInterval, monitorProtocol, transaction)) {
LOG.error("Unable to build tunnel {} -- {}", hwTep.getHwIp(), vtep.getIpAddress());
}
// OVS-TOR
LOG.trace("wire up {} and {}", vtep, hwTep);
boolean useOfTunnel = ItmUtils.falseIfNull(vtep.isOptionOfTunnel());
if (!wireUp(vtep.getDpnId(), vtep.getPortname(), sub.getVlanId(), vtep.getIpAddress(), useOfTunnel, hwTep.getNodeId(), hwTep.getHwIp(), sub.getPrefix(), sub.getGatewayIp(), hwTep.getIpPrefix(), tunType, false, monitorInterval, monitorProtocol, transaction)) {
LOG.debug("wireUp returned false");
}
}
}
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class ItmExternalTunnelDeleteWorker method deleteTunnelsInTransportZone.
private static void deleteTunnelsInTransportZone(String zoneName, DPNTEPsInfo dpn, TunnelEndPoints srcTep, List<HwVtep> cfgdhwVteps, DataBroker dataBroker, WriteTransaction writeTransaction) {
InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(zoneName)).build();
Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
if (transportZoneOptional.isPresent()) {
TransportZone tzone = transportZoneOptional.get();
// do we need to check tunnel type?
if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
for (Subnets sub : tzone.getSubnets()) {
if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
// OVS-TOR-OVS
deleteTrunksOvsTor(dataBroker, dpn.getDPNID(), srcTep.getInterfaceName(), srcTep.getIpAddress(), hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), tzone.getTunnelType(), writeTransaction);
}
}
}
}
if (cfgdhwVteps != null && !cfgdhwVteps.isEmpty()) {
for (HwVtep hwVtep : cfgdhwVteps) {
deleteTrunksOvsTor(dataBroker, dpn.getDPNID(), srcTep.getInterfaceName(), srcTep.getIpAddress(), hwVtep.getTopoId(), hwVtep.getNodeId(), hwVtep.getHwIp(), TunnelTypeVxlan.class, writeTransaction);
}
}
}
}
Aggregations