2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.testtool;
10 import com.google.common.base.Preconditions;
11 import com.google.common.net.HostAndPort;
12 import java.net.InetSocketAddress;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.concurrent.ExecutionException;
16 import org.opendaylight.protocol.pcep.PCEPCapability;
17 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
18 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
19 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
20 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
21 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
22 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
23 import org.opendaylight.protocol.util.InetSocketAddressUtil;
25 public class PCCMock {
27 public static void main(final String[] args) throws InterruptedException, ExecutionException {
28 Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
29 final List<PCEPCapability> caps = new ArrayList<>();
30 final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);
31 final PCEPSessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
32 final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
33 final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHostText(), serverHostAndPort
34 .getPortOrDefault(12345));
35 final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
37 try (final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry())) {
38 pccDispatcher.createClient(serverAddr, -1, SimpleSessionListener::new, snf, null, clientAddr).get();