blob: 82a30ffc6423896519e675705b7027cad36a5062 [file] [log] [blame]
Charles Chand5814aa2018-08-19 19:21:46 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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
17package org.onosproject.segmentrouting.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Command;
Charles Chand5814aa2018-08-19 19:21:46 -070020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.flowobjective.NextObjective;
22import org.onosproject.segmentrouting.SegmentRoutingService;
23
24import java.util.ArrayList;
25import java.util.Comparator;
26import java.util.Map;
27
28/**
29 * Command to read the current state of the pseudowire next stores.
30 */
31@Command(scope = "onos", name = "sr-next-pw",
32 description = "Displays the current next-id for pseudowire")
33public class PseudowireNextListCommand extends AbstractShellCommand {
34 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070035 protected void doExecute() {
Charles Chand5814aa2018-08-19 19:21:46 -070036 SegmentRoutingService srService =
37 AbstractShellCommand.get(SegmentRoutingService.class);
38 print(srService.getPwInitNext());
39 print(srService.getPwTermNext());
40 }
41
42 private void print(Map<String, NextObjective> nextStore) {
43 ArrayList<String> a = new ArrayList<>(nextStore.keySet());
44 a.sort(Comparator.comparing((String o) -> o));
45
46 StringBuilder builder = new StringBuilder();
47 a.forEach(k ->
48 builder.append("\n")
49 .append(k)
50 .append(" --> ")
51 .append(nextStore.get(k).id())
52 );
53 print(builder.toString());
54 }
55}