From efab324f0f34b857e4ad0fd6cfbde32eb1b7f511 Mon Sep 17 00:00:00 2001 From: Junhua Zhai Date: Fri, 27 Sep 2024 12:46:53 +0000 Subject: [PATCH] 1. Add dash flow in sairedis 2. Refer to newer SAI, same as the one on DASH pipeline --- .gitmodules | 2 +- SAI | 2 +- lib/Recorder.h | 4 +++ meta/Meta.cpp | 46 +++++++++++++++++++++++++++++++ meta/Meta.h | 5 ++++ meta/SaiInterface.h | 2 ++ meta/SaiSerialize.cpp | 37 +++++++++++++++++++++++++ meta/sai_serialize.h | 7 +++++ syncd/VendorSai.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 167 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 1d075ba3a..742d7504a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "SAI"] path = SAI - url = https://github.com/opencomputeproject/SAI.git + url = https://github.com/jimmyzhai/SAI.git ignore = dirty branch = v1.3 diff --git a/SAI b/SAI index 684a8ee78..c081aed98 160000 --- a/SAI +++ b/SAI @@ -1 +1 @@ -Subproject commit 684a8ee78d4f7393e355ddc4bf1181f8aa57708e +Subproject commit c081aed98abbbfb9f4287587c5bc331bdc2155ba diff --git a/lib/Recorder.h b/lib/Recorder.h index 920ee0c7f..57f11a36c 100644 --- a/lib/Recorder.h +++ b/lib/Recorder.h @@ -178,6 +178,7 @@ namespace sairedis SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(pa_validation_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(outbound_routing_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(outbound_ca_to_pa_entry); + SAI_REDIS_RECORDER_DECLARE_RECORD_CREATE(flow_entry); public: // remove ENTRY @@ -197,6 +198,7 @@ namespace sairedis SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(pa_validation_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(outbound_routing_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(outbound_ca_to_pa_entry); + SAI_REDIS_RECORDER_DECLARE_RECORD_REMOVE(flow_entry); public: // set ENTRY @@ -216,6 +218,7 @@ namespace sairedis SAI_REDIS_RECORDER_DECLARE_RECORD_SET(pa_validation_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_SET(outbound_routing_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_SET(outbound_ca_to_pa_entry); + SAI_REDIS_RECORDER_DECLARE_RECORD_SET(flow_entry); public: // get ENTRY @@ -235,6 +238,7 @@ namespace sairedis SAI_REDIS_RECORDER_DECLARE_RECORD_GET(pa_validation_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_GET(outbound_routing_entry); SAI_REDIS_RECORDER_DECLARE_RECORD_GET(outbound_ca_to_pa_entry); + SAI_REDIS_RECORDER_DECLARE_RECORD_GET(flow_entry); public: // SAI stats API diff --git a/meta/Meta.cpp b/meta/Meta.cpp index bd3f1b010..7d8cfaa27 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -3116,6 +3116,52 @@ sai_status_t Meta::meta_sai_validate_outbound_ca_to_pa_entry( return SAI_STATUS_SUCCESS; } +sai_status_t Meta::meta_sai_validate_flow_entry( + _In_ const sai_flow_entry_t* flow_entry, + _In_ bool create, + _In_ bool get) +{ + SWSS_LOG_ENTER(); + + if (flow_entry == NULL) + { + SWSS_LOG_ERROR("flow_entry pointer is NULL"); + + return SAI_STATUS_INVALID_PARAMETER; + } + + sai_object_meta_key_t meta_key_flow_entry = { + .objecttype = (sai_object_type_t)SAI_OBJECT_TYPE_FLOW_ENTRY, + .objectkey = { + .key = { .flow_entry = *flow_entry } + } + }; + + if (create) + { + if (m_saiObjectCollection.objectExists(meta_key_flow_entry)) + { + SWSS_LOG_ERROR("object key %s already exists", + sai_serialize_object_meta_key(meta_key_flow_entry).c_str()); + + return SAI_STATUS_ITEM_ALREADY_EXISTS; + } + + return SAI_STATUS_SUCCESS; + } + + // set, get, remove + if (!m_saiObjectCollection.objectExists(meta_key_flow_entry)) + { + SWSS_LOG_ERROR("object key %s doesn't exist", + sai_serialize_object_meta_key(meta_key_flow_entry).c_str()); + + return SAI_STATUS_INVALID_PARAMETER; + } + + return SAI_STATUS_SUCCESS; +} + sai_status_t Meta::meta_generic_validation_create( _In_ const sai_object_meta_key_t& meta_key, _In_ sai_object_id_t switch_id, diff --git a/meta/Meta.h b/meta/Meta.h index 12dbf3aa7..43728bda3 100644 --- a/meta/Meta.h +++ b/meta/Meta.h @@ -553,6 +553,11 @@ namespace saimeta _In_ bool create, _In_ bool get = false); + sai_status_t meta_sai_validate_flow_entry( + _In_ const sai_flow_entry_t* flow_entry, + _In_ bool create, + _In_ bool get = false); + public: /* diff --git a/meta/SaiInterface.h b/meta/SaiInterface.h index d45e0b974..65c02b05c 100644 --- a/meta/SaiInterface.h +++ b/meta/SaiInterface.h @@ -22,6 +22,7 @@ extern "C" { _X(PA_VALIDATION_ENTRY,pa_validation_entry); \ _X(OUTBOUND_ROUTING_ENTRY,outbound_routing_entry); \ _X(OUTBOUND_CA_TO_PA_ENTRY,outbound_ca_to_pa_entry); \ + _X(FLOW_ENTRY,flow_entry); \ #define SAIREDIS_DECLARE_EVERY_BULK_ENTRY(_X) \ _X(FDB_ENTRY,fdb_entry); \ @@ -37,6 +38,7 @@ extern "C" { _X(PA_VALIDATION_ENTRY,pa_validation_entry); \ _X(OUTBOUND_ROUTING_ENTRY,outbound_routing_entry); \ _X(OUTBOUND_CA_TO_PA_ENTRY,outbound_ca_to_pa_entry); \ + _X(FLOW_ENTRY,flow_entry); \ #define SAIREDIS_SAIINTERFACE_DECLARE_QUAD_ENTRY_VIRTUAL(OT,ot) \ virtual sai_status_t create( \ diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index dd268f26a..462a3a0ba 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -1850,6 +1850,25 @@ std::string sai_serialize_outbound_ca_to_pa_entry( return j.dump(); } +std::string sai_serialize_flow_entry( + _In_ const sai_flow_entry_t &flow_entry) +{ + SWSS_LOG_ENTER(); + + json j; + + j["switch_id"] = sai_serialize_object_id(flow_entry.switch_id); + j["eni_mac"] = sai_serialize_mac(flow_entry.eni_mac); + j["vnet_id"] = sai_serialize_number(flow_entry.vnet_id); + j["ip_proto"] = sai_serialize_number(flow_entry.ip_proto); + j["src_ip"] = sai_serialize_ip_address(flow_entry.src_ip); + j["dst_ip"] = sai_serialize_ip_address(flow_entry.dst_ip); + j["src_port"] = sai_serialize_number(flow_entry.src_port); + j["dst_port"] = sai_serialize_number(flow_entry.dst_port); + + return j.dump(); +} + std::string sai_serialize_system_port_config( _In_ const sai_attr_metadata_t &meta, _In_ const sai_system_port_config_t &sysportconfig) @@ -4728,6 +4747,24 @@ void sai_deserialize_outbound_ca_to_pa_entry( sai_deserialize_ip_address(j["dip"], outbound_ca_to_pa_entry.dip); } +void sai_deserialize_flow_entry( + _In_ const std::string &s, + _Out_ sai_flow_entry_t& flow_entry) +{ + SWSS_LOG_ENTER(); + + json j = json::parse(s); + + sai_deserialize_object_id(j["switch_id"], flow_entry.switch_id); + sai_deserialize_mac(j["eni_mac"], flow_entry.eni_mac); + sai_deserialize_number(j["vnet_id"], flow_entry.vnet_id); + sai_deserialize_number(j["ip_proto"], flow_entry.ip_proto); + sai_deserialize_ip_address(j["src_ip"], flow_entry.src_ip); + sai_deserialize_ip_address(j["dst_ip"], flow_entry.dst_ip); + sai_deserialize_number(j["src_port"], flow_entry.src_port); + sai_deserialize_number(j["dst_port"], flow_entry.dst_port); +} + void sai_deserialize_attr_id( _In_ const std::string& s, _Out_ const sai_attr_metadata_t** meta) diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index d74d753e7..47730264a 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -162,6 +162,9 @@ std::string sai_serialize_outbound_routing_entry( std::string sai_serialize_outbound_ca_to_pa_entry( _In_ const sai_outbound_ca_to_pa_entry_t &outbound_ca_to_pa_entry); +std::string sai_serialize_flow_entry( + _In_ const sai_flow_entry_t &flow_entry); + void sai_deserialize_system_port_config_list( _In_ const std::string& s, _Out_ sai_system_port_config_list_t& sysportconfiglist, @@ -459,6 +462,10 @@ void sai_deserialize_outbound_ca_to_pa_entry( _In_ const std::string &s, _Out_ sai_outbound_ca_to_pa_entry_t& outbound_ca_to_pa_entry); +void sai_deserialize_flow_entry( + _In_ const std::string &s, + _Out_ sai_flow_entry_t& flow_entry); + void sai_deserialize_attr_value( _In_ const std::string& s, _In_ const sai_attr_metadata_t& meta, diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index db8aba66b..6edcbfc1d 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -998,6 +998,33 @@ sai_status_t VendorSai::bulkCreate( object_statuses); } +sai_status_t VendorSai::bulkCreate( + _In_ uint32_t object_count, + _In_ const sai_flow_entry_t* entries, + _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) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + if (!m_apis.dash_flow_api->create_flow_entries) + { + SWSS_LOG_INFO("create_flow_entries is not supported"); + return SAI_STATUS_NOT_SUPPORTED; + } + + return m_apis.dash_flow_api->create_flow_entries( + object_count, + entries, + attr_count, + attr_list, + mode, + object_statuses); +} + // BULK REMOVE sai_status_t VendorSai::bulkRemove( @@ -1300,6 +1327,29 @@ sai_status_t VendorSai::bulkRemove( object_statuses); } +sai_status_t VendorSai::bulkRemove( + _In_ uint32_t object_count, + _In_ const sai_flow_entry_t *entries, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + if (!m_apis.dash_flow_api->remove_flow_entries) + { + SWSS_LOG_INFO("remove_flow_entries is not supported"); + return SAI_STATUS_NOT_SUPPORTED; + } + + return m_apis.dash_flow_api->remove_flow_entries( + object_count, + entries, + mode, + object_statuses); +} + // BULK SET sai_status_t VendorSai::bulkSet( @@ -1550,6 +1600,20 @@ sai_status_t VendorSai::bulkSet( return SAI_STATUS_NOT_SUPPORTED; } +sai_status_t VendorSai::bulkSet( + _In_ uint32_t object_count, + _In_ const sai_flow_entry_t *entries, + _In_ const sai_attribute_t *attr_list, + _In_ sai_bulk_op_error_mode_t mode, + _Out_ sai_status_t *object_statuses) +{ + MUTEX(); + SWSS_LOG_ENTER(); + VENDOR_CHECK_API_INITIALIZED(); + + return SAI_STATUS_NOT_SUPPORTED; +} + // NON QUAD API sai_status_t VendorSai::flushFdbEntries(