blob: 18b203393ef97ef6dd764abf638056dd67116aa3 [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;
Charles Chand5814aa2018-08-19 19:21:46 -070021import org.onosproject.segmentrouting.xconnect.api.XconnectKey;
22import org.onosproject.segmentrouting.xconnect.api.XconnectService;
23
24import java.util.ArrayList;
25import java.util.Comparator;
26import java.util.Map;
27
28/**
29 * Command to read the current state of the xconnect next stores.
30 */
31@Command(scope = "onos", name = "sr-next-xconnect",
32 description = "Displays the current next-id for xconnect")
33public class XconnectNextListCommand extends AbstractShellCommand {
34 @Override
35 protected void execute() {
36 XconnectService xconnectService =
37 AbstractShellCommand.get(XconnectService.class);
38 print(xconnectService.getNext());
39 }
40
Charles Chan3e56d9f2018-09-21 11:29:12 -070041 private void print(Map<XconnectKey, Integer> nextStore) {
Charles Chand5814aa2018-08-19 19:21:46 -070042 ArrayList<XconnectKey> a = new ArrayList<>(nextStore.keySet());
43 a.sort(Comparator
44 .comparing((XconnectKey o) -> o.deviceId().toString())
45 .thenComparing((XconnectKey o) -> o.vlanId().toShort()));
46
47 StringBuilder builder = new StringBuilder();
48 a.forEach(k ->
49 builder.append("\n")
50 .append(k)
51 .append(" --> ")
Charles Chan3e56d9f2018-09-21 11:29:12 -070052 .append(nextStore.get(k))
Charles Chand5814aa2018-08-19 19:21:46 -070053 );
54 print(builder.toString());
55 }
56}