blob: 269134d4b4454b36bf603c04d5c2a01a57cbf7ce [file] [log] [blame]
Saurav Das62ae6792017-05-15 15:34:25 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Saurav Das62ae6792017-05-15 15:34:25 -07003 *
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
17package org.onosproject.segmentrouting.cli;
18
19
20import java.util.Map;
21
Ray Milkeydb38bc82018-09-27 12:32:28 -070022import org.apache.karaf.shell.api.action.Command;
Ray Milkey52ca4e92018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Saurav Das62ae6792017-05-15 15:34:25 -070024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.net.DeviceId;
26import org.onosproject.segmentrouting.EcmpShortestPathGraph;
27import org.onosproject.segmentrouting.SegmentRoutingService;
28
29/**
30 * Command to read the current state of the ECMP shortest-path graph.
31 *
32 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070033@Service
Saurav Das62ae6792017-05-15 15:34:25 -070034@Command(scope = "onos", name = "sr-ecmp-spg",
35 description = "Displays the current ecmp shortest-path-graph in this "
36 + "controller instance")
37public class EcmpGraphCommand extends AbstractShellCommand {
38
39 private static final String FORMAT_MAPPING = " %s";
40
41 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070042 protected void doExecute() {
Saurav Das62ae6792017-05-15 15:34:25 -070043 SegmentRoutingService srService =
44 AbstractShellCommand.get(SegmentRoutingService.class);
45 printEcmpGraph(srService.getCurrentEcmpSpg());
46 }
47
48 private void printEcmpGraph(Map<DeviceId, EcmpShortestPathGraph> currentEcmpSpg) {
49 if (currentEcmpSpg == null) {
50 print(FORMAT_MAPPING, "No ECMP graph found");
51 return;
52 }
53 StringBuilder ecmp = new StringBuilder();
54 currentEcmpSpg.forEach((key, value) -> {
55 ecmp.append("\n\nRoot Device: " + key + " ECMP Paths: " + value);
56 });
57 print(FORMAT_MAPPING, ecmp.toString());
58 }
59}