Bump to odlparent-3.0.2 and yangtools-2.0.0
[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.PCEPSessionNegotiatorFactory;
19 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
20 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
21 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
22 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl;
23 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
24 import org.opendaylight.protocol.util.InetSocketAddressUtil;
25
26 public final class PCCMock {
27
28     private PCCMock() {
29         throw new UnsupportedOperationException();
30     }
31
32     public static void main(final String[] args) throws InterruptedException, ExecutionException {
33         Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
34         final List<PCEPCapability> caps = new ArrayList<>();
35         final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps);
36         final PCEPSessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
37         final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
38         final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHost(), serverHostAndPort
39                 .getPortOrDefault(12345));
40         final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);
41
42         try (PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext
43                 .getSingletonInstance().getMessageHandlerRegistry())) {
44             pccDispatcher.createClient(serverAddr, -1, SimpleSessionListener::new, snf,
45                     KeyMapping.getKeyMapping(), clientAddr).get();
46         }
47     }
48 }