blob: 71ad03fbde92d70e5375bb7455bbc6395a90c246 [file] [log] [blame]
jiangruia0fc6052015-11-28 14:03:42 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangruia0fc6052015-11-28 14:03:42 +08003 *
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 */
16package org.onosproject.vtnrsc.cli.routerinterface;
17
18import org.apache.karaf.shell.commands.Command;
19import org.apache.karaf.shell.commands.Option;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.vtnrsc.RouterInterface;
22import org.onosproject.vtnrsc.SubnetId;
23import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService;
24
25/**
26 * Supports for query a router interface.
27 */
28@Command(scope = "onos", name = "routerinterfaces", description = "Supports for querying a router interface")
29public class RouterInterfaceQueryCommand extends AbstractShellCommand {
30 @Option(name = "-s", aliases = "--subnetId", description = "The subnet identifier of router interface",
31 required = false, multiValued = false)
32 String subnetId = null;
33
34 private static final String FMT = "subnetId=%s, tenantId=%s, portId=%s, routerId=%s";
35
36 @Override
37 protected void execute() {
38 RouterInterfaceService service = get(RouterInterfaceService.class);
39 if (subnetId != null) {
40 RouterInterface routerInterface = service
41 .getRouterInterface(SubnetId.subnetId(subnetId));
42 printRouterInterface(routerInterface);
43 } else {
44 Iterable<RouterInterface> routerInterfaces = service
45 .getRouterInterfaces();
46 for (RouterInterface routerInterface : routerInterfaces) {
47 printRouterInterface(routerInterface);
48 }
49 }
50 }
51
52 private void printRouterInterface(RouterInterface routerInterface) {
53 print(FMT, routerInterface.subnetId(), routerInterface.tenantId(),
54 routerInterface.portId(), routerInterface.routerId());
55 }
56}