1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdint.h>
9 #include <unistd.h>
10
11 #include "test.h"
12
13 #include <rte_cycles.h>
14 #include <rte_meter.h>
15
16 #define mlog(format, ...) do{\
17 printf("Line %d:",__LINE__);\
18 printf(format, ##__VA_ARGS__);\
19 printf("\n");\
20 }while(0);
21
22 #define melog(format, ...) do{\
23 printf("Line %d:",__LINE__);\
24 printf(format, ##__VA_ARGS__);\
25 printf(" failed!\n");\
26 return -1;\
27 }while(0);
28
29 #define TM_TEST_SRTCM_CIR_DF 46000000
30 #define TM_TEST_SRTCM_CBS_DF 2048
31 #define TM_TEST_SRTCM_EBS_DF 4096
32
33 #define TM_TEST_TRTCM_CIR_DF 46000000
34 #define TM_TEST_TRTCM_PIR_DF 69000000
35 #define TM_TEST_TRTCM_EIR_DF 69000000
36 #define TM_TEST_TRTCM_CBS_DF 2048
37 #define TM_TEST_TRTCM_PBS_DF 4096
38 #define TM_TEST_TRTCM_EBS_DF 4096
39
40 static struct rte_meter_srtcm_params sparams =
41 {.cir = TM_TEST_SRTCM_CIR_DF,
42 .cbs = TM_TEST_SRTCM_CBS_DF,
43 .ebs = TM_TEST_SRTCM_EBS_DF,};
44
45 static struct rte_meter_trtcm_params tparams=
46 {.cir = TM_TEST_TRTCM_CIR_DF,
47 .pir = TM_TEST_TRTCM_PIR_DF,
48 .cbs = TM_TEST_TRTCM_CBS_DF,
49 .pbs = TM_TEST_TRTCM_PBS_DF,};
50
51 static struct rte_meter_trtcm_rfc4115_params rfc4115params =
52 {.cir = TM_TEST_TRTCM_CIR_DF,
53 .eir = TM_TEST_TRTCM_EIR_DF,
54 .cbs = TM_TEST_TRTCM_CBS_DF,
55 .ebs = TM_TEST_TRTCM_EBS_DF,};
56
57 /**
58 * functional test for rte_meter_srtcm_config
59 */
60 static inline int
tm_test_srtcm_config(void)61 tm_test_srtcm_config(void)
62 {
63 #define SRTCM_CFG_MSG "srtcm_config"
64 struct rte_meter_srtcm_profile sp;
65 struct rte_meter_srtcm_params sparams1;
66
67 /* invalid parameter test */
68 if (rte_meter_srtcm_profile_config(NULL, NULL) == 0)
69 melog(SRTCM_CFG_MSG);
70 if (rte_meter_srtcm_profile_config(&sp, NULL) == 0)
71 melog(SRTCM_CFG_MSG);
72 if (rte_meter_srtcm_profile_config(NULL, &sparams) == 0)
73 melog(SRTCM_CFG_MSG);
74
75 /* cbs and ebs can't both be zero */
76 sparams1 = sparams;
77 sparams1.cbs = 0;
78 sparams1.ebs = 0;
79 if (rte_meter_srtcm_profile_config(&sp, &sparams1) == 0)
80 melog(SRTCM_CFG_MSG);
81
82 /* cir should never be 0 */
83 sparams1 = sparams;
84 sparams1.cir = 0;
85 if (rte_meter_srtcm_profile_config(&sp, &sparams1) == 0)
86 melog(SRTCM_CFG_MSG);
87
88 /* one of ebs and cbs can be zero, should be successful */
89 sparams1 = sparams;
90 sparams1.ebs = 0;
91 if (rte_meter_srtcm_profile_config(&sp, &sparams1) != 0)
92 melog(SRTCM_CFG_MSG);
93
94 sparams1 = sparams;
95 sparams1.cbs = 0;
96 if (rte_meter_srtcm_profile_config(&sp, &sparams1) != 0)
97 melog(SRTCM_CFG_MSG);
98
99 /* usual parameter, should be successful */
100 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
101 melog(SRTCM_CFG_MSG);
102
103 return 0;
104
105 }
106
107 /**
108 * functional test for rte_meter_trtcm_config
109 */
110 static inline int
tm_test_trtcm_config(void)111 tm_test_trtcm_config(void)
112 {
113 struct rte_meter_trtcm_profile tp;
114 struct rte_meter_trtcm_params tparams1;
115 #define TRTCM_CFG_MSG "trtcm_config"
116
117 /* invalid parameter test */
118 if (rte_meter_trtcm_profile_config(NULL, NULL) == 0)
119 melog(TRTCM_CFG_MSG);
120 if (rte_meter_trtcm_profile_config(&tp, NULL) == 0)
121 melog(TRTCM_CFG_MSG);
122 if (rte_meter_trtcm_profile_config(NULL, &tparams) == 0)
123 melog(TRTCM_CFG_MSG);
124
125 /* cir, cbs, pir and pbs never be zero */
126 tparams1 = tparams;
127 tparams1.cir = 0;
128 if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
129 melog(TRTCM_CFG_MSG);
130
131 tparams1 = tparams;
132 tparams1.cbs = 0;
133 if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
134 melog(TRTCM_CFG_MSG);
135
136 tparams1 = tparams;
137 tparams1.pbs = 0;
138 if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
139 melog(TRTCM_CFG_MSG);
140
141 tparams1 = tparams;
142 tparams1.pir = 0;
143 if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
144 melog(TRTCM_CFG_MSG);
145
146 /* pir should be greater or equal to cir */
147 tparams1 = tparams;
148 tparams1.pir = tparams1.cir - 1;
149 if (rte_meter_trtcm_profile_config(&tp, &tparams1) == 0)
150 melog(TRTCM_CFG_MSG" pir < cir test");
151
152 /* usual parameter, should be successful */
153 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
154 melog(TRTCM_CFG_MSG);
155
156 return 0;
157 }
158
159 /**
160 * functional test for rte_meter_trtcm_rfc4115_config
161 */
162 static inline int
tm_test_trtcm_rfc4115_config(void)163 tm_test_trtcm_rfc4115_config(void)
164 {
165 struct rte_meter_trtcm_rfc4115_profile tp;
166 struct rte_meter_trtcm_rfc4115_params rfc4115params1;
167 #define TRTCM_RFC4115_CFG_MSG "trtcm_rfc4115_config"
168
169 /* invalid parameter test */
170 if (rte_meter_trtcm_rfc4115_profile_config(NULL, NULL) == 0)
171 melog(TRTCM_RFC4115_CFG_MSG);
172 if (rte_meter_trtcm_rfc4115_profile_config(&tp, NULL) == 0)
173 melog(TRTCM_RFC4115_CFG_MSG);
174 if (rte_meter_trtcm_rfc4115_profile_config(NULL, &rfc4115params) == 0)
175 melog(TRTCM_RFC4115_CFG_MSG);
176
177 /*
178 * cbs and pbs should be none-zero if cir and eir are none-zero
179 * respectively
180 */
181 rfc4115params1 = rfc4115params;
182 rfc4115params1.cbs = 0;
183 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params1) == 0)
184 melog(TRTCM_RFC4115_CFG_MSG);
185
186 rfc4115params1 = rfc4115params;
187 rfc4115params1.ebs = 0;
188 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params1) == 0)
189 melog(TRTCM_RFC4115_CFG_MSG);
190
191 /* usual parameter, should be successful */
192 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
193 melog(TRTCM_RFC4115_CFG_MSG);
194
195 return 0;
196 }
197
198 /**
199 * functional test for rte_meter_srtcm_color_blind_check
200 */
201 static inline int
tm_test_srtcm_color_blind_check(void)202 tm_test_srtcm_color_blind_check(void)
203 {
204 #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
205 struct rte_meter_srtcm_profile sp;
206 struct rte_meter_srtcm sm;
207 uint64_t time;
208 uint64_t hz = rte_get_tsc_hz();
209
210 /* Test green */
211 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
212 melog(SRTCM_BLIND_CHECK_MSG);
213 if (rte_meter_srtcm_config(&sm, &sp) != 0)
214 melog(SRTCM_BLIND_CHECK_MSG);
215 time = rte_get_tsc_cycles() + hz;
216 if (rte_meter_srtcm_color_blind_check(
217 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF - 1)
218 != RTE_COLOR_GREEN)
219 melog(SRTCM_BLIND_CHECK_MSG" GREEN");
220
221 /* Test yellow */
222 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
223 melog(SRTCM_BLIND_CHECK_MSG);
224 if (rte_meter_srtcm_config(&sm, &sp) != 0)
225 melog(SRTCM_BLIND_CHECK_MSG);
226 time = rte_get_tsc_cycles() + hz;
227 if (rte_meter_srtcm_color_blind_check(
228 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF + 1)
229 != RTE_COLOR_YELLOW)
230 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
231
232 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
233 melog(SRTCM_BLIND_CHECK_MSG);
234 if (rte_meter_srtcm_config(&sm, &sp) != 0)
235 melog(SRTCM_BLIND_CHECK_MSG);
236 time = rte_get_tsc_cycles() + hz;
237 if (rte_meter_srtcm_color_blind_check(
238 &sm, &sp, time, (uint32_t)sp.ebs - 1) != RTE_COLOR_YELLOW)
239 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
240
241 /* Test red */
242 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
243 melog(SRTCM_BLIND_CHECK_MSG);
244 if (rte_meter_srtcm_config(&sm, &sp) != 0)
245 melog(SRTCM_BLIND_CHECK_MSG);
246 time = rte_get_tsc_cycles() + hz;
247 if (rte_meter_srtcm_color_blind_check(
248 &sm, &sp, time, TM_TEST_SRTCM_EBS_DF + 1)
249 != RTE_COLOR_RED)
250 melog(SRTCM_BLIND_CHECK_MSG" RED");
251
252 return 0;
253
254 }
255
256 /**
257 * functional test for rte_meter_trtcm_color_blind_check
258 */
259 static inline int
tm_test_trtcm_color_blind_check(void)260 tm_test_trtcm_color_blind_check(void)
261 {
262 #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
263
264 uint64_t time;
265 struct rte_meter_trtcm_profile tp;
266 struct rte_meter_trtcm tm;
267 uint64_t hz = rte_get_tsc_hz();
268
269 /* Test green */
270 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
271 melog(TRTCM_BLIND_CHECK_MSG);
272 if (rte_meter_trtcm_config(&tm, &tp) != 0)
273 melog(TRTCM_BLIND_CHECK_MSG);
274 time = rte_get_tsc_cycles() + hz;
275 if (rte_meter_trtcm_color_blind_check(
276 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1)
277 != RTE_COLOR_GREEN)
278 melog(TRTCM_BLIND_CHECK_MSG" GREEN");
279
280 /* Test yellow */
281 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
282 melog(TRTCM_BLIND_CHECK_MSG);
283 if (rte_meter_trtcm_config(&tm, &tp) != 0)
284 melog(TRTCM_BLIND_CHECK_MSG);
285 time = rte_get_tsc_cycles() + hz;
286 if (rte_meter_trtcm_color_blind_check(
287 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1)
288 != RTE_COLOR_YELLOW)
289 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
290
291 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
292 melog(TRTCM_BLIND_CHECK_MSG);
293 if (rte_meter_trtcm_config(&tm, &tp) != 0)
294 melog(TRTCM_BLIND_CHECK_MSG);
295 time = rte_get_tsc_cycles() + hz;
296 if (rte_meter_trtcm_color_blind_check(
297 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF - 1)
298 != RTE_COLOR_YELLOW)
299 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
300
301 /* Test red */
302 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
303 melog(TRTCM_BLIND_CHECK_MSG);
304 if (rte_meter_trtcm_config(&tm, &tp) != 0)
305 melog(TRTCM_BLIND_CHECK_MSG);
306 time = rte_get_tsc_cycles() + hz;
307 if (rte_meter_trtcm_color_blind_check(
308 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF + 1)
309 != RTE_COLOR_RED)
310 melog(TRTCM_BLIND_CHECK_MSG" RED");
311
312 return 0;
313 }
314
315 /**
316 * functional test for rte_meter_trtcm_rfc4115_color_blind_check
317 */
318 static inline int
tm_test_trtcm_rfc4115_color_blind_check(void)319 tm_test_trtcm_rfc4115_color_blind_check(void)
320 {
321 #define TRTCM_RFC4115_BLIND_CHECK_MSG "trtcm_rfc4115_blind_check"
322
323 uint64_t time;
324 struct rte_meter_trtcm_rfc4115_profile tp;
325 struct rte_meter_trtcm_rfc4115 tm;
326 uint64_t hz = rte_get_tsc_hz();
327
328 /* Test green */
329 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
330 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
331 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
332 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
333 time = rte_get_tsc_cycles() + hz;
334 if (rte_meter_trtcm_rfc4115_color_blind_check(
335 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1)
336 != RTE_COLOR_GREEN)
337 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" GREEN");
338
339 /* Test yellow */
340 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
341 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
342 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
343 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
344 time = rte_get_tsc_cycles() + hz;
345 if (rte_meter_trtcm_rfc4115_color_blind_check(
346 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1)
347 != RTE_COLOR_YELLOW)
348 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" YELLOW");
349
350 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
351 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
352 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
353 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
354 time = rte_get_tsc_cycles() + hz;
355 if (rte_meter_trtcm_rfc4115_color_blind_check(
356 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF - 1)
357 != RTE_COLOR_YELLOW)
358 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" YELLOW");
359
360 /* Test red */
361 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
362 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
363 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
364 melog(TRTCM_RFC4115_BLIND_CHECK_MSG);
365 time = rte_get_tsc_cycles() + hz;
366 if (rte_meter_trtcm_rfc4115_color_blind_check(
367 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF + 1)
368 != RTE_COLOR_RED)
369 melog(TRTCM_RFC4115_BLIND_CHECK_MSG" RED");
370
371 return 0;
372 }
373
374
375 /**
376 * @in[4] : the flags packets carries.
377 * @in[4] : the flags function expect to return.
378 * It will do blind check at the time of 1 second from beginning.
379 * At the time, it will use packets length of cbs -1, cbs + 1,
380 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
381 * aware check, expect flag out[0], out[1], out[2] and out[3]
382 */
383
384 static inline int
tm_test_srtcm_aware_check(enum rte_color in[4],enum rte_color out[4])385 tm_test_srtcm_aware_check
386 (enum rte_color in[4], enum rte_color out[4])
387 {
388 #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
389 struct rte_meter_srtcm_profile sp;
390 struct rte_meter_srtcm sm;
391 uint64_t time;
392 uint64_t hz = rte_get_tsc_hz();
393
394 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
395 melog(SRTCM_AWARE_CHECK_MSG);
396 if (rte_meter_srtcm_config(&sm, &sp) != 0)
397 melog(SRTCM_AWARE_CHECK_MSG);
398 time = rte_get_tsc_cycles() + hz;
399 if (rte_meter_srtcm_color_aware_check(
400 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF - 1, in[0]) != out[0])
401 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
402
403 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
404 melog(SRTCM_AWARE_CHECK_MSG);
405 if (rte_meter_srtcm_config(&sm, &sp) != 0)
406 melog(SRTCM_AWARE_CHECK_MSG);
407 time = rte_get_tsc_cycles() + hz;
408 if (rte_meter_srtcm_color_aware_check(
409 &sm, &sp, time, TM_TEST_SRTCM_CBS_DF + 1, in[1]) != out[1])
410 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
411
412 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
413 melog(SRTCM_AWARE_CHECK_MSG);
414 if (rte_meter_srtcm_config(&sm, &sp) != 0)
415 melog(SRTCM_AWARE_CHECK_MSG);
416 time = rte_get_tsc_cycles() + hz;
417 if (rte_meter_srtcm_color_aware_check(
418 &sm, &sp, time, TM_TEST_SRTCM_EBS_DF - 1, in[2]) != out[2])
419 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
420
421 if (rte_meter_srtcm_profile_config(&sp, &sparams) != 0)
422 melog(SRTCM_AWARE_CHECK_MSG);
423 if (rte_meter_srtcm_config(&sm, &sp) != 0)
424 melog(SRTCM_AWARE_CHECK_MSG);
425 time = rte_get_tsc_cycles() + hz;
426 if (rte_meter_srtcm_color_aware_check(
427 &sm, &sp, time, TM_TEST_SRTCM_EBS_DF + 1, in[3]) != out[3])
428 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
429
430 return 0;
431 }
432
433
434 /**
435 * functional test for rte_meter_srtcm_color_aware_check
436 */
437 static inline int
tm_test_srtcm_color_aware_check(void)438 tm_test_srtcm_color_aware_check(void)
439 {
440 enum rte_color in[4], out[4];
441
442 /**
443 * test 4 points that will produce green, yellow, yellow, red flag
444 * if using blind check
445 */
446
447 /* previously have a green, test points should keep unchanged */
448 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
449 out[0] = RTE_COLOR_GREEN;
450 out[1] = RTE_COLOR_YELLOW;
451 out[2] = RTE_COLOR_YELLOW;
452 out[3] = RTE_COLOR_RED;
453 if (tm_test_srtcm_aware_check(in, out) != 0)
454 return -1;
455
456 /**
457 * previously have a yellow, green & yellow = yellow
458 * yellow & red = red
459 */
460 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
461 out[0] = RTE_COLOR_YELLOW;
462 out[1] = RTE_COLOR_YELLOW;
463 out[2] = RTE_COLOR_YELLOW;
464 out[3] = RTE_COLOR_RED;
465 if (tm_test_srtcm_aware_check(in, out) != 0)
466 return -1;
467
468 /**
469 * previously have a red, red & green = red
470 * red & yellow = red
471 */
472 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
473 out[0] = RTE_COLOR_RED;
474 out[1] = RTE_COLOR_RED;
475 out[2] = RTE_COLOR_RED;
476 out[3] = RTE_COLOR_RED;
477 if (tm_test_srtcm_aware_check(in, out) != 0)
478 return -1;
479
480 return 0;
481 }
482
483 /**
484 * @in[4] : the flags packets carries.
485 * @in[4] : the flags function expect to return.
486 * It will do blind check at the time of 1 second from beginning.
487 * At the time, it will use packets length of cbs -1, cbs + 1,
488 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
489 * aware check, expect flag out[0], out[1], out[2] and out[3]
490 */
491 static inline int
tm_test_trtcm_aware_check(enum rte_color in[4],enum rte_color out[4])492 tm_test_trtcm_aware_check
493 (enum rte_color in[4], enum rte_color out[4])
494 {
495 #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
496 struct rte_meter_trtcm_profile tp;
497 struct rte_meter_trtcm tm;
498 uint64_t time;
499 uint64_t hz = rte_get_tsc_hz();
500
501 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
502 melog(TRTCM_AWARE_CHECK_MSG);
503 if (rte_meter_trtcm_config(&tm, &tp) != 0)
504 melog(TRTCM_AWARE_CHECK_MSG);
505 time = rte_get_tsc_cycles() + hz;
506 if (rte_meter_trtcm_color_aware_check(
507 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
508 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
509
510 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
511 melog(TRTCM_AWARE_CHECK_MSG);
512 if (rte_meter_trtcm_config(&tm, &tp) != 0)
513 melog(TRTCM_AWARE_CHECK_MSG);
514 time = rte_get_tsc_cycles() + hz;
515 if (rte_meter_trtcm_color_aware_check(
516 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
517 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
518
519 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
520 melog(TRTCM_AWARE_CHECK_MSG);
521 if (rte_meter_trtcm_config(&tm, &tp) != 0)
522 melog(TRTCM_AWARE_CHECK_MSG);
523 time = rte_get_tsc_cycles() + hz;
524 if (rte_meter_trtcm_color_aware_check(
525 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF - 1, in[2]) != out[2])
526 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
527
528 if (rte_meter_trtcm_profile_config(&tp, &tparams) != 0)
529 melog(TRTCM_AWARE_CHECK_MSG);
530 if (rte_meter_trtcm_config(&tm, &tp) != 0)
531 melog(TRTCM_AWARE_CHECK_MSG);
532 time = rte_get_tsc_cycles() + hz;
533 if (rte_meter_trtcm_color_aware_check(
534 &tm, &tp, time, TM_TEST_TRTCM_PBS_DF + 1, in[3]) != out[3])
535 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
536
537 return 0;
538 }
539
540
541 /**
542 * functional test for rte_meter_trtcm_color_aware_check
543 */
544
545 static inline int
tm_test_trtcm_color_aware_check(void)546 tm_test_trtcm_color_aware_check(void)
547 {
548 enum rte_color in[4], out[4];
549 /**
550 * test 4 points that will produce green, yellow, yellow, red flag
551 * if using blind check
552 */
553
554 /* previously have a green, test points should keep unchanged */
555 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
556 out[0] = RTE_COLOR_GREEN;
557 out[1] = RTE_COLOR_YELLOW;
558 out[2] = RTE_COLOR_YELLOW;
559 out[3] = RTE_COLOR_RED;
560 if (tm_test_trtcm_aware_check(in, out) != 0)
561 return -1;
562
563 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
564 out[0] = RTE_COLOR_YELLOW;
565 out[1] = RTE_COLOR_YELLOW;
566 out[2] = RTE_COLOR_YELLOW;
567 out[3] = RTE_COLOR_RED;
568 if (tm_test_trtcm_aware_check(in, out) != 0)
569 return -1;
570
571 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
572 out[0] = RTE_COLOR_RED;
573 out[1] = RTE_COLOR_RED;
574 out[2] = RTE_COLOR_RED;
575 out[3] = RTE_COLOR_RED;
576 if (tm_test_trtcm_aware_check(in, out) != 0)
577 return -1;
578
579 return 0;
580 }
581
582 /**
583 * @in[4] : the flags packets carries.
584 * @in[4] : the flags function expect to return.
585 * It will do blind check at the time of 1 second from beginning.
586 * At the time, it will use packets length of cbs -1, cbs + 1,
587 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
588 * aware check, expect flag out[0], out[1], out[2] and out[3]
589 */
590 static inline int
tm_test_trtcm_rfc4115_aware_check(enum rte_color in[4],enum rte_color out[4])591 tm_test_trtcm_rfc4115_aware_check
592 (enum rte_color in[4], enum rte_color out[4])
593 {
594 #define TRTCM_RFC4115_AWARE_CHECK_MSG "trtcm_rfc4115_aware_check"
595 struct rte_meter_trtcm_rfc4115_profile tp;
596 struct rte_meter_trtcm_rfc4115 tm;
597 uint64_t time;
598 uint64_t hz = rte_get_tsc_hz();
599
600 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
601 melog(TRTCM_AWARE_CHECK_MSG);
602 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
603 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
604 time = rte_get_tsc_cycles() + hz;
605 if (rte_meter_trtcm_rfc4115_color_aware_check(
606 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
607 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
608
609 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
610 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
611 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
612 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
613 time = rte_get_tsc_cycles() + hz;
614 if (rte_meter_trtcm_rfc4115_color_aware_check(
615 &tm, &tp, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
616 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
617
618 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
619 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
620 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
621 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
622 time = rte_get_tsc_cycles() + hz;
623 if (rte_meter_trtcm_rfc4115_color_aware_check(
624 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF - 1, in[2]) != out[2])
625 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
626
627 if (rte_meter_trtcm_rfc4115_profile_config(&tp, &rfc4115params) != 0)
628 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
629 if (rte_meter_trtcm_rfc4115_config(&tm, &tp) != 0)
630 melog(TRTCM_RFC4115_AWARE_CHECK_MSG);
631 time = rte_get_tsc_cycles() + hz;
632 if (rte_meter_trtcm_rfc4115_color_aware_check(
633 &tm, &tp, time, TM_TEST_TRTCM_EBS_DF + 1, in[3]) != out[3])
634 melog(TRTCM_RFC4115_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
635
636 return 0;
637 }
638
639 /**
640 * functional test for rte_meter_trtcm_rfc4115_color_aware_check
641 */
642 static inline int
tm_test_trtcm_rfc4115_color_aware_check(void)643 tm_test_trtcm_rfc4115_color_aware_check(void)
644 {
645 enum rte_color in[4], out[4];
646 /**
647 * test 4 points that will produce green, yellow, yellow, red flag
648 * if using blind check
649 */
650
651 /* previously have a green, test points should keep unchanged */
652 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_GREEN;
653 out[0] = RTE_COLOR_GREEN;
654 out[1] = RTE_COLOR_YELLOW;
655 out[2] = RTE_COLOR_YELLOW;
656 out[3] = RTE_COLOR_RED;
657 if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
658 return -1;
659
660 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_YELLOW;
661 out[0] = RTE_COLOR_YELLOW;
662 out[1] = RTE_COLOR_YELLOW;
663 out[2] = RTE_COLOR_YELLOW;
664 out[3] = RTE_COLOR_RED;
665 if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
666 return -1;
667
668 in[0] = in[1] = in[2] = in[3] = RTE_COLOR_RED;
669 out[0] = RTE_COLOR_RED;
670 out[1] = RTE_COLOR_RED;
671 out[2] = RTE_COLOR_RED;
672 out[3] = RTE_COLOR_RED;
673 if (tm_test_trtcm_rfc4115_aware_check(in, out) != 0)
674 return -1;
675
676 return 0;
677 }
678
679 /**
680 * test main entrance for library meter
681 */
682 static int
test_meter(void)683 test_meter(void)
684 {
685 if (tm_test_srtcm_config() != 0)
686 return -1;
687
688 if (tm_test_trtcm_config() != 0)
689 return -1;
690
691 if (tm_test_trtcm_rfc4115_config() != 0)
692 return -1;
693
694 if (tm_test_srtcm_color_blind_check() != 0)
695 return -1;
696
697 if (tm_test_trtcm_color_blind_check() != 0)
698 return -1;
699
700 if (tm_test_trtcm_rfc4115_color_blind_check() != 0)
701 return -1;
702
703 if (tm_test_srtcm_color_aware_check() != 0)
704 return -1;
705
706 if (tm_test_trtcm_color_aware_check() != 0)
707 return -1;
708
709 if (tm_test_trtcm_rfc4115_color_aware_check() != 0)
710 return -1;
711
712 return 0;
713
714 }
715
716 REGISTER_FAST_TEST(meter_autotest, true, true, test_meter);
717