blob: f7a6b517ada39ddcf08efe4041753aaf9b3488b5 [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.net.flowobjective.NextObjective;
22import 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 */
32@Command(scope = "onos", name = "sr-next-xconnect",
33 description = "Displays the current next-id for xconnect")
34public class XconnectNextListCommand extends AbstractShellCommand {
35 @Override
36 protected void execute() {
37 XconnectService xconnectService =
38 AbstractShellCommand.get(XconnectService.class);
39 print(xconnectService.getNext());
40 }
41
42 private void print(Map<XconnectKey, NextObjective> nextStore) {
43 ArrayList<XconnectKey> a = new ArrayList<>(nextStore.keySet());
44 a.sort(Comparator
45 .comparing((XconnectKey o) -> o.deviceId().toString())
46 .thenComparing((XconnectKey o) -> o.vlanId().toShort()));
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}