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 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 22 | import org.onosproject.openstackvtap.api.OpenstackVtap; |
| 23 | import org.onosproject.openstackvtap.api.OpenstackVtapService; |
| 24 | |
| 25 | import java.util.Set; |
| 26 | |
Jian Li | 26ef130 | 2018-07-04 14:37:06 +0900 | [diff] [blame] | 27 | import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString; |
| 28 | |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 29 | /** |
| 30 | * Command line interface for listing openstack vTap rules. |
| 31 | */ |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 32 | @Service |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 33 | @Command(scope = "onos", name = "openstack-vtap-list", |
| 34 | description = "OpenstackVtap list") |
| 35 | public 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 Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 49 | protected void doExecute() { |
Jian Li | 26ef130 | 2018-07-04 14:37:06 +0900 | [diff] [blame] | 50 | OpenstackVtap.Type type = getVtapTypeFromString(vTapType); |
Jian Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 51 | 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 Li | c253810 | 2018-07-03 22:42:07 +0900 | [diff] [blame] | 62 | } |