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