blob: 5ffc265931258bcec8149aed31d145fd7b588b30 [file] [log] [blame]
Jian Lic2538102018-07-03 22:42:07 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
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.openstackvtap.cli;
Jian Li26ef1302018-07-04 14:37:06 +090017
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Jian Lic2538102018-07-03 22:42:07 +090021import org.onosproject.cli.AbstractShellCommand;
Jian Lic2538102018-07-03 22:42:07 +090022import org.onosproject.openstackvtap.api.OpenstackVtap;
23import org.onosproject.openstackvtap.api.OpenstackVtapService;
24
25import java.util.Set;
26
Jian Li26ef1302018-07-04 14:37:06 +090027import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString;
28
Jian Lic2538102018-07-03 22:42:07 +090029/**
30 * Command line interface for listing openstack vTap rules.
31 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070032@Service
Jian Lic2538102018-07-03 22:42:07 +090033@Command(scope = "onos", name = "openstack-vtap-list",
34 description = "OpenstackVtap list")
35public class OpenstackVtapListCommand extends AbstractShellCommand {
36
37 private final OpenstackVtapService vTapService = get(OpenstackVtapService.class);
38
39 @Argument(index = 0, name = "type",
40 description = "vTap type [all|tx|rx]",
41 required = false, multiValued = false)
42 String vTapType = "none";
43
44 private static final String FORMAT = "ID { %s }: type [%s], srcIP [%s], dstIP [%s]";
45 private static final String FORMAT_TX_DEVICES = " tx devices: %s";
46 private static final String FORMAT_RX_DEVICES = " rx devices: %s";
47
48 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070049 protected void doExecute() {
Jian Li26ef1302018-07-04 14:37:06 +090050 OpenstackVtap.Type type = getVtapTypeFromString(vTapType);
Jian Lic2538102018-07-03 22:42:07 +090051 Set<OpenstackVtap> openstackVtaps = vTapService.getVtaps(type);
52 for (OpenstackVtap vTap : openstackVtaps) {
53 print(FORMAT,
54 vTap.id().toString(),
55 vTap.type().toString(),
56 vTap.vTapCriterion().srcIpPrefix().toString(),
57 vTap.vTapCriterion().dstIpPrefix().toString());
58 print(FORMAT_TX_DEVICES, vTap.txDeviceIds());
59 print(FORMAT_RX_DEVICES, vTap.rxDeviceIds());
60 }
61 }
Jian Lic2538102018-07-03 22:42:07 +090062}