blob: f15555c455a3354c3739dde4fcce4e79c8a6bd7d [file] [log] [blame]
Manikandan Kf0b17ff2016-05-10 20:13:17 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Manikandan Kf0b17ff2016-05-10 20:13:17 +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.isis.cli;
17
Ray Milkey7a2dee52018-09-28 10:58:28 -070018import org.apache.karaf.shell.api.action.lifecycle.Service;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.osgi.service.component.annotations.Activate;
20import org.osgi.service.component.annotations.Deactivate;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070021import org.apache.karaf.shell.api.action.Argument;
22import org.apache.karaf.shell.api.action.Command;
Manikandan Kf0b17ff2016-05-10 20:13:17 +053023import org.onlab.packet.MacAddress;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.isis.controller.IsisController;
26import org.onosproject.isis.controller.IsisInterface;
27import org.onosproject.isis.controller.IsisLsdb;
28import org.onosproject.isis.controller.IsisNeighbor;
29import org.onosproject.isis.controller.IsisNetworkType;
30import org.onosproject.isis.controller.IsisProcess;
31import org.onosproject.isis.controller.IsisRouterType;
32import org.onosproject.isis.controller.LspWrapper;
33import org.onosproject.isis.io.isispacket.pdu.LsPdu;
34import org.onosproject.isis.io.util.IsisConstants;
35import org.slf4j.Logger;
36import org.slf4j.LoggerFactory;
37
38import java.net.NetworkInterface;
39import java.util.Iterator;
40import java.util.List;
41import java.util.Map;
42import java.util.Set;
43
44/**
45 * Lists ISIS neighbors, database and interfaces details.
46 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070047@Service
Manikandan Kf0b17ff2016-05-10 20:13:17 +053048@Command(scope = "onos", name = "isis", description = "lists database, neighbors and interfaces")
49public class ApplicationIsisCommand extends AbstractShellCommand {
50 private static final Logger log = LoggerFactory.getLogger(ApplicationIsisCommand.class);
51 private static final String INTERFACE = "interface";
52 private static final String DATABASE = "database";
53 private static final String NEIGHBOR = "neighbor";
54 private static final String P2P = "P2P";
55 private static final String LAN = "LAN";
56 private static final String L1 = "L1";
57 private static final String L2 = "L2";
58 private static final String L1L2 = "L1L2";
59 protected IsisController isisController;
60 @Argument(index = 0, name = "name",
61 description = "interface|database|neighbor",
62 required = true, multiValued = false)
63 String name = null;
64 @Argument(index = 1, name = "processId",
65 description = "processId", required = true, multiValued = false)
66 String processId = null;
67
68 @Activate
69 public void activate() {
70 log.debug("Activated...!!!");
71 }
72
73 @Deactivate
74 public void deactivate() {
75 log.debug("Deactivated...!!!");
76 }
77
78 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070079 protected void doExecute() {
Manikandan Kf0b17ff2016-05-10 20:13:17 +053080 switch (name) {
81 case INTERFACE:
82 displayIsisInterfaces();
83 break;
84 case NEIGHBOR:
85 displayIsisNeighbors();
86 break;
87 case DATABASE:
88 displayIsisDatabase();
89 break;
90 default:
91 log.debug("Unknown command...!!");
92 break;
93 }
94 }
95
96 /**
97 * Displays ISIS neighbor details.
98 */
99 private void displayIsisNeighbors() {
100 String interfaceName = "";
101 String circuitType = "";
102 boolean invalidProcess = true;
103 try {
104 this.isisController = get(IsisController.class);
105 List<IsisProcess> listOfProcess = isisController.allConfiguredProcesses();
106 if (listOfProcess == null) {
107 return;
108 }
109 displayNeighborHeader();
110 Iterator<IsisProcess> itrProcess = listOfProcess.iterator();
111 while (itrProcess.hasNext()) {
112 IsisProcess isisProcess = itrProcess.next();
113 if (processId != null && processId.trim().equals(isisProcess.processId())) {
114 invalidProcess = false;
115 List<IsisInterface> interfaceList = isisProcess.isisInterfaceList();
116 Iterator<IsisInterface> itrInterface = interfaceList.iterator();
117 while (itrInterface.hasNext()) {
118 IsisInterface isisInterface = itrInterface.next();
119 interfaceName = NetworkInterface.getByIndex(isisInterface.interfaceIndex()).getName();
120 Set<MacAddress> getNeighborList = isisInterface.neighbors();
121 for (MacAddress mac : getNeighborList) {
122 IsisNeighbor neighbor = isisInterface.lookup(mac);
123 switch (neighbor.routerType()) {
124 case L1:
125 circuitType = L1;
126 break;
127 case L2:
128 circuitType = L2;
129 break;
130 case L1L2:
131 circuitType = L1L2;
132 break;
133 default:
134 log.debug("Unknown circuit type...!!");
135 break;
136 }
137 print("%-20s%-20s%-20s%-20s%-20s%-20s\n", neighbor.neighborSystemId(),
138 neighbor.neighborMacAddress().toString(), interfaceName,
139 circuitType, neighbor.interfaceState(), neighbor.holdingTime());
140 }
141 }
142 }
143 }
144 if (invalidProcess) {
145 print("%s\n", "Process " + processId + " not exist...!!!");
146 }
147 } catch (Exception e) {
148 log.debug("Error occurred while displaying ISIS neighbor: {}", e.getMessage());
149 }
150 }
151
152 /**
153 * Displays ISIS database details.
154 */
155 private void displayIsisDatabase() {
156 try {
157 this.isisController = get(IsisController.class);
158 List<IsisProcess> listOfProcess = isisController.allConfiguredProcesses();
159 Iterator<IsisProcess> itrProcess = listOfProcess.iterator();
160 boolean invalidProcess = true;
161 while (itrProcess.hasNext()) {
162 IsisProcess isisProcess = itrProcess.next();
163 if (processId != null && processId.trim().equals(isisProcess.processId())) {
164 invalidProcess = false;
165 List<IsisInterface> interfaceList = isisProcess.isisInterfaceList();
166 Iterator<IsisInterface> itrInterface = interfaceList.iterator();
167 if (itrInterface.hasNext()) {
168 IsisInterface isisInterface = itrInterface.next();
169 IsisLsdb isisLsdb = isisInterface.isisLsdb();
170 if (isisLsdb != null) {
171 Map<String, LspWrapper> lsWrapperListL1 = isisLsdb.getL1Db();
172 Map<String, LspWrapper> lsWrapperListL2 = isisLsdb.getL2Db();
173 Set<String> l1Wrapper = lsWrapperListL1.keySet();
174 Set<String> l2Wrapper = lsWrapperListL2.keySet();
175 if (l1Wrapper.size() > 0) {
176 print("IS-IS Level-1 link-state database:");
177 displayDatabaseHeader();
178 for (String string : l1Wrapper) {
179 LspWrapper lspWrapper = lsWrapperListL1.get(string);
180 LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu();
181 print("%-25s%-25s%-25s%-25s%-25s\n", lsPdu.lspId(), lsPdu.pduLength(),
182 lsPdu.sequenceNumber(),
183 Integer.toHexString(lsPdu.checkSum()), lspWrapper.remainingLifetime());
184 }
185 }
186 if (l2Wrapper.size() > 0) {
187 print("IS-IS Level-2 link-state database:");
188 displayDatabaseHeader();
189 for (String string2 : l2Wrapper) {
190 LspWrapper lspWrapper2 = lsWrapperListL2.get(string2);
191 LsPdu lsPdu2 = (LsPdu) lspWrapper2.lsPdu();
192 print("%-25s%-25s%-25s%-25s%-25s\n", lsPdu2.lspId(), lsPdu2.pduLength(),
193 lsPdu2.sequenceNumber(), Integer.toHexString(lsPdu2.checkSum()),
194 IsisConstants.LSPMAXAGE - lspWrapper2.currentAge());
195 }
196 }
197 break;
198 }
199 }
200 }
201 }
202 if (invalidProcess) {
203 print("%s\n", "Process " + processId + " not exist...!!!");
204 }
205 } catch (Exception e) {
206 log.debug("Error occurred while displaying ISIS database: {}", e.getMessage());
207 }
208 }
209
210 /**
211 * Displays ISIS interfaces.
212 */
213 private void displayIsisInterfaces() {
214 String interfaceName = "";
215 String networkType = "";
216 String circuitType = "";
217 boolean invalidProcess = true;
218 try {
219 this.isisController = get(IsisController.class);
220 List<IsisProcess> listOfProcess = isisController.allConfiguredProcesses();
221 if (listOfProcess == null) {
222 return;
223 }
224 displayInterfaceHeader();
225 Iterator<IsisProcess> itrProcess = listOfProcess.iterator();
226 while (itrProcess.hasNext()) {
227 IsisProcess isisProcess = itrProcess.next();
228 if (processId != null && processId.trim().equals(isisProcess.processId())) {
229 invalidProcess = false;
230 List<IsisInterface> interfaceList = isisProcess.isisInterfaceList();
231 for (IsisInterface isisInterface : interfaceList) {
232
233 if (isisInterface.networkType() == IsisNetworkType.P2P) {
234 networkType = P2P;
235 } else {
236 networkType = LAN;
237 }
238
239 switch (IsisRouterType.get(isisInterface.reservedPacketCircuitType())) {
240 case L1:
241 circuitType = L1;
242 break;
243 case L2:
244 circuitType = L2;
245 break;
246 case L1L2:
247 circuitType = L1L2;
248 break;
249 default:
250 log.debug("Unknown circuit type...!!");
251 break;
252 }
253 interfaceName = NetworkInterface.getByIndex(isisInterface.interfaceIndex()).getName();
254 print("%-20s%-20s%-20s%-20s\n", interfaceName, isisInterface.areaAddress(),
255 networkType, circuitType);
256 }
257 }
258 }
259 if (invalidProcess) {
260 print("%s\n", "Process " + processId + " not exist...!!!");
261 }
262 } catch (Exception e) {
263 log.debug("Error occurred while displaying ISIS interface: {}", e.getMessage());
264 }
265 }
266
267 /**
268 * Displays ISIS interface header.
269 */
270 private void displayInterfaceHeader() {
271 print("%-20s%-20s%-20s%-20s\n", "Interface", "Area Id", "TYPE", "Level");
272 }
273
274 /**
275 * Displays ISIS neighbor header.
276 */
277 private void displayNeighborHeader() {
278 print("%-20s%-20s%-20s%-20s%-20s%-20s\n", "System Id", "Mac Id", "Interface",
279 "Level", "State", "Holding Time");
280 }
281
282 /**
283 * Displays ISIS database header.
284 */
285 private void displayDatabaseHeader() {
286 print("%-25s%-25s%-25s%-25s%-25s\n", "LSP ID ", "PduLen", "SeqNumber", "Checksum",
287 "Remaining Life Time");
288 }
289}