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 static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.MAX_DETECT_MULT;
12 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.MIN_DETECT_MULT;
13 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.MIN_RX_MAX;
14 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.MIN_RX_MIN;
15 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.MIN_TX_MAX;
16 import static org.opendaylight.netvirt.bgpmanager.oam.BgpConstants.MIN_TX_MIN;
18 import java.io.PrintStream;
20 import org.apache.karaf.shell.commands.Argument;
21 import org.apache.karaf.shell.commands.Command;
22 import org.apache.karaf.shell.commands.Option;
23 import org.apache.karaf.shell.console.OsgiCommandSupport;
24 import org.opendaylight.netvirt.bgpmanager.BgpManager;
25 import org.opendaylight.netvirt.bgpmanager.oam.BgpConstants;
27 @Command(scope = "odl", name = "bfd-config",
28 description = "Add or delete BFD neighbor")
29 public class Bfd extends OsgiCommandSupport {
30 private static final String RX = "--min-rx";
31 private static final String TX = "--min-tx";
32 private static final String DM = "--detect-mult";
33 private static final String MH = "--multi-hop";
35 @Argument(index = 0, name = "add|del", description = "The desired operation",
36 required = true, multiValued = false)
39 @Option(name = RX, aliases = {"-r"},
40 description = "Minimum BFD receive interval in millisec"
41 + "<" + MIN_RX_MIN + "-" + MIN_RX_MAX + ">",
42 required = false, multiValued = false)
45 @Option(name = TX, aliases = {"-t"},
46 description = "Minimum BFD transmit interval in millisec"
47 + "<" + MIN_TX_MIN + "-" + MIN_TX_MAX + ">",
48 required = false, multiValued = false)
51 @Option(name = DM, aliases = {"-d"},
52 description = "No of packet miss for marking session down"
53 + "<" + MIN_DETECT_MULT + "-" + MAX_DETECT_MULT + ">",
54 required = false, multiValued = false)
55 String detectMult = null;
57 @Option(name = MH, aliases = {"-m"},
58 description = "Multi-Hop or Single-Hop BFD"
60 required = false, multiValued = false)
61 String multiHop = null;
63 private final BgpManager bgpManager;
65 public Bfd(BgpManager bgpManager) {
66 this.bgpManager = bgpManager;
69 private Object usage() {
70 session.getConsole().println(
71 "usage: bgp-config [" + RX + " min-rx-interval] [" + TX + " min-tx-interval] ["
72 + DM + " detect-multiplier] [" + MH + " true|false] <add|del>");
77 protected Object doExecute() throws Exception {
78 PrintStream ps = session.getConsole();
81 int minrx = BgpConstants.BFD_DEFAULT_MIN_RX;
82 int mintx = BgpConstants.BFD_DEFAULT_MIN_TX;
83 int detectmult = BgpConstants.BFD_DEFAULT_DETECT_MULT;
84 boolean multihop = true;
86 if (!Commands.isValid(ps, minRX, Commands.Validators.INT, RX)) {
89 minrx = Integer.parseInt(minRX);
90 if (minrx < MIN_RX_MIN || minrx > MIN_RX_MAX) {
91 ps.println("error: value of RX should be between 50 and 50000");
98 if (!Commands.isValid(ps, minTX, Commands.Validators.INT, TX)) {
101 mintx = Integer.parseInt(minTX);
102 if (mintx < MIN_TX_MIN || mintx > MIN_TX_MAX) {
103 ps.println("error: value of TX should be between 1000 and 4294000");
109 if (detectMult != null) {
110 if (!Commands.isValid(ps, detectMult, Commands.Validators.INT, DM)) {
113 detectmult = Integer.parseInt(detectMult);
114 if (detectmult < MIN_DETECT_MULT || detectmult > MAX_DETECT_MULT) {
115 ps.println("error: value of detectMult should be between 2 to 255");
121 if (multiHop != null) {
122 if (!multiHop.equals("true") && !multiHop.equals("false")) {
123 ps.println("error: " + MH + "must be true or false");
126 if (multiHop.equals("false")) {
131 bgpManager.startBfd(detectmult, minrx, mintx, multihop);
135 if (detectMult != null || minRX != null || minTX != null || multiHop != null) {
136 session.getConsole().println("note: some option(s) not needed; ignored");
138 bgpManager.stopBfd();