blob: fddc1d77d02e23b3c8a0fd2dc64c0ae3ec3200f1 [file] [log] [blame]
Charles Chan0b1dd7e2018-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 Milkeydb38bc82018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Command;
Ray Milkey52ca4e92018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chan0b1dd7e2018-08-19 19:21:46 -070021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.segmentrouting.SegmentRoutingService;
23import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
24
25import java.util.ArrayList;
26import java.util.Comparator;
27import java.util.Map;
28
29/**
30 * Command to read the current state of the portNextObjStore.
31 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070032@Service
Charles Chan0b1dd7e2018-08-19 19:21:46 -070033@Command(scope = "onos", name = "sr-next-port",
34 description = "Displays the current port / next-id it mapping")
35public class NextPortCommand extends AbstractShellCommand {
36 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070037 protected void doExecute() {
Charles Chan0b1dd7e2018-08-19 19:21:46 -070038 SegmentRoutingService srService =
39 AbstractShellCommand.get(SegmentRoutingService.class);
40 print(srService.getPortNextObjStore());
41 }
42
43 private void print(Map<PortNextObjectiveStoreKey, Integer> portNextObjStore) {
44 ArrayList<PortNextObjectiveStoreKey> a = new ArrayList<>(portNextObjStore.keySet());
45 a.sort(Comparator
46 .comparing((PortNextObjectiveStoreKey o) -> o.deviceId().toString())
47 .thenComparing((PortNextObjectiveStoreKey o) -> o.portNumber().toLong()));
48
49 StringBuilder builder = new StringBuilder();
50 a.forEach(k ->
51 builder.append("\n")
52 .append(k)
53 .append(" --> ")
54 .append(portNextObjStore.get(k))
55 );
56 print(builder.toString());
57 }
58}