BGPCEP-685: Add Peer Release session rpc 28/65028/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 27 Oct 2017 12:45:46 +0000 (14:45 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 6 Nov 2017 07:01:07 +0000 (08:01 +0100)
old reset session rpc has been removed by
removal of cfg models. Therefore create a new
rpc providing the same service.
Change-Id: If17936e78642b5718126e79b6c197209af5ed268
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/rib-api/src/main/yang/bgp-peer-rpc.yang
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BgpPeerRpc.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BgpPeerRpcTest.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/BGPSessionListener.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerRPCs.java [new file with mode: 0644]

index 5a0d6a1679ab973c5eca4c26e9409c93a1fb5d03..22d450ced9faf785bbe8342887186275312a112a 100644 (file)
@@ -23,6 +23,10 @@ module bgp-peer-rpc {
         description "Initial revision";
     }
 
+    revision 2017-10-27 {
+        description "Add reset session RPC";
+    }
+
     identity peer-context {
         description "Identity used to mark the Peer context for binding RPCs in a particular RIB.";
     }
@@ -54,4 +58,11 @@ module bgp-peer-rpc {
     augment "/rib:bgp-rib/rib:rib/rib:peer" {
         ext:context-instance "peer-context";
     }
+
+    rpc release-connection {
+        description "Release the peer session";
+        input {
+            uses peer-reference;
+        }
+    }
 }
\ No newline at end of file
index a131ec00d87604dcd6b235213492d55d516d46bb..3c091107c7206a7ffa4636f0ae13ab74070fafd9 100644 (file)
@@ -84,8 +84,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.BgpPeerRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.PeerContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.BgpPeerRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.PeerContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.SimpleRoutingPolicy;
@@ -355,7 +355,8 @@ public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Pee
         }
 
         if (this.rpcRegistry != null) {
-            this.rpcRegistration = this.rpcRegistry.addRoutedRpcImplementation(BgpPeerRpcService.class, new BgpPeerRpc(session, this.tables));
+            this.rpcRegistration = this.rpcRegistry.addRoutedRpcImplementation(BgpPeerRpcService.class,
+                    new BgpPeerRpc(this, session, this.tables));
             final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer, PeerKey> path =
                     this.rib.getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer.class, new PeerKey(peerId));
             this.rpcRegistration.registerPath(PeerContext.class, path);
index c4309be5ac82d72f95edf06606163c9927b8c1cd..121b1dbc2a562b6c77a72704b7bc533117d5655f 100644 (file)
@@ -11,15 +11,18 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.channel.ChannelFuture;
 import java.util.Set;
 import java.util.concurrent.Future;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
+import org.opendaylight.protocol.bgp.rib.spi.PeerRPCs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefreshBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.BgpPeerRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.RouteRefreshRequestInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.BgpPeerRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.ReleaseConnectionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.RouteRefreshRequestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -31,15 +34,29 @@ public class BgpPeerRpc implements BgpPeerRpcService {
 
     private static final Logger LOG = LoggerFactory.getLogger(BgpPeerRpc.class);
     private static final String FAILURE_MSG = "Failed to send Route Refresh message";
+    private static final String FAILURE_RESET_SESSION_MSG = "Failed to reset session";
 
     private final BGPSession session;
     private final Set<TablesKey> supportedFamilies;
+    private final PeerRPCs peerRPCs;
 
-    BgpPeerRpc(final BGPSession session, final Set<TablesKey> supportedFamilies) {
+    BgpPeerRpc(final PeerRPCs peerRPCs, final BGPSession session, final Set<TablesKey> supportedFamilies) {
         this.session = requireNonNull(session);
+        this.peerRPCs = requireNonNull(peerRPCs);
         this.supportedFamilies = requireNonNull(supportedFamilies);
     }
 
+    @Override
+    public Future<RpcResult<Void>> releaseConnection(final ReleaseConnectionInput input) {
+        final ListenableFuture<?> f = this.peerRPCs.releaseConnection();
+        return Futures.transform(JdkFutureAdapters.listenInPoolThread(f), input1 -> {
+            if (f.isDone()) {
+                return RpcResultBuilder.<Void>success().build();
+            }
+            return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_RESET_SESSION_MSG).build();
+        }, MoreExecutors.directExecutor());
+    }
+
     @Override
     public Future<RpcResult<Void>> routeRefreshRequest(final RouteRefreshRequestInput input) {
         final ChannelFuture f = sendRRMessage(input);
@@ -51,7 +68,8 @@ public class BgpPeerRpc implements BgpPeerRpcService {
                 return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG).build();
             }, MoreExecutors.directExecutor());
         }
