Revert "Revert "Minor Checkstyle fix Custom Import Order error""
[netvirt.git] / vpnservice / bgpmanager / bgpmanager-impl / src / main / java / org / opendaylight / netvirt / bgpmanager / commands / Multipath.java
1 /*
2  * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netvirt.bgpmanager.commands;
10
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.omg.CORBA.Object;
16 import org.opendaylight.netvirt.bgpmanager.BgpManager;
17 import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi;
18 import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi;
19
20 @Command(scope = "odl", name = "multipath", description = "Enable/Disable multipaths")
21 public class Multipath extends OsgiCommandSupport {
22
23     private static final String AF = "--address-family";
24     private static final String RD = "--rd";
25     private static final String MAXPATH = "--maxpath";
26
27     @Option(name = RD, aliases = { "-r" },
28             description = "rd",
29             required = false,
30             multiValued = false)
31     String rd;
32
33     @Option(name = MAXPATH, aliases = { "-n" },
34             description = "max number of paths",
35             required = false,
36             multiValued = false)
37     String maxpath;
38
39     @Option(name = AF, aliases = {"-f"},
40             description = "Address family",
41             required = true, multiValued = false)
42
43     String addrFamily;
44
45
46     @Argument(name = "enable|disable|setmaxpath",
47             description = "The desired operation",
48             required = true, multiValued = false)
49
50     String multipathEnable;
51
52     @Override
53     protected Object doExecute() throws Exception {
54
55         if (!Commands.bgpRunning(session.getConsole())) {
56             return null;
57         }
58
59         BgpManager bm = Commands.getBgpManager();
60
61         af_afi afi = null;
62         af_safi safi = null;
63
64         if (addrFamily != null) {
65             if (!addrFamily.equals("lu"))  {
66                 session.getConsole().println("error: " + AF + " must be lu");
67                 return null;
68             }
69
70             // for WP 3 Qbgp, only IP/MPLS_VPN supported
71             afi = af_afi.AFI_IP;
72             safi = af_safi.SAFI_MPLS_VPN;
73         }
74
75         if (multipathEnable != null) {
76
77             switch (multipathEnable) {
78                 case "enable":
79                     bm.enableMultipath(afi, safi);
80                     break;
81                 case "disable":
82                     bm.disableMultipath(afi, safi);
83                     break;
84                 case "setmaxpath":
85                     if (rd != null && maxpath != null) {
86                         bm.multipaths(rd, Integer.parseInt(maxpath));
87                     }
88                     break;
89
90                 default:
91                     return usage();
92             }
93         }
94
95         return null;
96     }
97
98     private Object usage() {
99         session.getConsole().println("odl:multipath  -f lu <enable|disable> \n"
100                 + "odl:multipath -f lu -r <rd> -n <maxpath> setmaxpath");
101         return null;
102     }
103 }
104