blob: 31230013ab4f8081d05c9f18aa09b85e74e7051d [file] [log] [blame]
mohamedrahil00f6f262016-11-24 20:20:41 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
mohamedrahil00f6f262016-11-24 20:20:41 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.bgp.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
mohamedrahil00f6f262016-11-24 20:20:41 +053021import org.onosproject.bgp.controller.BgpCfg;
22import org.onosproject.bgp.controller.BgpConnectPeer;
23import org.onosproject.bgp.controller.BgpController;
24import org.onosproject.bgp.controller.BgpPeerCfg;
25import org.onosproject.cli.AbstractShellCommand;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import java.util.Set;
30import java.util.TreeMap;
31
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
mohamedrahil00f6f262016-11-24 20:20:41 +053033@Command(scope = "onos", name = "bgp", description = "lists configuration")
34public class BgpConfiguration extends AbstractShellCommand {
35 private static final Logger log = LoggerFactory.getLogger(BgpConfiguration.class);
36 private static final String CONFIGURATION = "configuration";
37 private static final String PEER = "peer";
38 protected BgpController bgpController;
39 protected BgpConnectPeer bgpConnectPeer;
40 protected BgpPeerCfg bgpPeerCfg;
41 protected BgpCfg bgpCfg;
42 @Argument(index = 0, name = "name",
43 description = "configuration" + "\n" + "peer",
44 required = true, multiValued = false)
45 String name = null;
46 @Argument(index = 1, name = "peer",
47 description = "peerIp",
48 required = false, multiValued = false)
49 String peer = null;
50
51 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070052 protected void doExecute() {
mohamedrahil00f6f262016-11-24 20:20:41 +053053 switch (name) {
54 case CONFIGURATION:
55 displayBgpConfiguration();
56 break;
57 case PEER:
58 displayBgpPeerConfiguration();
59 break;
60 default:
61 System.out.print("Unknown command...!!");
62 break;
63 }
64 }
65
66 private void displayBgpConfiguration() {
67 try {
68
69 this.bgpController = get(BgpController.class);
70 bgpCfg = bgpController.getConfig();
71 print("RouterID = %s, ASNumber = %s, MaxSession = %s, HoldingTime = %s, LsCapabality = %s," +
72 " LargeAsCapabality = %s, FlowSpecCapabality = %s", bgpCfg.getRouterId(),
73 bgpCfg.getAsNumber(), bgpCfg.getMaxSession(), bgpCfg.getHoldTime(),
74 bgpCfg.getLsCapability(), bgpCfg.getLargeASCapability(), bgpCfg.flowSpecCapability());
75
76 } catch (Exception e) {
77 log.debug("Error occurred while displaying BGP configuration: {}", e.getMessage());
78 }
79 }
80
81 private void displayBgpPeerConfiguration() {
82 try {
83 this.bgpController = get(BgpController.class);
84 BgpCfg bgpCfg = bgpController.getConfig();
85 if (bgpCfg == null) {
86 return;
87 }
88 TreeMap<String, BgpPeerCfg> displayPeerTree = bgpCfg.getPeerTree();
89 Set<String> peerKey = displayPeerTree.keySet();
90 if (peer != null) {
Jon Hallcbd1b392017-01-18 20:15:44 -080091 if (!peerKey.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053092 for (String peerIdKey : peerKey) {
93 bgpPeerCfg = displayPeerTree.get(peerIdKey);
94 bgpConnectPeer = bgpPeerCfg.connectPeer();
95 if (peerIdKey.equals(peer)) {
96 print("PeerRouterID = %s, PeerHoldingTime = %s, ASNumber = %s, PeerState = %s," +
97 " PeerPort = %s, ConnectRetryCounter = %s",
98 peer, bgpPeerCfg.getHoldtime(), bgpPeerCfg.getAsNumber(),
99 bgpPeerCfg.getState(), bgpConnectPeer.getPeerPort(),
100 bgpConnectPeer.getConnectRetryCounter());
101 }
102 }
103 }
104 } else {
Jon Hallcbd1b392017-01-18 20:15:44 -0800105 if (!peerKey.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530106 for (String peerIdKey : peerKey) {
107 bgpPeerCfg = displayPeerTree.get(peerIdKey);
108 bgpConnectPeer = bgpPeerCfg.connectPeer();
109 print("PeerRouterID = %s, PeerHoldingTime = %s, ASNumber = %s, PeerState = %s, PeerPort = %s," +
110 " ConnectRetryCounter = %s",
111 bgpPeerCfg.getPeerRouterId(), bgpPeerCfg.getHoldtime(), bgpPeerCfg.getAsNumber(),
112 bgpPeerCfg.getState(), bgpConnectPeer.getPeerPort(),
113 bgpConnectPeer.getConnectRetryCounter());
114 }
115 }
116
117 }
118 } catch (Exception e) {
119 log.debug("Error occurred while displaying BGP peer configuration: {}", e.getMessage());
120 }
121 }
122
123
124}