Skip to content

Commit

Permalink
orchagent: Fixing switch MAC logic (sonic-net#29)
Browse files Browse the repository at this point in the history
* fix switch mac logic.

If user sets the switch MAC via -m, then set the switch MAC to it.
Otherwise, get switch MAC from SAI.
  • Loading branch information
lguohan authored and stcheng committed May 23, 2016
1 parent ef9bd5d commit ad169ab
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using namespace std;
using namespace swss;

#define UNREFERENCED_PARAMETER(P) (P)
#define DEFAULT_MAC "00:11:11:11:11:00"

/* Initialize all global api pointers */
sai_switch_api_t* sai_switch_api;
Expand Down Expand Up @@ -160,20 +159,21 @@ int main(int argc, char **argv)

sai_attribute_t attr;
attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
status = sai_switch_api->get_switch_attribute(1, &attr);
if (status != SAI_STATUS_SUCCESS)
if (!gMacAddress)
{
SWSS_LOG_NOTICE("Failed to get MAC address from switch %d\n", status);
status = sai_switch_api->get_switch_attribute(1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get MAC address from switch %d\n", status);
exit(EXIT_FAILURE);
}
else
{
gMacAddress = attr.value.mac;
}
}
else
{
gMacAddress = attr.value.mac;
}

if (status != SAI_STATUS_SUCCESS || !gMacAddress)
{
gMacAddress = MacAddress(DEFAULT_MAC);

memcpy(attr.value.mac, gMacAddress.getMac(), 6);
status = sai_switch_api->set_switch_attribute(&attr);
if (status != SAI_STATUS_SUCCESS)
Expand Down

0 comments on commit ad169ab

Please sign in to comment.