blob: 68315e3017ce8690627a8f1d723a20755e4457ce [file] [log] [blame]
mohamedrahil00f6f262016-11-24 20:20:41 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
mohamedrahil00f6f262016-11-24 20:20:41 +05303 *
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.pcep.cli;
17
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
mohamedrahil00f6f262016-11-24 20:20:41 +053022import org.onosproject.cli.AbstractShellCommand;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053023import org.onosproject.pcep.server.PcepClientController;
24import org.onosproject.pcep.server.PcepErrorDetail;
25import org.onosproject.pcep.server.PcepErrorType;
mohamedrahil00f6f262016-11-24 20:20:41 +053026import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import java.util.Set;
30import java.util.Map;
31import java.util.List;
32import java.util.ArrayList;
33import java.util.TreeMap;
34
Ray Milkey7a2dee52018-09-28 10:58:28 -070035@Service
mohamedrahil00f6f262016-11-24 20:20:41 +053036@Command(scope = "onos", name = "pcep", description = "Pcep Session Info")
37public 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 Milkey86ad7bb2018-09-27 12:32:28 -070072 protected void doExecute() {
mohamedrahil00f6f262016-11-24 20:20:41 +053073 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 Hallcbd1b392017-01-18 20:15:44 -080097 if (!pcepSessionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053098 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 Hallcbd1b392017-01-18 20:15:44 -0800120 if (!pcepSessionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530121 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 Hallcbd1b392017-01-18 20:15:44 -0800147 if (!pcepSessionFailurekeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530148 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 Hallcbd1b392017-01-18 20:15:44 -0800162 if (!pcepSessionFailurekeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530163 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 Hallcbd1b392017-01-18 20:15:44 -0800185 if (!pcepErrorMsgKey.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530186 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) {
Saritha66fee922017-05-10 12:40:48 +0530194 if (sessionFailureKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530195 System.out.print(sessionEstablishmentFailureMap.get(sessionFailureKey));
196 }
197 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800198 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530199 case CAPABALITYNOTSUPPORTED:
200 System.out.print("Capability not supported");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800201 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530202 case UNKNOWNOBJECT:
203 unknownObjectMap = pcepErrorDetail.unknownObject();
204 Set<Integer> unknownObjectKeySet = unknownObjectMap.keySet();
205 for (Integer unknownObjectKey : unknownObjectKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530206 if (unknownObjectKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530207 System.out.print(unknownObjectMap.get(unknownObjectKey));
208 }
209 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800210 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530211 case NOTSUPPORTEDOBJECT:
212 notSupportedObjectMap = pcepErrorDetail.notSupportedObject();
213 Set<Integer> notSupportedObjectKeySet = notSupportedObjectMap.keySet();
214 for (Integer notSupportedObjectKey : notSupportedObjectKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530215 if (notSupportedObjectKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530216 System.out.print(notSupportedObjectMap.get(notSupportedObjectKey));
217 }
218 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800219 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530220 case POLICYVIOLATION:
221 policyViolationMap = pcepErrorDetail.policyViolation();
222 Set<Integer> policyViolationKeySet = policyViolationMap.keySet();
223 for (Integer policyViolationKey : policyViolationKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530224 if (policyViolationKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530225 System.out.print(policyViolationMap.get(policyViolationKey));
226 }
227 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800228 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530229 case MANDATORYOBJECTMISSING:
230 mandatoryObjectMissingMap = pcepErrorDetail.mandatoryObjectMissing();
231 Set<Integer> mandatoryObjectMissingKeySet = mandatoryObjectMissingMap.keySet();
232 for (Integer mandatoryObjectMissingKey : mandatoryObjectMissingKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530233 if (mandatoryObjectMissingKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530234 System.out.print(mandatoryObjectMissingMap.get(mandatoryObjectMissingKey));
235 }
236 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800237 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530238 case SYNCHRONIZEDPATHCOMPUTATIONREQUESTMISSING:
239 System.out.print("Synchronized path computation request missing");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800240 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530241 case UNKNOWNREQUESTREFERENCE:
242 System.out.print("Unknown request reference");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800243 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530244 case ESTABLISHINGSECONDPCEPSESSION:
245 System.out.print("Attempt to establish a second PCEP session");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800246 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530247 case RECEPTIONOFINVALIDOBJECT:
248 receptionOfInvalidObjectMap = pcepErrorDetail.receptionOfInvalidObject();
249 Set<Integer> receptionOfInvalidObjectKeySet = receptionOfInvalidObjectMap.keySet();
250 for (Integer receptionOfInvalidObjectKey : receptionOfInvalidObjectKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530251 if (receptionOfInvalidObjectKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530252 System.out.print(receptionOfInvalidObjectMap.get(receptionOfInvalidObjectKey));
253 }
254 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800255 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530256 case INVALIDOPERATION:
257 invalidOperationMap = pcepErrorDetail.invalidOperation();
258 Set<Integer> invalidOperationKeySet = invalidOperationMap.keySet();
259 for (Integer invalidOperationKey : invalidOperationKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530260 if (invalidOperationKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530261 System.out.print(invalidOperationMap.get(invalidOperationKey));
262 }
263 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800264 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530265 case VIRTUALNETWORKTLVMISSING:
266 System.out.print("VIRTUAL-NETWORK TLV missing");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800267 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530268 default:
269 System.out.print("Unknown error message");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800270 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530271 }
272 }
273 }
274 } catch (Exception e) {
275 log.debug("Error occurred while displaying PCEP error messages received: {}", e.getMessage());
276 }
277 }
278}