/* * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: LicenseRef-NvidiaProprietary * * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual * property and proprietary rights in and to this material, related * documentation and any modifications thereto. Any use, reproduction, * disclosure or distribution of this material and related documentation * without an express license agreement from NVIDIA CORPORATION or * its affiliates is strictly prohibited. */ #include #include #include #include #define ECMP_BUCKETS 16 struct usermeta_t { bit<4> ecmp_select; }; control c( inout nv_headers_t headers, in nv_standard_metadata_t std_meta, inout usermeta_t user_meta, inout nv_empty_metadata_t pkt_out_meta ) { // Create a hash object with the selected algorithm NvHash(NvHashAlgorithm.CRC32) hash; action drop() { nv_drop(); } action next_hop( nv_mac_addr_t dmac, nv_ipv4_addr_t ipv4, nv_logical_port_t port ) { headers.ethernet.dst_addr = dmac; headers.ipv4.dst_addr = ipv4; headers.ipv4.ttl -= 1; nv_send_to_port(port); } table ecmp_group { key = { headers.ipv4.dst_addr: lpm; } actions = { drop; NoAction; } default_action = drop; size = 1024; } table ecmp_nhop { key = { user_meta.ecmp_select: exact; } actions = { drop; next_hop; } default_action = drop; size = ECMP_BUCKETS; } apply { if (headers.ipv4.isValid() && std_meta.is_l4_ok == 1 && headers.ipv4.ttl != 0) { ecmp_group.apply(); user_meta.ecmp_select = (bit<4>)hash.get_hash( ECMP_BUCKETS, // size { headers.ipv4.src_addr, headers.ipv4.dst_addr, headers.ipv4.protocol, std_meta.l4_src_port, std_meta.l4_dst_port } ); ecmp_nhop.apply(); } } } NvDocaPipeline( nv_fixed_parser(), c() ) main;