Skip to content

Commit

Permalink
[vxlanmgrd]: Fix for vxlanmgrd cannot correctly work after config rel…
Browse files Browse the repository at this point in the history
…oad (sonic-net#934)

* [vxlanmgrd]: Fix for vxlanmgrd cannot correctly work after config reload

- What I did
  Clear old vxlan devices that were created at last time

- Why I did it
  1. "config reload" command will kill the swss container, which will make the vxlanmgrd loss the cache information. And to execute "ip link add xxx " command will fail after the vxlanmgrd process restart, because the vxlan device has been created.
  2. The Vnet was deleted by modifying config_db.json, and then execute "config reload" command, which will kill vxlanmgrd process. And when vxlanmgrd restart again, it will cannot receive the delete message, because the redis database also was clear after "config reload". So those vxlan devices will become garbage until the kernel restart.

- How I verified it
  Test it in Chassis topology.

Signed-off-by: Ze Gan <ganze718@gmail.com>

* Change ip addr to ip link to reduce the output

Signed-off-by: Ze Gan <ganze718@gmail.com>
  • Loading branch information
Pterosaur authored and prsunny committed Jul 9, 2019
1 parent c72f9ab commit d701ff8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
45 changes: 44 additions & 1 deletion cfgmgr/vxlanmgr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <algorithm>
#include <regex>
#include <sstream>
#include <string>
#include <net/if.h>

#include "logger.h"
Expand Down Expand Up @@ -155,6 +158,13 @@ VxlanMgr::VxlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb,
m_stateVrfTable(stateDb, STATE_VRF_TABLE_NAME),
m_stateVxlanTable(stateDb, STATE_VXLAN_TABLE_NAME)
{
// Clear old vxlan devices that were created at last time.
clearAllVxlanDevices();
}

VxlanMgr::~VxlanMgr()
{
clearAllVxlanDevices();
}

void VxlanMgr::doTask(Consumer &consumer)
Expand Down Expand Up @@ -526,5 +536,38 @@ bool VxlanMgr::deleteVxlan(const VxlanInfo & info)
return true;
}


void VxlanMgr::clearAllVxlanDevices()
{
std::string stdout;
const std::string cmd = std::string("") + IP_CMD + " link";
int ret = EXECUTE(cmd, stdout);
if (ret != 0)
{
SWSS_LOG_ERROR("Cannot get devices by command : %s", cmd.c_str());
return;
}
std::regex device_name_pattern("^\\d+:\\s+([^:]+)");
std::smatch match_result;
auto lines = tokenize(stdout, '\n');
for (const std::string & line : lines)
{
if (!std::regex_search(line, match_result, device_name_pattern))
{
continue;
}
std::string res;
std::string device_name = match_result[1];
VxlanInfo info;
if (device_name.find(VXLAN_NAME_PREFIX) == 0)
{
info.m_vxlan = device_name;
cmdDeleteVxlan(info, res);
}
else if (device_name.find(VXLAN_IF_NAME_PREFIX) == 0)
{
info.m_vxlanIf = device_name;
cmdDeleteVxlanIf(info, res);
}
}
}

3 changes: 2 additions & 1 deletion cfgmgr/vxlanmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VxlanMgr : public Orch
std::string m_vxlan;
std::string m_vxlanIf;
} VxlanInfo;

~VxlanMgr();
private:
void doTask(Consumer &consumer);

Expand All @@ -51,6 +51,7 @@ class VxlanMgr : public Orch
bool createVxlan(const VxlanInfo & info);
bool deleteVxlan(const VxlanInfo & info);

void clearAllVxlanDevices();

ProducerStateTable m_appVxlanTunnelTable,m_appVxlanTunnelMapTable;
Table m_cfgVxlanTunnelTable,m_cfgVnetTable,m_stateVrfTable,m_stateVxlanTable;
Expand Down

0 comments on commit d701ff8

Please sign in to comment.