[GEANT] Remove configuration from device interfaces.
Change-Id: Ie382a645c2ec8677ccd9ba6ed4b881e38686c1b9
diff --git a/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceAddCommand.java b/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceAddCommand.java
index 9ceeb65..f2a0bbc 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceAddCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceAddCommand.java
@@ -33,14 +33,14 @@
public class DeviceInterfaceAddCommand extends AbstractShellCommand {
private static final String CONFIG_VLAN_SUCCESS =
- "VLAN %s set on device %s interface %s.";
+ "VLAN %s added on device %s interface %s.";
private static final String CONFIG_VLAN_FAILURE =
- "Failed to set VLAN %s on device %s interface %s.";
+ "Failed to add VLAN %s on device %s interface %s.";
private static final String CONFIG_TRUNK_SUCCESS =
- "Trunk mode set for VLAN %s on device %s interface %s.";
+ "Trunk mode added for VLAN %s on device %s interface %s.";
private static final String CONFIG_TRUNK_FAILURE =
- "Failed to set trunk mode for VLAN %s on device %s interface %s.";
+ "Failed to add trunk mode for VLAN %s on device %s interface %s.";
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
diff --git a/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceRemoveCommand.java b/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceRemoveCommand.java
new file mode 100644
index 0000000..1f727cb
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/DeviceInterfaceRemoveCommand.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+
+/**
+ * Removes configured interface 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 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 REMOVE_TRUNK_SUCCESS =
+ "Trunk mode removed for VLAN %s on device %s interface %s.";
+ private static final String REMOVE_TRUNK_FAILURE =
+ "Failed to remove trunk mode for VLAN %s on 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)
+ private String portName = null;
+
+ @Argument(index = 2, name = "vlan",
+ description = "VLAN ID",
+ required = true, multiValued = false)
+ private String vlanString = null;
+
+ @Option(name = "-t", aliases = "--trunk",
+ description = "Remove trunk mode for VLAN",
+ required = false, multiValued = false)
+ private boolean trunkMode = false;
+
+ @Override
+ protected void execute() {
+ DriverService service = get(DriverService.class);
+ DeviceId deviceId = DeviceId.deviceId(uri);
+ DriverHandler h = service.createHandler(deviceId);
+ InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
+
+ VlanId vlanId = VlanId.vlanId(Short.parseShort(vlanString));
+
+ if (trunkMode) {
+ // Trunk mode for VLAN to be removed.
+ if (interfaceConfig.removeTrunkInterface(deviceId, portName, vlanId)) {
+ print(REMOVE_TRUNK_SUCCESS, vlanId, deviceId, portName);
+ } else {
+ print(REMOVE_TRUNK_FAILURE, vlanId, deviceId, portName);
+ }
+ return;
+ }
+
+ // Interface to be removed from VLAN.
+ if (interfaceConfig.removeInterfaceFromVlan(deviceId, portName, vlanId)) {
+ print(REMOVE_VLAN_SUCCESS, vlanId, deviceId, portName);
+ } else {
+ print(REMOVE_VLAN_FAILURE, vlanId, deviceId, portName);
+ }
+ }
+
+}
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index d57dcb2..a98a38a 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -161,6 +161,12 @@
</completers>
</command>
<command>
+ <action class="org.onosproject.cli.net.DeviceInterfaceRemoveCommand"/>
+ <completers>
+ <ref component-id="deviceIdCompleter"/>
+ </completers>
+ </command>
+ <command>
<action class="org.onosproject.cli.net.AddMeter"/>
<completers>
<ref component-id="deviceIdCompleter"/>
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java
index 4079350..1e1898f 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java
@@ -34,6 +34,15 @@
boolean addInterfaceToVlan(DeviceId deviceId, String intf, VlanId vlanId);
/**
+ * Removes an interface from 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);
+
+ /**
* Configures an interface as trunk for VLAN.
* @param deviceId the device ID
* @param intf the name of the interface
@@ -42,8 +51,19 @@
*/
boolean addTrunkInterface(DeviceId deviceId, String intf, VlanId vlanId);
- /* TODO Addition of more methods to make the behavior symmetrical.
- Methods removeVlanFromInterface, getInterfacesForVlan, getVlansForInterface
- should be added to complete the behavior.
+ /**
+ * Removes trunk mode configuration for VLAN from an interface.
+ * @param deviceId the device ID
+ * @param intf the name of the interface
+ * @param vlanId the VLAN ID
+ * @return the result of operation
*/
+ boolean removeTrunkInterface(DeviceId deviceId, String intf, VlanId vlanId);
+
+ /**
+ * TODO Addition of more methods to make the behavior symmetrical.
+ * Methods getInterfacesForVlan, getVlansForInterface, getTrunkforInterface,
+ * getInterfacesForTrunk should be added to complete the behavior.
+ */
+
}
diff --git a/drivers/cisco/features.xml b/drivers/cisco/features.xml
index 6fa9fe2..6c8158f 100644
--- a/drivers/cisco/features.xml
+++ b/drivers/cisco/features.xml
@@ -18,6 +18,8 @@
<feature name="${project.artifactId}" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
+ <bundle>mvn:${project.groupId}/onos-drivers-netconf/${project.version}</bundle>
+
<bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-drivers-utilities/${project.version}</bundle>
diff --git a/drivers/cisco/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoIosImpl.java b/drivers/cisco/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoIosImpl.java
new file mode 100644
index 0000000..4a9cced
--- /dev/null
+++ b/drivers/cisco/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoIosImpl.java
@@ -0,0 +1,304 @@
+/*
+ *
+ * * Copyright 2016 Open Networking Laboratory
+ * *
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package org.onosproject.drivers.cisco;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.InterfaceConfig;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.NetconfSession;
+import org.slf4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Configures interfaces on Cisco IOS devices.
+ */
+public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
+ implements InterfaceConfig {
+
+ private final Logger log = getLogger(getClass());
+
+ /**
+ * Adds an 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) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ //TODO remove XML triming if preceeds in Session
+ reply = session.requestSync(addInterfaceToVlanBuilder(intf, vlanId)).trim();
+ } catch (NetconfException e) {
+ log.error("Failed to configure VLAN ID {} on device {} interface {}.",
+ vlanId, deviceId, intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to add an 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) {
+ 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>");
+ 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>");
+
+ return rpc.toString();
+ }
+
+ /**
+ * Removes an interface from 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) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ //TODO remove XML triming if preceeds in Session
+ reply = session.requestSync(removeInterfaceFromVlanBuilder(intf, vlanId)).trim();
+ } catch (NetconfException e) {
+ log.error("Failed to remove VLAN ID {} from device {} interface {}.",
+ vlanId, deviceId, intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to remove an 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) {
+ 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>");
+ 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>");
+ rpc.append("</interface>");
+ rpc.append("</Device-Configuration>");
+ rpc.append("</xml-config-data>");
+ rpc.append("</config>");
+ rpc.append("</edit-config>");
+ rpc.append("</rpc>");
+
+ return rpc.toString();
+ }
+
+ /**
+ * Configures an interface as trunk for 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 addTrunkInterface(DeviceId deviceId, String intf, VlanId vlanId) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ //TODO remove XML triming if preceeds in Session
+ reply = session.requestSync(addTrunkInterfaceBuilder(intf, vlanId)).trim();
+ } catch (NetconfException e) {
+ log.error("Failed to configure trunk mode for VLAN ID {} on device {} interface {}.",
+ vlanId, deviceId, intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+ }
+
+ /**
+ * Builds a request to configure an interface as trunk for VLAN.
+ * @param intf the name of the interface
+ * @param vlanId the VLAN ID
+ * @return the request string.
+ */
+ private String addTrunkInterfaceBuilder(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>");
+ rpc.append("<switchport><trunk><encapsulation><dot1q/></encapsulation>");
+ rpc.append("</trunk></switchport><switchport><trunk><allowed><vlan>");
+ rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
+ rpc.append(vlanId);
+ 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>");
+
+ return rpc.toString();
+ }
+
+ /**
+ * Removes trunk mode configuration for VLAN from an interface.
+ * @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 removeTrunkInterface(DeviceId deviceId, String intf, VlanId vlanId) {
+ NetconfController controller = checkNotNull(handler()
+ .get(NetconfController.class));
+
+ NetconfSession session = controller.getDevicesMap().get(handler()
+ .data().deviceId()).getSession();
+ String reply;
+ try {
+ //TODO remove XML triming if preceeds in Session
+ reply = session.requestSync(removeTrunkInterfaceBuilder(intf, vlanId)).trim();
+ } catch (NetconfException e) {
+ log.error("Failed to remove trunk mode for VLAN ID {} on device {} interface {}.",
+ vlanId, deviceId, intf, e);
+ return false;
+ }
+
+ return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
+ new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
+}
+
+ /**
+ * Builds a request to remove trunk mode configuration for VLAN from an interface.
+ * @param intf the name of the interface
+ * @param vlanId the VLAN ID
+ * @return the request string.
+ */
+ private String removeTrunkInterfaceBuilder(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>");
+ 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(vlanId);
+ rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>");
+ rpc.append("</trunk></switchport></ConfigIf-Configuration>");
+ rpc.append("</interface>");
+ rpc.append("</Device-Configuration>");
+ rpc.append("</xml-config-data>");
+ rpc.append("</config>");
+ rpc.append("</edit-config>");
+ rpc.append("</rpc>");
+
+ return rpc.toString();
+ }
+
+}
+
diff --git a/drivers/cisco/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoSmXImpl.java b/drivers/cisco/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoSmXImpl.java
deleted file mode 100644
index 6df1076..0000000
--- a/drivers/cisco/src/main/java/org/onosproject/drivers/cisco/InterfaceConfigCiscoSmXImpl.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- *
- * * Copyright 2016 Open Networking Laboratory
- * *
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- *
- */
-
-package org.onosproject.drivers.cisco;
-
-import org.onlab.packet.VlanId;
-import org.onosproject.drivers.utilities.XmlConfigParser;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.behaviour.InterfaceConfig;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.netconf.NetconfController;
-import org.onosproject.netconf.NetconfException;
-import org.onosproject.netconf.NetconfSession;
-import org.slf4j.Logger;
-
-import java.io.ByteArrayInputStream;
-import java.nio.charset.StandardCharsets;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Configures interfaces on Cisco SM-X devices.
- */
-public class InterfaceConfigCiscoSmXImpl extends AbstractHandlerBehaviour
- implements InterfaceConfig {
-
- private final Logger log = getLogger(getClass());
-
- /**
- * Adds an 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) {
- NetconfController controller = checkNotNull(handler()
- .get(NetconfController.class));
-
- NetconfSession session = controller.getDevicesMap().get(handler()
- .data().deviceId()).getSession();
- String reply;
- try {
- reply = session.requestSync(addInterfaceToVlanBuilder(intf, vlanId)).trim();
- } catch (NetconfException e) {
- log.error("Failed to configure VLAN ID {} on device {} port {}.",
- vlanId, deviceId, intf, e);
- return false;
- }
-
- return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
- new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
- }
-
- /**
- * Builds a request crafted to add an 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) {
- StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- rpc.append("<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>");
- 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>");
-
- return rpc.toString();
- }
-
- /**
- * Configures an interface as trunk for 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 addTrunkInterface(DeviceId deviceId, String intf, VlanId vlanId) {
- NetconfController controller = checkNotNull(handler()
- .get(NetconfController.class));
-
- NetconfSession session = controller.getDevicesMap().get(handler()
- .data().deviceId()).getSession();
- String reply;
- try {
- reply = session.requestSync(addTrunkInterface(intf, vlanId)).trim();
- } catch (NetconfException e) {
- log.error("Failed to configure VLAN ID {} on device {} port {}.",
- vlanId, deviceId, intf, e);
- return false;
- }
-
- return XmlConfigParser.configSuccess(XmlConfigParser.loadXml(
- new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
- }
-
- /**
- * Builds a request crafted to configure an interface as trunk for VLAN.
- * @param intf the name of the interface
- * @param vlanId the VLAN ID
- * @return the request string.
- */
- private String addTrunkInterface(String intf, VlanId vlanId) {
- StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- rpc.append("<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>");
- rpc.append("<switchport><trunk><encapsulation><dot1q/></encapsulation></trunk></switchport>");
- rpc.append("<switchport><trunk><allowed><vlan><VLANIDsAllowedVLANsPortTrunkingMode>");
- rpc.append(vlanId);
- rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed></trunk></switchport>");
- rpc.append("<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>");
-
- return rpc.toString();
- }
-
-}
-
diff --git a/drivers/cisco/src/main/resources/cisco-drivers.xml b/drivers/cisco/src/main/resources/cisco-drivers.xml
index 2c07021..e779f2c 100644
--- a/drivers/cisco/src/main/resources/cisco-drivers.xml
+++ b/drivers/cisco/src/main/resources/cisco-drivers.xml
@@ -16,8 +16,8 @@
-->
<drivers>
<driver name="cisco-netconf" extends="netconf" manufacturer="Cisco"
- hwVersion="SM-X" swVersion="IOS 15">
+ hwVersion="" swVersion="IOS">
<behaviour api="org.onosproject.net.behaviour.InterfaceConfig"
- impl="org.onosproject.drivers.cisco.InterfaceConfigCiscoSmXImpl"/>
+ impl="org.onosproject.drivers.cisco.InterfaceConfigCiscoIosImpl"/>
</driver>
</drivers>