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

[dpu_tty]: Add a DPU TTY console utility #3535

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* [Console config commands](#console-config-commands)
* [Console connect commands](#console-connect-commands)
* [Console clear commands](#console-clear-commands)
* [DPU serial console utility](#dpu-serial-console-utility)
* [CMIS firmware upgrade](#cmis-firmware-upgrade)
* [CMIS firmware version show commands](#cmis-firmware-version-show-commands)
* [CMIS firmware upgrade commands](#cmis-firmware-upgrade-commands)
Expand Down Expand Up @@ -229,6 +230,7 @@

| Version | Modification Date | Details |
| --- | --- | --- |
| v9 | Sep-19-2024 | Add DPU serial console utility |
| v8 | Oct-09-2023 | Add CMIS firmware upgrade commands |
| v7 | Jun-22-2023 | Add static DNS show and config commands |
| v6 | May-06-2021 | Add SNMP show and config commands |
Expand Down Expand Up @@ -2825,7 +2827,7 @@ Optionally, you can display configured console ports only by specifying the `-b`
1 9600 Enabled - - switch1
```

## Console config commands
### Console config commands

This sub-section explains the list of configuration options available for console management module.

Expand Down Expand Up @@ -3001,6 +3003,88 @@ Optionally, you can clear with a remote device name by specifying the `-d` or `-

Go Back To [Beginning of the document](#) or [Beginning of this section](#console)

### DPU serial console utility

**dpu-tty.py**

This command allows user to connect to a DPU serial console via TTY device with
interactive CLI program: picocom. The configuration is from platform.json. The
utility works only on smart switch that provides DPU UART connections through
/dev/ttyS* devices.

- Usage:
```
dpu-tty.py (-n|--name) <DPU_NAME> [(-b|-baud) <BAUD_RATE>] [(-t|-tty) <TTY>]
```

- Example:
```
root@MtFuji:/home/cisco# dpu-tty.py -n dpu0
picocom v3.1

port is : /dev/ttyS4
flowcontrol : none
baudrate is : 115200
parity is : none
databits are : 8
stopbits are : 1
escape is : C-a
local echo is : no
noinit is : no
noreset is : no
hangup is : no
nolock is : no
send_cmd is : sz -vv
receive_cmd is : rz -vv -E
imap is :
omap is :
emap is : crcrlf,delbs,
logfile is : none
initstring : none
exit_after is : not set
exit is : no

Type [C-a] [C-h] to see available commands
Terminal ready

sonic login: admin
Password:
Linux sonic 6.1.0-11-2-arm64 #1 SMP Debian 6.1.38-4 (2023-08-08) aarch64
You are on
____ ___ _ _ _ ____
/ ___| / _ \| \ | (_)/ ___|
\___ \| | | | \| | | |
___) | |_| | |\ | | |___
|____/ \___/|_| \_|_|\____|

-- Software for Open Networking in the Cloud --

Unauthorized access and/or use are prohibited.
All access and/or use are subject to monitoring.

Help: https://sonic-net.github.io/SONiC/

Last login: Mon Sep 9 21:39:44 UTC 2024 on ttyS0
admin@sonic:~$
Terminating...
Thanks for using picocom
root@MtFuji:/home/cisco#
```

Optionally, user may overwrite baud rate for experiment.

- Example:
```
root@MtFuji:/home/cisco# dpu-tty.py -n dpu1 -b 9600
```

Optionally, user may overwrite TTY device for experiment.

- Example:
```
root@MtFuji:/home/cisco# dpu-tty.py -n dpu2 -t ttyS4
```

## CMIS firmware upgrade

### CMIS firmware version show commands
Expand Down
73 changes: 73 additions & 0 deletions scripts/dpu-tty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
#
# Copyright (c) 2024 Cisco Systems, Inc.
#

import argparse
import json
import os
import subprocess
from sonic_py_common import device_info

UART_CON = '/usr/bin/picocom'


def get_dpu_tty(dpu, tty, baud):

platform = device_info.get_platform()
if not platform:
print("No platform")
return None

# Get platform path.
platform_path = device_info.get_path_to_platform_dir()

if os.path.isfile(os.path.join(platform_path, device_info.PLATFORM_JSON_FILE)):
json_file = os.path.join(platform_path, device_info.PLATFORM_JSON_FILE)

try:
with open(json_file, 'r') as file:
platform_data = json.load(file)
except (json.JSONDecodeError, IOError, TypeError, ValueError):
print("No platform.json")
return None

dpus = platform_data.get('DPUS', None)
if dpus is None:
print("No DPUs in platform.json")
return None

if tty is None:
dev = dpus[dpu]["serial-console"]["device"]
else:
# overwrite tty device in platform.json
dev = tty

if baud is None:
baud = dpus[dpu]["serial-console"]["baud-rate"]
return dev, baud


def main():

parser = argparse.ArgumentParser(description='DPU TTY Console Utility')
parser.add_argument('-n', '--name', required=True)
parser.add_argument('-t', '--tty')
parser.add_argument('-b', '--baud')
args = parser.parse_args()

dpu_tty, dpu_baud = get_dpu_tty(args.name, args.tty, args.baud)
# Use UART console utility for error checking of dpu_tty and dpu_baud.

p = subprocess.run([UART_CON, '-b', dpu_baud, '/dev/%s' % dpu_tty])
if p.returncode:
print('{} failed'.format(p.args))
if p.stdout:
print(p.stdout)
if p.stderr:
print(p.stderr)
return p.returncode


if __name__ == "__main__":
exit(main())
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
'scripts/decode-syseeprom',
'scripts/dropcheck',
'scripts/disk_check.py',
'scripts/dpu-tty.py',
'scripts/dropconfig',
'scripts/dropstat',
'scripts/dualtor_neighbor_check.py',
Expand Down
Loading