Add missing annotation dependencies for Java 11
[netvirt.git] / 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.opendaylight.netvirt.bgpmanager.BgpConfigurationManager;
16 import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_afi;
17 import org.opendaylight.netvirt.bgpmanager.thrift.gen.af_safi;
18
19 @Command(scope = "odl", name = "multipath", description = "Enable/Disable multipaths")
20 public class Multipath extends OsgiCommandSupport {
21
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;
27
28     @Option(name = RD, aliases = { "-r" },
29             description = "rd",
30             required = false,
31             multiValued = false)
32     String rd;
33
34     @Option(name = MAXPATH, aliases = { "-n" },
35             description = "max number of paths",
36             required = false,
37             multiValued = false)
38     String maxpath;
39
40     @Option(name = AF, aliases = {"-f"},
41             description = "Address family",
42             required = false, multiValued = false)
43
44     String addrFamily;
45
46
47     @Argument(name = "enable|disable|setmaxpath",
48             description = "The desired operation",
49             required = true, multiValued = false)
50
51     String multipathEnable;
52
53     private final BgpConfigurationManager bgpConfigurationManager;
54
55     public Multipath(BgpConfigurationManager bgpConfigurationManager) {
56         this.bgpConfigurationManager = bgpConfigurationManager;
57     }
58
59     @Override
60     protected Object doExecute() {
61         af_afi afi = af_afi.findByValue(1);
62         af_safi safi = af_safi.findByValue(5);
63
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 ");
68                 return null;
69             }
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);
79             } else { // vpnv4
80                 afi = af_afi.findByValue(1);
81                 safi = af_safi.findByValue(5);
82             }
83         }
84
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 + "]");
89                 return null;
90             }
91         }
92
93         if (multipathEnable != null) {
94
95             switch (multipathEnable) {
96                 case "enable":
97                     bgpConfigurationManager.setMultipathStatus(afi, safi, true);
98                     break;
99                 case "disable":
100                     bgpConfigurationManager.setMultipathStatus(afi, safi, false);
101                     break;
102                 case "setmaxpath":
103                     if (rd != null && maxpath != null) {
104                         bgpConfigurationManager.setMultipaths(rd, Integer.parseInt(maxpath));
105                     }
106                     break;
107
108                 default:
109                     return usage();
110             }
111         }
112
113         return null;
114     }
115
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");
119         return null;
120     }
121 }
122