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.PCEPSessionListener;
18 import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
19 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory;
20 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
21 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
22 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
23 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
24 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
25 import org.opendaylight.protocol.util.InetSocketAddressUtil;
27 public class PCCMock {
29 public static void main(final String[] args) throws InterruptedException, ExecutionException {
30 Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
31 final List<PCEPCapability> caps = new ArrayList<>();
32 final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);
33 final PCEPSessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
34 final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
35 final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHostText(), serverHostAndPort
36 .getPortOrDefault(12345));
37 final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
39 try (final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry())) {
40 pccDispatcher.createClient(serverAddr, -1, new PCEPSessionListenerFactory() {
42 public PCEPSessionListener getSessionListener() {
43 return new SimpleSessionListener();
45 }, snf, null, clientAddr).get();