blob: d7d518995ca084cef515aeef8d688e51d7109e6d [file] [log] [blame]
Jonathan Hartfd176612016-04-11 10:42:10 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hartfd176612016-04-11 10:42:10 -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.cli.net;
18
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.incubator.net.routing.NextHop;
22import org.onosproject.incubator.net.routing.Route;
23import org.onosproject.incubator.net.routing.RouteService;
24
25import java.util.Collection;
26import java.util.Set;
27
28/**
29 * Command to show information about routing next hops.
30 */
31@Command(scope = "onos", name = "next-hops",
32 description = "Lists all next hops in the route store")
33public class NextHopsListCommand extends AbstractShellCommand {
34
35 private static final String FORMAT_HEADER =
36 " Network Next Hop";
37 private static final String FORMAT_ROUTE =
38 " %-18s %-15s";
39
40 private static final String FORMAT_TABLE = "Table: %s";
41 private static final String FORMAT_TOTAL = " Total: %d";
42
43 private static final String FORMAT = "ip=%s, mac=%s, numRoutes=%s";
44
45 @Override
46 protected void execute() {
47 RouteService service = AbstractShellCommand.get(RouteService.class);
48
49 Set<NextHop> nextHops = service.getNextHops();
50
51 nextHops.forEach(nextHop -> {
52 Collection<Route> routes = service.getRoutesForNextHop(nextHop.ip());
53 print(FORMAT, nextHop.ip(), nextHop.mac(), routes.size());
54 });
55
56 }
57
58}