blob: 8518a5f729ae1362fa170640de851643ca579c40 [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.VlanNextObjectiveStoreKey;
24
25import java.util.ArrayList;
26import java.util.Comparator;
27import java.util.Map;
28
29/**
30 * Command to read the current state of the vlanNextObjStore.
31 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070032@Service
Charles Chan0b1dd7e2018-08-19 19:21:46 -070033@Command(scope = "onos", name = "sr-next-vlan",
34 description = "Displays the current vlan / next-id it mapping")
35public class NextVlanCommand 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.getVlanNextObjStore());
41 }
42
43 private void print(Map<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore) {
44 ArrayList<VlanNextObjectiveStoreKey> a = new ArrayList<>(vlanNextObjStore.keySet());
45 a.sort(Comparator
46 .comparing((VlanNextObjectiveStoreKey o) -> o.deviceId().toString())
47 .thenComparing((VlanNextObjectiveStoreKey o) -> o.vlanId().toShort()));
48
49 StringBuilder builder = new StringBuilder();
50 a.forEach(k ->
51 builder.append("\n")
52 .append(k)
53 .append(" --> ")
54 .append(vlanNextObjStore.get(k))
55 );
56 print(builder.toString());
57 }
58}