Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.segmentrouting.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 23 | import org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.Comparator; |
| 27 | import 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") |
| 35 | public 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 | } |