blob: 4a70556d7174f5611b34f67b9dd465d7bb3467e0 [file] [log] [blame]
mohamedrahil00f6f262016-11-24 20:20:41 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.bgp.controller.BgpController;
21import org.onosproject.cli.AbstractShellCommand;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25import java.util.List;
26import java.util.Map;
27import java.util.Set;
28
29
30@Command(scope = "onos", name = "bgp-exception", description = "Displays Exceptions")
31public class BgpExceptions extends AbstractShellCommand {
32 public static final String ACTIVESESSION = "activesession";
33 public static final String CLOSEDSESSION = "closedsession";
34 private static final Logger log = LoggerFactory.getLogger(BgpExceptions.class);
35 protected BgpController bgpController;
36 @Argument(index = 0, name = "name",
37 description = "activesession" + "\n" + "closedsession",
38 required = true, multiValued = false)
39 String name = null;
40 @Argument(index = 1, name = "peerIp",
41 description = "peerId",
42 required = false, multiValued = false)
43 String peerId = null;
44 private Set<String> activeSessionExceptionkeySet;
45 private Set<String> closedSessionExceptionKeySet;
46
47 @Override
48 protected void execute() {
49 switch (name) {
50 case ACTIVESESSION:
51 displayActiveSessionException();
52 break;
53 case CLOSEDSESSION:
54 displayClosedSessionException();
55 break;
56 default:
57 System.out.print("Unknown Command");
58 break;
59 }
60 }
61
62 private void displayActiveSessionException() {
63 try {
64 this.bgpController = get(BgpController.class);
65 Map<String, List<String>> activeSessionExceptionMap = bgpController.activeSessionMap();
66 activeSessionExceptionkeySet = activeSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -080067 if (!activeSessionExceptionkeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053068 if (peerId != null) {
69 if (activeSessionExceptionkeySet.contains(peerId)) {
70 for (String peerIdKey : activeSessionExceptionkeySet) {
71 List activeSessionExceptionlist = activeSessionExceptionMap.get(peerIdKey);
72 System.out.println(activeSessionExceptionlist);
73 }
74 } else {
75 System.out.print("Wrong argument");
76 }
77 } else {
78 activeSessionExceptionkeySet = activeSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -080079 if (!activeSessionExceptionkeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053080 for (String peerId : activeSessionExceptionkeySet) {
81 print("PeerId = %s, Exception = %s ", peerId, activeSessionExceptionMap.get(peerId));
82 }
83 }
84 }
85 }
86 } catch (Exception e) {
87 log.debug("Error occurred while displaying BGP exceptions: {}", e.getMessage());
88 }
89 }
90
91 private void displayClosedSessionException() {
92 try {
93 this.bgpController = get(BgpController.class);
94 Map<String, List<String>> closedSessionExceptionMap = bgpController.closedSessionMap();
95 closedSessionExceptionKeySet = closedSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -080096 if (!closedSessionExceptionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053097 if (peerId != null) {
98 if (closedSessionExceptionKeySet.contains(peerId)) {
99 for (String peerIdKey : closedSessionExceptionKeySet) {
100 List closedSessionExceptionlist = closedSessionExceptionMap.get(peerIdKey);
101 print("Exceptions = %s", closedSessionExceptionlist);
102 }
103 } else {
104 System.out.print("Wrong argument");
105 }
106 } else {
107 closedSessionExceptionKeySet = closedSessionExceptionMap.keySet();
Jon Hallcbd1b392017-01-18 20:15:44 -0800108 if (!closedSessionExceptionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530109 for (String peerId : closedSessionExceptionKeySet) {
110 print("PeerId = %s, Exception = %s", peerId, closedSessionExceptionMap.get(peerId));
111 }
112 }
113 }
114 }
115 } catch (Exception e) {
116 log.debug("Error occurred while displaying resons for session closure: {}", e.getMessage());
117 }
118 }
119
120
121}
122
123