Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 1 | package org.onlab.onos.sdnip.cli; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Command; |
| 4 | import org.onlab.onos.cli.AbstractShellCommand; |
| 5 | import org.onlab.onos.sdnip.RouteEntry; |
| 6 | import org.onlab.onos.sdnip.SdnIpService; |
| 7 | |
| 8 | /** |
| 9 | * Command to show the list of routes in SDN-IP's routing table. |
| 10 | */ |
| 11 | @Command(scope = "onos", name = "routes", |
| 12 | description = "Lists all routes known to SDN-IP") |
| 13 | public class RoutesListCommand extends AbstractShellCommand { |
| 14 | |
| 15 | private static final String FORMAT = |
| 16 | "prefix=%s, nexthop=%s"; |
| 17 | |
| 18 | @Override |
| 19 | protected void execute() { |
| 20 | SdnIpService service = get(SdnIpService.class); |
| 21 | |
| 22 | for (RouteEntry route : service.getRoutes()) { |
| 23 | printRoute(route); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | private void printRoute(RouteEntry route) { |
| 28 | if (route != null) { |
| 29 | print(FORMAT, route.prefix(), route.nextHop()); |
| 30 | } |
| 31 | } |
| 32 | } |