use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class ItmUtils method getTunnelsofTzone.
public static List<String> getTunnelsofTzone(List<HwVtep> hwVteps, String tzone, DataBroker dataBroker, Boolean hwVtepsExist) {
List<String> tunnels = new ArrayList<>();
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();
Class<? extends TunnelTypeBase> tunType = transportZone.getTunnelType();
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(), tunType);
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);
}
}
}
}
if (hwVteps != null && !hwVteps.isEmpty()) {
for (HwVtep hwVtep : hwVteps) {
tunnels.add(getExtTunnel(hwVtep.getNodeId(), vtepLocal.getDpnId().toString(), tunType, dataBroker));
tunnels.add(getExtTunnel(vtepLocal.getDpnId().toString(), hwVtep.getNodeId(), tunType, dataBroker));
}
}
}
}
}
}
if (hwVtepsExist) {
for (HwVtep hwVtep : hwVteps) {
for (HwVtep hwVtepOther : hwVteps) {
if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
tunnels.add(getExtTunnel(hwVtep.getNodeId(), hwVtepOther.getNodeId(), tunType, dataBroker));
tunnels.add(getExtTunnel(hwVtepOther.getNodeId(), hwVtep.getNodeId(), tunType, dataBroker));
}
}
}
}
}
return tunnels;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class ItmUtils method deleteTransportZoneFromConfigDS.
/**
* Deletes the transport zone from Configuration datastore.
*
* @param tzName transport zone name
* @param dataBroker data broker handle to perform operations on datastore
*/
public static void deleteTransportZoneFromConfigDS(String tzName, DataBroker dataBroker) {
// check whether transport-zone exists in config DS.
TransportZone transportZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
if (transportZoneFromConfigDS != null) {
// it exists, delete default-TZ now
InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(tzName)).build();
LOG.debug("Removing {} transport-zone from config DS.", tzName);
try {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
} catch (TransactionCommitFailedException e) {
LOG.error("deleteTransportZoneFromConfigDS failed. {} could not be deleted.", tzName, e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class OvsdbTepAddConfigHelper method addTepReceivedFromOvsdb.
/**
* Adds the TEP into ITM configuration/operational Datastore in one of the following cases.
* 1) default transport zone
* 2) Configured transport zone
* 3) Unhosted transport zone
*
* @param tepIp TEP-IP address in string
* @param strDpnId bridge datapath ID in string
* @param tzName transport zone name in string
* @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
* @param dataBroker data broker handle to perform operations on config/operational datastore
* @param wrTx WriteTransaction object
*/
public static void addTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName, boolean ofTunnel, DataBroker dataBroker, WriteTransaction wrTx) {
BigInteger dpnId = BigInteger.valueOf(0);
if (strDpnId != null && !strDpnId.isEmpty()) {
dpnId = MDSALUtil.getDpnId(strDpnId);
}
// Get tep IP
IpAddress tepIpAddress = IpAddressBuilder.getDefaultInstance(tepIp);
TransportZone tzone = null;
// Case: TZ name is not given with OVS TEP.
if (tzName == null) {
tzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
// add TEP into default-TZ
tzone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
if (tzone == null) {
LOG.error("Error: default-transport-zone is not yet created.");
return;
}
LOG.trace("Add TEP into default-transport-zone.");
} else {
// Case: Add TEP into corresponding TZ created from Northbound.
tzone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
if (tzone == null) {
// Case: TZ is not configured from Northbound, then add TEP into "teps-in-not-hosted-transport-zone"
LOG.trace("Adding TEP with unknown TZ into teps-in-not-hosted-transport-zone.");
addUnknownTzTepIntoTepsNotHosted(tzName, tepIpAddress, dpnId, ofTunnel, dataBroker, wrTx);
return;
} else {
LOG.trace("Add TEP into transport-zone already configured by Northbound.");
}
}
// Get subnet list of corresponding TZ created from Northbound.
List<Subnets> subnetList = tzone.getSubnets();
String portName = ITMConstants.DUMMY_PORT;
IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
if (subnetList == null || subnetList.isEmpty()) {
if (subnetList == null) {
subnetList = new ArrayList<>();
}
List<Vteps> vtepList = new ArrayList<>();
LOG.trace("Add TEP in transport-zone when no subnet-list.");
addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
} else {
List<Vteps> vtepList = null;
// subnet list already exists case; check for dummy-subnet
for (Subnets subnet : subnetList) {
if (subnet.getKey().getPrefix().equals(subnetMaskObj)) {
LOG.trace("Subnet exists in the subnet list of transport-zone {}.", tzName);
// get vtep list of existing subnet
vtepList = subnet.getVteps();
break;
}
}
if (vtepList == null || vtepList.isEmpty()) {
// case: vtep list does not exist or it has no elements
if (vtepList == null) {
vtepList = new ArrayList<>();
}
LOG.trace("Add TEP in transport-zone when no vtep-list for specific subnet.");
addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
} else {
// case: vtep list has elements
boolean vtepFound = false;
Vteps oldVtep = null;
for (Vteps vtep : vtepList) {
if (vtep.getDpnId().equals(dpnId)) {
vtepFound = true;
oldVtep = vtep;
// get portName of existing vtep
portName = vtep.getPortname();
break;
}
}
if (!vtepFound) {
addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
} else {
// vtep is found, update it with tep-ip
vtepList.remove(oldVtep);
addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId, portName, ofTunnel, wrTx);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class OvsdbTepAddConfigHelper method addUnknownTzTepIntoTepsNotHosted.
/**
* Adds the TEP into Vtep list in the subnet list in the transport zone list
* from ITM operational Datastore by merge operation with write transaction.
*
* @param tzName transport zone name in string
* @param tepIpAddress TEP IP address in IpAddress object
* @param dpid bridge datapath ID in BigInteger
* @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
* @param dataBroker data broker handle to perform operations on operational datastore
* @param wrTx WriteTransaction object
*/
protected static void addUnknownTzTepIntoTepsNotHosted(String tzName, IpAddress tepIpAddress, BigInteger dpid, boolean ofTunnel, DataBroker dataBroker, WriteTransaction wrTx) {
List<UnknownVteps> vtepList = null;
TepsInNotHostedTransportZone tepsInNotHostedTransportZone = ItmUtils.getUnknownTransportZoneFromITMOperDS(tzName, dataBroker);
if (tepsInNotHostedTransportZone == null) {
LOG.trace("Unhosted TransportZone ({}) does not exist in OperDS.", tzName);
vtepList = new ArrayList<>();
addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
} else {
vtepList = tepsInNotHostedTransportZone.getUnknownVteps();
if (vtepList == null || vtepList.isEmpty()) {
// case: vtep list does not exist or it has no elements
if (vtepList == null) {
vtepList = new ArrayList<>();
}
LOG.trace("Add TEP into unhosted TZ ({}) when no vtep-list in the TZ.", tzName);
addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
} else {
// case: vtep list has elements
boolean vtepFound = false;
UnknownVteps oldVtep = null;
for (UnknownVteps vtep : vtepList) {
if (vtep.getDpnId().equals(dpid)) {
vtepFound = true;
oldVtep = vtep;
break;
}
}
if (!vtepFound) {
addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
} else {
// vtep is found, update it with tep-ip
vtepList.remove(oldVtep);
addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone in project genius by opendaylight.
the class OvsdbTepAddConfigHelper method addVtepInITMConfigDS.
/**
* Adds the TEP into Vtep list in the subnet list in the transport zone list
* from ITM configuration Datastore by merge operation with write transaction.
*
* @param subnetList subnets list object
* @param subnetMaskObj subnet mask in IpPrefix object
* @param updatedVtepList updated Vteps list object which will have new TEP for addition
* @param tepIpAddress TEP IP address in IpAddress object
* @param tzName transport zone name in string
* @param dpid bridge datapath ID in BigInteger
* @param portName port name as a part of VtepsKey
* @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
* @param wrTx WriteTransaction object
*/
public static void addVtepInITMConfigDS(List<Subnets> subnetList, IpPrefix subnetMaskObj, List<Vteps> updatedVtepList, IpAddress tepIpAddress, String tzName, BigInteger dpid, String portName, boolean ofTunnel, WriteTransaction wrTx) {
// Create TZ node path
InstanceIdentifier<TransportZone> tranzportZonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(tzName)).build();
// when VTEP is moved from TepsNotHosted list to TZ configured from Northbound.
if (dpid.compareTo(BigInteger.ZERO) > 0) {
// create vtep
VtepsKey vtepkey = new VtepsKey(dpid, portName);
Vteps vtepObj = new VtepsBuilder().setDpnId(dpid).setIpAddress(tepIpAddress).setKey(vtepkey).setPortname(portName).setOptionOfTunnel(ofTunnel).build();
// Add vtep obtained from bridge into list
updatedVtepList.add(vtepObj);
LOG.trace("Adding TEP (TZ: {} Subnet: {} TEP IP: {} DPID: {}, of-tunnel: {}) in ITM Config DS.", tzName, subnetMaskObj, tepIpAddress, dpid, ofTunnel);
} else {
// corresponding TZ is configured from northbound.
for (Vteps vtep : updatedVtepList) {
LOG.trace("Moving TEP (TEP IP: {} DPID: {}, of-tunnel: {})" + "from not-hosted-transport-zone {} into ITM Config DS.", vtep.getIpAddress(), vtep.getDpnId(), ofTunnel, tzName);
}
}
// Create subnet object
SubnetsKey subKey = new SubnetsKey(subnetMaskObj);
IpAddress gatewayIP = IpAddressBuilder.getDefaultInstance(ITMConstants.DUMMY_GATEWAY_IP);
int vlanID = ITMConstants.DUMMY_VLANID;
Subnets subnet = new SubnetsBuilder().setGatewayIp(gatewayIP).setKey(subKey).setPrefix(subnetMaskObj).setVlanId(vlanID).setVteps(updatedVtepList).build();
// add subnet into subnet list
subnetList.add(subnet);
// create TZ node with updated subnet having new vtep
TransportZone updatedTzone = new TransportZoneBuilder().setKey(new TransportZoneKey(tzName)).setSubnets(subnetList).setZoneName(tzName).build();
// Update TZ in Config DS to add vtep in TZ
wrTx.merge(LogicalDatastoreType.CONFIGURATION, tranzportZonePath, updatedTzone, true);
}
Aggregations