Skip to content

Commit

Permalink
Add useTempView flag (sonic-net#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Nov 23, 2016
1 parent b60f4bb commit ca6a247
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 20 deletions.
5 changes: 2 additions & 3 deletions lib/inc/sai_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extern void recordLine(std::string s);
extern std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple> &values);

extern volatile bool g_useTempView;

// other global declarations

extern service_method_table_t g_services;
Expand All @@ -43,9 +45,6 @@ extern swss::ProducerTable *g_asicState;
extern swss::ConsumerTable *g_redisGetConsumer;
extern swss::NotificationConsumer *g_redisNotifications;

extern swss::Table *g_vidToRid;
extern swss::Table *g_ridToVid;

extern swss::RedisClient *g_redisClient;

extern std::mutex g_apimutex;
Expand Down
13 changes: 13 additions & 0 deletions lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {

#define SYNCD_INIT_VIEW "INIT_VIEW"
#define SYNCD_APPLY_VIEW "APPLY_VIEW"
#define ASIC_STATE_TABLE "ASIC_STATE"

typedef enum _sai_redis_notify_syncd_t
{
Expand Down Expand Up @@ -36,6 +37,18 @@ typedef enum _sai_redis_switch_attr_t
*/
SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD,

/**
* @brief Use temporary view for all actions between
* init and apply view. By default init and apply view will
* not take effect. This is temporary solution until
* comparison logic will be in place.
*
* @type bool
* @flags CREATE_AND_SET
* @default false
*/
SAI_REDIS_SWITCH_ATTR_USE_TEMP_VIEW,

} sai_redis_switch_attr_t;

#endif // __SAIREDIS__
2 changes: 1 addition & 1 deletion lib/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CPPFLAGS = -I/usr/include/sai -I$(top_srcdir) -I$(top_srcdir)/lib/inc
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib/inc -I/usr/include/sai

if DEBUG
DBGFLAGS = -ggdb -D_DEBUG_
Expand Down
3 changes: 2 additions & 1 deletion lib/src/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string.h>
#include "sai_redis.h"
#include "sairedis.h"

std::mutex g_apimutex;

Expand Down Expand Up @@ -51,7 +52,7 @@ sai_status_t sai_api_initialize(
if (g_asicState != NULL)
delete g_asicState;

g_asicState = new swss::ProducerTable(g_db, "ASIC_STATE");
g_asicState = new swss::ProducerTable(g_db, ASIC_STATE_TABLE);

if (g_redisGetConsumer != NULL)
delete g_redisGetConsumer;
Expand Down
7 changes: 7 additions & 0 deletions lib/src/sai_redis_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sai_switch_notification_t redis_switch_notifications;
bool g_switchInitialized = false;
volatile bool g_asicInitViewMode = false; // default mode is apply mode
volatile bool g_run = false;
volatile bool g_useTempView = false;

std::shared_ptr<std::thread> notification_thread;

Expand Down Expand Up @@ -122,6 +123,8 @@ sai_status_t redis_initialize_switch(

g_asicInitViewMode = false;

g_useTempView = false;

setRecording(g_record);

SWSS_LOG_DEBUG("creating notification thread");
Expand Down Expand Up @@ -373,6 +376,10 @@ sai_status_t redis_set_switch_attribute(
case SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD:
return sai_redis_notify_syncd(attr);

case SAI_REDIS_SWITCH_ATTR_USE_TEMP_VIEW:
g_useTempView = attr->value.booldata;
return SAI_STATUS_SUCCESS;

default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion saidump/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CPPFLAGS = -I/usr/include/sai
AM_CPPFLAGS = -I$(top_srcdir)/lib/inc -I/usr/include/sai

bin_PROGRAMS = saidump

Expand Down
3 changes: 2 additions & 1 deletion saidump/saidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {
#include "swss/table.h"
#include "swss/logger.h"
#include "meta/saiserialize.h"
#include "sairedis.h"

#include <getopt.h>

Expand Down Expand Up @@ -182,7 +183,7 @@ int main(int argc, char ** argv)

swss::DBConnector db(ASIC_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);

swss::Table t(&db, "ASIC_STATE");
swss::Table t(&db, ASIC_STATE_TABLE);

TableDump dump;

Expand Down
2 changes: 1 addition & 1 deletion saiplayer/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CPPFLAGS = -I/usr/include/sai -I$(top_srcdir)/lib/inc
AM_CPPFLAGS = -I$(top_srcdir)/lib/inc -I/usr/include/sai

bin_PROGRAMS = saiplayer

Expand Down
18 changes: 17 additions & 1 deletion saiplayer/saiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,10 +1208,14 @@ void printUsage()
std::cout << " Will not send notify init/apply view to syncd" << std::endl << std::endl;
std::cout << " -d --enableDebug:" << std::endl;
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 << " -h --help:" << std::endl;
std::cout << " Print out this message" << std::endl << std::endl;
}

bool g_useTempView = false;

void handleCmdLine(int argc, char **argv)
{
SWSS_LOG_ENTER();
Expand All @@ -1220,13 +1224,14 @@ void handleCmdLine(int argc, char **argv)
{
static struct option long_options[] =
{
{ "useTempView", no_argument, 0, 'u' },
{ "help", no_argument, 0, 'h' },
{ "skipNotifySyncd", no_argument, 0, 'C' },
{ "enableDebug", no_argument, 0, 'd' },
{ 0, 0, 0, 0 }
};

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

int option_index;

Expand All @@ -1241,6 +1246,10 @@ void handleCmdLine(int argc, char **argv)
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
break;

case 'u':
g_useTempView = false;
break;

case 'C':
g_notifySyncd = false;
break;
Expand Down Expand Up @@ -1279,6 +1288,13 @@ int main(int argc, char **argv)

EXIT_ON_ERROR(sai_switch_api->initialize_switch(0, "", "", &switch_notifications));

sai_attribute_t attr;

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

EXIT_ON_ERROR(sai_switch_api->set_switch_attribute(&attr));

int exitcode = replay(argc, argv);

sai_switch_api->shutdown_switch(false);
Expand Down
2 changes: 1 addition & 1 deletion syncd/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AM_CPPFLAGS = -I/usr/include/sai -I$(top_srcdir)/vslib/inc -I$(top_srcdir)/lib/inc
AM_CPPFLAGS = -I$(top_srcdir)/vslib/inc -I$(top_srcdir)/lib/inc -I/usr/include/sai

bin_PROGRAMS = syncd syncd_request_shutdown

Expand Down
21 changes: 16 additions & 5 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ sai_status_t notifySyncd(const std::string& op)
sendResponse(SAI_STATUS_NOT_IMPLEMENTED);
exit_and_notify(EXIT_FAILURE);
}

return SAI_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -928,7 +928,9 @@ swss::Logger::Priority redisGetLogLevel()
auto plevel = g_redisClient->get("LOGLEVEL");

if (plevel == NULL)
{
return swss::Logger::SWSS_NOTICE;
}

return swss::Logger::stringToPriority(*plevel);
}
Expand Down Expand Up @@ -963,6 +965,7 @@ struct cmdOptions
{
int countersThreadIntervalInSeconds;
bool diagShell;
bool useTempView;
int startType;
bool disableCountersThread;
std::string profileMapFile;
Expand All @@ -975,7 +978,7 @@ struct cmdOptions

void printUsage()
{
std::cout << "Usage: syncd [-N] [-d] [-p profile] [-i interval] [-t [cold|warm|fast]] [-h]" << std::endl;
std::cout << "Usage: syncd [-N] [-d] [-p profile] [-i interval] [-t [cold|warm|fast]] [-h] [-u]" << std::endl;
std::cout << " -N --nocounters:" << std::endl;
std::cout << " Disable counter thread" << std::endl;
std::cout << " -d --diag:" << std::endl;
Expand All @@ -986,6 +989,8 @@ void printUsage()
std::cout << " Provide counter thread interval" << std::endl;
std::cout << " -t --startType type:" << std::endl;
std::cout << " Specify cold|warm|fast start type" << std::endl;
std::cout << " -u --useTempView type:" << std::endl;
std::cout << " Use temporary view between init and apply" << std::endl;
#ifdef SAITHRIFT
std::cout << " -r --rpcserver:" << std::endl;
std::cout << " Enable rpcserver" << std::endl;
Expand All @@ -1008,15 +1013,16 @@ cmdOptions handleCmdLine(int argc, char **argv)

#ifdef SAITHRIFT
options.run_rpc_server = false;
const char* const optstring = "dNt:p:i:rm:h";
const char* const optstring = "dNt:p:i:rm:hu";
#else
const char* const optstring = "dNt:p:i:h";
const char* const optstring = "dNt:p:i:hu";
#endif // SAITHRIFT

while(true)
{
static struct option long_options[] =
{
{ "useTempView", no_argument, 0, 'u' },
{ "diag", no_argument, 0, 'd' },
{ "nocounters", no_argument, 0, 'N' },
{ "startType", required_argument, 0, 't' },
Expand All @@ -1039,6 +1045,11 @@ cmdOptions handleCmdLine(int argc, char **argv)

switch (c)
{
case 'u':
SWSS_LOG_NOTICE("enable use temp view");
options.useTempView = true;
break;

case 'N':
SWSS_LOG_NOTICE("disable counters thread");
options.disableCountersThread = true;
Expand Down Expand Up @@ -1287,7 +1298,7 @@ int main(int argc, char **argv)

updateLogLevel();

swss::ConsumerTable *asicState = new swss::ConsumerTable(db, "ASIC_STATE");
swss::ConsumerTable *asicState = new swss::ConsumerTable(db, ASIC_STATE_TABLE);
swss::NotificationConsumer *restartQuery = new swss::NotificationConsumer(db, "RESTARTQUERY");

// at the end we cant use producer consumer concept since
Expand Down
3 changes: 2 additions & 1 deletion syncd/syncd_notifications.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "syncd.h"
#include "sairedis.h"

void send_notification(
_In_ std::string op,
Expand Down Expand Up @@ -76,7 +77,7 @@ void redisPutFdbEntryToAsicView(

std::string strFdbEntry = sai_serialize_fdb_entry(fdb->fdb_entry);

std::string key = "ASIC_STATE:" + strObjectType + ":" + strFdbEntry;
std::string key = ASIC_STATE_TABLE + (":" + strObjectType + ":" + strFdbEntry);

for (const auto &e: entry)
{
Expand Down
9 changes: 5 additions & 4 deletions syncd/syncd_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <set>

#include "syncd.h"
#include "sairedis.h"

sai_uint32_t saiGetPortCount()
{
Expand Down Expand Up @@ -218,7 +219,7 @@ std::vector<std::string> redisGetAsicStateKeys()
{
SWSS_LOG_ENTER();

return g_redisClient->keys("ASIC_STATE:*");
return g_redisClient->keys(ASIC_STATE_TABLE + std::string(":*"));
}

void redisClearVidToRidMap()
Expand Down Expand Up @@ -420,7 +421,7 @@ void redisSetDummyAsicStateForRealObjectId(sai_object_id_t rid)

std::string strVid = sai_serialize_object_id(vid);

std::string strKey = "ASIC_STATE:" + strObjectType + ":" + strVid;
std::string strKey = ASIC_STATE_TABLE + (":" + strObjectType + ":" + strVid);

g_redisClient->hset(strKey, "NULL", "NULL");

Expand Down Expand Up @@ -539,7 +540,7 @@ void redisCreateDummyEntryInAsicView(sai_object_id_t objectId)

std::string strVid = sai_serialize_object_id(vid);

std::string strKey = "ASIC_STATE:" + strObjectType + ":" + strVid;
std::string strKey = ASIC_STATE_TABLE + (":" + strObjectType + ":" + strVid);

g_redisClient->hset(strKey, "NULL", "NULL");
}
Expand Down Expand Up @@ -575,7 +576,7 @@ void helperCheckVlanId()

std::string strVlanId = sai_serialize_vlan_id(vlanId);

std::string strKey = "ASIC_STATE:" + strObjectType + ":" + strVlanId;
std::string strKey = ASIC_STATE_TABLE + (":" + strObjectType + ":" + strVlanId);

g_redisClient->hset(strKey, "NULL", "NULL");
}
Expand Down

0 comments on commit ca6a247

Please sign in to comment.