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 { ...@@ -28,6 +28,7 @@ public interface NetconfSession {
28 28
29 /** 29 /**
30 * Retrives the requested configuration, different from get-config. 30 * Retrives the requested configuration, different from get-config.
31 + *
31 * @param request the XML containing the request to the server. 32 * @param request the XML containing the request to the server.
32 * @return device running configuration 33 * @return device running configuration
33 */ 34 */
...@@ -35,6 +36,7 @@ public interface NetconfSession { ...@@ -35,6 +36,7 @@ public interface NetconfSession {
35 36
36 /** 37 /**
37 * Executes an RPC to the server. 38 * Executes an RPC to the server.
39 + *
38 * @param request the XML containing the RPC for the server. 40 * @param request the XML containing the RPC for the server.
39 * @return Server response or ERROR 41 * @return Server response or ERROR
40 */ 42 */
...@@ -69,6 +71,16 @@ public interface NetconfSession { ...@@ -69,6 +71,16 @@ public interface NetconfSession {
69 boolean editConfig(String newConfiguration) throws IOException; 71 boolean editConfig(String newConfiguration) throws IOException;
70 72
71 /** 73 /**
74 + * Retrives part of the specified configuration based on the filterSchema.
75 + * @param targetConfiguration the targetConfiguration to change
76 + * @param mode selected mode to change the configuration
77 + * @param newConfiguration configuration to set
78 + * @return true if the configuration was edited correctly
79 + */
80 + boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
81 + throws IOException;
82 +
83 + /**
72 * Copies the new configuration, an Url or a complete configuration xml tree 84 * Copies the new configuration, an Url or a complete configuration xml tree
73 * to the target configuration. 85 * to the target configuration.
74 * The target configuration can't be the running one 86 * The target configuration can't be the running one
...@@ -105,6 +117,7 @@ public interface NetconfSession { ...@@ -105,6 +117,7 @@ public interface NetconfSession {
105 /** 117 /**
106 * Closes the Netconf session with the device. 118 * Closes the Netconf session with the device.
107 * the first time it tries gracefully, then kills it forcefully 119 * the first time it tries gracefully, then kills it forcefully
120 + *
108 * @return true if closed 121 * @return true if closed
109 */ 122 */
110 boolean close() throws IOException; 123 boolean close() throws IOException;
...@@ -125,6 +138,7 @@ public interface NetconfSession { ...@@ -125,6 +138,7 @@ public interface NetconfSession {
125 138
126 /** 139 /**
127 * Sets the device capabilities. 140 * Sets the device capabilities.
141 + *
128 * @param capabilities list of capabilities the device has. 142 * @param capabilities list of capabilities the device has.
129 */ 143 */
130 void setDeviceCapabilities(List<String> capabilities); 144 void setDeviceCapabilities(List<String> capabilities);
......
...@@ -195,6 +195,29 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -195,6 +195,29 @@ public class NetconfSessionImpl implements NetconfSession {
195 } 195 }
196 196
197 @Override 197 @Override
198 + public boolean editConfig(String targetConfiguration, String mode, String newConfiguration)
199 + throws IOException {
200 + newConfiguration = newConfiguration.trim();
201 + StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
202 + rpc.append("<rpc message-id=\"" + messageID + "\" "
203 + + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
204 + rpc.append("<edit-config>");
205 + rpc.append("<target>");
206 + rpc.append("<" + targetConfiguration + "/>");
207 + rpc.append("</target>");
208 + rpc.append("<default-operation>");
209 + rpc.append(mode);
210 + rpc.append("</default-operation>");
211 + rpc.append("<config>");
212 + rpc.append(newConfiguration);
213 + rpc.append("</config>");
214 + rpc.append("</edit-config>");
215 + rpc.append("</rpc>");
216 + rpc.append(endpattern);
217 + return checkReply(doRequest(rpc.toString()));
218 + }
219 +
220 + @Override
198 public boolean copyConfig(String targetConfiguration, String newConfiguration) 221 public boolean copyConfig(String targetConfiguration, String newConfiguration)
199 throws IOException { 222 throws IOException {
200 newConfiguration = newConfiguration.trim(); 223 newConfiguration = newConfiguration.trim();
...@@ -322,6 +345,7 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -322,6 +345,7 @@ public class NetconfSessionImpl implements NetconfSession {
322 return true; 345 return true;
323 } 346 }
324 } 347 }
348 + log.warn("Error in reply {}", reply);
325 return false; 349 return false;
326 } 350 }
327 351
......