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.BgpConfigurationManager;
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 BgpConfigurationManager bgpConfigurationManager;
55 public Multipath(BgpConfigurationManager bgpConfigurationManager) {
56 this.bgpConfigurationManager = bgpConfigurationManager;
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 (addrFamily.equals("vpnv6")) {
71 afi = af_afi.findByValue(2);
72 safi = af_safi.findByValue(5);
73 } else if (addrFamily.equals("evpn")) {
74 afi = af_afi.findByValue(3);
75 safi = af_safi.findByValue(6);
76 } else if (addrFamily.equals("lu")) {
77 afi = af_afi.findByValue(1);
78 safi = af_safi.findByValue(4);
80 afi = af_afi.findByValue(1);
81 safi = af_safi.findByValue(5);
85 if (maxpath != null) {
86 int imaxpath = Integer.parseInt(maxpath);
87 if (imaxpath < MIN_MAXPATH || imaxpath > MAX_MAXPATH) {
88 session.getConsole().println("error: " + MAXPATH + " range[" + MIN_MAXPATH + " - " + MAX_MAXPATH + "]");
93 if (multipathEnable != null) {
95 switch (multipathEnable) {
97 bgpConfigurationManager.setMultipathStatus(afi, safi, true);
100 bgpConfigurationManager.setMultipathStatus(afi, safi, false);
103 if (rd != null && maxpath != null) {
104 bgpConfigurationManager.setMultipaths(rd, Integer.parseInt(maxpath));
116 private Object usage() {
117 session.getConsole().println("odl:multipath -f lu <enable|disable> \n"
118 + "odl:multipath -f lu -r <rd> -n <maxpath> setmaxpath");