/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.util.SubnetUtils;
import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
import org.opendaylight.genius.itm.api.IITMProvider;
import org.opendaylight.genius.itm.confighelpers.HwVtep;
import org.opendaylight.genius.itm.globals.ITMConstants;
-import org.opendaylight.genius.mdsalutil.*;
+import org.opendaylight.genius.mdsalutil.ActionInfo;
+import org.opendaylight.genius.mdsalutil.FlowEntity;
+import org.opendaylight.genius.mdsalutil.InstructionInfo;
+import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.genius.mdsalutil.MatchFieldType;
+import org.opendaylight.genius.mdsalutil.MatchInfo;
+import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
+import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlanBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifierBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.interfaces._interface.NodeIdentifierKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorInterval;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParams;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorParamsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.VtepConfigSchemas;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.VtepIpPools;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.vtep.config.schemas.VtepConfigSchema;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPointsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.tunnel.end.points.TzMembership;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.tunnel.end.points.TzMembershipBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnel.list.InternalTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnel.list.InternalTunnelBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnel.list.InternalTunnelKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBfd;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.genius.utils.cache.DataStoreCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
public class ItmUtils {
public static final String DUMMY_IP_ADDRESS = "0.0.0.0";
public static final String TUNNEL_TYPE_VXLAN = "VXLAN";
public static final String TUNNEL_TYPE_GRE = "GRE";
- public static final String TUNNEL = "TUNNEL";
+ public static final String TUNNEL = "tun";
public static ItmCache itmCache = new ItmCache();
private static final Logger LOG = LoggerFactory.getLogger(ItmUtils.class);
public static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
+ @Override
public void onSuccess(Void result) {
LOG.debug("Success in Datastore write operation");
}
+ @Override
public void onFailure(Throwable error) {
LOG.error("Error in Datastore write operation", error);
}
public static <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
InstanceIdentifier<T> path, DataBroker broker) {
-
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-
- Optional<T> result = Optional.absent();
- try {
- result = tx.read(datastoreType, path).get();
+ try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
-
- return result;
}
public static <T extends DataObject> void asyncWrite(LogicalDatastoreType datastoreType,
String trunkInterfaceName = String.format( "%s:%s:%s:%s", parentInterfaceName, localHostName,
remoteHostName, tunnelTypeStr);
LOG.trace("trunk interface name is {}", trunkInterfaceName);
- trunkInterfaceName = String.format("%s:%s", TUNNEL, getUniqueId(idManager, trunkInterfaceName));
+ trunkInterfaceName = String.format("%s%s", TUNNEL, getUniqueIdString(trunkInterfaceName));
return trunkInterfaceName;
}
}
String trunkInterfaceName = String.format("%s:%s:%s:%s", parentInterfaceName, localHostName, remoteHostName, tunnelTypeStr);
LOG.trace("Releasing Id for trunkInterface - {}", trunkInterfaceName );
- releaseId(idManager, trunkInterfaceName) ;
+ //releaseId(idManager, trunkInterfaceName) ;
}
public static InetAddress getInetAddressFromIpAddress(IpAddress ip) {
return new DPNTEPsInfoBuilder().setKey(new DPNTEPsInfoKey(dpId)).setTunnelEndPoints(endpoints).build();
}
- public static TunnelEndPoints createTunnelEndPoints(BigInteger dpnId, IpAddress ipAddress, String portName, int vlanId,
- IpPrefix prefix, IpAddress gwAddress, String zoneName, Class<? extends TunnelTypeBase> tunnel_type) {
+ public static TunnelEndPoints createTunnelEndPoints(BigInteger dpnId, IpAddress ipAddress, String portName,
+ boolean isOfTunnel, int vlanId, IpPrefix prefix,
+ IpAddress gwAddress, List<TzMembership> zones,
+ Class<? extends TunnelTypeBase> tunnel_type) {
// when Interface Mgr provides support to take in Dpn Id
return new TunnelEndPointsBuilder().setKey(new TunnelEndPointsKey(ipAddress, portName,tunnel_type, vlanId))
- .setSubnetMask(prefix).setGwIpAddress(gwAddress).setTransportZone(zoneName)
- .setInterfaceName(ItmUtils.getInterfaceName(dpnId, portName, vlanId)).setTunnelType(tunnel_type).build();
+ .setSubnetMask(prefix).setGwIpAddress(gwAddress).setTzMembership(zones)
+ .setOptionOfTunnel(isOfTunnel).setInterfaceName(ItmUtils.getInterfaceName(dpnId, portName, vlanId))
+ .setTunnelType(tunnel_type).build();
}
public static DpnEndpoints createDpnEndpoints(List<DPNTEPsInfo> dpnTepInfo) {
return id;
}
- public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled, Class<? extends TunnelTypeBase> tunType,
- IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp,Integer vlanId, boolean internal, Boolean monitorEnabled, Class<? extends TunnelMonitoringTypeBase> monitorProtocol, Integer monitorInterval) {
+ public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled,
+ Class<? extends TunnelTypeBase> tunType, IpAddress localIp,
+ IpAddress remoteIp, IpAddress gatewayIp, Integer vlanId,
+ boolean internal, Boolean monitorEnabled,
+ Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
+ Integer monitorInterval, boolean useOfTunnel) {
InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName)
.setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build();
builder.addAugmentation(ParentRefs.class, parentRefs);
+ Long monitoringInterval=null;
if( vlanId > 0) {
IfL2vlan l2vlan = new IfL2vlanBuilder().setVlanId(new VlanId(vlanId)).build();
builder.addAugmentation(IfL2vlan.class, l2vlan);
}
LOG.debug("buildTunnelInterface: monitorProtocol = {} and monitorInterval = {}",monitorProtocol.getName(),monitorInterval);
- Long monitoringInterval = (long)ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL;
- Boolean monitoringEnabled = true;
- if(monitorInterval!= null)
+
+ if(monitorInterval != null) {
monitoringInterval = monitorInterval.longValue();
- else {
- if (monitorProtocol.getName().contains("Bfd"))
- monitoringInterval = (long) ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL;
- else
- monitoringInterval = (long) ITMConstants.DEFAULT_MONITOR_INTERVAL;
}
- LOG.debug("buildTunnelInterface: monitorProtocol = {} and monitorInterval = {}",monitorProtocol.getName(),monitorInterval);
- if(monitorEnabled!=null )
- monitoringEnabled = monitorEnabled;
- IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(
- gatewayIp).setTunnelSource(localIp)
- .setTunnelInterfaceType(tunType).setInternal(internal).setMonitorEnabled(
- monitoringEnabled).setMonitorProtocol(monitorProtocol).setMonitorInterval(monitoringInterval).build();
+ IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(gatewayIp)
+ .setTunnelSource(localIp).setTunnelInterfaceType(tunType).setInternal(internal)
+ .setMonitorEnabled(monitorEnabled).setMonitorProtocol(monitorProtocol)
+ .setMonitorInterval(monitoringInterval).setTunnelRemoteIpFlow(useOfTunnel)
+ .build();
builder.addAugmentation(IfTunnel.class, tunnel);
return builder.build();
}
InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelIfName)).setName(
tunnelIfName).setDescription(desc).
setEnabled(enabled).setType(Tunnel.class);
- List<NodeIdentifier> nodeIds = new ArrayList<NodeIdentifier>();
+ List<NodeIdentifier> nodeIds = new ArrayList<>();
NodeIdentifier hWnode = new NodeIdentifierBuilder().setKey(new NodeIdentifierKey(topo_id)).setTopologyId(
topo_id).
setNodeId(node_id).build();
Long monitoringInterval = (long) ITMConstants.DEFAULT_MONITOR_INTERVAL;
Boolean monitoringEnabled = true;
Class<? extends TunnelMonitoringTypeBase> monitoringProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
- if(monitor_interval!= null)
+ if(monitor_interval!= null) {
monitoringInterval = monitor_interval.longValue();
- if(monitor_enabled!=null )
+ }
+ if(monitor_enabled!=null ) {
monitoringEnabled = monitor_enabled;
- if(monitorProtocol!=null)
+ }
+ if(monitorProtocol!=null) {
monitoringProtocol = monitorProtocol;
+ }
IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(destIp).setTunnelGateway(gWIp).setTunnelSource(
srcIp).setMonitorEnabled(monitoringEnabled).setMonitorProtocol(monitorProtocol).setMonitorInterval(100L).
setTunnelInterfaceType(tunType).setInternal(false).build();
public static List<DPNTEPsInfo> getTunnelMeshInfo(DataBroker dataBroker) {
List<DPNTEPsInfo> dpnTEPs= null ;
+ // Read the Mesh Information from Cache if not read from the DS
+ dpnTEPs = getTunnelMeshInfo() ;
+ if( dpnTEPs != null ) {
+ return dpnTEPs ;
+ }
+
// Read the EndPoint Info from the operational database
InstanceIdentifierBuilder<DpnEndpoints> depBuilder = InstanceIdentifier.builder( DpnEndpoints.class);
InstanceIdentifier<DpnEndpoints> deps = depBuilder.build();
DpnEndpoints tn= dpnEps.get() ;
dpnTEPs = tn.getDPNTEPsInfo();
LOG.debug( "Read from CONFIGURATION datastore - No. of Dpns " , dpnTEPs.size() );
- }else
+ } else {
LOG.debug( "No Dpn information in CONFIGURATION datastore " );
+ }
return dpnTEPs ;
}
+ // Reading the Mesh Information from Cache
+ public static List<DPNTEPsInfo> getTunnelMeshInfo(){
+ List<DPNTEPsInfo> dpnTepsInfo = null ;
+ List<Object> values = null ;
+
+ values = DataStoreCache.getValues(ITMConstants.DPN_TEPs_Info_CACHE_NAME);
+ if( values != null ) {
+ dpnTepsInfo = new ArrayList<>() ;
+ for( Object value : values ) {
+ dpnTepsInfo.add((DPNTEPsInfo)value) ;
+ }
+ }
+ return dpnTepsInfo ;
+ }
+
public static int getUniqueId(IdManagerService idManager, String idKey) {
AllocateIdInput getIdInput = new AllocateIdInputBuilder()
.setPoolName(ITMConstants.ITM_IDPOOL_NAME)
return 0;
}
+ public static String getUniqueIdString(String idKey) {
+ return UUID.nameUUIDFromBytes(idKey.getBytes()).toString().substring(0, 12).replace("-", "");
+ }
+
public static void releaseId(IdManagerService idManager, String idKey) {
ReleaseIdInput idInput =
new ReleaseIdInputBuilder().setPoolName(ITMConstants.ITM_IDPOOL_NAME).setIdKey(idKey).build();
public static List<DPNTEPsInfo> getDPNTEPListFromDPNId(DataBroker dataBroker, List<BigInteger> dpnIds) {
List<DPNTEPsInfo> meshedDpnList = getTunnelMeshInfo(dataBroker) ;
- List<DPNTEPsInfo> cfgDpnList = new ArrayList<DPNTEPsInfo>();
+ List<DPNTEPsInfo> cfgDpnList = new ArrayList<>();
if( null != meshedDpnList) {
for(BigInteger dpnId : dpnIds) {
for( DPNTEPsInfo teps : meshedDpnList ) {
- if( dpnId.equals(teps.getDPNID()))
+ if( dpnId.equals(teps.getDPNID())) {
cfgDpnList.add( teps) ;
+ }
}
}
}
}
public static void setUpOrRemoveTerminatingServiceTable(BigInteger dpnId, IMdsalApiManager mdsalManager, boolean addFlag) {
- String logmsg = ( addFlag == true) ? "Installing" : "Removing";
+ String logmsg = addFlag ? "Installing" : "Removing";
LOG.trace( logmsg + " PUNT to Controller flow in DPN {} ", dpnId );
- long dpId;
- List<ActionInfo> listActionInfo = new ArrayList<ActionInfo>();
- listActionInfo.add(new ActionInfo(ActionType.punt_to_controller,
- new String[] {}));
+ List<ActionInfo> listActionInfo = new ArrayList<>();
+ listActionInfo.add(new ActionPuntToController());
try {
- List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
+ List<MatchInfo> mkMatches = new ArrayList<>();
mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {
BigInteger.valueOf(ITMConstants.LLDP_SERVICE_ID) }));
- List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
- mkInstructions.add(new InstructionInfo(InstructionType.apply_actions,
- listActionInfo));
+ List<InstructionInfo> mkInstructions = new ArrayList<>();
+ mkInstructions.add(new InstructionApplyActions(listActionInfo));
FlowEntity terminatingServiceTableFlowEntity = MDSALUtil
.buildFlowEntity(
0, 0, ITMConstants.COOKIE_ITM
.add(BigInteger.valueOf(ITMConstants.LLDP_SERVICE_ID)),
mkMatches, mkInstructions);
- if(addFlag)
+ if(addFlag) {
mdsalManager.installFlow(terminatingServiceTableFlowEntity);
- else
+ } else {
mdsalManager.removeFlow(terminatingServiceTableFlowEntity);
+ }
} catch (Exception e) {
LOG.error("Error while setting up Table 36 for {}", dpnId, e);
}
}
private static String getFlowRef(long termSvcTable, int svcId) {
- return new StringBuffer().append(termSvcTable).append(svcId).toString();
+ return String.valueOf(termSvcTable) + svcId;
}
public static InstanceIdentifier<VtepConfigSchema> getVtepConfigSchemaIdentifier(String schemaName) {
return InstanceIdentifier.builder(VtepConfigSchemas.class)
if (!StringUtils.equalsIgnoreCase(schema.getSchemaName(), existingSchema.getSchemaName())
&& schema.getSubnet().equals(existingSchema.getSubnet())) {
String subnetCidr = getSubnetCidrAsString(schema.getSubnet());
- Preconditions.checkArgument(false, new StringBuilder("VTEP schema with subnet [").append(subnetCidr)
- .append("] already exists. Multiple VTEP schemas with same subnet is not allowed.").toString());
+ Preconditions.checkArgument(false, "VTEP schema with subnet [" + subnetCidr +
+ "] already exists. Multiple VTEP schemas with same subnet is not allowed.");
}
}
if (isNotEmpty(getDpnIdList(validSchema.getDpnIds()))) {
getDpnIdList(validSchema.getDpnIds()), existingSchemas);
if (!lstDpns.isEmpty()) {
Preconditions.checkArgument(false,
- new StringBuilder("DPN's ").append(lstDpns).append(" already configured for transport zone ")
- .append(tzone).append(". Only one end point per transport Zone per Dpn is allowed.")
- .toString());
+ "DPN's " + lstDpns + " already configured for transport zone " +
+ tzone + ". Only one end point per transport Zone per Dpn is allowed.");
}
if (schema.getTunnelType().equals(TunnelTypeGre.class)){
validateForSingleGreTep(validSchema.getSchemaName(), getDpnIdList(validSchema.getDpnIds()), existingSchemas);
private static void validateForSingleGreTep(String schemaName, List<BigInteger> lstDpnsForAdd,
List<VtepConfigSchema> existingSchemas) {
for (VtepConfigSchema existingSchema : emptyIfNull(existingSchemas)) {
- if ((TunnelTypeGre.class).equals(existingSchema.getTunnelType())
+ if (TunnelTypeGre.class.equals(existingSchema.getTunnelType())
&& !StringUtils.equalsIgnoreCase(schemaName, existingSchema.getSchemaName())) {
List<BigInteger> lstConflictingDpns = new ArrayList<>(getDpnIdList(existingSchema.getDpnIds()));
lstConflictingDpns.retainAll(emptyIfNull(lstDpnsForAdd));
if (!lstConflictingDpns.isEmpty()) {
- String errMsg = new StringBuilder("DPN's ").append(lstConflictingDpns)
- .append(" already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.")
- .toString();
+ String errMsg = "DPN's " + lstConflictingDpns +
+ " already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.";
Preconditions.checkArgument(false, errMsg);
}
}
Preconditions.checkNotNull(schema);
Preconditions.checkArgument(StringUtils.isNotBlank(schema.getSchemaName()));
Preconditions.checkArgument(StringUtils.isNotBlank(schema.getPortName()));
- Preconditions.checkArgument((schema.getVlanId() >= 0 && schema.getVlanId() < 4095),
+ Preconditions.checkArgument(schema.getVlanId() >= 0 && schema.getVlanId() < 4095,
"Invalid VLAN ID, range (0-4094)");
Preconditions.checkArgument(StringUtils.isNotBlank(schema.getTransportZoneName()));
Preconditions.checkNotNull(schema.getSubnet());
if (gatewayIp != null) {
String strGatewayIp = String.valueOf(gatewayIp.getValue());
if (!strGatewayIp.equals(ITMConstants.DUMMY_IP_ADDRESS) && !subnetUtils.getInfo().isInRange(strGatewayIp)) {
- Preconditions.checkArgument(false, new StringBuilder("Gateway IP address ").append(strGatewayIp)
- .append(" is not in subnet range ").append(subnetCidr).toString());
+ Preconditions.checkArgument(false, "Gateway IP address " + strGatewayIp +
+ " is not in subnet range " + subnetCidr);
}
}
ItmUtils.getExcludeIpAddresses(schema.getExcludeIpFilter(), subnetUtils.getInfo());
tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
} else {
tunnelType = StringUtils.upperCase(tunnelType);
- String error = new StringBuilder("Invalid tunnel type. Valid values: ")
- .append(ITMConstants.TUNNEL_TYPE_VXLAN).append(" | ").append(ITMConstants.TUNNEL_TYPE_GRE)
- .toString();
+ String error = "Invalid tunnel type. Valid values: " +
+ ITMConstants.TUNNEL_TYPE_VXLAN + " | " + ITMConstants.TUNNEL_TYPE_GRE;
Preconditions.checkArgument(ITMConstants.TUNNEL_TYPE_VXLAN.equals(tunnelType)
|| ITMConstants.TUNNEL_TYPE_GRE.equals(tunnelType), error);
}
IpAddress gatewayIpObj = StringUtils.isBlank(gatewayIp) ? null : new IpAddress(gatewayIp.toCharArray());
IpPrefix subnet = StringUtils.isBlank(subnetMask) ? null : new IpPrefix(subnetMask.toCharArray());
Class<? extends TunnelTypeBase> tunType ;
- if( tunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN))
+ if( tunnelType.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) {
tunType = TunnelTypeVxlan.class ;
- else
+ } else {
tunType = TunnelTypeGre.class ;
+ }
VtepConfigSchemaBuilder schemaBuilder = new VtepConfigSchemaBuilder().setSchemaName(schemaName)
.setPortName(portName).setVlanId(vlanId).setSubnet(subnet).setGatewayIp(gatewayIpObj)
.setTransportZoneName(transportZone).setTunnelType(tunType).setDpnIds(getDpnIdsListFromBigInt(dpnIds))
String strStartIp = StringUtils.trim(arrIpRange[0]);
String strEndIp = StringUtils.trim(arrIpRange[1]);
Preconditions.checkArgument(InetAddresses.isInetAddress(strStartIp),
- new StringBuilder("Invalid exclude IP filter: invalid IP address value ").append(strStartIp)
- .toString());
+ "Invalid exclude IP filter: invalid IP address value " + strStartIp);
Preconditions.checkArgument(InetAddresses.isInetAddress(strEndIp),
- new StringBuilder("Invalid exclude IP filter: invalid IP address value ").append(strEndIp)
- .toString());
+ "Invalid exclude IP filter: invalid IP address value " + strEndIp);
Preconditions.checkArgument(subnetInfo.isInRange(strStartIp),
- new StringBuilder("Invalid exclude IP filter: IP address [").append(strStartIp)
- .append("] not in subnet range ").append(subnetInfo.getCidrSignature()).toString());
+ "Invalid exclude IP filter: IP address [" + strStartIp +
+ "] not in subnet range " + subnetInfo.getCidrSignature());
Preconditions.checkArgument(subnetInfo.isInRange(strEndIp),
- new StringBuilder("Invalid exclude IP filter: IP address [").append(strEndIp)
- .append("] not in subnet range ").append(subnetInfo.getCidrSignature()).toString());
+ "Invalid exclude IP filter: IP address [" + strEndIp +
+ "] not in subnet range " + subnetInfo.getCidrSignature());
int startIp = subnetInfo.asInteger(strStartIp);
int endIp = subnetInfo.asInteger(strEndIp);
Preconditions.checkArgument(startIp < endIp,
- new StringBuilder("Invalid exclude IP filter: Invalid range [").append(ip).append("] ")
- .toString());
+ "Invalid exclude IP filter: Invalid range [" + ip + "] ");
for (int i = startIp; i <= endIp; i++) {
String ipAddress = ipFormat(toIpArray(i));
validateAndAddIpAddressToList(subnetInfo, lstIpAddress, ipAddress);
String ipAddress) {
String ip = StringUtils.trim(ipAddress);
Preconditions.checkArgument(InetAddresses.isInetAddress(ip),
- new StringBuilder("Invalid exclude IP filter: invalid IP address value ").append(ip).toString());
+ "Invalid exclude IP filter: invalid IP address value " + ip);
Preconditions.checkArgument(subnetInfo.isInRange(ip),
- new StringBuilder("Invalid exclude IP filter: IP address [").append(ip).append("] not in subnet range ")
- .append(subnetInfo.getCidrSignature()).toString());
+ "Invalid exclude IP filter: IP address [" + ip + "] not in subnet range " +
+ subnetInfo.getCidrSignature());
lstIpAddress.add(new IpAddress(ip.toCharArray()));
}
private static int[] toIpArray(int val) {
int[] ret = new int[4];
for (int j = 3; j >= 0; --j) {
- ret[j] |= ((val >>> 8 * (3 - j)) & (0xff));
+ ret[j] |= val >>> 8 * (3 - j) & 0xff;
}
return ret;
}
if ((lstDpnsForAdd == null || lstDpnsForAdd.isEmpty())
&& (lstDpnsForDelete == null || lstDpnsForDelete.isEmpty())) {
Preconditions.checkArgument(false,
- new StringBuilder("DPN ID list for add | delete is null or empty in schema ").append(schemaName)
- .toString());
+ "DPN ID list for add | delete is null or empty in schema " + schemaName);
}
VtepConfigSchema schema = itmProvider.getVtepConfigSchema(schemaName);
if (schema == null) {
- Preconditions.checkArgument(false, new StringBuilder("Specified VTEP Schema [").append(schemaName)
- .append("] doesn't exists!").toString());
+ Preconditions.checkArgument(false, "Specified VTEP Schema [" + schemaName +
+ "] doesn't exists!");
}
List<BigInteger> existingDpnIds = getDpnIdList(schema.getDpnIds());
if (isNotEmpty(lstDpnsForAdd)) {
List<BigInteger> lstAlreadyExistingDpns = new ArrayList<>(existingDpnIds);
lstAlreadyExistingDpns.retainAll(lstDpnsForAdd);
Preconditions.checkArgument(lstAlreadyExistingDpns.isEmpty(),
- new StringBuilder("DPN ID's ").append(lstAlreadyExistingDpns)
- .append(" already exists in VTEP schema [").append(schemaName).append("]").toString());
+ "DPN ID's " + lstAlreadyExistingDpns +
+ " already exists in VTEP schema [" + schemaName + "]");
// }
if (schema.getTunnelType().equals(TunnelTypeGre.class)) {
validateForSingleGreTep(schema.getSchemaName(), lstDpnsForAdd, itmProvider.getAllVtepConfigSchemas());
}
if (isNotEmpty(lstDpnsForDelete)) {
if (existingDpnIds == null || existingDpnIds.isEmpty()) {
- StringBuilder builder = new StringBuilder("DPN ID's ").append(lstDpnsForDelete)
- .append(" specified for delete from VTEP schema [").append(schemaName)
- .append("] are not configured in the schema.");
- Preconditions.checkArgument(false, builder.toString());
+ String builder = "DPN ID's " + lstDpnsForDelete +
+ " specified for delete from VTEP schema [" + schemaName +
+ "] are not configured in the schema.";
+ Preconditions.checkArgument(false, builder);
} else if (!existingDpnIds.containsAll(lstDpnsForDelete)) {
List<BigInteger> lstConflictingDpns = new ArrayList<>(lstDpnsForDelete);
lstConflictingDpns.removeAll(existingDpnIds);
- StringBuilder builder = new StringBuilder("DPN ID's ").append(lstConflictingDpns)
- .append(" specified for delete from VTEP schema [").append(schemaName)
- .append("] are not configured in the schema.");
- Preconditions.checkArgument(false, builder.toString());
+ String builder = "DPN ID's " + lstConflictingDpns +
+ " specified for delete from VTEP schema [" + schemaName +
+ "] are not configured in the schema.";
+ Preconditions.checkArgument(false, builder);
}
}
return schema;
}
public static String getSubnetCidrAsString(IpPrefix subnet) {
- return (subnet == null) ? StringUtils.EMPTY : String.valueOf(subnet.getValue());
+ return subnet == null ? StringUtils.EMPTY : String.valueOf(subnet.getValue());
}
public static <T> List<T> emptyIfNull(List<T> list) {
- return (list == null) ? Collections.<T> emptyList() : list;
+ return list == null ? Collections.emptyList() : list;
}
public static <T> boolean isEmpty(Collection<T> collection) {
- return (collection == null || collection.isEmpty()) ? true : false;
+ return collection == null || collection.isEmpty();
}
public static <T> boolean isNotEmpty(Collection<T> collection) {
return !isEmpty(collection);
}
public static List<BigInteger> getDpnIdList( List<DpnIds> dpnIds ) {
- List<BigInteger> dpnList = new ArrayList<BigInteger>() ;
+ List<BigInteger> dpnList = new ArrayList<>() ;
for( DpnIds dpn : dpnIds) {
dpnList.add(dpn.getDPN()) ;
}
}
public static List<DpnIds> getDpnIdsListFromBigInt( List<BigInteger> dpnIds) {
- List<DpnIds> dpnIdList = new ArrayList<DpnIds>() ;
+ List<DpnIds> dpnIdList = new ArrayList<>() ;
DpnIdsBuilder builder = new DpnIdsBuilder() ;
for( BigInteger dpnId : dpnIds) {
dpnIdList.add(builder.setKey(new DpnIdsKey(dpnId)).setDPN(dpnId).build() );
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> id = idBuilder.build();
return id;
}
- public static Boolean readMonitoringStateFromDS(DataBroker dataBroker) {
+ public static Boolean readMonitoringStateFromCache(DataBroker dataBroker) {
InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.create(TunnelMonitorParams.class);
- Optional<TunnelMonitorParams> TunnelMonitorParamsOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
- iid, dataBroker);
- if(TunnelMonitorParamsOptional.isPresent())
- return TunnelMonitorParamsOptional.get().isEnabled();
- return null;
+ TunnelMonitorParams tunnelMonitorParams = (TunnelMonitorParams) DataStoreCache.get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"MonitorParams",dataBroker,true);
+ if(tunnelMonitorParams!=null) {
+ return tunnelMonitorParams.isEnabled();
+ } else {
+ return ITMConstants.DEFAULT_MONITOR_ENABLED;
+ }
}
- public static Integer readMonitorIntervalfromDS(DataBroker dataBroker) {
+ public static Integer readMonitorIntervalfromCache(DataBroker dataBroker) {
InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.create(TunnelMonitorInterval.class);
- Optional<TunnelMonitorInterval> tunnelMonitorIOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, iid, dataBroker);
- if(tunnelMonitorIOptional.isPresent())
- return tunnelMonitorIOptional.get().getInterval();
+ TunnelMonitorInterval tunnelMonitorIOptional = (TunnelMonitorInterval)DataStoreCache.get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"Interval",dataBroker,true);
+ if(tunnelMonitorIOptional!=null) {
+ return tunnelMonitorIOptional.getInterval();
+ }
return null;
}
public static Integer determineMonitorInterval(DataBroker dataBroker) {
- Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromCache(dataBroker);
LOG.debug("determineMonitorInterval: monitorInterval from DS = {}", monitorInterval);
if(monitorInterval==null){
- Class<? extends TunnelMonitoringTypeBase> monitoringProtocol = determineMonitorProtocol(dataBroker);
- if(monitoringProtocol.getName().contains("Bfd"))
+ Class<? extends TunnelMonitoringTypeBase> monitorProtocol = determineMonitorProtocol(dataBroker);
+ if(monitorProtocol.isAssignableFrom(TunnelMonitoringTypeBfd.class)) {
monitorInterval = ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL;
- else
+ } else {
monitorInterval = ITMConstants.DEFAULT_MONITOR_INTERVAL;
+ }
}
LOG.debug("determineMonitorInterval: monitorInterval = {}", monitorInterval);
+ InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
+ TunnelMonitorInterval intervalBuilder = new TunnelMonitorIntervalBuilder().setInterval(monitorInterval).build();
+ ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, intervalBuilder, dataBroker, ItmUtils.DEFAULT_CALLBACK);
return monitorInterval;
}
+ public static List<String> getInternalTunnelInterfaces(DataBroker dataBroker){
+ List<String> tunnelList = new ArrayList<>();
+ Collection<String> internalInterfaces = itmCache.getAllInternalInterfaces();
+ if(internalInterfaces == null) {
+ updateTunnelsCache(dataBroker);
+ internalInterfaces = itmCache.getAllInternalInterfaces();
+ }
+ LOG.debug("ItmUtils.getTunnelList Cache Internal Interfaces size: {} ", internalInterfaces.size());
+ if(internalInterfaces!=null) {
+ tunnelList.addAll(internalInterfaces);
+ }
+ LOG.trace("ItmUtils.getTunnelList Internal: {}", tunnelList);
+ return tunnelList;
+ }
+
public static List<String> getTunnelsofTzone(List<HwVtep> hwVteps, String tzone, DataBroker dataBroker, Boolean hwVtepsExist) {
- List<String> tunnels = new ArrayList<String>();
+ List<String> tunnels = new ArrayList<>();
InstanceIdentifier<TransportZone> path = InstanceIdentifier.builder(TransportZones.class).
child(TransportZone.class, new TransportZoneKey(tzone)).build();
Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
- Class<? extends TunnelTypeBase> tunType = tZoneOptional.get().getTunnelType();
if (tZoneOptional.isPresent()) {
- if (tZoneOptional.get().getSubnets() != null && !tZoneOptional.get().getSubnets().isEmpty()) {
- for (Subnets sub : tZoneOptional.get().getSubnets()) {
+ TransportZone transportZone = tZoneOptional.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()) {
Optional<InternalTunnel> TunnelsOptional =
ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
if (TunnelsOptional.isPresent()) {
- LOG.trace("Internal Tunnel added {}",TunnelsOptional.get().getTunnelInterfaceName());
- tunnels.add(TunnelsOptional.get().getTunnelInterfaceName());
+ String tunnelInterfaceName = TunnelsOptional.get().getTunnelInterfaceName();
+ LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
+ tunnels.add(tunnelInterfaceName);
}
}
}
}
}
}
- }
- if (hwVtepsExist) {
- for (HwVtep hwVtep : hwVteps) {
- for (HwVtep hwVtepOther : hwVteps) {
- if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
- tunnels.add(getExtTunnel(hwVtep.getNode_id(), hwVtepOther.getNode_id(), tunType, dataBroker));
- tunnels.add(getExtTunnel(hwVtepOther.getNode_id(), hwVtep.getNode_id(), tunType, dataBroker));
+ if (hwVtepsExist) {
+ for (HwVtep hwVtep : hwVteps) {
+ for (HwVtep hwVtepOther : hwVteps) {
+ if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
+ tunnels.add(getExtTunnel(hwVtep.getNode_id(), hwVtepOther.getNode_id(), tunType, dataBroker));
+ tunnels.add(getExtTunnel(hwVtepOther.getNode_id(), hwVtep.getNode_id(), tunType, dataBroker));
+ }
}
}
}
}
public static List<String> getInternalTunnelsofTzone(String tzone, DataBroker dataBroker) {
- List<String> tunnels = new ArrayList<String>();
+ 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> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
if (tZoneOptional.isPresent()) {
- if (tZoneOptional.get().getSubnets() != null && !tZoneOptional.get().getSubnets().isEmpty()) {
- for (Subnets sub : tZoneOptional.get().getSubnets()) {
+ TransportZone transportZone = tZoneOptional.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(), tZoneOptional.get().getTunnelType());
+ 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 =
+ Optional<InternalTunnel> tunnelsOptional =
ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
- if (TunnelsOptional.isPresent()) {
- LOG.trace("Internal Tunnel added {}",
- TunnelsOptional.get().getTunnelInterfaceName());
- tunnels.add(TunnelsOptional.get().getTunnelInterfaceName());
+ if (tunnelsOptional.isPresent()) {
+ String tunnelInterfaceName = tunnelsOptional.get().getTunnelInterfaceName();
+ LOG.trace("Internal Tunnel added {}", tunnelInterfaceName);
+ tunnels.add(tunnelInterfaceName);
}
}
}
ExternalTunnelKey key = getExternalTunnelKey(dpId, node_id, tunType);
InstanceIdentifier<ExternalTunnel> intIID = InstanceIdentifier.builder(ExternalTunnelList.class).
child(ExternalTunnel.class, key).build();
- Optional<ExternalTunnel> TunnelsOptional =
+ Optional<ExternalTunnel> tunnelsOptional =
ItmUtils.read(LogicalDatastoreType.CONFIGURATION, intIID, dataBroker);
- if (TunnelsOptional.isPresent()) {
- LOG.trace("ext tunnel returned {} ",TunnelsOptional.get().getTunnelInterfaceName());
- return TunnelsOptional.get().getTunnelInterfaceName();
+ if (tunnelsOptional.isPresent()) {
+ String tunnelInterfaceName = tunnelsOptional.get().getTunnelInterfaceName();
+ LOG.trace("ext tunnel returned {} ", tunnelInterfaceName);
+ return tunnelInterfaceName;
}
return null;
}
}
public static TunnelList getAllInternalTunnels(DataBroker broker) {
InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class).build();
- Optional<TunnelList> tunnelList = read(LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier, broker);
- if (tunnelList.isPresent()) {
- return tunnelList.get();
- }
- return null;
+ return read(LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier, broker).orNull();
}
public static InternalTunnel getInternalTunnel(String interfaceName, DataBroker broker) {
InternalTunnel internalTunnel = null;
}
public static String convertTunnelTypetoString(Class<? extends TunnelTypeBase> tunType ) {
String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
- if( tunType.equals(TunnelTypeVxlan.class))
+ if( tunType.equals(TunnelTypeVxlan.class)) {
tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
- else if( tunType.equals(TunnelTypeGre.class) )
+ } else if( tunType.equals(TunnelTypeGre.class) ) {
tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
- else if (tunnelType.equals(TunnelTypeMplsOverGre.class))
- tunnelType = ITMConstants.TUNNEL_TYPE_MPLS_OVER_GRE;
+ } else if (tunnelType.equals(TunnelTypeMplsOverGre.class)) {
+ tunnelType = ITMConstants.TUNNEL_TYPE_MPLSoGRE;
+ }
return tunnelType ;
}
public static boolean isItmIfType(Class<? extends InterfaceType> ifType) {
- if( (ifType != null) && (ifType.isAssignableFrom(Tunnel.class)) ) {
- return true;
- }
- return false;
+ return ifType != null && ifType.isAssignableFrom(Tunnel.class);
}
public static StateTunnelListKey getTunnelStateKey( org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface iface) {
return result;
}
- public static Class<? extends TunnelMonitoringTypeBase> readMonitoringProtocolFromDS(DataBroker dataBroker) {
+ public static Class<? extends TunnelMonitoringTypeBase> readMonitoringProtocolFromCache(DataBroker dataBroker) {
InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.create(TunnelMonitorParams.class);
- Optional<TunnelMonitorParams> TunnelMonitorParamsOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
- iid, dataBroker);
- if(TunnelMonitorParamsOptional.isPresent())
- return TunnelMonitorParamsOptional.get().getMonitorProtocol();
+ TunnelMonitorParams tunnelMonitorParams = (TunnelMonitorParams) DataStoreCache.get(ITMConstants.ITM_MONIRORING_PARAMS_CACHE_NAME,iid,"MonitorParams",dataBroker,true);
+ if(tunnelMonitorParams!=null) {
+ return tunnelMonitorParams.getMonitorProtocol();
+ }
return null;
}
public static Class<? extends TunnelMonitoringTypeBase> determineMonitorProtocol(DataBroker dataBroker) {
- Class<? extends TunnelMonitoringTypeBase> monitoringProtocol = ItmUtils.readMonitoringProtocolFromDS(dataBroker);
+ Class<? extends TunnelMonitoringTypeBase> monitoringProtocol = ItmUtils.readMonitoringProtocolFromCache(dataBroker);
LOG.debug("determineMonitorProtocol: monitorProtocol from DS = {}", monitoringProtocol);
- if(monitoringProtocol==null)
+ if(monitoringProtocol==null) {
monitoringProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
+ }
LOG.debug("determineMonitorProtocol: monitorProtocol = {}", monitoringProtocol);
+ Boolean monitorState = ItmUtils.readMonitoringStateFromCache(dataBroker);
+ if(monitorState==null) {
+ monitorState = true;
+ }
+ LOG.debug("determineMonitorProtocol: monitorState = {}", monitorState);
+ InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
+ TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder().setEnabled(monitorState).setMonitorProtocol(monitoringProtocol).build();
+ ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, protocolBuilder, dataBroker, ItmUtils.DEFAULT_CALLBACK);
return monitoringProtocol;
}
-
public static List<DcGatewayIp> getDcGatewayIpList(DataBroker broker){
InstanceIdentifier<DcGatewayIpList> dcGatewayIpListid = InstanceIdentifier.builder(DcGatewayIpList.class).build();
Optional<DcGatewayIpList> dcGatewayIpListConfig = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dcGatewayIpListid, broker);
if(dcGatewayIpListConfig.isPresent()){
DcGatewayIpList containerList = dcGatewayIpListConfig.get();
if(containerList != null){
- return (containerList.getDcGatewayIp());
+ return containerList.getDcGatewayIp();
}
}
return null;
}
+
+ public static boolean falseIfNull(Boolean value) {
+ return value == null ? false : value;
+ }
+
+ public static <T> List<T> getIntersection(List<T> list1, List<T> list2) {
+ List<T> list = new ArrayList<>();
+ for (T t : list1) {
+ if(list2.contains(t)) {
+ list.add(t);
+ }
+ }
+ return list;
+ }
+
+ public static void addTransportZoneMembership(List<TzMembership> zones, String zoneName) {
+ zones.add(new TzMembershipBuilder().setZoneName(zoneName).build());
+ }
+
+ public static List<TzMembership> createTransportZoneMembership(String zoneName) {
+ List<TzMembership> zones = new ArrayList<>();
+ zones.add(new TzMembershipBuilder().setZoneName(zoneName).build());
+ return zones;
+ }
+
}