Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New session creation is failing #139

Open
bndeshpande opened this issue Jul 13, 2023 · 24 comments
Open

New session creation is failing #139

bndeshpande opened this issue Jul 13, 2023 · 24 comments

Comments

@bndeshpande
Copy link

Hi Team,

Facing issue some times create new session to confd is failing before push the config using below api.

String sessionName = IP + "" + VNF_TYPE +""+"CP";
NetconfSession session = null;
try {
session = device.getSession(sessionName);
if(session == null) {
device.newSession(sessionName); // Here it will throw exception.
}
}catch(Exception e) {
device.newSession(sessionName); // then here as well.
}

What could be the reason?

@jomiklos
Copy link
Contributor

it's hard to guess without any logs/error - why don't you write what specific exception/error message you see?

@bndeshpande
Copy link
Author

Hi @jomiklos ,
Getting below exception for the above try to create newSession.

Exception occured : null java.lang.NullPointerException
at com.tailf.jnc.Device.getConnData(Device.java:550)
at com.tailf.jnc.Device.newSession(Device.java:466)
at com.tailf.jnc.Device.newSession(Device.java:453)

@martin-volf
Copy link
Contributor

This is because you need to have an active connection to that device, i.e. you need to call one of Device.connect methods before calling Device.newSession.

@bndeshpande
Copy link
Author

Actually we will be checking the one initially created Device object is null or not. If not null we will be using that device object to call newSession even then we facing above issue.

@martin-volf
Copy link
Contributor

martin-volf commented Aug 4, 2023

So as to start a NETCONF session you need to have a Device instance, obviously, but you also need to establish a SSH connection to the actual device. In the 0-intro example the sequence (minus some error handling) is like

String emsUserName = "bobby";
duser = new DeviceUser(emsUserName, "admin", "admin");
dev = new Device("mydev", duser, "localhost", 2022);
dev.connect(emsUserName, 0, false);
dev.newSession("cfg");

I suspect you are missing an equivalent of the fourth line, i.e. the dev.connect(...) call.

@bndeshpande
Copy link
Author

Okay, I am facing issue in close the opened new session.
NetConfSession se = device.getSession("cfg");

if(device!=null) {
device.closeSession("cfg")
}
java.lang.IndexOutOfBoundsException: Index: 13, Size: 12
at java.util.ArrayList.rangeCheck(ArrayList.java:659)
at java.util.ArrayList.remove(ArrayList.java:498)
at com.tailf.jnc.Device.removeConnData(Device.java:570)
at com.tailf.jnc.Device.closeSession(Device.java:296)

@martin-volf
Copy link
Contributor

You seem to be using quite old JNC version, can you migrate to the latest one?

@bndeshpande
Copy link
Author

Hi @martin-volf , could you please suggest what is the latest JNC version and what is the fix for above issue?

@martin-volf
Copy link
Contributor

You can fetch/clone the recent code from this repository, or use a Maven repository. Please refer to the top-level README file for more details.
It is possible that there was a bug in the old version that has been fixed since then, or that certain use cases did not work, I am not able to tell right now. You would make it a lot simpler for us to pinpoint the problem if you update to a more recent version.

@bndeshpande
Copy link
Author

Hi @martin-volf , from the code base I could not find pom.xml to build using maven. It has only gradle. Could you please share me link where can download with maven supported?

@martin-volf
Copy link
Contributor

It does not support Maven per se, i.e. you cannot build the library using mvn; but if you are using it for your project, have a look at the example gradle build file - just point Maven to use the repository url mentioned there and use the artifact (group com.tailf.jnc, artifact-id JNC, version 1.1.0). What is not supported on Maven though is automatic (re)generation of classes from YANG modules, you have to do that "manually" as before.

@bndeshpande
Copy link
Author

bndeshpande commented Jan 23, 2024

Hi @martin-volf/ Team ,
As suggested have taken latest JNC and tried to connect incoming connection using Device instance getting below exceptions :

Please help to resolve the same.
The code snippet to connect device is as below :

String emsUserName = "bobby";
String ip = socket.getInetAddress().getHostAddress();
duser = new DeviceUser(emsUserName, "admin", "admin");
dev = new Device(ip, duser, ip, socket.getPort());
dev.connect(emsUserName, 10, false); // here unable to connect the device.

java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:68)
at com.tailf.jnc.SSHConnection.connect(SSHConnection.java:110)
at com.tailf.jnc.SSHConnection.connect(SSHConnection.java:81)
at com.tailf.jnc.Device.connect(Device.java:392)
at com.tailf.jnc.Device.connect(Device.java:365)

@bndeshpande
Copy link
Author

Hi @martin-volf ,
With new JNC trying to connect confd 7.1 version it is stuck in connect method itself and it is not connecting. Please help on this here, what could be the issue?

@martin-volf
Copy link
Contributor

You wrote at several places that you are using the new call-home feature; if that's the case, you should not call Device.connect(), the device is already connected when waitForCallHome() finishes. Call-home should be used like this:

