Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.openstackvtap.cli; |
Jian Li | 26ef130 | 2018-07-04 14:37:06 +0900 | [diff] [blame] | 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 21 | import org.onosproject.openstackvtap.api.OpenstackVtap; |
| 22 | import org.onosproject.openstackvtap.api.OpenstackVtapService; |
| 23 | |
| 24 | import java.util.Set; |
| 25 | |
Jian Li | 26ef130 | 2018-07-04 14:37:06 +0900 | [diff] [blame] | 26 | import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString; |
| 27 | |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 28 | /** |
| 29 | * Command line interface for listing openstack vTap rules. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "openstack-vtap-list", |
| 32 | description = "OpenstackVtap list") |
| 33 | public 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 Li | 26ef130 | 2018-07-04 14:37:06 +0900 | [diff] [blame] | 48 | OpenstackVtap.Type type = getVtapTypeFromString(vTapType); |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 49 | 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 Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 60 | } |