mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.bgp.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.bgp.controller.BgpController; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.Map; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | |
| 30 | @Command(scope = "onos", name = "bgp-exception", description = "Displays Exceptions") |
| 31 | public 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame^] | 67 | if (!activeSessionExceptionkeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 68 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame^] | 79 | if (!activeSessionExceptionkeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 80 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame^] | 96 | if (!closedSessionExceptionKeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 97 | 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 Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame^] | 108 | if (!closedSessionExceptionKeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 109 | 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 | |