X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgpmanager%2Fbgpmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fbgpmanager%2Fcommands%2FConnect.java;fp=bgpmanager%2Fbgpmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fbgpmanager%2Fcommands%2FConnect.java;h=47bec2afabf828aa2efac5576f4d26e981ba1cce;hb=46a65688345efa44e3c726ad11c1cc923878e708;hp=0000000000000000000000000000000000000000;hpb=b2dd97a5264bd734b036b8558ae1598d32781c88;p=vpnservice.git diff --git a/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/commands/Connect.java b/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/commands/Connect.java new file mode 100644 index 00000000..47bec2af --- /dev/null +++ b/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/bgpmanager/commands/Connect.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.bgpmanager.commands; + +import org.apache.karaf.shell.commands.*; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.opendaylight.bgpmanager.BgpManager; + +@Command(scope = "odl", name = "bgp-connect", + description = "Add or delete client connection to BGP Config Server") +public class Connect extends OsgiCommandSupport { + private static final String HOST = "--host"; + private static final String PORT = "--port"; + + @Argument(name="add|del", description="The desired operation", + required=true, multiValued = false) + String action = null; + + @Option(name=HOST, aliases={"-h"}, + description="IP address of the server", + required=false, multiValued=false) + String host = null; + + @Option(name=PORT, aliases={"-p"}, + description="Thrift port", required=false, + multiValued=false) + String port = null; + + private Object usage() { + System.err.println( + "usage: bgp-connect ["+HOST+" h] ["+PORT+" p] "); + return null; + } + + @Override + protected Object doExecute() throws Exception { + if (!Commands.bgpRunning()) { + return null; + } + BgpManager bm = Commands.getBgpManager(); + switch (action) { + case "add" : + if (host == null || port == null) { + System.err.println("error: "+HOST+" and "+PORT+" needed"); + return null; + } + if (!Commands.isValid(host, Commands.IPADDR, HOST) + || !Commands.isValid(port, Commands.INT, PORT)) { + return null; + } + // check: already connected? + bm.startConfig(host, Integer.valueOf(port)); + break; + case "del" : + if (host != null || port != null) { + System.err.println("note: option(s) not needed; ignored"); + } + // check: nothing to stop? + bm.stopConfig(); + break; + default : + return usage(); + } + return null; + } +}