Optimizing BGP routesync operation
[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 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory;
19
20
21 @Command(scope = "odl", name = "display-bgp-config", description = "")
22 public class DisplayBgpConfigCli extends OsgiCommandSupport {
23
24     @Option(name = "--debug", description = "print debug time stamps",
25             required = false, multiValued = false)
26     Boolean debug = false;
27
28     @Option(name = "--history", description = "print bgp updates",
29             required = false, multiValued = false)
30     Boolean showHistory = false;
31
32     private final BgpManager bgpManager;
33
34     public DisplayBgpConfigCli(BgpManager bgpManager) {
35         this.bgpManager = bgpManager;
36     }
37
38     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
39     @Override
40     protected Object doExecute() throws Exception {
41         PrintStream ps = System.out;
42
43         if (debug) {
44             ps.printf("%nis ODL Connected to Q-BGP: %s%n", bgpManager.isBgpConnected() ? "TRUE" : "FALSE");
45             final TTransport transport = bgpManager.getBgpConfigurationManager().getTransport();
46             if (transport != null) {
47                 ps.printf("%nODL BGP Router transport is open: %s%n",
48                         transport.isOpen() ? "TRUE" : "FALSE");
49             } else {
50                 ps.printf("%nODL BGP Router transport is NULL%n");
51             }
52             //last ODL connection attempted TS
53             ps.printf("Last ODL connection attempt TS: %s%n", new Date(bgpManager.getConnectTS()));
54             //last successful connected TS
55             ps.printf("Last Successful connection TS: %s%n", new Date(bgpManager.getLastConnectedTS()));
56             //last ODL started BGP due to configuration trigger TS
57             ps.printf("Last ODL started BGP at: %s%n", new Date(bgpManager.getStartTS()));
58             //last Quagga attempted to RESTART the connection
59             ps.printf("Last Quagga BGP, sent reSync at: %s%n", new Date(bgpManager.getQbgprestartTS()));
60
61             //stale cleanup start - end TS
62             ps.printf("Time taken to create stale fib : %s ms%n",
63                     bgpManager.getStaleEndTime() - bgpManager.getStaleStartTime());
64
65             //Config replay start - end TS
66             ps.printf("Time taken to create replay configuration : %s ms%n",
67                     bgpManager.getCfgReplayEndTime() - bgpManager.getCfgReplayStartTime());
68
69             //Stale cleanup time
70             ps.printf("Time taken for Stale FIB cleanup : %s ms%n", bgpManager.getStaleCleanupTime());
71
72             ps.printf("Total stale entries created %d %n",
73                             bgpManager.getBgpConfigurationManager().getTotalStaledCount());
74             ps.printf("Total stale entries cleared %d %n",
75                             bgpManager.getBgpConfigurationManager().getTotalCleared());
76
77             ps.printf("Am I Owner %s %n",
78                       bgpManager.getBgpConfigurationManager().isBGPEntityOwner() ? "True" : "False");
79         }
80
81         if (showHistory) {
82             TransactionHistory bgpUpdatesHistory = bgpManager.getBgpConfigurationManager().getBgpUpdatesHistory();
83             bgpUpdatesHistory.getElements().forEach(update -> {
84                 Date date = new Date(update.getDate());
85                 ps.println(date);
86                 ps.print(update.getData());
87                 ps.println();
88             });
89         }
90         Cache cache = new Cache(bgpManager);
91         return cache.show(session);
92     }
93 }