2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.netvirt.bgpmanager.commands;
11 import java.util.List;
12 import org.apache.karaf.shell.commands.Argument;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.opendaylight.netvirt.bgpmanager.BgpManager;
17 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp;
18 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors;
20 @Command(scope = "odl", name = "bgp-rtr",
21 description = "Add or delete BGP router instance")
22 public class Router extends OsgiCommandSupport {
23 private static final String AS = "--as-number";
24 private static final String RID = "--router-id";
25 private static final String SP = "--stale-path-time";
26 private static final String FB = "--f-bit";
28 @Argument(name = "add|del", description = "The desired operation",
29 required = true, multiValued = false)
30 private String action = null;
32 @Option(name = AS, aliases = {"-a"},
33 description = "AS number",
34 required = false, multiValued = false)
35 private String asNum = null;
37 @Option(name = RID, aliases = {"-r"},
38 description = "Router ID",
39 required = false, multiValued = false)
40 private String rid = null;
42 @Option(name = SP, aliases = {"-s"},
43 description = "Stale-path time",
44 required = false, multiValued = false)
45 private String spt = null;
47 @Option(name = FB, aliases = {"-f"},
48 description = "F-bit",
49 required = false, multiValued = false)
50 private String fbit = null;
52 private Object usage() {
53 session.getConsole().println(
54 "usage: bgp-rtr [" + AS + " as-number] [" + RID + " router-id] ["
55 + SP + " stale-path-time] [" + FB + " on|off] <add | del>");
60 protected Object doExecute() throws Exception {
61 if (!Commands.bgpRunning(session.getConsole())) {
64 BgpManager bm = Commands.getBgpManager();
67 // check: rtr already running?
72 session.getConsole().println("error: " + AS + " is needed");
75 if (!Commands.isValid(session.getConsole(), asNum, Commands.Validators.INT, AS)) {
78 asn = Long.valueOf(asNum);
79 if (rid != null && !Commands.isValid(session.getConsole(), rid, Commands.Validators.IPADDR, RID)) {
83 if (!Commands.isValid(session.getConsole(), spt, Commands.Validators.INT, SP)) {
86 stalePath = Integer.valueOf(spt);
98 session.getConsole().println("error: " + FB + " must be on or off");
102 bm.startBgp(asn, rid, stalePath, fb);
105 // check: nothing to stop?
106 if (asNum != null || rid != null || spt != null || fbit != null) {
107 session.getConsole().println("note: option(s) not needed; ignored");
109 Bgp conf = bm.getConfig();
111 session.getConsole().println("error : no BGP configs present");
114 List<Neighbors> nbrs = conf.getNeighbors();
115 if (nbrs != null && nbrs.size() > 0) {
116 session.getConsole().println("error: all BGP congiguration must be deleted "
117 + "before stopping the router instance");