blob: d4e14f831fa075d58f15167a138631fb63788b50 [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.BgpController;
22import org.onosproject.cli.AbstractShellCommand;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import java.util.List;
27import java.util.Map;
28import java.util.Set;
29
Ray Milkey7a2dee52018-09-28 10:58:28 -070030@Service
mohamedrahil00f6f262016-11-24 20:20:41 +053031@Command(scope = "onos", name = "bgp-exception", description = "Displays Exceptions")
32public class BgpExceptions extends AbstractShellCommand {
33 public static final String ACTIVESESSION = "activesession";
34 public static final String CLOSEDSESSION = "closedsession";
35 private static final Logger log = LoggerFactory.getLogger(BgpExceptions.class);
36 protected BgpController bgpController;
37 @Argument(index = 0, name = "name",
38 description = "activesession" + "\n" + "closedsession",
39 required = true, multiValued = false)
40 String name = null;
41 @Argument(index = 1, name = "peerIp",
42 description = "peerId",
43 required = false, multiValued = false)
44 String peerId = null;
45 private Set<String> activeSessionExceptionkeySet;
46 private Set<String> closedSessionExceptionKeySet;
47
48 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070049 protected void doExecute() {
mohamedrahil00f6f262016-11-24 20:20:41 +053050 switch (name) {
51 case ACTIVESESSION:
52 displayActiveSessionException();
53 break;
54 case CLOSEDSESSION:
55 displayClosedSessionException();
56 break;
57 default:
58 System.out.print("Unknown Command");
59 break;
60 }
61 }
62
63 private void displayActiveSessionException() {
64 try {
65 this.bgpController = get(BgpController.class);
66 Map<String, List<String>> activeSessionExceptionMap = bgpController.activeSessionMap();
67 activeSessionExceptionkeySet = activeSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -080068 if (!activeSessionExceptionkeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053069 if (peerId != null) {
70 if (activeSessionExceptionkeySet.contains(peerId)) {
71 for (String peerIdKey : activeSessionExceptionkeySet) {
72 List activeSessionExceptionlist = activeSessionExceptionMap.get(peerIdKey);
73 System.out.println(activeSessionExceptionlist);
74 }
75 } else {
76 System.out.print("Wrong argument");
77 }
78 } else {
79 activeSessionExceptionkeySet = activeSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -080080 if (!activeSessionExceptionkeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053081 for (String peerId : activeSessionExceptionkeySet) {
82 print("PeerId = %s, Exception = %s ", peerId, activeSessionExceptionMap.get(peerId));
83 }
84 }
85 }
86 }
87 } catch (Exception e) {
88 log.debug("Error occurred while displaying BGP exceptions: {}", e.getMessage());
89 }
90 }
91
92 private void displayClosedSessionException() {
93 try {
94 this.bgpController = get(BgpController.class);
95 Map<String, List<String>> closedSessionExceptionMap = bgpController.closedSessionMap();
96 closedSessionExceptionKeySet = closedSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -080097 if (!closedSessionExceptionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053098 if (peerId != null) {
99 if (closedSessionExceptionKeySet.contains(peerId)) {
100 for (String peerIdKey : closedSessionExceptionKeySet) {
101 List closedSessionExceptionlist = closedSessionExceptionMap.get(peerIdKey);
102 print("Exceptions = %s", closedSessionExceptionlist);
103 }
104 } else {
105 System.out.print("Wrong argument");
106 }
107 } else {
108 closedSessionExceptionKeySet = closedSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -0800109 if (!closedSessionExceptionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530110 for (String peerId : closedSessionExceptionKeySet) {
111 print("PeerId = %s, Exception = %s", peerId, closedSessionExceptionMap.get(peerId));
112 }
113 }
114 }
115 }
116 } catch (Exception e) {
117 log.debug("Error occurred while displaying resons for session closure: {}", e.getMessage());
118 }
119 }
120
121
122}
123
124