blob: e31e6931eddd356719b37ff21f372d7e0d7202ad [file] [log] [blame]
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001/*
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.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.segmentrouting.SegmentRoutingService;
23import org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey;
24
25import java.util.ArrayList;
26import java.util.Comparator;
27import java.util.Map;
28
29/**
30 * Command to read the current state of the macVlanNextObjStore.
31 */
32@Service
33@Command(scope = "onos", name = "sr-next-mac-vlan",
34 description = "Displays the current next-hop / next-id it mapping")
35public class NextMacVlanCommand extends AbstractShellCommand {
36 @Override
37 protected void doExecute() {
38 SegmentRoutingService srService =
39 AbstractShellCommand.get(SegmentRoutingService.class);
40 print(srService.getMacVlanNextObjStore());
41 }
42
43 private void print(Map<MacVlanNextObjectiveStoreKey, Integer> macVlanNextObjStore) {
44 ArrayList<MacVlanNextObjectiveStoreKey> a = new ArrayList<>(macVlanNextObjStore.keySet());
45 a.sort(Comparator
46 .comparing((MacVlanNextObjectiveStoreKey o) -> o.deviceId().toString())
47 .thenComparing((MacVlanNextObjectiveStoreKey o) -> o.vlanId().toString())
48 .thenComparing((MacVlanNextObjectiveStoreKey o) -> o.macAddr().toString()));
49
50 StringBuilder builder = new StringBuilder();
51 a.forEach(k ->
52 builder.append("\n")
53 .append(k)
54 .append(" --> ")
55 .append(macVlanNextObjStore.get(k))
56 );
57 print(builder.toString());
58 }
59}