BUG-5619 Enable maven parallel build for bgpcep I 03/43003/7
authorKevin Wang <kevixw@gmail.com>
Tue, 2 Aug 2016 23:08:37 +0000 (16:08 -0700)
committerKevin Wang <kevixw@gmail.com>
Tue, 9 Aug 2016 18:31:36 +0000 (11:31 -0700)
- This patch mainly change the unit test to use random
  IP address and port whenever initializing a client or
  server for testing

Change-Id: I101706aded57f435c80285728f4212cfe0b5669b
Signed-off-by: Kevin Wang <kevixw@gmail.com>
27 files changed:
bgp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockDispatcherTest.java
bgp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockSessionTest.java
bgp/bmp-mock/src/test/java/org/opendaylight/protocol/bmp/mock/BmpMockTest.java
bgp/rib-impl/pom.xml
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/TestClientDispatcher.java
pcep/impl/pom.xml
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImplTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImplTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCDispatcherImplTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCIncrementalSyncTest.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
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSyncAvoidanceProcedureTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTriggeredFullDBResyncTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTriggeredLspResyncTest.java
pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCTriggeredSyncTest.java
pcep/segment-routing/pom.xml
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractPCEPSessionTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTriggeredReSynchronizationProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListenerTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgrammingTest.java
testtool-util/src/main/java/org/opendaylight/protocol/util/InetSocketAddressUtil.java
testtool-util/src/test/java/org/opendaylight/protocol/util/InetSocketAddressUtilTest.java

index e2813fe6240028cc63306d0e2fd029f098857dc7..5e960b4f99a30146ea83a751784fe6eafe41df4a 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory;
 import org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl;
 import org.opendaylight.protocol.bmp.spi.registry.BmpMessageRegistry;
 import org.opendaylight.protocol.concepts.KeyMapping;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public class BmpMockDispatcherTest {
 
@@ -34,13 +35,14 @@ public class BmpMockDispatcherTest {
     @Test
     public void testCreateClient() throws InterruptedException {
         final BmpMockDispatcher dispatcher = new BmpMockDispatcher(this.registry, this.sessionFactory);
-        final int port = getRandomPort();
+        final int port = InetSocketAddressUtil.getRandomPort();
+        final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
         final BmpDispatcherImpl serverDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
             this.registry, this.sessionFactory);
-        final ChannelFuture futureServer = serverDispatcher.createServer(new InetSocketAddress(InetAddresses.forString("0.0.0.0"), port), this.slf, Optional.<KeyMapping>absent());
+        final ChannelFuture futureServer = serverDispatcher.createServer(serverAddr, this.slf, Optional.<KeyMapping>absent());
         waitFutureSuccess(futureServer);
-        final ChannelFuture channelFuture = dispatcher.createClient(new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 0),
-            new InetSocketAddress(InetAddresses.forString("127.0.0.3"), port));
+        final ChannelFuture channelFuture = dispatcher.createClient(InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0),
+            serverAddr);
         waitFutureSuccess(channelFuture);
         final Channel channel = channelFuture.sync().channel();
 
@@ -52,12 +54,12 @@ public class BmpMockDispatcherTest {
     @Test
     public void testCreateServer() throws InterruptedException {
         final BmpMockDispatcher dispatcher = new BmpMockDispatcher(this.registry, this.sessionFactory);
-        final int port = getRandomPort();
+        final int port = InetSocketAddressUtil.getRandomPort();
         final BmpDispatcherImpl serverDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
             this.registry, this.sessionFactory);
         final ChannelFuture futureServer = dispatcher.createServer(new InetSocketAddress(InetAddresses.forString("0.0.0.0"), port));
         waitFutureSuccess(futureServer);
-        final ChannelFuture channelFuture = serverDispatcher.createClient(new InetSocketAddress(InetAddresses.forString("127.0.0.3"), port), this.slf, Optional.<KeyMapping>absent());
+        final ChannelFuture channelFuture = serverDispatcher.createClient(InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port), this.slf, Optional.<KeyMapping>absent());
         waitFutureSuccess(channelFuture);
         final Channel channel = channelFuture.sync().channel();
 
@@ -66,8 +68,4 @@ public class BmpMockDispatcherTest {
         serverDispatcher.close();
     }
 
-    protected static int getRandomPort() {
-        return (int) (Math.random() * 64000 + 1024);
-    }
-
 }
index cd7896470523ba0a5b9ac40fb492b57f48f2f31d..5e6d42559aeb4d63286ceb7a597ad5a567c5e782 100644 (file)
@@ -26,6 +26,7 @@ import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.InitiationMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerUp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.RouteMonitoringMessage;
@@ -33,8 +34,8 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 
 public class BmpMockSessionTest {
 
-    private static final InetSocketAddress REMOTE_ADDRESS = new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 0);
-    private static final InetSocketAddress LOCAL_ADDRESS = new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 0);
+    private static final InetSocketAddress REMOTE_ADDRESS = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
+    private static final InetSocketAddress LOCAL_ADDRESS = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
 
     private ChannelHandlerContext context;
     private Channel channel;
index f127d41c9e1ac543bf021ba9833d25e5417892b6..e4013974324c146a98e10b4f180990182d90d90b 100644 (file)
@@ -32,12 +32,12 @@ import org.opendaylight.protocol.bmp.spi.registry.BmpExtensionProviderActivator;
 import org.opendaylight.protocol.bmp.spi.registry.BmpExtensionProviderContext;
 import org.opendaylight.protocol.bmp.spi.registry.SimpleBmpExtensionProviderContext;
 import org.opendaylight.protocol.concepts.KeyMapping;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 public class BmpMockTest {
 
     private final BmpSessionListener sessionListener = Mockito.mock(BmpSessionListener.class);
-    private int serverPort;
     private BmpExtensionProviderActivator bmpActivator;
     private BmpDispatcher bmpDispatcher;
 
@@ -49,7 +49,6 @@ public class BmpMockTest {
         this.bmpActivator.start(ctx);
         this.bmpDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx.getBmpMessageRegistry(),
             new DefaultBmpSessionFactory());
-        this.serverPort = BmpMockDispatcherTest.getRandomPort();
     }
 
     @After
