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