From 96adc95bf8316e1905143d9ecd21f32a43e80d7f Mon Sep 17 00:00:00 2001 From: Ann Pokora <44511240+qbdwlr@users.noreply.github.com> Date: Sun, 21 Feb 2021 23:38:37 -0500 Subject: [PATCH 01/20] Enhancements for MPLS support (#1181) * Enhancements for MPLS support Signed-off-by: Ann Pokora * remove unnecessary SAI_SWITCH_ATTR_AVAILABLE_MPLS_INSEG_ENTRY Signed-off-by: Ann Pokora --- inc/saimpls.h | 97 ++++++++++++++++++++++++++++++++++++++++ inc/sairouterinterface.h | 9 ++++ 2 files changed, 106 insertions(+) diff --git a/inc/saimpls.h b/inc/saimpls.h index f103fd1ea..eb17c4057 100644 --- a/inc/saimpls.h +++ b/inc/saimpls.h @@ -281,6 +281,98 @@ typedef sai_status_t (*sai_get_inseg_entry_attribute_fn)( _In_ uint32_t attr_count, _Inout_ sai_attribute_t *attr_list); +/** + * @brief Bulk create In Segment entry + * + * @param[in] object_count Number of objects to create + * @param[in] inseg_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_inseg_entry_fn)( + _In_ uint32_t object_count, + _In_ const sai_inseg_entry_t *inseg_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 In Segment entry + * + * @param[in] object_count Number of objects to remove + * @param[in] inseg_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_inseg_entry_fn)( + _In_ uint32_t object_count, + _In_ const sai_inseg_entry_t *inseg_entry, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses); + +/** + * @brief Bulk set attribute on In Segment entry + * + * @param[in] object_count Number of objects to set attribute + * @param[in] inseg_entry List of objects to set attribute + * @param[in] attr_list List of attributes to set on objects, one attribute per 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 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_set_inseg_entry_attribute_fn)( + _In_ uint32_t object_count, + _In_ const sai_inseg_entry_t *inseg_entry, + _In_ const sai_attribute_t *attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses); + +/** + * @brief Bulk get attribute on In Segment entry + * + * @param[in] object_count Number of objects to set attribute + * @param[in] inseg_entry List of objects to set attribute + * @param[in] attr_count List of attr_count. Caller passes the number + * of attribute for each object to get + * @param[inout] attr_list List of attributes to set on objects, one attribute per 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 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_get_inseg_entry_attribute_fn)( + _In_ uint32_t object_count, + _In_ const sai_inseg_entry_t *inseg_entry, + _In_ const uint32_t *attr_count, + _Inout_ sai_attribute_t **attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses); + /** * @brief MPLS methods table retrieved with sai_api_query() */ @@ -291,6 +383,11 @@ typedef struct _sai_mpls_api_t sai_set_inseg_entry_attribute_fn set_inseg_entry_attribute; sai_get_inseg_entry_attribute_fn get_inseg_entry_attribute; + sai_bulk_create_inseg_entry_fn create_inseg_entries; + sai_bulk_remove_inseg_entry_fn remove_inseg_entries; + sai_bulk_set_inseg_entry_attribute_fn set_inseg_entries_attribute; + sai_bulk_get_inseg_entry_attribute_fn get_inseg_entries_attribute; + } sai_mpls_api_t; /** diff --git a/inc/sairouterinterface.h b/inc/sairouterinterface.h index 0b4cd918e..1d71d488e 100644 --- a/inc/sairouterinterface.h +++ b/inc/sairouterinterface.h @@ -285,6 +285,15 @@ typedef enum _sai_router_interface_attr_t */ SAI_ROUTER_INTERFACE_ATTR_DISABLE_DECREMENT_TTL, + /** + * @brief Admin MPLS state + * + * @type bool + * @flags CREATE_AND_SET + * @default false + */ + SAI_ROUTER_INTERFACE_ATTR_ADMIN_MPLS_STATE, + /** * @brief End of attributes */ From b2d4c9a57c7f00b2632c35ca5eb3dd6480f7916a Mon Sep 17 00:00:00 2001 From: Jai Kumar Date: Sun, 21 Feb 2021 20:41:58 -0800 Subject: [PATCH 02/20] Switch scoped tunnel attributes (#1173) This PR is the closure of discussion in #1153 There is switch level tunnel object which can be set for various attributes per tunnel type. Signed-off-by: Jai Kumar --- inc/saiswitch.h | 265 +++++++++++++++++++++++++++++++++++++++++++++--- inc/saitunnel.h | 79 ++++----------- inc/saitypes.h | 1 + 3 files changed, 272 insertions(+), 73 deletions(-) diff --git a/inc/saiswitch.h b/inc/saiswitch.h index 0a358d081..51f3c9ab7 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -325,9 +325,187 @@ typedef enum _sai_switch_failover_config_mode_t } sai_switch_failover_config_mode_t; +/** + * @brief Defines tunnel type + */ +typedef enum _sai_tunnel_type_t +{ + SAI_TUNNEL_TYPE_IPINIP, + + SAI_TUNNEL_TYPE_IPINIP_GRE, + + SAI_TUNNEL_TYPE_VXLAN, + + SAI_TUNNEL_TYPE_MPLS, + +} sai_tunnel_type_t; + +/** + * @brief Defines VXLAN tunnel UDP source port mode + */ +typedef enum _sai_tunnel_vxlan_udp_sport_mode_t +{ + /** + * @brief User define value + */ + SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_USER_DEFINED, + + /** + * @brief RFC6335 Computed hash value in range 49152-65535 + */ + SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_EPHEMERAL, +} sai_tunnel_vxlan_udp_sport_mode_t; + +/** + * @brief Defines tunnel encap ECN mode + */ +typedef enum _sai_tunnel_encap_ecn_mode_t +{ + /** + * @brief Normal mode behavior defined in RFC 6040 + * section 4.1 copy from inner + */ + SAI_TUNNEL_ENCAP_ECN_MODE_STANDARD, + + /** + * @brief User defined behavior. + */ + SAI_TUNNEL_ENCAP_ECN_MODE_USER_DEFINED + +} sai_tunnel_encap_ecn_mode_t; + +/** + * @brief Defines tunnel decap ECN mode + */ +typedef enum _sai_tunnel_decap_ecn_mode_t +{ + /** + * @brief Behavior defined in RFC 6040 section 4.2 + */ + SAI_TUNNEL_DECAP_ECN_MODE_STANDARD, + + /** + * @brief Copy from outer ECN + */ + SAI_TUNNEL_DECAP_ECN_MODE_COPY_FROM_OUTER, + + /** + * @brief User defined behavior + */ + SAI_TUNNEL_DECAP_ECN_MODE_USER_DEFINED + +} sai_tunnel_decap_ecn_mode_t; + +/** + * @brief Defines tunnel attributes at switch level. + * SAI_OBJECT_TYPE_SWITCH_TUNNEL object provides + * per tunnel type global configuration. + * SAI_OBJECT_TYPE_TUNNEL object configuration + * overrides the switch scoped global configuration. + */ +typedef enum _sai_switch_tunnel_attr_t +{ + /** + * @brief Start of attributes + */ + SAI_SWITCH_TUNNEL_ATTR_START, + + /** + * @brief Tunnel type key + * + * @type sai_tunnel_type_t + * @flags MANDATORY_ON_CREATE | CREATE_ONLY | KEY + * @isresourcetype true + */ + SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE = SAI_SWITCH_TUNNEL_ATTR_START, + + /** + * @brief Packet action when a packet ingress and gets routed back to same tunnel + * + * @type sai_packet_action_t + * @flags CREATE_AND_SET + * @default SAI_PACKET_ACTION_FORWARD + */ + SAI_SWITCH_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION, + + /* Tunnel encap attributes */ + + /** + * @brief Tunnel encap ECN mode + * + * @type sai_tunnel_encap_ecn_mode_t + * @flags CREATE_ONLY + * @default SAI_TUNNEL_ENCAP_ECN_MODE_STANDARD + */ + SAI_SWITCH_TUNNEL_ATTR_TUNNEL_ENCAP_ECN_MODE, + + /** + * @brief Tunnel encap ECN mappers only + * + * @type sai_object_list_t + * @flags CREATE_ONLY + * @objects SAI_OBJECT_TYPE_TUNNEL_MAP + * @default empty + */ + SAI_SWITCH_TUNNEL_ATTR_ENCAP_MAPPERS, + + /* Tunnel decap attributes */ + + /** + * @brief Tunnel decap ECN mode + * + * @type sai_tunnel_decap_ecn_mode_t + * @flags CREATE_ONLY + * @default SAI_TUNNEL_DECAP_ECN_MODE_STANDARD + */ + SAI_SWITCH_TUNNEL_ATTR_TUNNEL_DECAP_ECN_MODE, + + /** + * @brief Tunnel decap ECN mappers only + * + * @type sai_object_list_t + * @flags CREATE_ONLY + * @objects SAI_OBJECT_TYPE_TUNNEL_MAP + * @default empty + */ + SAI_SWITCH_TUNNEL_ATTR_DECAP_MAPPERS, + + /** + * @brief Tunnel VXLAN UDP source port mode + * + * @type sai_tunnel_vxlan_udp_sport_mode_t + * @flags CREATE_AND_SET + * @default SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_EPHEMERAL + */ + SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE, + + /** + * @brief Tunnel UDP source port + * + * @type sai_uint16_t + * @flags CREATE_AND_SET + * @isvlan false + * @default 0 + * @validonly SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE == SAI_TUNNEL_TYPE_VXLAN and SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE == SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_USER_DEFINED + */ + SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT, + + /** + * @brief End of attributes + */ + SAI_SWITCH_TUNNEL_ATTR_END, + + /** Custom range base value */ + SAI_SWITCH_TUNNEL_ATTR_CUSTOM_RANGE_START = 0x10000000, + + /** End of custom range base */ + SAI_SWITCH_TUNNEL_ATTR_CUSTOM_RANGE_END + +} sai_switch_tunnel_attr_t; + /** * @brief Attribute Id in sai_set_switch_attribute() and - * sai_get_switch_attribute() calls + * sai_get_switch_attribute() calls. */ typedef enum _sai_switch_attr_t { @@ -2257,13 +2435,14 @@ typedef enum _sai_switch_attr_t SAI_SWITCH_ATTR_SUPPORTED_FAILOVER_MODE, /** - * @brief Packet action when a packet ingress and gets routed back to same tunnel + * @brief Switch scoped Tunnel objects * - * @type sai_packet_action_t + * @type sai_object_list_t * @flags CREATE_AND_SET - * @default SAI_PACKET_ACTION_FORWARD + * @objects SAI_OBJECT_TYPE_SWITCH_TUNNEL + * @default empty */ - SAI_SWITCH_ATTR_TUNNEL_LOOPBACK_PACKET_ACTION, + SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST, /** * @brief End of attributes @@ -2689,20 +2868,78 @@ typedef sai_status_t (*sai_clear_switch_stats_fn)( _In_ uint32_t number_of_counters, _In_ const sai_stat_id_t *counter_ids); +/** + * @brief Create switch scoped tunnel + * + * @param[out] switch_tunnel_id The Switch Tunnel Object 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_switch_tunnel_fn)( + _Out_ sai_object_id_t *switch_tunnel_id, + _In_ sai_object_id_t switch_id, + _In_ uint32_t attr_count, + _In_ const sai_attribute_t *attr_list); + +/** + * @brief Remove/disconnect Switch scope tunnel + * + * Release all resources associated with currently opened switch + * + * @param[in] switch_tunnel_id The Switch Tunnel id + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_remove_switch_tunnel_fn)( + _In_ sai_object_id_t switch_tunnel_id); + +/** + * @brief Set switch scoped tunnel attribute value + * + * @param[in] switch_tunnel_id Switch Tunnel id + * @param[in] attr Switch tunnel attribute + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_set_switch_tunnel_attribute_fn)( + _In_ sai_object_id_t switch_tunnel_id, + _In_ const sai_attribute_t *attr); + +/** + * @brief Get switch scoped tunnel attribute value + * + * @param[in] switch_tunnel_id Switch Tunnel id + * @param[in] attr_count Number of attributes + * @param[inout] attr_list Array of switch tunnel attributes + * + * @return #SAI_STATUS_SUCCESS on success, failure status code on error + */ +typedef sai_status_t (*sai_get_switch_tunnel_attribute_fn)( + _In_ sai_object_id_t switch_tunnel_id, + _In_ uint32_t attr_count, + _Inout_ sai_attribute_t *attr_list); + /** * @brief Switch method table retrieved with sai_api_query() */ typedef struct _sai_switch_api_t { - sai_create_switch_fn create_switch; - sai_remove_switch_fn remove_switch; - sai_set_switch_attribute_fn set_switch_attribute; - sai_get_switch_attribute_fn get_switch_attribute; - sai_get_switch_stats_fn get_switch_stats; - sai_get_switch_stats_ext_fn get_switch_stats_ext; - sai_clear_switch_stats_fn clear_switch_stats; - sai_switch_mdio_read_fn switch_mdio_read; - sai_switch_mdio_write_fn switch_mdio_write; + sai_create_switch_fn create_switch; + sai_remove_switch_fn remove_switch; + sai_set_switch_attribute_fn set_switch_attribute; + sai_get_switch_attribute_fn get_switch_attribute; + sai_get_switch_stats_fn get_switch_stats; + sai_get_switch_stats_ext_fn get_switch_stats_ext; + sai_clear_switch_stats_fn clear_switch_stats; + sai_switch_mdio_read_fn switch_mdio_read; + sai_switch_mdio_write_fn switch_mdio_write; + sai_create_switch_tunnel_fn create_switch_tunnel; + sai_remove_switch_tunnel_fn remove_switch_tunnel; + sai_set_switch_tunnel_attribute_fn set_switch_tunnel_attribute; + sai_get_switch_tunnel_attribute_fn get_switch_tunnel_attribute; } sai_switch_api_t; diff --git a/inc/saitunnel.h b/inc/saitunnel.h index 4a88093d6..877da1385 100644 --- a/inc/saitunnel.h +++ b/inc/saitunnel.h @@ -310,21 +310,6 @@ typedef sai_status_t (*sai_get_tunnel_map_attribute_fn)( _In_ uint32_t attr_count, _Inout_ sai_attribute_t *attr_list); -/** - * @brief Defines tunnel type - */ -typedef enum _sai_tunnel_type_t -{ - SAI_TUNNEL_TYPE_IPINIP, - - SAI_TUNNEL_TYPE_IPINIP_GRE, - - SAI_TUNNEL_TYPE_VXLAN, - - SAI_TUNNEL_TYPE_MPLS, - -} sai_tunnel_type_t; - /** * @brief Defines tunnel TTL mode */ @@ -385,50 +370,6 @@ typedef enum _sai_tunnel_dscp_mode_t } sai_tunnel_dscp_mode_t; -/** - * @brief Defines tunnel encap ECN mode - */ -typedef enum _sai_tunnel_encap_ecn_mode_t -{ - /** - * @brief Normal mode behavior defined in RFC 6040 - * section 4.1 copy from inner - */ - SAI_TUNNEL_ENCAP_ECN_MODE_STANDARD, - - /** - * @brief User defined behavior. - * - * Need to provide #SAI_TUNNEL_MAP_TYPE_OECN_TO_UECN in #SAI_TUNNEL_ATTR_ENCAP_MAPPERS. - */ - SAI_TUNNEL_ENCAP_ECN_MODE_USER_DEFINED - -} sai_tunnel_encap_ecn_mode_t; - -/** - * @brief Defines tunnel decap ECN mode - */ -typedef enum _sai_tunnel_decap_ecn_mode_t -{ - /** - * @brief Behavior defined in RFC 6040 section 4.2 - */ - SAI_TUNNEL_DECAP_ECN_MODE_STANDARD, - - /** - * @brief Copy from outer ECN - */ - SAI_TUNNEL_DECAP_ECN_MODE_COPY_FROM_OUTER, - - /** - * @brief User defined behavior - * - * Need to provide #SAI_TUNNEL_MAP_TYPE_UECN_OECN_TO_OECN in #SAI_TUNNEL_ATTR_DECAP_MAPPERS - */ - SAI_TUNNEL_DECAP_ECN_MODE_USER_DEFINED - -} sai_tunnel_decap_ecn_mode_t; - /** * @brief Defines tunnel peer mode */ @@ -653,6 +594,26 @@ typedef enum _sai_tunnel_attr_t */ SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION, + /** + * @brief Tunnel VXLAN UDP source port mode + * + * @type sai_tunnel_vxlan_udp_sport_mode_t + * @flags CREATE_AND_SET + * @default SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_EPHEMERAL + */ + SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE, + + /** + * @brief Tunnel UDP source port + * + * @type sai_uint16_t + * @flags CREATE_AND_SET + * @isvlan false + * @default 0 + * @validonly SAI_TUNNEL_ATTR_TYPE == SAI_TUNNEL_TYPE_VXLAN and SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE == SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_USER_DEFINED + */ + SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT, + /** * @brief End of attributes */ diff --git a/inc/saitypes.h b/inc/saitypes.h index 24d7f1d10..75ac53e1f 100644 --- a/inc/saitypes.h +++ b/inc/saitypes.h @@ -277,6 +277,7 @@ typedef enum _sai_object_type_t SAI_OBJECT_TYPE_MACSEC_SA = 92, SAI_OBJECT_TYPE_SYSTEM_PORT = 93, SAI_OBJECT_TYPE_FINE_GRAINED_HASH_FIELD = 94, + SAI_OBJECT_TYPE_SWITCH_TUNNEL = 95, SAI_OBJECT_TYPE_MAX, /* Must remain in last position */ } sai_object_type_t; From 1eb35afdb2146baf40e6c2b8f2f8bfe99075eaee Mon Sep 17 00:00:00 2001 From: Sujin Kang Date: Sun, 21 Feb 2021 20:43:11 -0800 Subject: [PATCH 03/20] Add SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO format for GB MDIO sysfs access (#1171) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO is the right attribute to be used to provide the each Phy information for mdio sysfs driver support SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO shall contain the interface_name and phy_id with “/” as the separator The data should be formatted as {intf_name}/{phy_id} : Ex) eth0/1 GB Phy SAI is expected to parse the SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO to determine the phy_id along with interface name for each phySAI Signed-off-by: sujinmkang --- inc/saiswitch.h | 4 +++- meta/aspell.en.pws | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/saiswitch.h b/inc/saiswitch.h index 51f3c9ab7..919404048 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -1622,8 +1622,10 @@ typedef enum _sai_switch_attr_t * * Hardware information format is based on SAI implementations by vendors. * String is NULL terminated. Format is vendor specific. - * Example: Like PCI location, I2C address etc. + * Example: Like PCI location, I2C address, MDIO address, MDIO bus SysFS information etc. * In case of NULL, First NPU attached to CPU will be initialized. + * For the MDIO SysFS driver support, the interface name and phy_id should be + * set and separated by "/", which should be formatted as {interface_name}/{phy_id} * Single NPU case this attribute is optional. * * @type sai_s8_list_t diff --git a/meta/aspell.en.pws b/meta/aspell.en.pws index 0696709a8..baaa7dd20 100644 --- a/meta/aspell.en.pws +++ b/meta/aspell.en.pws @@ -127,6 +127,7 @@ struct sublayer subnet subnets +SysFS timespec timestamp TLV From cbc9562bb7a8f2c3a79702b99be55f3b3afa6957 Mon Sep 17 00:00:00 2001 From: Jai Kumar Date: Mon, 8 Mar 2021 22:37:34 -0800 Subject: [PATCH 04/20] Override VRF (#1186) * Override VRF New virtual router boolean attribute is introduced to indicate that this is an override VRF and overrides other VRs Signed-off-by: Jai Kumar --- doc/Override-VRF.md | 114 ++++++++++++++++++++++++++++++++++++++++++++ inc/saiswitch.h | 12 +++++ 2 files changed, 126 insertions(+) create mode 100644 doc/Override-VRF.md diff --git a/doc/Override-VRF.md b/doc/Override-VRF.md new file mode 100644 index 000000000..6ff6db333 --- /dev/null +++ b/doc/Override-VRF.md @@ -0,0 +1,114 @@ +Override VRF +------------------------------------------------------------------------------- + Title | SAI Override VRF +-------------|----------------------------------------------------------------- + Authors | Jai Kumar, Broadcom Inc. + Status | In review + Type | Standards track + Created | 02/18/2021 + SAI-Version | 1.7.2 + + +------------------------------------------------------------------------------- + +This spec talks about the override VRF usecase. + +SAI pipleine define L3 lookup block as an abstracted stage where route lookup is abstracted as a single operation. +SAI pipeline do not specify how many parallel L3 lookups a device can/may support. + +Typically devices support multiple parallel L3 lookup to provide policy based forwarding. +Following usecase 1 is already covered in SAI spec. This spec adds support for usecase 2 and 3. + +New switch level default override VRF is introduced. +``` + /** + * @brief Default SAI Override Virtual Router ID + * + * Must return #SAI_STATUS_OBJECT_IN_USE when try to delete this VR ID. + * + * @type sai_object_id_t + * @flags READ_ONLY + * @objects SAI_OBJECT_TYPE_VIRTUAL_ROUTER + * @default internal + */ + SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID, +``` + + +### Usecase 1: VRF Fallback +In this case 2 parrallel lookups are performed +``` +Lookup 1: RIF/ACL -> VRF -> [VRF, DIP] -> R1 +Lookup 2: Switch -> Deafault_VRF -> [Default_VRF, DIP] -> R2 + +if (R1) + use R1; +elif (R2) + use R2; +else + MISS action; +``` + + + +### Usecase 2: Override VRF +In this case 2 parallel lookups are performed +``` +Lookup 1: Switch -> Override_VRF -> [Override_VRF, DIP] -> R1 +Lookup 2: RIF/ACL -> VRF -> [VRF, DIP] -> R2 + +if (R1) + use R1; +elif (R2) + use R2; +else + MISS action; +``` + +### Usecase 3: Override VRF and VRF Fallback +In this case 3 parallel lookups are performed +``` +Lookup 1: Switch -> Override_VRF -> [Override_VRF, DIP] -> R1 +Lookup 2: RIF/ACL -> VRF -> [VRF, DIP] -> R2 +Lookup 2: Switch -> Deafault_VRF -> [Default_VRF, DIP] -> R3 + +if (R1) + use R1; +elif (R2) + use R2; +elif (R3) + use R3; +else + MISS action; +``` + +Example WorkFlow: +Since SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID is a READ only attribute, SAI adapter creates a VRF object (virtual_router) during init. This object is emtpy and is returned when application quries for the override VRF. +Application MUST provide this VRF in the route update API. +``` +typedef struct _sai_route_entry_t +{ + /** + * @brief Switch ID + * + * @objects SAI_OBJECT_TYPE_SWITCH + */ + sai_object_id_t switch_id; + + /** + * @brief Virtual Router ID + * + * @objects SAI_OBJECT_TYPE_VIRTUAL_ROUTER + */ + sai_object_id_t vr_id; + + /** + * @brief IP Prefix Destination + */ + sai_ip_prefix_t destination; + +} sai_route_entry_t; + +``` + +> SAI adapter should return error if platform do not support SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID switch attribute diff --git a/inc/saiswitch.h b/inc/saiswitch.h index 919404048..8d0c2d722 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -861,6 +861,18 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID, + /** + * @brief Default SAI Override Virtual Router ID + * + * Must return #SAI_STATUS_OBJECT_IN_USE when try to delete this VR ID. + * + * @type sai_object_id_t + * @flags READ_ONLY + * @objects SAI_OBJECT_TYPE_VIRTUAL_ROUTER + * @default internal + */ + SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID, + /** * @brief Default .1Q Bridge ID * From f092ef1e3ce695fc3f9552721025695312b961a2 Mon Sep 17 00:00:00 2001 From: mikeberesford <69360661+mikeberesford@users.noreply.github.com> Date: Mon, 8 Mar 2021 22:42:49 -0800 Subject: [PATCH 05/20] Add IPv6 flow label hash attribute. (#1192) Signed-off-by: Mike Beresford --- inc/saihash.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inc/saihash.h b/inc/saihash.h index e4897658b..a6310a27c 100644 --- a/inc/saihash.h +++ b/inc/saihash.h @@ -166,6 +166,9 @@ typedef enum _sai_native_hash_field_t /** Native hash field fifth MPLS label from the top */ SAI_NATIVE_HASH_FIELD_MPLS_LABEL_4, + /** Native hash field IPv6 flow label */ + SAI_NATIVE_HASH_FIELD_IPV6_FLOW_LABEL, + /** No field - for compatibility, must be last */ SAI_NATIVE_HASH_FIELD_NONE, From 08192237963174cc60edae9b4812a39c43b291fd Mon Sep 17 00:00:00 2001 From: jasmeetbagga Date: Tue, 9 Mar 2021 22:07:25 -0800 Subject: [PATCH 06/20] Add attribute to query available packet DMA pool size (#1198) Summary: Add more attribute for querying available packet DMA pool size. This can be used for accounting for and debugging allocations from packet DMA pool. Co-authored-by: Jasmeet Bagga --- inc/saiswitch.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inc/saiswitch.h b/inc/saiswitch.h index 8d0c2d722..c4add9a21 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -2458,6 +2458,16 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST, + /** + * @brief The size of the available packet DMA pool memory in bytes + * This can be used in conjunction with total packet DMA pool + * size to account/debug % of memory available. + * + * @type sai_uint32_t + * @flags READ_ONLY + */ + SAI_SWITCH_ATTR_PACKET_AVAILABLE_DMA_MEMORY_POOL_SIZE, + /** * @brief End of attributes */ From 584c724864fe565357e82d097ddcc7363bddefac Mon Sep 17 00:00:00 2001 From: liushilongbuaa <584370777@qq.com> Date: Wed, 10 Mar 2021 14:23:00 +0800 Subject: [PATCH 07/20] [CI] Set up CI&PR with Azure Pipelines (#1200) [skip ci] Signed-off-by: Shilong Liu --- azure-pipelines.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..e2a95dae2 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,40 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: + branches: + include: + - master + +pr: + branches: + include: + - master + +pool: + vmImage: ubuntu-20.04 + +stages: +- stage: Build + jobs: + - job: + displayName: "build" + timeoutInMinutes: 60 + steps: + - checkout: self + clean: true + submodules: recursive + displayName: 'Checkout code' + - script: | + echo Hello + # the following is copied from jenkins + # set -ex + # #!/bin/bash -x + # export ANSI_COLORS_DISABLED=1 + # cd meta + # make + - publish: $(System.DefaultWorkingDirectory)/ + artifact: opencomputeproject.SAI + displayName: "Archive artifacts" From 744279839c176e68b19734657975e3f5ec6f1a32 Mon Sep 17 00:00:00 2001 From: dipankar-ba <58092765+dipankar-ba@users.noreply.github.com> Date: Tue, 9 Mar 2021 22:23:58 -0800 Subject: [PATCH 08/20] Replaced SAI_SWITCH_ATTR_MACSEC_OBJECT_ID with SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST (#1199) Signed-off-by: dipankar-ba --- inc/saiswitch.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/inc/saiswitch.h b/inc/saiswitch.h index c4add9a21..a74131737 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -2303,15 +2303,14 @@ typedef enum _sai_switch_attr_t SAI_SWITCH_ATTR_TYPE, /** - * @brief MACsec object for this switch. + * @brief MACsec object list for this switch. * - * @type sai_object_id_t + * @type sai_object_list_t * @flags CREATE_AND_SET * @objects SAI_OBJECT_TYPE_MACSEC - * @allownull true - * @default SAI_NULL_OBJECT_ID + * @default empty */ - SAI_SWITCH_ATTR_MACSEC_OBJECT_ID, + SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST, /** * @brief Enable EXP -> TC MAP on switch. From 2369ecb59fff1a5cae948d41eea06bf8b71330b2 Mon Sep 17 00:00:00 2001 From: Ravi Vantipalli <19242514+ravi861@users.noreply.github.com> Date: Sat, 13 Mar 2021 11:22:39 -0800 Subject: [PATCH 09/20] SAI versioning (#1183) * SAI versioning proposal --- doc/SAI-Proposal-versioning.md | 98 ++++++++++++++++++++++++++++++++++ saiversion.h | 36 +++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 doc/SAI-Proposal-versioning.md create mode 100644 saiversion.h diff --git a/doc/SAI-Proposal-versioning.md b/doc/SAI-Proposal-versioning.md new file mode 100644 index 000000000..63310fb2f --- /dev/null +++ b/doc/SAI-Proposal-versioning.md @@ -0,0 +1,98 @@ +SAI Versioning Proposal +======================= + +Title | SAI versioning +-------- | --- +Authors | Intel +Status | In review +Type | Standards track +Created | 01/21/2020 +SAI-Version | 1.7.1 + +---------- + +This document describes proposal to include versioning in the SAI library. This proposal only solves the following question.
+**How does a vendor support multiple SAI versions using only the trunk/master branch?** + +Requirements +------------ +Provide a mechanism for vendors to find the current version of SAI headers at compile time. + +Today, if a vendor wants to support multiple versions of SAI, + +### Binaries +A vendor publishes different libSAI implementations each compatible with different SAI versions. The users of the binaries can choose a version of the binary depending on which version of SAI they use for Sonic. The vendor publishes these binaries from different development branches dedicated to each SAI version. + +### Source Code +A vendor publishes their SDK in source form and advice their users of which version of their SDK can be used for the requested SAI version. It is assumed the most common form this takes is each vendor maintains a trunk branch with the latest code and patches are back ported to specific branches created for each SAI version. + +> ### Example +> Customer using Sonic version 201911 which is compatible with SAI 1.5.4. The vendor SDK version is 1.1. Their customer wants to upgrade to a newer version of the SDK which supports SAI objects/attributes that are only supported in SDK 1.2. The common method to support this is to backport the supported attributes to 1.1. + +Proposal +-------- +This proposal provides a static version file with version numbers hard-coded per release. + +### version.h +```c +#define SAI_MAJOR 1 +#define SAI_MINOR 7 +#define SAI_REVISION 1 + +#define SAI_VERSION(major, minor, micro) \ + (10000 * (major) + 100 * (minor) + (micro)) +#define SAI_API_VERSION SAI_VERSION(SAI_MAJOR, SAI_MINOR, SAI_REVISION) +``` + +### For a Vendor +A vendor can publish their SDK using the above versioning using static checks. + +Assuming a SAI_OBJECT_TYPE_TEST object with attributes SAI_TEST_ATTR_TYPE1 and SAI_TEST_ATTR_TYPE2.
+The “type1” attribute is only available after SAI 1.6.4.
+The “type2” attribute is only available after SAI 1.7.4
+A vendor implementation can now be, + +### Usage +```c +sai_status_t sai_set_test_attribute(sai_object_id_t id, + const sai_attribute_t *attr) { + switch (attr->id) { + case SAI_TEST_ATTR_START: + break; + +#if SAI_API_VERSION >= 164 + case SAI_TEST_ATTR_TYPE1: + // do your thing + break; +#endif + +#if SAI_API_VERSION >= 174 + case SAI_TEST_ATTR_TYPE2: + // do your thing + break; +#endif + + default: + break; + } +} +``` + +More versioning +--------------- +Versioning can be exported for the application build system to access without having to include the above header file. +### saiversion.makefile +```makefile +SAI_MAJOR := 1 +SAI_MINOR := 7 +SAI_REVISION := 1 + +SAI_API_VERSION := $(shell echo $$(( $(SAI_MAJOR)*10000+$(SAI_MINOR)*10+$(SAI_REVISION) ))) +``` +An application can then include this makefile to access the values +```makefile +include saiversion.makefile + +CXXFLAGS += -DSAI_API_VERSION=$(SAI_API_VERSION) +``` +More examples for other build systems like cmake are easy to find. diff --git a/saiversion.h b/saiversion.h new file mode 100644 index 000000000..6760fe189 --- /dev/null +++ b/saiversion.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2014 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 saiversion.h + * + * @brief Define the current version + */ + +#if !defined (__SAIVERSION_H_) +#define __SAIVERSION_H_ + +#define SAI_MAJOR 1 +#define SAI_MINOR 7 +#define SAI_REVISION 1 + +#define SAI_VERSION(major, minor, revision) (10000 * (major) + 100 * (minor) + (revision)) + +#define SAI_API_VERSION SAI_VERSION(SAI_MAJOR, SAI_MINOR, SAI_REVISION) + +#endif /** __SAIVERSION_H_ */ From 9755845a06525a3c17f03e7b936a70783e8ef068 Mon Sep 17 00:00:00 2001 From: erohsik <71034063+erohsik@users.noreply.github.com> Date: Tue, 16 Mar 2021 11:48:51 -0700 Subject: [PATCH 10/20] Packet header based VRF classification (#1185) Add Pre-Ingress ACL stage Add Set VRF action Add doc to describe the use case Co-authored-by: Kishore Gummadidala --- doc/Pre-Ingress-ACL.md | 158 +++++++++++++++++++++++++++++++++++++++++ inc/saiacl.h | 15 +++- inc/saiswitch.h | 16 +++++ inc/saitypes.h | 3 + 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100755 doc/Pre-Ingress-ACL.md diff --git a/doc/Pre-Ingress-ACL.md b/doc/Pre-Ingress-ACL.md new file mode 100755 index 000000000..b8e87b63b --- /dev/null +++ b/doc/Pre-Ingress-ACL.md @@ -0,0 +1,158 @@ +# Overview + +### Virtual Router derivation +In a standard router, a packet is received on a port. Based on the port property and relevant packet header fields, the ingress interface is derived.\ +L3 interfaces are assigned to a virtual router (VRF) when they are created. This VRF is used in route lookup. + +### Flexible Virtual Router assignment +It can be beneficial to have some flexibility in VRF assignment. Specifically it is useful to have the ability to match on packet header fields to override the VRF derived from the router interface.\ +An example use case would be to use the DSCP value from the packet’s header to set VRF in order to be able to forward high priority traffic on optimal paths. + +### Proposal +#### Pre-Ingress ACL stage +The packet header based VRF assignment functionality can be provided by an ACL that must be applied before the L3 forwarding lookup.\ +To enable this a new ACL stage is defined + +``` +inc/saitypes.h + + typedef enum _sai_acl_stage_t + { + ... + + /** Pre-ingress Stage */ + SAI_ACL_STAGE_PRE_INGRESS, + + } sai_acl_stage_t; + +``` + +in addition to an attribute to bind ACLs with this stage to the switch. + +``` +inc/saiswitch.h + typedef enum _sai_switch_attr_t + { + ... + + /** + * @brief Switch/Global bind point for pre-ingress ACL object + * + * Bind (or unbind) an pre-ingress ACL table or ACL group globally. Enable/Update + * pre-ingress ACL table or ACL group filtering by assigning the list of valid + * object id. Disable pre-ingress filtering by assigning SAI_NULL_OBJECT_ID + * in the attribute value. + * + * @type sai_object_id_t + * @flags CREATE_AND_SET + * @objects SAI_OBJECT_TYPE_ACL_TABLE, SAI_OBJECT_TYPE_ACL_TABLE_GROUP + * @allownull true + * @default SAI_NULL_OBJECT_ID + */ + SAI_SWITCH_ATTR_PRE_INGRESS_ACL, + + ... +} sai_switch_attr_t; +``` +Binding a Pre-Ingress ACL to the switch bind point allows all traffic to match on the rules before the L3 lookup. (This helps with scale when the rules in the Pre-Ingress ACL are not port specific)\ +Pre-Ingress ACLs take effect before Ingress ACL. So Ingress ACLs can override any non-terminal actions taken by the Pre-Ingress ACL.\ +The currently defined ACL match fields will be used for the Pre-Ingress ACL +stage as well.\ + +#### Set VRF action +This ACL will support a new ACL action to set VRF in the packet metadata.\ +This VRF will take precedence over the VRF derived from the ingress interface. + +``` +inc/saiacl.h +typedef enum _sai_acl_action_type_t +{ + ... + + /** Associate with virtual router */ + SAI_ACL_ACTION_TYPE_SET_VRF + +} sai_acl_action_type_t; +``` +``` +typedef enum _sai_acl_entry_attr_t +{ + ... + + /** + * @brief Set virtual router + * + * @type sai_acl_action_data_t sai_object_id_t + * @flags CREATE_AND_SET + * @objects SAI_OBJECT_TYPE_VIRTUAL_ROUTER + * @default disabled + */ + SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF, + + ... + +} sai_acl_entry_attr_t; +``` + + + + +### Usage +Create an ACL table +``` + sai_object_id_t acl_table_id = 0ULL; + acl_table_attrs[0].id = SAI_ACL_TABLE_ATTR_ACL_STAGE; + acl_table_attrs[0].value.s32 = SAI_ACL_STAGE_PRE_INGRESS; + + acl_table_attrs[1].id = SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST; + acl_table_attrs[1].value.objlist.count = 1; + acl_table_attrs[1].value.objlist.list[0] = SAI_ACL_BIND_POINT_TYPE_SWITCH; + + acl_table_attrs[2].id = SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL; + acl_table_attrs[2].value.booldata = true; + status = sai_acl_api->create_acl_table(&acl_table_id, 3, acl_table_attrs); + if (status != SAI_STATUS_SUCCESS) { + return status; + } +``` + +Create an ACL entry +``` + sai_object_id_t acl_entry_id = 0ULL; + acl_entry_attrs[0].id = SAI_ACL_ENTRY_ATTR_TABLE_ID; + acl_entry_attrs[0].value.oid = acl_table_id; + + acl_entry_attrs[1].id = SAI_ACL_ENTRY_ATTR_FIELD_IP_PROTOCOL; + acl_entry_attrs[1].value.aclfield.data.u8 = 17; + acl_entry_attrs[1].value.aclfield.mask.u8 = 255; + + acl_entry_attrs[2].id = SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF; + acl_entry_attrs[2].value.aclaction.enable = true; + acl_entry_attrs[2].value.aclaction.parameter.oid = vrf_oid; + + status = sai_acl_api->create_acl_entry(&acl_entry_id, 3, acl_entry_attrs); + if (status != SAI_STATUS_SUCCESS) { + return status; + } +``` + +Bind ACL table to switch +``` + switch_attr.id = SAI_SWITCH_ATTR_PRE_INGRESS_ACL; + switch_attr.value.oid = acl_table_id; + + status = sai_switch_api->set_switch_attribute(switch_id, &switch_attr); + if (status != SAI_STATUS_SUCCESS) { + return status; + } +``` + +### Questions raised in earlier meeting +* Would this apply to non-L3 traffic? + * Yes if ACL contains L2 only match fields, but the VRF would be ignored as L3 lookup will not happen +* What VRF if any would be in the punted packet metadata + * Should be the VRF used for L3 lookup +* Is this before or after decap? + * The intent is to override the VRF used for L3 lookup. Tunnel decap yields the Tunnel Interface which is part of a VRF. After decap the inner packet’s DIP is used for the forwarding lookup. Ideally the inner packet’s headers should be used for VRF override in case the tunnel decap has happened. +* What about other RIF properties? + * Only VRF is overridden, other RIF properties are retained. diff --git a/inc/saiacl.h b/inc/saiacl.h index 9c3a37fa7..6985a9b5f 100644 --- a/inc/saiacl.h +++ b/inc/saiacl.h @@ -271,6 +271,9 @@ typedef enum _sai_acl_action_type_t /** Set custom ECMP hash object ID */ SAI_ACL_ACTION_TYPE_SET_ECMP_HASH_ID, + /** Associate with virtual router */ + SAI_ACL_ACTION_TYPE_SET_VRF + } sai_acl_action_type_t; /** @@ -2909,10 +2912,20 @@ typedef enum _sai_acl_entry_attr_t */ SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID, + /** + * @brief Set virtual router + * + * @type sai_acl_action_data_t sai_object_id_t + * @flags CREATE_AND_SET + * @objects SAI_OBJECT_TYPE_VIRTUAL_ROUTER + * @default disabled + */ + SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF, + /** * @brief End of Rule Actions */ - SAI_ACL_ENTRY_ATTR_ACTION_END = SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID, + SAI_ACL_ENTRY_ATTR_ACTION_END = SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF, /** * @brief End of ACL Entry attributes diff --git a/inc/saiswitch.h b/inc/saiswitch.h index a74131737..a6a7bfa6d 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -2467,6 +2467,22 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_PACKET_AVAILABLE_DMA_MEMORY_POOL_SIZE, + /** + * @brief Switch/Global bind point for Pre-ingress ACL object + * + * Bind (or unbind) an Pre-ingress ACL table or ACL group globally. Enable/Update + * Pre-ingress ACL table or ACL group filtering by assigning the list of valid + * object id. Disable pre-ingress filtering by assigning SAI_NULL_OBJECT_ID + * in the attribute value. + * + * @type sai_object_id_t + * @flags CREATE_AND_SET + * @objects SAI_OBJECT_TYPE_ACL_TABLE, SAI_OBJECT_TYPE_ACL_TABLE_GROUP + * @allownull true + * @default SAI_NULL_OBJECT_ID + */ + SAI_SWITCH_ATTR_PRE_INGRESS_ACL, + /** * @brief End of attributes */ diff --git a/inc/saitypes.h b/inc/saitypes.h index 75ac53e1f..24898aa07 100644 --- a/inc/saitypes.h +++ b/inc/saitypes.h @@ -743,6 +743,9 @@ typedef enum _sai_acl_stage_t /** Egress Stage */ SAI_ACL_STAGE_EGRESS_MACSEC, + /** Pre-ingress Stage */ + SAI_ACL_STAGE_PRE_INGRESS, + } sai_acl_stage_t; /** From 13e5cd6940f9a0da1878d00f08e5941e09f16e7f Mon Sep 17 00:00:00 2001 From: Jai Kumar Date: Tue, 16 Mar 2021 22:27:56 -0700 Subject: [PATCH 11/20] PRBS RX State Data Type (#1179) * PRBS RX Error Count Read Only Attribute Signed-off-by: Jai Kumar --- inc/saiport.h | 29 ++++++++++------------------- inc/saitypes.h | 29 +++++++++++++++++++++++++++++ meta/parse.pl | 1 + meta/saimetadatatypes.h | 5 +++++ meta/saisanitycheck.c | 3 +++ 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/inc/saiport.h b/inc/saiport.h index 854b1f107..9ddb0b783 100644 --- a/inc/saiport.h +++ b/inc/saiport.h @@ -310,25 +310,6 @@ typedef enum _sai_port_link_training_rx_status_t SAI_PORT_LINK_TRAINING_RX_STATUS_TRAINED, } sai_port_link_training_rx_status_t; -/** - * @brief Attribute data for #SAI_PORT_ATTR_PRBS_RX_STATUS - */ -typedef enum _sai_port_prbs_rx_status_t -{ - /** PRBS is locked and error_count is 0 */ - SAI_PORT_PRBS_RX_STATUS_OK, - - /** PRBS is locked, but there are errors */ - SAI_PORT_PRBS_RX_STATUS_LOCK_WITH_ERRORS, - - /** PRBS not locked */ - SAI_PORT_PRBS_RX_STATUS_NOT_LOCKED, - - /** PRBS locked but there is loss of lock since last call */ - SAI_PORT_PRBS_RX_STATUS_LOST_LOCK, - -} sai_port_prbs_rx_status_t; - /** * @brief Attribute data for #SAI_PORT_ATTR_PRBS_CONFIG * PRBS configuration to enable transmitter, receiver or both @@ -1566,6 +1547,16 @@ typedef enum _sai_port_attr_t */ SAI_PORT_ATTR_PRBS_RX_STATUS, + /** + * @brief Attribute data for #SAI_PORT_ATTR_PRBS_RX_STATE + * Used for clear on read status/count register. + * Adapter should return SAI_STATUS_NOT_SUPPORTED if not supported. + * + * @type sai_prbs_rx_state_t + * @flags READ_ONLY + */ + SAI_PORT_ATTR_PRBS_RX_STATE, + /** * @brief Attribute data for #SAI_PORT_ATTR_AUTO_NEG_STATUS * diff --git a/inc/saitypes.h b/inc/saitypes.h index 24898aa07..f4831496d 100644 --- a/inc/saitypes.h +++ b/inc/saitypes.h @@ -392,6 +392,32 @@ typedef struct _sai_ip_prefix_t sai_ip_addr_t mask; } sai_ip_prefix_t; +/** + * @brief Attribute data for #SAI_PORT_ATTR_PRBS_RX_STATUS + */ +typedef enum _sai_port_prbs_rx_status_t +{ + /** PRBS is locked and error_count is 0 */ + SAI_PORT_PRBS_RX_STATUS_OK, + + /** PRBS is locked, but there are errors */ + SAI_PORT_PRBS_RX_STATUS_LOCK_WITH_ERRORS, + + /** PRBS not locked */ + SAI_PORT_PRBS_RX_STATUS_NOT_LOCKED, + + /** PRBS locked but there is loss of lock since last call */ + SAI_PORT_PRBS_RX_STATUS_LOST_LOCK, + +} sai_port_prbs_rx_status_t; + +typedef struct _sai_prbs_rx_state_t +{ + sai_port_prbs_rx_status_t rx_status; + + uint32_t error_count; +} sai_prbs_rx_state_t; + /** * @brief Field match mask * @@ -1143,6 +1169,9 @@ typedef union _sai_attribute_value_t /** @validonly meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_IP_PREFIX */ sai_ip_prefix_t ipprefix; + /** @validonly meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_PRBS_RX_STATE */ + sai_prbs_rx_state_t rx_state; + /** @validonly meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_ID */ sai_object_id_t oid; diff --git a/meta/parse.pl b/meta/parse.pl index 4f3d2ff9b..65a6c8962 100755 --- a/meta/parse.pl +++ b/meta/parse.pl @@ -2234,6 +2234,7 @@ sub ProcessStructValueType return "SAI_ATTR_VALUE_TYPE_MAC" if $type eq "sai_mac_t"; return "SAI_ATTR_VALUE_TYPE_IP_ADDRESS" if $type eq "sai_ip_address_t"; return "SAI_ATTR_VALUE_TYPE_IP_PREFIX" if $type eq "sai_ip_prefix_t"; + return "SAI_ATTR_VALUE_TYPE_PRBS_RX_STATE" if $type eq "sai_prbs_rx_state_t"; return "SAI_ATTR_VALUE_TYPE_UINT16" if $type eq "sai_vlan_id_t"; return "SAI_ATTR_VALUE_TYPE_UINT32" if $type eq "sai_label_id_t"; return "SAI_ATTR_VALUE_TYPE_UINT32" if $type eq "uint32_t"; diff --git a/meta/saimetadatatypes.h b/meta/saimetadatatypes.h index 3fe7f8c0f..64bc06d6b 100644 --- a/meta/saimetadatatypes.h +++ b/meta/saimetadatatypes.h @@ -141,6 +141,11 @@ typedef enum _sai_attr_value_type_t */ SAI_ATTR_VALUE_TYPE_IP_PREFIX, + /** + * @brief Attribute value is PRBS RX state + */ + SAI_ATTR_VALUE_TYPE_PRBS_RX_STATE, + /** * @brief Attribute value is object id. */ diff --git a/meta/saisanitycheck.c b/meta/saisanitycheck.c index 4c1df9a69..194ee44e3 100644 --- a/meta/saisanitycheck.c +++ b/meta/saisanitycheck.c @@ -645,6 +645,7 @@ void check_attr_object_type_provided( case SAI_ATTR_VALUE_TYPE_POINTER: case SAI_ATTR_VALUE_TYPE_IP_ADDRESS: case SAI_ATTR_VALUE_TYPE_IP_PREFIX: + case SAI_ATTR_VALUE_TYPE_PRBS_RX_STATE: case SAI_ATTR_VALUE_TYPE_CHARDATA: case SAI_ATTR_VALUE_TYPE_UINT32_RANGE: case SAI_ATTR_VALUE_TYPE_UINT32_LIST: @@ -913,6 +914,7 @@ void check_attr_default_required( case SAI_ATTR_VALUE_TYPE_MAC: case SAI_ATTR_VALUE_TYPE_IP_ADDRESS: case SAI_ATTR_VALUE_TYPE_IP_PREFIX: + case SAI_ATTR_VALUE_TYPE_PRBS_RX_STATE: case SAI_ATTR_VALUE_TYPE_TIMESPEC: case SAI_ATTR_VALUE_TYPE_IPV4: case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG: @@ -2587,6 +2589,7 @@ void check_attr_is_primitive( case SAI_ATTR_VALUE_TYPE_INT8: case SAI_ATTR_VALUE_TYPE_IP_ADDRESS: case SAI_ATTR_VALUE_TYPE_IP_PREFIX: + case SAI_ATTR_VALUE_TYPE_PRBS_RX_STATE: case SAI_ATTR_VALUE_TYPE_MAC: case SAI_ATTR_VALUE_TYPE_OBJECT_ID: case SAI_ATTR_VALUE_TYPE_POINTER: From f053d899feb9517f2db43ee462589a30572b5ed1 Mon Sep 17 00:00:00 2001 From: mikeberesford <69360661+mikeberesford@users.noreply.github.com> Date: Thu, 18 Mar 2021 09:26:15 -0700 Subject: [PATCH 12/20] Add switch attributes for hash offset configuration. (#1195) * Add switch attributes for hash offset configuration. Add ability to specify the hash offset (rotation) in addition to the hash seed. Signed-off-by: Mike Beresford --- inc/saiswitch.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inc/saiswitch.h b/inc/saiswitch.h index a6a7bfa6d..44823675d 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -1356,6 +1356,18 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED, + /** + * @brief SAI ECMP default hash offset + * + * When set, the output of the ECMP hash calculation will be rotated right + * by the specified number of bits. + * + * @type sai_uint8_t + * @flags CREATE_AND_SET + * @default 0 + */ + SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET, + /** * @brief SAI ECMP default symmetric hash * @@ -1421,6 +1433,18 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED, + /** + * @brief SAI LAG default hash offset + * + * When set, the output of the LAG hash calculation will be rotated right + * by the specified number of bits. + * + * @type sai_uint8_t + * @flags CREATE_AND_SET + * @default 0 + */ + SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET, + /** * @brief SAI LAG default symmetric hash * From 8731ca6e09c7ba99b0b009e5821d80598e216756 Mon Sep 17 00:00:00 2001 From: Kumaresh Perumal Date: Sun, 21 Mar 2021 20:20:10 -0700 Subject: [PATCH 13/20] Add source/dest/double NAPT entry available attributes (#1194) * Add source/dest/double NAPT entry available attributes --- inc/saiswitch.h | 24 ++++++++++++++++++++++++ meta/acronyms.txt | 3 +++ 2 files changed, 27 insertions(+) diff --git a/inc/saiswitch.h b/inc/saiswitch.h index 44823675d..c51190db8 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -2507,6 +2507,30 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_PRE_INGRESS_ACL, + /** + * @brief Available SNAPT entries + * + * @type sai_uint32_t + * @flags READ_ONLY + */ + SAI_SWITCH_ATTR_AVAILABLE_SNAPT_ENTRY, + + /** + * @brief Available DNAPT entries + * + * @type sai_uint32_t + * @flags READ_ONLY + */ + SAI_SWITCH_ATTR_AVAILABLE_DNAPT_ENTRY, + + /** + * @brief Available Double NAPT entries + * + * @type sai_uint32_t + * @flags READ_ONLY + */ + SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAPT_ENTRY, + /** * @brief End of attributes */ diff --git a/meta/acronyms.txt b/meta/acronyms.txt index 4fefbbbfc..d6cb882df 100644 --- a/meta/acronyms.txt +++ b/meta/acronyms.txt @@ -143,3 +143,6 @@ I2C - I squared C CPLD - Complex programmable logic device EEPROM - Electrically erasable programmable read-only memory PRBS - Pseudorandom binary sequence +NAPT - Network Address Port Translation +SNAPT - Source Network Address Port Translation +DNAPT - Destination Network Address Port Trasnlation From b3244ceceb45184ffe37da55bb9a98ef126050ce Mon Sep 17 00:00:00 2001 From: SarathBug <37321567+SarathBug@users.noreply.github.com> Date: Mon, 22 Mar 2021 09:05:20 +0530 Subject: [PATCH 14/20] saineighbor.h: Updated SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX and deprecated SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX (#1202) * saineighbor.h: Updated SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX and deprecated SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX Signed-off-by: SarathBug --- inc/saineighbor.h | 6 ++++-- meta/saisanitycheck.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/inc/saineighbor.h b/inc/saineighbor.h index 85149b9be..0153d5f8e 100644 --- a/inc/saineighbor.h +++ b/inc/saineighbor.h @@ -123,19 +123,21 @@ typedef enum _sai_neighbor_entry_attr_t * * @type sai_uint32_t * @flags CREATE_AND_SET - * @default 0 + * @default internal */ SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX, /** - * @brief Encapsulation index is imposed + * @brief Encapsulation index is imposed. This is deprecated * + * This attribute is deprecated * This is a flag which states that the encap index was imposed. On create and set * the SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX must be present. * * @type bool * @flags CREATE_AND_SET * @default false + * @deprecated true */ SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX, diff --git a/meta/saisanitycheck.c b/meta/saisanitycheck.c index 194ee44e3..ebfe8f788 100644 --- a/meta/saisanitycheck.c +++ b/meta/saisanitycheck.c @@ -1177,10 +1177,12 @@ void check_attr_default_value_type( case SAI_DEFAULT_VALUE_TYPE_SWITCH_INTERNAL: - if ((md->objecttype == SAI_OBJECT_TYPE_PORT) || (md->objecttype == SAI_OBJECT_TYPE_PORT_SERDES)) + if ((md->objecttype == SAI_OBJECT_TYPE_PORT) || + (md->objecttype == SAI_OBJECT_TYPE_PORT_SERDES) || + (md->objecttype == SAI_OBJECT_TYPE_NEIGHBOR_ENTRY)) { /* - * Allow PORT attribute list's to be set to internal. + * Allow PORT, NEIGHBOR attribute list's to be set to internal. */ break; } From 5a98bc3c7e86c01f3cf702054f9af7c7c5ca6daf Mon Sep 17 00:00:00 2001 From: rlhui <48738894+rlhui@users.noreply.github.com> Date: Sun, 21 Mar 2021 23:15:57 -0700 Subject: [PATCH 15/20] Update version to 1.8.0 (#1207) Update SAI version to v1.8.0 Signed-off-by: rlhui --- saiversion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saiversion.h b/saiversion.h index 6760fe189..3b349915f 100644 --- a/saiversion.h +++ b/saiversion.h @@ -26,8 +26,8 @@ #define __SAIVERSION_H_ #define SAI_MAJOR 1 -#define SAI_MINOR 7 -#define SAI_REVISION 1 +#define SAI_MINOR 8 +#define SAI_REVISION 0 #define SAI_VERSION(major, minor, revision) (10000 * (major) + 100 * (minor) + (revision)) From 48f084de6209b7462243130dc48ee0328282f701 Mon Sep 17 00:00:00 2001 From: lguohan Date: Thu, 1 Apr 2021 02:07:41 -0700 Subject: [PATCH 16/20] [ci]: add proper azp (#1212) Signed-off-by: Guohan Lu --- azure-pipelines.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e2a95dae2..5ae0eb165 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,13 +13,17 @@ pr: include: - master -pool: +pool: vmImage: ubuntu-20.04 stages: - stage: Build jobs: - job: + + container: + image: sonicdev-microsoft.azurecr.io:443/sonic-slave-buster:latest + displayName: "build" timeoutInMinutes: 60 steps: @@ -28,13 +32,8 @@ stages: submodules: recursive displayName: 'Checkout code' - script: | - echo Hello - # the following is copied from jenkins - # set -ex - # #!/bin/bash -x - # export ANSI_COLORS_DISABLED=1 - # cd meta - # make - - publish: $(System.DefaultWorkingDirectory)/ - artifact: opencomputeproject.SAI - displayName: "Archive artifacts" + set -ex + export ANSI_COLORS_DISABLED=1 + cd meta + make + displayName: "Metadata check" From 503311d483f406786fe2fa58432451be1e7551d6 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Mon, 5 Apr 2021 10:31:32 -0700 Subject: [PATCH 17/20] Fix error when compiling Broadcom SAI with v1.8.0 (#1216) With SAI v1.8.0 sanity check for having max attribute for any object to be < 200 is not valid for switch attribute. Commenting out check as of now. --- meta/saisanitycheck.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meta/saisanitycheck.c b/meta/saisanitycheck.c index ebfe8f788..cd676d10d 100644 --- a/meta/saisanitycheck.c +++ b/meta/saisanitycheck.c @@ -372,7 +372,9 @@ void check_attr_by_object_type() sai_object_type_t current = ot[index]->objecttype; META_ASSERT_TRUE(current == i, "object type must be equal on object type list"); - META_ASSERT_TRUE(index < 200, "object defines > 200 attributes, metadata bug?"); + /* For Switch Attribute we have crossed > 200 with Vendor extention for SAIv1.8.0 + so increasing threshold */ + META_ASSERT_TRUE(index < 300, "object defines > 300 attributes, metadata bug?"); META_ASSERT_TRUE(current > SAI_OBJECT_TYPE_NULL, "object type must be > NULL"); META_ASSERT_TRUE(current < SAI_OBJECT_TYPE_EXTENSIONS_MAX, "object type must be < MAX"); From 875fec72cc48814dfa8d9fad1621d5e985692c03 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Mon, 5 Apr 2021 14:24:46 -0700 Subject: [PATCH 18/20] Update SAI version to V1.8.1 (#1218) Update Sai version to 1.8.1. There is some fix needed on top of SAI1.8.0 --- saiversion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saiversion.h b/saiversion.h index 3b349915f..aa1b89670 100644 --- a/saiversion.h +++ b/saiversion.h @@ -27,7 +27,7 @@ #define SAI_MAJOR 1 #define SAI_MINOR 8 -#define SAI_REVISION 0 +#define SAI_REVISION 1 #define SAI_VERSION(major, minor, revision) (10000 * (major) + 100 * (minor) + (revision)) From 575ea81693d923ab5407c923eda4036f1bc58281 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Tue, 13 Apr 2021 19:55:22 +0200 Subject: [PATCH 19/20] [meta] Add support for ignored attribute names (#1214) --- meta/parse.pl | 10 ++++++++++ meta/saimetadatautils.c | 43 +++++++++++++++++++++++++++++++++++++++++ meta/saimetadatautils.h | 10 ++++++++++ meta/saisanitycheck.c | 18 +++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/meta/parse.pl b/meta/parse.pl index 65a6c8962..f4b813faf 100755 --- a/meta/parse.pl +++ b/meta/parse.pl @@ -464,6 +464,16 @@ sub ProcessEnumSection { LogInfo "Ignoring $enumvaluename"; + my $initializer = $ev->{initializer}[0]; + + if ($initializer =~ /^= (SAI_\w+)$/) + { + } + else + { + LogWarning "Enum $enumvaluename is ignored, but initializer is '$initializer' not in form '= SAI_\\w+'"; + } + # process ignore attributes if (not defined $SAI_ENUMS{$enumtypename}{ignoreval}) diff --git a/meta/saimetadatautils.c b/meta/saimetadatautils.c index b7d169dd2..21313121d 100644 --- a/meta/saimetadatautils.c +++ b/meta/saimetadatautils.c @@ -150,6 +150,49 @@ const sai_attr_metadata_t* sai_metadata_get_attr_metadata_by_attr_id_name( return NULL; } +const sai_attr_metadata_t* sai_metadata_get_ignored_attr_metadata_by_attr_id_name( + _In_ const char *attr_id_name) +{ + if (attr_id_name == NULL) + { + return NULL; + } + + sai_object_type_t ot; + + /* + * Since we don't have list of ignored attributes, enumerate all objects + * and attribute enums to find ignored values. + */ + + for (ot = SAI_OBJECT_TYPE_NULL; ot < SAI_OBJECT_TYPE_EXTENSIONS_MAX; ot++) + { + const sai_object_type_info_t* oti = sai_metadata_get_object_type_info(ot); + + if (oti == NULL) + continue; + + const sai_enum_metadata_t* em = oti->enummetadata; + + if (em->ignorevaluesnames) + { + size_t i; + + for (i = 0; em->ignorevaluesnames[i] != NULL; i++) + { + if (strcmp(attr_id_name, em->ignorevaluesnames[i]) == 0) + { + const char* name = sai_metadata_get_enum_value_name(em, em->ignorevalues[i]); + + return sai_metadata_get_attr_metadata_by_attr_id_name(name); + } + } + } + } + + return NULL; +} + const char* sai_metadata_get_enum_value_name( _In_ const sai_enum_metadata_t* metadata, _In_ int value) diff --git a/meta/saimetadatautils.h b/meta/saimetadatautils.h index d4beab58a..7d191a208 100644 --- a/meta/saimetadatautils.h +++ b/meta/saimetadatautils.h @@ -79,6 +79,16 @@ extern const sai_attr_metadata_t* sai_metadata_get_attr_metadata( extern const sai_attr_metadata_t* sai_metadata_get_attr_metadata_by_attr_id_name( _In_ const char *attr_id_name); +/** + * @brief Gets ignored attribute metadata based on attribute id name + * + * @param[in] attr_id_name Attribute id name + * + * @return Pointer to object metadata or NULL in case of failure + */ +extern const sai_attr_metadata_t* sai_metadata_get_ignored_attr_metadata_by_attr_id_name( + _In_ const char *attr_id_name); + /** * @brief Gets string representation of enum value * diff --git a/meta/saisanitycheck.c b/meta/saisanitycheck.c index cd676d10d..5573664a6 100644 --- a/meta/saisanitycheck.c +++ b/meta/saisanitycheck.c @@ -4701,6 +4701,23 @@ void check_all_object_infos() META_ASSERT_TRUE((size_t)SAI_OBJECT_TYPE_EXTENSIONS_MAX == (size_t)SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END, "must be equal"); } +void check_ignored_attributes() +{ + META_LOG_ENTER(); + + META_ASSERT_NULL(sai_metadata_get_attr_metadata_by_attr_id_name("SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE")); + + const sai_attr_metadata_t* meta = sai_metadata_get_ignored_attr_metadata_by_attr_id_name("SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE"); + + if (meta == NULL) + { + META_ASSERT_FAIL("Failed to find ignored attribute SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE"); + } + + META_ASSERT_TRUE(strcmp(meta->attridname, "SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE") == 0, + "expected attribute was SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE"); +} + int main(int argc, char **argv) { debug = (argc > 1); @@ -4739,6 +4756,7 @@ int main(int argc, char **argv) check_switch_pointers_list(); check_defines(); check_all_object_infos(); + check_ignored_attributes(); SAI_META_LOG_DEBUG("log test"); From 2c8dd5c4591e37ab69e90da0a64bd938379089ce Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Thu, 15 Apr 2021 14:24:18 +0200 Subject: [PATCH 20/20] [meta] Add support for auto generate saiswig.i (#1221) This will rewrite api structures which will be marked "callable" when using python bindings and also will generate helper apis to get each api structure directly. --- meta/parse.pl | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ meta/style.pm | 2 + meta/utils.pm | 15 +++++- 3 files changed, 147 insertions(+), 2 deletions(-) diff --git a/meta/parse.pl b/meta/parse.pl index f4b813faf..efeab9c06 100755 --- a/meta/parse.pl +++ b/meta/parse.pl @@ -61,6 +61,7 @@ our %OBJECT_TYPE_TO_STATS_MAP = (); our %ATTR_TO_CALLBACK = (); our %PRIMITIVE_TYPES = (); +our %FUNCTION_DEF = (); our @ALL_ENUMS = (); my $FLAGS = "MANDATORY_ON_CREATE|CREATE_ONLY|CREATE_AND_SET|READ_ONLY|KEY"; @@ -697,6 +698,11 @@ sub ProcessTypedefSection next; } + if ($typedefname =~ /^sai_\w+_fn$/) + { + $FUNCTION_DEF{$typedefname} = $memberdef->{definition}[0]; + } + if ($typedefname =~ /^sai_\w+_notification_fn$/) { if (not $typedeftype =~ /void\(\*/) @@ -4212,6 +4218,128 @@ sub CreateOtherStructs } } +sub CreateSaiSwigGetApiHelperFunctions +{ + # + # write swig get api helper functions, those functions could be moved to + # saimetadata.c directly, but inside sai_api_query is used, and currently + # sai metadata can be compiled and linked without any SAI library + # + + my @apis = @{ $SAI_ENUMS{sai_api_t}{values} }; + + WriteSwig "%{"; + + for my $Api (@apis) + { + $Api =~ /^SAI_API_(\w+)/; + + my $api = lc($1); + + next if $api =~ /unspecified/; + + WriteSwig "sai_status_t sai_get_${api}_api(sai_${api}_api_t* out)"; + WriteSwig "{"; + WriteSwig "sai_${api}_api_t* api;"; + WriteSwig "sai_status_t status = sai_api_query((sai_api_t)$Api, (void**)&api);"; + WriteSwig "if (status == SAI_STATUS_SUCCESS)"; + WriteSwig "{"; + WriteSwig "*out = *api;"; + WriteSwig "}"; + WriteSwig "return status;"; + WriteSwig "}"; + } + + WriteSwig "%}"; + + for my $Api (@apis) + { + $Api =~ /^SAI_API_(\w+)/; + + my $api = lc($1); + + next if $api =~ /unspecified/; + + WriteSwig "sai_status_t sai_get_${api}_api(sai_${api}_api_t* out);"; + } +} + +sub CreateSaiSwigApiStructs +{ + # + # for swig api to be callable, it needs to be created as a function in + # structure, not as member + # + + WriteSwig "%include \"saitypes.h\""; + + my @apis = @{ $SAI_ENUMS{sai_api_t}{values} }; + + for my $Api (@apis) + { + $Api =~ /^SAI_API_(\w+)/; + + my $api = lc($1); + + next if $api =~ /unspecified/; + + my $structname = "sai_${api}_api_t"; + + my %struct = ExtractStructInfo($structname, "struct_"); + + WriteSwig "typedef struct _$structname {"; + + for my $member (GetStructKeysInOrder(\%struct)) + { + my $type = $struct{$member}{type}; + my $name = $struct{$member}{name}; + + if (not defined $FUNCTION_DEF{$type}) + { + LogError "function type $type is not defined for $api.$name"; + next; + } + + my $prototype = $FUNCTION_DEF{$type}; + + if (not $prototype =~ /^typedef (\S+)\(\* $type\) \((.+)\)$/) + { + LogError "failed to match function proto type $type is not defined for $api.$name"; + next; + } + + my $returntype = $1; + my $params = $2; + + WriteSwig "$returntype $name($params);"; + } + + WriteSwig "} $structname;"; + WriteSwig ""; + } + + for my $Api (@apis) + { + $Api =~ /^SAI_API_(\w+)/; + + my $api = lc($1); + + next if $api =~ /unspecified/; + + WriteSwig "%ignore sai_${api}_api_t;"; + } + + my @headers = GetHeaderFiles(); + my @exheaders = GetExperimentalHeaderFiles(); + + my @merged = (@headers, @exheaders); + + for my $header (sort @merged) + { + WriteSwig "%include \"$header\""; + } +} + # # MAIN # @@ -4296,6 +4424,10 @@ sub CreateOtherStructs CreateSerializeMethods(); +CreateSaiSwigGetApiHelperFunctions(); + +CreateSaiSwigApiStructs(); + WriteHeaderFotter(); # Test Section diff --git a/meta/style.pm b/meta/style.pm index aa2b28227..9926cb9d9 100644 --- a/meta/style.pm +++ b/meta/style.pm @@ -606,6 +606,8 @@ sub CheckMetadataSourceFiles next if $file eq "saimetadata.c"; next if $file eq "saimetadatatest.c"; + next if $file =~ /swig|wrap/; + my $data = ReadHeaderFile($file); CheckHeaderLicense($data, $file); diff --git a/meta/utils.pm b/meta/utils.pm index fea296403..68db9a227 100644 --- a/meta/utils.pm +++ b/meta/utils.pm @@ -40,6 +40,7 @@ our $warnings = 0; our $HEADER_CONTENT = ""; our $SOURCE_CONTENT = ""; our $TEST_CONTENT = ""; +our $SWIG_CONTENT = ""; my $identLevel = 0; @@ -49,7 +50,7 @@ sub GetIdent return "" if $content =~ /\\$/; return " " if $content =~ /^\s*_(In|Out)/; - return " " x --$identLevel if $content =~ /^\s*}/; + return " " x --$identLevel if $content =~ /^\s*%?}/; return " " x $identLevel++ if $content =~ /{$/; return " " x $identLevel; } @@ -81,6 +82,15 @@ sub WriteTest $TEST_CONTENT .= $ident . $content . "\n"; } +sub WriteSwig +{ + my $content = shift; + + my $ident = GetIdent($content); + + $SWIG_CONTENT .= $ident . $content . "\n"; +} + sub WriteSectionComment { my $content = shift; @@ -318,6 +328,7 @@ sub WriteMetaDataFiles WriteFile("saimetadata.h", $HEADER_CONTENT); WriteFile("saimetadata.c", $SOURCE_CONTENT); WriteFile("saimetadatatest.c", $TEST_CONTENT); + WriteFile("saiswig.i", $SWIG_CONTENT); } sub GetStructKeysInOrder @@ -362,7 +373,7 @@ BEGIN WriteFile GetHeaderFiles GetMetaHeaderFiles GetExperimentalHeaderFiles GetMetadataSourceFiles ReadHeaderFile GetNonObjectIdStructNames IsSpecialObject GetStructLists GetStructKeysInOrder Trim ExitOnErrors - WriteHeader WriteSource WriteTest WriteMetaDataFiles WriteSectionComment + WriteHeader WriteSource WriteTest WriteSwig WriteMetaDataFiles WriteSectionComment $errors $warnings $NUMBER_REGEX $HEADER_CONTENT $SOURCE_CONTENT $TEST_CONTENT /;