blob: e1fc2a5a8a36f22adb49de87f61a112d2995e8e3 [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;
mohamedrahil00f6f262016-11-24 20:20:41 +053021import org.onosproject.cli.AbstractShellCommand;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053022import org.onosproject.pcep.server.PcepClientController;
23import org.onosproject.pcep.server.PcepErrorDetail;
24import org.onosproject.pcep.server.PcepErrorType;
mohamedrahil00f6f262016-11-24 20:20:41 +053025import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import java.util.Set;
29import java.util.Map;
30import java.util.List;
31import java.util.ArrayList;
32import java.util.TreeMap;
33
34
35@Command(scope = "onos", name = "pcep", description = "Pcep Session Info")
36public 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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070071 protected void doExecute() {
mohamedrahil00f6f262016-11-24 20:20:41 +053072 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) {
Jon Hallcbd1b392017-01-18 20:15:44 -080096 if (!pcepSessionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +053097 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 {
Jon Hallcbd1b392017-01-18 20:15:44 -0800119 if (!pcepSessionKeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530120 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();
Jon Hallcbd1b392017-01-18 20:15:44 -0800146 if (!pcepSessionFailurekeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530147 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();
Jon Hallcbd1b392017-01-18 20:15:44 -0800161 if (!pcepSessionFailurekeySet.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530162 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();
Jon Hallcbd1b392017-01-18 20:15:44 -0800184 if (!pcepErrorMsgKey.isEmpty()) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530185 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) {
Saritha66fee922017-05-10 12:40:48 +0530193 if (sessionFailureKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530194 System.out.print(sessionEstablishmentFailureMap.get(sessionFailureKey));
195 }
196 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800197 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530198 case CAPABALITYNOTSUPPORTED:
199 System.out.print("Capability not supported");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800200 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530201 case UNKNOWNOBJECT:
202 unknownObjectMap = pcepErrorDetail.unknownObject();
203 Set<Integer> unknownObjectKeySet = unknownObjectMap.keySet();
204 for (Integer unknownObjectKey : unknownObjectKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530205 if (unknownObjectKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530206 System.out.print(unknownObjectMap.get(unknownObjectKey));
207 }
208 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800209 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530210 case NOTSUPPORTEDOBJECT:
211 notSupportedObjectMap = pcepErrorDetail.notSupportedObject();
212 Set<Integer> notSupportedObjectKeySet = notSupportedObjectMap.keySet();
213 for (Integer notSupportedObjectKey : notSupportedObjectKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530214 if (notSupportedObjectKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530215 System.out.print(notSupportedObjectMap.get(notSupportedObjectKey));
216 }
217 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800218 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530219 case POLICYVIOLATION:
220 policyViolationMap = pcepErrorDetail.policyViolation();
221 Set<Integer> policyViolationKeySet = policyViolationMap.keySet();
222 for (Integer policyViolationKey : policyViolationKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530223 if (policyViolationKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530224 System.out.print(policyViolationMap.get(policyViolationKey));
225 }
226 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800227 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530228 case MANDATORYOBJECTMISSING:
229 mandatoryObjectMissingMap = pcepErrorDetail.mandatoryObjectMissing();
230 Set<Integer> mandatoryObjectMissingKeySet = mandatoryObjectMissingMap.keySet();
231 for (Integer mandatoryObjectMissingKey : mandatoryObjectMissingKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530232 if (mandatoryObjectMissingKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530233 System.out.print(mandatoryObjectMissingMap.get(mandatoryObjectMissingKey));
234 }
235 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800236 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530237 case SYNCHRONIZEDPATHCOMPUTATIONREQUESTMISSING:
238 System.out.print("Synchronized path computation request missing");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800239 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530240 case UNKNOWNREQUESTREFERENCE:
241 System.out.print("Unknown request reference");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800242 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530243 case ESTABLISHINGSECONDPCEPSESSION:
244 System.out.print("Attempt to establish a second PCEP session");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800245 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530246 case RECEPTIONOFINVALIDOBJECT:
247 receptionOfInvalidObjectMap = pcepErrorDetail.receptionOfInvalidObject();
248 Set<Integer> receptionOfInvalidObjectKeySet = receptionOfInvalidObjectMap.keySet();
249 for (Integer receptionOfInvalidObjectKey : receptionOfInvalidObjectKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530250 if (receptionOfInvalidObjectKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530251 System.out.print(receptionOfInvalidObjectMap.get(receptionOfInvalidObjectKey));
252 }
253 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800254 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530255 case INVALIDOPERATION:
256 invalidOperationMap = pcepErrorDetail.invalidOperation();
257 Set<Integer> invalidOperationKeySet = invalidOperationMap.keySet();
258 for (Integer invalidOperationKey : invalidOperationKeySet) {
Saritha66fee922017-05-10 12:40:48 +0530259 if (invalidOperationKey.equals(pcepErrorValue)) {
mohamedrahil00f6f262016-11-24 20:20:41 +0530260 System.out.print(invalidOperationMap.get(invalidOperationKey));
261 }
262 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800263 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530264 case VIRTUALNETWORKTLVMISSING:
265 System.out.print("VIRTUAL-NETWORK TLV missing");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800266 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530267 default:
268 System.out.print("Unknown error message");
Ray Milkeyd6a67c32018-02-02 10:30:35 -0800269 break;
mohamedrahil00f6f262016-11-24 20:20:41 +0530270 }
271 }
272 }
273 } catch (Exception e) {
274 log.debug("Error occurred while displaying PCEP error messages received: {}", e.getMessage());
275 }
276 }
277}