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 @@
-->
<drivers>
<!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB-->
<driver name="ovs-netconf" extends="default,ovs"
manufacturer="" hwVersion="" swVersion="">
<driver name="ovs-netconf" manufacturer="" hwVersion="" swVersion="">
<behaviour api="org.onosproject.net.behaviour.ControllerConfig"
impl="org.onosproject.drivers.netconf.NetconfControllerConfig"/>
<behaviour api="org.onosproject.net.behaviour.ConfigGetter"
......@@ -25,7 +24,7 @@
<behaviour api="org.onosproject.net.behaviour.ConfigSetter"
impl="org.onosproject.drivers.netconf.NetconfConfigSetter"/>
</driver>
<driver name="netconf" extends="default">
<driver name="netconf" manufacturer="" hwVersion="" swVersion="">
<behaviour api="org.onosproject.net.behaviour.ConfigGetter"
impl="org.onosproject.drivers.netconf.NetconfConfigGetter"/>
<behaviour api="org.onosproject.net.behaviour.ConfigSetter"
......
......@@ -32,7 +32,7 @@ import java.io.IOException;
public class DefaultNetconfDevice implements NetconfDevice {
public static final Logger log = LoggerFactory
.getLogger(NetconfSessionImpl.class);
.getLogger(DefaultNetconfDevice.class);
private NetconfDeviceInfo netconfDeviceInfo;
private boolean deviceState = false;
......@@ -75,7 +75,7 @@ public class DefaultNetconfDevice implements NetconfDevice {
try {
netconfSession.close();
} catch (IOException e) {
log.warn("Cannot communicate with the device {} ", netconfDeviceInfo);
log.warn("Cannot communicate with the device {} session already closed", netconfDeviceInfo);
}
}
......
......@@ -101,7 +101,7 @@ public class NetconfSessionImpl implements NetconfSession {
deviceInfo.password());
} else {
log.debug("Authenticating to device {} with username {}",
deviceInfo.getDeviceId(), deviceInfo.name(), deviceInfo.password());
deviceInfo.getDeviceId(), deviceInfo.name());
isAuthenticated = netconfConnection.authenticateWithPassword(
deviceInfo.name(), deviceInfo.password());
}
......@@ -117,8 +117,7 @@ public class NetconfSessionImpl implements NetconfSession {
Preconditions.checkArgument(isAuthenticated,
"Authentication to device {} with username " +
"{} Failed",
deviceInfo.getDeviceId(), deviceInfo.name(),
deviceInfo.password());
deviceInfo.getDeviceId(), deviceInfo.name());
startSshSession();
}
}
......@@ -170,7 +169,7 @@ public class NetconfSessionImpl implements NetconfSession {
try {
startConnection();
} catch (IOException e2) {
log.error("No connection {} for device, exception {}", netconfConnection, e2);
log.error("No connection {} for device", netconfConnection, e2);
throw new NetconfException("Cannot re-open the connection with device" + deviceInfo, e);
}
}
......@@ -206,7 +205,7 @@ public class NetconfSessionImpl implements NetconfSession {
throw new NetconfException("No matching reply for request " + request, e);
}
log.debug("Result {} from request {} to device {}", rp, request, deviceInfo);
return rp;
return rp.trim();
}
private String formatRequestMessageId(String request) {
......@@ -284,19 +283,20 @@ public class NetconfSessionImpl implements NetconfSession {
rpc.append(messageIdInteger.get());
rpc.append("\" ");
rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
rpc.append("<edit-config>");
rpc.append("<edit-config>\n");
rpc.append("<target>");
rpc.append("<").append(targetConfiguration).append("/>");
rpc.append("</target>");
rpc.append("</target>\n");
rpc.append("<default-operation>");
rpc.append(mode);
rpc.append("</default-operation>");
rpc.append("<config>");
rpc.append("</default-operation>\n");
rpc.append("<config>\n");
rpc.append(newConfiguration);
rpc.append("</config>");
rpc.append("</edit-config>");
rpc.append("</config>\n");
rpc.append("</edit-config>\n");
rpc.append("</rpc>");
rpc.append(ENDPATTERN);
log.info(rpc.toString());
return checkReply(sendRequest(rpc.toString()));
}
......
......@@ -161,13 +161,8 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
while (!socketClosed) {
int cInt = bufferReader.read();
if (cInt == -1) {
socketClosed = true;
log.debug("char {} " + bufferReader.read());
NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent(
NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED,
null, null, Optional.of(-1), netconfDeviceInfo);
netconfDeviceEventListeners.forEach(
listener -> listener.event(event));
log.debug("Netconf device {} sent error char in session," +
" will need to be reopend", netconfDeviceInfo);
}
char c = (char) cInt;
state = state.evaluateChar(c);
......@@ -175,6 +170,7 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
if (state == NetconfMessageState.END_PATTERN) {
String deviceReply = deviceReplyBuilder.toString();
if (deviceReply.equals(END_PATTERN)) {
socketClosed = true;
NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent(
NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED,
null, null, Optional.of(-1), netconfDeviceInfo);
......