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.bgp.testtool;
10 import io.netty.util.concurrent.GlobalEventExecutor;
12 import java.io.IOException;
13 import java.net.InetAddress;
14 import java.net.InetSocketAddress;
16 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
17 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
18 import org.opendaylight.protocol.bgp.parser.impl.SingletonProviderContext;
19 import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
20 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
21 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
22 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Starter class for testing.
33 private final static Logger logger = LoggerFactory.getLogger(Main.class);
35 public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
36 + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
37 + "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
38 + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
40 "\t-as\n" + "\t\t value of AS in the initial open message\n\n" +
42 "\t-h, --holdtimer\n" + "\t\tin seconds, value of the desired holdtimer\n"
43 + "\t\tAccording to RFC4271, recommended value for deadtimer is 90 seconds.\n"
44 + "\t\tIf not set, this will be the default value.\n\n" +
46 "\t--help\n" + "\t\tdisplay this help and exits\n\n" +
48 "With no parameters, this help is printed.";
50 BGPDispatcherImpl dispatcher;
52 public Main() throws IOException {
53 this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(SingletonProviderContext.getInstance().getMessageRegistry()));
56 public static void main(final String[] args) throws NumberFormatException, IOException {
57 if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
58 System.out.println(Main.usage);
62 InetSocketAddress address = null;
63 short holdTimerValue = 90;
67 while (i < args.length) {
68 if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) {
69 final String[] ip = args[i + 1].split(":");
70 address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.valueOf(ip[1]));
72 } else if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--holdtimer")) {
73 holdTimerValue = Short.valueOf(args[i + 1]);
75 } else if (args[i].equalsIgnoreCase("-as")) {
76 as = new AsNumber(Long.valueOf(args[i + 1]));
79 System.out.println("WARNING: Unrecognized argument: " + args[i]);
84 final Main m = new Main();
86 final BGPSessionListener sessionListener = new TestingListener();
88 final BGPSessionProposalImpl prop = new BGPSessionProposalImpl(holdTimerValue, as.getValue().intValue(), new Ipv4Address("25.25.25.2"));
90 final BGPSessionPreferences proposal = prop.getProposal();
92 logger.debug("{} {} {}", address, sessionListener, proposal);
94 final InetSocketAddress addr = address;
95 m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));