Andrea Campanella
Committed by Gerrit Code Review

ONOS-3577 Adding getConfig with realtive config XML-tree argument

Change-Id: I3ee69bea55352e35007826659277c839d8457d3f
......@@ -28,6 +28,7 @@ public interface NetconfSession {
/**
* Retrives the requested configuration, different from get-config.
*
* @param request the XML containing the request to the server.
* @return device running configuration
*/
......@@ -35,6 +36,7 @@ public interface NetconfSession {
/**
* Executes an RPC to the server.
*
* @param request the XML containing the RPC for the server.
* @return Server response or ERROR
*/
......@@ -69,6 +71,16 @@ public interface NetconfSession {
boolean editConfig(String newConfiguration) throws IOException;
/**
* Retrives part of the specified configuration based on the filterSchema.
* @param targetConfiguration 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
*/
boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
throws IOException;
/**
* 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
......@@ -105,6 +117,7 @@ public interface NetconfSession {
/**
* Closes the Netconf session with the device.
* the first time it tries gracefully, then kills it forcefully
*
* @return true if closed
*/
boolean close() throws IOException;
......@@ -125,6 +138,7 @@ public interface NetconfSession {
/**
* Sets the device capabilities.
*
* @param capabilities list of capabilities the device has.
*/
void setDeviceCapabilities(List<String> capabilities);
......
......@@ -195,6 +195,29 @@ public class NetconfSessionImpl implements NetconfSession {
}
@Override
public boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
throws IOException {
newConfiguration = newConfiguration.trim();
StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
rpc.append("<rpc message-id=\"" + messageID + "\" "
+ "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
rpc.append("<edit-config>");
rpc.append("<target>");
rpc.append("<" + targetConfiguration + "/>");
rpc.append("</target>");
rpc.append("<default-operation>");
rpc.append(mode);
rpc.append("</default-operation>");
rpc.append("<config>");
rpc.append(newConfiguration);
rpc.append("</config>");
rpc.append("</edit-config>");
rpc.append("</rpc>");
rpc.append(endpattern);
return checkReply(doRequest(rpc.toString()));
}
@Override
public boolean copyConfig(String targetConfiguration, String newConfiguration)
throws IOException {
newConfiguration = newConfiguration.trim();
......@@ -322,6 +345,7 @@ public class NetconfSessionImpl implements NetconfSession {
return true;
}
}
log.warn("Error in reply {}", reply);
return false;
}
......