ONOS-5937
- created enum for target config and replaced all appropiate usages
- added old methods and had them pointing to new implementation
- added deprecated annotation to old methods
Change-Id: I2562588d32c7ab944eb44a13e9b25a342196edf2
diff --git a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
index b66a63e..3d620c7 100644
--- a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
@@ -69,6 +69,7 @@
import java.util.regex.Pattern;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.runtime.helperutils.SerializerHelper.addDataNode;
@@ -142,7 +143,7 @@
public ResourceData getDeviceConfig(DeviceId deviceId) throws IOException {
NetconfSession session = getNetconfSession(deviceId);
/*FIXME "running" will be replaced with an enum once netconf supports multiple datastores.*/
- String reply = session.getConfig("running");
+ String reply = session.getConfig(RUNNING);
Matcher protocolStripper = GET_CONFIG_CORE_MESSAGE_PATTERN.matcher(reply);
reply = protocolStripper.group(GET_CONFIG_CORE_MESSAGE_GROUP);
return yangRuntimeService.decode(
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfig.java
index 79d0b06..4801001 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfig.java
@@ -31,6 +31,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
/**
* Implementation to get and set parameters available in vOLT
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java
index 5b55e0c..7a47533 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfig.java
@@ -31,6 +31,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
/**
* Implementation to get and set parameters available in vOLT
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
index 2f642e3..1378bfe 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java
@@ -35,6 +35,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
/**
* Implementation to get and set parameters available in vOLT
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionListenerTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionListenerTest.java
index c35ee21..2642e6b 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionListenerTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionListenerTest.java
@@ -17,6 +17,8 @@
package org.onosproject.drivers.fujitsu;
+import org.onosproject.netconf.TargetConfig;
+
public interface FujitsuNetconfSessionListenerTest {
/**
@@ -34,10 +36,23 @@
* @param mode selected mode to change the configuration
* @param newConfiguration configuration to set
* @return true if everuthing as expected
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
*/
+ @Deprecated
boolean verifyEditConfig(String targetConfiguration, String mode, String newConfiguration);
/**
+ * Verify editConfig request arguments.
+ *
+ * @param targetConfiguration the targetConfiguration to change
+ * @param mode selected mode to change the configuration
+ * @param newConfiguration configuration to set
+ * @return true if everuthing as expected
+ */
+ boolean verifyEditConfig(TargetConfig targetConfiguration, String mode, String newConfiguration);
+
+ /**
* Verify get request arguments.
*
* @param filterSchema XML subtrees to include in the reply
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionMock.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionMock.java
index 980bcb5..b3e5932 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionMock.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuNetconfSessionMock.java
@@ -17,6 +17,7 @@
package org.onosproject.drivers.fujitsu;
import com.google.common.annotations.Beta;
+import org.onosproject.netconf.TargetConfig;
import org.onosproject.netconf.NetconfDeviceOutputEventListener;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
@@ -80,11 +81,22 @@
}
@Override
+ public String getConfig(TargetConfig targetConfiguration) throws NetconfException {
+ return null;
+ }
+
+ @Override
public String getConfig(String targetConfiguration) throws NetconfException {
return null;
}
@Override
+ public String getConfig(TargetConfig targetConfiguration, String configurationFilterSchema)
+ throws NetconfException {
+ return null;
+ }
+
+ @Override
public String getConfig(String targetConfiguration, String configurationFilterSchema)
throws NetconfException {
return null;
@@ -100,6 +112,16 @@
}
@Override
+ public boolean editConfig(TargetConfig targetConfiguration, String mode, String newConfiguration)
+ throws NetconfException {
+ boolean result = true;
+ if (listener != null) {
+ result = listener.verifyEditConfig(targetConfiguration, mode, newConfiguration);
+ }
+ return result;
+ }
+
+ @Override
public boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
throws NetconfException {
boolean result = true;
@@ -110,16 +132,28 @@
}
@Override
+ public boolean copyConfig(TargetConfig targetConfiguration, String newConfiguration)
+ throws NetconfException {
+ return false;
+ }
+
+ @Override
public boolean copyConfig(String targetConfiguration, String newConfiguration)
throws NetconfException {
return false;
}
@Override
+ public boolean deleteConfig(TargetConfig targetConfiguration) throws NetconfException {
+ return false;
+ }
+
+ @Override
public boolean deleteConfig(String targetConfiguration) throws NetconfException {
return false;
}
+
@Override
public void startSubscription() throws NetconfException {
}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfigTest.java
index 156aacc..4847671 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfigTest.java
@@ -19,6 +19,7 @@
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -30,6 +31,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
+import static org.onosproject.netconf.TargetConfig.*;
/**
@@ -229,10 +231,15 @@
}
@Override
- public boolean verifyEditConfig(String target, String mode, String request) {
+ public boolean verifyEditConfig(String targetConfiguration, String mode, String newConfiguration) {
+ return verifyEditConfig(TargetConfig.valueOf(targetConfiguration), mode, newConfiguration);
+ }
+
+ @Override
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
boolean result;
- assertTrue("Incorrect target", target.equals(TEST_RUNNING));
+ assertTrue("Incorrect target", target.equals(RUNNING));
assertNull("Incorrect mode", mode);
request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java
index 72697ee..ce2befb 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfigTest.java
@@ -23,6 +23,7 @@
import org.onosproject.net.behaviour.ControllerInfo;
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import java.io.IOException;
import java.util.ArrayList;
@@ -190,6 +191,11 @@
}
@Override
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
+ return false;
+ }
+
+ @Override
public boolean verifyEditConfig(String target, String mode, String request) {
return false;
}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltFwdlConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltFwdlConfigTest.java
index 3c97458..9df7ece 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltFwdlConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltFwdlConfigTest.java
@@ -18,6 +18,7 @@
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
@@ -157,12 +158,18 @@
return false;
}
+
@Override
public boolean verifyEditConfig(String target, String mode, String request) {
return false;
}
@Override
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
+ return false;
+ }
+
+ @Override
public boolean verifyGet(String filterSchema, String withDefaultsMode) {
return false;
}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfigTest.java
index 9a85a81..039d303 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNeConfigTest.java
@@ -18,6 +18,7 @@
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
@@ -80,6 +81,11 @@
}
@Override
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
+ return false;
+ }
+
+ @Override
public boolean verifyEditConfig(String target, String mode, String request) {
return false;
}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java
index 6326e26..9105a81 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltNniLinkConfigTest.java
@@ -18,12 +18,14 @@
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
/**
* Unit tests for methods of FujitsuVoltPonLinkConfig.
@@ -214,10 +216,10 @@
}
@Override
- public boolean verifyEditConfig(String target, String mode, String request) {
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
boolean result;
- assertTrue("Incorrect target", target.equals(TEST_RUNNING));
+ assertTrue("Incorrect target", target.equals(RUNNING));
assertNull("Incorrect mode", mode);
request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
@@ -229,6 +231,21 @@
}
@Override
+ public boolean verifyEditConfig(String target, String mode, String request) {
+ boolean result;
+
+ assertTrue("Incorrect target", target.equals(TEST_RUNNING));
+ assertNull("Incorrect mode", mode);
+
+ request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
+ assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
+ request.contains(TEST_VOLT_NAMESPACE));
+ result = verifyEditConfigRequest(request);
+ assertTrue("XML verification failure", result);
+ return result;
+ }
+
+ @Override
public boolean verifyGet(String filterSchema, String withDefaultsMode) {
boolean result;
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java
index 172380b..16f3aa3 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfigTest.java
@@ -18,6 +18,7 @@
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
@@ -344,7 +345,12 @@
}
@Override
- public boolean verifyEditConfig(String target, String mode, String request) {
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
+ return false;
+ }
+
+ @Override
+ public boolean verifyEditConfig(String targetConfiguration, String mode, String newConfiguration) {
return false;
}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfigTest.java
index a48a75d..f8d8401 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfigTest.java
@@ -18,6 +18,7 @@
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
@@ -219,6 +220,11 @@
}
@Override
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
+ return false;
+ }
+
+ @Override
public boolean verifyEditConfig(String target, String mode, String request) {
return false;
}
diff --git a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
index 829604d..a0326d2 100644
--- a/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
+++ b/drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
@@ -18,12 +18,14 @@
import org.junit.Before;
import org.junit.Test;
+import org.onosproject.netconf.TargetConfig;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
/**
* Unit tests for methods of FujitsuVoltPonLinkConfig.
@@ -225,6 +227,21 @@
}
@Override
+ public boolean verifyEditConfig(TargetConfig target, String mode, String request) {
+ boolean result;
+
+ assertTrue("Incorrect target", target.equals(RUNNING));
+ assertNull("Incorrect mode", mode);
+
+ request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
+ assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
+ request.contains(TEST_VOLT_NAMESPACE));
+ result = verifyEditConfigRequest(request);
+ assertTrue("XML verification failure", result);
+ return result;
+ }
+
+ @Override
public boolean verifyEditConfig(String target, String mode, String request) {
boolean result;
@@ -233,7 +250,7 @@
request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE);
assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE,
- request.contains(TEST_VOLT_NAMESPACE));
+ request.contains(TEST_VOLT_NAMESPACE));
result = verifyEditConfigRequest(request);
assertTrue("XML verification failure", result);
return result;
diff --git a/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfConfigGetter.java b/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfConfigGetter.java
index 8a373c4..51abcaa 100644
--- a/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfConfigGetter.java
+++ b/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfConfigGetter.java
@@ -19,6 +19,7 @@
import com.google.common.base.Preconditions;
import org.onosproject.net.DeviceId;
import org.onosproject.net.behaviour.ConfigGetter;
+import org.onosproject.netconf.TargetConfig;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.netconf.NetconfController;
@@ -55,12 +56,11 @@
return controller.getDevicesMap().
get(ofDeviceId).
getSession().
- getConfig(type);
+ getConfig(TargetConfig.valueOf(type));
} catch (IOException e) {
log.error("Configuration could not be retrieved {}",
e.getMessage());
}
return UNABLE_TO_READ_CONFIG;
}
-
}
diff --git a/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java b/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java
index 832ac3d..be55574 100644
--- a/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java
+++ b/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java
@@ -26,6 +26,7 @@
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfDevice;
+
import org.slf4j.Logger;
import java.io.ByteArrayInputStream;
@@ -34,6 +35,7 @@
import java.util.ArrayList;
import java.util.List;
+import static org.onosproject.netconf.TargetConfig.RUNNING;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -57,7 +59,7 @@
if (mastershipService.isLocalMaster(deviceId)) {
try {
String reply = controller.getNetconfDevice(deviceId).getSession().
- getConfig("running");
+ getConfig(RUNNING);
log.debug("Reply XML {}", reply);
controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
@@ -85,7 +87,7 @@
String config = null;
try {
- String reply = device.getSession().getConfig("running");
+ String reply = device.getSession().getConfig(RUNNING);
log.info("reply XML {}", reply);
config = XmlConfigParser.createControllersConfig(
XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")),
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java
index 172d53c..e2d435d 100644
--- a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java
@@ -17,6 +17,7 @@
package org.onosproject.netconf;
import com.google.common.annotations.Beta;
+
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -88,26 +89,57 @@
/**
* Retrives the specified configuration.
*
- * @param targetConfiguration the type of configuration to retrieve.
+ * @param netconfTargetConfig the type of configuration to retrieve.
* @return specified configuration.
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- String getConfig(String targetConfiguration) throws NetconfException;
+ String getConfig(TargetConfig netconfTargetConfig) throws NetconfException;
+
+ /**
+ * Retrives the specified configuration.
+ *
+ * @param netconfTargetConfig the type of configuration to retrieve.
+ * @return specified configuration.
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ String getConfig(String netconfTargetConfig) throws NetconfException;
+
/**
* Retrives part of the specivied configuration based on the filterSchema.
*
- * @param targetConfiguration the type of configuration to retrieve.
+ * @param netconfTargetConfig the type of configuration to retrieve.
+ * @param configurationFilterSchema XML schema to filter the configuration
+ * elements we are interested in
+ * @return device running configuration.
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ String getConfig(String netconfTargetConfig, String configurationFilterSchema)
+ throws NetconfException;
+
+ /**
+ * Retrives part of the specivied configuration based on the filterSchema.
+ *
+ * @param netconfTargetConfig the type of configuration to retrieve.
* @param configurationFilterSchema XML schema to filter the configuration
* elements we are interested in
* @return device running configuration.
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- String getConfig(String targetConfiguration, String configurationFilterSchema)
+ String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema)
throws NetconfException;
+
/**
* Retrives part of the specified configuration based on the filterSchema.
*
@@ -122,14 +154,30 @@
/**
* Retrives part of the specified configuration based on the filterSchema.
*
- * @param targetConfiguration the targetConfiguration to change
+ * @param netconfTargetConfig the targetConfiguration to change
+ * @param mode selected mode to change the configuration
+ * @param newConfiguration configuration to set
+ * @return true if the configuration was edited correctly
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration)
+ throws NetconfException;
+
+ /**
+ * Retrives part of the specified configuration based on the filterSchema.
+ *
+ * @param netconfTargetConfig the targetConfiguration to change
* @param mode selected mode to change the configuration
* @param newConfiguration configuration to set
* @return true if the configuration was edited correctly
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
+ boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration)
throws NetconfException;
/**
@@ -137,24 +185,54 @@
* to the target configuration.
* The target configuration can't be the running one
*
- * @param targetConfiguration the type of configuration to retrieve.
+ * @param netconfTargetConfig the type of configuration to retrieve.
+ * @param newConfiguration configuration to set
+ * @return true if the configuration was copied correctly
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ boolean copyConfig(String netconfTargetConfig, String newConfiguration)
+ throws NetconfException;
+
+ /**
+ * Copies the new configuration, an Url or a complete configuration xml tree
+ * to the target configuration.
+ * The target configuration can't be the running one
+ *
+ * @param netconfTargetConfig the type of configuration to retrieve.
* @param newConfiguration configuration to set
* @return true if the configuration was copied correctly
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- boolean copyConfig(String targetConfiguration, String newConfiguration)
+ boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration)
throws NetconfException;
/**
* Deletes part of the specified configuration based on the filterSchema.
*
- * @param targetConfiguration the name of the configuration to delete
+ * @param netconfTargetConfig the name of the configuration to delete
+ * @return true if the configuration was copied correctly
+ * @throws NetconfException when there is a problem in the communication process on
+ * the underlying connection
+ * @deprecated - 1.10.0 Kingfisher use method overload that accepts
+ * org.onosproject.netconf.TargetConfig enum parameter instead
+ */
+ @Deprecated
+ boolean deleteConfig(String netconfTargetConfig) throws NetconfException;
+
+ /**
+ * Deletes part of the specified configuration based on the filterSchema.
+ *
+ * @param netconfTargetConfig the name of the configuration to delete
* @return true if the configuration was copied correctly
* @throws NetconfException when there is a problem in the communication process on
* the underlying connection
*/
- boolean deleteConfig(String targetConfiguration) throws NetconfException;
+ boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException;
/**
* Starts subscription to the device's notifications.
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
new file mode 100644
index 0000000..ecc924c
--- /dev/null
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/TargetConfig.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-present 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.netconf;
+
+public enum TargetConfig {
+ RUNNING("running"),
+ CANDIDATE("candidate"),
+ STARTUP("startup");
+
+ private String name;
+
+ TargetConfig(String name) {
+ this.name = name;
+ }
+
+ TargetConfig toTargetConfig(String targetConfig) {
+ switch (targetConfig) {
+ case "running":
+ return RUNNING;
+ case "candidate":
+ return CANDIDATE;
+ case "startup":
+ return STARTUP;
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return this.name;
+ }
+}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
index 73c6f93..72ae513 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
@@ -20,6 +20,7 @@
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import com.google.common.base.Preconditions;
+import org.onosproject.netconf.TargetConfig;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfDeviceOutputEvent;
import org.onosproject.netconf.NetconfDeviceOutputEventListener;
@@ -385,12 +386,22 @@
}
@Override
- public String getConfig(String targetConfiguration) throws NetconfException {
- return getConfig(targetConfiguration, null);
+ public String getConfig(TargetConfig netconfTargetConfig) throws NetconfException {
+ return getConfig(netconfTargetConfig, null);
}
@Override
- public String getConfig(String targetConfiguration, String configurationSchema) throws NetconfException {
+ public String getConfig(String netconfTargetConfig) throws NetconfException {
+ return getConfig(TargetConfig.valueOf(netconfTargetConfig));
+ }
+
+ @Override
+ public String getConfig(String netconfTargetConfig, String configurationFilterSchema) throws NetconfException {
+ return getConfig(TargetConfig.valueOf(netconfTargetConfig), configurationFilterSchema);
+ }
+
+ @Override
+ public String getConfig(TargetConfig netconfTargetConfig, String configurationSchema) throws NetconfException {
StringBuilder rpc = new StringBuilder(XML_HEADER);
rpc.append("<rpc ");
rpc.append(MESSAGE_ID_STRING);
@@ -401,7 +412,7 @@
rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
rpc.append("<get-config>\n");
rpc.append("<source>\n");
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append("</source>");
if (configurationSchema != null) {
rpc.append("<filter type=\"subtree\">\n");
@@ -422,7 +433,13 @@
}
@Override
- public boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
+ public boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration)
+ throws NetconfException {
+ return editConfig(TargetConfig.valueOf(netconfTargetConfig), mode, newConfiguration);
+ }
+
+ @Override
+ public boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration)
throws NetconfException {
newConfiguration = newConfiguration.trim();
StringBuilder rpc = new StringBuilder(XML_HEADER);
@@ -435,7 +452,7 @@
rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
rpc.append(EDIT_CONFIG_OPEN).append("\n");
rpc.append(TARGET_OPEN);
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append(TARGET_CLOSE).append("\n");
if (mode != null) {
rpc.append(DEFAULT_OPERATION_OPEN);
@@ -454,7 +471,12 @@
}
@Override
- public boolean copyConfig(String targetConfiguration, String newConfiguration)
+ public boolean copyConfig(String netconfTargetConfig, String newConfiguration) throws NetconfException {
+ return copyConfig(TargetConfig.valueOf(netconfTargetConfig), newConfiguration);
+ }
+
+ @Override
+ public boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration)
throws NetconfException {
newConfiguration = newConfiguration.trim();
if (!newConfiguration.startsWith("<config>")) {
@@ -466,7 +488,7 @@
rpc.append(NETCONF_BASE_NAMESPACE).append(">\n");
rpc.append("<copy-config>");
rpc.append("<target>");
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append("</target>");
rpc.append("<source>");
rpc.append(newConfiguration);
@@ -478,17 +500,22 @@
}
@Override
- public boolean deleteConfig(String targetConfiguration) throws NetconfException {
- if (targetConfiguration.equals("running")) {
+ public boolean deleteConfig(String netconfTargetConfig) throws NetconfException {
+ return deleteConfig(TargetConfig.valueOf(netconfTargetConfig));
+ }
+
+ @Override
+ public boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException {
+ if (netconfTargetConfig.equals("running")) {
log.warn("Target configuration for delete operation can't be \"running\"",
- targetConfiguration);
+ netconfTargetConfig);
return false;
}
StringBuilder rpc = new StringBuilder(XML_HEADER);
rpc.append("<rpc>");
rpc.append("<delete-config>");
rpc.append("<target>");
- rpc.append("<").append(targetConfiguration).append("/>");
+ rpc.append("<").append(netconfTargetConfig).append("/>");
rpc.append("</target>");
rpc.append("</delete-config>");
rpc.append("</rpc>");
diff --git a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java
index 661c290..fe2a0d5 100644
--- a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java
+++ b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/NetconfSessionImplTest.java
@@ -18,6 +18,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.onosproject.netconf.TargetConfig.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -42,6 +43,7 @@
import org.junit.Test;
import org.onlab.junit.TestTools;
import org.onlab.packet.Ip4Address;
+import org.onosproject.netconf.TargetConfig;
import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
@@ -128,7 +130,7 @@
log.info("Starting edit-config async");
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
- assertTrue("NETCONF edit-config command failed", session1.editConfig("running", null, SAMPLE_REQUEST));
+ assertTrue("NETCONF edit-config command failed", session1.editConfig(RUNNING, null, SAMPLE_REQUEST));
} catch (NetconfException e) {
e.printStackTrace();
fail("NETCONF edit-config test failed: " + e.getMessage());
@@ -141,7 +143,7 @@
log.info("Starting copy-config async");
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
- assertTrue("NETCONF edit-config command failed", session1.copyConfig("running", "candidate"));
+ assertTrue("NETCONF edit-config command failed", session1.copyConfig(RUNNING, "candidate"));
} catch (NetconfException e) {
e.printStackTrace();
fail("NETCONF edit-config test failed: " + e.getMessage());
@@ -155,10 +157,10 @@
assertNotNull("Incorrect sessionId", session1.getSessionId());
try {
assertTrue("NETCONF get-config running command failed. ",
- GET_REPLY_PATTERN.matcher(session1.getConfig("running", SAMPLE_REQUEST)).matches());
+ GET_REPLY_PATTERN.matcher(session1.getConfig(RUNNING, SAMPLE_REQUEST)).matches());
assertTrue("NETCONF get-config candidate command failed. ",
- GET_REPLY_PATTERN.matcher(session1.getConfig("candidate", SAMPLE_REQUEST)).matches());
+ GET_REPLY_PATTERN.matcher(session1.getConfig(CANDIDATE, SAMPLE_REQUEST)).matches());
} catch (NetconfException e) {
e.printStackTrace();
@@ -184,8 +186,8 @@
@Test
public void testConcurrentSameSessionAccess() throws InterruptedException {
- NCCopyConfigCallable testCopyConfig1 = new NCCopyConfigCallable(session1, "running", "candidate");
- NCCopyConfigCallable testCopyConfig2 = new NCCopyConfigCallable(session1, "candidate", "startup");
+ NCCopyConfigCallable testCopyConfig1 = new NCCopyConfigCallable(session1, RUNNING, "candidate");
+ NCCopyConfigCallable testCopyConfig2 = new NCCopyConfigCallable(session1, RUNNING, "startup");
FutureTask<Boolean> futureCopyConfig1 = new FutureTask<Boolean>(testCopyConfig1);
FutureTask<Boolean> futureCopyConfig2 = new FutureTask<Boolean>(testCopyConfig2);
@@ -210,8 +212,8 @@
@Test
public void test2SessionAccess() throws InterruptedException {
- NCCopyConfigCallable testCopySession1 = new NCCopyConfigCallable(session1, "running", "candidate");
- NCCopyConfigCallable testCopySession2 = new NCCopyConfigCallable(session2, "running", "candidate");
+ NCCopyConfigCallable testCopySession1 = new NCCopyConfigCallable(session1, RUNNING, "candidate");
+ NCCopyConfigCallable testCopySession2 = new NCCopyConfigCallable(session2, RUNNING, "candidate");
FutureTask<Boolean> futureCopySession1 = new FutureTask<Boolean>(testCopySession1);
FutureTask<Boolean> futureCopySession2 = new FutureTask<Boolean>(testCopySession2);
@@ -338,10 +340,10 @@
public class NCCopyConfigCallable implements Callable<Boolean> {
private NetconfSession session;
- private String target;
+ private TargetConfig target;
private String source;
- public NCCopyConfigCallable(NetconfSession session, String target, String source) {
+ public NCCopyConfigCallable(NetconfSession session, TargetConfig target, String source) {
this.session = session;
this.target = target;
this.source = source;