Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling Framework : sonic-swss-common library support #309

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sivamukka
Copy link

@sivamukka sivamukka commented Sep 20, 2019

Error handling framework is responsible for notifying ASIC/SAI programming failures to the applications.
Error handling framework is responsible for notifying ASIC/SAI programming failures to the applications.

This repo defines the following classes as part of error handling feature.

  1. Error listener class: This class provides functions for applications to register and receive error notifications from error handling framework.
  2. Error map class: It converts SAI specific error codes to SWSS error codes that application can understand.

Related PRs:
sonic-net/sonic-utilities#666
sonic-net/sonic-swss#1100
sonic-net/sonic-sairedis#523

Signed-off-by: Siva Mukka ([email protected])

@@ -26,7 +26,8 @@ const TableNameSeparatorMap TableBase::tableNameSeparatorMap = {
{ CONFIG_DB, TABLE_NAME_SEPARATOR_VBAR },
{ PFC_WD_DB, TABLE_NAME_SEPARATOR_COLON },
{ FLEX_COUNTER_DB, TABLE_NAME_SEPARATOR_COLON },
{ STATE_DB, TABLE_NAME_SEPARATOR_VBAR }
{ STATE_DB, TABLE_NAME_SEPARATOR_VBAR },
{ ERROR_DB, TABLE_NAME_SEPARATOR_COLON }
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TABLE_NAME_SEPARATOR_COLON [](start = 22, length = 26)

prefer TABLE_NAME_SEPARATOR_VBAR for new comer #Closed

Copy link
Author

@sivamukka sivamukka Nov 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key format in ERROR_DB is same as in APP_DB. This is the reason why COLON was chosen instead of VBAR. As you said, ERROR_DB delimiter will be moved to VBAR when APP_DB delimiter changes to VBAR in future.

{ "SAI_STATUS_FAILURE", "SWSS_RC_FAILURE" }
};

ErrorMap &ErrorMap::getInstance()
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInstance [](start = 24, length = 11)

everything in ErrorMap is static, why we need an instance? #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed getIntance() in ErrorMap

#include "notificationconsumer.h"
#include "selectable.h"
#include "table.h"
#include <dbconnector.h>
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <dbconnector.h>
#include "dbconnector.h"
``` #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


static std::string getErrorChannelName(std::string& appTableName)
{
std::string errorChnl = "ERROR_";
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errorChnl [](start = 28, length = 9)

errorChannel #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// Filter the error notifications that the caller is not interested in.
if (!(((m_errorFlags & ERR_NOTIFY_POSITIVE_ACK) && (j["rc"] == "SWSS_RC_SUCCESS")) ||
((m_errorFlags & ERR_NOTIFY_FAIL) && (j["rc"] != "SWSS_RC_SUCCESS"))))
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)))) [](start = 86, length = 4)

Too complex in single expression. Consider split to multiple statements. #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified by splitting into two statements.

m_errorNotificationConsumer->pop(op, data, values);
SWSS_LOG_DEBUG("ErrorListener op: %s data: %s", op.c_str(), data.c_str());

json j = json::parse(data);
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse [](start = 23, length = 5)

parse [](start = 23, length = 5)

possible to throw? should we return -1? #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to return -1 here. This return code is ignored by applications processing the error (Ex: BGP). But the error can still be fetched from the error database.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean json::parse() will throw if it met some invalid input. I guess you need to catch it and return -1.


In reply to: 340924415 [](ancestors = 340924415)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return -1;
}

key = j["key"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j["key"]; [](start = 14, length = 9)

possible to throw? should we return -1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to return -1 here. This return code is ignored by applications processing the error (Ex: BGP). But the error can still be fetched from the error database.

warm_restart.cpp
warm_restart.cpp \
errormap.cpp \
errorlistener.cpp
Copy link
Contributor

@qiluo-msft qiluo-msft Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are only used in swss, how about move code to that repo? #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's placed in swss-common folder as the error listener could be in any docker. The docker that is interested in receiving the error needs to link swss-common package.

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented


return errorChnl;
return errorChannel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't put code to header files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to corresponding .cpp files


return errorChnl;
return errorChannel;
}

int getFd() { return m_errorNotificationConsumer->getFd(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont put code in headers, move to cpp file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to corresponding .cpp file

delete m_errorNotificationsDb;
}

/* Returns the Error notification corresponding to an entry in the APP_DB.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make function comments in doxygen format with brief line and then main explanation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

common/errorlistener.cpp Show resolved Hide resolved
#include "dbconnector.h"

// Error notifications of interest to the error listener
typedef enum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typedef enum _error_notify_flags_t

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


ErrorMap::SwssRC ErrorMap::getSwssRC(const std::string &swssRCStr)
{
for (auto &elem : m_swssStrToRC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use find ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used array of pairs for m_swssStrToRC instead of map, as we need functions to convert from SWSS RC string to SWSS RC code and vice versa. This is the reason why for loop is used to find the given input in the array.

/* Error mapping is not found */
SWSS_LOG_ERROR("Invalid SWSS error code %d is received", rc);

return "SWSS_RC_UNKNOWN";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used multiple times, actually you can introduce this error code and return it from map

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codes mentioned in m_swssStrToRC and m_saiToSwssRC are the codes generated by SAI and supported in error handling framework. In the case where SAI return code is not supported in error handling framework, we return UNKNOWN error code.


private:
ErrorMap() = default;
~ErrorMap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also = default,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the default constructor.

};

typedef std::map<std::string, std::string> SaiToSwssRCMap;
typedef std::vector<std::pair<std::string, SwssRC>> SwssStrToRCMap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whyt this is vector and not actual map ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used array of pairs for m_swssStrToRC instead of map, as we need functions to convert from SWSS RC string to SWSS RC code and vice versa. This is the reason why for loop is used to find the given input in the array.

If we want to use map here, then we need to have two maps one taking SWSS RC code as key and another taking SWSS RC string as key. To avoid two maps, I have used array of pairs.

{ std::make_pair("SWSS_RC_INVALID_OBJECT_ID", SWSS_RC_INVALID_OBJECT_ID)}
};

const ErrorMap::SaiToSwssRCMap ErrorMap::m_saiToSwssRC = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert to std::map

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used array of pairs for m_swssStrToRC instead of map, as we need functions to convert from SWSS RC string to SWSS RC code and vice versa. This is the reason why for loop is used to find the given input in the array.

If we want to use map here, then we need to have two maps one taking SWSS RC code as key and another taking SWSS RC string as key. To avoid two maps, I have used array of pairs.

qiluo-msft
qiluo-msft previously approved these changes Dec 11, 2019
Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please check with other reviewers.

// Error notifications of interest to the error listener
typedef enum _error_notify_flags_t
{
ERR_NOTIFY_FAIL = 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious why not have enum start from zero?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ERR_NOTIFY_NONE with value of zero to indicate that application is not interested in any notifications

Defined ERR_NOTIFY_NONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants