blob: 79bedf3606ced73e46acc417e0794e497e1494d5 [file] [log] [blame]
Andreas Papazois92e4a042016-02-24 15:29:30 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andreas Papazois92e4a042016-02-24 15:29:30 +02003 *
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.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.apache.karaf.shell.commands.Option;
Andreas Papazois92e4a042016-02-24 15:29:30 +020021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.behaviour.InterfaceConfig;
24import org.onosproject.net.driver.DriverHandler;
25import org.onosproject.net.driver.DriverService;
26
27/**
28 * Removes configured interface from a device.
29 */
30@Command(scope = "onos", name = "device-remove-interface",
31 description = "Removes an interface configuration from a device")
32public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
33
Andreas Papazois827d8d02016-04-15 11:53:16 +030034 private static final String REMOVE_ACCESS_SUCCESS =
35 "Access mode deleted from device %s interface %s.";
36 private static final String REMOVE_ACCESS_FAILURE =
37 "Failed to delete access mode from device %s interface %s.";
Andreas Papazois92e4a042016-02-24 15:29:30 +020038
39 private static final String REMOVE_TRUNK_SUCCESS =
Andreas Papazois827d8d02016-04-15 11:53:16 +030040 "Trunk mode deleted from device %s interface %s.";
Andreas Papazois92e4a042016-02-24 15:29:30 +020041 private static final String REMOVE_TRUNK_FAILURE =
Andreas Papazois827d8d02016-04-15 11:53:16 +030042 "Failed to delete trunk mode from device %s interface %s.";
Andreas Papazois92e4a042016-02-24 15:29:30 +020043
44 @Argument(index = 0, name = "uri", description = "Device ID",
45 required = true, multiValued = false)
46 private String uri = null;
47
48 @Argument(index = 1, name = "interface",
49 description = "Interface name",
50 required = true, multiValued = false)
51 private String portName = null;
52
Andreas Papazois92e4a042016-02-24 15:29:30 +020053 @Option(name = "-t", aliases = "--trunk",
Andreas Papazois59e19bb2016-04-12 13:59:58 +030054 description = "Remove trunk mode for VLAN(s)",
Andreas Papazois92e4a042016-02-24 15:29:30 +020055 required = false, multiValued = false)
56 private boolean trunkMode = false;
57
58 @Override
59 protected void execute() {
60 DriverService service = get(DriverService.class);
61 DeviceId deviceId = DeviceId.deviceId(uri);
62 DriverHandler h = service.createHandler(deviceId);
63 InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
64
Andreas Papazois92e4a042016-02-24 15:29:30 +020065 if (trunkMode) {
66 // Trunk mode for VLAN to be removed.
Andreas Papazois827d8d02016-04-15 11:53:16 +030067 if (interfaceConfig.removeTrunkInterface(deviceId, portName)) {
68 print(REMOVE_TRUNK_SUCCESS, deviceId, portName);
Andreas Papazois92e4a042016-02-24 15:29:30 +020069 } else {
Andreas Papazois827d8d02016-04-15 11:53:16 +030070 print(REMOVE_TRUNK_FAILURE, deviceId, portName);
Andreas Papazois92e4a042016-02-24 15:29:30 +020071 }
72 return;
73 }
74
Andreas Papazois59e19bb2016-04-12 13:59:58 +030075 // Access mode for VLAN to be removed.
Andreas Papazois827d8d02016-04-15 11:53:16 +030076 if (interfaceConfig.removeAccessInterface(deviceId, portName)) {
77 print(REMOVE_ACCESS_SUCCESS, deviceId, portName);
Andreas Papazois92e4a042016-02-24 15:29:30 +020078 } else {
Andreas Papazois827d8d02016-04-15 11:53:16 +030079 print(REMOVE_ACCESS_FAILURE, deviceId, portName);
Andreas Papazois92e4a042016-02-24 15:29:30 +020080 }
81 }
82
83}