cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
463
Views
0
Helpful
1
Replies

ydk-cpp How to check if NetconfServiceProvider session is open

EricMonson
Level 1
Level 1

I've searched through the documentation, forums, and code. I don't see a simple way in c++ of asking a NetconfServiceProvider if its session is currently open. When sending a command with CrudService, you get a boolean back stating whether the command succeeded or failed, but you don't know if it was due to a connection issue, or a malformed request.

 

It appears that if the connection is not valid, a YClientError exception is thrown with an error message. However, I'd rather not parse the error message as a mechanism to see if the issue was due to a closed connection since that error message could in the future change (and in fact it really should change as the message contains a double negative "Cannot not execute playload")

 

Is there a mechanism that I'm not seeing to check if the NetconfServiceProvider's session is currently believed to be active, or known to be closed?

 

Edit:

I'll add one more thought. I noticed that NetconfSession contains a method called "check_session_state". The problem is that it is not a const function. "get_session" returns a const Session& object, so dynamic casting it to a NetconfSession and calling check_session_state doesn't work.

 

auto& session = provider->get_session();
auto netconf_session = dynamic_cast<const ydk::path::NetconfSession*>(&session);
netconf_session->check_session_state();         # Compiler error

 

 

1 Accepted Solution

Accepted Solutions

yangorelik
Spotlight
Spotlight

Hi Eric

The check_session_state() function is used internally. However it is not reliable way to check status of connection, because the netconf client does not implement 'I am alive' protocol, like TCP does, and retains status of the SSH channel after the last transaction. The connectivity break can be detected only during transaction. When this happens, the client develops a system signal, which is then caught in the YDK code and YDK exception is thrown. When this happens, the instances of NetconfSession and NeconfServiceProvider classes got destroyed and further their use will create segmentation fault signal. Therefore it is strongly recommended to enclose any calls for NetconfSession or NetconfServiceProvider in try-catch conditions. There is not need to check status of the session, because it is kept alive until it is automatically closed.

Yan Gorelik
YDK Solutions

View solution in original post

1 Reply 1

yangorelik
Spotlight
Spotlight

Hi Eric

The check_session_state() function is used internally. However it is not reliable way to check status of connection, because the netconf client does not implement 'I am alive' protocol, like TCP does, and retains status of the SSH channel after the last transaction. The connectivity break can be detected only during transaction. When this happens, the client develops a system signal, which is then caught in the YDK code and YDK exception is thrown. When this happens, the instances of NetconfSession and NeconfServiceProvider classes got destroyed and further their use will create segmentation fault signal. Therefore it is strongly recommended to enclose any calls for NetconfSession or NetconfServiceProvider in try-catch conditions. There is not need to check status of the session, because it is kept alive until it is automatically closed.

Yan Gorelik
YDK Solutions
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: