blob: 0b81186a0961981ba411ef29a37bfbfa8d3180df [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;
Charles Chan0b1dd7e2018-08-19 19:21:46 -070022import org.onosproject.segmentrouting.xconnect.api.XconnectKey;
23import org.onosproject.segmentrouting.xconnect.api.XconnectService;
24
25import java.util.ArrayList;
26import java.util.Comparator;
27import java.util.Map;
28
29/**
30 * Command to read the current state of the xconnect next stores.
31 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070032@Service
Charles Chan0b1dd7e2018-08-19 19:21:46 -070033@Command(scope = "onos", name = "sr-next-xconnect",
34 description = "Displays the current next-id for xconnect")
35public class XconnectNextListCommand extends AbstractShellCommand {
36 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070037 protected void doExecute() {
Charles Chan0b1dd7e2018-08-19 19:21:46 -070038 XconnectService xconnectService =
39 AbstractShellCommand.get(XconnectService.class);
40 print(xconnectService.getNext());
41 }
42
Charles Chan1fb65132018-09-21 11:29:12 -070043 private void print(Map<XconnectKey, Integer> nextStore) {
Charles Chan0b1dd7e2018-08-19 19:21:46 -070044 ArrayList<XconnectKey> a = new ArrayList<>(nextStore.keySet());
45 a.sort(Comparator
46 .comparing((XconnectKey o) -> o.deviceId().toString())
47 .thenComparing((XconnectKey o) -> o.vlanId().toShort()));
48
49 StringBuilder builder = new StringBuilder();
50 a.forEach(k ->
51 builder.append("\n")
52 .append(k)
53 .append(" --> ")
Charles Chan1fb65132018-09-21 11:29:12 -070054 .append(nextStore.get(k))
Charles Chan0b1dd7e2018-08-19 19:21:46 -070055 );
56 print(builder.toString());
57 }
58}