Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.segmentrouting.cli; |
| 18 | |
| 19 | |
| 20 | import java.util.Map; |
| 21 | |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 24 | import org.onosproject.cli.AbstractShellCommand; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.segmentrouting.EcmpShortestPathGraph; |
| 27 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 28 | |
| 29 | /** |
| 30 | * Command to read the current state of the ECMP shortest-path graph. |
| 31 | * |
| 32 | */ |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 33 | @Service |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 34 | @Command(scope = "onos", name = "sr-ecmp-spg", |
| 35 | description = "Displays the current ecmp shortest-path-graph in this " |
| 36 | + "controller instance") |
| 37 | public class EcmpGraphCommand extends AbstractShellCommand { |
| 38 | |
| 39 | private static final String FORMAT_MAPPING = " %s"; |
| 40 | |
| 41 | @Override |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 42 | protected void doExecute() { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 43 | 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 | } |