From 75e707b364cd6fadc460b4fa96c31c4fa697305c Mon Sep 17 00:00:00 2001 From: Nishchya Gupta Date: Wed, 15 Jul 2020 13:11:06 +0530 Subject: [PATCH] Provide API support for External tunnels Till now external tunnels were created only through cli. Now we provide support for API also by attaching a DcGatewayIplistener to the datastore in such a way the functionality of CLI and API are in sync. Signed-off-by: Nishchya Gupta Change-Id: I20d94c442b4643d7cd5b145f90d9f52f246b7367 --- .../itm/listeners/DcGatewayIpListener.java | 128 ++++++++++++++++++ .../genius/itm/rpc/ItmManagerRpcService.java | 6 - .../itm/tests/ItmManagerRpcServiceTest.java | 12 +- .../xtend/ExpectedDcGatewayIpObjects.xtend | 24 ++++ 4 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/DcGatewayIpListener.java create mode 100644 itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/xtend/ExpectedDcGatewayIpObjects.xtend diff --git a/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/DcGatewayIpListener.java b/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/DcGatewayIpListener.java new file mode 100644 index 000000000..4382bd1eb --- /dev/null +++ b/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/DcGatewayIpListener.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2019 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.genius.itm.listeners; + +import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.Callable; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache; +import org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelAddWorker; +import org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelDeleteWorker; +import org.opendaylight.genius.itm.globals.ITMConstants; +import org.opendaylight.infrautils.jobcoordinator.JobCoordinator; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner; +import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.serviceutils.tools.mdsal.listener.AbstractSyncDataTreeChangeListener; +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.itm.config.rev160406.ItmConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo; +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.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Singleton +public class DcGatewayIpListener extends AbstractSyncDataTreeChangeListener { + private static final Logger LOG = LoggerFactory.getLogger(DcGatewayIpListener.class); + private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("GeniusEventLogger"); + private final DPNTEPsInfoCache dpnTEPsInfoCache; + private final ItmExternalTunnelAddWorker externalTunnelAddWorker; + private final DataBroker dataBroker; + private final JobCoordinator coordinator; + private final ManagedNewTransactionRunner txRunner; + + @Inject + public DcGatewayIpListener(final DPNTEPsInfoCache dpnTEPsInfoCache, final DataBroker dataBroker, + final ItmConfig itmConfig, final JobCoordinator coordinator) { + super(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(DcGatewayIpList.class) + .child(DcGatewayIp.class)); + this.dpnTEPsInfoCache = dpnTEPsInfoCache; + this.coordinator = coordinator; + this.dataBroker = dataBroker; + this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker); + this.externalTunnelAddWorker = new ItmExternalTunnelAddWorker(itmConfig, dpnTEPsInfoCache); + } + + @Override + public void add(DcGatewayIp input) { + LOG.debug("Received ADD event for {}", input.getIpAddress()); + coordinator.enqueueJob(input.getIpAddress().stringValue(), + new DcGatewayIpAddWorker(input.getIpAddress(),input.getTunnnelType()), ITMConstants.JOB_MAX_RETRIES); + } + + @Override + public void update(DcGatewayIp original, DcGatewayIp update) { + //Do nothing + } + + @Override + public void remove(DcGatewayIp input) { + LOG.debug("Received REMOVE event for {}", input.getIpAddress()); + coordinator.enqueueJob(input.getIpAddress().stringValue(), + new DcGatewayIpRemoveWorker(input.getIpAddress(),input.getTunnnelType()), ITMConstants.JOB_MAX_RETRIES); + } + + + private class DcGatewayIpAddWorker implements Callable>> { + private final IpAddress ipAddress; + private final Class tunnelType; + + DcGatewayIpAddWorker(IpAddress ipAddress, Class tunnelType) { + this.ipAddress = ipAddress; + this.tunnelType = tunnelType; + } + + @Override + public List> call() throws Exception { + EVENT_LOGGER.debug("ITM-DcGatewayIp,ADD {}", ipAddress); + Collection meshedDpnList = dpnTEPsInfoCache.getAllPresent(); + return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, + tx -> externalTunnelAddWorker.buildTunnelsToExternalEndPoint(meshedDpnList, + ipAddress, tunnelType, tx))); + } + + @Override + public String toString() { + return "DcGatewayIpAddWorker{ dcGatewayIp =" + ipAddress + '\'' + '}'; + } + } + + private class DcGatewayIpRemoveWorker implements Callable>> { + private final IpAddress ipAddress; + private final Class tunnelType; + + DcGatewayIpRemoveWorker(IpAddress ipAddress, Class tunnelType) { + this.ipAddress = ipAddress; + this.tunnelType = tunnelType; + } + + @Override + public List> call() throws Exception { + EVENT_LOGGER.debug("ITM-DcGatewayIp,REMOVE {}", ipAddress); + Collection meshedDpnList = dpnTEPsInfoCache.getAllPresent(); + return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, + tx -> ItmExternalTunnelDeleteWorker.deleteTunnels(meshedDpnList, + ipAddress, tunnelType, tx))); + } + + @Override + public String toString() { + return "DcGatewayIpRemoveWorker{ dcGatewayIp =" + ipAddress + '\'' + '}'; + } + } +} \ No newline at end of file diff --git a/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java b/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java index 208ae6d92..d63c8a565 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java @@ -450,11 +450,8 @@ public class ItmManagerRpcService implements ItmRpcService { RemoveExternalTunnelEndpointInput input) { //Ignore the Futures for now final SettableFuture> result = SettableFuture.create(); - Collection meshedDpnList = dpnTEPsInfoCache.getAllPresent(); FluentFuture future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> { - ItmExternalTunnelDeleteWorker.deleteTunnels(meshedDpnList, input.getDestinationIp(), - input.getTunnelType(), tx); InstanceIdentifier extPath = InstanceIdentifier.builder(DcGatewayIpList.class) .child(DcGatewayIp.class, new DcGatewayIpKey(input.getDestinationIp())).build(); tx.delete(extPath); @@ -538,7 +535,6 @@ public class ItmManagerRpcService implements ItmRpcService { //Ignore the Futures for now final SettableFuture> result = SettableFuture.create(); - Collection meshedDpnList = dpnTEPsInfoCache.getAllPresent(); InstanceIdentifier extPath = InstanceIdentifier.builder(DcGatewayIpList.class) .child(DcGatewayIp.class, new DcGatewayIpKey(input.getDestinationIp())).build(); DcGatewayIp dcGatewayIp = @@ -547,8 +543,6 @@ public class ItmManagerRpcService implements ItmRpcService { FluentFuture future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> { - externalTunnelAddWorker.buildTunnelsToExternalEndPoint(meshedDpnList, input.getDestinationIp(), - input.getTunnelType(), tx); tx.mergeParentStructurePut(extPath, dcGatewayIp); } ); diff --git a/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmManagerRpcServiceTest.java b/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmManagerRpcServiceTest.java index 2fac0cf52..7c178cc7f 100644 --- a/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmManagerRpcServiceTest.java +++ b/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmManagerRpcServiceTest.java @@ -27,6 +27,7 @@ import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule import org.opendaylight.genius.datastoreutils.testutils.TestableDataTreeChangeListenerModule; import org.opendaylight.genius.itm.impl.ItmUtils; import org.opendaylight.genius.itm.rpc.ItmManagerRpcService; +import org.opendaylight.genius.itm.tests.xtend.ExpectedDcGatewayIp; import org.opendaylight.genius.itm.tests.xtend.ExpectedDeviceVtepsObjects; import org.opendaylight.genius.itm.tests.xtend.ExpectedExternalTunnelObjects; import org.opendaylight.genius.itm.tests.xtend.ExpectedInternalTunnelIdentifierObjects; @@ -55,7 +56,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ext 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.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.dc.gateway.ip.list.DcGatewayIpKey; 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.TransportZoneBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey; @@ -142,6 +146,8 @@ public class ItmManagerRpcServiceTest { DeleteL2GwMlagDeviceInput deleteL2GwMlagDeviceInput; GetTunnelInterfaceNameInput getTunnelInterfaceNameInput; + InstanceIdentifier dcGatewayIpIdentifier = InstanceIdentifier.builder(DcGatewayIpList.class) + .child(DcGatewayIp.class, new DcGatewayIpKey(ItmTestConstants.IP_ADDRESS_3)).build(); InstanceIdentifier externalTunnelIdentifier = InstanceIdentifier.create(ExternalTunnelList.class) .child(ExternalTunnel.class, new ExternalTunnelKey(ItmTestConstants.IP_ADDRESS_3.stringValue(), ItmTestConstants.DP_ID_1.toString(), TunnelTypeMplsOverGre.class)); @@ -337,10 +343,10 @@ public class ItmManagerRpcServiceTest { // check RPC response is SUCCESS assertThat(rpcRes.get().isSuccessful()).isTrue(); - // check ExternalTunnelEndpoint is added in config DS - assertEqualBeans(ExpectedExternalTunnelObjects.newExternalTunnelForRpcTest(), + // check DCGatewayIp is added in config DS + assertEqualBeans(ExpectedDcGatewayIp.newDcGatewayIpForRpcTest(), dataBroker.newReadOnlyTransaction() - .read(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifierNew).get().get()); + .read(LogicalDatastoreType.CONFIGURATION, dcGatewayIpIdentifier).get().get()); } @Test diff --git a/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/xtend/ExpectedDcGatewayIpObjects.xtend b/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/xtend/ExpectedDcGatewayIpObjects.xtend new file mode 100644 index 000000000..b1034f107 --- /dev/null +++ b/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/xtend/ExpectedDcGatewayIpObjects.xtend @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.genius.itm.tests.xtend; + +import org.opendaylight.genius.itm.tests.ItmTestConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIpBuilder; + +import static extension org.opendaylight.mdsal.binding.testutils.XtendBuilderExtensions.operator_doubleGreaterThan + +class ExpectedDcGatewayIp { + + static def newDcGatewayIpForRpcTest() { + new DcGatewayIpBuilder >> [ + ipAddress = ItmTestConstants.IP_ADDRESS_3 + tunnnelType = ItmTestConstants.TUNNEL_TYPE_VXLAN + ] + } +} \ No newline at end of file -- 2.36.6