BGPCEP-758: Use random ip for Pcc mock tests 35/68235/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 14 Feb 2018 11:06:38 +0000 (12:06 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Wed, 14 Feb 2018 12:00:07 +0000 (12:00 +0000)
-perform some clean up

Change-Id: I79ef9f8e5f01b1d461c5848d7966f9e3521f926d
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/Main.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTunnelBuilder.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCsBuilder.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/protocol/PCCDispatcherImpl.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockTest.java

index 03d0bdac840c8f192da1ae9de5e45e743e033b0f..3f1ce826f5a30afd2fc27fa15d7327b0eeb7a66d 100755 (executable)
@@ -16,7 +16,6 @@ import com.google.common.net.InetAddresses;
 import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -48,7 +47,7 @@ public final class Main {
         throw new UnsupportedOperationException();
     }
 
-    public static void main(final String[] args) throws InterruptedException, ExecutionException, UnknownHostException {
+    public static void main(final String[] args) throws InterruptedException, ExecutionException {
         InetSocketAddress localAddress = new InetSocketAddress(LOCALHOST, DEFAULT_LOCAL_PORT);
         List<InetSocketAddress> remoteAddress = Collections
                 .singletonList(new InetSocketAddress(LOCALHOST, DEFAULT_REMOTE_PORT));
index 29e0c9ae82c8568e5b64f8c1e0d586f38f0a3c66..17e46a7b867b7e88ae90712786ae868d85f579ef 100644 (file)
@@ -13,7 +13,6 @@ import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createP
 import com.google.common.collect.Lists;
 import java.util.HashMap;
 import java.util.Map;
-import javax.annotation.Nonnull;
 import org.opendaylight.protocol.pcep.pcc.mock.api.LspType;
 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
@@ -25,16 +24,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
 
 final class PCCTunnelBuilder {
-    private static final Subobject DEFAULT_ENDPOINT_HOP = getDefaultEROEndpointHop();
+    static final int PCC_DELEGATION = -1;
     private static final String ENDPOINT_ADDRESS = "1.1.1.1";
     private static final String ENDPOINT_PREFIX = ENDPOINT_ADDRESS + "/32";
-    static final int PCC_DELEGATION = -1;
+    private static final Subobject DEFAULT_ENDPOINT_HOP = getDefaultEROEndpointHop();
 
     private PCCTunnelBuilder() {
         throw new UnsupportedOperationException();
     }
 
-    @Nonnull
     static Map<PlspId, PCCTunnel> createTunnels(final String address, final int lsps) {
         final Map<PlspId, PCCTunnel> tunnels = new HashMap<>();
         for (int i = 1; i <= lsps; i++) {
@@ -49,7 +47,7 @@ final class PCCTunnelBuilder {
         final SubobjectBuilder builder = new SubobjectBuilder();
         builder.setLoose(false);
         builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(
-            new IpPrefix(new Ipv4Prefix(ENDPOINT_PREFIX))).build()).build());
+                new IpPrefix(new Ipv4Prefix(ENDPOINT_PREFIX))).build()).build());
         return builder.build();
     }
 }
index 1951ddca9ebf0cfeb6d9e35308895d2eef65bcd0..e93f54bd12c8000a2a8a8a46bcb3d989257031cc 100644 (file)
@@ -17,7 +17,6 @@ import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.protocol.concepts.KeyMapping;
@@ -70,8 +69,7 @@ final class PCCsBuilder {
         startActivators();
     }
 
-    void createPCCs(final BigInteger initialDBVersion, final Optional<TimerHandler> timerHandler)
-        throws InterruptedException, ExecutionException {
+    void createPCCs(final BigInteger initialDBVersion, final Optional<TimerHandler> timerHandler) {
         InetAddress currentAddress = this.localAddress.getAddress();
         this.pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance()
                 .getMessageHandlerRegistry());
@@ -88,8 +86,7 @@ final class PCCsBuilder {
     }
 
     private void createPCC(@Nonnull final InetSocketAddress plocalAddress,
-            final PCCTunnelManager tunnelManager, final BigInteger initialDBVersion)
-            throws InterruptedException, ExecutionException {
+            final PCCTunnelManager tunnelManager, final BigInteger initialDBVersion) {
         final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf = getSessionNegotiatorFactory();
         for (final InetSocketAddress pceAddress : this.remoteAddress) {
             this.pccDispatcher.createClient(pceAddress, this.reconnectTime, () -> new PCCSessionListener(
index 969a45b896f318edd1159ab31944aca3c86cde63..4c20c71ea1b5a619ee3eb183352193ce7750f3d4 100755 (executable)
@@ -83,7 +83,7 @@ public final class PCCDispatcherImpl implements PCCDispatcher, AutoCloseable {
                 new PCCReconnectPromise(remoteAddress, (int) retryTimer, CONNECT_TIMEOUT, b);
         final ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
             @Override
-            protected void initChannel(final SocketChannel ch) throws Exception {
+            protected void initChannel(final SocketChannel ch) {
                 ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getDecoders());
                 ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(
                         new PCEPSessionNegotiatorFactoryDependencies() {
@@ -100,7 +100,7 @@ public final class PCCDispatcherImpl implements PCCDispatcher, AutoCloseable {
                 ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getEncoders());
                 ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                     @Override
-                    public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
+                    public void channelInactive(final ChannelHandlerContext ctx) {
                         if (promise.isCancelled()) {
                             return;
                         }
index 8da18d8d43054e504105834808207fb0c44aadc9..f8773474fc0aa708a01dd8a2555031b3de396ec7 100644 (file)
@@ -68,7 +68,8 @@ public abstract class PCCMockCommon {
     private final int port = InetSocketAddressUtil.getRandomPort();
     final InetSocketAddress remoteAddress = InetSocketAddressUtil
             .getRandomLoopbackInetSocketAddress(this.port);
-    final InetSocketAddress localAddress = new InetSocketAddress("127.0.0.1", this.port);
+    final InetSocketAddress localAddress = InetSocketAddressUtil
+            .getRandomLoopbackInetSocketAddress(this.port);
     PCCSessionListener pccSessionListener;
     private PCEPDispatcher pceDispatcher;
     private PCEPExtensionProviderContext extensionProvider;
index 1498a70b54f21bb8375b369b0a5506d1ac42cd41..02884424199f3e8ac3cbf0a685a095a976e2c6d3 100644 (file)
@@ -17,7 +17,9 @@ import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public final class PCCMockTest extends PCCMockCommon {
-    private final String[] mainInput = new String[]{"--local-address", this.localAddress.getHostString(),
+    private final String localAddress2 = "127.0.0.2";
+    private final String localIpAddress = "127.0.0.1";
+    private final String[] mainInput = new String[]{"--local-address", localIpAddress,
         "--remote-address", InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1",
         "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
         "--redelegation-timeout", "0", "--state-timeout", "-1"};
@@ -31,14 +33,13 @@ public final class PCCMockTest extends PCCMockCommon {
         //3 reported LSPs + syc
         final int numMessages = 4;
         final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory,
-                this.localAddress.getHostString());
+                this.localIpAddress);
         checkSession(sessionListener.getSession(), 40, 10);
     }
 
 
     @Test
     public void testMockPCCToManyPCE() throws Exception {
-        final String localAddress2 = "127.0.0.2";
         final InetSocketAddress serverAddress2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final InetSocketAddress serverAddress3 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final InetSocketAddress serverAddress4 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
@@ -50,22 +51,21 @@ public final class PCCMockTest extends PCCMockCommon {
         final Channel channel2 = createServer(factory2, serverAddress3);
         final Channel channel3 = createServer(factory3, serverAddress4);
 
-        Main.main(new String[]{"--local-address", this.localAddress.getHostString(), "--remote-address",
-            InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + ","
-                + InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + ","
-                + InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(),
-            "--pcc", "2"});
+        Main.main(new String[]{"--local-address", this.localIpAddress, "--remote-address",
+                InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + ","
+                        + InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + ","
+                        + InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(), "--pcc", "2"});
         Thread.sleep(1000);
         //PCE1
         final int numMessages = 2;
-        checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
-        checkSessionListener(numMessages, channel, factory, localAddress2);
+        checkSessionListener(numMessages, channel, factory, this.localIpAddress);
+        checkSessionListener(numMessages, channel, factory, this.localAddress2);
         //PCE2
-        checkSessionListener(numMessages, channel2, factory2, this.localAddress.getHostString());
-        checkSessionListener(numMessages, channel2, factory2, localAddress2);
+        checkSessionListener(numMessages, channel2, factory2, this.localIpAddress);
+        checkSessionListener(numMessages, channel2, factory2, this.localAddress2);
         //PCE3
-        checkSessionListener(numMessages, channel3, factory3, this.localAddress.getHostString());
-        checkSessionListener(numMessages, channel3, factory3, localAddress2);
+        checkSessionListener(numMessages, channel3, factory3, this.localIpAddress);
+        checkSessionListener(numMessages, channel3, factory3, this.localAddress2);
     }
 
     @Override