@@ -60,13 +59,14 @@ public class BmpMockTest {
 
     @Test
     public void testMain() throws Exception {
+        final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
-        final ChannelFuture futureServer = bmpDispatcher.createServer(new InetSocketAddress("127.0.0.1", serverPort),
+        final ChannelFuture futureServer = bmpDispatcher.createServer(serverAddr,
             bmpSessionListenerFactory, Optional.<KeyMapping>absent());
         waitFutureSuccess(futureServer);
         Channel serverChannel = futureServer.channel();
 
-        BmpMock.main(new String[]{"--remote_address", "127.0.0.1:" + serverPort, "--peers_count", "3", "--pre_policy_routes", "3"});
+        BmpMock.main(new String[]{"--remote_address", InetSocketAddressUtil.toHostAndPort(serverAddr).toString(), "--peers_count", "3", "--pre_policy_routes", "3"});
         Thread.sleep(1000);
         Mockito.verify(this.sessionListener).onSessionUp(Mockito.any(BmpSession.class));
         //1 * Initiate message + 3 * PeerUp Notification + 9 * Route Monitoring message
@@ -77,11 +77,13 @@ public class BmpMockTest {
 
     @Test
     public void testMainInPassiveMode() throws Exception {
+        final InetSocketAddress serverAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final BmpSessionListenerFactory bmpSessionListenerFactory = () -> BmpMockTest.this.sessionListener;
 
         // create a local server in passive mode instead
-        BmpMock.main(new String[]{"--local_address", "127.0.0.1:" + serverPort, "--peers_count", "3", "--pre_policy_routes", "3", "--passive"});
-        final ChannelFuture futureServer = bmpDispatcher.createClient(new InetSocketAddress("127.0.0.1", serverPort),
+        BmpMock.main(new String[]{"--local_address", InetSocketAddressUtil.toHostAndPort(serverAddr).toString(),
+            "--peers_count", "3", "--pre_policy_routes", "3", "--passive"});
+        final ChannelFuture futureServer = bmpDispatcher.createClient(serverAddr,
             bmpSessionListenerFactory, Optional.<KeyMapping>absent());
         waitFutureSuccess(futureServer);
         Channel serverChannel = futureServer.channel();
index b013afd0d1a0d815918fe8ab7564fdf93a3304a8..83d8c87590305145091d8288dacf5bda5316ab2e 100644 (file)
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>com.google.code.findbugs</groupId>
             <artifactId>jsr305</artifactId>
index 0d836f1a5a600ad6b5a875a52a88a20059926ad7..96e80dc542715a7b25677aaccf1ddc4636fa4832 100755 (executable)
@@ -38,6 +38,7 @@ import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
@@ -105,7 +106,7 @@ public class BGPDispatcherImplTest {
     }
 
     private void configureClient(final BGPExtensionProviderContext ctx) {
-        final InetSocketAddress clientAddress = new InetSocketAddress("127.0.11.0", 1791);
+        final InetSocketAddress clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
         this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
         this.clientDispatcher = new TestClientDispatcher(this.boss, this.worker, ctx.getMessageRegistry(), clientAddress);
@@ -136,7 +137,7 @@ public class BGPDispatcherImplTest {
 
     @Test
     public void testCreateClient() throws InterruptedException, ExecutionException {
-        final InetSocketAddress serverAddress = new InetSocketAddress("127.0.10.0", 1790);
+        final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final Channel serverChannel = createServer(serverAddress);
         Thread.sleep(1000);
         final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(serverAddress, this.registry, 2, Optional.absent());
@@ -155,7 +156,7 @@ public class BGPDispatcherImplTest {
 
     @Test
     public void testCreateReconnectingClient() throws Exception {
-        final InetSocketAddress serverAddress = new InetSocketAddress("127.0.20.0", 1792);
+        final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, this.registry, RETRY_TIMER, Optional.absent());
         waitFutureSuccess(future);
         final Channel serverChannel = createServer(serverAddress);
index 0e294f0815fe383c3d3df73cb81c434efb6f1860..715fd6d2749293c6d2c69d5b3abe38b0fe6b34a6 100755 (executable)
@@ -24,12 +24,12 @@ import org.opendaylight.protocol.concepts.KeyMapping;
 public class TestClientDispatcher {
 
     private final BGPHandlerFactory hf;
-    private final InetSocketAddress defaulAddress;
+    private final InetSocketAddress defaultAddress;
     private InetSocketAddress localAddress;
     private final BGPDispatcherImpl disp;
 
     protected TestClientDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MessageRegistry messageRegistry,
-            final InetSocketAddress locaAddress) {
+            final InetSocketAddress localAddress) {
         this.disp = new BGPDispatcherImpl(messageRegistry, bossGroup, workerGroup) {
             @Override
             protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) {
@@ -46,14 +46,14 @@ public class TestClientDispatcher {
                 if (bootstrap.group() == null) {
                     bootstrap.group(workerGroup);
                 }
-                bootstrap.localAddress(locaAddress);
+                bootstrap.localAddress(localAddress);
                 bootstrap.option(ChannelOption.SO_REUSEADDR, true);
                 return bootstrap;
             }
         };
         this.hf = new BGPHandlerFactory(messageRegistry);
-        this.localAddress = locaAddress;
-        this.defaulAddress = locaAddress;
+        this.localAddress = localAddress;
+        this.defaultAddress = localAddress;
     }
 
     public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress,
@@ -72,7 +72,7 @@ public class TestClientDispatcher {
         if (localAddress.isPresent()) {
             this.localAddress = localAddress.get();
         } else {
-            this.localAddress = this.defaulAddress;
+            this.localAddress = this.defaultAddress;
         }
     }
 }
index 9417b48c13bbf259014684dc6a445899ebb9c188..5c9bfd9899c69ef035dd72b13edf3d769346f76d 100644 (file)
             <groupId>${project.groupId}</groupId>
             <artifactId>util</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-buffer</artifactId>
index 9b78a5b9abe5233e054219833dabb3d9f8d69078..f42aca5f751e7da532709349d888e931f2337b0b 100644 (file)
@@ -31,6 +31,7 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open;
@@ -44,7 +45,6 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 
 public class AbstractPCEPSessionTest {
 
-    protected static final String IP_ADDRESS = "127.0.0.1";
     protected static final short KEEP_ALIVE = 15;
     protected static final short DEADTIMER = 40;
 
@@ -66,6 +66,8 @@ public class AbstractPCEPSessionTest {
     @Mock
     private SocketAddress address;
 
+    protected final String ipAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
+    protected final int port = InetSocketAddressUtil.getRandomPort();
     protected final List<Notification> msgsSend = Lists.newArrayList();
 
     protected Open openMsg;
@@ -101,8 +103,8 @@ public class AbstractPCEPSessionTest {
         doReturn(this.pipeline).when(this.pipeline).addFirst(any(ChannelHandler.class));
         doReturn(true).when(this.channel).isActive();
         doReturn(mock(ChannelFuture.class)).when(this.channel).close();
-        doReturn(new InetSocketAddress(IP_ADDRESS, 4189)).when(this.channel).remoteAddress();
-        doReturn(new InetSocketAddress(IP_ADDRESS, 4189)).when(this.channel).localAddress();
+        doReturn(new InetSocketAddress(ipAddress, port)).when(this.channel).remoteAddress();
+        doReturn(new InetSocketAddress(ipAddress, port)).when(this.channel).localAddress();
         this.openMsg = new OpenBuilder().setOpenMessage(
                 new OpenMessageBuilder().setOpen(
                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setDeadTimer(
index 0c1f69836df36cbc14e993b3d0e5c50f84c57f7e..7eb1a68d61efc1d1049a6098547bafefe72a4fde 100755 (executable)
@@ -44,12 +44,9 @@ import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl.ChannelPipelineInitializer;
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public class PCEPDispatcherImplTest {
-
-    private static final int PORT = 4189;
-    private static final InetSocketAddress CLIENT1_ADDRESS = new InetSocketAddress("127.0.0.10", PORT);
-    private static final InetSocketAddress CLIENT2_ADDRESS = new InetSocketAddress("127.0.0.11", PORT);
     private static final short DEAD_TIMER = 120;
     private static final short KEEP_ALIVE = 30;
     private static final int RETRY_TIMER = 0;
@@ -89,22 +86,26 @@ public class PCEPDispatcherImplTest {
 
     @Test
     public void testCreateClientServer() throws InterruptedException, ExecutionException {
-        final ChannelFuture futureChannel = this.dispatcher.createServer(new InetSocketAddress("0.0.0.0", PORT),
+        final int port = InetSocketAddressUtil.getRandomPort();
+        final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
+        final InetSocketAddress clientAddr1 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+        final InetSocketAddress clientAddr2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+        final ChannelFuture futureChannel = this.dispatcher.createServer(serverAddr,
                 () -> new SimpleSessionListener(), null);
-        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(CLIENT1_ADDRESS,
+        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr1,
                 RETRY_TIMER, CONNECT_TIMEOUT,
                 () -> new SimpleSessionListener()).get();
 
-        final PCEPSessionImpl session2 = (PCEPSessionImpl) this.pccMock.createClient(CLIENT2_ADDRESS,
+        final PCEPSessionImpl session2 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr2,
                 RETRY_TIMER, CONNECT_TIMEOUT,
                 () -> new SimpleSessionListener()).get();
 
         Assert.assertTrue(futureChannel.channel().isActive());
-        Assert.assertEquals(CLIENT1_ADDRESS.getAddress().getHostAddress(), session1.getPeerPref().getIpAddress());
+        Assert.assertEquals(clientAddr1.getAddress().getHostAddress(), session1.getPeerPref().getIpAddress());
         Assert.assertEquals(DEAD_TIMER, session1.getDeadTimerValue().shortValue());
         Assert.assertEquals(KEEP_ALIVE, session1.getKeepAliveTimerValue().shortValue());
 
-        Assert.assertEquals(CLIENT2_ADDRESS.getAddress().getHostAddress(), session2.getPeerPref().getIpAddress());
+        Assert.assertEquals(clientAddr2.getAddress().getHostAddress(), session2.getPeerPref().getIpAddress());
         Assert.assertEquals(DEAD_TIMER, session2.getDeadTimerValue().shortValue());
         Assert.assertEquals(KEEP_ALIVE, session2.getKeepAliveTimerValue().shortValue());
 
@@ -115,14 +116,18 @@ public class PCEPDispatcherImplTest {
 
     @Test
     public void testCreateDuplicateClient() throws InterruptedException, ExecutionException {
-        this.dispatcher.createServer(new InetSocketAddress("0.0.0.0", PORT),
+        final int port = InetSocketAddressUtil.getRandomPort();
+        final InetSocketAddress serverAddr = new InetSocketAddress("0.0.0.0", port);
+        final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+        this.dispatcher.createServer(serverAddr,
                 () -> new SimpleSessionListener(), null);
-        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(CLIENT1_ADDRESS,
+        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT,
                 () -> new SimpleSessionListener()).get();
 
         try {
-            this.pccMock.createClient(CLIENT1_ADDRESS, RETRY_TIMER, CONNECT_TIMEOUT,
+            this.pccMock.createClient(clientAddr,
+                    RETRY_TIMER, CONNECT_TIMEOUT,
                     () -> new SimpleSessionListener()).get();
             Assert.fail();
         } catch (final ExecutionException e) {
@@ -134,22 +139,24 @@ public class PCEPDispatcherImplTest {
 
     @Test
     public void testReconectClient() throws InterruptedException, ExecutionException {
-        this.dispatcher.createServer(new InetSocketAddress("0.0.0.0", PORT),
+        final int port = InetSocketAddressUtil.getRandomPort();
+        final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+        this.dispatcher.createServer(new InetSocketAddress("0.0.0.0", port),
                 () -> new SimpleSessionListener(), null);
-        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(CLIENT1_ADDRESS,
+        final PCEPSessionImpl session1 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT,
                 () -> new SimpleSessionListener()).get();
 
-        Assert.assertEquals(CLIENT1_ADDRESS.getAddress(), session1.getRemoteAddress());
+        Assert.assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
         Assert.assertEquals(DEAD_TIMER, session1.getDeadTimerValue().shortValue());
         Assert.assertEquals(KEEP_ALIVE, session1.getKeepAliveTimerValue().shortValue());
         session1.close();
 
-        final PCEPSessionImpl session2 = (PCEPSessionImpl) this.pccMock.createClient(CLIENT1_ADDRESS,
+        final PCEPSessionImpl session2 = (PCEPSessionImpl) this.pccMock.createClient(clientAddr,
                 RETRY_TIMER, CONNECT_TIMEOUT,
                 () -> new SimpleSessionListener()).get();
 
-        Assert.assertEquals(CLIENT1_ADDRESS.getAddress(), session1.getRemoteAddress());
+        Assert.assertEquals(clientAddr.getAddress(), session1.getRemoteAddress());
         Assert.assertEquals(DEAD_TIMER, session2.getDeadTimerValue().shortValue());
         Assert.assertEquals(KEEP_ALIVE, session2.getKeepAliveTimerValue().shortValue());
 
@@ -158,10 +165,13 @@ public class PCEPDispatcherImplTest {
 
     @Test
     public void testCustomizeBootstrap() {
-        final KeyMapping keys = KeyMapping.getKeyMapping(CLIENT1_ADDRESS.getAddress(), new String("CLIENT1_ADDRESS"));
-        keys.put(CLIENT2_ADDRESS.getAddress(), new String("CLIENT2_ADDRESS").getBytes() );
+        final int port = InetSocketAddressUtil.getRandomPort();
+        final InetSocketAddress clientAddr1 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+        final InetSocketAddress clientAddr2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+        final KeyMapping keys = KeyMapping.getKeyMapping(clientAddr1.getAddress(), new String("CLIENT1_ADDRESS"));
+        keys.put(clientAddr2.getAddress(), new String("CLIENT2_ADDRESS").getBytes() );
 
-        final ChannelFuture futureChannel = this.disp2Spy.createServer(new InetSocketAddress("0.0.0.0", PORT),
+        final ChannelFuture futureChannel = this.disp2Spy.createServer(new InetSocketAddress("0.0.0.0", port),
                 () -> new SimpleSessionListener(), null);
         Mockito.verify(this.disp2Spy).createServerBootstrap(Mockito.any(PCEPDispatcherImpl.ChannelPipelineInitializer.class));
     }
index 3b1d63a3259e4a92155d79b65175d5e481f639d1..29677fd23bd51111bbe1962d8787b964a64becbe 100644 (file)
@@ -112,14 +112,14 @@ public class PCEPSessionImplTest extends AbstractPCEPSessionTest {
     @Test
     public void testSessionStatistics() {
         this.session.handleMessage(Util.createErrorMessage(PCEPErrors.LSP_RSVP_ERROR, null));
-        Assert.assertEquals(IP_ADDRESS, this.session.getPeerPref().getIpAddress());
+        Assert.assertEquals(ipAddress, this.session.getPeerPref().getIpAddress());
         final PeerPref peerPref = this.session.getPeerPref();
-        Assert.assertEquals(IP_ADDRESS, peerPref.getIpAddress());
+        Assert.assertEquals(ipAddress, peerPref.getIpAddress());
         Assert.assertEquals(DEADTIMER, peerPref.getDeadtimer().shortValue());
         Assert.assertEquals(KEEP_ALIVE, peerPref.getKeepalive().shortValue());
         Assert.assertEquals(0, peerPref.getSessionId().intValue());
         final LocalPref localPref = this.session.getLocalPref();
-        Assert.assertEquals(IP_ADDRESS, localPref.getIpAddress());
+        Assert.assertEquals(ipAddress, localPref.getIpAddress());
         Assert.assertEquals(DEADTIMER, localPref.getDeadtimer().shortValue());
         Assert.assertEquals(KEEP_ALIVE, localPref.getKeepalive().shortValue());
         Assert.assertEquals(0, localPref.getSessionId().intValue());
index fb8265ddcbcfa0a7b6b38a0621939363ae179753..1539456fb8457340277a3dbd4d19fa21db8b9684 100644 (file)
@@ -20,7 +20,6 @@ import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Random;
 import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.Assert;
@@ -37,13 +36,13 @@ import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public class PCCDispatcherImplTest {
 
     private static final List<PCEPCapability> CAPS = new ArrayList<>();
     private static final PCEPSessionProposalFactory PROPOSAL = new BasePCEPSessionProposalFactory(30, 120, CAPS);
     private final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(PROPOSAL, 0);
-    private final Random random = new Random();
     private PCCDispatcherImpl dispatcher;
     private PCEPDispatcher pcepDispatcher;
     private InetSocketAddress serverAddress;
@@ -58,8 +57,8 @@ public class PCCDispatcherImplTest {
         this.dispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry());
         this.pcepDispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(),
             this.nf, this.bossGroup, this.workerGroup);
-        this.serverAddress = new InetSocketAddress("127.0.5.0", getRandomPort());
-        this.clientAddress = new InetSocketAddress("127.0.4.0", getRandomPort());
+        this.serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
+        this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
     }
 
     @After
@@ -83,7 +82,7 @@ public class PCCDispatcherImplTest {
         waitFutureSuccess(futureServer);
         final Channel channel = futureServer.channel();
         Assert.assertNotNull(futureSession.get());
-        checkSessionListenerNotNull(slf, "127.0.4.0");
+        checkSessionListenerNotNull(slf, this.clientAddress.getHostString());
         final TestingSessionListener sl = checkSessionListenerNotNull(slf, this.clientAddress.getAddress().getHostAddress());
         Assert.assertNotNull(sl.getSession());
         Assert.assertTrue(sl.isUp());
@@ -103,8 +102,4 @@ public class PCCDispatcherImplTest {
         Assert.assertNotNull(sl2.getSession());
         Assert.assertTrue(sl2.isUp());
     }
-
-    private int getRandomPort() {
-        return this.random.nextInt(4000) + 1024;
-    }
 }
index ed0e6d1447e19a1d055199565e1a6be429df62c1..1fc61fda37da4e3873c64671de0752f864017b31 100644 (file)
@@ -21,6 +21,7 @@ import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCServerPeerProposal;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public class PCCIncrementalSyncTest extends PCCMockCommon {
 
@@ -30,15 +31,15 @@ public class PCCIncrementalSyncTest extends PCCMockCommon {
      * Create 8 lsp, then it disconnects after 5 sec and then after 5 sec reconnects with Pcc DBVersion 10
      * After reconnection PCE has DBVersion 10, therefore there is 9 changes missed. 9 Pcrt + 1 Pcrt-Sync
      */
-    private final String[] mainInputIncrementalSync = new String[]{"--local-address", PCCMockTest.LOCAL_ADDRESS, "--remote-address",
-        PCCMockTest.REMOTE_ADDRESS + ":4578", "--pcc", "1", "--lsp", lsp.toString(), "--log-level", "DEBUG", "-ka", "40", "-d", "120",
+    private final String[] mainInputIncrementalSync = new String[]{"--local-address", this.localAddress.getHostString(), "--remote-address",
+        InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1", "--lsp", lsp.toString(), "--log-level", "DEBUG", "-ka", "40", "-d", "120",
         "--reconnect", "-1", "--redelegation-timeout", "0", "--state-timeout", "-1", "--incremental-sync-procedure", "10", "5", "5"};
 
     @Test
     public void testSessionIncrementalSyncEstablishment() throws UnknownHostException, InterruptedException, ExecutionException {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(8);
-        final Channel channel = createServer(factory, socket, new PCCServerPeerProposal(numberOflspAndDBv));
+        final Channel channel = createServer(factory, this.remoteAddress, new PCCServerPeerProposal(numberOflspAndDBv));
         Main.main(mainInputIncrementalSync);
         Thread.sleep(1000);
         final TestingSessionListener pceSessionListener = getListener(factory);
@@ -58,9 +59,4 @@ public class PCCIncrementalSyncTest extends PCCMockCommon {
         caps.add(new PCEPStatefulCapability(true, true, true, false, false, true, true));
         return caps;
     }
-
-    @Override
-    protected int getPort() {
-        return 4578;
-    }
 }
index 2ba820d46391105dd5c1b005560eefa933d1a292..0bb6afea324497e3dbc9c2c35192796ab548f7fa 100644 (file)
@@ -26,7 +26,6 @@ import io.netty.util.concurrent.Future;
 import java.math.BigInteger;
 import java.net.InetSocketAddress;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Before;
@@ -48,6 +47,7 @@ import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCSessionListener;
 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
 import org.opendaylight.protocol.pcep.sync.optimizations.SyncOptimizationsActivator;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
@@ -57,19 +57,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 
 public abstract class PCCMockCommon {
-    protected static final String REMOTE_ADDRESS = "127.0.1.0";
-    protected static final String LOCAL_ADDRESS = "127.0.0.1";
     private final static short KEEP_ALIVE = 40;
     private final static short DEAD_TIMER = 120;
-    protected final InetSocketAddress socket = new InetSocketAddress(PCCMockCommon.REMOTE_ADDRESS, getPort());
+    protected final int port = InetSocketAddressUtil.getRandomPort();
+    protected final InetSocketAddress remoteAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(port);
+    protected final InetSocketAddress localAddress = new InetSocketAddress("127.0.0.1", port);
     protected PCCSessionListener pccSessionListener;
     private PCEPDispatcher pceDispatcher;
     private PCCDispatcherImpl pccDispatcher;
 
     protected abstract List<PCEPCapability> getCapabilities();
 
-    protected abstract int getPort();
-
     @Before
     public void setUp() {
         final BasePCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE, getCapabilities());
@@ -200,25 +198,17 @@ public abstract class PCCMockCommon {
     protected Future<PCEPSession> createPCCSession(BigInteger DBVersion) {
         this.pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry());
         final PCEPSessionNegotiatorFactory<PCEPSessionImpl> snf = getSessionNegotiatorFactory();
-        final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(3, getLocalAdress().getAddress(), 0, -1, new HashedWheelTimer(),
+        final PCCTunnelManager tunnelManager = new PCCTunnelManagerImpl(3, this.localAddress.getAddress(), 0, -1, new HashedWheelTimer(),
             Optional.<TimerHandler>absent());
 
-        return pccDispatcher.createClient(getRemoteAdress(), -1,
+        return pccDispatcher.createClient(this.remoteAddress, -1,
             new PCEPSessionListenerFactory() {
                 @Override
                 public PCEPSessionListener getSessionListener() {
                     pccSessionListener = new PCCSessionListener(1, tunnelManager, false);
                     return pccSessionListener;
                 }
-            }, snf, null, getLocalAdress(), DBVersion);
-    }
-
-    private InetSocketAddress getLocalAdress() {
-        return new InetSocketAddress(PCCMockTest.LOCAL_ADDRESS, getPort());
-    }
-
-    private InetSocketAddress getRemoteAdress() {
-        return new InetSocketAddress(PCCMockTest.REMOTE_ADDRESS, getPort());
+            }, snf, null, this.localAddress, DBVersion);
     }
 
     private PCEPSessionNegotiatorFactory<PCEPSessionImpl> getSessionNegotiatorFactory() {
@@ -226,6 +216,6 @@ public abstract class PCCMockCommon {
     }
 
     protected TestingSessionListener getListener(final TestingSessionListenerFactory factory) {
-        return checkSessionListenerNotNull(factory, PCCMockTest.LOCAL_ADDRESS);
+        return checkSessionListenerNotNull(factory, this.localAddress.getHostString());
     }
 }
index 39362d8e5742b18fee29d684b0b3212b1a8c02ab..cb989257dca4b9eb041965b4246d18250cfe4af6 100644 (file)
@@ -12,60 +12,61 @@ import io.netty.channel.Channel;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPCapability;
 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
-public class PCCMockTest extends PCCMockCommon {
-    private static final String REMOTE_ADDRESS2 = "127.0.2.0";
-    private static final String REMOTE_ADDRESS3 = "127.0.3.0";
-    private static final String REMOTE_ADDRESS4 = "127.0.4.0";
-    private static final String LOCAL_ADDRESS2 = "127.0.0.2";
-    private static final InetSocketAddress SERVER_ADDRESS2 = new InetSocketAddress(REMOTE_ADDRESS2, 4189);
-    private static final InetSocketAddress SERVER_ADDRESS3 = new InetSocketAddress(REMOTE_ADDRESS3, 4189);
-    private static final InetSocketAddress SERVER_ADDRESS4 = new InetSocketAddress(REMOTE_ADDRESS4, 4189);
-    private final String[] mainInput = new String[]{"--local-address", PCCMockCommon.LOCAL_ADDRESS, "--remote-address",
-        PCCMockCommon.REMOTE_ADDRESS + ":4560", "--pcc", "1", "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
+public final class PCCMockTest extends PCCMockCommon {
+    private final String[] mainInput = new String[] {"--local-address", this.localAddress.getHostString(), "--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"};
 
     @Test
     public void testSessionEstablishment() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
-        final Channel channel = createServer(factory, this.socket);
+        final Channel channel = createServer(factory, this.remoteAddress);
         Main.main(mainInput);
         Thread.sleep(1000);
         //3 reported LSPs + syc
         final int numMessages = 4;
-        final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory, PCCMockCommon.LOCAL_ADDRESS);
+        final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
         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();
+
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final TestingSessionListenerFactory factory2 = new TestingSessionListenerFactory();
         final TestingSessionListenerFactory factory3 = new TestingSessionListenerFactory();
-        final Channel channel = createServer(factory, SERVER_ADDRESS2);
-        final Channel channel2 = createServer(factory2, SERVER_ADDRESS3);
-        final Channel channel3 = createServer(factory3, SERVER_ADDRESS4);
+        final Channel channel = createServer(factory, serverAddress2);
+        final Channel channel2 = createServer(factory2, serverAddress3);
+        final Channel channel3 = createServer(factory3, serverAddress4);
 
-        Main.main(new String[]{"--local-address", PCCMockCommon.LOCAL_ADDRESS, "--remote-address", REMOTE_ADDRESS2 + "," + REMOTE_ADDRESS3 + "," + REMOTE_ADDRESS4, "--pcc", "2"});
+        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"});
         Thread.sleep(1000);
         //PCE1
         int numMessages = 2;
-        checkSessionListener(numMessages, channel, factory, PCCMockCommon.LOCAL_ADDRESS);
-        checkSessionListener(numMessages, channel, factory, LOCAL_ADDRESS2);
+        checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
+        checkSessionListener(numMessages, channel, factory, localAddress2);
         //PCE2
-        checkSessionListener(numMessages, channel2, factory2, LOCAL_ADDRESS);
-        checkSessionListener(numMessages, channel2, factory2, LOCAL_ADDRESS2);
+        checkSessionListener(numMessages, channel2, factory2, this.localAddress.getHostString());
+        checkSessionListener(numMessages, channel2, factory2, localAddress2);
         //PCE3
-        checkSessionListener(numMessages, channel3, factory3, PCCMockCommon.LOCAL_ADDRESS);
-        checkSessionListener(numMessages, channel3, factory3, LOCAL_ADDRESS2);
+        checkSessionListener(numMessages, channel3, factory3, this.localAddress.getHostString());
+        checkSessionListener(numMessages, channel3, factory3, localAddress2);
     }
 
     @Test(expected = UnsupportedOperationException.class)
@@ -83,9 +84,4 @@ public class PCCMockTest extends PCCMockCommon {
     protected List<PCEPCapability> getCapabilities() {
         return Collections.emptyList();
     }
-
-    @Override
-    protected int getPort() {
-        return 4560;
-    }
 }
index 56574b5e7a924f501ed1151fa3686602fd92050e..18bb21ebd49d4428b8e3a31dc7c256ccbbc7f681 100644 (file)
@@ -28,7 +28,7 @@ public class PCCSyncAvoidanceProcedureTest extends PCCMockCommon {
     public void testSessionAvoidanceDesynchronizedEstablishment() throws UnknownHostException, InterruptedException, ExecutionException {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
 
-        final Channel channel = createServer(factory, socket, new PCCPeerProposal());
+        final Channel channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
         PCEPSession session = createPCCSession(BigInteger.TEN).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
@@ -44,9 +44,4 @@ public class PCCSyncAvoidanceProcedureTest extends PCCMockCommon {
         caps.add(new PCEPStatefulCapability(true, true, true, false, false, false, true));
         return caps;
     }
-
-    @Override
-    protected int getPort() {
-        return 4567;
-    }
 }
index 87739b0cc6466f966a4690e01de16bd011f04906..df48b5eb95b3ad8140a4f58a7fe27337e9fefcc7 100644 (file)
@@ -41,7 +41,7 @@ public class PCCTriggeredFullDBResyncTest extends PCCMockCommon {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
         final int lspQuantity = 3;
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(lspQuantity);
-        this.channel = createServer(factory, socket, new PCCPeerProposal());
+        this.channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
         PCEPSession session = createPCCSession(numberOflspAndDBv).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
@@ -76,9 +76,4 @@ public class PCCTriggeredFullDBResyncTest extends PCCMockCommon {
         caps.add(new PCEPStatefulCapability(true, true, true, false, true, false, true));
         return caps;
     }
-
-    @Override
-    protected int getPort() {
-        return 4566;
-    }
 }
index 5084bab344c73696ae7bb61eb7acee58686fd0bf..ed7bb6c231e846837a3510455c3a6bf6e06d1f19 100644 (file)
@@ -42,7 +42,7 @@ public class PCCTriggeredLspResyncTest extends PCCMockCommon {
         final int lspQuantity = 3;
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(lspQuantity);
 
-        this.channel = createServer(factory, socket, new PCCPeerProposal());
+        this.channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
         PCEPSession session = createPCCSession(numberOflspAndDBv).get();
         assertNotNull(session);
         final TestingSessionListener pceSessionListener = getListener(factory);
@@ -77,9 +77,4 @@ public class PCCTriggeredLspResyncTest extends PCCMockCommon {
         caps.add(new PCEPStatefulCapability(true, true, true, false, true, false, true));
         return caps;
     }
-
-    @Override
-    protected int getPort() {
-        return 4584;
-    }
 }
index 5f3072a87198b627f566711efa05c3b1bf981b5f..d129313db7b29d6892e26acc1ed676f100b352f4 100644 (file)
@@ -39,7 +39,7 @@ public class PCCTriggeredSyncTest extends PCCMockCommon {
     @Test
     public void testSessionTriggeredSync() throws Exception {
         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
-        this.channel = createServer(factory, socket, new PCCPeerProposal());
+        this.channel = createServer(factory, this.remoteAddress, new PCCPeerProposal());
         final BigInteger numberOflspAndDBv = BigInteger.valueOf(3);
         PCEPSession session = createPCCSession(numberOflspAndDBv).get();
         assertNotNull(session);
@@ -77,10 +77,5 @@ public class PCCTriggeredSyncTest extends PCCMockCommon {
         caps.add(new PCEPStatefulCapability(true, true, true, true, false, false, true));
         return caps;
     }
-
-    @Override
-    protected int getPort() {
-        return 4582;
-    }
 }
 
index f7010a7bfcc98922d821a39d5baeb4e6d8f79ae6..373b3e8f8f41113abd722268efe0858a3d7df54e 100644 (file)
          <type>test-jar</type>
          <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>${project.groupId}</groupId>
+         <artifactId>testtool-util</artifactId>
+         <scope>test</scope>
+      </dependency>
       <dependency>
          <groupId>org.opendaylight.controller</groupId>
          <artifactId>sal-binding-broker-impl</artifactId>
index c9c8057651d4a4d6b793cd80e830ec291976aa09..50bd8c09f1456ac442dea2697356d468e6082e8e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.testtool;
 
+import com.google.common.base.Preconditions;
+import com.google.common.net.HostAndPort;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.List;
@@ -20,21 +22,27 @@ import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public class PCCMock {
 
     public static void main(final String[] args) throws InterruptedException, ExecutionException {
+        Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
         final List<PCEPCapability> caps = new ArrayList<>();
         final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);
         final PCEPSessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
+        final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
+        final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHostText(), serverHostAndPort
+            .getPortOrDefault(12345));
+        final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
 
         try (final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry())) {
-            pccDispatcher.createClient(new InetSocketAddress("127.0.0.3", 12345), -1, new PCEPSessionListenerFactory() {
+            pccDispatcher.createClient(serverAddr, -1, new PCEPSessionListenerFactory() {
                 @Override
                 public PCEPSessionListener getSessionListener() {
                     return new SimpleSessionListener();
                 }
-            }, snf, null, new InetSocketAddress("127.0.0.1", 12345)).get();
+            }, snf, null, clientAddr).get();
         }
     }
 }
index 15a8651bae262f393b610df1b4eb002f0816b8f7..d2d209996036d9f8ab6aeed8a40114f888bc4cb5 100644 (file)
@@ -11,8 +11,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
@@ -20,13 +20,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 public class PCEPTestingToolTest {
 
     @Test
-    public void testSessionEstablishment() {
-        try {
-            Main.main(new String[]{"-a", "127.0.0.3:12345", "-ka", "10", "-d", "0", "--stateful", "--active", "--instant"});
-            PCCMock.main(new String[0]);
-        } catch (final Exception e) {
-            Assert.fail();
-        }
+    public void testSessionEstablishment() throws Exception {
+        final String serverAddr = InetSocketAddressUtil
+            .toHostAndPort(InetSocketAddressUtil.getRandomLoopbackInetSocketAddress()).toString();
+        Main.main(new String[] {"-a", serverAddr,
+            "-ka", "10", "-d", "0", "--stateful", "--active", "--instant"});
+        PCCMock.main(new String[] {serverAddr});
     }
 
     @Test
index b72da6a09055c94be5fd8db9b61949690206976b..7f9fb8f0779e4f89edd8f117626ec95872ac7c3f 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiator;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
@@ -68,17 +69,17 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
     protected static final String TEST_TOPOLOGY_NAME = "testtopo";
     protected static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
             Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).build();
-    protected static final String TEST_ADDRESS = "127.0.0.1";
-    protected static final NodeId NODE_ID = new NodeId("pcc://" + TEST_ADDRESS);
-    protected static final String TEST_LSP_NAME = "tunnel0";
     protected static final String IPV4_MASK = "/32";
-    protected static final String ERO_IP_PREFIX = TEST_ADDRESS + IPV4_MASK;
-    protected static final String NEW_DESTINATION_ADDRESS = "127.0.1.0";
-    protected static final String DST_IP_PREFIX = NEW_DESTINATION_ADDRESS + IPV4_MASK;
     protected static final short DEAD_TIMER = 30;
     protected static final short KEEP_ALIVE = 10;
     protected static final int RPC_TIMEOUT = 4;
 
+    protected final String testAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
+    protected final NodeId nodeId = new NodeId("pcc://" + testAddress);
+    protected final String eroIpPrefix = testAddress + IPV4_MASK;
+    protected final String newDestinationAddress = InetSocketAddressUtil.getRandomLoopbackIpAddress();
+    protected final String dstIpPrefix = newDestinationAddress + IPV4_MASK;
+
     protected List<Notification> receivedMsgs;
 
     @Mock
@@ -124,9 +125,9 @@ public abstract class AbstractPCEPSessionTest<T extends TopologySessionListenerF
         doReturn(this.eventLoop).when(this.clientListener).eventLoop();
         doReturn(null).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
         doReturn(true).when(this.clientListener).isActive();
-        final SocketAddress ra = new InetSocketAddress(TEST_ADDRESS, 4189);
+        final SocketAddress ra = new InetSocketAddress(testAddress, 4189);
         doReturn(ra).when(this.clientListener).remoteAddress();
-        final SocketAddress la = new InetSocketAddress(TEST_ADDRESS, 30000);
+        final SocketAddress la = new InetSocketAddress(testAddress, InetSocketAddressUtil.getRandomPort());
         doReturn(la).when(this.clientListener).localAddress();
 
         doReturn(mock(ChannelFuture.class)).when(this.clientListener).close();
index 9ce0ddde248ae9c0ebe0fc85425fa0e12587a1ee..f75a17df263d8f3b61576b259653f3fd95f54f4e 100644 (file)
@@ -78,7 +78,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         Assert.assertFalse(pcc.getReportedLsp().isEmpty());
 
         //PCEP Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).build());
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).build());
 
         final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
         Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
@@ -95,7 +95,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         Assert.assertEquals(1, pcc3.getReportedLsp().size());
 
         //Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).build());
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).build());
         this.listener.onMessage(session, pcRpt);
         //end of sync
         this.listener.onMessage(session, syncMsg);
@@ -123,7 +123,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         Assert.assertFalse(reportedLspPcc.isEmpty());
 
         //Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).setName("test").build());
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).setName("test").build());
 
         final PathComputationClient pcc1 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
         Assert.assertEquals(PccSyncState.PcepTriggeredResync, pcc1.getStateSync());
@@ -143,7 +143,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         Assert.assertEquals(1, pcc2.getReportedLsp().size());
 
         //Trigger Full Resync
-        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(NODE_ID).setName("test").build());
+        this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(nodeId).setName("test").build());
         this.listener.onMessage(session, syncMsg);
 
         final PathComputationClient pcc3 = getTopology().get().getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
index a143d05bc67d686c5360d8c944844c8722083a73..ff70d2d139f542b9bbc2a8ab62b6e70ab7c00092 100755 (executable)
@@ -98,7 +98,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
 
-    private static final String TUNNEL_NAME = "pcc_" + TEST_ADDRESS + "_tunnel_0";
+    private final String TUNNEL_NAME = "pcc_" + testAddress + "_tunnel_0";
 
     private Stateful07TopologySessionListener listener;
 
@@ -116,17 +116,17 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     public void testStateful07TopologySessionListener() throws Exception {
         this.listener.onSessionUp(this.session);
 
-        assertEquals(TEST_ADDRESS, this.listener.getPeerId());
+        assertEquals(testAddress, this.listener.getPeerId());
         final SessionState state = this.listener.getSessionState();
         assertNotNull(state);
         assertEquals(DEAD_TIMER, state.getLocalPref().getDeadtimer().shortValue());
         assertEquals(KEEP_ALIVE, state.getLocalPref().getKeepalive().shortValue());
         assertEquals(0, state.getLocalPref().getSessionId().intValue());
-        assertEquals(TEST_ADDRESS, state.getLocalPref().getIpAddress());
+        assertEquals(testAddress, state.getLocalPref().getIpAddress());
         assertEquals(DEAD_TIMER, state.getPeerPref().getDeadtimer().shortValue());
         assertEquals(KEEP_ALIVE, state.getPeerPref().getKeepalive().shortValue());
         assertEquals(0, state.getPeerPref().getSessionId().intValue());
-        assertEquals(TEST_ADDRESS, state.getPeerPref().getIpAddress());
+        assertEquals(testAddress, state.getPeerPref().getIpAddress());
 
         // add-lsp
         this.topologyRpcs.addLsp(createAddLspInput());
@@ -136,7 +136,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
+            testAddress, testAddress, testAddress, Optional.<byte[]>absent());
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
         this.listener.onMessage(this.session, esm);
@@ -148,7 +148,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Node1 node = topology.getNode().get(0).getAugmentation(Node1.class);
         assertNotNull(node);
         PathComputationClient pcc = node.getPathComputationClient();
-        assertEquals(TEST_ADDRESS, pcc.getIpAddress().getIpv4Address().getValue());
+        assertEquals(testAddress, pcc.getIpAddress().getIpv4Address().getValue());
         // reported lsp so far empty, has not received response (PcRpt) yet
         assertTrue(pcc.getReportedLsp().isEmpty());
         this.listener.onMessage(this.session, pcRpt);
@@ -161,7 +161,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         assertEquals(1, reportedLsp.getPath().size());
         Path path = reportedLsp.getPath().get(0);
         assertEquals(1, path.getEro().getSubobject().size());
-        assertEquals(ERO_IP_PREFIX, getLastEroIpPrefix(path.getEro()));
+        assertEquals(eroIpPrefix, getLastEroIpPrefix(path.getEro()));
         // check stats
         assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
         assertTrue(this.listener.getSynchronized());
@@ -173,9 +173,9 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
 
         // update-lsp
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
-        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX, DST_IP_PREFIX)));
+        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
         updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
-        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
         this.topologyRpcs.updateLsp(update);
         assertEquals(2, this.receivedMsgs.size());
         assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
@@ -183,7 +183,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
         final long srpId2 = upd.getSrp().getOperationId().getValue();
         final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
-                NEW_DESTINATION_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
+            newDestinationAddress, testAddress, testAddress, Optional.<byte[]>absent());
         final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath().getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt2);
         //check updated lsp
@@ -195,7 +195,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         assertEquals(1, reportedLsp.getPath().size());
         path = reportedLsp.getPath().get(0);
         assertEquals(2, path.getEro().getSubobject().size());
-        assertEquals(DST_IP_PREFIX, getLastEroIpPrefix(path.getEro()));
+        assertEquals(dstIpPrefix, getLastEroIpPrefix(path.getEro()));
         // check stats
         assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
         assertTrue(this.listener.getSynchronized());
@@ -212,13 +212,13 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         // ensure-operational
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
         ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
-        final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+        final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
         final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
         //check result
         assertNull(result.getFailure());
 
         // remove-lsp
-        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
         this.topologyRpcs.removeLsp(remove);
         assertEquals(3, this.receivedMsgs.size());
         assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
@@ -226,7 +226,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
         final long srpId3 = req2.getSrp().getOperationId().getValue();
         final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
+            testAddress, testAddress, testAddress, Optional.<byte[]>absent());
         final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3).setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(), Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.<Subobject>emptyList()));
         this.listener.onMessage(this.session, pcRpt3);
         // check if lsp was removed
@@ -293,7 +293,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
+            testAddress, testAddress, testAddress, Optional.<byte[]>absent());
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt);
         assertEquals(1, getTopology().get().getNode().size());
@@ -320,9 +320,9 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     public void testUpdateUnknownLsp() throws InterruptedException, ExecutionException {
         this.listener.onSessionUp(this.session);
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
-        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX, DST_IP_PREFIX)));
+        updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
         updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
-        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+        final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
         final UpdateLspOutput result = this.topologyRpcs.updateLsp(update).get().getResult();
         assertEquals(FailureType.Unsent, result.getFailure());
         assertEquals(1, result.getError().size());
@@ -334,7 +334,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     @Test
     public void testRemoveUnknownLsp() throws InterruptedException, ExecutionException {
         this.listener.onSessionUp(this.session);
-        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+        final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
         final OperationResult result = this.topologyRpcs.removeLsp(remove).get().getResult();
         assertEquals(FailureType.Unsent, result.getFailure());
         assertEquals(1, result.getError().size());
@@ -353,7 +353,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
+            testAddress, testAddress, testAddress, Optional.<byte[]>absent());
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt);
 
@@ -398,10 +398,10 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
     private AddLspInput createAddLspInput() {
         final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
         final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
-        ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(TEST_ADDRESS)).setDestinationIpv4Address(new Ipv4Address(TEST_ADDRESS)).build());
+        ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(testAddress)).setDestinationIpv4Address(new Ipv4Address(testAddress)).build());
         argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
-        argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX)));
+        argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix)));
         argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
-        return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+        return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
     }
 }
index c3d5168b4cc1625405df2a6ff68cbed0be777a89..93cd460edab4ae11a55ed1696f3d76487584365a 100644 (file)
@@ -187,57 +187,57 @@ public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopol
     public void testSubmitAddLsp() throws InterruptedException, ExecutionException {
         final SubmitAddLspInputBuilder inputBuilder = new SubmitAddLspInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(NODE_ID);
+        inputBuilder.setNode(nodeId);
         inputBuilder.setArguments(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder().build());
         this.topologyProgramming.submitAddLsp(inputBuilder.build());
         Assert.assertNotNull(this.addLspArgs);
         Assert.assertEquals(NAME, this.addLspArgs.getName());
-        Assert.assertEquals(NODE_ID, this.addLspArgs.getNode());
+        Assert.assertEquals(nodeId, this.addLspArgs.getNode());
     }
 
     @Test
     public void testSubmitUpdateLsp() {
         final SubmitUpdateLspInputBuilder inputBuilder = new SubmitUpdateLspInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(NODE_ID);
+        inputBuilder.setNode(nodeId);
         this.topologyProgramming.submitUpdateLsp(inputBuilder.build());
         Assert.assertNotNull(this.updateLspArgs);
         Assert.assertEquals(NAME, this.updateLspArgs.getName());
-        Assert.assertEquals(NODE_ID, this.updateLspArgs.getNode());
+        Assert.assertEquals(nodeId, this.updateLspArgs.getNode());
     }
 
     @Test
     public void testSubmitEnsureLsp() {
         final SubmitEnsureLspOperationalInputBuilder inputBuilder = new SubmitEnsureLspOperationalInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(NODE_ID);
+        inputBuilder.setNode(nodeId);
         inputBuilder.setArguments(new ArgumentsBuilder().build());
         this.topologyProgramming.submitEnsureLspOperational(inputBuilder.build());
         Assert.assertNotNull(this.ensureLspInput);
         Assert.assertEquals(NAME, this.ensureLspInput.getName());
-        Assert.assertEquals(NODE_ID, this.ensureLspInput.getNode());
+        Assert.assertEquals(nodeId, this.ensureLspInput.getNode());
     }
 
     @Test
     public void testSubmitRemoveLsp() {
         final SubmitRemoveLspInputBuilder inputBuilder = new SubmitRemoveLspInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(NODE_ID);
+        inputBuilder.setNode(nodeId);
         this.topologyProgramming.submitRemoveLsp(inputBuilder.build());
         Assert.assertNotNull(this.removeLspArgs);
         Assert.assertEquals(NAME, this.removeLspArgs.getName());
-        Assert.assertEquals(NODE_ID, this.removeLspArgs.getNode());
+        Assert.assertEquals(nodeId, this.removeLspArgs.getNode());
     }
 
     @Test
     public void testSubmitTriggerSync() {
         final SubmitTriggerSyncInputBuilder inputBuilder = new SubmitTriggerSyncInputBuilder();
         inputBuilder.setName(NAME);
-        inputBuilder.setNode(NODE_ID);
+        inputBuilder.setNode(nodeId);
         this.topologyProgramming.submitTriggerSync(inputBuilder.build());
         Assert.assertNotNull(this.triggerSyncArgs);
         Assert.assertEquals(NAME, this.triggerSyncArgs.getName());
-        Assert.assertEquals(NODE_ID, this.triggerSyncArgs.getNode());
+        Assert.assertEquals(nodeId, this.triggerSyncArgs.getNode());
     }
 
     protected static final class MockedTopologySessionListenerFactory implements TopologySessionListenerFactory {
index f92debe3c1a9823760cd63d14a75f2e37fedd831..5b977b40e28f0fbe5fea87dc10dd95f087138bee 100644 (file)
@@ -32,6 +32,10 @@ public final class InetSocketAddressUtil {
         return Lists.transform(Arrays.asList(address.split(SEPARATOR)), input -> getInetSocketAddress(input, null));
     }
 
+    public static HostAndPort toHostAndPort(final InetSocketAddress address) {
+        return HostAndPort.fromParts(address.getHostString(), address.getPort());
+    }
+
     public static InetSocketAddress getInetSocketAddress(final String hostPortString, final Integer defaultPort) {
         final HostAndPort hostAndPort = HostAndPort.fromString(hostPortString);
         if (defaultPort != null) {
@@ -39,4 +43,36 @@ public final class InetSocketAddressUtil {
         }
         return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
     }
+
+    public static InetSocketAddress getRandomLoopbackInetSocketAddress(final int port) {
+        return new InetSocketAddress(getRandomLoopbackIpAddress(), port);
+    }
+
+    public static InetSocketAddress getRandomLoopbackInetSocketAddress() {
+        return getRandomLoopbackInetSocketAddress(getRandomPort());
+    }
+
+    /**
+     * Generate a random high range port number
+     *
+     * @return A port number range from 10000 to 50000
+     */
+    public static int getRandomPort() {
+        final int randPort = 10000 + (int) Math.round(40000 * Math.random());
+        return randPort;
+    }
+
+    /**
+     * Generate a random loopback ip address
+     * IP address range: 127.50.50.50 ~ 127.250.250.250
+     * We did not utilize the whole 127./8 range to avoid using common addresses like 127.0.0.1
+     * @return Generated random loopback IP address
+     */
+    public static String getRandomLoopbackIpAddress() {
+        final StringBuilder sb = new StringBuilder("127");
+        for (int i = 0; i < 3; i++) {
+            sb.append(".").append(50 + (int) Math.round(Math.random() * 200));
+        }
+        return sb.toString();
+    }
 }
index 3370547796bda327dc94d2a2f66015d65bd9d475..526b16588e7d1fa9c22edd6bd7660932b5c5e28e 100644 (file)
@@ -9,6 +9,8 @@
 package org.opendaylight.protocol.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.net.InetSocketAddress;
 import java.util.Arrays;
@@ -49,4 +51,15 @@ public class InetSocketAddressUtilTest {
         assertEquals(new InetSocketAddress(ADDRESS1, PORT1), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1 + ":" + PORT1, DEFAULT_PORT));
         assertEquals(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1, DEFAULT_PORT));
     }
+
+    @Test
+    public void getRandomLoopbackInetSocketAddressTest() throws Exception {
+        final InetSocketAddress addr1 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
+        final InetSocketAddress addr2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
+        assertNotNull(addr1);
+        assertNotNull(addr2);
+        assertNotEquals(addr1, addr2);
+        assertNotEquals(addr1.getHostString(), addr2.getHostString());
+        assertNotEquals(addr1.getPort(), addr2.getPort());
+    }
 }
\ No newline at end of file