blob: 8f706b0874cb02bda2d32b49000c89ec841a583d [file] [log] [blame]
Charles Chanc81c45b2016-10-20 17:02:44 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chanc81c45b2016-10-20 17:02:44 -07003 *
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 Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Pier Ventre10bd8d12016-11-26 21:05:22 -080021import org.onlab.packet.IpPrefix;
Charles Chanc81c45b2016-10-20 17:02:44 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.DeviceId;
24import org.onosproject.segmentrouting.SegmentRoutingService;
25
26import java.util.Map;
27import java.util.Set;
28
29/**
30 * Command to list device-subnet mapping in Segment Routing.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Charles Chanc81c45b2016-10-20 17:02:44 -070033@Command(scope = "onos", name = "sr-device-subnets",
34 description = "List device-subnet mapping in Segment Routing")
35public class DeviceSubnetListCommand extends AbstractShellCommand {
36 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070037 protected void doExecute() {
Charles Chanc81c45b2016-10-20 17:02:44 -070038 SegmentRoutingService srService =
39 AbstractShellCommand.get(SegmentRoutingService.class);
40 printDeviceSubnetMap(srService.getDeviceSubnetMap());
41 }
42
Pier Ventre10bd8d12016-11-26 21:05:22 -080043 private void printDeviceSubnetMap(Map<DeviceId, Set<IpPrefix>> deviceSubnetMap) {
44 deviceSubnetMap.forEach(((deviceId, ipPrefices) -> {
Charles Chanc81c45b2016-10-20 17:02:44 -070045 print("%s", deviceId);
Pier Ventref4b5fce2016-11-28 16:48:06 -080046 ipPrefices.forEach(ipPrefix -> print(" %s", ipPrefix));
Charles Chanc81c45b2016-10-20 17:02:44 -070047 }));
48 }
49}