From 87233a3d5ae8762470b752f530549ca1255f6f9e Mon Sep 17 00:00:00 2001 From: Marian Pritsak Date: Wed, 3 Dec 2025 06:44:20 +0200 Subject: [PATCH] Change mapping key IP to prefix Some use cases have multiplle sequential addresses mapped to the same PA. For such cases, aggregation into prefixes provides a better scale. Signed-off-by: Marian Pritsak --- dash-pipeline/SAI/specs/dash_outbound_ca_to_pa.yaml | 8 ++++---- dash-pipeline/bmv2/stages/outbound_mapping.p4 | 2 +- test/test-cases/functional/ptf/sai_dash_utils.py | 12 +++++++++++- test/test-cases/functional/ptf/saidashacl.py | 5 +++-- .../test-cases/functional/ptf/saidashdpapp_sanity.py | 11 +++++++++-- test/test-cases/functional/ptf/saidashflow.py | 5 +++-- test/test-cases/functional/ptf/saidashvnet.py | 12 ++++++------ test/test-cases/functional/ptf/saidashvnet_sanity.py | 11 +++++++++-- 8 files changed, 46 insertions(+), 20 deletions(-) diff --git a/dash-pipeline/SAI/specs/dash_outbound_ca_to_pa.yaml b/dash-pipeline/SAI/specs/dash_outbound_ca_to_pa.yaml index 1834f0ec4..171043cae 100644 --- a/dash-pipeline/SAI/specs/dash_outbound_ca_to_pa.yaml +++ b/dash-pipeline/SAI/specs/dash_outbound_ca_to_pa.yaml @@ -39,8 +39,8 @@ sai_apis: valid_only: null - !!python/object:utils.sai_spec.sai_struct_entry.SaiStructEntry name: dip - description: Exact matched key dip - type: sai_ip_address_t + description: LPM matched key dip + type: sai_ip_prefix_t objects: null valid_only: null attributes: @@ -289,8 +289,8 @@ sai_apis: - !!python/object:utils.sai_spec.sai_api_p4_meta.SaiApiP4MetaKey name: dip id: 3 - match_type: exact - field: ipaddr + match_type: lpm + field: ipPrefix bitwidth: 128 ip_is_v6_field_id: 2 is_object_key: false diff --git a/dash-pipeline/bmv2/stages/outbound_mapping.p4 b/dash-pipeline/bmv2/stages/outbound_mapping.p4 index 5f9038091..7897dd8f8 100644 --- a/dash-pipeline/bmv2/stages/outbound_mapping.p4 +++ b/dash-pipeline/bmv2/stages/outbound_mapping.p4 @@ -16,7 +16,7 @@ control outbound_mapping_stage( /* Flow for express route */ meta.dst_vnet_id: exact @SaiVal[type="sai_object_id_t"]; meta.is_lkup_dst_ip_v6 : exact @SaiVal[name = "dip_is_v6"]; - meta.lkup_dst_ip_addr : exact @SaiVal[name = "dip"]; + meta.lkup_dst_ip_addr : lpm @SaiVal[name = "dip"]; } actions = { diff --git a/test/test-cases/functional/ptf/sai_dash_utils.py b/test/test-cases/functional/ptf/sai_dash_utils.py index c203a97c0..55c8ce801 100644 --- a/test/test-cases/functional/ptf/sai_dash_utils.py +++ b/test/test-cases/functional/ptf/sai_dash_utils.py @@ -373,10 +373,20 @@ def outbound_ca_to_pa_create(self, dst_vnet_id, dip, underlay_dip, """ Create outband CA PA mapping """ + + # Ensure dip has a prefix length for LPM matching + if "/" not in dip: + # Auto-detect IPv4 vs IPv6 and add appropriate prefix + if ":" in dip: + # IPv6 address - add /128 for single host + dip = dip + "/128" + else: + # IPv4 address - add /32 for single host + dip = dip + "/32" ca_to_pa_entry = sai_thrift_outbound_ca_to_pa_entry_t(switch_id=self.switch_id, dst_vnet_id=dst_vnet_id, - dip=sai_ipaddress(dip)) + dip=sai_ipprefix(dip)) sai_thrift_create_outbound_ca_to_pa_entry(self.client, ca_to_pa_entry, action=SAI_OUTBOUND_CA_TO_PA_ENTRY_ACTION_SET_TUNNEL_MAPPING, underlay_dip=sai_ipaddress(underlay_dip), diff --git a/test/test-cases/functional/ptf/saidashacl.py b/test/test-cases/functional/ptf/saidashacl.py index 3fd48f0bb..05e6327b3 100644 --- a/test/test-cases/functional/ptf/saidashacl.py +++ b/test/test-cases/functional/ptf/saidashacl.py @@ -242,8 +242,9 @@ def setUpSwitch(self): self.create_entry(sai_thrift_create_eni_ether_address_map_entry, sai_thrift_remove_eni_ether_address_map_entry, self.eam, eni_id=self.eni) - dip = sai_thrift_ip_address_t(addr_family=SAI_IP_ADDR_FAMILY_IPV4, - addr=sai_thrift_ip_addr_t(ip4=self.dst_ca_ip)) + dip = sai_thrift_ip_prefix_t(addr_family=SAI_IP_ADDR_FAMILY_IPV4, + addr=sai_thrift_ip_addr_t(ip4=self.dst_ca_ip), + mask=sai_thrift_ip_addr_t(ip4="255.255.255.255")) ca_prefix = sai_thrift_ip_prefix_t(addr_family=SAI_IP_ADDR_FAMILY_IPV4, addr=sai_thrift_ip_addr_t( diff --git a/test/test-cases/functional/ptf/saidashdpapp_sanity.py b/test/test-cases/functional/ptf/saidashdpapp_sanity.py index a2d82668f..2dcf807ca 100644 --- a/test/test-cases/functional/ptf/saidashdpapp_sanity.py +++ b/test/test-cases/functional/ptf/saidashdpapp_sanity.py @@ -142,8 +142,15 @@ def configureVnet(self): eni_id=self.eni) assert(status == SAI_STATUS_SUCCESS) - dip = sai_thrift_ip_address_t(addr_family=self.sai_ip_addr_family, - addr=sai_thrift_ip_addr_t(**{self.ip_addr_family_attr: self.dst_ca_ip})) + # Set appropriate mask for IPv4 (/32) or IPv6 (/128) + if self.sai_ip_addr_family == SAI_IP_ADDR_FAMILY_IPV6: + mask_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + else: + mask_str = "255.255.255.255" + + dip = sai_thrift_ip_prefix_t(addr_family=self.sai_ip_addr_family, + addr=sai_thrift_ip_addr_t(**{self.ip_addr_family_attr: self.dst_ca_ip}), + mask=sai_thrift_ip_addr_t(**{self.ip_addr_family_attr: mask_str})) # TODO: Enable ACL rule for IPv6 if self.sai_ip_addr_family == SAI_IP_ADDR_FAMILY_IPV4: diff --git a/test/test-cases/functional/ptf/saidashflow.py b/test/test-cases/functional/ptf/saidashflow.py index ab3d18eb2..d8d6f3c54 100644 --- a/test/test-cases/functional/ptf/saidashflow.py +++ b/test/test-cases/functional/ptf/saidashflow.py @@ -383,8 +383,9 @@ def setUpSwitch(self): self.create_entry(sai_thrift_create_eni_ether_address_map_entry, sai_thrift_remove_eni_ether_address_map_entry, self.eam, eni_id=self.eni) - dip = sai_thrift_ip_address_t(addr_family=SAI_IP_ADDR_FAMILY_IPV4, - addr=sai_thrift_ip_addr_t(ip4=self.dst_ca_ip)) + dip = sai_thrift_ip_prefix_t(addr_family=SAI_IP_ADDR_FAMILY_IPV4, + addr=sai_thrift_ip_addr_t(ip4=self.dst_ca_ip), + mask=sai_thrift_ip_addr_t(ip4="255.255.255.255")) ca_prefix = sai_thrift_ip_prefix_t(addr_family=SAI_IP_ADDR_FAMILY_IPV4, addr=sai_thrift_ip_addr_t( diff --git a/test/test-cases/functional/ptf/saidashvnet.py b/test/test-cases/functional/ptf/saidashvnet.py index 14b882bbd..09b244b61 100644 --- a/test/test-cases/functional/ptf/saidashvnet.py +++ b/test/test-cases/functional/ptf/saidashvnet.py @@ -2635,7 +2635,7 @@ def configureTest(self): dst_vnet_id=dst_vnet_0, overlay_ip="192.168.1.111") self.outbound_ca_to_pa_create(dst_vnet_id=dst_vnet_0, - dip="192.168.1.111", + dip="192.168.1.111/32", underlay_dip=self.rx_host_0.ip, overlay_dmac=self.rx_host.client.mac, use_dst_vnet_vni=True) @@ -2645,7 +2645,7 @@ def configureTest(self): dst_vnet_id=dst_vnet_1, overlay_ip="192.168.2.222") self.outbound_ca_to_pa_create(dst_vnet_id=dst_vnet_1, - dip="192.168.2.222", + dip="192.168.2.222/32", underlay_dip=self.rx_host_1.ip, overlay_dmac=self.rx_host_1.client.mac, use_dst_vnet_vni=False) @@ -2708,7 +2708,7 @@ def configureTest(self): dst_vnet_id=dst_vnet_0, overlay_ip="bbbb::bc") self.outbound_ca_to_pa_create(dst_vnet_id=dst_vnet_0, - dip="bbbb::bc", + dip="bbbb::bc/128", underlay_dip=self.rx_host_0.ip, overlay_dmac=self.rx_host.client.mac, use_dst_vnet_vni=True) @@ -2718,7 +2718,7 @@ def configureTest(self): dst_vnet_id=dst_vnet_1, overlay_ip="cccc::bc") self.outbound_ca_to_pa_create(dst_vnet_id=dst_vnet_1, - dip="cccc::bc", + dip="cccc::bc/128", underlay_dip=self.rx_host_1.ip, overlay_dmac=self.rx_host_1.client.mac, use_dst_vnet_vni=False) @@ -3203,7 +3203,7 @@ def configureTest(self): dst_vnet_id=dst_vnet_2, overlay_ip="192.168.1.111") self.outbound_ca_to_pa_create(dst_vnet_id=dst_vnet_2, - dip="192.168.1.111", + dip="192.168.1.111/32", underlay_dip=self.rx_host_2.ip, overlay_dmac=self.rx_host_2.client.mac, use_dst_vnet_vni=True) @@ -3377,7 +3377,7 @@ def configureTest(self): dst_vnet_id=dst_vnet_2, overlay_ip="bbbb::bc") self.outbound_ca_to_pa_create(dst_vnet_id=dst_vnet_2, - dip="bbbb::bc", + dip="bbbb::bc/128", underlay_dip=self.rx_host_2.ip, overlay_dmac=self.rx_host_2.client.mac, use_dst_vnet_vni=True) diff --git a/test/test-cases/functional/ptf/saidashvnet_sanity.py b/test/test-cases/functional/ptf/saidashvnet_sanity.py index 368d8e2ec..036fcda48 100644 --- a/test/test-cases/functional/ptf/saidashvnet_sanity.py +++ b/test/test-cases/functional/ptf/saidashvnet_sanity.py @@ -136,8 +136,15 @@ def configureVnet(self): eni_id=self.eni) assert(status == SAI_STATUS_SUCCESS) - dip = sai_thrift_ip_address_t(addr_family=self.sai_ip_addr_family, - addr=sai_thrift_ip_addr_t(**{self.ip_addr_family_attr: self.dst_ca_ip})) + # Set appropriate mask for IPv4 (/32) or IPv6 (/128) + if self.sai_ip_addr_family == SAI_IP_ADDR_FAMILY_IPV6: + mask_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" + else: + mask_str = "255.255.255.255" + + dip = sai_thrift_ip_prefix_t(addr_family=self.sai_ip_addr_family, + addr=sai_thrift_ip_addr_t(**{self.ip_addr_family_attr: self.dst_ca_ip}), + mask=sai_thrift_ip_addr_t(**{self.ip_addr_family_attr: mask_str})) # TODO: Enable ACL rule for IPv6 if self.sai_ip_addr_family == SAI_IP_ADDR_FAMILY_IPV4: