4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <cmdline_parse.h>
45 #ifdef RTE_LIBRTE_METER
47 #include <rte_cycles.h>
48 #include <rte_meter.h>
50 #define mlog(format, ...) do{\
51 printf("Line %d:",__LINE__);\
52 printf(format, ##__VA_ARGS__);\
56 #define melog(format, ...) do{\
57 printf("Line %d:",__LINE__);\
58 printf(format, ##__VA_ARGS__);\
59 printf(" failed!\n");\
63 #define TM_TEST_SRTCM_CIR_DF 46000000
64 #define TM_TEST_SRTCM_CBS_DF 2048
65 #define TM_TEST_SRTCM_EBS_DF 4096
67 #define TM_TEST_TRTCM_CIR_DF 46000000
68 #define TM_TEST_TRTCM_PIR_DF 69000000
69 #define TM_TEST_TRTCM_CBS_DF 2048
70 #define TM_TEST_TRTCM_PBS_DF 4096
72 static struct rte_meter_srtcm_params sparams =
73 {.cir = TM_TEST_SRTCM_CIR_DF,
74 .cbs = TM_TEST_SRTCM_CBS_DF,
75 .ebs = TM_TEST_SRTCM_EBS_DF,};
77 static struct rte_meter_trtcm_params tparams=
78 {.cir = TM_TEST_TRTCM_CIR_DF,
79 .pir = TM_TEST_TRTCM_PIR_DF,
80 .cbs = TM_TEST_TRTCM_CBS_DF,
81 .pbs = TM_TEST_TRTCM_PBS_DF,};
84 * functional test for rte_meter_srtcm_config
87 tm_test_srtcm_config(void)
89 #define SRTCM_CFG_MSG "srtcm_config"
90 struct rte_meter_srtcm sm;
91 struct rte_meter_srtcm_params sparams1;
93 /* invalid parameter test */
94 if(rte_meter_srtcm_config(NULL, NULL) == 0)
96 if(rte_meter_srtcm_config(&sm, NULL) == 0)
98 if(rte_meter_srtcm_config(NULL, &sparams) == 0)
101 /* cbs and ebs can't both be zero */
105 if(rte_meter_srtcm_config(&sm, &sparams1) == 0)
106 melog(SRTCM_CFG_MSG);
108 /* cir should never be 0 */
111 if(rte_meter_srtcm_config(&sm, &sparams1) == 0)
112 melog(SRTCM_CFG_MSG);
114 /* one of ebs and cbs can be zero, should be successful */
117 if(rte_meter_srtcm_config(&sm, &sparams1) != 0)
118 melog(SRTCM_CFG_MSG);
122 if(rte_meter_srtcm_config(&sm, &sparams1) != 0)
123 melog(SRTCM_CFG_MSG);
125 /* usual parameter, should be successful */
126 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
127 melog(SRTCM_CFG_MSG);
134 * functional test for rte_meter_trtcm_config
137 tm_test_trtcm_config(void)
139 struct rte_meter_trtcm tm;
140 struct rte_meter_trtcm_params tparams1;
141 #define TRTCM_CFG_MSG "trtcm_config"
143 /* invalid parameter test */
144 if(rte_meter_trtcm_config(NULL, NULL) == 0)
145 melog(TRTCM_CFG_MSG);
146 if(rte_meter_trtcm_config(&tm, NULL) == 0)
147 melog(TRTCM_CFG_MSG);
148 if(rte_meter_trtcm_config(NULL, &tparams) == 0)
149 melog(TRTCM_CFG_MSG);
151 /* cir, cbs, pir and pbs never be zero */
154 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
155 melog(TRTCM_CFG_MSG);
159 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
160 melog(TRTCM_CFG_MSG);
164 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
165 melog(TRTCM_CFG_MSG);
169 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
170 melog(TRTCM_CFG_MSG);
172 /* pir should be greater or equal to cir */
174 tparams1.pir = tparams1.cir - 1;
175 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
176 melog(TRTCM_CFG_MSG" pir < cir test");
178 /* usual parameter, should be successful */
179 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
180 melog(TRTCM_CFG_MSG);
186 * functional test for rte_meter_srtcm_color_blind_check
189 tm_test_srtcm_color_blind_check(void)
191 #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
192 struct rte_meter_srtcm sm;
194 uint64_t hz = rte_get_tsc_hz();
197 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
198 melog(SRTCM_BLIND_CHECK_MSG);
199 time = rte_get_tsc_cycles() + hz;
200 if(rte_meter_srtcm_color_blind_check(
201 &sm, time, TM_TEST_SRTCM_CBS_DF - 1)
202 != e_RTE_METER_GREEN)
203 melog(SRTCM_BLIND_CHECK_MSG" GREEN");
206 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
207 melog(SRTCM_BLIND_CHECK_MSG);
208 time = rte_get_tsc_cycles() + hz;
209 if(rte_meter_srtcm_color_blind_check(
210 &sm, time, TM_TEST_SRTCM_CBS_DF + 1)
211 != e_RTE_METER_YELLOW)
212 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
214 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
215 melog(SRTCM_BLIND_CHECK_MSG);
216 time = rte_get_tsc_cycles() + hz;
217 if(rte_meter_srtcm_color_blind_check(
218 &sm, time, (uint32_t)sm.ebs - 1) != e_RTE_METER_YELLOW)
219 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
222 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
223 melog(SRTCM_BLIND_CHECK_MSG);
224 time = rte_get_tsc_cycles() + hz;
225 if(rte_meter_srtcm_color_blind_check(
226 &sm, time, TM_TEST_SRTCM_EBS_DF + 1)
228 melog(SRTCM_BLIND_CHECK_MSG" RED");
235 * functional test for rte_meter_trtcm_color_blind_check
238 tm_test_trtcm_color_blind_check(void)
240 #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
243 struct rte_meter_trtcm tm;
244 uint64_t hz = rte_get_tsc_hz();
247 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
248 melog(TRTCM_BLIND_CHECK_MSG);
249 time = rte_get_tsc_cycles() + hz;
250 if(rte_meter_trtcm_color_blind_check(
251 &tm, time, TM_TEST_TRTCM_CBS_DF - 1)
252 != e_RTE_METER_GREEN)
253 melog(TRTCM_BLIND_CHECK_MSG" GREEN");
256 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
257 melog(TRTCM_BLIND_CHECK_MSG);
258 time = rte_get_tsc_cycles() + hz;
259 if(rte_meter_trtcm_color_blind_check(
260 &tm, time, TM_TEST_TRTCM_CBS_DF + 1)
261 != e_RTE_METER_YELLOW)
262 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
264 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
265 melog(TRTCM_BLIND_CHECK_MSG);
266 time = rte_get_tsc_cycles() + hz;
267 if(rte_meter_trtcm_color_blind_check(
268 &tm, time, TM_TEST_TRTCM_PBS_DF - 1)
269 != e_RTE_METER_YELLOW)
270 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
273 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
274 melog(TRTCM_BLIND_CHECK_MSG);
275 time = rte_get_tsc_cycles() + hz;
276 if(rte_meter_trtcm_color_blind_check(
277 &tm, time, TM_TEST_TRTCM_PBS_DF + 1)
279 melog(TRTCM_BLIND_CHECK_MSG" RED");
286 * @in[4] : the flags packets carries.
287 * @in[4] : the flags function expect to return.
288 * It will do blind check at the time of 1 second from beginning.
289 * At the time, it will use packets length of cbs -1, cbs + 1,
290 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
291 * aware check, expect flag out[0], out[1], out[2] and out[3]
295 tm_test_srtcm_aware_check
296 (enum rte_meter_color in[4], enum rte_meter_color out[4])
298 #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
299 struct rte_meter_srtcm sm;
301 uint64_t hz = rte_get_tsc_hz();
303 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
304 melog(SRTCM_AWARE_CHECK_MSG);
305 time = rte_get_tsc_cycles() + hz;
306 if(rte_meter_srtcm_color_aware_check(
307 &sm, time, TM_TEST_SRTCM_CBS_DF - 1, in[0]) != out[0])
308 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
310 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
311 melog(SRTCM_AWARE_CHECK_MSG);
312 time = rte_get_tsc_cycles() + hz;
313 if(rte_meter_srtcm_color_aware_check(
314 &sm, time, TM_TEST_SRTCM_CBS_DF + 1, in[1]) != out[1])
315 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
317 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
318 melog(SRTCM_AWARE_CHECK_MSG);
319 time = rte_get_tsc_cycles() + hz;
320 if(rte_meter_srtcm_color_aware_check(
321 &sm, time, TM_TEST_SRTCM_EBS_DF - 1, in[2]) != out[2])
322 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
324 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
325 melog(SRTCM_AWARE_CHECK_MSG);
326 time = rte_get_tsc_cycles() + hz;
327 if(rte_meter_srtcm_color_aware_check(
328 &sm, time, TM_TEST_SRTCM_EBS_DF + 1, in[3]) != out[3])
329 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
336 * functional test for rte_meter_srtcm_color_aware_check
339 tm_test_srtcm_color_aware_check(void)
341 enum rte_meter_color in[4], out[4];
344 * test 4 points that will produce green, yellow, yellow, red flag
345 * if using blind check
348 /* previouly have a green, test points should keep unchanged */
349 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_GREEN;
350 out[0] = e_RTE_METER_GREEN;
351 out[1] = e_RTE_METER_YELLOW;
352 out[2] = e_RTE_METER_YELLOW;
353 out[3] = e_RTE_METER_RED;
354 if(tm_test_srtcm_aware_check(in, out) != 0)
358 * previously have a yellow, green & yellow = yellow
361 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_YELLOW;
362 out[0] = e_RTE_METER_YELLOW;
363 out[1] = e_RTE_METER_YELLOW;
364 out[2] = e_RTE_METER_YELLOW;
365 out[3] = e_RTE_METER_RED;
366 if(tm_test_srtcm_aware_check(in, out) != 0)
370 * previously have a red, red & green = red
373 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_RED;
374 out[0] = e_RTE_METER_RED;
375 out[1] = e_RTE_METER_RED;
376 out[2] = e_RTE_METER_RED;
377 out[3] = e_RTE_METER_RED;
378 if(tm_test_srtcm_aware_check(in, out) != 0)
385 * @in[4] : the flags packets carries.
386 * @in[4] : the flags function expect to return.
387 * It will do blind check at the time of 1 second from beginning.
388 * At the time, it will use packets length of cbs -1, cbs + 1,
389 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
390 * aware check, expect flag out[0], out[1], out[2] and out[3]
393 tm_test_trtcm_aware_check
394 (enum rte_meter_color in[4], enum rte_meter_color out[4])
396 #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
397 struct rte_meter_trtcm tm;
399 uint64_t hz = rte_get_tsc_hz();
401 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
402 melog(TRTCM_AWARE_CHECK_MSG);
403 time = rte_get_tsc_cycles() + hz;
404 if(rte_meter_trtcm_color_aware_check(
405 &tm, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
406 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
408 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
409 melog(TRTCM_AWARE_CHECK_MSG);
410 time = rte_get_tsc_cycles() + hz;
411 if(rte_meter_trtcm_color_aware_check(
412 &tm, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
413 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
415 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
416 melog(TRTCM_AWARE_CHECK_MSG);
417 time = rte_get_tsc_cycles() + hz;
418 if(rte_meter_trtcm_color_aware_check(
419 &tm, time, TM_TEST_TRTCM_PBS_DF - 1, in[2]) != out[2])
420 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
422 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
423 melog(TRTCM_AWARE_CHECK_MSG);
424 time = rte_get_tsc_cycles() + hz;
425 if(rte_meter_trtcm_color_aware_check(
426 &tm, time, TM_TEST_TRTCM_PBS_DF + 1, in[3]) != out[3])
427 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
434 * functional test for rte_meter_trtcm_color_aware_check
438 tm_test_trtcm_color_aware_check(void)
440 enum rte_meter_color in[4], out[4];
442 * test 4 points that will produce green, yellow, yellow, red flag
443 * if using blind check
446 /* previouly have a green, test points should keep unchanged */
447 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_GREEN;
448 out[0] = e_RTE_METER_GREEN;
449 out[1] = e_RTE_METER_YELLOW;
450 out[2] = e_RTE_METER_YELLOW;
451 out[3] = e_RTE_METER_RED;
452 if(tm_test_trtcm_aware_check(in, out) != 0)
455 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_YELLOW;
456 out[0] = e_RTE_METER_YELLOW;
457 out[1] = e_RTE_METER_YELLOW;
458 out[2] = e_RTE_METER_YELLOW;
459 out[3] = e_RTE_METER_RED;
460 if(tm_test_trtcm_aware_check(in, out) != 0)
463 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_RED;
464 out[0] = e_RTE_METER_RED;
465 out[1] = e_RTE_METER_RED;
466 out[2] = e_RTE_METER_RED;
467 out[3] = e_RTE_METER_RED;
468 if(tm_test_trtcm_aware_check(in, out) != 0)
475 * test main entrance for library meter
480 if(tm_test_srtcm_config() != 0 )
483 if(tm_test_trtcm_config() != 0 )
486 if(tm_test_srtcm_color_blind_check() != 0)
489 if(tm_test_trtcm_color_blind_check()!= 0)
492 if(tm_test_srtcm_color_aware_check()!= 0)
495 if(tm_test_trtcm_color_aware_check()!= 0)
502 #else /* RTE_LIBRTE_METER */
507 printf("The meter library is not included in this build\n");
510 #endif /* RTE_LIBRTE_METER */