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 {
@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();
@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();
serverDispatcher.close();
}
- protected static int getRandomPort() {
- return (int) (Math.random() * 64000 + 1024);
- }
-
}
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;
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;
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;
this.bmpActivator.start(ctx);
this.bmpDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx.getBmpMessageRegistry(),
new DefaultBmpSessionFactory());
- this.serverPort = BmpMockDispatcherTest.getRandomPort();
}
@After
@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
@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();
<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>
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;
}
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);
@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());
@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);
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) {
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,
if (localAddress.isPresent()) {
this.localAddress = localAddress.get();
} else {
- this.localAddress = this.defaulAddress;
+ this.localAddress = this.defaultAddress;
}
}
}
<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>
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;
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;
@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;
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(
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;
@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());
@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) {
@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());
@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));
}
@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());
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;
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;
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
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());
Assert.assertNotNull(sl2.getSession());
Assert.assertTrue(sl2.isUp());
}
-
- private int getRandomPort() {
- return this.random.nextInt(4000) + 1024;
- }
}
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 {
* 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);
caps.add(new PCEPStatefulCapability(true, true, true, false, false, true, true));
return caps;
}
-
- @Override
- protected int getPort() {
- return 4578;
- }
}
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;
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;
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());
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() {
}
protected TestingSessionListener getListener(final TestingSessionListenerFactory factory) {
- return checkSessionListenerNotNull(factory, PCCMockTest.LOCAL_ADDRESS);
+ return checkSessionListenerNotNull(factory, this.localAddress.getHostString());
}
}
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)
protected List<PCEPCapability> getCapabilities() {
return Collections.emptyList();
}
-
- @Override
- protected int getPort() {
- return 4560;
- }
}
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);
caps.add(new PCEPStatefulCapability(true, true, true, false, false, false, true));
return caps;
}
-
- @Override
- protected int getPort() {
- return 4567;
- }
}
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);
caps.add(new PCEPStatefulCapability(true, true, true, false, true, false, true));
return caps;
}
-
- @Override
- protected int getPort() {
- return 4566;
- }
}
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);
caps.add(new PCEPStatefulCapability(true, true, true, false, true, false, true));
return caps;
}
-
- @Override
- protected int getPort() {
- return 4584;
- }
}
@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);
caps.add(new PCEPStatefulCapability(true, true, true, true, false, false, true));
return caps;
}
-
- @Override
- protected int getPort() {
- return 4582;
- }
}
<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>
*/
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;
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();
}
}
}
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;
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
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;
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
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();
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());
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);
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());
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();
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;
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());
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);
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);
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());
// 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);
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
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());
// 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);
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
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());
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());
@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());
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);
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();
}
}
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 {
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) {
}
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();
+ }
}
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;
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