blob: 1a04f845cc0b76c28b01a2eeeb43dc92e6adf6ec [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;
17
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.onlab.packet.VlanId;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.Device;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.PortNumber;
26import org.onosproject.net.device.DeviceService;
27import org.onosproject.openstackvtap.api.OpenstackVtap;
28import org.onosproject.openstackvtap.api.OpenstackVtapAdminService;
29
30import static org.onlab.packet.VlanId.UNTAGGED;
Jian Li26ef1302018-07-04 14:37:06 +090031import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString;
Jian Lic2538102018-07-03 22:42:07 +090032
33/**
34 * Command line interface for set openstack vTap output.
35 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070036@Service
Jian Lic2538102018-07-03 22:42:07 +090037@Command(scope = "onos", name = "openstack-vtap-output",
38 description = "OpenstackVtap output setup")
39public class OpenstackVtapOutputCommand extends AbstractShellCommand {
40
41 private final DeviceService deviceService = get(DeviceService.class);
Jian Li26ef1302018-07-04 14:37:06 +090042 private final OpenstackVtapAdminService vTapAdminService =
43 get(OpenstackVtapAdminService.class);
Jian Lic2538102018-07-03 22:42:07 +090044
45 @Argument(index = 0, name = "deviceId", description = "device id",
46 required = true, multiValued = false)
47 String id = "";
48
49 @Argument(index = 1, name = "port", description = "output port number",
50 required = true, multiValued = false)
51 int port = 0;
52
53 @Argument(index = 2, name = "vlan", description = "vlan id",
54 required = false, multiValued = false)
55 int vlan = UNTAGGED;
56
57 @Argument(index = 3, name = "type", description = "vTap type [all|tx|rx]",
58 required = false, multiValued = false)
Jian Li26ef1302018-07-04 14:37:06 +090059 String vTapTypeStr = "all";
Jian Lic2538102018-07-03 22:42:07 +090060
61 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070062 protected void doExecute() {
Jian Lic2538102018-07-03 22:42:07 +090063 try {
64 Device device = deviceService.getDevice(DeviceId.deviceId(id));
65 if (device != null) {
Jian Li26ef1302018-07-04 14:37:06 +090066 OpenstackVtap.Type type = getVtapTypeFromString(vTapTypeStr);
Jian Lic2538102018-07-03 22:42:07 +090067
68 vTapAdminService.setVtapOutput(device.id(), type,
69 PortNumber.portNumber(port), VlanId.vlanId((short) vlan));
70 print("Set OpenstackVtap output deviceId { %s }, port=%s, vlan=%s",
71 device.id().toString(),
72 PortNumber.portNumber(port).toString(),
73 VlanId.vlanId((short) vlan).toString());
74 } else {
75 print("Invalid device id");
76 }
77 } catch (Exception e) {
78 print("Invalid parameter: %s", e.toString());
79 }
80 }
Jian Lic2538102018-07-03 22:42:07 +090081}