blob: 257cb9a679d263397691bfe8ffdd949babb8bf42 [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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.packet.VlanId;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.Device;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.PortNumber;
25import org.onosproject.net.device.DeviceService;
26import org.onosproject.openstackvtap.api.OpenstackVtap;
27import org.onosproject.openstackvtap.api.OpenstackVtapAdminService;
28
29import static org.onlab.packet.VlanId.UNTAGGED;
Jian Li26ef1302018-07-04 14:37:06 +090030import static org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString;
Jian Lic2538102018-07-03 22:42:07 +090031
32/**
33 * Command line interface for set openstack vTap output.
34 */
35@Command(scope = "onos", name = "openstack-vtap-output",
36 description = "OpenstackVtap output setup")
37public class OpenstackVtapOutputCommand extends AbstractShellCommand {
38
39 private final DeviceService deviceService = get(DeviceService.class);
Jian Li26ef1302018-07-04 14:37:06 +090040 private final OpenstackVtapAdminService vTapAdminService =
41 get(OpenstackVtapAdminService.class);
Jian Lic2538102018-07-03 22:42:07 +090042
43 @Argument(index = 0, name = "deviceId", description = "device id",
44 required = true, multiValued = false)
45 String id = "";
46
47 @Argument(index = 1, name = "port", description = "output port number",
48 required = true, multiValued = false)
49 int port = 0;
50
51 @Argument(index = 2, name = "vlan", description = "vlan id",
52 required = false, multiValued = false)
53 int vlan = UNTAGGED;
54
55 @Argument(index = 3, name = "type", description = "vTap type [all|tx|rx]",
56 required = false, multiValued = false)
Jian Li26ef1302018-07-04 14:37:06 +090057 String vTapTypeStr = "all";
Jian Lic2538102018-07-03 22:42:07 +090058
59 @Override
60 protected void execute() {
61 try {
62 Device device = deviceService.getDevice(DeviceId.deviceId(id));
63 if (device != null) {
Jian Li26ef1302018-07-04 14:37:06 +090064 OpenstackVtap.Type type = getVtapTypeFromString(vTapTypeStr);
Jian Lic2538102018-07-03 22:42:07 +090065
66 vTapAdminService.setVtapOutput(device.id(), type,
67 PortNumber.portNumber(port), VlanId.vlanId((short) vlan));
68 print("Set OpenstackVtap output deviceId { %s }, port=%s, vlan=%s",
69 device.id().toString(),
70 PortNumber.portNumber(port).toString(),
71 VlanId.vlanId((short) vlan).toString());
72 } else {
73 print("Invalid device id");
74 }
75 } catch (Exception e) {
76 print("Invalid parameter: %s", e.toString());
77 }
78 }
Jian Lic2538102018-07-03 22:42:07 +090079}