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 ECMP calculator tool #12482

Merged
merged 18 commits into from
Dec 4, 2022
Merged

Add ECMP calculator tool #12482

merged 18 commits into from
Dec 4, 2022

Conversation

liorghub
Copy link
Contributor

@liorghub liorghub commented Oct 25, 2022

This PR must be merged after PR #12840

Why I did it

Added ECMP calculator tool.

How I did it

New files were added.

How to verify it

Manual tests performed according to tests chapter in HLD
Automated tests will be added by verification.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

Description for the changelog

Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@liorghub liorghub requested a review from lguohan as a code owner October 25, 2022 03:47
@liorghub liorghub marked this pull request as draft October 25, 2022 03:48
@lgtm-com
Copy link

lgtm-com bot commented Oct 25, 2022

This pull request introduces 1 alert when merging b53de67 into a0661e2 - view on LGTM.com

new alerts:

  • 1 for Unused import

@liat-grozovik liat-grozovik requested a review from prsunny October 30, 2022 07:57
@dprital dprital requested a review from nazariig October 30, 2022 11:18
@lgtm-com
Copy link

lgtm-com bot commented Oct 31, 2022

This pull request introduces 4 alerts when merging d97f5c0 into 6bed69a - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Oct 31, 2022

This pull request introduces 1 alert when merging 5b6d48c into 6bed69a - view on LGTM.com

new alerts:

  • 1 for Unused import

@liat-grozovik
Copy link
Collaborator

@liorghub is this PR ready for review? anything else is missing?

@liorghub
Copy link
Contributor Author

liorghub commented Nov 8, 2022

@liat-grozovik No, this PR is not ready for review. Rest of the code is ready and reviewed internally, I will publish it once I will get verification approval.

@liorghub liorghub changed the title Add ECMP calculator SDK module Add ECMP calculator tool Nov 9, 2022
@liorghub
Copy link
Contributor Author

liorghub commented Nov 9, 2022

@liat-grozovik
PR was updated and now contains all the code, however, it is marked as draft.
When verification will approve I will remove the draft.

@nazariig
Can you please approve?

@liat-grozovik
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liorghub
Copy link
Contributor Author

liorghub commented Nov 15, 2022

@liat-grozovik Compilation is failing since SDK does not contain hash calculator debian. PR Add SDK hash calculator debian to SONiC Bullseye should be merged to fix it.

Build log error:

cp: cannot stat 'platform/mellanox/sdk-src/sx-kernel/Switch-SDK-drivers/bin//bullseye/amd64//sx-hash-calc_1.mlnx.4.5.3186_amd64.deb': No such file or directory

delete_uint32_t_p(entries_cnt_p)
delete_sx_ip_prefix_t_p(ip_prefix_p)

def sx_router_operational_ecmp_get(handle, ecmp_id):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this API to something like sx_router_ecmp_get_nexthops?

Copy link
Contributor Author

@liorghub liorghub Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, API name changed.

delete_sx_router_id_t_p(vrid_p)

def sx_port_vport_base_get(handle, vport):
""" Get SDK logical index for given vport
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logical index and Vlan?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I updated function documentation.

handle (sx_api_handle_t): SDK handle
rif (sx_port_id_t): SDK vport id
addr (sx_ip_addr_t): Neighbour IP address
type_ipv6 (bool): True for IPv6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type_ipv6 is not used. Please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable type_ipv6 was removed.

@@ -70,4 +71,10 @@ RUN mkdir -p /etc/supervisor/conf.d/
RUN sonic-cfggen -a "{\"ENABLE_ASAN\":\"{{ENABLE_ASAN}}\"}" -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
RUN rm -f /usr/share/sonic/templates/supervisord.conf.j2

RUN mkdir -p /usr/bin/ecmp_calculator
COPY ["ecmp_calculator/ecmp_calc_sdk.py", "/usr/bin/ecmp_calculator"]
COPY ["ecmp_calculator/ecmp_calc.py", "/usr/bin/ecmp_calculator"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from ecmp_calc.py other files are not binaries but libraries.Can we package them accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def validate_inner_header(self):
inner_header = None
try:
inner_header = self.packet['packet_info']['inner']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead we could do something like inner_header = self.packet['packet_info'].get('inner') instead of doing try except. get will return None if there is no such key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code to use get().

if ip in header and is_ip_valid(header[ip], IP_VERSION_IPV6) == False:
raise ValueError("Json validation failed: invalid IP {}".format(header[ip]))

def validate_layer2_header(self, header):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ethertype, vlan and other L2 fields be validated as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By design, Ethertype, vlan and other L2 fields are being validated for their types only.
Each field is defined in PACKET_SCHEME as a number or as a string and validation is being performed using python3-jsonschema module.


raise ValueError("VRF validation failed: VRF {} does not exist".format(self.user_vrf))

def get_ecmp_ids(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_ecmp_id* since we will get only one per route

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function name changed to get_ecmp_id().

log_cb_fn = log_cb_type(log_cb)
handle_p = ctypes.pointer(ctypes.c_int64())

rc = sx_api.sx_api_open(log_cb_fn, handle_p)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During cleanup before the application exits can we invoke sx_api_close?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added call to sx_api_close() in destructor.

@liorghub
Copy link
Contributor Author

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 12482 in repo sonic-net/sonic-buildimage

@liorghub
Copy link
Contributor Author

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

lane_index = get_lane_index(lane_bmap, ASIC_MAX_LANES[chip_type])
assert lane_index != -1, "Failed to calculate port index"

sonic_index = label_port * ASIC_MAX_LANES[chip_type] + lane_index;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if label port start from 1 or 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Label port is the port number printed on the front panel minus one.
On ACS-MSN3700C with 32 ports, first label port is 0 and last is 31 (total of 32 as expected).

out = exec_cmd([HASH_CALC_PATH, '-c', HASH_CALC_INPUT_FILE, '-o', HASH_CALC_OUTPUT_FILE, '-d'])
self.debug_print ("Hash calculator output:\n{}".format(out))

with open(HASH_CALC_OUTPUT_FILE, 'r') as openfile:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to delete the file after using it. There is no delete for this file

Copy link
Contributor Author

@liorghub liorghub Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added call to temporary files cleanup in destructor.

@liorghub liorghub marked this pull request as ready for review November 29, 2022 15:50
@liat-grozovik liat-grozovik merged commit e580802 into sonic-net:master Dec 4, 2022
StormLiangMS pushed a commit to StormLiangMS/sonic-buildimage that referenced this pull request Dec 8, 2022
…compile it (sonic-net#12840)

- Why I did it
Add SDK hash calculator Debian and update SDK makefile to compile it.

- How I did it
SDK hash calculator Debian will be used by ECMP calculator (PR sonic-net#12482)

- How to verify it
Compile sonic-buildimage and verify SDK hash calculator Debian exist in target folder.
StormLiangMS pushed a commit that referenced this pull request Dec 10, 2022
…compile it (#12840)

- Why I did it
Add SDK hash calculator Debian and update SDK makefile to compile it.

- How I did it
SDK hash calculator Debian will be used by ECMP calculator (PR #12482)

- How to verify it
Compile sonic-buildimage and verify SDK hash calculator Debian exist in target folder.
mssonicbld pushed a commit to mssonicbld/sonic-buildimage that referenced this pull request Jan 8, 2023
- Why I did it
Added ECMP calculator tool.

- How I did it
New files were added.

- How to verify it
Manual tests performed according to tests chapter in HLD
Automated tests will be added by verification.
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202211: #13301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants