Skip to content

Commit 383ee68

Browse files
authored
[refactor]Refactoring sai handle status (#2621)
* [refactor]Refactoring sai handle status
1 parent cd95972 commit 383ee68

11 files changed

+240
-215
lines changed

orchagent/cbf/cbfnhgorch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ bool CbfNhg::sync()
343343
SWSS_LOG_ERROR("Failed to create CBF next hop group %s, rv %d",
344344
m_key.c_str(),
345345
status);
346-
task_process_status handle_status = gCbfNhgOrch->handleSaiCreateStatus(SAI_API_NEXT_HOP_GROUP, status);
346+
task_process_status handle_status = handleSaiCreateStatus(SAI_API_NEXT_HOP_GROUP, status);
347347
if (handle_status != task_success)
348348
{
349-
return gCbfNhgOrch->parseHandleSaiStatusFailure(handle_status);
349+
return parseHandleSaiStatusFailure(handle_status);
350350
}
351351
}
352352

orchagent/crmorch.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "crmorch.h"
55
#include "converter.h"
66
#include "timer.h"
7+
#include "saihelper.h"
78

89
#define CRM_POLLING_INTERVAL "polling_interval"
910
#define CRM_COUNTERS_TABLE_KEY "STATS"

orchagent/fabricportsorch.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "schema.h"
1010
#include "sai_serialize.h"
1111
#include "timer.h"
12+
#include "saihelper.h"
1213

1314
#define FABRIC_POLLING_INTERVAL_DEFAULT (30)
1415
#define FABRIC_PORT_PREFIX "PORT"

orchagent/nhgbase.h

-5
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,6 @@ class NhgOrchCommon : public Orch
451451
}
452452
inline void decSyncedNhgCount() { NhgBase::decSyncedCount(); }
453453

454-
/* Handling SAI status*/
455-
using Orch::handleSaiCreateStatus;
456-
using Orch::handleSaiRemoveStatus;
457-
using Orch::parseHandleSaiStatusFailure;
458-
459454
protected:
460455
/*
461456
* Map of synced next hop groups.

orchagent/nhgorch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,10 @@ bool NextHopGroup::sync()
576576
SWSS_LOG_ERROR("Failed to create next hop group %s, rv:%d",
577577
m_key.to_string().c_str(), status);
578578

579-
task_process_status handle_status = gNhgOrch->handleSaiCreateStatus(SAI_API_NEXT_HOP_GROUP, status);
579+
task_process_status handle_status = handleSaiCreateStatus(SAI_API_NEXT_HOP_GROUP, status);
580580
if (handle_status != task_success)
581581
{
582-
return gNhgOrch->parseHandleSaiStatusFailure(handle_status);
582+
return parseHandleSaiStatusFailure(handle_status);
583583
}
584584
}
585585

orchagent/orch.cpp

-199
Original file line numberDiff line numberDiff line change
@@ -856,205 +856,6 @@ Executor *Orch::getExecutor(string executorName)
856856
return NULL;
857857
}
858858

859-
task_process_status Orch::handleSaiCreateStatus(sai_api_t api, sai_status_t status, void *context)
860-
{
861-
/*
862-
* This function aims to provide coarse handling of failures in sairedis create
863-
* operation (i.e., notify users by throwing excepions when failures happen).
864-
* Return value: task_success - Handled the status successfully. No need to retry this SAI operation.
865-
* task_need_retry - Cannot handle the status. Need to retry the SAI operation.
866-
* task_failed - Failed to handle the status but another attempt is unlikely to resolve the failure.
867-
* TODO: 1. Add general handling logic for specific statuses (e.g., SAI_STATUS_ITEM_ALREADY_EXISTS)
868-
* 2. Develop fine-grain failure handling mechanisms and replace this coarse handling
869-
* in each orch.
870-
* 3. Take the type of sai api into consideration.
871-
*/
872-
switch (api)
873-
{
874-
case SAI_API_FDB:
875-
switch (status)
876-
{
877-
case SAI_STATUS_SUCCESS:
878-
SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiCreateStatus");
879-
return task_success;
880-
case SAI_STATUS_ITEM_ALREADY_EXISTS:
881-
/*
882-
* In FDB creation, there are scenarios where the hardware learns an FDB entry before orchagent.
883-
* In such cases, the FDB SAI creation would report the status of SAI_STATUS_ITEM_ALREADY_EXISTS,
884-
* and orchagent should ignore the error and treat it as entry was explicitly created.
885-
*/
886-
return task_success;
887-
default:
888-
SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s",
889-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
890-
abort();
891-
}
892-
break;
893-
case SAI_API_HOSTIF:
894-
switch (status)
895-
{
896-
case SAI_STATUS_SUCCESS:
897-
return task_success;
898-
case SAI_STATUS_FAILURE:
899-
/*
900-
* Host interface maybe failed due to lane not available.
901-
* In some scenarios, like SONiC virtual machine, the invalid lane may be not enabled by VM configuration,
902-
* So just ignore the failure and report an error log.
903-
*/
904-
return task_ignore;
905-
default:
906-
SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s",
907-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
908-
abort();
909-
}
910-
default:
911-
switch (status)
912-
{
913-
case SAI_STATUS_SUCCESS:
914-
SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiCreateStatus");
915-
return task_success;
916-
default:
917-
SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s",
918-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
919-
abort();
920-
}
921-
}
922-
return task_need_retry;
923-
}
924-
925-
task_process_status Orch::handleSaiSetStatus(sai_api_t api, sai_status_t status, void *context)
926-
{
927-
/*
928-
* This function aims to provide coarse handling of failures in sairedis set
929-
* operation (i.e., notify users by throwing excepions when failures happen).
930-
* Return value: task_success - Handled the status successfully. No need to retry this SAI operation.
931-
* task_need_retry - Cannot handle the status. Need to retry the SAI operation.
932-
* task_failed - Failed to handle the status but another attempt is unlikely to resolve the failure.
933-
* TODO: 1. Add general handling logic for specific statuses
934-
* 2. Develop fine-grain failure handling mechanisms and replace this coarse handling
935-
* in each orch.
936-
* 3. Take the type of sai api into consideration.
937-
*/
938-
if (status == SAI_STATUS_SUCCESS)
939-
{
940-
SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiSetStatus");
941-
return task_success;
942-
}
943-
944-
switch (api)
945-
{
946-
case SAI_API_PORT:
947-
switch (status)
948-
{
949-
case SAI_STATUS_INVALID_ATTR_VALUE_0:
950-
/*
951-
* If user gives an invalid attribute value, no need to retry or exit orchagent, just fail the current task
952-
* and let user correct the configuration.
953-
*/
954-
SWSS_LOG_ERROR("Encountered SAI_STATUS_INVALID_ATTR_VALUE_0 in set operation, task failed, SAI API: %s, status: %s",
955-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
956-
return task_failed;
957-
default:
958-
SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s",
959-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
960-
abort();
961-
}
962-
case SAI_API_TUNNEL:
963-
switch (status)
964-
{
965-
case SAI_STATUS_ATTR_NOT_SUPPORTED_0:
966-
SWSS_LOG_ERROR("Encountered SAI_STATUS_ATTR_NOT_SUPPORTED_0 in set operation, task failed, SAI API: %s, status: %s",
967-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
968-
return task_failed;
969-
default:
970-
SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s",
971-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
972-
abort();
973-
}
974-
default:
975-
SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s",
976-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
977-
abort();
978-
}
979-
980-
return task_need_retry;
981-
}
982-
983-
task_process_status Orch::handleSaiRemoveStatus(sai_api_t api, sai_status_t status, void *context)
984-
{
985-
/*
986-
* This function aims to provide coarse handling of failures in sairedis remove
987-
* operation (i.e., notify users by throwing excepions when failures happen).
988-
* Return value: task_success - Handled the status successfully. No need to retry this SAI operation.
989-
* task_need_retry - Cannot handle the status. Need to retry the SAI operation.
990-
* task_failed - Failed to handle the status but another attempt is unlikely to resolve the failure.
991-
* TODO: 1. Add general handling logic for specific statuses (e.g., SAI_STATUS_OBJECT_IN_USE,
992-
* SAI_STATUS_ITEM_NOT_FOUND)
993-
* 2. Develop fine-grain failure handling mechanisms and replace this coarse handling
994-
* in each orch.
995-
* 3. Take the type of sai api into consideration.
996-
*/
997-
switch (status)
998-
{
999-
case SAI_STATUS_SUCCESS:
1000-
SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiRemoveStatus");
1001-
return task_success;
1002-
default:
1003-
SWSS_LOG_ERROR("Encountered failure in remove operation, exiting orchagent, SAI API: %s, status: %s",
1004-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
1005-
abort();
1006-
}
1007-
return task_need_retry;
1008-
}
1009-
1010-
task_process_status Orch::handleSaiGetStatus(sai_api_t api, sai_status_t status, void *context)
1011-
{
1012-
/*
1013-
* This function aims to provide coarse handling of failures in sairedis get
1014-
* operation (i.e., notify users by throwing excepions when failures happen).
1015-
* Return value: task_success - Handled the status successfully. No need to retry this SAI operation.
1016-
* task_need_retry - Cannot handle the status. Need to retry the SAI operation.
1017-
* task_failed - Failed to handle the status but another attempt is unlikely to resolve the failure.
1018-
* TODO: 1. Add general handling logic for specific statuses
1019-
* 2. Develop fine-grain failure handling mechanisms and replace this coarse handling
1020-
* in each orch.
1021-
* 3. Take the type of sai api into consideration.
1022-
*/
1023-
switch (status)
1024-
{
1025-
case SAI_STATUS_SUCCESS:
1026-
SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiGetStatus");
1027-
return task_success;
1028-
case SAI_STATUS_NOT_IMPLEMENTED:
1029-
SWSS_LOG_ERROR("Encountered failure in get operation due to the function is not implemented, exiting orchagent, SAI API: %s",
1030-
sai_serialize_api(api).c_str());
1031-
throw std::logic_error("SAI get function not implemented");
1032-
default:
1033-
SWSS_LOG_ERROR("Encountered failure in get operation, SAI API: %s, status: %s",
1034-
sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str());
1035-
}
1036-
return task_failed;
1037-
}
1038-
1039-
bool Orch::parseHandleSaiStatusFailure(task_process_status status)
1040-
{
1041-
/*
1042-
* This function parses task process status from SAI failure handling function to whether a retry is needed.
1043-
* Return value: true - no retry is needed.
1044-
* false - retry is needed.
1045-
*/
1046-
switch (status)
1047-
{
1048-
case task_need_retry:
1049-
return false;
1050-
case task_failed:
1051-
return true;
1052-
default:
1053-
SWSS_LOG_WARN("task_process_status %d is not expected in parseHandleSaiStatusFailure", status);
1054-
}
1055-
return true;
1056-
}
1057-
1058859
void Orch2::doTask(Consumer &consumer)
1059860
{
1060861
SWSS_LOG_ENTER();

orchagent/orch.h

-7
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,6 @@ class Orch
246246
void addExecutor(Executor* executor);
247247
Executor *getExecutor(std::string executorName);
248248

249-
/* Handling SAI status*/
250-
virtual task_process_status handleSaiCreateStatus(sai_api_t api, sai_status_t status, void *context = nullptr);
251-
virtual task_process_status handleSaiSetStatus(sai_api_t api, sai_status_t status, void *context = nullptr);
252-
virtual task_process_status handleSaiRemoveStatus(sai_api_t api, sai_status_t status, void *context = nullptr);
253-
virtual task_process_status handleSaiGetStatus(sai_api_t api, sai_status_t status, void *context = nullptr);
254-
bool parseHandleSaiStatusFailure(task_process_status status);
255-
256249
ResponsePublisher m_publisher;
257250
private:
258251
void addConsumer(swss::DBConnector *db, std::string tableName, int pri = default_orch_pri);

orchagent/p4orch/tests/test_main.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ sai_my_mac_api_t *sai_my_mac_api;
8080
sai_counter_api_t *sai_counter_api;
8181
sai_generic_programmable_api_t *sai_generic_programmable_api;
8282

83+
task_process_status handleSaiCreateStatus(sai_api_t api, sai_status_t status, void *context)
84+
{
85+
return task_success;
86+
}
87+
88+
task_process_status handleSaiSetStatus(sai_api_t api, sai_status_t status, void *context)
89+
{
90+
return task_success;
91+
}
92+
93+
task_process_status handleSaiRemoveStatus(sai_api_t api, sai_status_t status, void *context)
94+
{
95+
return task_success;
96+
}
97+
98+
task_process_status handleSaiGetStatus(sai_api_t api, sai_status_t status, void *context)
99+
{
100+
return task_success;
101+
}
102+
103+
bool parseHandleSaiStatusFailure(task_process_status status)
104+
{
105+
return true;
106+
}
107+
108+
83109
namespace
84110
{
85111

0 commit comments

Comments
 (0)