Andreas Papazois
Committed by Gerrit Code Review

[GEANT] VLAN arg not needed when removing interface.

Change-Id: I9015f7df65b924901dab7c32a7dd757f7fa55234
......@@ -94,7 +94,7 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand {
return;
}
VlanId accessVlanId = vlanIds.get(0);
if (interfaceConfig.addInterfaceToVlan(deviceId, portName, accessVlanId)) {
if (interfaceConfig.addAccessInterface(deviceId, portName, accessVlanId)) {
print(CONFIG_VLAN_SUCCESS, accessVlanId, deviceId, portName);
} else {
print(CONFIG_VLAN_FAILURE, accessVlanId, deviceId, portName);
......
......@@ -18,16 +18,12 @@ package org.onosproject.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onlab.packet.VlanId;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.InterfaceConfig;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import java.util.ArrayList;
import java.util.List;
/**
* Removes configured interface from a device.
*/
......@@ -35,17 +31,15 @@ import java.util.List;
description = "Removes an interface configuration from a device")
public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
private static final String REMOVE_VLAN_SUCCESS =
"VLAN %s removed from device %s interface %s.";
private static final String REMOVE_VLAN_FAILURE =
"Failed to remove VLAN %s from device %s interface %s.";
private static final String ONE_VLAN_ALLOWED =
"Only one VLAN allowed for access mode on device %s interface %s.";
private static final String REMOVE_ACCESS_SUCCESS =
"Access mode deleted from device %s interface %s.";
private static final String REMOVE_ACCESS_FAILURE =
"Failed to delete access mode from device %s interface %s.";
private static final String REMOVE_TRUNK_SUCCESS =
"Trunk mode removed for VLAN %s on device %s interface %s.";
"Trunk mode deleted from device %s interface %s.";
private static final String REMOVE_TRUNK_FAILURE =
"Failed to remove trunk mode for VLAN %s on device %s interface %s.";
"Failed to delete trunk mode from device %s interface %s.";
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
......@@ -56,11 +50,6 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
required = true, multiValued = false)
private String portName = null;
@Argument(index = 2, name = "vlan",
description = "VLAN ID",
required = true, multiValued = true)
private String[] vlanStrings = null;
@Option(name = "-t", aliases = "--trunk",
description = "Remove trunk mode for VLAN(s)",
required = false, multiValued = false)
......@@ -73,31 +62,21 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
DriverHandler h = service.createHandler(deviceId);
InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
List<VlanId> vlanIds = new ArrayList<>();
for (String vlanString : vlanStrings) {
vlanIds.add(VlanId.vlanId(Short.parseShort(vlanString)));
}
if (trunkMode) {
// Trunk mode for VLAN to be removed.
if (interfaceConfig.removeTrunkInterface(deviceId, portName, vlanIds)) {
print(REMOVE_TRUNK_SUCCESS, vlanIds, deviceId, portName);
if (interfaceConfig.removeTrunkInterface(deviceId, portName)) {
print(REMOVE_TRUNK_SUCCESS, deviceId, portName);
} else {
print(REMOVE_TRUNK_FAILURE, vlanIds, deviceId, portName);
print(REMOVE_TRUNK_FAILURE, deviceId, portName);
}
return;
}
// Access mode for VLAN to be removed.
if (vlanIds.size() != 1) {
print(ONE_VLAN_ALLOWED, deviceId, portName);
return;
}
VlanId accessVlanId = vlanIds.get(0);
if (interfaceConfig.removeInterfaceFromVlan(deviceId, portName, accessVlanId)) {
print(REMOVE_VLAN_SUCCESS, accessVlanId, deviceId, portName);
if (interfaceConfig.removeAccessInterface(deviceId, portName)) {
print(REMOVE_ACCESS_SUCCESS, deviceId, portName);
} else {
print(REMOVE_VLAN_FAILURE, accessVlanId, deviceId, portName);
print(REMOVE_ACCESS_FAILURE, deviceId, portName);
}
}
......
......@@ -27,25 +27,24 @@ import java.util.List;
public interface InterfaceConfig extends HandlerBehaviour {
/**
* Adds an interface to a VLAN.
* Adds an access interface to a VLAN.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
boolean addInterfaceToVlan(DeviceId deviceId, String intf, VlanId vlanId);
boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId);
/**
* Removes an interface from a VLAN.
* Removes an access interface to a VLAN.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
boolean removeInterfaceFromVlan(DeviceId deviceId, String intf, VlanId vlanId);
boolean removeAccessInterface(DeviceId deviceId, String intf);
/**
* Configures an interface as trunk for VLANs.
* Adds a trunk interface for VLANs.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
......@@ -54,13 +53,12 @@ public interface InterfaceConfig extends HandlerBehaviour {
boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds);
/**
* Removes trunk mode configuration for VLANs from an interface.
* Removes trunk mode configuration from an interface.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the result of operation
*/
boolean removeTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds);
boolean removeTrunkInterface(DeviceId deviceId, String intf);
/**
* TODO Addition of more methods to make the behavior symmetrical.
......
......@@ -44,14 +44,14 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
private final Logger log = getLogger(getClass());
/**
* Adds an interface to a VLAN.
* Adds an access interface to a VLAN.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
@Override
public boolean addInterfaceToVlan(DeviceId deviceId, String intf, VlanId vlanId) {
public boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -59,7 +59,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addInterfaceToVlanBuilder(intf, vlanId));
reply = session.requestSync(addAccessInterfaceBuilder(intf, vlanId));
} catch (NetconfException e) {
log.error("Failed to configure VLAN ID {} on device {} interface {}.",
vlanId, deviceId, intf, e);
......@@ -71,12 +71,12 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
}
/**
* Builds a request to add an interface to a VLAN.
* Builds a request to add an access interface to a VLAN.
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the request string.
*/
private String addInterfaceToVlanBuilder(String intf, VlanId vlanId) {
private String addAccessInterfaceBuilder(String intf, VlanId vlanId) {
StringBuilder rpc =
new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
......@@ -106,15 +106,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
}
/**
* Removes an interface from a VLAN.
* Removes an access interface to a VLAN.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
@Override
public boolean removeInterfaceFromVlan(DeviceId deviceId, String intf,
VlanId vlanId) {
public boolean removeAccessInterface(DeviceId deviceId, String intf) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -122,10 +120,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeInterfaceFromVlanBuilder(intf, vlanId));
reply = session.requestSync(removeAccessInterfaceBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove VLAN ID {} from device {} interface {}.",
vlanId, deviceId, intf, e);
log.error("Failed to remove access mode from device {} interface {}.",
deviceId, intf, e);
return false;
}
......@@ -134,12 +132,11 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
}
/**
* Builds a request to remove an interface from a VLAN.
* Builds a request to remove an access interface from a VLAN.
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the request string.
*/
private String removeInterfaceFromVlanBuilder(String intf, VlanId vlanId) {
private String removeAccessInterfaceBuilder(String intf) {
StringBuilder rpc =
new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
......@@ -154,7 +151,6 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
rpc.append("</Param>");
rpc.append("<ConfigIf-Configuration>");
rpc.append("<switchport operation=\"delete\"><access><vlan><VLANIDVLANPortAccessMode>");
rpc.append(vlanId);
rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>");
rpc.append("<switchport operation=\"delete\"><mode><access/></mode></switchport>");
rpc.append("</ConfigIf-Configuration>");
......@@ -169,7 +165,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
}
/**
* Configures an interface as trunk for VLANs.
* Adds a trunk interface for VLANs.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
......@@ -233,14 +229,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
}
/**
* Removes trunk mode configuration for VLANs from an interface.
* Removes trunk mode configuration from an interface.
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the result of operation
*/
@Override
public boolean removeTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds) {
public boolean removeTrunkInterface(DeviceId deviceId, String intf) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -248,10 +243,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeTrunkInterfaceBuilder(intf, vlanIds));
reply = session.requestSync(removeTrunkInterfaceBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove trunk mode for VLAN ID {} on device {} interface {}.",
vlanIds, deviceId, intf, e);
log.error("Failed to remove trunk mode on device {} interface {}.",
deviceId, intf, e);
return false;
}
......@@ -260,12 +255,11 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
}
/**
* Builds a request to remove trunk mode configuration for VLANs from an interface.
* Builds a request to remove trunk mode configuration from an interface.
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the request string.
*/
private String removeTrunkInterfaceBuilder(String intf, List<VlanId> vlanIds) {
private String removeTrunkInterfaceBuilder(String intf) {
StringBuilder rpc =
new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
......@@ -284,7 +278,6 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
rpc.append("<dot1q/></encapsulation></trunk></switchport>");
rpc.append("<switchport><trunk operation=\"delete\"><allowed><vlan>");
rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
rpc.append(getVlansString(vlanIds));
rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>");
rpc.append("</trunk></switchport></ConfigIf-Configuration>");
rpc.append("</interface>");
......