Skip to content

Commit

Permalink
Add syncd/saiplayer feature: inspect ASIC (sonic-net#332)
Browse files Browse the repository at this point in the history
* Add syncd feature "SYNCD_INSPECT_ASIC"

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Add sairedis logic

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Fix string splitting

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Fix verify asic

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Fix OT_POSITION in vslib

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Refactor

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* saiplayer: add verify asic feature

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Compare fields and values from ASIC_DB and SAI response

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Refine verb

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Fix vid to rid

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Fix log arg numbers

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Refactor

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>

* Revert "Fix OT_POSITION in vslib"

This reverts commit 70cbad0b0b981679d2b31433aa051cd344bc79e9.

* Remove printf

Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
  • Loading branch information
qiluo-msft authored and lguohan committed Jul 10, 2018
1 parent 8585fc8 commit c808a0f
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 15 deletions.
5 changes: 4 additions & 1 deletion lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ extern "C" {

#define SYNCD_INIT_VIEW "INIT_VIEW"
#define SYNCD_APPLY_VIEW "APPLY_VIEW"
#define SYNCD_INSPECT_ASIC "SYNCD_INSPECT_ASIC"
#define ASIC_STATE_TABLE "ASIC_STATE"
#define TEMP_PREFIX "TEMP_"

typedef enum _sai_redis_notify_syncd_t
{
SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW,

SAI_REDIS_NOTIFY_SYNCD_APPLY_VIEW
SAI_REDIS_NOTIFY_SYNCD_APPLY_VIEW,

SAI_REDIS_NOTIFY_SYNCD_INSPECT_ASIC

} sai_redis_notify_syncd_t;

Expand Down
5 changes: 5 additions & 0 deletions lib/src/sai_redis_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ sai_status_t sai_redis_notify_syncd(
g_asicInitViewMode = false;
break;

case SAI_REDIS_NOTIFY_SYNCD_INSPECT_ASIC:
SWSS_LOG_NOTICE("sending syncd INSPECT ASIC");
op = SYNCD_INSPECT_ASIC;
break;

default:
SWSS_LOG_ERROR("invalid notify syncd attr value %d", attr->value.s32);
return SAI_STATUS_FAILURE;
Expand Down
34 changes: 34 additions & 0 deletions meta/saiattributelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ SaiAttributeList::SaiAttributeList(
}
}

SaiAttributeList::SaiAttributeList(
_In_ const sai_object_type_t object_type,
_In_ const std::unordered_map<std::string, std::string>& hash,
_In_ bool countOnly)
{
for (auto it = hash.begin(); it != hash.end(); it++)
{
const std::string &str_attr_id = it->first;
const std::string &str_attr_value = it->second;

if (str_attr_id == "NULL")
{
continue;
}

sai_attribute_t attr;
memset(&attr, 0, sizeof(sai_attribute_t));

sai_deserialize_attr_id(str_attr_id, attr.id);

auto meta = sai_metadata_get_attr_metadata(object_type, attr.id);

if (meta == NULL)
{
SWSS_LOG_THROW("FATAL: failed to find metadata for object type %d and attr id %d", object_type, attr.id);
}

sai_deserialize_attr_value(str_attr_value, *meta, attr, countOnly);

m_attr_list.push_back(attr);
m_attr_value_type_list.push_back(meta->attrvaluetype);
}
}

SaiAttributeList::~SaiAttributeList()
{
size_t attr_count = m_attr_list.size();
Expand Down
6 changes: 6 additions & 0 deletions meta/saiattributelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <vector>
#include <unordered_map>

#include <hiredis/hiredis.h>
#include "swss/dbconnector.h"
Expand All @@ -21,6 +22,11 @@ class SaiAttributeList
_In_ const std::vector<swss::FieldValueTuple> &values,
_In_ bool countOnly);

SaiAttributeList(
_In_ const sai_object_type_t object_type,
_In_ const std::unordered_map<std::string, std::string>& hash,
_In_ bool countOnly);

~SaiAttributeList();

sai_attribute_t* get_attr_list();
Expand Down
49 changes: 35 additions & 14 deletions saiplayer/saiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ int replay(int argc, char **argv)

SWSS_LOG_ENTER();

if (argc < 2)
if (argc == 0)
{
fprintf(stderr, "ERR: need to specify filename\n");

Expand Down Expand Up @@ -1244,13 +1244,16 @@ void printUsage()
std::cout << " Enable syslog debug messages" << std::endl << std::endl;
std::cout << " -u --useTempView:" << std::endl;
std::cout << " Enable temporary view between init and apply" << std::endl << std::endl;
std::cout << " -i --inspectAsic:" << std::endl;
std::cout << " Inspect ASIC by ASIC DB" << std::endl << std::endl;
std::cout << " -h --help:" << std::endl;
std::cout << " Print out this message" << std::endl << std::endl;
}

bool g_useTempView = false;
bool g_inspectAsic = false;

void handleCmdLine(int argc, char **argv)
int handleCmdLine(int argc, char **argv)
{
SWSS_LOG_ENTER();

Expand All @@ -1262,14 +1265,13 @@ void handleCmdLine(int argc, char **argv)
{ "help", no_argument, 0, 'h' },
{ "skipNotifySyncd", no_argument, 0, 'C' },
{ "enableDebug", no_argument, 0, 'd' },
{ "inspectAsic", no_argument, 0, 'i' },
{ 0, 0, 0, 0 }
};

const char* const optstring = "hCdu";
const char* const optstring = "hCdui";

int option_index;

int c = getopt_long(argc, argv, optstring, long_options, &option_index);
int c = getopt_long(argc, argv, optstring, long_options, 0);

if (c == -1)
break;
Expand All @@ -1288,6 +1290,10 @@ void handleCmdLine(int argc, char **argv)
g_notifySyncd = false;
break;

case 'i':
g_inspectAsic = true;
break;

case 'h':
printUsage();
exit(EXIT_SUCCESS);
Expand All @@ -1302,6 +1308,8 @@ void handleCmdLine(int argc, char **argv)
exit(EXIT_FAILURE);
}
}

return optind;
}

void sai_meta_log_syncd(
Expand Down Expand Up @@ -1340,11 +1348,11 @@ void sai_meta_log_syncd(
break;
case SAI_LOG_LEVEL_ERROR:
p = swss::Logger::SWSS_ERROR;
fprintf(stderr, "ERROR: %s: %s", func, buffer);
fprintf(stderr, "ERROR: %s: %s\n", func, buffer);
break;
case SAI_LOG_LEVEL_WARN:
p = swss::Logger::SWSS_WARN;
fprintf(stderr, "WARN: %s: %s", func, buffer);
fprintf(stderr, "WARN: %s: %s\n", func, buffer);
break;
case SAI_LOG_LEVEL_CRITICAL:
p = swss::Logger::SWSS_CRIT;
Expand All @@ -1366,7 +1374,9 @@ int main(int argc, char **argv)

swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE);

handleCmdLine(argc, argv);
int handled = handleCmdLine(argc, argv);
argc -= handled;
argv += handled;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
Expand All @@ -1380,19 +1390,30 @@ int main(int argc, char **argv)

sai_attribute_t attr;

attr.id = SAI_REDIS_SWITCH_ATTR_USE_TEMP_VIEW;
attr.value.booldata = g_useTempView;

/*
* Notice that we use null object id as switch id, which is fine since
* those attributes don't need switch.
*/

sai_object_id_t switch_id = SAI_NULL_OBJECT_ID;

EXIT_ON_ERROR(sai_metadata_sai_switch_api->set_switch_attribute(switch_id, &attr));
if (g_inspectAsic)
{
attr.id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD;
attr.value.s32 = SAI_REDIS_NOTIFY_SYNCD_INSPECT_ASIC;
EXIT_ON_ERROR(sai_metadata_sai_switch_api->set_switch_attribute(switch_id, &attr));
}

int exitcode = 0;
if (argc > 0)
{
attr.id = SAI_REDIS_SWITCH_ATTR_USE_TEMP_VIEW;
attr.value.booldata = g_useTempView;

int exitcode = replay(argc, argv);
EXIT_ON_ERROR(sai_metadata_sai_switch_api->set_switch_attribute(switch_id, &attr));

exitcode = replay(argc, argv);
}

sai_api_uninitialize();

Expand Down
Loading

0 comments on commit c808a0f

Please sign in to comment.