tail-f-systems / JNC

JNC (Java NETCONF Client) is the name of a Java library for communicating with NETCONF agents, and a plugin for pyang (http://code.google.com/p/pyang/) to generate Java classes from YANG models, to be used by the JNC library.
Other
77 stars 87 forks source link

Session closed #141

Open tomek-jaworski-elb opened 1 year ago

tomek-jaworski-elb commented 1 year ago

Hi, I'm connecting to Cisco router successfully. After sending request to get configuration or just only simple get() during retrieving of data I receive IOEXception and session closed.

faulty method NodeSet elements = session.getConfig();

log _Caused by: java.io.IOException: Session closed at com.tailf.jnc.SSHSession$SessionDataReader.readData(SSHSession.java:138) at com.tailf.jnc.framing.NC1_1_Framer.readChunkHeader(Framer.java:144) at com.tailf.jnc.framing.NC1_1Framer.parseFrame(Framer.java:164) at com.tailf.jnc.SSHSession.readOne(SSHSession.java:258) at com.tailf.jnc.NetconfSession.recvRpcReply(NetconfSession.java:1527) at com.tailf.jnc.NetconfSession.recvRpcReplyData(NetconfSession.java:1511) at com.tailf.jnc.NetconfSession.getConfig(NetconfSession.java:460) at com.tailf.jnc.NetconfSession.getConfig(NetconfSession.java:449)

Do You have any idea how to solve this error?

Edit: This is a Netconf v1.1 issue. After checkout to branch JNC/developmnet error didn't occure.

Is it possible to use Netconf 1.1 with the JNC/master branch?

martin-volf commented 1 year ago

development has already been merged to master, and master is actually a couple of commits ahead of that now and development should have been already deleted. So whatever works in development, should work in master too.

You may want to increase the debug level - it can be done by calling the static method Element.setDebugLevel(int) early on in your code, the level ranges from 0 for no debug info up to 4. (Yes, I know, we should have implemented standard logging mechanism long ago.)

tomek-jaworski-elb commented 1 year ago

Thank you for your quick reply and debugging tip. However, the device operation on the master branch still does not work, I receive information end of input (-1) and then java.io.IOException: Session closed

Is there any solution for this issue?

martin-volf commented 1 year ago

At this point we have no clue as to where the issue is, or even if there is any, we need your help in reproducing it on our side. Are you able to get the traffic between the client and the device? The debug output with level at least 2 contains the traffic, or possibly the device logs that somewhere too.

The end of input means that the device closed the stream, you should be able to find a reason for that in device's logs too.

tomek-jaworski-elb commented 1 year ago

I have no idea how to printout a receiving stream. But I've found a place where is the issue. Incoming stream is filled by 0 and in this case method from line 134 returns -1. Attaching some code from debug mode.

image

Edit: this part of code comes from branch development works for me, but there is a difference in master branch

martin-volf commented 1 year ago

Yes, when the other side (your device in this case) closes the stream, it manifests as that the read function returns -1. Normally, the device would not close the stream on its own, it is usually the client that sends close-session and then the streams are closed on both sides, that's why I think there should be something in the device's log that would indicate why the device decided to close the stream.

As for the stream contents - as I wrote, you can get that if you add a call like

Element.setDebugLevel(2);

somewhere early in your code, possibly even into the main() method. That would cause that the traffic (and other stuff) is logged on stdout.

By the way, there was a bug in logging introduced between development and master, we have just fixed; there is a very small chance that it fixes your problem too.