From b08bf36434d436e36073eedad8cbc9e37daa0237 Mon Sep 17 00:00:00 2001 From: "shine.chen" Date: Mon, 11 Mar 2019 00:00:40 -0700 Subject: [PATCH] [intfsorch]: add support to change rif mac-address Signed-off-by: shine.chen --- orchagent/intfsorch.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 4421caae8cf..a61f71bb288 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -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 keys = tokenize(kfvKey(t), ':'); string alias(keys[0]); @@ -208,6 +212,12 @@ void IntfsOrch::doTask(Consumer &consumer) { vnet_name = value; } + else if (field == "mac_addr") + { + mac_attr_set = 1; + + mac = MacAddress(field); + } } if (alias == "eth0" || alias == "docker0") @@ -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)