import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import org.apache.commons.net.util.SubnetUtils;
+import org.apache.felix.service.command.CommandSession;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.itm.globals.ITMConstants;
import org.opendaylight.genius.itm.impl.ItmUtils;
import org.opendaylight.genius.mdsalutil.MDSALDataStoreUtils;
+import org.opendaylight.genius.utils.cache.DataStoreCache;
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.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBfd;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeLldp;
+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.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.op.rev160406.TunnelList;
-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.TepTypeInternal;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZonesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-//import org.opendaylight.genius.interfacemgr.util.OperationalIfmUtil;
-
-
+@Singleton
public class TepCommandHelper {
private static final Logger LOG = LoggerFactory.getLogger(TepCommandHelper.class);
- private DataBroker dataBroker;
+ private final DataBroker dataBroker;
static int check = 0;
static short flag = 0;
/*
* command is Tep-add else set to false when Tep-delete is called
* tepCommandHelper object is created only once in session initiated
*/
- final Map<String, Map<SubnetObject, List<Vteps>>> tZones = new HashMap<String, Map<SubnetObject, List<Vteps>>>();
- private List<Subnets> subnetList = new ArrayList<Subnets>();
- private List<TransportZone> tZoneList = new ArrayList<TransportZone>();
- private List<Vteps> vtepDelCommitList = new ArrayList<Vteps>();
- private IInterfaceManager interfaceManager;
+ final Map<String, Map<SubnetObject, List<Vteps>>> tZones = new HashMap<>();
+ private List<Subnets> subnetList = new ArrayList<>();
+ private List<TransportZone> tZoneList = new ArrayList<>();
+ private List<Vteps> vtepDelCommitList = new ArrayList<>();
// private List<InstanceIdentifier<? extends DataObject>> vtepPaths = new
// ArrayList<>();
-
- public TepCommandHelper(final DataBroker broker) {
- this.dataBroker = broker;
+ @Inject
+ public TepCommandHelper(final DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
}
+ @PostConstruct
+ public void start() {
+ configureTunnelType(ITMConstants.DEFAULT_TRANSPORT_ZONE,ITMConstants.TUNNEL_TYPE_VXLAN);
+ LOG.info("TepCommandHelper Started");
+ }
- public void setInterfaceManager(IInterfaceManager interfaceManager) {
- this.interfaceManager = interfaceManager;
+ @PreDestroy
+ public void close() {
+ LOG.info("TepCommandHelper Closed");
}
public void createLocalCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress,
- String subnetMask, String gatewayIp, String transportZone) {
+ String subnetMask, String gatewayIp, String transportZone, CommandSession session) throws TepException{
check++;
IpAddress ipAddressObj = null;
LOG.debug("gateway is null");
}
} catch (Exception e) {
- System.out.println("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255");
+ handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
return;
}
try {
subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
} catch (Exception e) {
- System.out.println("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32");
+ handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
return;
}
if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
- System.out.println("IpAddress and gateWayIp should belong to the subnet provided");
+ handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
return;
}
if (checkTepPerTzPerDpn(transportZone, dpnId)) {
- System.out.println("Only one end point per transport Zone per Dpn is allowed");
+ if(session != null) {
+ session.getConsole().println("Only one end point per transport Zone per Dpn is allowed");
+ }
return;
}
Vteps vtepCli = new VtepsBuilder().setDpnId(dpnId).setIpAddress(ipAddressObj).setKey(vtepkey)
SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
if (tZones.containsKey(transportZone)) {
- Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(transportZone);
+ Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(transportZone);
if (subVtepMapTemp.containsKey(subObCli)) { // if Subnet exists
- List<Vteps> vtepListTemp = (List<Vteps>) subVtepMapTemp.get(subObCli);
+ List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
if (vtepListTemp.contains(vtepCli)) {
// do nothing
} else {
}
} else { // subnet doesnt exist
if (checkExistingSubnet(subVtepMapTemp, subObCli)) {
- System.out.println("subnet with subnet mask " + subObCli.get_key() + "already exists");
+ if(session != null) {
+ session.getConsole().println("subnet with subnet mask " + subObCli.get_key() + "already exists");
+ }
return;
}
- List<Vteps> vtepListTemp = new ArrayList<Vteps>();
+ List<Vteps> vtepListTemp = new ArrayList<>();
vtepListTemp.add(vtepCli);
subVtepMapTemp.put(subObCli, vtepListTemp);
}
} else {
- List<Vteps> vtepListTemp = new ArrayList<Vteps>();
+ List<Vteps> vtepListTemp = new ArrayList<>();
vtepListTemp.add(vtepCli);
- Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<SubnetObject, List<Vteps>>();
+ Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<>();
subVtepMapTemp.put(subObCli, vtepListTemp);
tZones.put(transportZone, subVtepMapTemp);
}
// Checking for duplicates in local cache
for (String tZ : tZones.keySet()) {
boolean isGreType = isGreTunnelType(tZ, tZoneMap);
- Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(tZ);
+ Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tZ);
for (SubnetObject subOb : subVtepMapTemp.keySet()) {
List<Vteps> vtepList = subVtepMapTemp.get(subOb);
validateForDuplicateAndSingleGreTep(inputVtep, isConfiguredTepGreType, isGreType, vtepList);
if (isConfiguredTepGreType && isGreType) {
for (Vteps vtep : vtepList) {
if (vtep.getDpnId().equals(dpnId)) {
- String errMsg = new StringBuilder("DPN [").append(dpnId)
- .append("] already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.")
- .toString();
+ String errMsg = "DPN [" + dpnId +
+ "] already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.";
Preconditions.checkArgument(false, errMsg);
}
}
return true;
}
*/
- if( (tzone != null) && (tzone.getTunnelType()).equals(TunnelTypeGre.class) ) {
- return true;
- }
- return false;
+ return (tzone != null) && (tzone.getTunnelType()).equals(TunnelTypeGre.class);
}
/**
public TransportZone getTransportZone(String tzone) {
InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
.child(TransportZone.class, new TransportZoneKey(tzone)).build();
- Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
- dataBroker);
- if (tZoneOptional.isPresent()) {
- return tZoneOptional.get();
- }
- return null;
- }
-
- /**
- * Gets the transport zone from config ds.
- *
- * @param tzone
- * the tzone
- * @return the transport zone
- */
- public TransportZone getTransportZoneFromConfigDS(String tzone) {
- InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
- .child(TransportZone.class, new TransportZoneKey(tzone)).build();
- Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
- dataBroker);
- if (tZoneOptional.isPresent()) {
- return tZoneOptional.get();
- }
- return null;
+ return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker).orNull();
}
/**
*/
public TransportZones getAllTransportZones() {
InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
- Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
- if (tZonesOptional.isPresent()) {
- return tZonesOptional.get();
- }
- return null;
+ return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker).orNull();
}
public boolean checkExistingSubnet(Map<SubnetObject, List<Vteps>> subVtepMapTemp, SubnetObject subObCli) {
public boolean checkTepPerTzPerDpn(String tzone, BigInteger dpnId) {
// check in local cache
if (tZones.containsKey(tzone)) {
- Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(tzone);
+ Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tzone);
for (SubnetObject subOb : subVtepMapTemp.keySet()) {
List<Vteps> vtepList = subVtepMapTemp.get(subOb);
for (Vteps vtep : vtepList)
try {
LOG.debug("no of teps added" + check);
if (tZones != null || !tZones.isEmpty()) {
- tZoneList = new ArrayList<TransportZone>();
+ tZoneList = new ArrayList<>();
for (String tZ : tZones.keySet()) {
LOG.debug("tZones" + tZ);
- subnetList = new ArrayList<Subnets>();
- Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(tZ);
+ subnetList = new ArrayList<>();
+ Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(tZ);
for (SubnetObject subOb : subVtepMapTemp.keySet()) {
LOG.debug("subnets" + subOb.get_prefix());
List<Vteps> vtepList = subVtepMapTemp.get(subOb);
LOG.debug("NO vteps were configured");
}
} catch (Exception e) {
- e.printStackTrace();
+ LOG.error(e.getMessage());
}
}
- public void showTeps(boolean monitorEnabled, int monitorInterval) {
+ public void showTeps(boolean monitorEnabled, int monitorInterval, CommandSession session) throws TepException {
boolean flag = false;
InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
TransportZones tZones = tZonesOptional.get();
if(tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty())
{
- System.out.println("No teps configured");
+ handleError("No teps configured", session);
return;
}
- List<String> result = new ArrayList<String>();
+ List<String> result = new ArrayList<>();
result.add(String.format("Tunnel Monitoring (for VXLAN tunnels): %s", (monitorEnabled ? "On" : "Off")));
result.add(String.format("Tunnel Monitoring Interval (for VXLAN tunnels): %d", monitorInterval));
result.add(System.lineSeparator());
result.add(String.format("%-16s %-16s %-16s %-12s %-12s %-12s %-16s %-12s", tZ.getZoneName(), strTunnelType, sub
.getPrefix().getIpv4Prefix().getValue(), sub.getGatewayIp().getIpv4Address()
.getValue(), sub.getVlanId().toString(), vtep.getDpnId().toString(), vtep
- .getIpAddress().getIpv4Address().getValue(), vtep.getPortname().toString()));
+ .getIpAddress().getIpv4Address().getValue(), vtep.getPortname()));
}
}
}
- if (flag == true) {
- for (String p : result) {
- System.out.println(p);
+ if (session != null) {
+ if (flag) {
+ for (String p : result) {
+ System.out.println(p);
+ }
+ } else {
+ System.out.println("No teps to display");
}
- } else
- System.out.println("No teps to display");
- } else
+ }
+ } else if(session != null){
System.out.println("No teps configured");
+ }
}
+public void showCache(String cacheName) {
+
+ if( !DataStoreCache.isCacheValid(cacheName)) {
+ System.out.println( " " + cacheName + " is not a valid Cache Name ") ;
+ return ;
+ }
+ List<Object> keys = null ;
+ keys = DataStoreCache.getKeys(cacheName);
+ if( keys != null && !keys.isEmpty()) {
+ System.out.println( "Dumping the data in cache for " + cacheName ) ;
+ for( Object key : keys ) {
+ System.out.println( " KEY: " + key + " Value: " + DataStoreCache.get(cacheName, key) ) ;
+ System.out.println() ;
+ }
+
+ }else
+ System.out.println( "No data in cache for " + cacheName ) ;
+ }
public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
- String gatewayIp, String transportZone) {
+ String gatewayIp, String transportZone,CommandSession session) throws TepException {
IpAddress ipAddressObj = null;
IpAddress gatewayIpObj = null;
LOG.debug("gateway is null");
}
} catch (Exception e) {
- System.out.println("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255");
+ handleError("Invalid IpAddress. Expected: 1.0.0.0 to 254.255.255.255", session);
return;
}
try {
subnetMaskObj = new IpPrefix(subnetMask.toCharArray());
} catch (Exception e) {
- System.out.println("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32");
+ handleError("Invalid Subnet Mask. Expected: 0.0.0.0/0 to 255.255.255.255/32", session);
return;
}
if (!validateIPs(ipAddress, subnetMask, gatewayIp)) {
- System.out.println("IpAddress and gateWayIp should belong to the subnet provided");
+ handleError("IpAddress and gateWayIp should belong to the subnet provided", session);
return;
}
SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
.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);
+ 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()) {
if(subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)){
vtepDelCommitList.add(vtepCli);
}
- else
- System.out.println(String.format("vtep with this vlan or gateway doesnt exist"));
+ else if(session != null) {
+ session.getConsole().println("vtep with this vlan or gateway doesnt exist");
+ }
}
}
- else
- System.out.println(String.format("Vtep with this ipaddress doesnt exist"));
- } else {
- System.out.println(String.format("Vtep 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");
}
}
}
List<InstanceIdentifier<T>> vtepPaths = new ArrayList<>();
List<InstanceIdentifier<T>> subnetPaths = new ArrayList<>();
List<InstanceIdentifier<T>> tzPaths = new ArrayList<>();
- List<Subnets> subDelList = new ArrayList<Subnets>();
- List<TransportZone> tzDelList = new ArrayList<TransportZone>();
- List<Vteps> vtepDelList = new ArrayList<Vteps>();
+ 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()) {
vtepDelCommitList.clear();
}
} catch (Exception e) {
- e.printStackTrace();
+ LOG.error(e.getMessage());
}
}
- public void showState(TunnelList tunnels, boolean tunnelMonitorEnabled) {
- IfTunnel tunnelInterface = null;
- IfL2vlan l2Vlan = null;
- List<InternalTunnel> tunnelLists = tunnels.getInternalTunnel();
+ public void showState(List<StateTunnelList> tunnelLists, boolean tunnelMonitorEnabled,CommandSession session) throws TepException{
if (tunnelLists == null || tunnelLists.isEmpty()) {
- System.out.println("No Internal Tunnels Exist");
+ handleError("No Internal Tunnels Exist", session);
return;
}
if (!tunnelMonitorEnabled) {
- System.out.println("Tunnel Monitoring is Off");
+ if(session != null) {
+ session.getConsole().println("Tunnel Monitoring is Off");
+ }
}
- String displayFormat = "%-16s %-16s %-16s %-16s %-16s %-8s %-10s %-10s";
+ String displayFormat = "%-16s %-16s %-16s %-16s %-16s %-10s %-10s";
System.out.println(String.format(displayFormat, "Tunnel Name", "Source-DPN",
- "Destination-DPN", "Source-IP", "Destination-IP", "Vlan Id", "Trunk-State", "Transport Type"));
+ "Destination-DPN", "Source-IP", "Destination-IP", "Trunk-State", "Transport Type"));
System.out.println("-------------------------------------------------------------------------------------------------------------------------------------");
- for (InternalTunnel tunnel : tunnelLists) {
- String tunnelInterfaceName = tunnel.getTunnelInterfaceName();
- LOG.trace("tunnelInterfaceName::: {}", tunnelInterfaceName);
-
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
- ItmUtils.buildStateInterfaceId(tunnelInterfaceName);
- Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional =
- ItmUtils.read(LogicalDatastoreType.OPERATIONAL, ifStateId, dataBroker);
- String tunnelState = "DOWN" ;
- if (ifStateOptional.isPresent()) {
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface iface = ifStateOptional.get() ;
- if(iface.getAdminStatus() == AdminStatus.Up && iface.getOperStatus() == OperStatus.Up)
- tunnelState = "UP" ;
- }
- InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
- Optional<Interface> ifaceObj = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, dataBroker) ;
- if (ifaceObj.isPresent()) {
- l2Vlan = (IfL2vlan) ifaceObj.get().getAugmentation(IfL2vlan.class);
- tunnelInterface = (IfTunnel) ifaceObj.get().getAugmentation(IfTunnel.class);
-
- Class<? extends TunnelTypeBase> tunType = tunnelInterface.getTunnelInterfaceType();
+ for (StateTunnelList tunnelInst : tunnelLists) {
+ // Display only the internal tunnels
+ if( tunnelInst.getDstInfo().getTepDeviceType().equals(TepTypeInternal.class)) {
+ String tunnelInterfaceName = tunnelInst.getTunnelInterfaceName();
+ LOG.trace("tunnelInterfaceName::: {}", tunnelInterfaceName);
+ String tunnelState = ITMConstants.TUNNEL_STATE_UNKNOWN;
+ if (tunnelInst.getOperState() == TunnelOperStatus.Up)
+ tunnelState = ITMConstants.TUNNEL_STATE_UP;
+ else if (tunnelInst.getOperState() == TunnelOperStatus.Down )
+ tunnelState = ITMConstants.TUNNEL_STATE_DOWN;
+ Class<? extends TunnelTypeBase> tunType = tunnelInst.getTransportType();
String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
if( tunType.equals(TunnelTypeVxlan.class))
tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN ;
else if( tunType.equals(TunnelTypeGre.class) )
tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
- int vlanId = 0;
- if( l2Vlan != null ) {
- vlanId = l2Vlan.getVlanId().getValue() ;
- }
- System.out.println(String.format(displayFormat, tunnel.getTunnelInterfaceName(), tunnel
- .getSourceDPN().toString(), tunnel.getDestinationDPN().toString(), tunnelInterface.getTunnelSource().getIpv4Address().getValue(), tunnelInterface.getTunnelDestination().getIpv4Address().getValue(),vlanId, tunnelState ,
- tunnelType));
+ else if (tunType.equals(TunnelTypeMplsOverGre.class))
+ tunnelType = ITMConstants.TUNNEL_TYPE_MPLSoGRE;
+ System.out.println(String.format(displayFormat, tunnelInst.getTunnelInterfaceName(), tunnelInst.getSrcInfo().getTepDeviceId(),
+ tunnelInst.getDstInfo().getTepDeviceId(), tunnelInst.getSrcInfo().getTepIp().getIpv4Address().getValue(), tunnelInst.getDstInfo().getTepIp().getIpv4Address().getValue(), tunnelState,
+ tunnelType));
}
}
}
// deletes from ADD-cache if it exists.
public boolean isInCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
- String gatewayIp, String transportZone) {
+ String gatewayIp, String transportZone, CommandSession session) {
boolean exists = false;
VtepsKey vtepkey = new VtepsKey(dpnId, portName);
IpAddress ipAddressObj = new IpAddress(ipAddress.toCharArray());
SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
if (tZones.containsKey(transportZone)) {
- Map<SubnetObject, List<Vteps>> subVtepMapTemp = (Map<SubnetObject, List<Vteps>>) tZones.get(transportZone);
+ Map<SubnetObject, List<Vteps>> subVtepMapTemp = tZones.get(transportZone);
if (subVtepMapTemp.containsKey(subObCli)) { // if Subnet exists
- List<Vteps> vtepListTemp = (List<Vteps>) subVtepMapTemp.get(subObCli);
+ List<Vteps> vtepListTemp = subVtepMapTemp.get(subObCli);
if (vtepListTemp.contains(vtepCli)) {
exists = true; // return true if tzones has vtep
vtepListTemp.remove(vtepCli);
tZones.remove(transportZone);
}
}
- } else {
- System.out.println("Vtep " + "has not been configured");
+ } else if(session != null) {
+ session.getConsole().println("Vtep " + "has not been configured");
}
}
}
public void configureTunnelType(String tZoneName, String tunnelType) {
LOG.debug("configureTunnelType {} for transportZone {}", tunnelType, tZoneName);
- TransportZone tZoneFromConfigDS = getTransportZoneFromConfigDS(tZoneName);
+ TransportZone tZoneFromConfigDS = ItmUtils.getTransportZoneFromConfigDS(tZoneName, dataBroker);
validateTunnelType(tZoneName, tunnelType,tZoneFromConfigDS);
if (tZoneFromConfigDS != null) {
if (tZones.isPresent()) {
tZoneList = tZones.get().getTransportZone();
if(tZoneList == null || tZoneList.isEmpty()) {
- tZoneList = new ArrayList<TransportZone>();
+ tZoneList = new ArrayList<>();
}
} else {
- tZoneList = new ArrayList<TransportZone>();
+ tZoneList = new ArrayList<>();
}
tZoneList.add(tZone);
transportZones = new TransportZonesBuilder().setTransportZone(tZoneList).build();
// if (tZone != null) {
if (tZoneFromConfigDS != null) {
if( (!tZoneFromConfigDS.getTunnelType().equals(tunType)) && ItmUtils.isNotEmpty(tZoneFromConfigDS.getSubnets())) {
- String errorMsg = new StringBuilder("Changing the tunnel type from ").append(tZoneFromConfigDS.getTunnelType())
- .append(" to ").append(strTunnelType)
- .append(" is not allowed for already configured transport zone [").append(tZoneName)
- .append("].").toString();
+ String errorMsg = "Changing the tunnel type from " + tZoneFromConfigDS.getTunnelType() +
+ " to " + strTunnelType +
+ " is not allowed for already configured transport zone [" + tZoneName +
+ "].";
Preconditions.checkArgument(false, errorMsg);
}
}
ItmUtils.DEFAULT_CALLBACK);
}
}
+
+ public void handleError(String errorMessage, CommandSession session) throws TepException {
+ if(session != null) {
+ session.getConsole().println(errorMessage);
+ } else {
+ throw new TepException(errorMessage);
+ }
+
+ }
}