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

Add CLI command for ECMP calculator #2538

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
33 changes: 33 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
PLATFORM_JSON = 'platform.json'
HWSKU_JSON = 'hwsku.json'
PORT_STR = "Ethernet"
ECMP_CALC = '/usr/bin/ecmp_calc.py'
CONTAINER_NAME = 'syncd'

VLAN_SUB_INTERFACE_SEPARATOR = '.'

Expand Down Expand Up @@ -1033,6 +1035,37 @@ def fib(ipaddress, verbose):
cmd += " -ip {}".format(ipaddress)
run_command(cmd, display_cmd=verbose)

#
# 'ecmp-egress-port' subcommand ("show ip ecmp-egress-port...")
#

@ip.command()
@click.option('--packet', '-p', required=True, help="Json file describing a packet")
@click.option('--ingress-port', '-i', required=True, help="Ingress port")
@click.option('--vrf', '-v', required=False, help="VRF name")
@click.option('--debug', '-d', required=False, is_flag=True, help="Run in debug mode")
def ecmp_egress_port(packet, ingress_port, vrf, debug):
"""Show egress port for given packet"""

# Check if ECMP calculaor is implemented
proc = subprocess.run(['docker', 'exec', '-it', CONTAINER_NAME, 'test', '-f', ECMP_CALC])
if proc.returncode != 0:
click.echo("ECMP calculator is not available in this image")
return

# Copy packet JSON to syncd
cmd = "docker cp {} {}:/".format(packet, CONTAINER_NAME)
run_command(cmd)

# Call ECMP calculaor
packet = os.path.basename(packet)
cmd = "docker exec {} {} --packet {} --interface {}".format(CONTAINER_NAME, ECMP_CALC, packet, ingress_port)
if vrf is not None:
cmd += " --vrf {}".format(vrf)
if debug is True:
cmd += " --debug"
run_command(cmd, display_cmd=debug)


#
# 'ipv6' group ("show ipv6 ...")
Expand Down