MRI version bumpup for Aluminium
[netvirt.git] / bgpmanager / impl / src / main / java / org / opendaylight / netvirt / bgpmanager / commands / BfdCache.java
1 /*
2  * Copyright (c) 2015 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
10 package org.opendaylight.netvirt.bgpmanager.commands;
11
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.io.PrintStream;
14 import org.apache.felix.service.command.CommandSession;
15 import org.apache.karaf.shell.commands.Command;
16 import org.apache.karaf.shell.console.OsgiCommandSupport;
17 import org.opendaylight.netvirt.bgpmanager.BgpUtil;
18 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebfd.rev190219.BfdConfig;
19 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.DcgwTepList;
20
21
22
23 @Command(scope = "odl", name = "bfd-cache",
24         description = "Text dump of BFD config cache")
25 @SuppressFBWarnings("DM_DEFAULT_ENCODING")
26 public class BfdCache extends OsgiCommandSupport {
27     private static final String MINRX = "min-rx";
28     private static final String MINTX = "min-tx";
29     private static final String DMULT = "detect-mult";
30     private static final String MLHOP = "multi-hop";
31     private static final String DCGWIP = "dcgw-ip";
32     private static final String TEPIP = "tep-ip";
33
34     private final BgpUtil bgpUtil;
35
36     public BfdCache(BgpUtil bgpUtil) {
37         this.bgpUtil = bgpUtil;
38     }
39
40     /*private Object usage() {
41         session.getConsole().println("usage: bfd-cache ");
42         return null;
43     }*/
44
45     public Object show(CommandSession session) throws Exception {
46         this.session = session;
47         return doExecute();
48     }
49
50     public Object show() throws Exception {
51         return doExecute();
52     }
53
54     @SuppressWarnings("resource")
55     @Override
56     protected Object doExecute() throws Exception {
57
58         PrintStream ps = session.getConsole();
59         BfdConfig bfdConfig = bgpUtil.getBfdConfig();
60         if (bfdConfig != null) {
61             boolean bfdEnabled = bfdConfig.isBfdEnabled();
62             ps.printf("%nbfd-enabled     %s%n", bfdEnabled ? "yes" : "no");
63             int minrx = bfdConfig.getMinRx().intValue();
64             int mintx = bfdConfig.getMinTx().intValue();
65             int detectmult = bfdConfig.getDetectMult().intValue();
66             boolean multihop = bfdConfig.isMultihop();
67             ps.printf("%n\t%-15s  %d%n\t%-15s  %d%n\t%-15s  %d%n\t%-15s  %s%n",
68                     MINRX, minrx, MINTX, mintx, DMULT, detectmult, MLHOP, multihop ? "yes" : "no");
69         } else {
70             ps.printf("%nbfd-enabled     %s%n", "no");
71         }
72
73         DcgwTepList dcgwTepList = bgpUtil.getDcgwTepConfig();
74         if (dcgwTepList != null) {
75             dcgwTepList.getDcgwTep().values().forEach(dcgwTep -> {
76                 ps.printf("%n%n%-15s  %s", DCGWIP, dcgwTep.getDcGwIp());
77                 dcgwTep.getTepIps().forEach(tep -> {
78                     ps.printf("%n\t%-15s  %s", TEPIP, tep);
79                 });
80             });
81             ps.printf("%n");
82         }
83         return null;
84     }
85 }