Skip to content

Commit 9e0a4fa

Browse files
authored
[config][show] cli support for retrieving ber, eye-info and configuring prbs, loopback on Y-cable (sonic-net#1386)
This PR provides the support for adding CLI commands for configuring prbs, loopback and showing the BER and Eye info of the muxcable. In particular these Cli commands are supported: ` show muxcable eyeinfo <portnumber><target>` ` show muxcable berinfo <portnumber> <target>` `config muxcable prbs <portnumber> <target> <mode> <lanemap>` `config muxcable loopback <portnumber> <target> <lanemap>` #### What is the motivation for this PR? To add the support for Cli for muxcable to be utilized for configuring prbs, loopback modes and showing the ber, eye info of all the Port/Ports on a muxcable. Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
1 parent 9ac47e5 commit 9e0a4fa

File tree

5 files changed

+331
-37
lines changed

5 files changed

+331
-37
lines changed

config/muxcable.py

+72-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
7070
ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE")
7171

7272
state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE")
73-
if (state == "active" and configdb_state == "active") or (state == "standby" and configdb_state == "active") or (state == "unknown" and configdb_state == "active") :
73+
if (state == "active" and configdb_state == "active") or (state == "standby" and configdb_state == "active") or (state == "unknown" and configdb_state == "active"):
7474
if state_cfg_val == "active":
7575
# status is already active, so right back error
7676
port_status_dict[port] = 'OK'
@@ -89,7 +89,7 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
8989
# dont write anything to db, write OK to user
9090
port_status_dict[port] = 'OK'
9191

92-
elif (state == "standby" and configdb_state == "auto") or (state == "unknown" and configdb_state == "auto"):
92+
elif (state == "standby" and configdb_state == "auto") or (state == "unknown" and configdb_state == "auto"):
9393
if state_cfg_val == "active":
9494
# make the state active
9595
config_db.set_entry("MUX_CABLE", port, {"state": "active",
@@ -187,3 +187,73 @@ def mode(state, port, json_output):
187187
click.echo(tabulate(data, headers=headers))
188188

189189
sys.exit(CONFIG_SUCCESSFUL)
190+
191+
@muxcable.group(cls=clicommon.AbbreviationGroup)
192+
def prbs():
193+
"""Enable/disable PRBS mode on a port"""
194+
pass
195+
196+
@prbs.command()
197+
@click.argument('port', required=True, default=None, type=click.INT)
198+
@click.argument('target', required=True, default=None, type=click.INT)
199+
@click.argument('mode_value', required=True, default=None, type=click.INT)
200+
@click.argument('lane_map', required=True, default=None, type=click.INT)
201+
def enable(port, target, mode_value, lane_map):
202+
"""Enable PRBS mode on a port"""
203+
204+
import sonic_y_cable.y_cable
205+
res = sonic_y_cable.y_cable.enable_prbs_mode(port, target, mode_value, lane_map)
206+
if res != True:
207+
click.echo("PRBS config unsuccesful")
208+
sys.exit(CONFIG_FAIL)
209+
click.echo("PRBS config sucessful")
210+
sys.exit(CONFIG_SUCCESSFUL)
211+
212+
@prbs.command()
213+
@click.argument('port', required=True, default=None, type=click.INT)
214+
@click.argument('target', required=True, default=None, type=click.INT)
215+
def disable(port, target):
216+
"""Disable PRBS mode on a port"""
217+
218+
import sonic_y_cable.y_cable
219+
res = sonic_y_cable.y_cable.disable_prbs_mode(port, target)
220+
if res != True:
221+
click.echo("PRBS disable unsuccesful")
222+
sys.exit(CONFIG_FAIL)
223+
click.echo("PRBS disable sucessful")
224+
sys.exit(CONFIG_SUCCESSFUL)
225+
226+
@muxcable.group(cls=clicommon.AbbreviationGroup)
227+
def loopback():
228+
"""Enable/disable loopback mode on a port"""
229+
pass
230+
231+
232+
@loopback.command()
233+
@click.argument('port', required=True, default=None, type=click.INT)
234+
@click.argument('target', required=True, default=None, type=click.INT)
235+
@click.argument('lane_map', required=True, default=None, type=click.INT)
236+
def enable(port, target, lane_map):
237+
"""Enable loopback mode on a port"""
238+
239+
import sonic_y_cable.y_cable
240+
res = sonic_y_cable.y_cable.enable_loopback_mode(port, target, lane_map)
241+
if res != True:
242+
click.echo("loopback config unsuccesful")
243+
sys.exit(CONFIG_FAIL)
244+
click.echo("loopback config sucessful")
245+
sys.exit(CONFIG_SUCCESSFUL)
246+
247+
@loopback.command()
248+
@click.argument('port', required=True, default=None, type=click.INT)
249+
@click.argument('target', required=True, default=None, type=click.INT)
250+
def disable(port, target):
251+
"""Disable loopback mode on a port"""
252+
253+
import sonic_y_cable.y_cable
254+
res = sonic_y_cable.y_cable.disable_loopback_mode(port, target)
255+
if res != True:
256+
click.echo("loopback disable unsuccesful")
257+
sys.exit(CONFIG_FAIL)
258+
click.echo("loopback disable sucessful")
259+
sys.exit(CONFIG_SUCCESSFUL)

doc/Command-Reference.md

+109-2
Original file line numberDiff line numberDiff line change
@@ -4734,6 +4734,54 @@ While displaying the muxcable configuration, users can configure the following f
47344734
}
47354735
```
47364736
4737+
**show muxcable ber-info**
4738+
4739+
This command displays the ber(Bit error rate) of the port user provides on the target user provides. The target provided as an integer corresponds to actual target as.
4740+
0 -> local
4741+
1 -> tor 1
4742+
2 -> tor 2
4743+
3 -> nic
4744+
4745+
- Usage:
4746+
```
4747+
Usage: show muxcable ber-info [OPTIONS] PORT TARGET
4748+
```
4749+
4750+
4751+
- PORT required - Port number should be a valid port
4752+
- TARGET required - the actual target to get the ber info of.
4753+
4754+
- Example:
4755+
```
4756+
admin@sonic:~$ show muxcable ber-info 1 1
4757+
Lane1 Lane2
4758+
------- -------
4759+
0 0
4760+
```
4761+
4762+
**show muxcable ber-info**
4763+
4764+
This command displays the eye info in mv(milli volts) of the port user provides on the target user provides. The target provided as an integer corresponds to actual target as.
4765+
0 -> local
4766+
1 -> tor 1
4767+
2 -> tor 2
4768+
3 -> nic
4769+
4770+
- Usage:
4771+
```
4772+
Usage: show muxcable eye-info [OPTIONS] PORT TARGET
4773+
```
4774+
4775+
- PORT required - Port number should be a valid port
4776+
- TARGET required - the actual target to get the eye info of.
4777+
4778+
- Example:
4779+
```
4780+
admin@sonic:~$ show muxcable ber-info 1 1
4781+
Lane1 Lane2
4782+
------- -------
4783+
632 622
4784+
```
47374785
47384786
### Muxcable Config commands
47394787
@@ -4769,7 +4817,6 @@ While configuring the muxcable, users needs to configure the following fields fo
47694817
"Ethernet0": "OK"
47704818
}
47714819
```
4772-
47734820
```
47744821
admin@sonic:~$ sudo config muxcable mode active all
47754822
port state
@@ -4785,7 +4832,67 @@ While configuring the muxcable, users needs to configure the following fields fo
47854832
"Ethernet32": "INPROGRESS",
47864833
"Ethernet0": "OK"
47874834
}
4788-
```
4835+
```
4836+
**config muxcable prbs enable/disable**
4837+
4838+
This command is used for setting the configuration and enable/diable of prbs on a port user provides. While enabling in addition to port the user also needs to provides the target, prbs mode and lane map on which the user intends to run prbs on. The target reflects where the enable/dsiable will happen.
4839+
4840+
- Usage:
4841+
```
4842+
config muxcable prbs enable [OPTIONS] PORT TARGET MODE_VALUE LANE_MAP
4843+
config muxcable prbs disable [OPTIONS] PORT TARGET
4844+
```
4845+
4846+
While configuring the muxcable, users needs to configure the following fields for the operation
4847+
4848+
- PORT required - Port number should be a valid port
4849+
- TARGET required - the actual target to run the prbs on
4850+
0 -> local side,
4851+
1 -> TOR 1
4852+
2 -> TOR 2
4853+
3 -> NIC
4854+
- MODE_VALUE required - the mode/type for configuring the PRBS mode.
4855+
0x00 = PRBS 9, 0x01 = PRBS 15, 0x02 = PRBS 23, 0x03 = PRBS 31
4856+
- LANE_MAP required - an integer representing the lane_map to be run PRBS on
4857+
0bit for lane 0, 1bit for lane1 and so on.
4858+
for example 3 -> 0b'0011 , means running on lane0 and lane1
4859+
- Example:
4860+
```
4861+
admin@sonic:~$ sudo config muxcable prbs enable 1 1 3 3
4862+
PRBS config sucessful
4863+
admin@sonic:~$ sudo config muxcable prbs disable 1 0
4864+
PRBS disable sucessful
4865+
```
4866+
4867+
**config muxcable loopback enable/disable**
4868+
4869+
This command is used for setting the configuration and enable/disable of loopback on a port user provides. While enabling in addition to port the user also needs to provides the target and lane map on which the user intends to run loopback on. The target reflects where the enable/dsiable will happen.
4870+
4871+
- Usage:
4872+
```
4873+
config muxcable loopback enable [OPTIONS] PORT TARGET LANE_MAP
4874+
config muxcable loopback disable [OPTIONS] PORT TARGET
4875+
```
4876+
4877+
While configuring the muxcable, users needs to configure the following fields for the operation
4878+
4879+
- PORT required - Port number should be a valid port
4880+
- TARGET required - the actual target to run the loopback on
4881+
0 -> local side,
4882+
1 -> TOR 1
4883+
2 -> TOR 2
4884+
3 -> NIC
4885+
- LANE_MAP required - an integer representing the lane_map to be run loopback on
4886+
0bit for lane 0, 1bit for lane1 and so on.
4887+
for example 3 -> 0b'0011 , means running on lane0 and lane1
4888+
4889+
- Example:
4890+
```
4891+
admin@sonic:~$ sudo config muxcable loopback enable 1 1 3
4892+
loopback config sucessful
4893+
admin@sonic:~$ sudo config muxcable loopback disable 1 0
4894+
loopback disable sucessfull
4895+
```
47894896
47904897
Go Back To [Beginning of the document](#) or [Beginning of this section](#muxcable)
47914898

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
'netifaces==0.10.7',
157157
'pexpect==4.8.0',
158158
'requests==2.25.0',
159+
'sonic-platform-common',
159160
'sonic-py-common',
160161
'sonic-yang-mgmt',
161162
'swsssdk>=2.0.1',

show/muxcable.py

+45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import sys
34

45
import click
@@ -14,6 +15,8 @@
1415

1516
CONFIG_SUCCESSFUL = 101
1617
CONFIG_FAIL = 1
18+
EXIT_FAIL = 1
19+
EXIT_SUCCESS = 0
1720
STATUS_FAIL = 1
1821
STATUS_SUCCESSFUL = 102
1922

@@ -335,3 +338,45 @@ def config(port, json_output):
335338
click.echo(tabulate(print_data, headers=headers))
336339

337340
sys.exit(CONFIG_SUCCESSFUL)
341+
342+
343+
@muxcable.command()
344+
@click.argument('port', required=True, default=None, type=click.INT)
345+
@click.argument('target', required=True, default=None, type=click.INT)
346+
def berinfo(port, target):
347+
"""Show muxcable BER (bit error rate) information"""
348+
349+
if os.geteuid() != 0:
350+
click.echo("Root privileges are required for this operation")
351+
sys.exit(EXIT_FAIL)
352+
import sonic_y_cable.y_cable
353+
res = sonic_y_cable.y_cable.get_ber_info(port, target)
354+
if res == False or res == -1:
355+
click.echo("Unable to fetch ber info")
356+
sys.exit(EXIT_FAIL)
357+
headers = ['Lane1', 'Lane2', 'Lane3', 'Lane4']
358+
lane_data = []
359+
lane_data.append(res)
360+
click.echo(tabulate(lane_data, headers=headers))
361+
sys.exit(EXIT_SUCCESS)
362+
363+
364+
@muxcable.command()
365+
@click.argument('port', required=True, default=None, type=click.INT)
366+
@click.argument('target', required=True, default=None, type=click.INT)
367+
def eyeinfo(port, target):
368+
"""Show muxcable eye information in mv"""
369+
370+
if os.geteuid() != 0:
371+
click.echo("Root privileges are required for this operation")
372+
sys.exit(EXIT_FAIL)
373+
import sonic_y_cable.y_cable
374+
res = sonic_y_cable.y_cable.get_eye_info(port, target)
375+
if res == False or res == -1:
376+
click.echo("Unable to fetch eye info")
377+
sys.exit(EXIT_FAIL)
378+
headers = ['Lane1', 'Lane2', 'Lane3', 'Lane4']
379+
lane_data = []
380+
lane_data.append(res)
381+
click.echo(tabulate(lane_data, headers=headers))
382+
sys.exit(EXIT_SUCCESS)

0 commit comments

Comments
 (0)