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.pcep.cli; |
| 17 | |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
harikrushna-Huawei | a2c7c20 | 2017-04-10 18:22:00 +0530 | [diff] [blame] | 23 | import org.onosproject.pcep.server.PcepClientController; |
| 24 | import org.onosproject.pcep.server.PcepErrorDetail; |
| 25 | import org.onosproject.pcep.server.PcepErrorType; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import java.util.Set; |
| 30 | import java.util.Map; |
| 31 | import java.util.List; |
| 32 | import java.util.ArrayList; |
| 33 | import java.util.TreeMap; |
| 34 | |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 35 | @Service |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 36 | @Command(scope = "onos", name = "pcep", description = "Pcep Session Info") |
| 37 | public class PcepSessionCommand extends AbstractShellCommand { |
| 38 | private static final Logger log = LoggerFactory.getLogger(PcepSessionCommand.class); |
| 39 | private static final String SESSION = "session"; |
| 40 | private static final String EXCEPTION = "exception"; |
| 41 | private static final String ERROR = "error"; |
| 42 | private PcepClientController pcepClientController; |
| 43 | private byte sessionId; |
| 44 | private Set<String> pcepSessionKeySet; |
| 45 | private Set<String> pcepSessionIdKeySet; |
| 46 | private Integer sessionIdValue = 0; |
| 47 | private String sessionStatus; |
| 48 | private List pcepSessionExceptions = new ArrayList(); |
| 49 | private Set<String> pcepSessionFailurekeySet; |
| 50 | private PcepErrorDetail pcepErrorDetail; |
| 51 | private PcepErrorType pcepErrorType; |
| 52 | private Map<Integer, String> sessionEstablishmentFailureMap = new TreeMap<>(); |
| 53 | private Map<Integer, String> unknownObjectMap = new TreeMap<>(); |
| 54 | private Map<Integer, String> notSupportedObjectMap = new TreeMap<>(); |
| 55 | private Map<Integer, String> policyViolationMap = new TreeMap<>(); |
| 56 | private Map<Integer, String> mandatoryObjectMissingMap = new TreeMap<>(); |
| 57 | private Map<Integer, String> receptionOfInvalidObjectMap = new TreeMap<>(); |
| 58 | private Map<Integer, String> invalidOperationMap = new TreeMap<>(); |
| 59 | private Set<Integer> pcepErrorMsgKey; |
| 60 | private Integer pcepErrorValue = 0; |
| 61 | |
| 62 | @Argument(index = 0, name = "name", |
| 63 | description = "session" + "\n" + "exception" + "\n" + "error", |
| 64 | required = true, multiValued = false) |
| 65 | String name = null; |
| 66 | @Argument(index = 1, name = "peer", |
| 67 | description = "peerIp", |
| 68 | required = false, multiValued = false) |
| 69 | String peer = null; |
| 70 | |
| 71 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 72 | protected void doExecute() { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 73 | switch (name) { |
| 74 | case SESSION: |
| 75 | displayPcepSession(); |
| 76 | break; |
| 77 | case EXCEPTION: |
| 78 | displayPcepSessionFailureReason(); |
| 79 | break; |
| 80 | case ERROR: |
| 81 | displayPcepErrorMsgs(); |
| 82 | break; |
| 83 | default: |
| 84 | System.out.print("Unknown Command"); |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | private void displayPcepSession() { |
| 90 | try { |
| 91 | this.pcepClientController = get(PcepClientController.class); |
| 92 | Map<String, String> pcepSessionMap = pcepClientController.getPcepSessionMap(); |
| 93 | Map<String, Byte> pcepSessionIdMap = pcepClientController.getPcepSessionIdMap(); |
| 94 | pcepSessionKeySet = pcepSessionMap.keySet(); |
| 95 | pcepSessionIdKeySet = pcepSessionIdMap.keySet(); |
| 96 | if (peer != null) { |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 97 | if (!pcepSessionKeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 98 | if (pcepSessionKeySet.contains(peer)) { |
| 99 | for (String pcepSessionPeer : pcepSessionKeySet) { |
| 100 | if (pcepSessionPeer.equals(peer)) { |
| 101 | for (String pcepSessionId : pcepSessionIdKeySet) { |
| 102 | if (pcepSessionId.equals(peer)) { |
| 103 | sessionId = pcepSessionIdMap.get(pcepSessionId); |
| 104 | sessionStatus = pcepSessionMap.get(pcepSessionPeer); |
| 105 | if (sessionId < 0) { |
| 106 | sessionIdValue = sessionId + 256; |
| 107 | } else { |
| 108 | sessionIdValue = (int) sessionId; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | print("SessionIp = %s, Status = %s, sessionId = %s", pcepSessionPeer, sessionStatus, sessionIdValue); |
| 113 | } |
| 114 | } |
| 115 | } else { |
| 116 | System.out.print("Wrong Peer IP"); |
| 117 | } |
| 118 | } |
| 119 | } else { |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 120 | if (!pcepSessionKeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 121 | for (String pcepSessionPeer : pcepSessionKeySet) { |
| 122 | for (String pcepSessionId : pcepSessionIdKeySet) { |
| 123 | if (pcepSessionId.equals(pcepSessionPeer)) { |
| 124 | sessionId = pcepSessionIdMap.get(pcepSessionId); |
| 125 | sessionStatus = pcepSessionMap.get(pcepSessionPeer); |
| 126 | if (sessionId < 0) { |
| 127 | sessionIdValue = sessionId + 256; |
| 128 | } else { |
| 129 | sessionIdValue = (int) sessionId; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | print("SessionIp = %s, Status = %s, sessionId = %s", pcepSessionPeer, sessionStatus, sessionIdValue); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } catch (Exception e) { |
| 138 | log.debug("Error occurred while displaying PCEP session information: {}", e.getMessage()); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private void displayPcepSessionFailureReason() { |
| 143 | try { |
| 144 | this.pcepClientController = get(PcepClientController.class); |
| 145 | Map<String, List<String>> pcepSessionFailureReasonMap = pcepClientController.getPcepExceptions(); |
| 146 | pcepSessionFailurekeySet = pcepSessionFailureReasonMap.keySet(); |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 147 | if (!pcepSessionFailurekeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 148 | if (peer != null) { |
| 149 | if (pcepSessionFailurekeySet.contains(peer)) { |
| 150 | for (String pcepSessionPeerId : pcepSessionFailurekeySet) { |
| 151 | if (pcepSessionPeerId.equals(peer)) { |
| 152 | pcepSessionExceptions = pcepSessionFailureReasonMap.get(pcepSessionPeerId); |
| 153 | print("PeerId = %s, FailureReason = %s", pcepSessionPeerId, pcepSessionExceptions); |
| 154 | } |
| 155 | } |
| 156 | } else { |
| 157 | System.out.print("Wrong Peer IP"); |
| 158 | } |
| 159 | |
| 160 | } else { |
| 161 | pcepSessionFailurekeySet = pcepSessionFailureReasonMap.keySet(); |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 162 | if (!pcepSessionFailurekeySet.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 163 | for (String pcepSessionPeerId : pcepSessionFailurekeySet) { |
| 164 | pcepSessionExceptions = pcepSessionFailureReasonMap.get(pcepSessionPeerId); |
| 165 | print("PeerId = %s, FailureReason = %s", pcepSessionPeerId, pcepSessionExceptions); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | } |
| 171 | |
| 172 | |
| 173 | } catch (Exception e) { |
| 174 | log.debug("Error occurred while displaying PCEP session failure reasons: {}", e.getMessage()); |
| 175 | } |
| 176 | |
| 177 | } |
| 178 | |
| 179 | |
| 180 | private void displayPcepErrorMsgs() { |
| 181 | try { |
| 182 | this.pcepClientController = get(PcepClientController.class); |
| 183 | Map<Integer, Integer> pcepErrorMsgMap = pcepClientController.getPcepErrorMsg(); |
| 184 | pcepErrorMsgKey = pcepErrorMsgMap.keySet(); |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 185 | if (!pcepErrorMsgKey.isEmpty()) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 186 | for (Integer errorType : pcepErrorMsgKey) { |
| 187 | pcepErrorValue = pcepErrorMsgMap.get(errorType); |
| 188 | pcepErrorType = PcepErrorType.values()[errorType]; |
| 189 | switch (pcepErrorType) { |
| 190 | case SESSIONESTABLISHMENTFAILURE: |
| 191 | sessionEstablishmentFailureMap = pcepErrorDetail.sessionEstablishmentFailure(); |
| 192 | Set<Integer> sessionFailureKeySet = sessionEstablishmentFailureMap.keySet(); |
| 193 | for (Integer sessionFailureKey : sessionFailureKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 194 | if (sessionFailureKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 195 | System.out.print(sessionEstablishmentFailureMap.get(sessionFailureKey)); |
| 196 | } |
| 197 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 198 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 199 | case CAPABALITYNOTSUPPORTED: |
| 200 | System.out.print("Capability not supported"); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 201 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 202 | case UNKNOWNOBJECT: |
| 203 | unknownObjectMap = pcepErrorDetail.unknownObject(); |
| 204 | Set<Integer> unknownObjectKeySet = unknownObjectMap.keySet(); |
| 205 | for (Integer unknownObjectKey : unknownObjectKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 206 | if (unknownObjectKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 207 | System.out.print(unknownObjectMap.get(unknownObjectKey)); |
| 208 | } |
| 209 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 210 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 211 | case NOTSUPPORTEDOBJECT: |
| 212 | notSupportedObjectMap = pcepErrorDetail.notSupportedObject(); |
| 213 | Set<Integer> notSupportedObjectKeySet = notSupportedObjectMap.keySet(); |
| 214 | for (Integer notSupportedObjectKey : notSupportedObjectKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 215 | if (notSupportedObjectKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 216 | System.out.print(notSupportedObjectMap.get(notSupportedObjectKey)); |
| 217 | } |
| 218 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 219 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 220 | case POLICYVIOLATION: |
| 221 | policyViolationMap = pcepErrorDetail.policyViolation(); |
| 222 | Set<Integer> policyViolationKeySet = policyViolationMap.keySet(); |
| 223 | for (Integer policyViolationKey : policyViolationKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 224 | if (policyViolationKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 225 | System.out.print(policyViolationMap.get(policyViolationKey)); |
| 226 | } |
| 227 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 228 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 229 | case MANDATORYOBJECTMISSING: |
| 230 | mandatoryObjectMissingMap = pcepErrorDetail.mandatoryObjectMissing(); |
| 231 | Set<Integer> mandatoryObjectMissingKeySet = mandatoryObjectMissingMap.keySet(); |
| 232 | for (Integer mandatoryObjectMissingKey : mandatoryObjectMissingKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 233 | if (mandatoryObjectMissingKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 234 | System.out.print(mandatoryObjectMissingMap.get(mandatoryObjectMissingKey)); |
| 235 | } |
| 236 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 237 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 238 | case SYNCHRONIZEDPATHCOMPUTATIONREQUESTMISSING: |
| 239 | System.out.print("Synchronized path computation request missing"); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 240 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 241 | case UNKNOWNREQUESTREFERENCE: |
| 242 | System.out.print("Unknown request reference"); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 243 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 244 | case ESTABLISHINGSECONDPCEPSESSION: |
| 245 | System.out.print("Attempt to establish a second PCEP session"); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 246 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 247 | case RECEPTIONOFINVALIDOBJECT: |
| 248 | receptionOfInvalidObjectMap = pcepErrorDetail.receptionOfInvalidObject(); |
| 249 | Set<Integer> receptionOfInvalidObjectKeySet = receptionOfInvalidObjectMap.keySet(); |
| 250 | for (Integer receptionOfInvalidObjectKey : receptionOfInvalidObjectKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 251 | if (receptionOfInvalidObjectKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 252 | System.out.print(receptionOfInvalidObjectMap.get(receptionOfInvalidObjectKey)); |
| 253 | } |
| 254 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 255 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 256 | case INVALIDOPERATION: |
| 257 | invalidOperationMap = pcepErrorDetail.invalidOperation(); |
| 258 | Set<Integer> invalidOperationKeySet = invalidOperationMap.keySet(); |
| 259 | for (Integer invalidOperationKey : invalidOperationKeySet) { |
Saritha | 66fee92 | 2017-05-10 12:40:48 +0530 | [diff] [blame] | 260 | if (invalidOperationKey.equals(pcepErrorValue)) { |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 261 | System.out.print(invalidOperationMap.get(invalidOperationKey)); |
| 262 | } |
| 263 | } |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 264 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 265 | case VIRTUALNETWORKTLVMISSING: |
| 266 | System.out.print("VIRTUAL-NETWORK TLV missing"); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 267 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 268 | default: |
| 269 | System.out.print("Unknown error message"); |
Ray Milkey | d6a67c3 | 2018-02-02 10:30:35 -0800 | [diff] [blame] | 270 | break; |
mohamedrahil | 00f6f26 | 2016-11-24 20:20:41 +0530 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | } catch (Exception e) { |
| 275 | log.debug("Error occurred while displaying PCEP error messages received: {}", e.getMessage()); |
| 276 | } |
| 277 | } |
| 278 | } |