Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 16 | package org.onlab.onos.sdnip.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Command; |
| 19 | import org.onlab.onos.cli.AbstractShellCommand; |
| 20 | import org.onlab.onos.sdnip.RouteEntry; |
| 21 | import org.onlab.onos.sdnip.SdnIpService; |
| 22 | |
| 23 | /** |
| 24 | * Command to show the list of routes in SDN-IP's routing table. |
| 25 | */ |
| 26 | @Command(scope = "onos", name = "routes", |
| 27 | description = "Lists all routes known to SDN-IP") |
| 28 | public class RoutesListCommand extends AbstractShellCommand { |
| 29 | |
| 30 | private static final String FORMAT = |
| 31 | "prefix=%s, nexthop=%s"; |
| 32 | |
| 33 | @Override |
| 34 | protected void execute() { |
| 35 | SdnIpService service = get(SdnIpService.class); |
| 36 | |
| 37 | for (RouteEntry route : service.getRoutes()) { |
| 38 | printRoute(route); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | private void printRoute(RouteEntry route) { |
| 43 | if (route != null) { |
| 44 | print(FORMAT, route.prefix(), route.nextHop()); |
| 45 | } |
| 46 | } |
| 47 | } |