diff --git a/doc/SAI-Proposal-Prefix-Compression.md b/doc/SAI-Proposal-Prefix-Compression.md new file mode 100644 index 000000000..48ad6d837 --- /dev/null +++ b/doc/SAI-Proposal-Prefix-Compression.md @@ -0,0 +1,425 @@ +# Prefix Compression # +------------------------------------------------------------------------------- + Title | Prefix Compression +-------------|----------------------------------------------------------------- + Authors | Nader Shinouda, Cisco + Status | In review + Type | Standards track + Created | 2024-07-1 - Initial Draft + SAI-Version | 1.16 +------------------------------------------------------------------------------- + + +## 1.0 Introduction ## + +This specification introduces Prefix Compression, which enables the mapping of an IP prefix/mask (longest prefix) to a meta-data value. These prefix/meta-data mappings can be grouped to form a prefix compression table. These tables can include both IPv4 and IPv6 entries. + +Prefix compression tables can be utilized in features such as ACL to match specific meta fields, thereby enhancing the functionality of ACLs or any other feature that can benefit from these groupings. + +## 1.1.0 Function Requirement of Prefix Compression +- Enable the creation of a prefix compresison table as a SAI object +- Enable adding IPV4/IPV6 Prefix mapping to a META value + +## 2.0 Specification ## + +Specficicaton covers prefix compression and ACL use of Prefix Compression + +## 2.1 Prefix Compression + +A prefix compression table is represented by an object of type SAI_PREFIX_COMPRESSION_TABLE. Creating this object allocates an empty table to which specific entries can be added later. The table creation process requires associating a stage with the table and specifying the type of table being created: source addresses, destination addresses, or both. + +### sai.h ### +New type SAI_API_PREFIX_COMPRESSION is added into sai_api_t + +### saiobject.h ### +New entry sai_prefix_compression_entry_t prefix_compression_entry. + +### saitypes.h ### +Two new types: SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE and SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY + +### New Header saiprefixcompression.h ### + +#### sai_prefix_compression_table_attr_t #### +This defines the prefix compression attributes table + +Tables are composed of prefix compression entries. These entries map a specific IP prefix to a meta data value. Both IPV4 and IPV6 entries can be added to the same table. During table creation a stage must be set to the table (Ingress/Egress) + +```c +typedef enum _sai_prefix_compression_table_attr_t +{ + /** + * @brief Start of attributes + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_START, + + /** + * @brief Label attribute used to unique identify Table. + * + * @type char + * @flags CREATE_AND_SET + * @default "" + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_LABEL = SAI_PREFIX_COMPRESSION_TABLE_ATTR_START, + + /** + * @brief Prefix Compression table stage + * + * @type sai_prefix_compression_stage_t + * @flags MANDATORY_ON_CREATE | CREATE_ONLY + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_PREFIX_COMPRESSION_STAGE, + + /** + * @brief Prefix Compression table type + * + * @type sai_prefix_compression_type_t + * @flags MANDATORY_ON_CREATE | CREATE_ONLY + * @isresourcetype true + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_PREFIX_COMPRESSION_TYPE, + +``` + +#### sai_prefix_compression_entry_attr_t #### + +Attributes structure for prefix compression entries + +```c + /** + * @brief Attribute Id for SAI prefix compression object + */ + typedef enum _sai_prefix_compression_entry_attr_t + { + /** + * @brief Start of attributes + */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_START, + + /** + * @brief Prefix Compression entry META data + * + * @type sai_uint32_t + * @flags MANDATORY_ON_CREATE | CREATE_AND_SET + */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_META = SAI_PREFIX_COMPRESSION_ENTRY_ATTR_START, +``` + +#### sai_prefix_compression_entry_t #### + +This structure defines a prefix compression entry. A prefix compression entry is composed of switch ID, a table ID that the entry will be added to and a IP prefix + +```c +typedef struct _sai_prefix_compression_entry_t +{ + /** + * @brief Switch ID + * + * @objects SAI_OBJECT_TYPE_SWITCH + */ + sai_object_id_t switch_id; + + /** + * @brief Prefix Compression Table ID + * + * @objects SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE + */ + sai_object_id_t prefix_table_id; + + /** + * @brief IP Prefix Destination + */ + sai_ip_prefix_t prefix; +``` + +#### sai_create_prefix_compression_table_fn #### +This defines the interface to create prefix compression table + +- prefix_compression_table_id (Out): Prefix Compression table object ID +- switch_id (In): The ID of the switch on which the ICMP ECHO session is to be created. +- attr_count (In): The number of attributes provided in the attr_list. +- attr_list (In): An array of sai_attribute_t structures containing the attribute key-value pairs to configure the ICMP ECHO session. + +#### sai_remove_prefix_compression_table_fn #### +The function takes a Prefix Compression object ID as a parameter. The function returns SAI_STATUS_SUCCESS if the operation is successful; otherwise, it returns a different error code indicating the nature of the failure. + +#### sai_set_prefix_compression_table_attribute_fn #### +This defines the interfaces to update prefix compression table. It requires the unique identifier prefix_compression_table_id, and the attr parameter represents the attribute to be set along with its value. The function returns SAI_STATUS_SUCCESS if the operation is successful; otherwise, it returns an error code, indicating the nature of the failure. + +#### sai_get_prefix_compression_table_attribute_fn #### +It takes the unique identifier prefix_compression_table_id to specify the Prefix Compression table for which attributes are to be retrieved. The attr_count parameter indicates the number of attributes in the attr_list, and the attr_list itself holds the values of the requested attributes. + +#### sai_create_prefix_compression_entry_fn #### +This defines the interface to create prefix compression entry + +- prefix_compression_entry (In): Prefix Compression table object ID +- attr_count (In): The number of attributes provided in the attr_list. +- attr_list (In): An array of sai_attribute_t structures containing the attribute key-value pairs to configure the ICMP ECHO session. + +#### sai_set_prefix_compression_entry_attribute_fn #### +This defines the interfaces to update prefix compression entry. It takes the entry to be modified, and the attr parameter represents the attribute to be set along with its value. The function returns SAI_STATUS_SUCCESS if the operation is successful; otherwise, it returns an error code, indicating the nature of the failure. + +#### sai_get_prefix_compression_entry_attribute_fn #### +It takes a specific entry that will be used to reterive information about the entry. The attr_count parameter indicates the number of attributes in the attr_list, and the attr_list itself holds the values of the requested attributes. + +#### sai_bulk_create_prefix_compression_entry_fn #### +This defines a bulk entry create API that is used to create multiple entries at once. This API takes: +- object_count (In): Number of objects to create +- prefix_compression_entry (In): List of object to create +- attr_count (In): List of attr_count. Caller passes the number of attribute for each object to create. +- attr_list (In): List of attributes for every object. +- mode (In): Bulk operation error handling mode. +- object_statuses (Out): List of status for every object. Caller needs to allocate the buffer + +#### sai_bulk_remove_prefix_compression_entry_fn #### +This defines a bulk remove of entries in a prefix compression table: +- object_count (In): Number of objects to remove +- prefix_compression_entry (In): List of objects to remove +- mode (In): Bulk operation error handling mode. +- object_statuses (Out): List of status for every object. Caller needs to allocate the buffer + +#### sai_prefix_compression_api_t #### +```c +typedef struct _sai_prefix_compression_api_t +{ + sai_create_prefix_compression_table_fn create_prefix_compression_table; + sai_remove_prefix_compression_table_fn remove_prefix_compression_table; + sai_set_prefix_compression_table_attribute_fn set_prefix_compression_table_attribute; + sai_get_prefix_compression_table_attribute_fn get_prefix_compression_table_attribute; + sai_create_prefix_compression_entry_fn create_prefix_compression_entry; + sai_remove_prefix_compression_entry_fn remove_prefix_compression_entry; + sai_set_prefix_compression_entry_attribute_fn set_prefix_compression_entry_attribute; + sai_get_prefix_compression_entry_attribute_fn get_prefix_compression_entry_attribute; + sai_bulk_create_prefix_compression_entry_fn create_prefix_compression_entries; + sai_bulk_remove_prefix_compression_entry_fn remove_prefix_compression_entries; +} sai_prefix_compression_api_t; +``` + +## 2.2 ACL with Prefix Compression + +Enhanced support for meta-data field matching in ACL. New table attributes enable the configuration of source and destination prefix compression tables during the creation of an ACL table. Additionally, new field entry attributes allow matching on specific meta-data from either the source or destination prefix tables. + + +```c + /** + * @brief SRC prefix Table Object ID + * + * An object pointer to a prefix table used for + * source prefix lookups + * + * @type sai_object_id_t + * @flags CREATE_ONLY + * @objects SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE + * @allownull true + * @default SAI_NULL_OBJECT_ID + */ + SAI_ACL_TABLE_ATTR_SRC_PREFIX_COMPRESSION_TABLE, + /** + * @brief DST prefix Table Object ID + * + * An object pointer to a prefix table used for + * destination prefix lookups + * + * @type sai_object_id_t + * @flags CREATE_ONLY + * @objects SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE + * @allownull true + * @default SAI_NULL_OBJECT_ID + */ + SAI_ACL_TABLE_ATTR_DST_PREFIX_COMPRESSION_TABLE, +``` + +New field entry attributes allow for lookups based on a meta-data value. + +```c + /** + * @brief SRC meta-data + * + * @type sai_acl_field_data_t sai_uint32_t + * @flags CREATE_AND_SET + * @default disabled + */ + SAI_ACL_ENTRY_ATTR_FIELD_SRC_PREFIX_META = SAI_ACL_ENTRY_ATTR_FIELD_START + 0x15b, + + /** + * @brief DST meta-data + * + * @type sai_acl_field_data_t sai_uint32_t + * @flags CREATE_AND_SET + * @default disabled + */ + SAI_ACL_ENTRY_ATTR_FIELD_DST_PREFIX_META = SAI_ACL_ENTRY_ATTR_FIELD_START + 0x15c, +``` + +## 2.2.1 Prefix Compression packet pipeline + +New table attributes allow for the configuration of both source and destination prefix compression tables, which are used in field matching. The prefix compression SAI object ID is stored within the ACL table. An ACL table can be configured to use different prefix compression tables for the source and destination or the same table for both. This flexibility extends to different ACL tables as well, permitting the reuse of the same prefix compression table across multiple ACL tables or the creation of unique tables for each specific ACL table. + +During meta-data entry lookup in an ACL, the packet derives the associated prefix compression table from the ACL table configuration, either using SAI_ACL_TABLE_ATTR_SRC_PREFIX_COMPRESSION_TABLE or SAI_ACL_TABLE_ATTR_DST_PREFIX_COMPRESSION_TABLE. There is no match criteria to derive the source or destination compression tables; this is not an action. Subsequently, a lookup is performed on either the source or destination compression table, resulting in a "metadata" value. This "metadata" is then used as match criteria for the ACL entry, determining a hit or miss. Standard ACL actions for a hit or miss will then take effect. + +In a typical pipeline, an entire table is not usually derived from another table. Instead, entries are created in another table based on specific lookup criteria. However, this should not pose an issue in this instance, as we are leveraging the stages of an ACL tables/groups. In hardware, there is no direct derivation from ACL tables. Instead, there is an inherent pipeline behavior where the prefix compression table lookup always precedes the ACL table lookup. This sequence ensures that the metadata from the compression table is available for matching in the ACL table. + +Example: Two prefix compression tables, Table_1 and Table_2, are created. ACL Table_1 is then configured with the attributes SAI_ACL_TABLE_ATTR_SRC_PREFIX_COMPRESSION_TABLE set to Prefix Compression Table_1 and SAI_ACL_TABLE_ATTR_DST_PREFIX_COMPRESSION_TABLE set to Prefix Compression Table_2. Under ACL Table_1, two entries are created. Entry_1 references metadata from Prefix Compression Table_1, and Entry_2 references metadata from Prefix Compression Table_2. During the pipeline process for Entry_1, the ID of Prefix Compression Table_1 is dereferenced from ACL Table_1. there is not a result of an action. A lookup is performed on Prefix Compression Table_1, which is a separate table in the pipeline. The result of this lookup determines whether Entry_1 hits or misses in the ACL. The same process applies to Entry_2, with the lookup performed in Prefix Compression Table_2. + +## 3 Examples + +## 3.0.1 Create Prefix Compression Table with entries + +```c +// Create Prefix Compression Table 1 +sai_attr_table_list[]; +sai_attr_table_list[0].id = SAI_ACL_TABLE_ATTR_PREFIX_COMPRESSION_STAGE; +sai_attr_table_list[0].value.s32 = SAI_PREFIX_COMPRESSION_STAGE_INGRESS; +sai_attr_table_list[0].id = SAI_PREFIX_COMPRESSION_TABLE_ATTR_PREFIX_COMPRESSION_TYPE; +sai_attr_table_list[0].value.s32 = SAI_PREFIX_COMPRESSION_TYPE_SRC; + +attr_table_count = 0; +sai_create_prefix_compression_table_fn( + &src_prefix_compression_table_id, + switch_id, + attr_table_count, + sai_attr_table_list); + +// Create Prefix Compression Table 2 +sai_attr_table_list[]; +sai_attr_table_list[0].id = SAI_ACL_TABLE_ATTR_PREFIX_COMPRESSION_STAGE; +sai_attr_table_list[0].value.s32 = SAI_PREFIX_COMPRESSION_STAGE_INGRESS; +sai_attr_table_list[0].id = SAI_PREFIX_COMPRESSION_TABLE_ATTR_PREFIX_COMPRESSION_TYPE; +sai_attr_table_list[0].value.s32 = SAI_PREFIX_COMPRESSION_TYPE_DST; + +attr_table_count = 0; +sai_create_prefix_compression_table_fn( + &dst_prefix_compression_table_id, + switch_id, + attr_table_count, + sai_attr_table_list); + +// Example: Create Prefix Compression Entries in SRC table +// IPV4 First Entry +sai_prefix_compression_entry_t entry_v4_1; +entry_v4_1.switch_id = switch_id; +entry_v4_1.prefix_table_id = src_prefix_compression_table_id; +entry_v4_1.prefix.addr_family = SAI_IP_ADDR_FAMILY_IPV4; +entry_v4_1.prefix.addr.ipv4 = "1.1.1.1"; +entry_v4_1.prefix_mask.ipv4 = "255.255.255.0"; +sai_entry_list[0].id = SAI_PREFIX_COMPRESSION_ENTRY_ATTR_META; +sai_entry_list[0].value.u32 = 2; + +// IPV4 Second Entry +sai_prefix_compression_entry_t entry_v4_2; +entry_v4_2.switch_id = switch_id; +entry_v4_2.prefix_table_id = src_prefix_compression_table_id; +entry_v4_2.prefix.addr_family = SAI_IP_ADDR_FAMILY_IPV4; +entry_v4_2.prefix.addr.ipv4 = "2.2.2.1"; +entry_v4_2.prefix_mask.ipv4 = "255.255.255.0"; +sai_entries_attribute_list[0].id = SAI_PREFIX_COMPRESSION_ENTRY_ATTR_META; +sai_entries_attribute_list[0].value.u32 = 800; + +// IPV6 Entry +sai_prefix_compression_entry_t entry_v6_1; +entry_v6_1.switch_id = switch_id; +entry_v6_1.prefix_table_id = src_prefix_compression_table_id; +entry_v6_1.prefix.addr_family = SAI_IP_ADDR_FAMILY_IPV6; +entry_v6_1.prefix.addr.ipv4 ="2001:1::4"; +entry_v6_1.prefix_mask = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc"; +sai_entries_attribute_list[1].id = SAI_PREFIX_COMPRESSION_ENTRY_ATTR_META; +sai_entries_attribute_list[1].value.u32 = 4; + + +// Example: Create Prefix Compression Entries in DST table +// IPV4 Entry +sai_prefix_compression_entry_t entry_v4_3; +entry_v4_3.switch_id = switch_id; +entry_v4_3.prefix_table_id = dst_prefix_compression_table_id; +entry_v4_3.prefix.addr_family = SAI_IP_ADDR_FAMILY_IPV4; +entry_v4_3.prefix.addr.ipv4 = "12.12.1.1"; +entry_v4_3.prefix_mask.ipv4 = "255.255.0.0"; +sai_entry_list[0].id = SAI_PREFIX_COMPRESSION_ENTRY_ATTR_META; +sai_entry_list[0].value.u32 = 200; + +entries_list = [entry_v4_2, entry_v6_1, entry_v4_3]; +entries_list_size = 2; +sai_status_t bulk_status; + +// Adding a single entry to a table +sai_attr_list_count = 1; +sai_create_prefix_compression_entry_fn( + entry_v4_1, + sai_attr_list, + sai_attr_list_count); + +// Adding using bulk add +attr_entries_count = 2; +sai_bulk_create_prefix_compression_entry_fn( + entries_list_size, + entries_list, + attr_entries_count, + sai_entries_attribute_list, + SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, + bulk_status); + +// Example of using Prefix Compression with ACL +// Create ACL table +sai_table_attr_list[0].id = SAI_ACL_TABLE_ATTR_SRC_PREFIX_COMPRESSION_TABLE; +sai_table_attr_list[0].value.oid = src_prefix_compression_table_id; +sai_table_attr_list[0].id = SAI_ACL_TABLE_ATTR_DST_PREFIX_COMPRESSION_TABLE; +sai_table_attr_list[0].value.oid = dst_prefix_compression_table_id; +sai_table_attr_count = 1; + +sai_create_acl_table_fn( + &acl_table_id, + switch_id, + sai_table_attr_count, + sai_table_attr_list); + +// Entry 1 +sai_entry_attr_list[0].id = SAI_ACL_ENTRY_ATTR_FIELD_SRC_PREFIX_META; +sai_attr_list[1].value.aclfield.enable = true; +sai_attr_list[1].value.aclfield.mask = 0xFFFFFF; +sai_attr_list[1].value.aclfield.data = 800; +sai_entry_attr_count = 1; + +// Create an Entry to match on META data +sai_create_acl_entry_fn( + &acl_entry_id_1, + switch_id, + sai_entry_attr_count, + sai_entry_attr_list); + +// Entry 2 +sai_entry_attr_list[0].id = SAI_ACL_ENTRY_ATTR_FIELD_DST_PREFIX_META; +sai_attr_list[1].value.aclfield.enable = true; +sai_attr_list[1].value.aclfield.mask = 0xFFFFFF; +sai_attr_list[1].value.aclfield.data = 200; +sai_entry_attr_count = 1; + +// Create an Entry to match on META data +sai_create_acl_entry_fn( + &acl_entry_id_2, + switch_id, + sai_entry_attr_count, + sai_entry_attr_list); + +// Remove ACL entry +sai_remove_acl_entry_fn( + acl_entry_id_1); + +// Remove ACL Table +sai_remove_acl_entry_fn( + acl_table_id_2); + +// Remove Single Entry +sai_remove_prefix_compression_entry_fn( + entry_v4_1); + +// Remove Bulk Entries +sai_bulk_remove_prefix_compression_entry_fn( + entries_list_size, + entries_list, + SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, + bulk_status); + +// Remove Prefix Compression Table +sai_remove_prefix_compression_table_fn( + src_prefix_compression_table_id); + +``` \ No newline at end of file diff --git a/inc/sai.h b/inc/sai.h index 8ce7039bb..4a802b4f9 100644 --- a/inc/sai.h +++ b/inc/sai.h @@ -150,6 +150,7 @@ typedef enum _sai_api_t SAI_API_TWAMP = 50, /**< sai_twamp_api_t */ SAI_API_POE = 51, /**< sai_poe_api_t */ SAI_API_ICMP_ECHO = 52, /**< sai_icmp_echo_api_t */ + SAI_API_PREFIX_COMPRESSION = 53, /**< sai_prefix_compression_api_t */ SAI_API_MAX, /**< total number of APIs */ /** diff --git a/inc/saiacl.h b/inc/saiacl.h index df92e7bff..022de6fc6 100644 --- a/inc/saiacl.h +++ b/inc/saiacl.h @@ -1541,10 +1541,32 @@ typedef enum _sai_acl_table_attr_t */ SAI_ACL_TABLE_ATTR_FIELD_TUNNEL_TERMINATED = SAI_ACL_TABLE_ATTR_FIELD_START + 0x15f, + /** + * @brief SRC META data + * + * This key is dedicated to matching on a SRC META data + * + * @type bool + * @flags CREATE_ONLY + * @default false + */ + SAI_ACL_TABLE_ATTR_FIELD_SRC_PREFIX_META = SAI_ACL_TABLE_ATTR_FIELD_START + 0x160, + + /** + * @brief DST META data + * + * This key is dedicated to matching on a DST META data + * + * @type bool + * @flags CREATE_ONLY + * @default false + */ + SAI_ACL_TABLE_ATTR_FIELD_DST_PREFIX_META = SAI_ACL_TABLE_ATTR_FIELD_START + 0x161, + /** * @brief End of ACL Table Match Field */ - SAI_ACL_TABLE_ATTR_FIELD_END = SAI_ACL_TABLE_ATTR_FIELD_TUNNEL_TERMINATED, + SAI_ACL_TABLE_ATTR_FIELD_END = SAI_ACL_TABLE_ATTR_FIELD_DST_PREFIX_META, /** * @brief ACL table entries associated with this table. @@ -1580,6 +1602,34 @@ typedef enum _sai_acl_table_attr_t */ SAI_ACL_TABLE_ATTR_ACL_TABLE_MATCH_TYPE, + /** + * @brief SRC prefix Table Object ID + * + * An object pointer to a prefix table used for + * source prefix lookups + * + * @type sai_object_id_t + * @flags CREATE_ONLY + * @objects SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE + * @allownull true + * @default SAI_NULL_OBJECT_ID + */ + SAI_ACL_TABLE_ATTR_SRC_PREFIX_COMPRESSION_TABLE, + + /** + * @brief DST prefix Table Object ID + * + * An object pointer to a prefix table used for + * destination prefix lookups + * + * @type sai_object_id_t + * @flags CREATE_ONLY + * @objects SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE + * @allownull true + * @default SAI_NULL_OBJECT_ID + */ + SAI_ACL_TABLE_ATTR_DST_PREFIX_COMPRESSION_TABLE, + /** * @brief Start of Table Match valid bits * @@ -2623,10 +2673,28 @@ typedef enum _sai_acl_entry_attr_t */ SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_TERMINATED = SAI_ACL_ENTRY_ATTR_FIELD_START + 0x15f, + /** + * @brief SRC META data + * + * @type sai_acl_field_data_t sai_uint32_t + * @flags CREATE_AND_SET + * @default disabled + */ + SAI_ACL_ENTRY_ATTR_FIELD_SRC_PREFIX_META = SAI_ACL_ENTRY_ATTR_FIELD_START + 0x160, + + /** + * @brief DST META data + * + * @type sai_acl_field_data_t sai_uint32_t + * @flags CREATE_AND_SET + * @default disabled + */ + SAI_ACL_ENTRY_ATTR_FIELD_DST_PREFIX_META = SAI_ACL_ENTRY_ATTR_FIELD_START + 0x161, + /** * @brief End of Rule Match Fields */ - SAI_ACL_ENTRY_ATTR_FIELD_END = SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_TERMINATED, + SAI_ACL_ENTRY_ATTR_FIELD_END = SAI_ACL_ENTRY_ATTR_FIELD_DST_PREFIX_META, /* * Actions [sai_acl_action_data_t] diff --git a/inc/saiobject.h b/inc/saiobject.h index 2951de49e..6ea788f58 100644 --- a/inc/saiobject.h +++ b/inc/saiobject.h @@ -35,6 +35,7 @@ #include #include #include +#include /* new experimental object type includes */ #include @@ -116,6 +117,9 @@ typedef union _sai_object_key_entry_t /** @validonly object_type == SAI_OBJECT_TYPE_PA_VALIDATION_ENTRY */ sai_pa_validation_entry_t pa_validation_entry; + /** @validonly object_type == SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY */ + sai_prefix_compression_entry_t prefix_compression_entry; + /** @validonly object_type == SAI_OBJECT_TYPE_VIP_ENTRY */ sai_vip_entry_t vip_entry; diff --git a/inc/saiprefixcompression.h b/inc/saiprefixcompression.h new file mode 100644 index 000000000..38c30838a --- /dev/null +++ b/inc/saiprefixcompression.h @@ -0,0 +1,313 @@ +/** + * Copyright (c) 2024 Microsoft Open Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT + * LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS + * FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. + * + * See the Apache Version 2.0 License for specific language governing + * permissions and limitations under the License. + * + * Microsoft would like to thank the following companies for their review and + * assistance with these files: Intel Corporation, Mellanox Technologies Ltd, + * Dell Products, L.P., Facebook, Inc., Marvell International Ltd. + * + * @file saiprefixcompression.h + * + * @brief This module defines SAI prefix compression interface + */ + +#if !defined (__SAIPREFIXCOMPRESSION_H_) +#define __SAIPREFIXCOMPRESSION_H_ + +#include + +/** + * @defgroup SAIPREFIXCOMPRESSION SAI - Prefix Compression API definitions + * + * @{ + */ + +/** + * @brief Attribute Id for SAI prefix compression object + */ +typedef enum _sai_prefix_compression_table_attr_t +{ + /** + * @brief Start of attributes + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_START, + + /** + * @brief Label attribute used to unique identify Table. + * + * @type char + * @flags CREATE_AND_SET + * @default "" + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_LABEL = SAI_PREFIX_COMPRESSION_TABLE_ATTR_START, + + /** + * @brief Prefix Compression table stage + * + * @type sai_prefix_compression_stage_t + * @flags MANDATORY_ON_CREATE | CREATE_ONLY + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_PREFIX_COMPRESSION_STAGE, + + /** + * @brief Prefix Compression table type + * + * @type sai_prefix_compression_type_t + * @flags MANDATORY_ON_CREATE | CREATE_ONLY + * @isresourcetype true + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_PREFIX_COMPRESSION_TYPE, + + /** + * @brief End of attributes + */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_END, + + /** Custom range base value */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_CUSTOM_RANGE_START = 0x10000000, + + /** End of custom range base */ + SAI_PREFIX_COMPRESSION_TABLE_ATTR_CUSTOM_RANGE_END + +} sai_prefix_compression_table_attr_t; + +/** + * @brief Attribute Id for SAI prefix compression object + */ +typedef enum _sai_prefix_compression_entry_attr_t +{ + /** + * @brief Start of attributes + */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_START, + + /** + * @brief Prefix Compression entry meta data + * + * @type sai_uint32_t + * @flags MANDATORY_ON_CREATE | CREATE_AND_SET + */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_META = SAI_PREFIX_COMPRESSION_ENTRY_ATTR_START, + + /** + * @brief End of attributes + */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_END, + + /** Custom range base value */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_CUSTOM_RANGE_START = 0x10000000, + + /** End of custom range base */ + SAI_PREFIX_COMPRESSION_ENTRY_ATTR_CUSTOM_RANGE_END + +} sai_prefix_compression_entry_attr_t; + +/** + * @brief Prefix Compression entry + */ +typedef struct _sai_prefix_compression_entry_t +{ + /** + * @brief Switch ID + * + * @objects SAI_OBJECT_TYPE_SWITCH + */ + sai_object_id_t switch_id; + + /** + * @brief Prefix Compression Table ID + * + * @objects SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE + */ + sai_object_id_t prefix_table_id; + + /** + * @brief IP Prefix Destination + */ + sai_ip_prefix_t prefix; + +} sai_prefix_compression_entry_t; + +/** + * @brief Create prefix compression table + * + * @param[out] prefix_compression_table_id Prefix compression table ID + * @param[in] switch_id Switch id + * @param[in] attr_count Number of attributes + * @param[in] attr_list Array of attributes + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_create_prefix_compression_table_fn)( + _Out_ sai_object_id_t *prefix_compression_table_id, + _In_ sai_object_id_t switch_id, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list); + +/** + * @brief Remove prefix compression table + * + * @param[in] prefix_compression_table_id Prefix compression table ID + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_remove_prefix_compression_table_fn)( + _In_ sai_object_id_t prefix_compression_table_id); + +/** + * @brief Set prefix compression attribute Value + * + * @param[in] prefix_compression_table_id Prefix compression table ID + * @param[in] attr Attribute + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_set_prefix_compression_table_attribute_fn)( + _In_ sai_object_id_t prefix_compression_table_id, + _In_ const sai_attribute_t *attr); + +/** + * @brief Get prefix compression attribute Value + * + * @param[in] prefix_compression_table_id Prefix compression table ID + * @param[in] attr_count Number of attributes + * @param[inout] attr_list Array of attributes + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_get_prefix_compression_table_attribute_fn)( + _In_ sai_object_id_t prefix_compression_table_id, + _In_ uint32_t attr_count, + _Inout_ sai_attribute_t *attr_list); + +/** + * @brief Create prefix compression Entry + * + * Note: IP prefix/mask expected in Network Byte Order. + * + * @param[in] prefix_compression_entry Prefix Compression entry + * @param[in] attr_count Number of attributes + * @param[in] attr_list Array of attributes + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_create_prefix_compression_entry_fn)( + _In_ const sai_prefix_compression_entry_t *prefix_compression_entry, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list); + +/** + * @brief Remove prefix compression Entry + * + * Note: IP prefix/mask expected in Network Byte Order. + * + * @param[in] prefix_compression_entry Prefix Compression entry + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_remove_prefix_compression_entry_fn)( + _In_ const sai_prefix_compression_entry_t *prefix_compression_entry); + +/** + * @brief Set prefix compression attribute value + * + * @param[in] prefix_compression_entry Prefix Compression entry + * @param[in] attr Attribute + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_set_prefix_compression_entry_attribute_fn)( + _In_ const sai_prefix_compression_entry_t *prefix_compression_entry, + _In_ const sai_attribute_t *attr); + +/** + * @brief Get prefix compression attribute value + * + * @param[in] prefix_compression_entry Prefix Compression entry + * @param[in] attr_count Number of attributes + * @param[inout] attr_list Array of attributes + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_get_prefix_compression_entry_attribute_fn)( + _In_ const sai_prefix_compression_entry_t *prefix_compression_entry, + _In_ uint32_t attr_count, + _Inout_ sai_attribute_t *attr_list); + +/** + * @brief Bulk create prefix compression entry + * + * @param[in] object_count Number of objects to create + * @param[in] prefix_compression_entry List of object to create + * @param[in] attr_count List of attr_count. Caller passes the number + * of attribute for each object to create. + * @param[in] attr_list List of attributes for every object. + * @param[in] mode Bulk operation error handling mode. + * @param[out] object_statuses List of status for every object. Caller needs to + * allocate the buffer + * + * @return #SAI_STATUS_SUCCESS on success when all objects are created or + * #SAI_STATUS_FAILURE when any of the objects fails to create. When there is + * failure, Caller is expected to go through the list of returned statuses to + * find out which fails and which succeeds. + */ +typedef sai_status_t (*sai_bulk_create_prefix_compression_entry_fn)( + _In_ uint32_t object_count, + _In_ const sai_prefix_compression_entry_t *prefix_compression_entry, + _In_ const uint32_t *attr_count, + _In_ const sai_attribute_t **attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses); + +/** + * @brief Bulk remove prefix compression entry + * + * @param[in] object_count Number of objects to remove + * @param[in] prefix_compression_entry List of objects to remove + * @param[in] mode Bulk operation error handling mode. + * @param[out] object_statuses List of status for every object. Caller needs to + * allocate the buffer + * + * @return #SAI_STATUS_SUCCESS on success when all objects are removed or + * #SAI_STATUS_FAILURE when any of the objects fails to remove. When there is + * failure, Caller is expected to go through the list of returned statuses to + * find out which fails and which succeeds. + */ +typedef sai_status_t (*sai_bulk_remove_prefix_compression_entry_fn)( + _In_ uint32_t object_count, + _In_ const sai_prefix_compression_entry_t *prefix_compression_entry, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses); + +/** + * @brief Prefix Compression methods table retrieved with sai_api_query() + */ +typedef struct _sai_prefix_compression_api_t +{ + sai_create_prefix_compression_table_fn create_prefix_compression_table; + sai_remove_prefix_compression_table_fn remove_prefix_compression_table; + sai_set_prefix_compression_table_attribute_fn set_prefix_compression_table_attribute; + sai_get_prefix_compression_table_attribute_fn get_prefix_compression_table_attribute; + sai_create_prefix_compression_entry_fn create_prefix_compression_entry; + sai_remove_prefix_compression_entry_fn remove_prefix_compression_entry; + sai_set_prefix_compression_entry_attribute_fn set_prefix_compression_entry_attribute; + sai_get_prefix_compression_entry_attribute_fn get_prefix_compression_entry_attribute; + sai_bulk_create_prefix_compression_entry_fn create_prefix_compression_entries; + sai_bulk_remove_prefix_compression_entry_fn remove_prefix_compression_entries; +} sai_prefix_compression_api_t; + +/** + * @} + */ +#endif /** __SAIPREFIXCOMPRESSION_H_ */ diff --git a/inc/saitypes.h b/inc/saitypes.h index b2a730a19..b65be6bdb 100644 --- a/inc/saitypes.h +++ b/inc/saitypes.h @@ -299,6 +299,8 @@ typedef enum _sai_object_type_t SAI_OBJECT_TYPE_POE_PSE = 109, SAI_OBJECT_TYPE_POE_PORT = 110, SAI_OBJECT_TYPE_ICMP_ECHO_SESSION = 111, + SAI_OBJECT_TYPE_PREFIX_COMPRESSION_TABLE = 112, + SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY = 113, /** Must remain in last position */ SAI_OBJECT_TYPE_MAX, @@ -980,6 +982,35 @@ typedef enum _sai_tam_bind_point_type_t } sai_tam_bind_point_type_t; +/** + * @brief Attribute data for SAI_PREFIX_COMPRESSION_TABLE_ATTR_STAGE + */ +typedef enum _sai_prefix_compression_stage_t +{ + /** Ingress Stage */ + SAI_PREFIX_COMPRESSION_STAGE_INGRESS, + + /** Egress Stage */ + SAI_PREFIX_COMPRESSION_STAGE_EGRESS, + +} sai_prefix_compression_stage_t; + +/** + * @brief Attribute data for SAI_PREFIX_COMPRESSION_TABLE_ATTR_TYPE + */ +typedef enum _sai_prefix_compression_type_t +{ + /** SRC/DST table type */ + SAI_PREFIX_COMPRESSION_TYPE_BOTH, + + /** SRC table type */ + SAI_PREFIX_COMPRESSION_TYPE_SRC, + + /** DST table type */ + SAI_PREFIX_COMPRESSION_TYPE_DST, + +} sai_prefix_compression_type_t; + /** * @brief Structure for ACL Resource Count */