21
21
#include < net/if_arp.h>
22
22
#include < linux/if_ether.h>
23
23
24
+ #include " swss/json.hpp"
25
+
26
+ using json = nlohmann::json;
27
+
24
28
// TODO on hostif remove we should stop threads
25
29
26
30
typedef struct _hostif_info_t
@@ -45,6 +49,43 @@ std::map<std::string, std::shared_ptr<hostif_info_t>> hostif_info_map;
45
49
46
50
std::set<fdb_info_t > g_fdb_info_set;
47
51
52
+ std::string sai_vs_serialize_fdb_info (
53
+ _In_ const fdb_info_t & fi)
54
+ {
55
+ SWSS_LOG_ENTER ();
56
+
57
+ json j;
58
+
59
+ j[" port_id" ] = sai_serialize_object_id (fi.port_id );
60
+ j[" vlan_id" ] = sai_serialize_vlan_id (fi.vlan_id );
61
+ j[" bridge_port_id" ] = sai_serialize_object_id (fi.bridge_port_id );
62
+ j[" fdb_entry" ] = sai_serialize_fdb_entry (fi.fdb_entry );
63
+ j[" timestamp" ] = sai_serialize_number (fi.timestamp );
64
+
65
+ SWSS_LOG_INFO (" item: %s" , j.dump ().c_str ());
66
+
67
+ return j.dump ();
68
+ }
69
+
70
+ void sai_vs_deserialize_fdb_info (
71
+ _In_ const std::string& data,
72
+ _Out_ fdb_info_t & fi)
73
+ {
74
+ SWSS_LOG_ENTER ();
75
+
76
+ SWSS_LOG_INFO (" item: %s" , data.c_str ());
77
+
78
+ const json& j = json::parse (data);
79
+
80
+ memset (&fi, 0 , sizeof (fi));
81
+
82
+ sai_deserialize_object_id (j[" port_id" ], fi.port_id );
83
+ sai_deserialize_vlan_id (j[" vlan_id" ], fi.vlan_id );
84
+ sai_deserialize_object_id (j[" bridge_port_id" ], fi.bridge_port_id );
85
+ sai_deserialize_fdb_entry (j[" fdb_entry" ], fi.fdb_entry );
86
+ sai_deserialize_number (j[" timestamp" ], fi.timestamp );
87
+ }
88
+
48
89
void updateLocalDB (
49
90
_In_ const sai_fdb_event_notification_data_t &data,
50
91
_In_ sai_fdb_event_t fdb_event)
@@ -961,24 +1002,13 @@ bool hostif_create_tap_veth_forwarding(
961
1002
return true ;
962
1003
}
963
1004
964
- sai_status_t vs_create_hostif_int (
965
- _In_ sai_object_type_t object_type,
966
- _Out_ sai_object_id_t *hostif_id,
1005
+ sai_status_t vs_create_hostif_tap_interface (
967
1006
_In_ sai_object_id_t switch_id,
968
1007
_In_ uint32_t attr_count,
969
1008
_In_ const sai_attribute_t *attr_list)
970
1009
{
971
1010
SWSS_LOG_ENTER ();
972
1011
973
- if (g_vs_hostif_use_tap_device == false )
974
- {
975
- return vs_generic_create (object_type,
976
- hostif_id,
977
- switch_id,
978
- attr_count,
979
- attr_list);
980
- }
981
-
982
1012
// validate SAI_HOSTIF_ATTR_TYPE
983
1013
984
1014
auto attr_type = sai_metadata_get_attr_by_id (SAI_HOSTIF_ATTR_TYPE, attr_count, attr_list);
@@ -1061,6 +1091,8 @@ sai_status_t vs_create_hostif_int(
1061
1091
1062
1092
sai_attribute_t attr;
1063
1093
1094
+ memset (&attr, 0 , sizeof (attr));
1095
+
1064
1096
attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
1065
1097
1066
1098
sai_status_t status = vs_generic_get (SAI_OBJECT_TYPE_SWITCH, switch_id, 1 , &attr);
@@ -1105,7 +1137,69 @@ sai_status_t vs_create_hostif_int(
1105
1137
1106
1138
SWSS_LOG_INFO (" created tap interface %s" , name.c_str ());
1107
1139
1108
- return vs_generic_create (object_type,
1140
+ return SAI_STATUS_SUCCESS;
1141
+ }
1142
+
1143
+ sai_status_t vs_recreate_hostif_tap_interfaces (
1144
+ _In_ sai_object_id_t switch_id)
1145
+ {
1146
+ SWSS_LOG_ENTER ();
1147
+
1148
+ if (g_vs_hostif_use_tap_device == false )
1149
+ {
1150
+ return SAI_STATUS_SUCCESS;
1151
+ }
1152
+
1153
+ if (g_switch_state_map.find (switch_id) == g_switch_state_map.end ())
1154
+ {
1155
+ SWSS_LOG_ERROR (" failed to find switch %s in switch state map" , sai_serialize_object_id (switch_id).c_str ());
1156
+
1157
+ return SAI_STATUS_FAILURE;
1158
+ }
1159
+
1160
+ auto &objectHash = g_switch_state_map.at (switch_id)->objectHash .at (SAI_OBJECT_TYPE_HOSTIF);
1161
+
1162
+ SWSS_LOG_NOTICE (" attempt to recreate %zu tap devices for host interfaces" , objectHash.size ());
1163
+
1164
+ for (auto okvp: objectHash)
1165
+ {
1166
+ std::vector<sai_attribute_t > attrs;
1167
+
1168
+ for (auto akvp: okvp.second )
1169
+ {
1170
+ attrs.push_back (*akvp.second ->getAttr ());
1171
+ }
1172
+
1173
+ vs_create_hostif_tap_interface (switch_id, (uint32_t )attrs.size (), attrs.data ());
1174
+ }
1175
+
1176
+ return SAI_STATUS_SUCCESS;
1177
+ }
1178
+
1179
+ sai_status_t vs_create_hostif_int (
1180
+ _In_ sai_object_type_t object_type,
1181
+ _Out_ sai_object_id_t *hostif_id,
1182
+ _In_ sai_object_id_t switch_id,
1183
+ _In_ uint32_t attr_count,
1184
+ _In_ const sai_attribute_t *attr_list)
1185
+ {
1186
+ SWSS_LOG_ENTER ();
1187
+
1188
+ if (g_vs_hostif_use_tap_device == true )
1189
+ {
1190
+ sai_status_t status = vs_create_hostif_tap_interface (
1191
+ switch_id,
1192
+ attr_count,
1193
+ attr_list);
1194
+
1195
+ if (status != SAI_STATUS_SUCCESS)
1196
+ {
1197
+ return status;
1198
+ }
1199
+ }
1200
+
1201
+ return vs_generic_create (
1202
+ object_type,
1109
1203
hostif_id,
1110
1204
switch_id,
1111
1205
attr_count,
0 commit comments