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

[orchagent]: Create the switch with source MAC address #253

Merged
merged 1 commit into from
Jul 15, 2017
Merged
Changes from all commits
Commits
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
80 changes: 37 additions & 43 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,14 @@ int main(int argc, char **argv)

initSaiApi();

SWSS_LOG_NOTICE("sai_switch_api: create a switch");

vector<sai_attribute_t> switch_attrs;

sai_attribute_t switch_attr;
switch_attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
switch_attr.value.booldata = true;
switch_attrs.push_back(switch_attr);

switch_attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
switch_attr.value.ptr = (void *)on_fdb_event;
switch_attrs.push_back(switch_attr);

switch_attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
switch_attr.value.ptr = (void *)on_port_state_change;
switch_attrs.push_back(switch_attr);

switch_attr.id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
switch_attr.value.ptr = (void *)on_switch_shutdown_request;
switch_attrs.push_back(switch_attr);

sai_attribute_t attr;

/*
* NOTE: Notice that all redis attributes here are using SAI_NULL_OBJECT_ID
* as switch id, because thsoe operations don't require actual switch to be
* performed, and they should be executed before creating switch.
*/

sai_attribute_t attr;

/* Disable/enable SAI Redis recording */
if (gSairedisRecord)
{
Expand Down Expand Up @@ -227,61 +206,76 @@ int main(int argc, char **argv)
}
}

SWSS_LOG_NOTICE("Notify syncd INIT_VIEW");

attr.id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD;
attr.value.s32 = SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW;
status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to notify syncd INIT_VIEW %d", status);
SWSS_LOG_ERROR("Failed to notify syncd INIT_VIEW, rv:%d", status);
exit(EXIT_FAILURE);
}

SWSS_LOG_NOTICE("Enable redis pipeline");
SWSS_LOG_NOTICE("Notify syncd INIT_VIEW");

attr.id = SAI_REDIS_SWITCH_ATTR_USE_PIPELINE;
attr.value.booldata = true;

status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to enable redis pipeline %d", status);
SWSS_LOG_ERROR("Failed to enable redis pipeline, rv:%d", status);
exit(EXIT_FAILURE);
}
SWSS_LOG_NOTICE("Enable redis pipeline");

vector<sai_attribute_t> attrs;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;
attrs.push_back(attr);

attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
attr.value.ptr = (void *)on_fdb_event;
attrs.push_back(attr);

attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
attr.value.ptr = (void *)on_port_state_change;
attrs.push_back(attr);

attr.id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
attr.value.ptr = (void *)on_switch_shutdown_request;
attrs.push_back(attr);

if (gMacAddress)
{
attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
memcpy(attr.value.mac, gMacAddress.getMac(), 6);
attrs.push_back(attr);
}

status = sai_switch_api->create_switch(&gSwitchId, switch_attrs.size(), switch_attrs.data());
status = sai_switch_api->create_switch(&gSwitchId, attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create a switch %d", status);
SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status);
exit(EXIT_FAILURE);
}
SWSS_LOG_NOTICE("Create a switch");

attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
/* Get switch source MAC address if not provided */
if (!gMacAddress)
{
attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get MAC address from switch %d", status);
SWSS_LOG_ERROR("Failed to get MAC address from switch, rv:%d", status);
exit(EXIT_FAILURE);
}
else
{
gMacAddress = attr.value.mac;
}
Copy link
Contributor

@lguohan lguohan Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not have switchid yet, you need to move this after create_switch. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


In reply to: 127554898 [](ancestors = 127554898)

}
else
{
memcpy(attr.value.mac, gMacAddress.getMac(), 6);
status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set MAC address to switch %d", status);
exit(EXIT_FAILURE);
}
}

/* Get the default virtual router ID */
attr.id = SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID;
Expand Down