blob: afb9bbf955f80febe4fb0caef2f1afa567196a63 [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
18import org.apache.karaf.shell.commands.Argument;
Jian Lic2538102018-07-03 22:42:07 +090019import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
Jian Lic2538102018-07-03 22:42:07 +090021import org.onosproject.openstackvtap.api.OpenstackVtap;
22import org.onosproject.openstackvtap.api.OpenstackVtapService;
23
24import java.util.Set;
25
Jian Li26ef1302018-07-04 14:37:06 +090026import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString;
27
Jian Lic2538102018-07-03 22:42:07 +090028/**
29 * Command line interface for listing openstack vTap rules.
30 */
31@Command(scope = "onos", name = "openstack-vtap-list",
32 description = "OpenstackVtap list")
33public class OpenstackVtapListCommand extends AbstractShellCommand {
34
35 private final OpenstackVtapService vTapService = get(OpenstackVtapService.class);
36
37 @Argument(index = 0, name = "type",
38 description = "vTap type [all|tx|rx]",
39 required = false, multiValued = false)
40 String vTapType = "none";
41
42 private static final String FORMAT = "ID { %s }: type [%s], srcIP [%s], dstIP [%s]";
43 private static final String FORMAT_TX_DEVICES = " tx devices: %s";
44 private static final String FORMAT_RX_DEVICES = " rx devices: %s";
45
46 @Override
47 protected void execute() {
Jian Li26ef1302018-07-04 14:37:06 +090048 OpenstackVtap.Type type = getVtapTypeFromString(vTapType);
Jian Lic2538102018-07-03 22:42:07 +090049 Set<OpenstackVtap> openstackVtaps = vTapService.getVtaps(type);
50 for (OpenstackVtap vTap : openstackVtaps) {
51 print(FORMAT,
52 vTap.id().toString(),
53 vTap.type().toString(),
54 vTap.vTapCriterion().srcIpPrefix().toString(),
55 vTap.vTapCriterion().dstIpPrefix().toString());
56 print(FORMAT_TX_DEVICES, vTap.txDeviceIds());
57 print(FORMAT_RX_DEVICES, vTap.rxDeviceIds());
58 }
59 }
Jian Lic2538102018-07-03 22:42:07 +090060}