Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[intfsorch]:add support to change rif mac address #814

Merged
merged 25 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9326978
Merge pull request #1 from Azure/master
shine4chen Feb 13, 2019
7796b10
[intfsorch]: add support to change rif mac-address
Mar 11, 2019
af68d10
add the corresponding vs-test
leoli-nps Jun 2, 2019
2da2d4a
[vstest] update the corresponding vstest for pr#814
leoli-nps Jun 12, 2019
115f9aa
refine code according to prsunny/stcheng review
Jun 18, 2019
065c10f
fix bool value condition judgement
Jul 8, 2019
dfcae9b
[vstest] update the corresponding vstest for pr#814
leoli-nps Jul 9, 2019
d6fbb23
Merge branch 'master' of https://github.com/Azure/sonic-swss into rif…
Jul 9, 2019
4b26a95
move mac-address change code to intfGeneralTask
Jul 10, 2019
76fa655
Merge branch 'rif-change-mac' of https://github.com/shine4chen/sonic-…
Jul 10, 2019
d34689d
remove unnecessary condition statement
Jul 10, 2019
53063a0
[vstest] update the corresponding vstest for pr#814
leoli-nps Jul 10, 2019
39a5b31
minor format adjustment in intfmgr.cpp
shine4chen Jul 11, 2019
b9bed3a
Merge branch 'master' into rif-change-mac
prsunny Aug 12, 2019
b80f60c
[vstest] update the corresponding vstest for pr#814
leoli-nps Aug 15, 2019
165964a
fix the issue that intf mac can't be recovered correctly after warm-r…
Sep 9, 2019
295136b
Merge branch 'master' into rif-change-mac
shine4chen Oct 4, 2019
961ff0c
Merge branch 'master' into rif-change-mac
shine4chen Nov 16, 2019
f577cc7
reformat intmgr.h
shine4chen Nov 16, 2019
b190f4d
Update intfmgr.cpp
shine4chen Nov 16, 2019
405f413
set {mac:""} to app-db if not existed in cfg-db
shine4chen Nov 30, 2019
5484fe0
move mac variable definition down
shine4chen Nov 30, 2019
9bd1b17
Merge pull request #4 from Azure/master
shine4chen Nov 30, 2019
eff6af9
add some sleep on test case
Nov 30, 2019
7283a4c
Merge branch 'master' into rif-change-mac
shine4chen Feb 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "intfmgr.h"
#include "exec.h"
#include "shellcmd.h"
#include "macaddress.h"
#include "warm_restart.h"

using namespace std;
Expand Down Expand Up @@ -65,6 +66,20 @@ void IntfMgr::setIntfIp(const string &alias, const string &opCmd,
}
}

void IntfMgr::setIntfMac(const string &alias, const string &mac_str)
{
stringstream cmd;
string res;

cmd << IP_CMD << " link set " << alias << " address " << mac_str;

int ret = swss::exec(cmd.str(), res);
if (ret)
{
SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret);
}
}

void IntfMgr::setIntfVrf(const string &alias, const string &vrfName)
{
stringstream cmd;
Expand Down Expand Up @@ -413,7 +428,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
alias = alias.substr(0, found);
}
bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX);

string mac = "";
string vrf_name = "";
string mtu = "";
string adminStatus = "";
Expand All @@ -427,8 +442,11 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
vrf_name = value;
}

if (field == "admin_status")
else if (field == "mac_addr")
{
mac = value;
}
else if (field == "admin_status")
{
adminStatus = value;
}
Expand Down Expand Up @@ -479,6 +497,17 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
setIntfVrf(alias, vrf_name);
}

/*Set the mac of interface*/
if (!mac.empty())
{
setIntfMac(alias, mac);
}
wendani marked this conversation as resolved.
Show resolved Hide resolved
else
{
FieldValueTuple fvTuple("mac_addr", MacAddress().to_string());
data.push_back(fvTuple);
}

if (!subIntfAlias.empty())
{
if (m_subIntfList.find(subIntfAlias) == m_subIntfList.end())
Expand Down
4 changes: 4 additions & 0 deletions cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ class IntfMgr : public Orch

void setIntfIp(const std::string &alias, const std::string &opCmd, const IpPrefix &ipPrefix);
void setIntfVrf(const std::string &alias, const std::string &vrfName);
void setIntfMac(const std::string &alias, const std::string &macAddr);

bool doIntfGeneralTask(const std::vector<std::string>& keys, std::vector<FieldValueTuple> data, const std::string& op);
bool doIntfAddrTask(const std::vector<std::string>& keys, const std::vector<FieldValueTuple>& data, const std::string& op);
void doTask(Consumer &consumer);

bool isIntfStateOk(const std::string &alias);
bool isIntfCreated(const std::string &alias);
bool isIntfChangeVrf(const std::string &alias, const std::string &vrfName);
int getIntfIpCount(const std::string &alias);

void addLoopbackIntf(const std::string &alias);
void delLoopbackIntf(const std::string &alias);
void flushLoopbackIntfs(void);
Expand Down
44 changes: 43 additions & 1 deletion orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ void IntfsOrch::doTask(Consumer &consumer)
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;

vector<string> keys = tokenize(kfvKey(t), ':');
string alias(keys[0]);

Expand All @@ -436,6 +435,8 @@ void IntfsOrch::doTask(Consumer &consumer)

const vector<FieldValueTuple>& data = kfvFieldsValues(t);
string vrf_name = "", vnet_name = "", nat_zone = "";
MacAddress mac;

uint32_t mtu;
bool adminUp;
uint32_t nat_zone_id = 0;
Expand All @@ -452,6 +453,18 @@ void IntfsOrch::doTask(Consumer &consumer)
{
vnet_name = value;
}
else if (field == "mac_addr")
{
try
{
mac = MacAddress(value);
}
catch (const std::invalid_argument &e)
{
SWSS_LOG_ERROR("Invalid mac argument %s to %s()", value.c_str(), e.what());
continue;
}
}
else if (field == "nat_zone")
{
try
Expand Down Expand Up @@ -624,6 +637,35 @@ void IntfsOrch::doTask(Consumer &consumer)
}
}

if (mac)
{
/* Get mac information and update mac of the interface*/
shine4chen marked this conversation as resolved.
Show resolved Hide resolved
sai_attribute_t attr;
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t));

/*port.m_rif_id is set in setIntf(), need get port again*/
if (gPortsOrch->getPort(alias, port))
{
sai_status_t status = sai_router_intfs_api->set_router_interface_attribute(port.m_rif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, rv:%d",
mac.to_string().c_str(), port.m_alias.c_str(), status);
}
else
{
SWSS_LOG_NOTICE("Set router interface mac %s for port %s success",
mac.to_string().c_str(), port.m_alias.c_str());
}
}
else
{
SWSS_LOG_ERROR("Failed to set router interface mac %s for port %s, getPort fail",
mac.to_string().c_str(), alias.c_str());
}
}

it = consumer.m_toSync.erase(it);
}
else if (op == DEL_COMMAND)
Expand Down
Loading