blob: 0c4445300f4adfb2b3853cc33aa520ae84c6857a [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Jonathan Hart0b04bed2014-10-16 16:39:19 -070016package org.onlab.onos.sdnip.cli;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onlab.onos.cli.AbstractShellCommand;
20import org.onlab.onos.sdnip.RouteEntry;
21import 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")
28public 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}