blob: f2b3e8d2bb29f765e16549b89ae8f3aac5108be6 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chand5814aa2018-08-19 19:21:46 -070021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.flowobjective.NextObjective;
23import org.onosproject.segmentrouting.SegmentRoutingService;
24
25import java.util.ArrayList;
26import java.util.Comparator;
27import java.util.Map;
28
29/**
30 * Command to read the current state of the pseudowire next stores.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Charles Chand5814aa2018-08-19 19:21:46 -070033@Command(scope = "onos", name = "sr-next-pw",
34 description = "Displays the current next-id for pseudowire")
35public class PseudowireNextListCommand extends AbstractShellCommand {
36 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070037 protected void doExecute() {
Charles Chand5814aa2018-08-19 19:21:46 -070038 SegmentRoutingService srService =
39 AbstractShellCommand.get(SegmentRoutingService.class);
40 print(srService.getPwInitNext());
41 print(srService.getPwTermNext());
42 }
43
44 private void print(Map<String, NextObjective> nextStore) {
45 ArrayList<String> a = new ArrayList<>(nextStore.keySet());
46 a.sort(Comparator.comparing((String o) -> o));
47
48 StringBuilder builder = new StringBuilder();
49 a.forEach(k ->
50 builder.append("\n")
51 .append(k)
52 .append(" --> ")
53 .append(nextStore.get(k).id())
54 );
55 print(builder.toString());
56 }
57}