X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fitm%2Fimpl%2FItmProvider.java;fp=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fitm%2Fimpl%2FItmProvider.java;h=57ed05ae157e49b0227347410e8bf0acb466cca7;hb=04f73a9e43b63c4c3c1ae2214562741f8bc25c85;hp=2c2126e95cc6f428f9e1117d07cdc387cb32882f;hpb=10fe581ba61a6ea7df588bd5ec410f2787648512;p=vpnservice.git diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmProvider.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmProvider.java index 2c2126e9..57ed05ae 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmProvider.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015, 2016 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, @@ -22,20 +22,33 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager; import org.opendaylight.vpnservice.itm.api.IITMProvider; +import org.opendaylight.vpnservice.itm.cli.TepCommandHelper; import org.opendaylight.vpnservice.itm.globals.ITMConstants; +import org.opendaylight.vpnservice.itm.impl.ItmUtils; import org.opendaylight.vpnservice.itm.listeners.TransportZoneListener; +import org.opendaylight.vpnservice.itm.listeners.VtepConfigSchemaListener; import org.opendaylight.vpnservice.itm.rpc.ItmManagerRpcService; +import org.opendaylight.vpnservice.itm.snd.ITMStatusMonitor; +import org.opendaylight.vpnservice.mdsalutil.MDSALUtil; import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.VtepConfigSchemas; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.VtepConfigSchema; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.vtep.config.schemas.VtepConfigSchemaBuilder; +//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; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService; - import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; + public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMProvider /*,ItmStateService */{ private static final Logger LOG = LoggerFactory.getLogger(ItmProvider.class); @@ -47,8 +60,17 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro private ItmManagerRpcService itmRpcService ; private IdManagerService idManager; private NotificationService notificationService; + private TepCommandHelper tepCommandHelper; private TransportZoneListener tzChangeListener; + private VtepConfigSchemaListener vtepConfigSchemaListener; private RpcProviderRegistry rpcProviderRegistry; + private static final ITMStatusMonitor itmStatusMonitor = ITMStatusMonitor.getInstance(); + static short flag = 0; + + public ItmProvider() { + LOG.info("ItmProvider Before register MBean"); + itmStatusMonitor.registerMbean(); + } public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) { this.rpcProviderRegistry = rpcProviderRegistry; @@ -61,6 +83,7 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro @Override public void onSessionInitiated(ProviderContext session) { LOG.info("ItmProvider Session Initiated"); + itmStatusMonitor.reportStatus("STARTING"); try { dataBroker = session.getSALService(DataBroker.class); idManager = getRpcProviderRegistry().getRpcService(IdManagerService.class); @@ -68,6 +91,8 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro itmManager = new ITMManager(dataBroker); tzChangeListener = new TransportZoneListener(dataBroker, idManager) ; itmRpcService = new ItmManagerRpcService(dataBroker, idManager); + vtepConfigSchemaListener = new VtepConfigSchemaListener(dataBroker); + tepCommandHelper = new TepCommandHelper(dataBroker); final BindingAwareBroker.RpcRegistration rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService); itmRpcService.setMdsalManager(mdsalManager); itmManager.setMdsalManager(mdsalManager); @@ -76,9 +101,13 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro tzChangeListener.setMdsalManager(mdsalManager); tzChangeListener.setItmManager(itmManager); tzChangeListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker); + tepCommandHelper = new TepCommandHelper(dataBroker); + tepCommandHelper.setInterfaceManager(interfaceManager); createIdPool(); + itmStatusMonitor.reportStatus("OPERATIONAL"); } catch (Exception e) { LOG.error("Error initializing services", e); + itmStatusMonitor.reportStatus("ERROR"); } } @@ -124,4 +153,163 @@ public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMPro LOG.error("Failed to create idPool for ITM Service",e); } } + + @Override + public DataBroker getDataBroker() { + return dataBroker; + } + @Override + public void createLocalCache(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask, + String gatewayIp, String transportZone) { + if (tepCommandHelper != null) { + tepCommandHelper.createLocalCache(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone); + } else { + LOG.trace("tepCommandHelper doesnt exist"); + } + } + + @Override + public void commitTeps() { + try { + 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 deleteVtep(BigInteger dpnId, String portName, Integer vlanId, String ipAddress, String subnetMask, + String gatewayIp, String transportZone) { + try { + tepCommandHelper.deleteVtep(dpnId, portName, vlanId, ipAddress, subnetMask, gatewayIp, transportZone); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void configureTunnelType(String transportZone, String tunnelType) { + LOG .debug("ItmProvider: configureTunnelType {} for transportZone {}", tunnelType, transportZone); + tepCommandHelper.configureTunnelType(transportZone,tunnelType); + } + + /* + * (non-Javadoc) + * + * @see + * org.opendaylight.vpnservice.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, + getAllVtepConfigSchemas()); + + String schemaName = validatedSchema.getSchemaName(); + VtepConfigSchema existingSchema = getVtepConfigSchema(schemaName); + if (existingSchema != null) { + Preconditions.checkArgument(false, String.format("VtepConfigSchema [%s] already exists!", schemaName)); + } + MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION, + ItmUtils.getVtepConfigSchemaIdentifier(schemaName), validatedSchema); + LOG.debug("Vtep config schema {} added to config DS", schemaName); + } + + /* + * (non-Javadoc) + * + * @see + * org.opendaylight.vpnservice.itm.api.IITMProvider#getVtepConfigSchema(java + * .lang.String) + */ + @Override + public VtepConfigSchema getVtepConfigSchema(String schemaName) { + Optional schema = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, + ItmUtils.getVtepConfigSchemaIdentifier(schemaName), this.dataBroker); + if (schema.isPresent()) { + return schema.get(); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see + * org.opendaylight.vpnservice.itm.api.IITMProvider#getAllVtepConfigSchemas( + * ) + */ + @Override + public List getAllVtepConfigSchemas() { + Optional schemas = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, + ItmUtils.getVtepConfigSchemasIdentifier(), this.dataBroker); + if (schemas.isPresent()) { + return schemas.get().getVtepConfigSchema(); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see + * org.opendaylight.vpnservice.itm.api.IITMProvider#updateVtepSchema(java. + * lang.String, java.util.List, java.util.List) + */ + @Override + public void updateVtepSchema(String schemaName, List lstDpnsForAdd, List lstDpnsForDelete) { + LOG.trace("Updating VTEP schema {} by adding DPN's {} and deleting DPN's {}.", schemaName, lstDpnsForAdd, + lstDpnsForDelete); + + VtepConfigSchema schema = ItmUtils.validateForUpdateVtepSchema(schemaName, lstDpnsForAdd, lstDpnsForDelete, + this); + if (ItmUtils.getDpnIdList(schema.getDpnIds()) == null) { + VtepConfigSchemaBuilder builder = new VtepConfigSchemaBuilder(schema); + builder.setDpnIds(schema.getDpnIds()); + schema = builder.build(); + } else { + if (lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty()) { + ItmUtils.getDpnIdList(schema.getDpnIds()).addAll(lstDpnsForAdd); + } + if (lstDpnsForDelete != null && !lstDpnsForDelete.isEmpty()) { + ItmUtils.getDpnIdList(schema.getDpnIds()).removeAll(lstDpnsForDelete); + } + } + 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.vpnservice.itm.api.IITMProvider#deleteAllVtepSchemas() + */ + @Override + public void deleteAllVtepSchemas() { + List lstSchemas = getAllVtepConfigSchemas(); + if (lstSchemas != null && !lstSchemas.isEmpty()) { + for (VtepConfigSchema schema : lstSchemas) { + MDSALUtil.syncDelete(this.dataBroker, LogicalDatastoreType.CONFIGURATION, + ItmUtils.getVtepConfigSchemaIdentifier(schema.getSchemaName())); + } + } + LOG.debug("Deleted all Vtep schemas from config DS"); + } + + public void configureTunnelMonitorEnabled(boolean monitorEnabled) { + tepCommandHelper.configureTunnelMonitorEnabled(monitorEnabled); + } + + public void configureTunnelMonitorInterval(int interval) { + tepCommandHelper.configureTunnelMonitorInterval(interval); + } }