@@ -791,7 +791,71 @@ int vs_set_dev_mac_address(
791
791
return err;
792
792
}
793
793
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)
795
859
{
796
860
SWSS_LOG_ENTER ();
797
861
@@ -825,6 +889,14 @@ int ifup(const char *dev)
825
889
{
826
890
close (s);
827
891
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
+
828
900
return 0 ;
829
901
}
830
902
@@ -1201,7 +1273,7 @@ bool hostif_create_tap_veth_forwarding(
1201
1273
1202
1274
SWSS_LOG_INFO (" interface index = %d %s\n " , sock_address.sll_ifindex , vethname.c_str ());
1203
1275
1204
- if (ifup (vethname.c_str ()))
1276
+ if (ifup (vethname.c_str (), port_id ))
1205
1277
{
1206
1278
SWSS_LOG_ERROR (" ifup failed on %s" , vethname.c_str ());
1207
1279
0 commit comments