forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IntfMgrd] Retry adding ipv6 prefix by setting disabled_ipv6 flag (so…
…nic-net#2267) *intfmgrd sets the flag by itself and retries setting the ip address if the ipv6 assignment fails for the first time *There might be a race condition b/w intfmgrd and Mellanox SDK where the SDK created Linux Netdev iface but still doesn't yet set disable_ipv6 flag to 0. If intfmgrd tries to assign ip to the iface, the attempt fails.
- Loading branch information
Showing
5 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "gtest/gtest.h" | ||
#include <iostream> | ||
#include <fstream> | ||
#include <unistd.h> | ||
#include <sys/stat.h> | ||
#include "../mock_table.h" | ||
#include "warm_restart.h" | ||
#define private public | ||
#include "intfmgr.h" | ||
#undef private | ||
|
||
/* Override this pointer for custom behavior */ | ||
int (*callback)(const std::string &cmd, std::string &stdout) = nullptr; | ||
std::vector<std::string> mockCallArgs; | ||
|
||
namespace swss { | ||
int exec(const std::string &cmd, std::string &stdout) | ||
{ | ||
mockCallArgs.push_back(cmd); | ||
return callback(cmd, stdout); | ||
} | ||
} | ||
|
||
bool Ethernet0IPv6Set = false; | ||
|
||
int cb(const std::string &cmd, std::string &stdout){ | ||
if (cmd == "sysctl -w net.ipv6.conf.\"Ethernet0\".disable_ipv6=0") Ethernet0IPv6Set = true; | ||
else if (cmd.find("/sbin/ip -6 address \"add\"") == 0) { | ||
return Ethernet0IPv6Set ? 0 : 2; | ||
} | ||
else { | ||
return 0; | ||
} | ||
return 0; | ||
} | ||
|
||
// Test Fixture | ||
namespace add_ipv6_prefix_ut | ||
{ | ||
struct IntfMgrTest : public ::testing::Test | ||
{ | ||
std::shared_ptr<swss::DBConnector> m_config_db; | ||
std::shared_ptr<swss::DBConnector> m_app_db; | ||
std::shared_ptr<swss::DBConnector> m_state_db; | ||
std::vector<std::string> cfg_intf_tables; | ||
|
||
virtual void SetUp() override | ||
{ | ||
testing_db::reset(); | ||
m_config_db = std::make_shared<swss::DBConnector>("CONFIG_DB", 0); | ||
m_app_db = std::make_shared<swss::DBConnector>("APPL_DB", 0); | ||
m_state_db = std::make_shared<swss::DBConnector>("STATE_DB", 0); | ||
|
||
swss::WarmStart::initialize("intfmgrd", "swss"); | ||
|
||
std::vector<std::string> tables = { | ||
CFG_INTF_TABLE_NAME, | ||
CFG_LAG_INTF_TABLE_NAME, | ||
CFG_VLAN_INTF_TABLE_NAME, | ||
CFG_LOOPBACK_INTERFACE_TABLE_NAME, | ||
CFG_VLAN_SUB_INTF_TABLE_NAME, | ||
CFG_VOQ_INBAND_INTERFACE_TABLE_NAME, | ||
}; | ||
cfg_intf_tables = tables; | ||
mockCallArgs.clear(); | ||
callback = cb; | ||
} | ||
}; | ||
|
||
TEST_F(IntfMgrTest, testSettingIpv6Flag){ | ||
Ethernet0IPv6Set = false; | ||
swss::IntfMgr intfmgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_intf_tables); | ||
/* Set portStateTable */ | ||
std::vector<swss::FieldValueTuple> values; | ||
values.emplace_back("state", "ok"); | ||
intfmgr.m_statePortTable.set("Ethernet0", values, "SET", ""); | ||
/* Set m_stateIntfTable */ | ||
values.clear(); | ||
values.emplace_back("vrf", ""); | ||
intfmgr.m_stateIntfTable.set("Ethernet0", values, "SET", ""); | ||
/* Set Ipv6 prefix */ | ||
const std::vector<std::string>& keys = {"Ethernet0", "2001::8/64"}; | ||
const std::vector<swss::FieldValueTuple> data; | ||
intfmgr.doIntfAddrTask(keys, data, "SET"); | ||
int ip_cmd_called = 0; | ||
for (auto cmd : mockCallArgs){ | ||
if (cmd.find("/sbin/ip -6 address \"add\"") == 0){ | ||
ip_cmd_called++; | ||
} | ||
} | ||
ASSERT_EQ(ip_cmd_called, 2); | ||
} | ||
|
||
TEST_F(IntfMgrTest, testNoSettingIpv6Flag){ | ||
Ethernet0IPv6Set = true; // Assuming it is already set by SDK | ||
swss::IntfMgr intfmgr(m_config_db.get(), m_app_db.get(), m_state_db.get(), cfg_intf_tables); | ||
/* Set portStateTable */ | ||
std::vector<swss::FieldValueTuple> values; | ||
values.emplace_back("state", "ok"); | ||
intfmgr.m_statePortTable.set("Ethernet0", values, "SET", ""); | ||
/* Set m_stateIntfTable */ | ||
values.clear(); | ||
values.emplace_back("vrf", ""); | ||
intfmgr.m_stateIntfTable.set("Ethernet0", values, "SET", ""); | ||
/* Set Ipv6 prefix */ | ||
const std::vector<std::string>& keys = {"Ethernet0", "2001::8/64"}; | ||
const std::vector<swss::FieldValueTuple> data; | ||
intfmgr.doIntfAddrTask(keys, data, "SET"); | ||
int ip_cmd_called = 0; | ||
for (auto cmd : mockCallArgs){ | ||
if (cmd.find("/sbin/ip -6 address \"add\"") == 0){ | ||
ip_cmd_called++; | ||
} | ||
} | ||
ASSERT_EQ(ip_cmd_called, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters