Andreas Papazois
Committed by Gerrit Code Review

[GEANT] Rate limit on port via NetConf and refactoring.

Change-Id: Id5b5a196bed3b28159160b94bc5ae838d00cb765
......@@ -35,17 +35,20 @@ import java.util.List;
description = "Configures a device interface")
public class DeviceInterfaceAddCommand extends AbstractShellCommand {
private static final String ONE_ACTION_ALLOWED =
"One configuration action allowed at a time";
private static final String CONFIG_VLAN_SUCCESS =
"VLAN %s added on device %s interface %s.";
private static final String CONFIG_VLAN_FAILURE =
"Failed to add VLAN %s on 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 CONFIG_TRUNK_SUCCESS =
"Trunk mode added for VLAN %s on device %s interface %s.";
private static final String CONFIG_TRUNK_FAILURE =
"Failed to add trunk mode for VLAN %s on device %s interface %s.";
private static final String CONFIG_RATE_SUCCESS =
"Rate limit %d%% added on device %s interface %s.";
private static final String CONFIG_RATE_FAILURE =
"Failed to add rate limit %d%% on device %s interface %s.";
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
......@@ -56,15 +59,20 @@ public class DeviceInterfaceAddCommand 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 = "-r", aliases = "--rate-limit",
description = "Percentage for egress bandwidth limit",
required = false, multiValued = false)
private String limitString = null;
@Option(name = "-t", aliases = "--trunk",
description = "Configure interface as trunk for VLAN(s)",
description = "VLAN(s) for trunk port (multiple values are allowed)",
required = false, multiValued = true)
private String[] trunkVlanStrings = null;
@Option(name = "-a", aliases = "--access",
description = "VLAN for access port",
required = false, multiValued = false)
private boolean trunkMode = false;
private String accessVlanString = null;
@Override
protected void execute() {
......@@ -73,31 +81,51 @@ public class DeviceInterfaceAddCommand 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 (accessVlanString != null && trunkVlanStrings == null &&
limitString == null) {
// Access mode to be enabled for VLAN.
addAccessModeToIntf(interfaceConfig);
} else if (trunkVlanStrings != null && accessVlanString == null &&
limitString == null) {
// Trunk mode to be enabled for VLANs.
addTrunkModeToIntf(interfaceConfig);
} else if (limitString != null && accessVlanString == null &&
trunkVlanStrings == null) {
// Rate limit to be set on interface.
addRateLimitToIntf(interfaceConfig);
} else {
// Option has not been correctly set.
print(ONE_ACTION_ALLOWED);
}
}
if (trunkMode) {
// Trunk mode to be enabled for VLAN.
if (interfaceConfig.addTrunkInterface(deviceId, portName, vlanIds)) {
print(CONFIG_TRUNK_SUCCESS, vlanIds, deviceId, portName);
} else {
print(CONFIG_TRUNK_FAILURE, vlanIds, deviceId, portName);
}
return;
private void addRateLimitToIntf(InterfaceConfig config) {
short rate = Short.parseShort(limitString);
if (config.addRateLimit(portName, rate)) {
print(CONFIG_RATE_SUCCESS, rate, uri, portName);
} else {
print(CONFIG_RATE_FAILURE, rate, uri, portName);
}
}
// Access mode to be enabled for VLAN.
if (vlanIds.size() != 1) {
print(ONE_VLAN_ALLOWED, deviceId, portName);
return;
private void addTrunkModeToIntf(InterfaceConfig config) {
List<VlanId> vlanIds = new ArrayList<>();
for (String vlanString : trunkVlanStrings) {
vlanIds.add(VlanId.vlanId(Short.parseShort(vlanString)));
}
VlanId accessVlanId = vlanIds.get(0);
if (interfaceConfig.addAccessInterface(deviceId, portName, accessVlanId)) {
print(CONFIG_VLAN_SUCCESS, accessVlanId, deviceId, portName);
if (config.addTrunkMode(portName, vlanIds)) {
print(CONFIG_TRUNK_SUCCESS, vlanIds, uri, portName);
} else {
print(CONFIG_TRUNK_FAILURE, vlanIds, uri, portName);
}
}
private void addAccessModeToIntf(InterfaceConfig config) {
VlanId accessVlanId = VlanId.vlanId(Short.parseShort(accessVlanString));
if (config.addAccessMode(portName, accessVlanId)) {
print(CONFIG_VLAN_SUCCESS, accessVlanId, uri, portName);
} else {
print(CONFIG_VLAN_FAILURE, accessVlanId, deviceId, portName);
print(CONFIG_VLAN_FAILURE, accessVlanId, uri, portName);
}
}
......
......@@ -25,36 +25,51 @@ import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
/**
* Removes configured interface from a device.
* Removes an interface configurion from a device.
*/
@Command(scope = "onos", name = "device-remove-interface",
description = "Removes an interface configuration from a device")
public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
private static final String ONE_ACTION_ALLOWED =
"One configuration removal allowed at a time";
private static final String REMOVE_ACCESS_SUCCESS =
"Access mode deleted from device %s interface %s.";
"Access mode removed from device %s interface %s.";
private static final String REMOVE_ACCESS_FAILURE =
"Failed to delete access mode from device %s interface %s.";
"Failed to remove access mode from device %s interface %s.";
private static final String REMOVE_TRUNK_SUCCESS =
"Trunk mode deleted from device %s interface %s.";
"Trunk mode removed from device %s interface %s.";
private static final String REMOVE_TRUNK_FAILURE =
"Failed to delete trunk mode from device %s interface %s.";
"Failed to remove trunk mode from device %s interface %s.";
private static final String REMOVE_RATE_SUCCESS =
"Rate limit removed from device %s interface %s.";
private static final String REMOVE_RATE_FAILURE =
"Failed to remove rate limit from device %s interface %s.";
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
private String uri = null;
@Argument(index = 1, name = "interface",
description = "Interface name",
required = true, multiValued = false)
description = "Interface name",
required = true, multiValued = false)
private String portName = null;
@Option(name = "-r", aliases = "--rate-limit",
description = "Percentage for egress bandwidth limit",
required = false, multiValued = false)
private boolean rateLimit = false;
@Option(name = "-t", aliases = "--trunk",
description = "Remove trunk mode for VLAN(s)",
required = false, multiValued = false)
private boolean trunkMode = false;
@Option(name = "-a", aliases = "--access",
description = "Remove access mode for VLAN",
required = false, multiValued = false)
private boolean accessMode = false;
@Override
protected void execute() {
DriverService service = get(DriverService.class);
......@@ -62,21 +77,42 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
DriverHandler h = service.createHandler(deviceId);
InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
if (trunkMode) {
if (trunkMode && !accessMode && !rateLimit) {
// Trunk mode for VLAN to be removed.
if (interfaceConfig.removeTrunkInterface(deviceId, portName)) {
print(REMOVE_TRUNK_SUCCESS, deviceId, portName);
} else {
print(REMOVE_TRUNK_FAILURE, deviceId, portName);
}
return;
removeTrunkModeFromIntf(interfaceConfig);
} else if (accessMode && !trunkMode && !rateLimit) {
// Access mode for VLAN to be removed.
removeAccessModeFromIntf(interfaceConfig);
} else if (rateLimit && !trunkMode && !accessMode) {
// Rate limit to be removed.
removeRateLimitFromIntf(interfaceConfig);
} else {
// Option has not been correctly set.
print(ONE_ACTION_ALLOWED);
}
}
private void removeAccessModeFromIntf(InterfaceConfig interfaceConfig) {
if (interfaceConfig.removeAccessMode(portName)) {
print(REMOVE_ACCESS_SUCCESS, uri, portName);
} else {
print(REMOVE_ACCESS_FAILURE, uri, portName);
}
}
private void removeTrunkModeFromIntf(InterfaceConfig interfaceConfig) {
if (interfaceConfig.removeTrunkMode(portName)) {
print(REMOVE_TRUNK_SUCCESS, uri, portName);
} else {
print(REMOVE_TRUNK_FAILURE, uri, portName);
}
}
// Access mode for VLAN to be removed.
if (interfaceConfig.removeAccessInterface(deviceId, portName)) {
print(REMOVE_ACCESS_SUCCESS, deviceId, portName);
private void removeRateLimitFromIntf(InterfaceConfig config) {
if (config.removeRateLimit(portName)) {
print(REMOVE_RATE_SUCCESS, uri, portName);
} else {
print(REMOVE_ACCESS_FAILURE, deviceId, portName);
print(REMOVE_RATE_FAILURE, uri, portName);
}
}
......
......@@ -78,7 +78,7 @@ public class DeviceInterfacesListCommand extends DevicesListCommand {
InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
List<DeviceInterfaceDescription> interfaces =
interfaceConfig.getInterfaces(device.id());
interfaceConfig.getInterfaces();
if (interfaces == null) {
print(ERROR_RESULT);
} else if (interfaces.isEmpty()) {
......
......@@ -34,8 +34,19 @@ public interface InterfaceConfig extends HandlerBehaviour {
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
* @deprecated in 1.7.0 Hummingbird release - use of addAccessMode() instead
*/
boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId);
@Deprecated
public boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId);
/**
* Adds an access interface to a VLAN.
*
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
boolean addAccessMode(String intf, VlanId vlanId);
/**
* Removes an access interface to a VLAN.
......@@ -43,40 +54,99 @@ public interface InterfaceConfig extends HandlerBehaviour {
* @param deviceId the device ID
* @param intf the name of the interface
* @return the result of operation
* @deprecated in 1.7.0 Hummingbird release - use of removeAccessMode() instead
*/
@Deprecated
boolean removeAccessInterface(DeviceId deviceId, String intf);
/**
* Removes an access interface to a VLAN.
*
* @param intf the name of the interface
* @return the result of operation
*/
boolean removeAccessMode(String intf);
/**
* Adds a trunk interface for VLANs.
*
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the result of operation
* @deprecated in 1.7.0 Hummingbird release - use of addTrunkMode() instead
*/
@Deprecated
boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds);
/**
* Removes trunk mode configuration from an interface.
* Adds a trunk interface for VLANs.
*
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the result of operation
*/
boolean addTrunkMode(String intf, List<VlanId> vlanIds);
/**
* Removes trunk mode configuration from an interface.
*
* @param deviceId the device ID
* @param intf the name of the interface
* @return the result of operation
* @deprecated in 1.7.0 Hummingbird release - use of removeTrunkMode() instead
*/
@Deprecated
boolean removeTrunkInterface(DeviceId deviceId, String intf);
/**
* Removes trunk mode configuration from an interface.
*
* @param intf the name of the interface
* @return the result of operation
*/
boolean removeTrunkMode(String intf);
/**
* Adds a rate limit on an interface.
*
* @param intf the name of the interface
* @param limit the limit as a percentage
* @return the result of operation
*/
boolean addRateLimit(String intf, short limit);
/**
* Removes rate limit from an interface.
*
* @param intf the name of the interface
* @return the result of operation
*/
boolean removeRateLimit(String intf);
/**
* Provides the interfaces configured on a device.
*
* @param deviceId the device ID
* @return the list of the configured interfaces
* @deprecated in 1.7.0 Hummingbird release - use of getInterfaces() without
* deviceId as parameter instead
*/
@Deprecated
public List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId);
/**
* Provides the interfaces configured on a device.
*
* @return the list of the configured interfaces
*/
List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId);
List<DeviceInterfaceDescription> getInterfaces();
/**
* TODO Addition of more methods to make the behavior symmetrical.
* Methods getInterfacesForVlan, getVlansForInterface, getTrunkforInterface,
* getInterfacesForTrunk should be added to complete the behavior.
* Methods getInterfacesForVlan(VlanId), hasAccessMode(), hasTrunkMode(),
* getTrunkVlans(Interface), getAccessVlan(Interface) should be added to
* complete the behavior.
*/
}
......
......@@ -54,6 +54,18 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
*/
@Override
public boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId) {
return addAccessMode(intf, vlanId);
}
/**
* Adds an access interface to a VLAN.
*
* @param intf the name of the interface
* @param vlanId the VLAN ID
* @return the result of operation
*/
@Override
public boolean addAccessMode(String intf, VlanId vlanId) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -61,10 +73,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addAccessInterfaceBuilder(intf, vlanId));
reply = session.requestSync(addAccessModeBuilder(intf, vlanId));
} catch (NetconfException e) {
log.error("Failed to configure VLAN ID {} on device {} interface {}.",
vlanId, deviceId, intf, e);
vlanId, handler().data().deviceId(), intf, e);
return false;
}
......@@ -79,31 +91,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
* @param vlanId the VLAN ID
* @return the request string.
*/
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\">");
rpc.append("<edit-config>");
rpc.append("<target>");
rpc.append("<running/>");
rpc.append("</target>");
rpc.append("<config>");
rpc.append("<xml-config-data>");
rpc.append("<Device-Configuration><interface><Param>");
rpc.append(intf);
rpc.append("</Param>");
rpc.append("<ConfigIf-Configuration>");
private String addAccessModeBuilder(String intf, VlanId vlanId) {
StringBuilder rpc = new StringBuilder(getOpeningString(intf));
rpc.append("<switchport><access><vlan><VLANIDVLANPortAccessMode>");
rpc.append(vlanId);
rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>");
rpc.append("<switchport><mode><access/></mode></switchport>");
rpc.append("</ConfigIf-Configuration>");
rpc.append("</interface>");
rpc.append("</Device-Configuration>");
rpc.append("</xml-config-data>");
rpc.append("</config>");
rpc.append("</edit-config>");
rpc.append("</rpc>");
rpc.append(getClosingString());
return rpc.toString();
}
......@@ -117,6 +111,17 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
*/
@Override
public boolean removeAccessInterface(DeviceId deviceId, String intf) {
return removeAccessMode(intf);
}
/**
* Removes an access interface to a VLAN.
*
* @param intf the name of the interface
* @return the result of operation
*/
@Override
public boolean removeAccessMode(String intf) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -124,10 +129,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeAccessInterfaceBuilder(intf));
reply = session.requestSync(removeAccessModeBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove access mode from device {} interface {}.",
deviceId, intf, e);
handler().data().deviceId(), intf, e);
return false;
}
......@@ -141,30 +146,12 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
* @param intf the name of the interface
* @return the request string.
*/
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\">");
rpc.append("<edit-config>");
rpc.append("<target>");
rpc.append("<running/>");
rpc.append("</target>");
rpc.append("<config>");
rpc.append("<xml-config-data>");
rpc.append("<Device-Configuration><interface><Param>");
rpc.append(intf);
rpc.append("</Param>");
rpc.append("<ConfigIf-Configuration>");
private String removeAccessModeBuilder(String intf) {
StringBuilder rpc = new StringBuilder(getOpeningString(intf));
rpc.append("<switchport operation=\"delete\"><access><vlan><VLANIDVLANPortAccessMode>");
rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>");
rpc.append("<switchport operation=\"delete\"><mode><access/></mode></switchport>");
rpc.append("</ConfigIf-Configuration>");
rpc.append("</interface>");
rpc.append("</Device-Configuration>");
rpc.append("</xml-config-data>");
rpc.append("</config>");
rpc.append("</edit-config>");
rpc.append("</rpc>");
rpc.append(getClosingString());
return rpc.toString();
}
......@@ -179,6 +166,18 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
*/
@Override
public boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds) {
return addTrunkMode(intf, vlanIds);
}
/**
* Adds a trunk interface for VLANs.
*
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
* @return the result of operation
*/
@Override
public boolean addTrunkMode(String intf, List<VlanId> vlanIds) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -186,10 +185,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addTrunkInterfaceBuilder(intf, vlanIds));
reply = session.requestSync(addTrunkModeBuilder(intf, vlanIds));
} catch (NetconfException e) {
log.error("Failed to configure trunk mode for VLAN ID {} on device {} interface {}.",
vlanIds, deviceId, intf, e);
vlanIds, handler().data().deviceId(), intf, e);
return false;
}
......@@ -204,33 +203,15 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
* @param vlanIds the VLAN IDs
* @return the request string.
*/
private String addTrunkInterfaceBuilder(String intf, List<VlanId> vlanIds) {
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\">");
rpc.append("<edit-config>");
rpc.append("<target>");
rpc.append("<running/>");
rpc.append("</target>");
rpc.append("<config>");
rpc.append("<xml-config-data>");
rpc.append("<Device-Configuration><interface><Param>");
rpc.append(intf);
rpc.append("</Param>");
rpc.append("<ConfigIf-Configuration>");
private String addTrunkModeBuilder(String intf, List<VlanId> vlanIds) {
StringBuilder rpc = new StringBuilder(getOpeningString(intf));
rpc.append("<switchport><trunk><encapsulation><dot1q/></encapsulation>");
rpc.append("</trunk></switchport><switchport><trunk><allowed><vlan>");
rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
rpc.append(getVlansString(vlanIds));
rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed></trunk>");
rpc.append("</switchport><switchport><mode><trunk/></mode></switchport>");
rpc.append("</ConfigIf-Configuration>");
rpc.append("</interface>");
rpc.append("</Device-Configuration>");
rpc.append("</xml-config-data>");
rpc.append("</config>");
rpc.append("</edit-config>");
rpc.append("</rpc>");
rpc.append(getClosingString());
return rpc.toString();
}
......@@ -244,6 +225,17 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
*/
@Override
public boolean removeTrunkInterface(DeviceId deviceId, String intf) {
return removeTrunkMode(intf);
}
/**
* Removes trunk mode configuration from an interface.
*
* @param intf the name of the interface
* @return the result of operation
*/
@Override
public boolean removeTrunkMode(String intf) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
......@@ -251,10 +243,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeTrunkInterfaceBuilder(intf));
reply = session.requestSync(removeTrunkModeBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove trunk mode on device {} interface {}.",
deviceId, intf, e);
log.error("Failed to remove trunk mode from device {} interface {}.",
handler().data().deviceId(), intf, e);
return false;
}
......@@ -268,7 +260,114 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
* @param intf the name of the interface
* @return the request string.
*/
private String removeTrunkInterfaceBuilder(String intf) {
private String removeTrunkModeBuilder(String intf) {
StringBuilder rpc = new StringBuilder(getOpeningString(intf));
rpc.append("<switchport><mode operation=\"delete\"><trunk/></mode></switchport>");
rpc.append("<switchport><trunk operation=\"delete\"><encapsulation>");
rpc.append("<dot1q/></encapsulation></trunk></switchport>");
rpc.append("<switchport><trunk operation=\"delete\"><allowed><vlan>");
rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>");
rpc.append("</trunk></switchport>");
rpc.append(getClosingString());
return rpc.toString();
}
/**
* Adds a rate limit on an interface.
*
* @param intf the name of the interface
* @param limit the limit as a percentage
* @return the result of operation
*/
@Override
public boolean addRateLimit(String intf, short limit) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler()
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(addRateLimitBuilder(intf, limit));
} catch (NetconfException e) {
log.error("Failed to configure rate limit {}%% on device {} interface {}.",
limit, handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
/**
* Builds a request to configure an interface with rate limit.
*
* @param intf the name of the interface
* @param limit the limit as a percentage
* @return the request string.
*/
private String addRateLimitBuilder(String intf, short limit) {
StringBuilder rpc = new StringBuilder(getOpeningString(intf));
rpc.append("<srr-queue><bandwidth><limit>");
rpc.append("<EnterBandwidthLimitInterfaceAsPercentage>");
rpc.append(limit);
rpc.append("</EnterBandwidthLimitInterfaceAsPercentage>");
rpc.append("</limit></bandwidth></srr-queue>");
rpc.append(getClosingString());
return rpc.toString();
}
/**
* Removes rate limit from an interface.
*
* @param intf the name of the interface
* @return the result of operation
*/
@Override
public boolean removeRateLimit(String intf) {
NetconfController controller = checkNotNull(handler()
.get(NetconfController.class));
NetconfSession session = controller.getDevicesMap().get(handler()
.data().deviceId()).getSession();
String reply;
try {
reply = session.requestSync(removeRateLimitBuilder(intf));
} catch (NetconfException e) {
log.error("Failed to remove rate limit from device {} interface {}.",
handler().data().deviceId(), intf, e);
return false;
}
return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
/**
* Builds a request to remove a rate limit from an interface.
*
* @param intf the name of the interface
* @return the request string.
*/
private String removeRateLimitBuilder(String intf) {
StringBuilder rpc = new StringBuilder(getOpeningString(intf));
rpc.append("<srr-queue operation=\"delete\"><bandwidth><limit>");
rpc.append("</limit></bandwidth></srr-queue>");
rpc.append(getClosingString());
return rpc.toString();
}
/**
* Builds the opening of a request for the configuration of an interface.
*
* @param intf the interface to be configured
* @return the opening string
*/
private String getOpeningString(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\">");
......@@ -282,13 +381,17 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
rpc.append(intf);
rpc.append("</Param>");
rpc.append("<ConfigIf-Configuration>");
rpc.append("<switchport><mode operation=\"delete\"><trunk/></mode></switchport>");
rpc.append("<switchport><trunk operation=\"delete\"><encapsulation>");
rpc.append("<dot1q/></encapsulation></trunk></switchport>");
rpc.append("<switchport><trunk operation=\"delete\"><allowed><vlan>");
rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>");
rpc.append("</trunk></switchport></ConfigIf-Configuration>");
return rpc.toString();
}
/**
* Builds the closing of a request for the configuration of an interface.
*
* @return the closing string
*/
private String getClosingString() {
StringBuilder rpc = new StringBuilder("</ConfigIf-Configuration>");
rpc.append("</interface>");
rpc.append("</Device-Configuration>");
rpc.append("</xml-config-data>");
......@@ -326,6 +429,16 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
*/
@Override
public List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId) {
return getInterfaces();
}
/**
* Provides the interfaces configured on a device.
*
* @return the list of the configured interfaces
*/
@Override
public List<DeviceInterfaceDescription> getInterfaces() {
NetconfController controller =
checkNotNull(handler().get(NetconfController.class));
......@@ -336,7 +449,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
reply = session.requestSync(getConfigBuilder());
} catch (NetconfException e) {
log.error("Failed to retrieve configuration from device {}.",
deviceId, e);
handler().data().deviceId(), e);
return null;
}
......