blob: 1af409a4c1f6e6ba2edec6fc3c748d0b8c397627 [file] [log] [blame]
Jonathan Hart0b04bed2014-10-16 16:39:19 -07001package org.onlab.onos.sdnip.cli;
2
3import org.apache.karaf.shell.commands.Command;
4import org.onlab.onos.cli.AbstractShellCommand;
5import org.onlab.onos.sdnip.RouteEntry;
6import 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")
13public 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}