Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -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 | package org.onosproject.cli.net; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
| 19 | import org.onosproject.cli.AbstractShellCommand; |
| 20 | import org.onosproject.incubator.net.routing.Route; |
| 21 | import org.onosproject.incubator.net.routing.RouteService; |
| 22 | import org.onosproject.incubator.net.routing.RouteTableId; |
| 23 | |
| 24 | import java.util.Collection; |
| 25 | import 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") |
| 33 | public 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 | } |