Andrea Campanella
Committed by Gerrit Code Review

ONOS-4000 trimming reply from device and minor Netconf classes refactoring

Change-Id: I33a6d5cac8a2523d377c662e3ae362903d9883fb
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
16 --> 16 -->
17 <drivers> 17 <drivers>
18 <!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB--> 18 <!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB-->
19 - <driver name="ovs-netconf" extends="default,ovs" 19 + <driver name="ovs-netconf" manufacturer="" hwVersion="" swVersion="">
20 - manufacturer="" hwVersion="" swVersion="">
21 <behaviour api="org.onosproject.net.behaviour.ControllerConfig" 20 <behaviour api="org.onosproject.net.behaviour.ControllerConfig"
22 impl="org.onosproject.drivers.netconf.NetconfControllerConfig"/> 21 impl="org.onosproject.drivers.netconf.NetconfControllerConfig"/>
23 <behaviour api="org.onosproject.net.behaviour.ConfigGetter" 22 <behaviour api="org.onosproject.net.behaviour.ConfigGetter"
...@@ -25,7 +24,7 @@ ...@@ -25,7 +24,7 @@
25 <behaviour api="org.onosproject.net.behaviour.ConfigSetter" 24 <behaviour api="org.onosproject.net.behaviour.ConfigSetter"
26 impl="org.onosproject.drivers.netconf.NetconfConfigSetter"/> 25 impl="org.onosproject.drivers.netconf.NetconfConfigSetter"/>
27 </driver> 26 </driver>
28 - <driver name="netconf" extends="default"> 27 + <driver name="netconf" manufacturer="" hwVersion="" swVersion="">
29 <behaviour api="org.onosproject.net.behaviour.ConfigGetter" 28 <behaviour api="org.onosproject.net.behaviour.ConfigGetter"
30 impl="org.onosproject.drivers.netconf.NetconfConfigGetter"/> 29 impl="org.onosproject.drivers.netconf.NetconfConfigGetter"/>
31 <behaviour api="org.onosproject.net.behaviour.ConfigSetter" 30 <behaviour api="org.onosproject.net.behaviour.ConfigSetter"
......
...@@ -32,7 +32,7 @@ import java.io.IOException; ...@@ -32,7 +32,7 @@ import java.io.IOException;
32 public class DefaultNetconfDevice implements NetconfDevice { 32 public class DefaultNetconfDevice implements NetconfDevice {
33 33
34 public static final Logger log = LoggerFactory 34 public static final Logger log = LoggerFactory
35 - .getLogger(NetconfSessionImpl.class); 35 + .getLogger(DefaultNetconfDevice.class);
36 36
37 private NetconfDeviceInfo netconfDeviceInfo; 37 private NetconfDeviceInfo netconfDeviceInfo;
38 private boolean deviceState = false; 38 private boolean deviceState = false;
...@@ -75,7 +75,7 @@ public class DefaultNetconfDevice implements NetconfDevice { ...@@ -75,7 +75,7 @@ public class DefaultNetconfDevice implements NetconfDevice {
75 try { 75 try {
76 netconfSession.close(); 76 netconfSession.close();
77 } catch (IOException e) { 77 } catch (IOException e) {
78 - log.warn("Cannot communicate with the device {} ", netconfDeviceInfo); 78 + log.warn("Cannot communicate with the device {} session already closed", netconfDeviceInfo);
79 } 79 }
80 } 80 }
81 81
......
...@@ -101,7 +101,7 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -101,7 +101,7 @@ public class NetconfSessionImpl implements NetconfSession {
101 deviceInfo.password()); 101 deviceInfo.password());
102 } else { 102 } else {
103 log.debug("Authenticating to device {} with username {}", 103 log.debug("Authenticating to device {} with username {}",
104 - deviceInfo.getDeviceId(), deviceInfo.name(), deviceInfo.password()); 104 + deviceInfo.getDeviceId(), deviceInfo.name());
105 isAuthenticated = netconfConnection.authenticateWithPassword( 105 isAuthenticated = netconfConnection.authenticateWithPassword(
106 deviceInfo.name(), deviceInfo.password()); 106 deviceInfo.name(), deviceInfo.password());
107 } 107 }
...@@ -117,8 +117,7 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -117,8 +117,7 @@ public class NetconfSessionImpl implements NetconfSession {
117 Preconditions.checkArgument(isAuthenticated, 117 Preconditions.checkArgument(isAuthenticated,
118 "Authentication to device {} with username " + 118 "Authentication to device {} with username " +
119 "{} Failed", 119 "{} Failed",
120 - deviceInfo.getDeviceId(), deviceInfo.name(), 120 + deviceInfo.getDeviceId(), deviceInfo.name());
121 - deviceInfo.password());
122 startSshSession(); 121 startSshSession();
123 } 122 }
124 } 123 }
...@@ -170,7 +169,7 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -170,7 +169,7 @@ public class NetconfSessionImpl implements NetconfSession {
170 try { 169 try {
171 startConnection(); 170 startConnection();
172 } catch (IOException e2) { 171 } catch (IOException e2) {
173 - log.error("No connection {} for device, exception {}", netconfConnection, e2); 172 + log.error("No connection {} for device", netconfConnection, e2);
174 throw new NetconfException("Cannot re-open the connection with device" + deviceInfo, e); 173 throw new NetconfException("Cannot re-open the connection with device" + deviceInfo, e);
175 } 174 }
176 } 175 }
...@@ -206,7 +205,7 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -206,7 +205,7 @@ public class NetconfSessionImpl implements NetconfSession {
206 throw new NetconfException("No matching reply for request " + request, e); 205 throw new NetconfException("No matching reply for request " + request, e);
207 } 206 }
208 log.debug("Result {} from request {} to device {}", rp, request, deviceInfo); 207 log.debug("Result {} from request {} to device {}", rp, request, deviceInfo);
209 - return rp; 208 + return rp.trim();
210 } 209 }
211 210
212 private String formatRequestMessageId(String request) { 211 private String formatRequestMessageId(String request) {
...@@ -284,19 +283,20 @@ public class NetconfSessionImpl implements NetconfSession { ...@@ -284,19 +283,20 @@ public class NetconfSessionImpl implements NetconfSession {
284 rpc.append(messageIdInteger.get()); 283 rpc.append(messageIdInteger.get());
285 rpc.append("\" "); 284 rpc.append("\" ");
286 rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); 285 rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
287 - rpc.append("<edit-config>"); 286 + rpc.append("<edit-config>\n");
288 rpc.append("<target>"); 287 rpc.append("<target>");
289 rpc.append("<").append(targetConfiguration).append("/>"); 288 rpc.append("<").append(targetConfiguration).append("/>");
290 - rpc.append("</target>"); 289 + rpc.append("</target>\n");
291 rpc.append("<default-operation>"); 290 rpc.append("<default-operation>");
292 rpc.append(mode); 291 rpc.append(mode);
293 - rpc.append("</default-operation>"); 292 + rpc.append("</default-operation>\n");
294 - rpc.append("<config>"); 293 + rpc.append("<config>\n");
295 rpc.append(newConfiguration); 294 rpc.append(newConfiguration);
296 - rpc.append("</config>"); 295 + rpc.append("</config>\n");
297 - rpc.append("</edit-config>"); 296 + rpc.append("</edit-config>\n");
298 rpc.append("</rpc>"); 297 rpc.append("</rpc>");
299 rpc.append(ENDPATTERN); 298 rpc.append(ENDPATTERN);
299 + log.info(rpc.toString());
300 return checkReply(sendRequest(rpc.toString())); 300 return checkReply(sendRequest(rpc.toString()));
301 } 301 }
302 302
......
...@@ -161,13 +161,8 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler ...@@ -161,13 +161,8 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
161 while (!socketClosed) { 161 while (!socketClosed) {
162 int cInt = bufferReader.read(); 162 int cInt = bufferReader.read();
163 if (cInt == -1) { 163 if (cInt == -1) {
164 - socketClosed = true; 164 + log.debug("Netconf device {} sent error char in session," +
165 - log.debug("char {} " + bufferReader.read()); 165 + " will need to be reopend", netconfDeviceInfo);
166 - NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent(
167 - NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED,
168 - null, null, Optional.of(-1), netconfDeviceInfo);
169 - netconfDeviceEventListeners.forEach(
170 - listener -> listener.event(event));
171 } 166 }
172 char c = (char) cInt; 167 char c = (char) cInt;
173 state = state.evaluateChar(c); 168 state = state.evaluateChar(c);
...@@ -175,6 +170,7 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler ...@@ -175,6 +170,7 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
175 if (state == NetconfMessageState.END_PATTERN) { 170 if (state == NetconfMessageState.END_PATTERN) {
176 String deviceReply = deviceReplyBuilder.toString(); 171 String deviceReply = deviceReplyBuilder.toString();
177 if (deviceReply.equals(END_PATTERN)) { 172 if (deviceReply.equals(END_PATTERN)) {
173 + socketClosed = true;
178 NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent( 174 NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent(
179 NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED, 175 NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED,
180 null, null, Optional.of(-1), netconfDeviceInfo); 176 null, null, Optional.of(-1), netconfDeviceInfo);
......