mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.bgp.cli; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 21 | import org.onosproject.bgp.controller.BgpController; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.slf4j.Logger; |
| 24 | import org.slf4j.LoggerFactory; |
| 25 | |
| 26 | import java.util.List; |
| 27 | import java.util.Map; |
| 28 | import java.util.Set; |
| 29 | |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 30 | @Service |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 31 | @Command(scope = "onos", name = "bgp-exception", description = "Displays Exceptions") |
| 32 | public 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 Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 49 | protected void doExecute() { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 50 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 68 | if (!activeSessionExceptionkeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 69 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 80 | if (!activeSessionExceptionkeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 81 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 97 | if (!closedSessionExceptionKeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 98 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 109 | if (!closedSessionExceptionKeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 110 | 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 | |