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.bgpmanager.commands;
11 import org.apache.karaf.shell.commands.*;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.bgpmanager.BgpManager;
14 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.*;
15 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.*;
16 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.neighbors.*;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.*;
21 @Command(scope = "odl", name = "bgp-cache",
22 description = "Text dump of BGP config cache")
23 public class Cache extends OsgiCommandSupport {
24 private static final String LST = "--list";
25 private static final String OFL = "--out-file";
27 @Argument(name="dummy", description="Argument not needed",
28 required=false, multiValued = false)
29 private String action = null;
31 @Option(name=LST, aliases={"-l"},
32 description="list vrfs and/or networks",
33 required=false, multiValued=true)
34 private List<String> list = null;
36 @Option(name=OFL, aliases={"-o"},
37 description="output file",
38 required=false, multiValued=false)
39 private String ofile = null;
41 private static final String HTSTR = "Host";
42 private static final String PTSTR = "Port";
43 private static final String ASSTR = "AS-Number";
44 private static final String RISTR = "Router-ID";
45 private static final String SPSTR = "Stale-Path-Time";
46 private static final String FBSTR = "F-bit";
47 private static final String LFSTR = "Log-File";
48 private static final String LLSTR = "Log-Level";
49 private static final String USSTR = "Update-Source";
50 private static final String EBSTR = "EBGP-Multihops";
51 private static final String AFSTR = "Address-Families";
52 private static final String ERSTR = "Export-RTs";
53 private static final String IRSTR = "Import-RTs";
54 private static final String NHSTR = "Nexthop";
55 private static final String LBSTR = "Label";
56 private static final String RDSTR = "RD";
58 private Object usage() {
60 ("usage: bgp-cache ["+LST+" vrfs | networks] ["+OFL+" file-name]");
67 public Object show() throws Exception {
72 protected Object doExecute() throws Exception {
73 if (!Commands.bgpRunning()) {
76 Bgp config = Commands.getBgpManager().getConfig();
77 boolean list_vrfs = false;
78 boolean list_nets = false;
79 PrintStream ps = System.out;
86 ps = new PrintStream(ofile);
87 } catch (Exception e) {
88 System.err.println("error: cannot create file "+ofile +"; exception: "+e);
93 for (String item : list) {
102 System.err.println("error: unknown value for "+LST+": "+item);
107 // we'd normally read this directly from 'config' but
108 // legacy behaviour forces to check for a connection
109 // that's initiated by default at startup without
110 // writing to config.
111 String cHost = Commands.getBgpManager().getConfigHost();
112 int cPort = Commands.getBgpManager().getConfigPort();
113 ps.printf("\nConfiguration Server\n\t%s %s\n\t%s %d\n",
114 HTSTR, cHost, PTSTR, cPort);
115 if (config == null) {
118 AsId a = config.getAsId();
120 int asNum = a.getLocalAs().intValue();
121 Ipv4Address routerId = a.getRouterId();
122 Long spt = a.getStalepathTime();
123 Boolean afb = a.isAnnounceFbit();
124 String rid = (routerId == null) ? "<n/a>" : routerId.getValue();
125 int s = (spt == null) ? 0 : spt.intValue();
126 String bit = (afb == null) ? "OFF" : (afb.booleanValue() ? "ON" : "OFF");
128 GracefulRestart g = config.getGracefulRestart();
130 s = g.getStalepathTime().intValue();
132 ps.printf("\nBGP Router\n");
133 ps.printf("\t%-15s %d\n\t%-15s %s\n\t%-15s %d\n\t%-15s %s\n",
134 ASSTR, asNum, RISTR, rid, SPSTR, s, FBSTR, bit);
137 Logging l = config.getLogging();
139 ps.printf("\t%-15s %s\n\t%-15s %s\n", LFSTR, l.getFile(),
140 LLSTR, l.getLevel());
143 List<Neighbors> n = config.getNeighbors();
145 ps.printf("\nNeighbors\n");
146 for (Neighbors nbr : n) {
147 ps.printf("\t%s\n\t\t%-16s %d\n", nbr.getAddress().getValue(),
148 ASSTR, nbr.getRemoteAs().intValue());
149 EbgpMultihop en = nbr.getEbgpMultihop();
151 ps.printf("\t\t%-16s %d\n", EBSTR, en.getNhops().intValue());
153 UpdateSource us = nbr.getUpdateSource();
155 ps.printf("\t\t%-16s %s\n", USSTR, us.getSourceIp().getValue());
157 ps.printf("\t\t%-16s IPv4-Labeled-VPN", AFSTR);
158 List<AddressFamilies> afs = nbr.getAddressFamilies();
160 for (AddressFamilies af : afs) {
161 ps.printf(" %s", af.getSafi().intValue() == 4 ?
162 "IPv4-Labeled-Unicast" : "Unknown");
170 List<Vrfs> v = config.getVrfs();
172 ps.printf("\nVRFs\n");
174 ps.printf("\t%s\n",vrf.getRd());
175 ps.printf("\t\t%s ", IRSTR);
176 for (String rt : vrf.getImportRts())
177 ps.printf("%s ", rt);
178 ps.printf("\n\t\t%s ", ERSTR);
179 for (String rt : vrf.getExportRts())
180 ps.printf("%s ", rt);
187 List<Networks> ln = config.getNetworks();
189 ps.printf("\nNetworks\n");
190 for (Networks net : ln) {
191 String rd = net.getRd();
192 String pfxlen = net.getPrefixLen();
193 String nh = net.getNexthop().getValue();
194 int label = net.getLabel().intValue();
195 ps.printf("\t%s\n\t\t%-7s %s\n\t\t%-7s %s\n\t\t%-7s %d\n",
196 pfxlen, RDSTR, rd, NHSTR, nh, LBSTR, label);