blob: 678114a059b5d2cf9a97dbbca986b43e4d8f849c [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
22import org.apache.karaf.shell.commands.Command;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.net.DeviceId;
25import org.onosproject.segmentrouting.EcmpShortestPathGraph;
26import org.onosproject.segmentrouting.SegmentRoutingService;
27
28/**
29 * Command to read the current state of the ECMP shortest-path graph.
30 *
31 */
32@Command(scope = "onos", name = "sr-ecmp-spg",
33 description = "Displays the current ecmp shortest-path-graph in this "
34 + "controller instance")
35public class EcmpGraphCommand extends AbstractShellCommand {
36
37 private static final String FORMAT_MAPPING = " %s";
38
39 @Override
40 protected void execute() {
41 SegmentRoutingService srService =
42 AbstractShellCommand.get(SegmentRoutingService.class);
43 printEcmpGraph(srService.getCurrentEcmpSpg());
44 }
45
46 private void printEcmpGraph(Map<DeviceId, EcmpShortestPathGraph> currentEcmpSpg) {
47 if (currentEcmpSpg == null) {
48 print(FORMAT_MAPPING, "No ECMP graph found");
49 return;
50 }
51 StringBuilder ecmp = new StringBuilder();
52 currentEcmpSpg.forEach((key, value) -> {
53 ecmp.append("\n\nRoot Device: " + key + " ECMP Paths: " + value);
54 });
55 print(FORMAT_MAPPING, ecmp.toString());
56 }
57}