-        return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG + " due to unsupported address families.").buildFuture();
+        return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG +
+                " due to unsupported address families.").buildFuture();
     }
 
     private ChannelFuture sendRRMessage(final RouteRefreshRequestInput input) {
index a7ad6bcc1202afcfa8f7a14bfa537c4c2bfb5e46..d7eaed37da81a759d9b898b73c5fbb80b239e879 100644 (file)
@@ -9,17 +9,23 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+
+import com.google.common.util.concurrent.Futures;
 import io.netty.channel.ChannelFuture;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Collections;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.PeerRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.RouteRefreshRequestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.RouteRefreshRequestInputBuilder;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.protocol.bgp.rib.spi.PeerRPCs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.PeerRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.ReleaseConnectionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.ReleaseConnectionInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.RouteRefreshRequestInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev171027.RouteRefreshRequestInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
@@ -27,21 +33,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-public class BgpPeerRpcTest {
-
-    private final Set<TablesKey> supportedFamilies = new HashSet<>();
-    private final BGPSessionImpl session = Mockito.mock(BGPSessionImpl.class);
-    private final BgpPeerRpc rpc = new BgpPeerRpc(this.session, this.supportedFamilies);
-    private final PeerRef peer = Mockito.mock(PeerRef.class);
-
-    private final ChannelOutputLimiter limiter = new ChannelOutputLimiter(this.session);
-    private final ChannelFuture future = Mockito.mock(ChannelFuture.class);
+public final class BgpPeerRpcTest {
+    @Mock
+    private BGPSessionImpl session;
+    @Mock
+    private PeerRPCs peerRpcs;
+    @Mock
+    private PeerRef peer;
+    @Mock
+    private ChannelFuture future;
+    private BgpPeerRpc rpc;
 
     @Before
     public void setUp() throws InterruptedException, ExecutionException {
-        this.supportedFamilies.add(new TablesKey(Ipv4AddressFamily.class, SubsequentAddressFamily.class));
+        MockitoAnnotations.initMocks(this);
+        this.rpc = new BgpPeerRpc(this.peerRpcs, this.session,
+                Collections.singleton(new TablesKey(Ipv4AddressFamily.class, SubsequentAddressFamily.class)));
+        final ChannelOutputLimiter limiter = new ChannelOutputLimiter(this.session);
 
-        Mockito.doReturn(this.limiter).when(this.session).getLimiter();
+        Mockito.doReturn(limiter).when(this.session).getLimiter();
         Mockito.doReturn(this.future).when(this.session).writeAndFlush(Mockito.any(Notification.class));
         Mockito.doReturn(true).when(this.future).isDone();
         Mockito.doReturn(null).when(this.future).get();
@@ -49,23 +59,33 @@ public class BgpPeerRpcTest {
     }
 
     @Test
-    public void testSuccessRequest() throws InterruptedException, ExecutionException {
+    public void testRouteRefreshRequestSuccessRequest() throws InterruptedException, ExecutionException {
         final RouteRefreshRequestInput input = new RouteRefreshRequestInputBuilder()
-            .setAfi(Ipv4AddressFamily.class)
-            .setSafi(SubsequentAddressFamily.class)
-            .setPeerRef(this.peer).build();
+                .setAfi(Ipv4AddressFamily.class)
+                .setSafi(SubsequentAddressFamily.class)
+                .setPeerRef(this.peer).build();
         final Future<RpcResult<Void>> result = this.rpc.routeRefreshRequest(input);
         assertTrue(result.get().getErrors().isEmpty());
     }
 
     @Test
-    public void testFailedRequest() throws InterruptedException, ExecutionException {
+    public void testRouteRefreshRequestFailedRequest() throws InterruptedException, ExecutionException {
         final RouteRefreshRequestInput input = new RouteRefreshRequestInputBuilder()
-            .setAfi(Ipv6AddressFamily.class)
-            .setSafi(SubsequentAddressFamily.class)
-            .setPeerRef(this.peer).build();
+                .setAfi(Ipv6AddressFamily.class)
+                .setSafi(SubsequentAddressFamily.class)
+                .setPeerRef(this.peer).build();
         final Future<RpcResult<Void>> result = this.rpc.routeRefreshRequest(input);
         assertEquals(1, result.get().getErrors().size());
-        assertEquals("Failed to send Route Refresh message due to unsupported address families.", result.get().getErrors().iterator().next().getMessage());
+        assertEquals("Failed to send Route Refresh message due to unsupported address families.",
+                result.get().getErrors().iterator().next().getMessage());
+    }
+
+    @Test
+    public void testResetSessionRequestSuccessRequest() throws InterruptedException, ExecutionException {
+        Mockito.doReturn(Futures.immediateFuture(null)).when(this.peerRpcs).releaseConnection();
+        final ReleaseConnectionInput input = new ReleaseConnectionInputBuilder()
+                .setPeerRef(this.peer).build();
+        final Future<RpcResult<Void>> result = this.rpc.releaseConnection(input);
+        assertTrue(result.get().getErrors().isEmpty());
     }
 }
index 4b30eee531cf9dd5fc1d061b7bd8ae184b473131..7d984c20c34d21de6c1104b5d6500dca19a93e11 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.bgp.rib.spi;
 
-import com.google.common.util.concurrent.ListenableFuture;
 import java.util.EventListener;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
@@ -16,7 +15,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 /**
  * Listener that receives session informations from the session.
  */
-public interface BGPSessionListener extends EventListener {
+public interface BGPSessionListener extends PeerRPCs, EventListener {
 
     /**
      * Marks synchronization finished for given Table key
@@ -54,6 +53,4 @@ public interface BGPSessionListener extends EventListener {
      * @param notification Protocol message
      */
     void onMessage(BGPSession session, Notification notification) throws BGPDocumentedException;
-
-    ListenableFuture<?> releaseConnection();
 }
diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerRPCs.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/PeerRPCs.java
new file mode 100644 (file)
index 0000000..d1a6767
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. 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.protocol.bgp.rib.spi;
+
+import com.google.common.util.concurrent.ListenableFuture;
+
+/**
+ * Contains all Peer RPC methods related.
+ */
+public interface PeerRPCs {
+    /**
+     * Release Peer session
+     */
+    ListenableFuture<?> releaseConnection();
+}