Provide API support for External tunnels 28/91328/6
authorNishchya Gupta <nishchyag@altencalsoftlabs.com>
Wed, 15 Jul 2020 07:41:06 +0000 (13:11 +0530)
committerHema Gopalakrishnan <hema.gopalkrishnan@ericsson.com>
Wed, 2 Sep 2020 08:55:28 +0000 (08:55 +0000)
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 <nishchyag@altencalsoftlabs.com>
Change-Id: I20d94c442b4643d7cd5b145f90d9f52f246b7367

itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/DcGatewayIpListener.java [new file with mode: 0644]
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmManagerRpcServiceTest.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/xtend/ExpectedDcGatewayIpObjects.xtend [new file with mode: 0644]

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 (file)
index 0000000..4382bd1
--- /dev/null
@@ -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<DcGatewayIp> {
+    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<List<? extends ListenableFuture<?>>> {
+        private final IpAddress ipAddress;
+        private final Class<? extends TunnelTypeBase> tunnelType;
+
+        DcGatewayIpAddWorker(IpAddress ipAddress, Class<? extends TunnelTypeBase> tunnelType) {
+            this.ipAddress = ipAddress;
+            this.tunnelType = tunnelType;
+        }
+
+        @Override
+        public List<ListenableFuture<?>> call() throws Exception {
+            EVENT_LOGGER.debug("ITM-DcGatewayIp,ADD {}", ipAddress);
+            Collection<DPNTEPsInfo> 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<List<? extends ListenableFuture<?>>> {
+        private final IpAddress ipAddress;
+        private final Class<? extends TunnelTypeBase> tunnelType;
+
+        DcGatewayIpRemoveWorker(IpAddress ipAddress, Class<? extends TunnelTypeBase> tunnelType) {
+            this.ipAddress = ipAddress;
+            this.tunnelType = tunnelType;
+        }
+
+        @Override
+        public List<ListenableFuture<?>> call() throws Exception {
+            EVENT_LOGGER.debug("ITM-DcGatewayIp,REMOVE {}", ipAddress);
+            Collection<DPNTEPsInfo> 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
index 208ae6d9235ecade5fb135459aa61566b9902a6a..d63c8a565408abce2f86dc7378acee9bcb86d85c 100644 (file)
@@ -450,11 +450,8 @@ public class ItmManagerRpcService implements ItmRpcService {
             RemoveExternalTunnelEndpointInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<RemoveExternalTunnelEndpointOutput>> result = SettableFuture.create();
-        Collection<DPNTEPsInfo> meshedDpnList = dpnTEPsInfoCache.getAllPresent();
         FluentFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
             tx -> {
-                ItmExternalTunnelDeleteWorker.deleteTunnels(meshedDpnList, input.getDestinationIp(),
-                        input.getTunnelType(), tx);
                 InstanceIdentifier<DcGatewayIp> 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<RpcResult<AddExternalTunnelEndpointOutput>> result = SettableFuture.create();
-        Collection<DPNTEPsInfo> meshedDpnList = dpnTEPsInfoCache.getAllPresent();
         InstanceIdentifier<DcGatewayIp> 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);
             }
         );
index 2fac0cf520bb36f7a91f5bad5d9afd06799a78b1..7c178cc7f9be160d5f2ef528064b0022b55f75c1 100644 (file)
@@ -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<DcGatewayIp> dcGatewayIpIdentifier = InstanceIdentifier.builder(DcGatewayIpList.class)
+            .child(DcGatewayIp.class, new DcGatewayIpKey(ItmTestConstants.IP_ADDRESS_3)).build();
     InstanceIdentifier<ExternalTunnel> 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 (file)
index 0000000..b1034f1
--- /dev/null
@@ -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