@@ -3,8 +3,13 @@ extern "C" {
3
3
#include " saistatus.h"
4
4
}
5
5
6
+ #include < fstream>
6
7
#include < map>
8
+ #include < sys/time.h>
9
+
7
10
#include < logger.h>
11
+ #include < sairedis.h>
12
+
8
13
#include " saihelper.h"
9
14
10
15
using namespace std ;
@@ -35,6 +40,12 @@ sai_acl_api_t* sai_acl_api;
35
40
sai_mirror_api_t * sai_mirror_api;
36
41
sai_fdb_api_t * sai_fdb_api;
37
42
43
+ extern sai_object_id_t gSwitchId ;
44
+ extern bool gSairedisRecord ;
45
+ extern bool gSwssRecord ;
46
+ extern ofstream gRecordOfs ;
47
+ extern string gRecordFile ;
48
+
38
49
map<string, string> gProfileMap ;
39
50
40
51
const char *test_profile_get_value (
@@ -140,3 +151,87 @@ void initSaiApi()
140
151
sai_log_set (SAI_API_SCHEDULER_GROUP, SAI_LOG_LEVEL_NOTICE);
141
152
sai_log_set (SAI_API_ACL, SAI_LOG_LEVEL_NOTICE);
142
153
}
154
+
155
+ string getTimestamp ()
156
+ {
157
+ char buffer[64 ];
158
+ struct timeval tv;
159
+ gettimeofday (&tv, NULL );
160
+
161
+ size_t size = strftime (buffer, 32 ," %Y-%m-%d.%T." , localtime (&tv.tv_sec ));
162
+ snprintf (&buffer[size], 32 , " %06ld" , tv.tv_usec );
163
+
164
+ return string (buffer);
165
+ }
166
+
167
+ void initSaiRedis (const string &record_location)
168
+ {
169
+ /* *
170
+ * NOTE: Notice that all Redis attributes here are using SAI_NULL_OBJECT_ID
171
+ * as the switch ID, because those operations don't require actual switch
172
+ * to be performed, and they should be executed before creating switch.
173
+ */
174
+
175
+ /* Disable/enable SAI Redis recording */
176
+ sai_attribute_t attr;
177
+ attr.id = SAI_REDIS_SWITCH_ATTR_RECORD;
178
+ attr.value .booldata = gSairedisRecord ;
179
+
180
+ sai_status_t status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
181
+ if (status != SAI_STATUS_SUCCESS)
182
+ {
183
+ SWSS_LOG_ERROR (" Failed to %s SAI Redis recording, rv:%d" ,
184
+ gSairedisRecord ? " enable" : " disable" , status);
185
+ exit (EXIT_FAILURE);
186
+ }
187
+
188
+ if (gSairedisRecord )
189
+ {
190
+ attr.id = SAI_REDIS_SWITCH_ATTR_RECORDING_OUTPUT_DIR;
191
+ attr.value .s8list .count = record_location.size ();
192
+ attr.value .s8list .list = (signed char *) record_location.c_str ();
193
+
194
+ status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
195
+ if (status != SAI_STATUS_SUCCESS)
196
+ {
197
+ SWSS_LOG_ERROR (" Failed to set SAI Redis recording output folder to %s, rv:%d" ,
198
+ record_location.c_str (), status);
199
+ exit (EXIT_FAILURE);
200
+ }
201
+ }
202
+
203
+ /* Disable/enable SwSS recording */
204
+ if (gSwssRecord )
205
+ {
206
+ gRecordFile = record_location + " /" + " swss." + getTimestamp () + " .rec" ;
207
+ gRecordOfs .open (gRecordFile );
208
+ if (!gRecordOfs .is_open ())
209
+ {
210
+ SWSS_LOG_ERROR (" Failed to open SwSS recording file %s" , gRecordFile .c_str ());
211
+ exit (EXIT_FAILURE);
212
+ }
213
+ }
214
+
215
+ attr.id = SAI_REDIS_SWITCH_ATTR_USE_PIPELINE;
216
+ attr.value .booldata = true ;
217
+
218
+ status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
219
+ if (status != SAI_STATUS_SUCCESS)
220
+ {
221
+ SWSS_LOG_ERROR (" Failed to enable redis pipeline, rv:%d" , status);
222
+ exit (EXIT_FAILURE);
223
+ }
224
+ SWSS_LOG_NOTICE (" Enable redis pipeline" );
225
+
226
+ attr.id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD;
227
+ attr.value .s32 = SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW;
228
+ status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
229
+
230
+ if (status != SAI_STATUS_SUCCESS)
231
+ {
232
+ SWSS_LOG_ERROR (" Failed to notify syncd INIT_VIEW, rv:%d" , status);
233
+ exit (EXIT_FAILURE);
234
+ }
235
+ SWSS_LOG_NOTICE (" Notify syncd INIT_VIEW" );
236
+
237
+ }
0 commit comments