X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Ftesttool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Ftesttool%2FMain.java;h=e593770b0971661c953125b7f9a209e39e32d3f2;hb=e6d9fbf96737ba5d69a77ac79127b348d13d6a7a;hp=44ebe77f1c201c747787aeeea33ff76e1df2caaf;hpb=5a544d0ea2e3719e814d9e071f72920349fa5acd;p=bgpcep.git diff --git a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java index 44ebe77f1c..e593770b09 100644 --- a/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java +++ b/bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java @@ -7,90 +7,111 @@ */ package org.opendaylight.protocol.bgp.testtool; +import io.netty.channel.nio.NioEventLoopGroup; import io.netty.util.concurrent.GlobalEventExecutor; - -import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; - -import org.opendaylight.protocol.bgp.parser.BGPSessionListener; -import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; +import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl; import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl; +import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences; -import org.opendaylight.protocol.concepts.ASNumber; -import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener; import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Starter class for testing. */ -public class Main { +public final class Main { + + private static final Logger LOG = LoggerFactory.getLogger(Main.class); + + private static final String USAGE = "DESCRIPTION:\n" + + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n" + + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n" + + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" + + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" + + + "\t-as\n" + "\t\t value of AS in the initial open message\n\n" + + + "\t-h, --holdtimer\n" + "\t\tin seconds, value of the desired holdtimer\n" + + "\t\tAccording to RFC4271, recommended value for deadtimer is 90 seconds.\n" + + "\t\tIf not set, this will be the default value.\n\n" + - private final static Logger logger = LoggerFactory.getLogger(Main.class); + "\t--help\n" + "\t\tdisplay this help and exits\n\n" + - public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections " - + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n" - + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" - + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" + + "With no parameters, this help is printed."; - "\t-as\n" + "\t\t value of AS in the initial open message\n\n" + + private final BGPDispatcherImpl dispatcher; - "\t-h, --holdtimer\n" + "\t\tin seconds, value of the desired holdtimer\n" - + "\t\tAccording to RFC4271, recommended value for deadtimer is 90 seconds.\n" - + "\t\tIf not set, this will be the default value.\n\n" + + private static final int INITIAL_HOLD_TIME = 90; - "\t--help\n" + "\t\tdisplay this help and exits\n\n" + + private static final int RECONNECT_MILLIS = 5000; - "With no parameters, this help is printed."; + private Main() { + this.dispatcher = new BGPDispatcherImpl(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup()); + } - BGPDispatcherImpl dispatcher; + public static void main(final String[] args) throws UnknownHostException { + if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) { + LOG.info(Main.USAGE); + return; + } - public Main() throws IOException { - this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl()); - } + InetSocketAddress address = null; + short holdTimerValue = INITIAL_HOLD_TIME; + AsNumber as = null; - public static void main(final String[] args) throws NumberFormatException, IOException { - if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) { - System.out.println(Main.usage); - return; - } + int i = 0; + while (i < args.length) { + if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) { + final String[] ip = args[i + 1].split(":"); + address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1])); + i++; + } else if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--holdtimer")) { + holdTimerValue = Short.valueOf(args[i + 1]); + i++; + } else if (args[i].equalsIgnoreCase("-as")) { + as = new AsNumber(Long.valueOf(args[i + 1])); + i++; + } else { + LOG.error("WARNING: Unrecognized argument: {}", args[i]); + } + i++; + } - InetSocketAddress address = null; - short holdTimerValue = 90; - ASNumber as = null; + final Main m = new Main(); - int i = 0; - while (i < args.length) { - if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) { - final String[] ip = args[i + 1].split(":"); - address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.valueOf(ip[1])); - i++; - } else if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--holdtimer")) { - holdTimerValue = Short.valueOf(args[i + 1]); - i++; - } else if (args[i].equalsIgnoreCase("-as")) { - as = new ASNumber(Long.valueOf(args[i + 1])); - i++; - } else { - System.out.println("WARNING: Unrecognized argument: " + args[i]); - } - i++; - } + final BGPSessionListener sessionListener = new TestingListener(); - final Main m = new Main(); + final Map, Class> tables = new HashMap<>(); + tables.put(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class); + tables.put(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class); - final BGPSessionListener sessionListener = new TestingListener(); + final BGPSessionProposalImpl prop = new BGPSessionProposalImpl(holdTimerValue, as, new Ipv4Address("25.25.25.2"), tables, as); - final BGPSessionProposalImpl prop = new BGPSessionProposalImpl(holdTimerValue, as, new IPv4Address(InetAddress.getByName("25.25.25.2"))); + final BGPSessionPreferences proposal = prop.getProposal(); - final BGPSessionPreferences proposal = prop.getProposal(); + LOG.debug("{} {} {}", address, sessionListener, proposal); - logger.debug("{} {} {}", address, sessionListener, proposal); + final InetSocketAddress addr = address; + final StrictBGPPeerRegistry strictBGPPeerRegistry = new StrictBGPPeerRegistry(); + strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(address), sessionListener, proposal); - final InetSocketAddress addr = address; - m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)); - } + m.dispatcher.createClient(addr, strictBGPPeerRegistry, + new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS)); + } }