Skip to content

Commit

Permalink
[intfsorch]: add support to change rif mac-address
Browse files Browse the repository at this point in the history
Signed-off-by: shine.chen <[email protected]>
  • Loading branch information
shine.chen committed Mar 19, 2019
1 parent 9326978 commit 7796b10
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ void IntfsOrch::doTask(Consumer &consumer)
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;
MacAddress mac;
int mac_attr_set;

mac_attr_set = 0;

vector<string> keys = tokenize(kfvKey(t), ':');
string alias(keys[0]);
Expand Down Expand Up @@ -208,6 +212,12 @@ void IntfsOrch::doTask(Consumer &consumer)
{
vnet_name = value;
}
else if (field == "mac_addr")
{
mac_attr_set = 1;

mac = MacAddress(value);
}
}

if (alias == "eth0" || alias == "docker0")
Expand Down Expand Up @@ -299,6 +309,31 @@ void IntfsOrch::doTask(Consumer &consumer)
}
}

if (mac_attr_set == 1)
{
auto it_intfs = m_syncdIntfses.find(alias);
if (it_intfs != m_syncdIntfses.end())
{
/* Get mac information and update mac of the interface*/
sai_attribute_t attr;

attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
memcpy(attr.value.mac, mac.getMac(), sizeof(sai_mac_t));

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());
}
}
}

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

0 comments on commit 7796b10

Please sign in to comment.