CiscoXrBase: Reduce the time duration for session preparation
See original GitHub issuenetmiko: 3.2.0 Cisco XR: 7.0.1
[Problem Description]
It takes long time (approx. 4.7 secs) until a new session preparation is completed by ConnectHandler(). I think this issue is not specific to CiscoXrBase but also applicable to other platforms calling BaseConnection::_test_channel_read() method.
I’d like to reduce this time duration and I could improve the behavior by my local patch, but I have a question before submitting a pull request.
netconn = ConnectHandler(**device)
Please see the below CiscoXr syslog and netmiko logger for details.
- CiscoXr (syslog)
The below CiscoXr syslog says SSH connection itself is established at 19:12:15.922
.
RP/0/RP0/CPU0:2020 Aug 14 19:12:15.922 JST: SSHD_[68443]: %SECURITY-SSHD-6-INFO_SUCCESS : Successfully authenticated user 'cisco' from '10.71.38.195' on 'vty3'(cipher 'aes128-ctr', mac 'hmac-sha2-256')
- netmiko (logger)
The below netmiko logger says session_preparation() is completed at around 19:12:20.676
, which means it took about 4.754 secs
after a SSH connection is established.
2020-08-14 19:12:17.171 [ DEBUG] read_channel:
RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:17.273 [ DEBUG] read_channel:
2020-08-14 19:12:19.276 [ DEBUG] read_channel:
2020-08-14 19:12:19.381 [ DEBUG] read_channel:
2020-08-14 19:12:19.382 [ DEBUG] write_channel: b'\n'
2020-08-14 19:12:19.488 [ DEBUG] read_channel:
RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:19.696 [ DEBUG] read_channel:
2020-08-14 19:12:19.697 [ DEBUG] [find_prompt()]: prompt is RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:19.902 [ DEBUG] read_channel:
2020-08-14 19:12:19.903 [ DEBUG] In disable_paging
2020-08-14 19:12:19.904 [ DEBUG] Command: terminal length 0
2020-08-14 19:12:19.905 [ DEBUG] write_channel: b'terminal length 0\n'
2020-08-14 19:12:19.906 [ DEBUG] Pattern is: RP/0/RP0/CPU0:NCS\-5501c\-ME04
2020-08-14 19:12:19.931 [ DEBUG] _read_channel_expect read_data: terminal length 0
2020-08-14 19:12:20.033 [ DEBUG] _read_channel_expect read_data: Fri Aug 14 19:12:19.798 JST
2020-08-14 19:12:20.138 [ DEBUG] _read_channel_expect read_data: RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:20.138 [ DEBUG] Pattern found: RP/0/RP0/CPU0:NCS\-5501c\-ME04 terminal length 0
Fri Aug 14 19:12:19.798 JST
RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:20.139 [ DEBUG] terminal length 0
Fri Aug 14 19:12:19.798 JST
RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:20.140 [ DEBUG] Exiting disable_paging
2020-08-14 19:12:20.141 [ DEBUG] write_channel: b'terminal width 511\n'
2020-08-14 19:12:20.142 [ DEBUG] Pattern is: RP/0/RP0/CPU0:NCS\-5501c\-ME04
2020-08-14 19:12:20.160 [ DEBUG] _read_channel_expect read_data: terminal width 511
2020-08-14 19:12:20.265 [ DEBUG] _read_channel_expect read_data: Fri Aug 14 19:12:20.025 JST
RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:20.266 [ DEBUG] Pattern found: RP/0/RP0/CPU0:NCS\-5501c\-ME04 terminal width 511
Fri Aug 14 19:12:20.025 JST
RP/0/RP0/CPU0:NCS-5501c-ME04#
2020-08-14 19:12:20.676 [ DEBUG] read_channel:
[Troubleshoot]
class CiscoXrBase(CiscoBaseConnection):
def establish_connection(self):
"""Establish SSH connection to the network device"""
super().establish_connection(width=511, height=511)
def session_preparation(self):
"""Prepare the session after the connection has been established."""
self._test_channel_read()
self.set_base_prompt()
self.disable_paging()
self.set_terminal_width(command="terminal width 511")
# Clear the read buffer
time.sleep(0.3 * self.global_delay_factor)
self.clear_buffer()
After some code trace and experiment, I found the time duration could be reduced by the following enhancement.
- disable_paging() and set_terminal_width() can be removed when we calls establish_connection(width=511, height=0)
- _test_channel_read() always takes about 2 secs+ due to extra sleep(final_delay * delay_factor) in _read_channel_timing().
- _test_channel_read() can be replaced by read_until_pattern() with regular expression for CiscoXr prompt.
- set_base_prompt() can be removed if we set a prompt string directly to self.base_prompt.
[Question]
Would you think if it’s ok for now to improve the behavior in CiscoXrBase only, even though this might be a common issue?
If yes, I’m going to submit a pull request only for CiscoXrBase changes.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
@ktbyers
Thank you for your comments. That would be great if both
_test_channel_read()
and extra sleep beforeclear_buffer()
could be removed.I modified the patch like above and verified it could also reduce the time duration a lot. Please see the below logs for details.
Regarding the above XR7 (new IOS-XR software architecture), I checked with the XR code base and SSH server implementation seems to be same as other XR architectures (Evolved XR 64bit and Classic XR 32bit). I also verified the below control was also working well with Cisco 8000 in my local lab. It’s not required anymore in this discussion, though.
Thanks, Taisuke
Develop branch should have new performance improvements for IOS-XR.