2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.netvirt.bgpmanager;
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;
21 @Command(scope = "odl", name = "display-bgp-config", description = "")
22 public class DisplayBgpConfigCli extends OsgiCommandSupport {
24 @Option(name = "--debug", description = "print debug time stamps",
25 required = false, multiValued = false)
26 Boolean debug = false;
28 @Option(name = "--history", description = "print bgp updates",
29 required = false, multiValued = false)
30 Boolean showHistory = false;
32 private final BgpManager bgpManager;
34 public DisplayBgpConfigCli(BgpManager bgpManager) {
35 this.bgpManager = bgpManager;
38 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
40 protected Object doExecute() throws Exception {
41 PrintStream ps = System.out;
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");
50 ps.printf("%nODL BGP Router transport is NULL%n");
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()));
61 //stale cleanup start - end TS
62 ps.printf("Time taken to create stale fib : %s ms%n",
63 bgpManager.getStaleEndTime() - bgpManager.getStaleStartTime());
65 //Config replay start - end TS
66 ps.printf("Time taken to create replay configuration : %s ms%n",
67 bgpManager.getCfgReplayEndTime() - bgpManager.getCfgReplayStartTime());
70 ps.printf("Time taken for Stale FIB cleanup : %s ms%n", bgpManager.getStaleCleanupTime());
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());
77 ps.printf("Am I Owner %s %n",
78 bgpManager.getBgpConfigurationManager().isBGPEntityOwner() ? "True" : "False");
82 TransactionHistory bgpUpdatesHistory = bgpManager.getBgpConfigurationManager().getBgpUpdatesHistory();
83 bgpUpdatesHistory.getElements().forEach(update -> {
84 Date date = new Date(update.getDate());
86 ps.print(update.getData());
90 Cache cache = new Cache(bgpManager);
91 return cache.show(session);