blob: d084cc3751bc929299ab4cbac8a6b6700f3a4c2c [file] [log] [blame]
Saurav Dasc88d4662017-05-15 15:34:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Saurav Dasc88d4662017-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.segmentrouting.SegmentRoutingService;
25import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey;
26
27/**
28 * Command to read the current state of the neighborSetNextObjectiveStore.
29 *
30 */
31@Command(scope = "onos", name = "sr-ns-objstore",
32 description = "Displays the current neighborSet seen by each switch "
33 + "in the network and the next-id it maps to")
34public class NeighborSetCommand extends AbstractShellCommand {
35
36 private static final String FORMAT_MAPPING = " %s";
37
38 @Override
39 protected void execute() {
40 SegmentRoutingService srService =
41 AbstractShellCommand.get(SegmentRoutingService.class);
42 printNeighborSet(srService.getNeighborSet());
43 }
44
45 private void printNeighborSet(Map<NeighborSetNextObjectiveStoreKey, Integer> ns) {
46 StringBuilder nsbldr = new StringBuilder();
47 ns.entrySet().forEach(entry -> {
48 nsbldr.append("\n " + entry.getKey());
49 nsbldr.append(" --> NextId: " + entry.getValue());
50 });
51 print(FORMAT_MAPPING, nsbldr.toString());
52 }
53}