Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 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.commands.Command; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 20 | import org.onlab.packet.IpPrefix; |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 24 | |
| 25 | import java.util.Map; |
| 26 | import java.util.Set; |
| 27 | |
| 28 | /** |
| 29 | * Command to list device-subnet mapping in Segment Routing. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "sr-device-subnets", |
| 32 | description = "List device-subnet mapping in Segment Routing") |
| 33 | public class DeviceSubnetListCommand extends AbstractShellCommand { |
| 34 | @Override |
| 35 | protected void execute() { |
| 36 | SegmentRoutingService srService = |
| 37 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 38 | printDeviceSubnetMap(srService.getDeviceSubnetMap()); |
| 39 | } |
| 40 | |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 41 | private void printDeviceSubnetMap(Map<DeviceId, Set<IpPrefix>> deviceSubnetMap) { |
| 42 | deviceSubnetMap.forEach(((deviceId, ipPrefices) -> { |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 43 | print("%s", deviceId); |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame] | 44 | ipPrefices.forEach(ipPrefix -> print(" %s", ipPrefix)); |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 45 | })); |
| 46 | } |
| 47 | } |