+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.pcep.pcc.mock;
-
-import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.socket.nio.NioSocketChannel;
-import io.netty.util.concurrent.EventExecutor;
-import io.netty.util.concurrent.Future;
-import java.net.InetSocketAddress;
-import org.opendaylight.protocol.framework.AbstractDispatcher;
-import org.opendaylight.protocol.framework.ProtocolSession;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.SessionListener;
-
-/**
- * BindableDispatcher abstract class for creating clients that are bound to a specified local InetSocketAddress.
- */
-public abstract class BindableDispatcher<S extends ProtocolSession<?>, L extends SessionListener<?, ?, ?>> extends AbstractDispatcher<S, L> {
-
- private final EventLoopGroup workerGroup;
-
- protected BindableDispatcher(final EventExecutor executor, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
- super(executor, bossGroup, workerGroup);
- this.workerGroup = workerGroup;
- }
-
- /**
- * Creates a client.
- *
- * @param localAddress local address
- * @param remoteAddress remote address
- * @param connectStrategy Reconnection strategy to be used when initial connection fails
- *
- * @return Future representing the connection process. Its result represents the combined success of TCP connection
- * as well as session negotiation.
- */
- protected Future<S> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
- final ReconnectStrategy strategy, final PipelineInitializer<S> initializer) {
- Bootstrap bootstrap = new Bootstrap();
- bootstrap.localAddress(localAddress).option(ChannelOption.SO_KEEPALIVE, true);
- customizeBootstrap(bootstrap);
- bootstrap.group(this.workerGroup);
- bootstrap.channel(NioSocketChannel.class);
- return super.createClient(remoteAddress, strategy, bootstrap, initializer);
- }
-}
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.protocol.framework.NeverReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectImmediatelyStrategy;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.PCEPSessionListener;
import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
-import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
final InetAddress localAddress, final List<InetAddress> remoteAddress, final short keepalive, final short deadtimer) throws InterruptedException, ExecutionException {
final StatefulActivator activator07 = new StatefulActivator();
activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
- for (final InetAddress pceAddress : remoteAddress) {
- InetAddress currentAddress = localAddress;
- int i = 0;
- while (i < pccCount) {
- final InetAddress pccAddress = currentAddress;
- final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf = new DefaultPCEPSessionNegotiatorFactory(
- new OpenBuilder().setKeepalive(keepalive).setDeadTimer(deadtimer).setSessionId((short) 0).build(), 0);
-
- final PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pcc = new PCCMock<Message, PCEPSessionImpl, PCEPSessionListener>(snf, new PCEPHandlerFactory(
- ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry()));
- pcc.createClient(new InetSocketAddress(pccAddress, 0), new InetSocketAddress(pceAddress, DEFAULT_PORT),
- new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT),
- new SessionListenerFactory<PCEPSessionListener>() {
+ InetAddress currentAddress = localAddress;
+ final PCCDispatcher pccDispatcher = new PCCDispatcher(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(),
+ getSessionNegotiatorFactory(keepalive, deadtimer));
+ for (int i = 0; i < pccCount; i++) {
+ createPCC(lspsPerPcc, pcerr, currentAddress, remoteAddress, keepalive, deadtimer, pccDispatcher);
+ currentAddress = InetAddresses.increment(currentAddress);
+ }
+ }
- @Override
- public PCEPSessionListener getSessionListener() {
- return new SimpleSessionListener(lspsPerPcc, pcerr, pccAddress);
- }
- }).get();
- i++;
- currentAddress = InetAddresses.increment(currentAddress);
- }
+ private static void createPCC(final int lspsPerPcc, final boolean pcerr, final InetAddress localAddress,
+ final List<InetAddress> remoteAddress, final short keepalive, final short deadtimer, final PCCDispatcher pccDispatcher) throws InterruptedException, ExecutionException {
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf = getSessionNegotiatorFactory(keepalive, deadtimer);
+ for (final InetAddress pceAddress : remoteAddress) {
+ pccDispatcher.createClient(new InetSocketAddress(localAddress, 0), new InetSocketAddress(pceAddress, DEFAULT_PORT), new ReconnectImmediatelyStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT), new SessionListenerFactory<PCEPSessionListener>() {
+ @Override
+ public PCEPSessionListener getSessionListener() {
+ return new SimpleSessionListener(lspsPerPcc, pcerr, localAddress);
+ }
+ }, snf);
}
}
+ private static SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> getSessionNegotiatorFactory(final short keepalive,
+ final short deadtimer) {
+ return new DefaultPCEPSessionNegotiatorFactory(
+ new OpenBuilder().setKeepalive(keepalive).setDeadTimer(deadtimer).setSessionId((short) 0).build(), 0);
+ }
+
private static ch.qos.logback.classic.Logger getRootLogger(final LoggerContext lc) {
return Iterables.find(lc.getLoggerList(), new Predicate<Logger>() {
@Override
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.pcep.pcc.mock;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07SrpObjectParser;
-import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
-import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
-
-public class PCCActivator extends AbstractPCEPExtensionProviderActivator {
-
- @Override
- protected List<AutoCloseable> startImpl(PCEPExtensionProviderContext context) {
- final List<AutoCloseable> regs = new ArrayList<>();
- regs.add(context.registerObjectParser(Stateful07SrpObjectParser.CLASS, Stateful07SrpObjectParser.TYPE,
- new PCCSrpObjectParser(context.getTlvHandlerRegistry(), context.getVendorInformationTlvRegistry())));
- return regs;
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep.pcc.mock;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.Promise;
+import java.net.InetSocketAddress;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.SessionListenerFactory;
+import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
+import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
+import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
+import org.opendaylight.protocol.pcep.spi.MessageRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+
+public final class PCCDispatcher extends PCEPDispatcherImpl {
+
+ private InetSocketAddress localAddress;
+ private final PCEPHandlerFactory factory;
+
+ public PCCDispatcher(final MessageRegistry registry,
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
+ super(registry, negotiatorFactory, new NioEventLoopGroup(), new NioEventLoopGroup(), null, null);
+ this.factory = new PCEPHandlerFactory(registry);
+ }
+
+ @Override
+ protected void customizeBootstrap(final Bootstrap b) {
+ super.customizeBootstrap(b);
+ if (this.localAddress != null) {
+ b.localAddress(this.localAddress);
+ }
+ }
+
+ public synchronized Future<PCEPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
+ final ReconnectStrategy strategy, final SessionListenerFactory<PCEPSessionListener> listenerFactory,
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
+ this.localAddress = localAddress;
+ final Future<PCEPSessionImpl> futureClient = super.createClient(remoteAddress, strategy, new PipelineInitializer<PCEPSessionImpl>() {
+ @Override
+ public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise) {
+ ch.pipeline().addLast(PCCDispatcher.this.factory.getDecoders());
+ ch.pipeline().addLast("negotiator",
+ negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
+ ch.pipeline().addLast(PCCDispatcher.this.factory.getEncoders());
+ }
+ });
+ this.localAddress = null;
+ return futureClient;
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.pcep.pcc.mock;
-
-import com.google.common.base.Preconditions;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.GlobalEventExecutor;
-import io.netty.util.concurrent.Promise;
-import java.net.InetSocketAddress;
-import org.opendaylight.protocol.framework.ProtocolSession;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.SessionListener;
-import org.opendaylight.protocol.framework.SessionListenerFactory;
-import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
-import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
-
-public class PCCMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends BindableDispatcher<S, L> {
-
- private final SessionNegotiatorFactory<M, S, L> negotiatorFactory;
- private final PCEPHandlerFactory factory;
-
- public PCCMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final PCEPHandlerFactory factory) {
- super(GlobalEventExecutor.INSTANCE, new NioEventLoopGroup(), new NioEventLoopGroup());
- this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
- this.factory = Preconditions.checkNotNull(factory);
- }
-
- public Future<S> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress, final ReconnectStrategy strategy,
- final SessionListenerFactory<L> listenerFactory) {
- return super.createClient(localAddress, remoteAddress, strategy, new PipelineInitializer<S>() {
- @Override
- public void initializeChannel(final SocketChannel ch, final Promise<S> promise) {
- ch.pipeline().addLast(PCCMock.this.factory.getDecoders());
- ch.pipeline().addLast("negotiator",
- PCCMock.this.negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
- ch.pipeline().addLast(PCCMock.this.factory.getEncoders());
- }
- });
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.pcep.pcc.mock;
-
-import com.google.common.base.Preconditions;
-import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07SrpObjectParser;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvRegistry;
-import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
-
-public class PCCSrpObjectParser extends Stateful07SrpObjectParser {
-
- protected PCCSrpObjectParser(TlvRegistry tlvReg, VendorInformationTlvRegistry viTlvReg) {
- super(tlvReg, viTlvReg);
- }
-
- @Override
- public Srp parseObject(ObjectHeader header, ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
- if (bytes.readableBytes() < MIN_SIZE) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
- + "; Expected: >=" + MIN_SIZE + ".");
- }
- final SrpBuilder builder = new SrpBuilder();
- builder.setIgnore(header.isIgnore());
- builder.setProcessingRule(header.isProcessingRule());
- bytes.readerIndex(bytes.readerIndex() + FLAGS_SIZE);
- builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
- final TlvsBuilder tlvsBuilder = new TlvsBuilder();
- parseTlvs(tlvsBuilder, bytes.slice());
- builder.setTlvs(tlvsBuilder.build());
- return builder.build();
- }
-}
package org.opendaylight.protocol.pcep.pcc.mock;
-import io.netty.buffer.Unpooled;
+import com.google.common.net.InetAddresses;
+import io.netty.channel.Channel;
+import io.netty.channel.nio.NioEventLoopGroup;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutionException;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+public class PCCMockTest {
+ private static final short KEEP_ALIVE = 30;
+ private static final short DEAD_TIMER = 120;
+ private static final String REMOTE_ADDRESS = "127.0.1.0";
+ 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 InetSocketAddress SERVER_ADDRESS = new InetSocketAddress(REMOTE_ADDRESS, 4189);
+ 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 static final String LOCAL_ADDRESS = "127.0.0.1";
+ private static final String LOCAL_ADDRESS2 = "127.0.0.2";
-public class PCCMockTest {
+ private PCEPDispatcher pceDispatcher;
- @Test
- public void testSessionEstablishment() {
- try {
- org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.1.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
- Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.1.0", "--pcc", "2", "--lsp", "1", "--log-level", "DEBUG", "-ka", "10", "-d", "0",});
- } catch (Exception e) {
- Assert.fail(e.getMessage());
- }
+ @Before
+ public void setUp() {
+ final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(
+ new OpenBuilder().setKeepalive(KEEP_ALIVE).setDeadTimer(DEAD_TIMER).setSessionId((short) 0).build(), 0);
+ this.pceDispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(),
+ nf, new NioEventLoopGroup(), new NioEventLoopGroup());
}
@Test
- public void testMockPCCToManyPCE() {
- try {
- org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.4.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
- org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.2.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
- org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.3.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
- Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.4.0,127.0.2.0,127.0.3.0", "--pcc", "3"});
- } catch (Exception e) {
- Assert.fail(e.getMessage());
- }
+ public void testSessionEstablishment() throws UnknownHostException, InterruptedException, ExecutionException {
+ final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
+ final Channel channel = this.pceDispatcher.createServer(SERVER_ADDRESS, factory).channel();
+ Main.main(new String[] {"--local-address", LOCAL_ADDRESS, "--remote-address", REMOTE_ADDRESS, "--pcc", "1", "--lsp", "3",
+ "--log-level", "DEBUG", "-ka", "10", "-d", "40"});
+ Thread.sleep(1000);
+ final TestingSessionListener sessionListener = factory.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS));
+ Assert.assertTrue(sessionListener.isUp());
+ //3 reported LSPs + syc
+ Assert.assertEquals(4, sessionListener.messages().size());
+ final PCEPSession session = sessionListener.getSession();
+ Assert.assertNotNull(session);
+ Assert.assertEquals(40, session.getPeerPref().getDeadtimer().shortValue());
+ Assert.assertEquals(10, session.getPeerPref().getKeepalive().shortValue());
+ channel.close().get();
}
@Test
- public void testSrpObjectParser() throws PCEPDeserializerException {
- final byte[] bytes = {
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- };
- final PCEPExtensionProviderContext ctx = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
- final PCCSrpObjectParser parser = new PCCSrpObjectParser(ctx.getTlvHandlerRegistry(), ctx.getVendorInformationTlvRegistry());
- final Srp srp = new SrpBuilder().setIgnore(true).setProcessingRule(true).setOperationId(new SrpIdNumber(0L)).setTlvs(new TlvsBuilder().build()).build();
- Assert.assertEquals(srp, parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.wrappedBuffer(bytes)));
+ public void testMockPCCToManyPCE() throws InterruptedException, ExecutionException, UnknownHostException {
+ final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(
+ new OpenBuilder().setKeepalive(KEEP_ALIVE).setDeadTimer(DEAD_TIMER).setSessionId((short) 0).build(), 0);
+ PCEPDispatcher dispatcher2 = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(),
+ nf, new NioEventLoopGroup(), new NioEventLoopGroup());
+ final DefaultPCEPSessionNegotiatorFactory nf2 = new DefaultPCEPSessionNegotiatorFactory(
+ new OpenBuilder().setKeepalive(KEEP_ALIVE).setDeadTimer(DEAD_TIMER).setSessionId((short) 0).build(), 0);
+ PCEPDispatcher dispatcher3 = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(),
+ nf2, new NioEventLoopGroup(), new NioEventLoopGroup());
+ final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
+ final TestingSessionListenerFactory factory2 = new TestingSessionListenerFactory();
+ final TestingSessionListenerFactory factory3 = new TestingSessionListenerFactory();
+ final Channel channel = pceDispatcher.createServer(SERVER_ADDRESS2, factory).channel();
+ final Channel channel2 = dispatcher2.createServer(SERVER_ADDRESS3, factory2).channel();
+ final Channel channel3 = dispatcher3.createServer(SERVER_ADDRESS4, factory3).channel();
+
+ Main.main(new String[] {"--local-address", LOCAL_ADDRESS, "--remote-address", REMOTE_ADDRESS2 + "," + REMOTE_ADDRESS3 + "," + REMOTE_ADDRESS4,
+ "--pcc", "2"});
+ Thread.sleep(1000);
+ //PCE1
+ TestingSessionListener sessionListener1 = factory.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS));
+ TestingSessionListener sessionListener2 = factory.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS2));
+ Assert.assertNotNull(sessionListener1);
+ Assert.assertNotNull(sessionListener2);
+ Assert.assertTrue(sessionListener1.isUp());
+ Assert.assertTrue(sessionListener2.isUp());
+ Assert.assertEquals(2, sessionListener1.messages().size());
+ Assert.assertEquals(2, sessionListener2.messages().size());
+ //PCE2
+ sessionListener1 = factory2.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS));
+ sessionListener2 = factory2.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS2));
+ Assert.assertNotNull(sessionListener1);
+ Assert.assertNotNull(sessionListener2);
+ Assert.assertTrue(sessionListener1.isUp());
+ Assert.assertTrue(sessionListener2.isUp());
+ Assert.assertEquals(2, sessionListener1.messages().size());
+ Assert.assertEquals(2, sessionListener2.messages().size());
+ //PCE3
+ sessionListener1 = factory3.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS));
+ sessionListener2 = factory3.getSessionListenerByRemoteAddress(InetAddresses.forString(LOCAL_ADDRESS2));
+ Assert.assertNotNull(sessionListener1);
+ Assert.assertNotNull(sessionListener2);
+ Assert.assertTrue(sessionListener1.isUp());
+ Assert.assertTrue(sessionListener2.isUp());
+ Assert.assertEquals(2, sessionListener1.messages().size());
+ Assert.assertEquals(2, sessionListener2.messages().size());
+
+ channel.close().get();
+ channel2.close().get();
+ channel3.close().get();
}
@Test(expected=UnsupportedOperationException.class)
throw e.getCause();
}
}
-
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep.pcc.mock;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.PCEPTerminationReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestingSessionListener implements PCEPSessionListener {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestingSessionListener.class);
+
+ private final List<Message> messages = Lists.newArrayList();
+
+ private boolean up = false;
+ private PCEPSession session = null;
+
+ @Override
+ public void onMessage(final PCEPSession session, final Message message) {
+ LOG.debug("Received message: {}", message);
+ this.messages.add(message);
+ }
+
+ @Override
+ public void onSessionUp(final PCEPSession session) {
+ LOG.debug("Session up.");
+ this.up = true;
+ this.session = session;
+ }
+
+ @Override
+ public void onSessionDown(final PCEPSession session, final Exception e) {
+ LOG.debug("Session down. Cause : {} ", e, e);
+ this.up = false;
+ this.session = null;
+ }
+
+ @Override
+ public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
+ LOG.debug("Session terminated. Cause : {}", cause);
+ }
+
+ public List<Message> messages() {
+ return this.messages;
+ }
+
+ public boolean isUp () {
+ return this.up;
+ }
+
+ public PCEPSession getSession() {
+ return this.session;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep.pcc.mock;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
+
+public class TestingSessionListenerFactory implements PCEPSessionListenerFactory {
+
+ @GuardedBy("this")
+ private List<TestingSessionListener> sessionListeners = new ArrayList<>();
+
+ @Override
+ public PCEPSessionListener getSessionListener() {
+ final TestingSessionListener sessionListener = new TestingSessionListener();
+ this.sessionListeners.add(sessionListener);
+ return sessionListener;
+ }
+
+ public TestingSessionListener getSessionListenerByRemoteAddress(final InetAddress ipAddress) {
+ for (final TestingSessionListener sessionListener : this.sessionListeners) {
+ if (sessionListener.isUp()) {
+ final PCEPSession session = sessionListener.getSession();
+ if (session.getRemoteAddress().equals(ipAddress)) {
+ return sessionListener;
+ }
+ }
+ }
+ return null;
+ }
+}