From afa3e9fa65fb301dd36c8ff639c0f68417e38476 Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Sat, 18 Nov 2017 04:32:39 +0900 Subject: [PATCH] [vlanmgrd]: Use sonic-swss-common instead of exec redis-cli (#392) This enforces portability of vlanmgrd Signed-off-by: Wataru Ishida --- cfgmgr/shellcmd.h | 1 - cfgmgr/vlanmgrd.cpp | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cfgmgr/shellcmd.h b/cfgmgr/shellcmd.h index e73416ff367a..520739c0df7c 100644 --- a/cfgmgr/shellcmd.h +++ b/cfgmgr/shellcmd.h @@ -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" diff --git a/cfgmgr/vlanmgrd.cpp b/cfgmgr/vlanmgrd.cpp index bdf30660b89d..6fc0ed2efd3a 100644 --- a/cfgmgr/vlanmgrd.cpp +++ b/cfgmgr/vlanmgrd.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "dbconnector.h" #include "select.h" #include "exec.h" @@ -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 cfg_vlan_tables = { CFG_VLAN_TABLE_NAME, CFG_VLAN_MEMBER_TABLE_NAME, @@ -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 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 cfgOrchList = {&vlanmgr};