2 * Copyright (c) 2017 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 org.apache.karaf.shell.commands.Argument;
12 import org.apache.karaf.shell.commands.Command;
13 import org.apache.karaf.shell.commands.Option;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.netvirt.bgpmanager.BgpManager;
16 import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi;
17 import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi;
19 @Command(scope = "odl", name = "multipath", description = "Enable/Disable multipaths")
20 public class Multipath extends OsgiCommandSupport {
22 private static final String AF = "--address-family";
23 private static final String RD = "--rd";
24 private static final String MAXPATH = "--maxpath";
25 private static final int MIN_MAXPATH = 1;
26 private static final int MAX_MAXPATH = 64;
28 @Option(name = RD, aliases = { "-r" },
34 @Option(name = MAXPATH, aliases = { "-n" },
35 description = "max number of paths",
40 @Option(name = AF, aliases = {"-f"},
41 description = "Address family",
42 required = false, multiValued = false)
47 @Argument(name = "enable|disable|setmaxpath",
48 description = "The desired operation",
49 required = true, multiValued = false)
51 String multipathEnable;
53 private final BgpManager bgpManager;
55 public Multipath(BgpManager bgpManager) {
56 this.bgpManager = bgpManager;
60 protected Object doExecute() {
61 af_afi afi = af_afi.findByValue(1);
62 af_safi safi = af_safi.findByValue(5);
64 if (addrFamily != null) {
65 if (!addrFamily.equals("lu") && !addrFamily.equals("vpnv6")
66 && !addrFamily.equals("evpn") && !addrFamily.equals("vpnv4")) {
67 session.getConsole().println("error: " + AF + " must be lu/evpn/vpnv4/vpnv6 ");
70 if (multipathEnable != null
71 && multipathEnable.equals("setmaxpath")) {
72 session.getConsole().println("error: " + AF + "can be configured with enable/disable only");
75 if (addrFamily.equals("vpnv6")) {
76 afi = af_afi.findByValue(2);
77 safi = af_safi.findByValue(5);
78 } else if (addrFamily.equals("evpn")) {
79 afi = af_afi.findByValue(3);
80 safi = af_safi.findByValue(6);
81 } else if (addrFamily.equals("lu")) {
82 afi = af_afi.findByValue(1);
83 safi = af_safi.findByValue(4);
85 afi = af_afi.findByValue(1);
86 safi = af_safi.findByValue(5);
90 if (maxpath != null) {
91 int imaxpath = Integer.parseInt(maxpath);
92 if (imaxpath < MIN_MAXPATH || imaxpath > MAX_MAXPATH) {
93 session.getConsole().println("error: " + MAXPATH + " range[" + MIN_MAXPATH + " - " + MAX_MAXPATH + "]");
96 if (multipathEnable != null
97 && (multipathEnable.equals("enable") || multipathEnable.equals("disable"))) {
98 session.getConsole().println("error: " + MAXPATH + "can be configured with setmaxpath only");
103 if (multipathEnable != null) {
104 switch (multipathEnable) {
106 bgpManager.enableMultipath(afi, safi);
109 bgpManager.disableMultipath(afi, safi);
112 if (rd != null && maxpath != null) {
113 bgpManager.setMultipaths(rd, Integer.parseInt(maxpath));
124 private Object usage() {
125 session.getConsole().println("odl:multipath -f lu <enable|disable> \n"
126 + "odl:multipath -f lu -r <rd> -n <maxpath> setmaxpath");