Skip to content

Commit

Permalink
Send port status notification when creating hostif interface (sonic-n…
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and lguohan committed Nov 22, 2019
1 parent 54d2864 commit 5337490
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/src/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ sai_status_t sai_query_attribute_enum_values_capability(
recordLine("Q|attribute_enum_values_capability|SAI_STATUS_FAILURE");
}

SWSS_LOG_ERROR("Invalid response from syncd: expected 2 values, received %d", values.size());
SWSS_LOG_ERROR("Invalid response from syncd: expected 2 values, received %zu", values.size());
return SAI_STATUS_FAILURE;
}

Expand All @@ -375,7 +375,7 @@ sai_status_t sai_query_attribute_enum_values_capability(
{
if (num_capabilities != i + 1)
{
SWSS_LOG_WARN("Query returned less attributes than expected: expected %d, recieved %d");
SWSS_LOG_WARN("Query returned less attributes than expected: expected %d, recieved %d", num_capabilities, i+1);
}

break;
Expand Down Expand Up @@ -492,7 +492,7 @@ sai_status_t sai_object_type_get_availability(
recordLine("Q|object_type_get_availability|SAI_STATUS_FAILURE");
}

SWSS_LOG_ERROR("Invalid response from syncd: expected 1 value, received %d", values.size());
SWSS_LOG_ERROR("Invalid response from syncd: expected 1 value, received %zu", values.size());
return SAI_STATUS_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2883,7 +2883,7 @@ sai_status_t processAttrEnumValuesCapabilityQuery(

if (values.size() != 3)
{
SWSS_LOG_ERROR("Invalid input: expected 3 arguments, received %d", values.size());
SWSS_LOG_ERROR("Invalid input: expected 3 arguments, received %zu", values.size());
getResponse->set(sai_serialize_status(SAI_STATUS_INVALID_PARAMETER), {}, attrEnumValuesCapabilityResponse);
return SAI_STATUS_INVALID_PARAMETER;
}
Expand Down
7 changes: 7 additions & 0 deletions vslib/inc/sai_vs_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,11 @@ void processFdbInfo(
_In_ const fdb_info_t &fi,
_In_ sai_fdb_event_t fdb_event);

void update_port_oper_status(
_In_ sai_object_id_t port_id,
_In_ sai_port_oper_status_t port_oper_status);

std::shared_ptr<SwitchState> vs_get_switch_state(
_In_ sai_object_id_t switch_id);

#endif // __SAI_VS_STATE__
76 changes: 74 additions & 2 deletions vslib/src/sai_vs_hostintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,71 @@ int vs_set_dev_mac_address(
return err;
}

int ifup(const char *dev)
void send_port_up_notification(
_In_ sai_object_id_t port_id)
{
SWSS_LOG_ENTER();

sai_object_id_t switch_id = sai_switch_id_query(port_id);

if (switch_id == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_ERROR("failed to get switch OID from port id %s",
sai_serialize_object_id(port_id).c_str());
return;
}

std::shared_ptr<SwitchState> sw = vs_get_switch_state(switch_id);

if (sw == nullptr)
{
SWSS_LOG_ERROR("failed to get switch state for switch id %s",
sai_serialize_object_id(switch_id).c_str());
return;
}

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;

if (vs_switch_api.get_switch_attribute(switch_id, 1, &attr) != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to get SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY for switch %s",
sai_serialize_object_id(switch_id).c_str());
return;
}

sai_port_state_change_notification_fn callback =
(sai_port_state_change_notification_fn)attr.value.ptr;

if (callback == NULL)
{
SWSS_LOG_INFO("SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY callback is NULL");
return;
}

sai_port_oper_status_notification_t data;

data.port_id = port_id;
data.port_state = SAI_PORT_OPER_STATUS_UP;

attr.id = SAI_PORT_ATTR_OPER_STATUS;

update_port_oper_status(port_id, data.port_state);

SWSS_LOG_NOTICE("explicitly send SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY for port %s: %s (port was UP)",
sai_serialize_object_id(data.port_id).c_str(),
sai_serialize_port_oper_status(data.port_state).c_str());

// NOTE this callback should be executed from separate non blocking thread

if (callback)
callback(1, &data);
}

int ifup(
_In_ const char *dev,
_In_ sai_object_id_t port_id)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -825,6 +889,14 @@ int ifup(const char *dev)
{
close(s);

// interface status didn't changed, we need to send manual notification
// that interface status is UP but that notification would need to be
// sent after actual interface creation, since user may receive that
// notification before hostif create function will actually return,
// this can happen when syncd will be operating in synchronous mode

send_port_up_notification(port_id);

return 0;
}

Expand Down Expand Up @@ -1201,7 +1273,7 @@ bool hostif_create_tap_veth_forwarding(

SWSS_LOG_INFO("interface index = %d %s\n", sock_address.sll_ifindex, vethname.c_str());

if (ifup(vethname.c_str()))
if (ifup(vethname.c_str(), port_id))
{
SWSS_LOG_ERROR("ifup failed on %s", vethname.c_str());

Expand Down

0 comments on commit 5337490

Please sign in to comment.