Remove unused exceptions
[netvirt.git] / bgpmanager / impl / src / main / java / org / opendaylight / netvirt / bgpmanager / DisplayBgpConfigCli.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 package org.opendaylight.netvirt.bgpmanager;
10
11 import java.io.PrintStream;
12 import java.util.Date;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.apache.thrift.transport.TTransport;
17 import org.opendaylight.netvirt.bgpmanager.commands.Cache;
18
19
20 @Command(scope = "odl", name = "display-bgp-config", description = "")
21 public class DisplayBgpConfigCli extends OsgiCommandSupport {
22
23     @Option(name = "--debug", description = "print debug time stamps",
24             required = false, multiValued = false)
25     Boolean debug = false;
26
27     private final BgpManager bgpManager;
28
29     public DisplayBgpConfigCli(BgpManager bgpManager) {
30         this.bgpManager = bgpManager;
31     }
32
33     @Override
34     protected Object doExecute() {
35         PrintStream ps = session.getConsole();
36
37         if (debug) {
38             ps.printf("%nis ODL Connected to Q-BGP: %s%n", bgpManager.isBgpConnected() ? "TRUE" : "FALSE");
39             final TTransport transport = bgpManager.getBgpConfigurationManager().getTransport();
40             if (transport != null) {
41                 ps.printf("%nODL BGP Router transport is open: %s%n",
42                         transport.isOpen() ? "TRUE" : "FALSE");
43             } else {
44                 ps.printf("%nODL BGP Router transport is NULL%n");
45             }
46             //last ODL connection attempted TS
47             ps.printf("Last ODL connection attempt TS: %s%n", new Date(bgpManager.getConnectTS()));
48             //last successful connected TS
49             ps.printf("Last Successful connection TS: %s%n", new Date(bgpManager.getLastConnectedTS()));
50             //last ODL started BGP due to configuration trigger TS
51             ps.printf("Last ODL started BGP at: %s%n", new Date(bgpManager.getStartTS()));
52             //last Quagga attempted to RESTART the connection
53             ps.printf("Last Quagga BGP, sent reSync at: %s%n", new Date(bgpManager.getQbgprestartTS()));
54
55             //stale cleanup start - end TS
56             ps.printf("Time taken to create stale fib : %s ms%n",
57                     bgpManager.getStaleEndTime() - bgpManager.getStaleStartTime());
58
59             //Config replay start - end TS
60             ps.printf("Time taken to create replay configuration : %s ms%n",
61                     bgpManager.getCfgReplayEndTime() - bgpManager.getCfgReplayStartTime());
62
63             //Stale cleanup time
64             ps.printf("Time taken for Stale FIB cleanup : %s ms%n", bgpManager.getStaleCleanupTime());
65
66             ps.printf("Total stale entries created %d %n", bgpManager.getBgpConfigurationManager()
67                     .getTotalStaledCount());
68             ps.printf("Total stale entries cleared %d %n", bgpManager.getBgpConfigurationManager().getTotalCleared());
69         }
70         Cache cache = new Cache(bgpManager);
71         return cache.show(session);
72     }
73 }