import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import java.math.BigInteger;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.apache.felix.service.command.CommandSession;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.NotificationService;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.itm.api.IITMProvider;
import org.opendaylight.genius.itm.cli.TepCommandHelper;
+import org.opendaylight.genius.itm.cli.TepException;
import org.opendaylight.genius.itm.globals.ITMConstants;
+import org.opendaylight.genius.itm.listeners.InterfaceStateListener;
import org.opendaylight.genius.itm.listeners.TransportZoneListener;
import org.opendaylight.genius.itm.listeners.TunnelMonitorChangeListener;
import org.opendaylight.genius.itm.listeners.TunnelMonitorIntervalListener;
import org.opendaylight.genius.itm.listeners.VtepConfigSchemaListener;
+import org.opendaylight.genius.itm.monitoring.ItmTunnelEventListener;
import org.opendaylight.genius.itm.rpc.ItmManagerRpcService;
import org.opendaylight.genius.itm.snd.ITMStatusMonitor;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+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.VtepConfigSchemas;
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.config.rev160406.vtep.config.schemas.VtepConfigSchemaBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
+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.rpcs.rev160406.AddExternalTunnelEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveExternalTunnelEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddExternalTunnelEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveExternalTunnelEndpointInputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.config.rev151102.VtepConfigSchemas;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.config.rev151102.vtep.config.schemas.VtepConfigSchemaBuilder;
-
public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMProvider /*,ItmStateService */{
private static final Logger LOG = LoggerFactory.getLogger(ItmProvider.class);
private TunnelMonitorChangeListener tnlToggleListener;
private TunnelMonitorIntervalListener tnlIntervalListener;
private VtepConfigSchemaListener vtepConfigSchemaListener;
+ private InterfaceStateListener ifStateListener;
private RpcProviderRegistry rpcProviderRegistry;
private static final ITMStatusMonitor itmStatusMonitor = ITMStatusMonitor.getInstance();
+ private ItmTunnelEventListener itmStateListener;
static short flag = 0;
public ItmProvider() {
tzChangeListener = new TransportZoneListener(dataBroker, idManager) ;
itmRpcService = new ItmManagerRpcService(dataBroker, idManager);
vtepConfigSchemaListener = new VtepConfigSchemaListener(dataBroker);
+ this.ifStateListener = new InterfaceStateListener(dataBroker);
tnlToggleListener = new TunnelMonitorChangeListener(dataBroker);
tnlIntervalListener = new TunnelMonitorIntervalListener(dataBroker);
tepCommandHelper = new TepCommandHelper(dataBroker);
- final BindingAwareBroker.RpcRegistration<ItmRpcService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
+ getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
itmRpcService.setMdsalManager(mdsalManager);
itmManager.setMdsalManager(mdsalManager);
itmManager.setNotificationPublishService(notificationPublishService);
tnlToggleListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
tepCommandHelper = new TepCommandHelper(dataBroker);
tepCommandHelper.setInterfaceManager(interfaceManager);
+ tepCommandHelper.configureTunnelType(ITMConstants.DEFAULT_TRANSPORT_ZONE,ITMConstants.TUNNEL_TYPE_VXLAN);
+ tepCommandHelper.configureTunnelMonitorParams(ITMConstants.DEFAULT_MONITOR_ENABLED,ITMConstants.MONITOR_TYPE_BFD);
+ tepCommandHelper.configureTunnelMonitorInterval(ITMConstants.DEFAULT_MONITOR_INTERVAL);
+ itmStateListener =new ItmTunnelEventListener(dataBroker);
createIdPool();
itmStatusMonitor.reportStatus("OPERATIONAL");
} catch (Exception e) {
public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
this.notificationPublishService = notificationPublishService;
}
-
+
public void setMdsalApiManager(IMdsalApiManager mdsalMgr) {
this.mdsalManager = mdsalMgr;
}
private void createIdPool() {
CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
- .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
- .setLow(ITMConstants.ITM_IDPOOL_START)
- .setHigh(new BigInteger(ITMConstants.ITM_IDPOOL_SIZE).longValue())
- .build();
+ .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
+ .setLow(ITMConstants.ITM_IDPOOL_START)
+ .setHigh(new BigInteger(ITMConstants.ITM_IDPOOL_SIZE).longValue())
+ .build();
try {
Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
if ((result != null) && (result.get().isSuccessful())) {
public DataBroker getDataBroker() {
return dataBroker;
}
+
+ public void addExternalEndpoint(Class<? extends TunnelTypeBase> tunnelType, IpAddress dcgwIP) {
+ AddExternalTunnelEndpointInput addExternalTunnelEndpointInput =
+ new AddExternalTunnelEndpointInputBuilder().setTunnelType(tunnelType)
+ .setDestinationIp(dcgwIP).build();
+ itmRpcService.addExternalTunnelEndpoint(addExternalTunnelEndpointInput);
+ }
+
+ public void remExternalEndpoint(Class<? extends TunnelTypeBase> tunnelType, IpAddress dcgwIP) {
+ RemoveExternalTunnelEndpointInput removeExternalTunnelEndpointInput =
+ new RemoveExternalTunnelEndpointInputBuilder().setTunnelType(tunnelType)
+ .setDestinationIp(dcgwIP).build();
+ itmRpcService.removeExternalTunnelEndpoint(removeExternalTunnelEndpointInput);
+ }
@Override
public void createLocalCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
- String gatewayIp, String transportZone) {
+ String gatewayIp, String transportZone, CommandSession session) {
if (tepCommandHelper != null) {
- tepCommandHelper.createLocalCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone);
+ try {
+ tepCommandHelper.createLocalCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone, session);
+ } catch (TepException e) {
+ LOG.error(e.getMessage());
+ }
} else {
LOG.trace("tepCommandHelper doesnt exist");
}
@Override
public void commitTeps() {
try {
- tepCommandHelper.deleteOnCommit();
- tepCommandHelper.buildTeps();
+ tepCommandHelper.deleteOnCommit();
+ tepCommandHelper.buildTeps();
} catch (Exception e) {
LOG.debug("unable to configure teps" + e.toString());
}
}
@Override
- public void showTeps() {
- tepCommandHelper.showTeps(itmManager.getTunnelMonitorEnabledFromConfigDS(),
- itmManager.getTunnelMonitorIntervalFromConfigDS());
+ public void showTeps(CommandSession session) {
+ try {
+ tepCommandHelper.showTeps(itmManager.getTunnelMonitorEnabledFromConfigDS(), ItmUtils.determineMonitorInterval(this.dataBroker), session);
+ } catch (TepException e) {
+ LOG.error(e.getMessage());
+ }
}
- public void showState(TunnelList tunnels) {
- if (tunnels != null)
- tepCommandHelper.showState(tunnels, itmManager.getTunnelMonitorEnabledFromConfigDS());
+ public void showState(TunnelList tunnels, CommandSession session) {
+ if (tunnels != null) {
+ try {
+ tepCommandHelper.showState(tunnels, itmManager.getTunnelMonitorEnabledFromConfigDS(), session);
+ } catch (TepException e) {
+ LOG.trace(e.getMessage());
+ }
+ }
else
LOG.debug("No tunnels available");
}
public void deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask,
- String gatewayIp, String transportZone) {
+ String gatewayIp, String transportZone, CommandSession session) {
try {
- tepCommandHelper.deleteVtep(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone);
+ tepCommandHelper.deleteVtep(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone, session);
} catch (Exception e) {
- e.printStackTrace();
+ LOG.error(e.getMessage());
}
}
tepCommandHelper.configureTunnelType(transportZone,tunnelType);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.genius.itm.api.IITMProvider#addVtepConfigSchema(org.
- * opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.config.
- * rev151102.vtep.config.schemas.VtepConfigSchema)
- */
@Override
public void addVtepConfigSchema(VtepConfigSchema vtepConfigSchema) {
VtepConfigSchema validatedSchema = ItmUtils.validateForAddVtepConfigSchema(vtepConfigSchema,
LOG.debug("Vtep config schema {} added to config DS", schemaName);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.genius.itm.api.IITMProvider#getVtepConfigSchema(java
- * .lang.String)
- */
@Override
public VtepConfigSchema getVtepConfigSchema(String schemaName) {
Optional<VtepConfigSchema> schema = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
return null;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.genius.itm.api.IITMProvider#getAllVtepConfigSchemas(
- * )
- */
@Override
public List<VtepConfigSchema> getAllVtepConfigSchemas() {
Optional<VtepConfigSchemas> schemas = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
return null;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.genius.itm.api.IITMProvider#updateVtepSchema(java.
- * lang.String, java.util.List, java.util.List)
- */
@Override
public void updateVtepSchema(String schemaName, List<BigInteger> lstDpnsForAdd, List<BigInteger> lstDpnsForDelete) {
LOG.trace("Updating VTEP schema {} by adding DPN's {} and deleting DPN's {}.", schemaName, lstDpnsForAdd,
VtepConfigSchema schema = ItmUtils.validateForUpdateVtepSchema(schemaName, lstDpnsForAdd, lstDpnsForDelete,
this);
VtepConfigSchemaBuilder builder = new VtepConfigSchemaBuilder(schema);
- if (ItmUtils.getDpnIdList(schema.getDpnIds()).isEmpty()) {
+ /* if (ItmUtils.getDpnIdList(schema.getDpnIds()).isEmpty()) {
builder.setDpnIds(schema.getDpnIds());
- } else {
+ } else {*/
if (lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty()) {
List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds()) ;
originalDpnList.addAll(lstDpnsForAdd) ;
}
if (lstDpnsForDelete != null && !lstDpnsForDelete.isEmpty()) {
List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds()) ;
- originalDpnList.removeAll(lstDpnsForAdd) ;
+ originalDpnList.removeAll(lstDpnsForDelete) ;
builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList)) ;
// schema.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(ItmUtils.getDpnIdList(schema.getDpnIds()).removeAll(lstDpnsForAdd)));
}
- }
+ // }
schema = builder.build();
MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION,
ItmUtils.getVtepConfigSchemaIdentifier(schemaName), schema);
LOG.debug("Vtep config schema {} updated to config DS with DPN's {}", schemaName, ItmUtils.getDpnIdList(schema.getDpnIds()));
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.genius.itm.api.IITMProvider#deleteAllVtepSchemas()
- */
@Override
public void deleteAllVtepSchemas() {
List<VtepConfigSchema> lstSchemas = getAllVtepConfigSchemas();
LOG.debug("Deleted all Vtep schemas from config DS");
}
- public void configureTunnelMonitorEnabled(boolean monitorEnabled) {
- tepCommandHelper.configureTunnelMonitorEnabled(monitorEnabled);
+ public void configureTunnelMonitorParams(boolean monitorEnabled, String monitorProtocol) {
+ tepCommandHelper.configureTunnelMonitorParams(monitorEnabled, monitorProtocol);
}
public void configureTunnelMonitorInterval(int interval) {
tepCommandHelper.configureTunnelMonitorInterval(interval);
}
+
+ public boolean validateIP (final String ip){
+ if (ip == null || ip.equals("")) {
+ return false;
+ }
+ final String PATTERN =
+ "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
+ Pattern pattern = Pattern.compile(PATTERN);
+ Matcher matcher = pattern.matcher(ip);
+ return matcher.matches();
+ }
}