Search in sources :

Example 1 with PCEPSessionProposalFactory

use of org.opendaylight.protocol.pcep.PCEPSessionProposalFactory 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 PCEPSessionProposalFactory

use of org.opendaylight.protocol.pcep.PCEPSessionProposalFactory in project bgpcep by opendaylight.

the class PCEPDispatcherImplTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final List<PCEPCapability> capList = new ArrayList<>();
    final PCEPSessionProposalFactory sessionProposal = new BasePCEPSessionProposalFactory(DEAD_TIMER, KEEP_ALIVE, capList);
    final EventLoopGroup eventLoopGroup;
    if (Epoll.isAvailable()) {
        eventLoopGroup = new EpollEventLoopGroup();
    } else {
        eventLoopGroup = new NioEventLoopGroup();
    }
    final MessageRegistry msgReg = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry();
    this.dispatcher = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), eventLoopGroup, eventLoopGroup);
    doReturn(KeyMapping.getKeyMapping()).when(this.dispatcherDependencies).getKeys();
    doReturn(null).when(this.dispatcherDependencies).getPeerProposal();
    doReturn("mockChannel").when(this.mockChannel).toString();
    final PCEPDispatcherImpl dispatcher2 = new PCEPDispatcherImpl(msgReg, new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), eventLoopGroup, eventLoopGroup);
    this.disp2Spy = Mockito.spy(dispatcher2);
    this.pccMock = new PCCMock(new DefaultPCEPSessionNegotiatorFactory(sessionProposal, 0), new PCEPHandlerFactory(msgReg));
}
Also used : ArrayList(java.util.ArrayList) PCEPSessionProposalFactory(org.opendaylight.protocol.pcep.PCEPSessionProposalFactory) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) MessageRegistry(org.opendaylight.protocol.pcep.spi.MessageRegistry) PCEPCapability(org.opendaylight.protocol.pcep.PCEPCapability) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Before(org.junit.Before)

Example 3 with PCEPSessionProposalFactory

use of org.opendaylight.protocol.pcep.PCEPSessionProposalFactory in project bgpcep by opendaylight.

the class PCCMock method main.

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.getHost(), serverHostAndPort.getPortOrDefault(12345));
    final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
    try (PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry())) {
        pccDispatcher.createClient(serverAddr, -1, SimpleSessionListener::new, snf, KeyMapping.getKeyMapping(), clientAddr).get();
    }
}
Also used : PCCDispatcherImpl(org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl) HostAndPort(com.google.common.net.HostAndPort) DefaultPCEPSessionNegotiatorFactory(org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory) InetSocketAddress(java.net.InetSocketAddress) BasePCEPSessionProposalFactory(org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory) ArrayList(java.util.ArrayList) PCEPCapability(org.opendaylight.protocol.pcep.PCEPCapability) BasePCEPSessionProposalFactory(org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory) PCEPSessionProposalFactory(org.opendaylight.protocol.pcep.PCEPSessionProposalFactory) DefaultPCEPSessionNegotiatorFactory(org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory) PCEPSessionNegotiatorFactory(org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory)

Aggregations

ArrayList (java.util.ArrayList)3 PCEPCapability (org.opendaylight.protocol.pcep.PCEPCapability)3 PCEPSessionProposalFactory (org.opendaylight.protocol.pcep.PCEPSessionProposalFactory)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 InetSocketAddress (java.net.InetSocketAddress)2 BasePCEPSessionProposalFactory (org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory)2 DefaultPCEPSessionNegotiatorFactory (org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory)2 HostAndPort (com.google.common.net.HostAndPort)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 Before (org.junit.Before)1 PCEPSessionNegotiatorFactory (org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory)1 PCEPStatefulCapability (org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability)1 StatefulActivator (org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator)1 PCEPDispatcherImpl (org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl)1 PCCDispatcherImpl (org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl)1 MessageRegistry (org.opendaylight.protocol.pcep.spi.MessageRegistry)1