blob: b87e0bf133f117eb182f3441d7a919750a7cbbf8 [file] [log] [blame]
Jonathan Hartbfc5c482016-04-05 18:57:00 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hartbfc5c482016-04-05 18:57:00 -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 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.incubator.net.routing.Route;
21import org.onosproject.incubator.net.routing.RouteService;
22import org.onosproject.incubator.net.routing.RouteTableId;
23
24import java.util.Collection;
25import java.util.Map;
26
27/**
28 * Command to show the routes in the routing tables.
29 */
30// TODO update command name when we switch over to new rib
31@Command(scope = "onos", name = "routes2",
32 description = "Lists all routes in the route store")
33public class RoutesListCommand 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 @Override
44 protected void execute() {
45 RouteService service = AbstractShellCommand.get(RouteService.class);
46
47 Map<RouteTableId, Collection<Route>> allRoutes = service.getAllRoutes();
48
49 allRoutes.forEach((id, routes) -> {
50 print(FORMAT_TABLE, id);
51 print(FORMAT_HEADER);
52 routes.forEach(r -> print(FORMAT_ROUTE, r.prefix(), r.nextHop()));
53 print(FORMAT_TOTAL, routes.size());
54 print("");
55 });
56
57 }
58
59}