Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 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.cli.net; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.apache.karaf.shell.commands.Option; |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.behaviour.InterfaceConfig; |
| 24 | import org.onosproject.net.driver.DriverHandler; |
| 25 | import 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") |
| 32 | public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { |
| 33 | |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 34 | 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 Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 38 | |
| 39 | private static final String REMOVE_TRUNK_SUCCESS = |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 40 | "Trunk mode deleted from device %s interface %s."; |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 41 | private static final String REMOVE_TRUNK_FAILURE = |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 42 | "Failed to delete trunk mode from device %s interface %s."; |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 43 | |
| 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 Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 53 | @Option(name = "-t", aliases = "--trunk", |
Andreas Papazois | 59e19bb | 2016-04-12 13:59:58 +0300 | [diff] [blame] | 54 | description = "Remove trunk mode for VLAN(s)", |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 55 | 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 Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 65 | if (trunkMode) { |
| 66 | // Trunk mode for VLAN to be removed. |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 67 | if (interfaceConfig.removeTrunkInterface(deviceId, portName)) { |
| 68 | print(REMOVE_TRUNK_SUCCESS, deviceId, portName); |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 69 | } else { |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 70 | print(REMOVE_TRUNK_FAILURE, deviceId, portName); |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 71 | } |
| 72 | return; |
| 73 | } |
| 74 | |
Andreas Papazois | 59e19bb | 2016-04-12 13:59:58 +0300 | [diff] [blame] | 75 | // Access mode for VLAN to be removed. |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 76 | if (interfaceConfig.removeAccessInterface(deviceId, portName)) { |
| 77 | print(REMOVE_ACCESS_SUCCESS, deviceId, portName); |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 78 | } else { |
Andreas Papazois | 827d8d0 | 2016-04-15 11:53:16 +0300 | [diff] [blame^] | 79 | print(REMOVE_ACCESS_FAILURE, deviceId, portName); |
Andreas Papazois | 92e4a04 | 2016-02-24 15:29:30 +0200 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | } |