Skip to content

Commit

Permalink
[vlanmgrd]: Use sonic-swss-common instead of exec redis-cli (sonic-ne…
Browse files Browse the repository at this point in the history
…t#392)

This enforces portability of vlanmgrd

Signed-off-by: Wataru Ishida <[email protected]>
  • Loading branch information
Wataru Ishida authored and Shuotian Cheng committed Nov 17, 2017
1 parent 4cb542f commit afa3e9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion cfgmgr/shellcmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define IP_CMD "/sbin/ip"
#define BRIDGE_CMD "/sbin/bridge"
#define ECHO_CMD "/bin/echo"
#define REDIS_CLI_CMD "/usr/bin/redis-cli"
#define XARGS_CMD "/usr/bin/xargs"
#define GREP_CMD "/bin/grep"
#define AWK_CMD "/usr/bin/awk"
Expand Down
26 changes: 15 additions & 11 deletions cfgmgr/vlanmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fstream>
#include <iostream>
#include <mutex>
#include <algorithm>
#include "dbconnector.h"
#include "select.h"
#include "exec.h"
Expand Down Expand Up @@ -46,17 +47,6 @@ int main(int argc, char **argv)

try
{
/*
* swss service starts after interfaces-config.service which will have
* switch_mac set.
* Dynamic switch_mac update is not supported for now.
*/
string switch_mac_str;
stringstream cmd;
cmd << REDIS_CLI_CMD << " -n " << CONFIG_DB << " hget " << " \"DEVICE_METADATA|localhost\" " << " mac";
EXEC_WITH_ERROR_THROW(cmd.str(), switch_mac_str);
gMacAddress = MacAddress(switch_mac_str);

vector<string> cfg_vlan_tables = {
CFG_VLAN_TABLE_NAME,
CFG_VLAN_MEMBER_TABLE_NAME,
Expand All @@ -66,6 +56,20 @@ int main(int argc, char **argv)
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);

/*
* swss service starts after interfaces-config.service which will have
* switch_mac set.
* Dynamic switch_mac update is not supported for now.
*/
Table table(&cfgDb, "DEVICE_METADATA", CONFIGDB_TABLE_NAME_SEPARATOR);
std::vector<FieldValueTuple> ovalues;
table.get("localhost", ovalues);
auto it = std::find_if( ovalues.begin(), ovalues.end(), [](const FieldValueTuple& t){ return t.first == "mac";} );
if ( it == ovalues.end() ) {
throw runtime_error("couldn't find MAC address of the device from config DB");
}
gMacAddress = MacAddress(it->second);

VlanMgr vlanmgr(&cfgDb, &appDb, &stateDb, cfg_vlan_tables);

std::vector<Orch *> cfgOrchList = {&vlanmgr};
Expand Down

0 comments on commit afa3e9f

Please sign in to comment.