Andrea Campanella
Committed by Gerrit Code Review

ONOS-3575 Netconf connection exceptions refactoring and port number in netconf-cfg.json

Change-Id: I46771a1a3ce99b25c2aecd7ba1838f9f1614e789
...@@ -27,6 +27,7 @@ import org.onosproject.netconf.NetconfDevice; ...@@ -27,6 +27,7 @@ import org.onosproject.netconf.NetconfDevice;
27 import org.slf4j.Logger; 27 import org.slf4j.Logger;
28 28
29 import java.io.ByteArrayInputStream; 29 import java.io.ByteArrayInputStream;
30 +import java.io.IOException;
30 import java.nio.charset.StandardCharsets; 31 import java.nio.charset.StandardCharsets;
31 import java.util.ArrayList; 32 import java.util.ArrayList;
32 import java.util.List; 33 import java.util.List;
...@@ -49,10 +50,14 @@ public class NetconfControllerConfig extends AbstractHandlerBehaviour ...@@ -49,10 +50,14 @@ public class NetconfControllerConfig extends AbstractHandlerBehaviour
49 DeviceId ofDeviceId = handler.data().deviceId(); 50 DeviceId ofDeviceId = handler.data().deviceId();
50 Preconditions.checkNotNull(controller, "Netconf controller is null"); 51 Preconditions.checkNotNull(controller, "Netconf controller is null");
51 List<ControllerInfo> controllers = new ArrayList<>(); 52 List<ControllerInfo> controllers = new ArrayList<>();
52 - controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser. 53 + try {
53 - loadXml(new ByteArrayInputStream(controller. 54 + controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.
54 - getDevicesMap().get(ofDeviceId).getSession(). 55 + loadXml(new ByteArrayInputStream(controller.
55 - getConfig("running").getBytes(StandardCharsets.UTF_8))))); 56 + getDevicesMap().get(ofDeviceId).getSession().
57 + getConfig("running").getBytes(StandardCharsets.UTF_8)))));
58 + } catch (IOException e) {
59 + log.error("Cannot comunicate to device {} ", ofDeviceId);
60 + }
56 return controllers; 61 return controllers;
57 } 62 }
58 63
...@@ -65,19 +70,26 @@ public class NetconfControllerConfig extends AbstractHandlerBehaviour ...@@ -65,19 +70,26 @@ public class NetconfControllerConfig extends AbstractHandlerBehaviour
65 try { 70 try {
66 NetconfDevice device = controller.getNetconfDevice(deviceId); 71 NetconfDevice device = controller.getNetconfDevice(deviceId);
67 log.warn("provider map {}", controller.getDevicesMap()); 72 log.warn("provider map {}", controller.getDevicesMap());
68 - String config = XmlConfigParser.createControllersConfig( 73 + String config = null;
69 - XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")), 74 + try {
70 - XmlConfigParser.loadXml( 75 + config = XmlConfigParser.createControllersConfig(
71 - new ByteArrayInputStream(device.getSession() 76 + XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")),
72 - .getConfig("running") 77 + XmlConfigParser.loadXml(
73 - .getBytes( 78 + new ByteArrayInputStream(device.getSession()
74 - StandardCharsets.UTF_8))), 79 + .getConfig("running")
75 - "running", "merge", "create", controllers 80 + .getBytes(
76 - ); 81 + StandardCharsets.UTF_8))),
82 + "running", "merge", "create", controllers
83 + );
84 + } catch (IOException e) {
85 + log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
86 + }
77 device.getSession().editConfig(config.substring(config.indexOf("-->") + 3)); 87 device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
78 } catch (NullPointerException e) { 88 } catch (NullPointerException e) {
79 log.warn("No NETCONF device with requested parameters " + e); 89 log.warn("No NETCONF device with requested parameters " + e);
80 throw new NullPointerException("No NETCONF device with requested parameters " + e); 90 throw new NullPointerException("No NETCONF device with requested parameters " + e);
91 + } catch (IOException e) {
92 + log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
81 } 93 }
82 94
83 } 95 }
......
...@@ -68,7 +68,7 @@ public class NetconfDeviceInfo { ...@@ -68,7 +68,7 @@ public class NetconfDeviceInfo {
68 * @param password the password for the device 68 * @param password the password for the device
69 * @param ipAddress the ip address 69 * @param ipAddress the ip address
70 * @param port the tcp port 70 * @param port the tcp port
71 - * @param keyString the string cointaing the key. 71 + * @param keyString the string containing the key.
72 */ 72 */
73 public NetconfDeviceInfo(String name, String password, IpAddress ipAddress, 73 public NetconfDeviceInfo(String name, String password, IpAddress ipAddress,
74 int port, String keyString) { 74 int port, String keyString) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.netconf; 17 package org.onosproject.netconf;
18 18
19 +import java.io.IOException;
19 import java.util.List; 20 import java.util.List;
20 21
21 /** 22 /**
...@@ -30,14 +31,14 @@ public interface NetconfSession { ...@@ -30,14 +31,14 @@ public interface NetconfSession {
30 * @param request the XML containing the request to the server. 31 * @param request the XML containing the request to the server.
31 * @return device running configuration 32 * @return device running configuration
32 */ 33 */
33 - String get(String request); 34 + String get(String request) throws IOException;
34 35
35 /** 36 /**
36 * Executes an RPC to the server. 37 * Executes an RPC to the server.
37 * @param request the XML containing the RPC for the server. 38 * @param request the XML containing the RPC for the server.
38 * @return Server response or ERROR 39 * @return Server response or ERROR
39 */ 40 */
40 - String doRPC(String request); 41 + String doRPC(String request) throws IOException;
41 42
42 /** 43 /**
43 * Retrives the specified configuration. 44 * Retrives the specified configuration.
...@@ -45,7 +46,7 @@ public interface NetconfSession { ...@@ -45,7 +46,7 @@ public interface NetconfSession {
45 * @param targetConfiguration the type of configuration to retrieve. 46 * @param targetConfiguration the type of configuration to retrieve.
46 * @return specified configuration. 47 * @return specified configuration.
47 */ 48 */
48 - String getConfig(String targetConfiguration); 49 + String getConfig(String targetConfiguration) throws IOException;
49 50
50 /** 51 /**
51 * Retrives part of the specivied configuration based on the filterSchema. 52 * Retrives part of the specivied configuration based on the filterSchema.
...@@ -55,7 +56,8 @@ public interface NetconfSession { ...@@ -55,7 +56,8 @@ public interface NetconfSession {
55 * elements we are interested in 56 * elements we are interested in
56 * @return device running configuration. 57 * @return device running configuration.
57 */ 58 */
58 - String getConfig(String targetConfiguration, String configurationFilterSchema); 59 + String getConfig(String targetConfiguration, String configurationFilterSchema)
60 + throws IOException;
59 61
60 /** 62 /**
61 * Retrives part of the specified configuration based on the filterSchema. 63 * Retrives part of the specified configuration based on the filterSchema.
...@@ -64,7 +66,7 @@ public interface NetconfSession { ...@@ -64,7 +66,7 @@ public interface NetconfSession {
64 * @return true if the configuration was edited correctly 66 * @return true if the configuration was edited correctly
65 */ 67 */
66 68
67 - boolean editConfig(String newConfiguration); 69 + boolean editConfig(String newConfiguration) throws IOException;
68 70
69 /** 71 /**
70 * Copies the new configuration, an Url or a complete configuration xml tree 72 * Copies the new configuration, an Url or a complete configuration xml tree
...@@ -75,7 +77,8 @@ public interface NetconfSession { ...@@ -75,7 +77,8 @@ public interface NetconfSession {
75 * @param newConfiguration configuration to set 77 * @param newConfiguration configuration to set
76 * @return true if the configuration was copied correctly 78 * @return true if the configuration was copied correctly
77 */ 79 */
78 - boolean copyConfig(String targetConfiguration, String newConfiguration); 80 + boolean copyConfig(String targetConfiguration, String newConfiguration)
81 + throws IOException;
79 82
80 /** 83 /**
81 * Deletes part of the specified configuration based on the filterSchema. 84 * Deletes part of the specified configuration based on the filterSchema.
...@@ -83,28 +86,28 @@ public interface NetconfSession { ...@@ -83,28 +86,28 @@ public interface NetconfSession {
83 * @param targetConfiguration the name of the configuration to delete 86 * @param targetConfiguration the name of the configuration to delete
84 * @return true if the configuration was copied correctly 87 * @return true if the configuration was copied correctly
85 */ 88 */
86 - boolean deleteConfig(String targetConfiguration); 89 + boolean deleteConfig(String targetConfiguration) throws IOException;
87 90
88 /** 91 /**
89 * Locks the candidate configuration. 92 * Locks the candidate configuration.
90 * 93 *
91 * @return true if successful. 94 * @return true if successful.
92 */ 95 */
93 - boolean lock(); 96 + boolean lock() throws IOException;
94 97
95 /** 98 /**
96 * Unlocks the candidate configuration. 99 * Unlocks the candidate configuration.
97 * 100 *
98 * @return true if successful. 101 * @return true if successful.
99 */ 102 */
100 - boolean unlock(); 103 + boolean unlock() throws IOException;
101 104
102 /** 105 /**
103 * Closes the Netconf session with the device. 106 * Closes the Netconf session with the device.
104 * the first time it tries gracefully, then kills it forcefully 107 * the first time it tries gracefully, then kills it forcefully
105 * @return true if closed 108 * @return true if closed
106 */ 109 */
107 - boolean close(); 110 + boolean close() throws IOException;
108 111
109 /** 112 /**
110 * Gets the session ID of the Netconf session. 113 * Gets the session ID of the Netconf session.
......
...@@ -80,20 +80,19 @@ public class NetconfControllerImpl implements NetconfController { ...@@ -80,20 +80,19 @@ public class NetconfControllerImpl implements NetconfController {
80 80
81 @Override 81 @Override
82 public NetconfDevice getNetconfDevice(IpAddress ip, int port) { 82 public NetconfDevice getNetconfDevice(IpAddress ip, int port) {
83 - NetconfDevice device = null;
84 for (DeviceId info : netconfDeviceMap.keySet()) { 83 for (DeviceId info : netconfDeviceMap.keySet()) {
85 if (IpAddress.valueOf(info.uri().getHost()).equals(ip) && 84 if (IpAddress.valueOf(info.uri().getHost()).equals(ip) &&
86 info.uri().getPort() == port) { 85 info.uri().getPort() == port) {
87 return netconfDeviceMap.get(info); 86 return netconfDeviceMap.get(info);
88 } 87 }
89 } 88 }
90 - return device; 89 + return null;
91 } 90 }
92 91
93 @Override 92 @Override
94 public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws IOException { 93 public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws IOException {
95 if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) { 94 if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
96 - log.info("Device {} is already present"); 95 + log.warn("Device {} is already present", deviceInfo);
97 return netconfDeviceMap.get(deviceInfo.getDeviceId()); 96 return netconfDeviceMap.get(deviceInfo.getDeviceId());
98 } else { 97 } else {
99 log.info("Creating NETCONF device {}", deviceInfo); 98 log.info("Creating NETCONF device {}", deviceInfo);
...@@ -104,7 +103,7 @@ public class NetconfControllerImpl implements NetconfController { ...@@ -104,7 +103,7 @@ public class NetconfControllerImpl implements NetconfController {
104 @Override 103 @Override
105 public void removeDevice(NetconfDeviceInfo deviceInfo) { 104 public void removeDevice(NetconfDeviceInfo deviceInfo) {
106 if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) { 105 if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
107 - log.warn("Device {} is not present"); 106 + log.warn("Device {} is not present", deviceInfo);
108 } else { 107 } else {
109 stopDevice(deviceInfo); 108 stopDevice(deviceInfo);
110 } 109 }
......
...@@ -19,6 +19,8 @@ package org.onosproject.netconf.ctl; ...@@ -19,6 +19,8 @@ package org.onosproject.netconf.ctl;
19 import org.onosproject.netconf.NetconfDevice; 19 import org.onosproject.netconf.NetconfDevice;
20 import org.onosproject.netconf.NetconfDeviceInfo; 20 import org.onosproject.netconf.NetconfDeviceInfo;
21 import org.onosproject.netconf.NetconfSession; 21 import org.onosproject.netconf.NetconfSession;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
22 24
23 import java.io.IOException; 25 import java.io.IOException;
24 26
...@@ -27,10 +29,12 @@ import java.io.IOException; ...@@ -27,10 +29,12 @@ import java.io.IOException;
27 */ 29 */
28 public class NetconfDeviceImpl implements NetconfDevice { 30 public class NetconfDeviceImpl implements NetconfDevice {
29 31
32 + public static final Logger log = LoggerFactory
33 + .getLogger(NetconfSessionImpl.class);
34 +
30 private NetconfDeviceInfo netconfDeviceInfo; 35 private NetconfDeviceInfo netconfDeviceInfo;
31 private boolean deviceState = false; 36 private boolean deviceState = false;
32 private NetconfSession netconfSession; 37 private NetconfSession netconfSession;
33 - //private String config;
34 38
35 public NetconfDeviceImpl(NetconfDeviceInfo deviceInfo) throws IOException { 39 public NetconfDeviceImpl(NetconfDeviceInfo deviceInfo) throws IOException {
36 netconfDeviceInfo = deviceInfo; 40 netconfDeviceInfo = deviceInfo;
...@@ -40,7 +44,6 @@ public class NetconfDeviceImpl implements NetconfDevice { ...@@ -40,7 +44,6 @@ public class NetconfDeviceImpl implements NetconfDevice {
40 throw new IOException("Cannot create connection and session", e); 44 throw new IOException("Cannot create connection and session", e);
41 } 45 }
42 deviceState = true; 46 deviceState = true;
43 - //config = netconfSession.getConfig("running");
44 } 47 }
45 48
46 @Override 49 @Override
...@@ -56,7 +59,11 @@ public class NetconfDeviceImpl implements NetconfDevice { ...@@ -56,7 +59,11 @@ public class NetconfDeviceImpl implements NetconfDevice {
56 @Override 59 @Override
57 public void disconnect() { 60 public void disconnect() {
58 deviceState = false; 61 deviceState = false;
59 - netconfSession.close(); 62 + try {
63 + netconfSession.close();
64 + } catch (IOException e) {
65 + log.warn("Cannot communicate with the device {} ", netconfDeviceInfo);
66 + }
60 } 67 }
61 68
62 @Override 69 @Override
......
...@@ -18,6 +18,7 @@ package org.onosproject.netconf.ctl; ...@@ -18,6 +18,7 @@ package org.onosproject.netconf.ctl;
18 18
19 import ch.ethz.ssh2.Connection; 19 import ch.ethz.ssh2.Connection;
20 import ch.ethz.ssh2.Session; 20 import ch.ethz.ssh2.Session;
21 +import ch.ethz.ssh2.StreamGobbler;
21 import com.google.common.base.Preconditions; 22 import com.google.common.base.Preconditions;
22 import org.onosproject.netconf.NetconfDeviceInfo; 23 import org.onosproject.netconf.NetconfDeviceInfo;
23 import org.onosproject.netconf.NetconfSession; 24 import org.onosproject.netconf.NetconfSession;
...@@ -29,8 +30,7 @@ import java.io.IOException; ...@@ -29,8 +30,7 @@ import java.io.IOException;
29 import java.io.InputStreamReader; 30 import java.io.InputStreamReader;
30 import java.io.PrintWriter; 31 import java.io.PrintWriter;
31 import java.io.StringWriter; 32 import java.io.StringWriter;
32 -import java.util.ArrayList; 33 +import java.util.Collections;
33 -import java.util.Arrays;
34 import java.util.List; 34 import java.util.List;
35 35
36 /** 36 /**
...@@ -50,11 +50,9 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -50,11 +50,9 @@ public class NetconfSessionImpl implements NetconfSession {
50 private BufferedReader bufferReader = null; 50 private BufferedReader bufferReader = null;
51 private PrintWriter out = null; 51 private PrintWriter out = null;
52 private int messageID = 0; 52 private int messageID = 0;
53 - 53 + //TODO inject these capabilites from yang model provided by app
54 private List<String> deviceCapabilities = 54 private List<String> deviceCapabilities =
55 - new ArrayList<>( 55 + Collections.singletonList("urn:ietf:params:netconf:base:1.0");
56 - Arrays.asList("urn:ietf:params:netconf:base:1.0"));
57 -
58 private String serverCapabilities; 56 private String serverCapabilities;
59 private String endpattern = "]]>]]>"; 57 private String endpattern = "]]>]]>";
60 58
...@@ -98,8 +96,8 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -98,8 +96,8 @@ public class NetconfSessionImpl implements NetconfSession {
98 try { 96 try {
99 sshSession = netconfConnection.openSession(); 97 sshSession = netconfConnection.openSession();
100 sshSession.startSubSystem("netconf"); 98 sshSession.startSubSystem("netconf");
101 - bufferReader = new BufferedReader(new InputStreamReader( 99 + bufferReader = new BufferedReader(new InputStreamReader(new StreamGobbler(
102 - sshSession.getStdout())); 100 + sshSession.getStdout())));
103 out = new PrintWriter(sshSession.getStdin()); 101 out = new PrintWriter(sshSession.getStdin());
104 sendHello(); 102 sendHello();
105 } catch (IOException e) { 103 } catch (IOException e) {
...@@ -127,51 +125,50 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -127,51 +125,50 @@ public class NetconfSessionImpl implements NetconfSession {
127 } 125 }
128 126
129 @Override 127 @Override
130 - public String doRPC(String request) { 128 + public String doRPC(String request) throws IOException {
131 - String reply = "ERROR"; 129 + String reply = doRequest(request);
132 - try { 130 + return checkReply(reply) ? reply : "ERROR " + reply;
133 - reply = doRequest(request);
134 - if (checkReply(reply)) {
135 - return reply;
136 - } else {
137 - return "ERROR " + reply;
138 - }
139 - } catch (IOException e) {
140 - log.error("Problem in the reading from the SSH connection " + e);
141 - }
142 - return reply;
143 } 131 }
144 132
145 private String doRequest(String request) throws IOException { 133 private String doRequest(String request) throws IOException {
146 - log.info("sshState " + sshSession.getState() + "request" + request); 134 + //log.info("sshState " + sshSession.getState() + "request" + request);
135 + checkAndRestablishSession();
136 + //log.info("sshState after" + sshSession.getState());
137 + out.print(request);
138 + out.flush();
139 + messageID++;
140 + return readOne();
141 + }
142 +
143 + private void checkAndRestablishSession() throws IOException {
147 if (sshSession.getState() != 2) { 144 if (sshSession.getState() != 2) {
148 try { 145 try {
149 startSshSession(); 146 startSshSession();
150 } catch (IOException e) { 147 } catch (IOException e) {
151 log.info("the connection had to be reopened"); 148 log.info("the connection had to be reopened");
152 - startConnection(); 149 + try {
150 + startConnection();
151 + } catch (IOException e2) {
152 + log.error("No connection {} for device, exception {}", netconfConnection, e2);
153 + throw new IOException(e.getMessage());
154 + //TODO remove device from ONOS
155 + }
153 } 156 }
154 - sendHello();
155 } 157 }
156 - log.info("sshState after" + sshSession.getState());
157 - out.print(request);
158 - out.flush();
159 - messageID++;
160 - return readOne();
161 } 158 }
162 159
163 @Override 160 @Override
164 - public String get(String request) { 161 + public String get(String request) throws IOException {
165 return doRPC(request); 162 return doRPC(request);
166 } 163 }
167 164
168 @Override 165 @Override
169 - public String getConfig(String targetConfiguration) { 166 + public String getConfig(String targetConfiguration) throws IOException {
170 return getConfig(targetConfiguration, null); 167 return getConfig(targetConfiguration, null);
171 } 168 }
172 169
173 @Override 170 @Override
174 - public String getConfig(String targetConfiguration, String configurationSchema) { 171 + public String getConfig(String targetConfiguration, String configurationSchema) throws IOException {
175 StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 172 StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
176 rpc.append("<rpc message-id=\"" + messageID + "\" " 173 rpc.append("<rpc message-id=\"" + messageID + "\" "
177 + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); 174 + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
...@@ -187,30 +184,19 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -187,30 +184,19 @@ public class NetconfSessionImpl implements NetconfSession {
187 rpc.append("</get-config>\n"); 184 rpc.append("</get-config>\n");
188 rpc.append("</rpc>\n"); 185 rpc.append("</rpc>\n");
189 rpc.append(endpattern); 186 rpc.append(endpattern);
190 - String reply = null; 187 + String reply = doRequest(rpc.toString());
191 - try { 188 + return checkReply(reply) ? reply : "ERROR " + reply;
192 - reply = doRequest(rpc.toString());
193 - } catch (IOException e) {
194 - e.printStackTrace();
195 - }
196 -
197 - return checkReply(reply) ? reply : null;
198 } 189 }
199 190
200 @Override 191 @Override
201 - public boolean editConfig(String newConfiguration) { 192 + public boolean editConfig(String newConfiguration) throws IOException {
202 newConfiguration = newConfiguration + endpattern; 193 newConfiguration = newConfiguration + endpattern;
203 - String reply = null; 194 + return checkReply(doRequest(newConfiguration));
204 - try {
205 - reply = doRequest(newConfiguration);
206 - } catch (IOException e) {
207 - e.printStackTrace();
208 - }
209 - return checkReply(reply);
210 } 195 }
211 196
212 @Override 197 @Override
213 - public boolean copyConfig(String targetConfiguration, String newConfiguration) { 198 + public boolean copyConfig(String targetConfiguration, String newConfiguration)
199 + throws IOException {
214 newConfiguration = newConfiguration.trim(); 200 newConfiguration = newConfiguration.trim();
215 if (!newConfiguration.startsWith("<configuration>")) { 201 if (!newConfiguration.startsWith("<configuration>")) {
216 newConfiguration = "<configuration>" + newConfiguration 202 newConfiguration = "<configuration>" + newConfiguration
...@@ -229,18 +215,11 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -229,18 +215,11 @@ public class NetconfSessionImpl implements NetconfSession {
229 rpc.append("</copy-config>"); 215 rpc.append("</copy-config>");
230 rpc.append("</rpc>"); 216 rpc.append("</rpc>");
231 rpc.append(endpattern); 217 rpc.append(endpattern);
232 - String reply = null; 218 + return checkReply(doRequest(rpc.toString()));
233 - try {
234 - reply = doRequest(rpc.toString());
235 - } catch (IOException e) {
236 - e.printStackTrace();
237 - }
238 -
239 - return checkReply(reply);
240 } 219 }
241 220
242 @Override 221 @Override
243 - public boolean deleteConfig(String targetConfiguration) { 222 + public boolean deleteConfig(String targetConfiguration) throws IOException {
244 if (targetConfiguration.equals("running")) { 223 if (targetConfiguration.equals("running")) {
245 log.warn("Target configuration for delete operation can't be \"running\"", 224 log.warn("Target configuration for delete operation can't be \"running\"",
246 targetConfiguration); 225 targetConfiguration);
...@@ -256,18 +235,11 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -256,18 +235,11 @@ public class NetconfSessionImpl implements NetconfSession {
256 rpc.append("</delete-config>"); 235 rpc.append("</delete-config>");
257 rpc.append("</rpc>"); 236 rpc.append("</rpc>");
258 rpc.append(endpattern); 237 rpc.append(endpattern);
259 - String reply = null; 238 + return checkReply(doRequest(rpc.toString()));
260 - try {
261 - reply = doRequest(rpc.toString());
262 - } catch (IOException e) {
263 - e.printStackTrace();
264 - }
265 -
266 - return checkReply(reply);
267 } 239 }
268 240
269 @Override 241 @Override
270 - public boolean lock() { 242 + public boolean lock() throws IOException {
271 StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" " + 243 StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" " +
272 "encoding=\"UTF-8\"?>"); 244 "encoding=\"UTF-8\"?>");
273 rpc.append("<rpc>"); 245 rpc.append("<rpc>");
...@@ -278,17 +250,11 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -278,17 +250,11 @@ public class NetconfSessionImpl implements NetconfSession {
278 rpc.append("</lock>"); 250 rpc.append("</lock>");
279 rpc.append("</rpc>"); 251 rpc.append("</rpc>");
280 rpc.append(endpattern); 252 rpc.append(endpattern);
281 - String reply = null; 253 + return checkReply(doRequest(rpc.toString()));
282 - try {
283 - reply = doRequest(rpc.toString());
284 - } catch (IOException e) {
285 - e.printStackTrace();
286 - }
287 - return checkReply(reply);
288 } 254 }
289 255
290 @Override 256 @Override
291 - public boolean unlock() { 257 + public boolean unlock() throws IOException {
292 StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" " + 258 StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" " +
293 "encoding=\"UTF-8\"?>"); 259 "encoding=\"UTF-8\"?>");
294 rpc.append("<rpc>"); 260 rpc.append("<rpc>");
...@@ -299,21 +265,15 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -299,21 +265,15 @@ public class NetconfSessionImpl implements NetconfSession {
299 rpc.append("</unlock>"); 265 rpc.append("</unlock>");
300 rpc.append("</rpc>"); 266 rpc.append("</rpc>");
301 rpc.append(endpattern); 267 rpc.append(endpattern);
302 - String reply = null; 268 + return checkReply(doRequest(rpc.toString()));
303 - try {
304 - reply = doRequest(rpc.toString());
305 - } catch (IOException e) {
306 - e.printStackTrace();
307 - }
308 - return checkReply(reply);
309 } 269 }
310 270
311 @Override 271 @Override
312 - public boolean close() { 272 + public boolean close() throws IOException {
313 return close(false); 273 return close(false);
314 } 274 }
315 275
316 - private boolean close(boolean force) { 276 + private boolean close(boolean force) throws IOException {
317 StringBuilder rpc = new StringBuilder(); 277 StringBuilder rpc = new StringBuilder();
318 rpc.append("<rpc>"); 278 rpc.append("<rpc>");
319 if (force) { 279 if (force) {
...@@ -324,7 +284,7 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -324,7 +284,7 @@ public class NetconfSessionImpl implements NetconfSession {
324 rpc.append("<close-configuration/>"); 284 rpc.append("<close-configuration/>");
325 rpc.append("</rpc>"); 285 rpc.append("</rpc>");
326 rpc.append(endpattern); 286 rpc.append(endpattern);
327 - return checkReply(rpc.toString()) ? true : close(true); 287 + return checkReply(doRequest(rpc.toString())) || close(true);
328 } 288 }
329 289
330 @Override 290 @Override
......
...@@ -40,7 +40,6 @@ import org.onosproject.net.device.DeviceDescription; ...@@ -40,7 +40,6 @@ import org.onosproject.net.device.DeviceDescription;
40 import org.onosproject.net.device.DeviceProvider; 40 import org.onosproject.net.device.DeviceProvider;
41 import org.onosproject.net.device.DeviceProviderRegistry; 41 import org.onosproject.net.device.DeviceProviderRegistry;
42 import org.onosproject.net.device.DeviceProviderService; 42 import org.onosproject.net.device.DeviceProviderService;
43 -import org.onosproject.net.device.DeviceService;
44 import org.onosproject.net.provider.AbstractProvider; 43 import org.onosproject.net.provider.AbstractProvider;
45 import org.onosproject.net.provider.ProviderId; 44 import org.onosproject.net.provider.ProviderId;
46 import org.onosproject.netconf.NetconfController; 45 import org.onosproject.netconf.NetconfController;
...@@ -66,8 +65,8 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -66,8 +65,8 @@ public class NetconfDeviceProvider extends AbstractProvider
66 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 protected DeviceProviderRegistry providerRegistry; 66 protected DeviceProviderRegistry providerRegistry;
68 67
69 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 68 + // @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 - protected DeviceService deviceService; 69 +// protected DeviceService deviceService;
71 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
72 protected NetconfController controller; //where is initiated ? 71 protected NetconfController controller; //where is initiated ?
73 72
...@@ -156,7 +155,6 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -156,7 +155,6 @@ public class NetconfDeviceProvider extends AbstractProvider
156 public void deviceAdded(NetconfDeviceInfo nodeId) { 155 public void deviceAdded(NetconfDeviceInfo nodeId) {
157 Preconditions.checkNotNull(nodeId, ISNOTNULL); 156 Preconditions.checkNotNull(nodeId, ISNOTNULL);
158 DeviceId deviceId = nodeId.getDeviceId(); 157 DeviceId deviceId = nodeId.getDeviceId();
159 - //TODO filter for not netconf devices
160 //Netconf configuration object 158 //Netconf configuration object
161 ChassisId cid = new ChassisId(); 159 ChassisId cid = new ChassisId();
162 String ipAddress = nodeId.ip().toString(); 160 String ipAddress = nodeId.ip().toString();
...@@ -191,7 +189,6 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -191,7 +189,6 @@ public class NetconfDeviceProvider extends AbstractProvider
191 private void connectDevices() { 189 private void connectDevices() {
192 NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class); 190 NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class);
193 if (cfg != null) { 191 if (cfg != null) {
194 - log.info("cfg {}", cfg);
195 try { 192 try {
196 cfg.getDevicesAddresses().stream() 193 cfg.getDevicesAddresses().stream()
197 .forEach(addr -> { 194 .forEach(addr -> {
...@@ -204,8 +201,8 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -204,8 +201,8 @@ public class NetconfDeviceProvider extends AbstractProvider
204 } catch (IOException e) { 201 } catch (IOException e) {
205 log.warn("Can't connect to NETCONF " + 202 log.warn("Can't connect to NETCONF " +
206 "device on {}:{}", 203 "device on {}:{}",
207 - addr.ip(), 204 + addr.ip(),
208 - addr.port()); 205 + addr.port());
209 } 206 }
210 } 207 }
211 ); 208 );
......
...@@ -89,5 +89,4 @@ public class NetconfProviderConfig extends Config<ApplicationId> { ...@@ -89,5 +89,4 @@ public class NetconfProviderConfig extends Config<ApplicationId> {
89 } 89 }
90 } 90 }
91 91
92 -
93 } 92 }
......
1 { 1 {
2 "devices":{ 2 "devices":{
3 - "netconf:mininet@10.1.9.24:1830":{ 3 + "netconf:mininet@10.1.9.24:830":{
4 "basic":{ 4 "basic":{
5 "driver":"ovs-netconf" 5 "driver":"ovs-netconf"
6 } 6 }
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
12 "name":"mininet", 12 "name":"mininet",
13 "password":"mininet", 13 "password":"mininet",
14 "ip":"10.1.9.24", 14 "ip":"10.1.9.24",
15 - "port":1830 15 + "port":830
16 }] 16 }]
17 } 17 }
18 } 18 }
......