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.bgpmanager.commands;
11 import org.apache.karaf.shell.commands.*;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.bgpmanager.BgpManager;
14 import org.opendaylight.bgpmanager.thrift.gen.qbgpConstants;
16 @Command(scope = "odl", name = "bgp-network",
17 description = "Add or delete BGP static routes")
18 public class Network extends OsgiCommandSupport {
19 private static final String RD = "--rd";
20 private static final String PFX = "--prefix";
21 private static final String NH = "--nexthop";
22 private static final String LB = "--label";
24 @Argument(name="add|del", description="The desired operation",
25 required=true, multiValued = false)
26 private String action = null;
28 @Option(name=RD, aliases={"-r"},
29 description="Route distinguisher",
30 required=false, multiValued=false)
31 private String rd = null;
33 @Option(name=PFX, aliases={"-p"},
34 description="prefix/length",
35 required=false, multiValued=false)
36 private String pfx = null;
38 @Option(name=NH, aliases={"-n"},
39 description="Nexthop",
40 required=false, multiValued=false)
41 private String nh = null;
43 @Option(name=LB, aliases={"-l"},
45 required=false, multiValued=false)
46 private String lbl = null;
48 private Object usage() {
50 "usage: bgp-network ["+RD+" rd] ["+PFX+" prefix/len] ["
51 +NH+" nexthop] ["+LB+" label] <add|del>");
56 protected Object doExecute() throws Exception {
57 if (!Commands.bgpRunning()) {
60 BgpManager bm = Commands.getBgpManager();
63 int label = qbgpConstants.LBL_EXPLICIT_NULL;
65 System.err.println("error: "+PFX+" is needed");
69 System.err.println("error: "+NH+" is needed");
72 //todo: syntactic validation of prefix
73 if (!Commands.isValid(nh, Commands.IPADDR, NH)) {
77 if (!Commands.isValid(lbl, Commands.INT, LB)) {
80 label = Integer.valueOf(lbl);
82 } else if (rd == null) {
83 System.err.println("error: "+RD+" is needed");
86 bm.addPrefix(rd, pfx, nh, label);
90 System.err.println("error: "+PFX+" is needed");
93 if (nh != null || lbl != null) {
94 System.err.println("note: some option(s) not needed; ignored");
96 bm.deletePrefix(rd, pfx);