dc2d8bcbd4f24c9f08f5eed5600e54bafe97efa2
[bgpcep.git] / pcep / testtool / src / test / java / org / opendaylight / protocol / pcep / testtool / PCCMock.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.testtool;
9
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.concepts.KeyMapping;
17 import org.opendaylight.protocol.pcep.PCEPCapability;
18 import org.opendaylight.protocol.pcep.PCEPSession;
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;
26
27 public final class PCCMock {
28
29     private PCCMock() {
30         throw new UnsupportedOperationException();
31     }
32
33     public static void main(final String[] args) throws InterruptedException, ExecutionException {
34         Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
35         final List<PCEPCapability> caps = new ArrayList<>();
36         final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);
37         final PCEPSessionNegotiatorFactory<? extends PCEPSession> snf
38             = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
39         final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
40         final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHost(), serverHostAndPort
41                 .getPortOrDefault(12345));
42         final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
43
44         try (PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext
45                 .getSingletonInstance().getMessageHandlerRegistry())) {
46             pccDispatcher.createClient(serverAddr, -1, SimpleSessionListener::new, snf,
47                     KeyMapping.getKeyMapping(), clientAddr).get();
48         }
49     }
50 }