ONOS-4000 trimming reply from device and minor Netconf classes refactoring
Change-Id: I33a6d5cac8a2523d377c662e3ae362903d9883fb
diff --git a/drivers/netconf/src/main/resources/netconf-drivers.xml b/drivers/netconf/src/main/resources/netconf-drivers.xml
index d9930ad..6a4e2ae 100644
--- a/drivers/netconf/src/main/resources/netconf-drivers.xml
+++ b/drivers/netconf/src/main/resources/netconf-drivers.xml
@@ -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"
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/DefaultNetconfDevice.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/DefaultNetconfDevice.java
index a7b7717..7202fb7 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/DefaultNetconfDevice.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/DefaultNetconfDevice.java
@@ -32,7 +32,7 @@
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 @@
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);
}
}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
index 6634cf6..5369335 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
@@ -101,7 +101,7 @@
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 @@
Preconditions.checkArgument(isAuthenticated,
"Authentication to device {} with username " +
"{} Failed",
- deviceInfo.getDeviceId(), deviceInfo.name(),
- deviceInfo.password());
+ deviceInfo.getDeviceId(), deviceInfo.name());
startSshSession();
}
}
@@ -170,7 +169,7 @@
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 @@
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 @@
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()));
}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfStreamThread.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfStreamThread.java
index 7df7849..1ed3f39 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfStreamThread.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfStreamThread.java
@@ -161,13 +161,8 @@
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 @@
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);