blob: 5be9d77a2a71f6bc5dae3f6407e2d11097a08c5f [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
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.segmentrouting.SegmentRoutingService;
22import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
23
24import java.util.ArrayList;
25import java.util.Comparator;
26import java.util.Map;
27
28/**
29 * Command to read the current state of the portNextObjStore.
30 */
31@Command(scope = "onos", name = "sr-next-port",
32 description = "Displays the current port / next-id it mapping")
33public class NextPortCommand extends AbstractShellCommand {
34 @Override
35 protected void execute() {
36 SegmentRoutingService srService =
37 AbstractShellCommand.get(SegmentRoutingService.class);
38 print(srService.getPortNextObjStore());
39 }
40
41 private void print(Map<PortNextObjectiveStoreKey, Integer> portNextObjStore) {
42 ArrayList<PortNextObjectiveStoreKey> a = new ArrayList<>(portNextObjStore.keySet());
43 a.sort(Comparator
44 .comparing((PortNextObjectiveStoreKey o) -> o.deviceId().toString())
45 .thenComparing((PortNextObjectiveStoreKey o) -> o.portNumber().toLong()));
46
47 StringBuilder builder = new StringBuilder();
48 a.forEach(k ->
49 builder.append("\n")
50 .append(k)
51 .append(" --> ")
52 .append(portNextObjStore.get(k))
53 );
54 print(builder.toString());
55 }
56}