du = new DeviceUser("bob", "admin", "admin");
dev = new Device.CallHome("confd").waitForCallHome();
dev.addUser(du);
dev.authenticate("bob");

(A side note: confd-7.1 is 5 years old, is that indeed your best option?)

@bndeshpande
Copy link
Author

bndeshpande commented Mar 13, 2024

Hi @martin-volf ,

You wrote at several places that you are using the new call-home feature;
Yes we are using Device.connect method which is working as expected.

if that's the case, you should not call Device.connect(), the device is already connected when waitForCallHome() finishes. Call-home should be used like this:

du = new DeviceUser("bob", "admin", "admin");
dev = new Device.CallHome("confd").waitForCallHome();
dev.addUser(du);
dev.authenticate("bob");

I have used above code where it got stuck in waitForCallHome() method itself its not coming out. How can I add loggers in JNC code and which can enable in spring boot application?

(A side note: confd-7.1 is 5 years old, is that indeed your best option?)
Yes as of now no plans to upgrade confd. Please suggest is new JNC compatible with confd 7.1?

@martin-volf
Copy link
Contributor

The method waitForCallHome() waits till the device "calls home", i.e. connects to the call-home port, by default 4334. With ConfD you can make it "call home" using maapi_netconf_ssh_call_home function or with the confd_cmd tool as in

$ confd_cmd -c "netconf_ssh_call_home 127.0.0.1 4334"

You need this only if the device is not accessible from the host where the client is running, e.g. if the device is behind a firewall or a NAT gateway.

As for compatibility - yes, the protocol is NETCONF, so I would not expect incompatibility issues with confd-7.1.

@bndeshpande
Copy link
Author

Hi @martin-volf ,

The method waitForCallHome() waits till the device "calls home", i.e. connects to the call-home port, by default 4334. With ConfD you can make it "call home" using maapi_netconf_ssh_call_home function or with the confd_cmd tool as in

$ confd_cmd -c "netconf_ssh_call_home 10.10.10.10 4334"
You need this only if the device is not accessible from the host where the client is running, e.g. if the device is behind a firewall or a NAT gateway.

We have spring boot application. Where our application act as server keeps listening on 4334 call home port. There is another application where it has confd from that above command will be trigger with our application IP. So when we run below command in our application pod.

netstat -anpt | grep 4334
tcp6 0 0 :::4334 :::* LISTEN 43827/java
tcp6 23 0 10.10.10.10:4334 10.10.10.20:51618 ESTABLISHED 43827/java

So how to handle this case. Since waitForCallHome() internally connect to 4334 but call home established on 51618 port. Seems due to this code is stuck on waitForCallHome() method itself it is not coming out. The other side confd application expecting our application needs to accept call home and complete subscriptions withing 5 sec other wise it keeps sending one more call home with diff port. Please help on this to further proceed.

@martin-volf
Copy link
Contributor

There may be multiple reasons for this, we may need to investigate more, but let me first ask you - what version of the SSHJ library are you using, how do you integrate it?

@bndeshpande
Copy link
Author

bndeshpande commented Mar 14, 2024

Below is the version of SSHJ added in pom.xml of JNC-master do I need to add same dependency in my spring boot as well?

com.hierynomus sshj 0.36.0

@martin-volf
Copy link
Contributor

That is likely the problem. This SSHJ release does not support call-home feature. The support has been implemented and merged to the SSHJ master branch, but it has not been released yet. So as to use the feature, you need to build SSHJ from the source and use that, or perhaps make a fork and do a release to your own Maven repo or something like that, I'm by far not a Maven expert.

@bndeshpande
Copy link
Author

Can you please share SSHJ master branch url here to download source to compile and use of that jar in our application.

@martin-volf
Copy link
Contributor

Ah, of course: https://github.com/hierynomus/sshj

It uses gradle, so you should be able to get a jar with gradle jar given a gradle installation.

@bndeshpande
Copy link
Author

@martin-volf ,

I have downloaded sshj code from above link compiled it and used sshj jar in both JNC as well as my spring boot application but still same issue. Below is code used where it still stuck in Device.CallHome method only its not printing next log message . Here I have overridden new method of Device.CallHome accept both incoming ip address with its port to connect the call home. Please help further.

log.error("Before device.callhome.waitForCallhome");
device = new Device.CallHome(IPAddressUtil.convertIPV6LongToShort(soc.getInetAddress().getHostAddress())).waitForCallHome(IPAddressUtil.convertIPV6LongToShort(soc.getInetAddress().getHostAddress()),soc.getPort());
log.error("After device.callhome.waitForCallhome");
log.error("Before adduser");
device.addUser(deviceUser);
log.error("Before authenticate user");
device.authenticate(localUserName);

@martin-volf
Copy link
Contributor

Can you test it without modifications? Please understand, it is very difficult to provide any support when you are using a number of unspecified modifications to the library code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants