Skip to content

Commit 5337490

Browse files
kcudniklguohan
authored andcommitted
Send port status notification when creating hostif interface (#535)
1 parent 54d2864 commit 5337490

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

lib/src/sai_redis_interfacequery.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ sai_status_t sai_query_attribute_enum_values_capability(
351351
recordLine("Q|attribute_enum_values_capability|SAI_STATUS_FAILURE");
352352
}
353353

354-
SWSS_LOG_ERROR("Invalid response from syncd: expected 2 values, received %d", values.size());
354+
SWSS_LOG_ERROR("Invalid response from syncd: expected 2 values, received %zu", values.size());
355355
return SAI_STATUS_FAILURE;
356356
}
357357

@@ -375,7 +375,7 @@ sai_status_t sai_query_attribute_enum_values_capability(
375375
{
376376
if (num_capabilities != i + 1)
377377
{
378-
SWSS_LOG_WARN("Query returned less attributes than expected: expected %d, recieved %d");
378+
SWSS_LOG_WARN("Query returned less attributes than expected: expected %d, recieved %d", num_capabilities, i+1);
379379
}
380380

381381
break;
@@ -492,7 +492,7 @@ sai_status_t sai_object_type_get_availability(
492492
recordLine("Q|object_type_get_availability|SAI_STATUS_FAILURE");
493493
}
494494

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

syncd/syncd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ sai_status_t processAttrEnumValuesCapabilityQuery(
28832883

28842884
if (values.size() != 3)
28852885
{
2886-
SWSS_LOG_ERROR("Invalid input: expected 3 arguments, received %d", values.size());
2886+
SWSS_LOG_ERROR("Invalid input: expected 3 arguments, received %zu", values.size());
28872887
getResponse->set(sai_serialize_status(SAI_STATUS_INVALID_PARAMETER), {}, attrEnumValuesCapabilityResponse);
28882888
return SAI_STATUS_INVALID_PARAMETER;
28892889
}

vslib/inc/sai_vs_state.h

+7
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,11 @@ void processFdbInfo(
328328
_In_ const fdb_info_t &fi,
329329
_In_ sai_fdb_event_t fdb_event);
330330

331+
void update_port_oper_status(
332+
_In_ sai_object_id_t port_id,
333+
_In_ sai_port_oper_status_t port_oper_status);
334+
335+
std::shared_ptr<SwitchState> vs_get_switch_state(
336+
_In_ sai_object_id_t switch_id);
337+
331338
#endif // __SAI_VS_STATE__

vslib/src/sai_vs_hostintf.cpp

+74-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,71 @@ int vs_set_dev_mac_address(
791791
return err;
792792
}
793793

794-
int ifup(const char *dev)
794+
void send_port_up_notification(
795+
_In_ sai_object_id_t port_id)
796+
{
797+
SWSS_LOG_ENTER();
798+
799+
sai_object_id_t switch_id = sai_switch_id_query(port_id);
800+
801+
if (switch_id == SAI_NULL_OBJECT_ID)
802+
{
803+
SWSS_LOG_ERROR("failed to get switch OID from port id %s",
804+
sai_serialize_object_id(port_id).c_str());
805+
return;
806+
}
807+
808+
std::shared_ptr<SwitchState> sw = vs_get_switch_state(switch_id);
809+
810+
if (sw == nullptr)
811+
{
812+
SWSS_LOG_ERROR("failed to get switch state for switch id %s",
813+
sai_serialize_object_id(switch_id).c_str());
814+
return;
815+
}
816+
817+
sai_attribute_t attr;
818+
819+
attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
820+
821+
if (vs_switch_api.get_switch_attribute(switch_id, 1, &attr) != SAI_STATUS_SUCCESS)
822+
{
823+
SWSS_LOG_ERROR("failed to get SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY for switch %s",
824+
sai_serialize_object_id(switch_id).c_str());
825+
return;
826+
}
827+
828+
sai_port_state_change_notification_fn callback =
829+
(sai_port_state_change_notification_fn)attr.value.ptr;
830+
831+
if (callback == NULL)
832+
{
833+
SWSS_LOG_INFO("SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY callback is NULL");
834+
return;
835+
}
836+
837+
sai_port_oper_status_notification_t data;
838+
839+
data.port_id = port_id;
840+
data.port_state = SAI_PORT_OPER_STATUS_UP;
841+
842+
attr.id = SAI_PORT_ATTR_OPER_STATUS;
843+
844+
update_port_oper_status(port_id, data.port_state);
845+
846+
SWSS_LOG_NOTICE("explicitly send SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY for port %s: %s (port was UP)",
847+
sai_serialize_object_id(data.port_id).c_str(),
848+
sai_serialize_port_oper_status(data.port_state).c_str());
849+
850+
// NOTE this callback should be executed from separate non blocking thread
851+
852+
if (callback)
853+
callback(1, &data);
854+
}
855+
856+
int ifup(
857+
_In_ const char *dev,
858+
_In_ sai_object_id_t port_id)
795859
{
796860
SWSS_LOG_ENTER();
797861

@@ -825,6 +889,14 @@ int ifup(const char *dev)
825889
{
826890
close(s);
827891

892+
// interface status didn't changed, we need to send manual notification
893+
// that interface status is UP but that notification would need to be
894+
// sent after actual interface creation, since user may receive that
895+
// notification before hostif create function will actually return,
896+
// this can happen when syncd will be operating in synchronous mode
897+
898+
send_port_up_notification(port_id);
899+
828900
return 0;
829901
}
830902

@@ -1201,7 +1273,7 @@ bool hostif_create_tap_veth_forwarding(
12011273

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

1204-
if (ifup(vethname.c_str()))
1276+
if (ifup(vethname.c_str(), port_id))
12051277
{
12061278
SWSS_LOG_ERROR("ifup failed on %s", vethname.c_str());
12071279

0 commit comments

Comments
 (0)