Search in sources :

Example 1 with PCEPDispatcherImpl

use of org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl in project bgpcep by opendaylight.

the class Main method main.

public static void main(final String[] args) throws UnknownHostException, InterruptedException, ExecutionException {
    if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
        LOG.info(Main.USAGE);
        return;
    }
    InetSocketAddress address = null;
    int keepAliveValue = KA_DEFAULT;
    int deadTimerValue = 0;
    boolean stateful = false;
    boolean active = false;
    boolean instant = false;
    int pos = 0;
    while (pos < args.length) {
        if (args[pos].equalsIgnoreCase("-a") || args[pos].equalsIgnoreCase("--address")) {
            final String[] ip = args[pos + 1].split(":");
            address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
            pos++;
        } else if (args[pos].equalsIgnoreCase("-d") || args[pos].equalsIgnoreCase("--deadtimer")) {
            deadTimerValue = Integer.parseInt(args[pos + 1]);
            pos++;
        } else if (args[pos].equalsIgnoreCase("-ka") || args[pos].equalsIgnoreCase("--keepalive")) {
            keepAliveValue = Integer.parseInt(args[pos + 1]);
            pos++;
        } else if (args[pos].equalsIgnoreCase("--stateful")) {
            stateful = true;
        } else if (args[pos].equalsIgnoreCase("--active")) {
            stateful = true;
            active = true;
        } else if (args[pos].equalsIgnoreCase("--instant")) {
            stateful = true;
            instant = true;
        } else {
            LOG.warn("WARNING: Unrecognized argument: {}", args[pos]);
        }
        pos++;
    }
    if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * KA_TO_DEADTIMER_RATIO) {
        LOG.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
    }
    if (deadTimerValue == 0) {
        deadTimerValue = keepAliveValue * KA_TO_DEADTIMER_RATIO;
    }
    final List<PCEPCapability> caps = new ArrayList<>();
    caps.add(new PCEPStatefulCapability(stateful, active, instant, false, false, false, false));
    final PCEPSessionProposalFactory spf = new BasePCEPSessionProposalFactory(deadTimerValue, keepAliveValue, caps);
    try (StatefulActivator activator07 = new StatefulActivator()) {
        activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
        final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(spf, MAX_UNKNOWN_MESSAGES), new NioEventLoopGroup(), new NioEventLoopGroup());
        dispatcher.createServer(new TestToolPCEPDispatcherDependencies(address)).get();
    }
}
Also used : StatefulActivator(org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator) PCEPDispatcherImpl(org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl) PCEPStatefulCapability(org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability) DefaultPCEPSessionNegotiatorFactory(org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory) InetSocketAddress(java.net.InetSocketAddress) BasePCEPSessionProposalFactory(org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory) ArrayList(java.util.ArrayList) BasePCEPSessionProposalFactory(org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory) PCEPSessionProposalFactory(org.opendaylight.protocol.pcep.PCEPSessionProposalFactory) PCEPCapability(org.opendaylight.protocol.pcep.PCEPCapability) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with PCEPDispatcherImpl

use of org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl in project bgpcep by opendaylight.

the class PCCDispatcherImplTest method testClientReconnect.

@Test
public void testClientReconnect() throws Exception {
    final Future<PCEPSession> futureSession = this.dispatcher.createClient(this.serverAddress, 1, new TestingSessionListenerFactory(), this.nf, KeyMapping.getKeyMapping(), this.clientAddress);
    final TestingSessionListenerFactory slf = new TestingSessionListenerFactory();
    doReturn(slf).when(this.dispatcherDependencies).getListenerFactory();
    final ChannelFuture futureServer = this.pcepDispatcher.createServer(this.dispatcherDependencies);
    waitFutureSuccess(futureServer);
    final Channel channel = futureServer.channel();
    Assert.assertNotNull(futureSession.get());
    checkSessionListenerNotNull(slf, this.clientAddress.getHostString());
    final TestingSessionListener sl = checkSessionListenerNotNull(slf, this.clientAddress.getAddress().getHostAddress());
    Assert.assertNotNull(sl.getSession());
    Assert.assertTrue(sl.isUp());
    channel.close().get();
    closeEventLoopGroups();
    this.workerGroup = new NioEventLoopGroup();
    this.bossGroup = new NioEventLoopGroup();
    this.pcepDispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), this.nf, this.bossGroup, this.workerGroup);
    final TestingSessionListenerFactory slf2 = new TestingSessionListenerFactory();
    doReturn(slf2).when(this.dispatcherDependencies).getListenerFactory();
    final ChannelFuture future2 = this.pcepDispatcher.createServer(this.dispatcherDependencies);
    waitFutureSuccess(future2);
    final Channel channel2 = future2.channel();
    final TestingSessionListener sl2 = checkSessionListenerNotNull(slf2, this.clientAddress.getAddress().getHostAddress());
    Assert.assertNotNull(sl2.getSession());
    Assert.assertTrue(sl2.isUp());
    channel2.close();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) PCEPDispatcherImpl(org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl) PCEPSession(org.opendaylight.protocol.pcep.PCEPSession) Channel(io.netty.channel.Channel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.Test)

Example 3 with PCEPDispatcherImpl

use of org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl in project bgpcep by opendaylight.

the class PCCDispatcherImplTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    this.workerGroup = new NioEventLoopGroup();
    this.bossGroup = new NioEventLoopGroup();
    this.dispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry());
    this.pcepDispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), this.nf, this.bossGroup, this.workerGroup);
    this.serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
    this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
    doReturn(KeyMapping.getKeyMapping()).when(this.dispatcherDependencies).getKeys();
    doReturn(this.serverAddress).when(this.dispatcherDependencies).getAddress();
    doReturn(null).when(this.dispatcherDependencies).getPeerProposal();
}
Also used : PCCDispatcherImpl(org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl) PCEPDispatcherImpl(org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Before(org.junit.Before)

Example 4 with PCEPDispatcherImpl

use of org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl in project bgpcep by opendaylight.

the class PCCMockCommon method setUp.

@Before
public void setUp() {
    final BasePCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE, getCapabilities());
    final DefaultPCEPSessionNegotiatorFactory nf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
    this.extensionProvider = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
    this.messageRegistry = this.extensionProvider.getMessageHandlerRegistry();
    this.pceDispatcher = new PCEPDispatcherImpl(this.messageRegistry, nf, new NioEventLoopGroup(), new NioEventLoopGroup());
}
Also used : PCEPDispatcherImpl(org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl) DefaultPCEPSessionNegotiatorFactory(org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory) BasePCEPSessionProposalFactory(org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Before(org.junit.Before)

Aggregations

NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)4 PCEPDispatcherImpl (org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl)4 Before (org.junit.Before)2 BasePCEPSessionProposalFactory (org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory)2 DefaultPCEPSessionNegotiatorFactory (org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory)2 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 PCEPCapability (org.opendaylight.protocol.pcep.PCEPCapability)1 PCEPSession (org.opendaylight.protocol.pcep.PCEPSession)1 PCEPSessionProposalFactory (org.opendaylight.protocol.pcep.PCEPSessionProposalFactory)1 PCEPStatefulCapability (org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability)1 StatefulActivator (org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator)1 PCCDispatcherImpl (org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl)1