sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
3.95k stars 931 forks source link

Can't connect to Cisco IOS XR with NetconfClient #62

Closed lafrank closed 8 years ago

lafrank commented 8 years ago

I try to connect to a Cisco IOS XR router using the below code :

      _ncClient = new NetConfClient("10.10.10.1", 830, "admin", "admin");
      _ncClient.KeepAliveInterval = TimeSpan.FromSeconds(2);
      _ncClient.OperationTimeout = TimeSpan.FromSeconds(60);
      _ncClient.ErrorOccurred += ErrorOccurred;
      _ncClient.AutomaticMessageIdHandling = false;
      _ncClient.Connect();

At first the connection seems to suceed as IsConnected is true, but a second later the ErrorOccured event is fired with a message like : "An establshed connection was aborted by the server"

This happens right after the call to_netConfSession.Connect();

I also checked that SshClient can connect to the same router with no issues, therefore I am sure the underlying SSH transport is workingcorrectly.

Also, the same router accepts Netconf sessions when I use a Python code, so the issue I guess is not related to router configuration.

I have seen some article suggesting this might be related to ClientCapabilities xml as set by NetconfSession constructor, but could not figure out whether this was the problem or not :

      ClientCapabilities.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                          "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                                              "<capabilities>" +
                                                  "<capability>" +
                                                      "urn:ietf:params:netconf:base:1.0" +
                                                  "</capability>" +
                                              "</capabilities>" +
                                          "</hello>");

Any ideas please ?

lafrank commented 8 years ago

Ok, resolved by changing the hello message to also include netconf 1.1 capability, like below :

<hello xmlns=""urn:ietf:params:xml:ns:netconf:base:1.0"">
    <capabilities>
        <capability>
            urn:ietf:params:netconf:base:1.0
        </capability>
        <capability>
            urn:ietf:params:netconf:base:1.1
        </capability>
    </capabilities>
</hello>";

Not sure of future implications or whether it is correct, but this seems working at least for now and I can also send/receive rpc requests.