4 * Copyright(c) 2010-2014 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.
40 #include <cmdline_parse.h>
44 #ifdef RTE_LIBRTE_METER
46 #include <rte_cycles.h>
47 #include <rte_meter.h>
49 #define mlog(format, ...) do{\
50 printf("Line %d:",__LINE__);\
51 printf(format, ##__VA_ARGS__);\
55 #define melog(format, ...) do{\
56 printf("Line %d:",__LINE__);\
57 printf(format, ##__VA_ARGS__);\
58 printf(" failed!\n");\
62 #define TM_TEST_SRTCM_CIR_DF 46000000
63 #define TM_TEST_SRTCM_CBS_DF 2048
64 #define TM_TEST_SRTCM_EBS_DF 4096
66 #define TM_TEST_TRTCM_CIR_DF 46000000
67 #define TM_TEST_TRTCM_PIR_DF 69000000
68 #define TM_TEST_TRTCM_CBS_DF 2048
69 #define TM_TEST_TRTCM_PBS_DF 4096
71 static struct rte_meter_srtcm_params sparams =
72 {.cir = TM_TEST_SRTCM_CIR_DF,
73 .cbs = TM_TEST_SRTCM_CBS_DF,
74 .ebs = TM_TEST_SRTCM_EBS_DF,};
76 static struct rte_meter_trtcm_params tparams=
77 {.cir = TM_TEST_TRTCM_CIR_DF,
78 .pir = TM_TEST_TRTCM_PIR_DF,
79 .cbs = TM_TEST_TRTCM_CBS_DF,
80 .pbs = TM_TEST_TRTCM_PBS_DF,};
83 * functional test for rte_meter_srtcm_config
86 tm_test_srtcm_config(void)
88 #define SRTCM_CFG_MSG "srtcm_config"
89 struct rte_meter_srtcm sm;
90 struct rte_meter_srtcm_params sparams1;
92 /* invalid parameter test */
93 if(rte_meter_srtcm_config(NULL, NULL) == 0)
95 if(rte_meter_srtcm_config(&sm, NULL) == 0)
97 if(rte_meter_srtcm_config(NULL, &sparams) == 0)
100 /* cbs and ebs can't both be zero */
104 if(rte_meter_srtcm_config(&sm, &sparams1) == 0)
105 melog(SRTCM_CFG_MSG);
107 /* cir should never be 0 */
110 if(rte_meter_srtcm_config(&sm, &sparams1) == 0)
111 melog(SRTCM_CFG_MSG);
113 /* one of ebs and cbs can be zero, should be successful */
116 if(rte_meter_srtcm_config(&sm, &sparams1) != 0)
117 melog(SRTCM_CFG_MSG);
121 if(rte_meter_srtcm_config(&sm, &sparams1) != 0)
122 melog(SRTCM_CFG_MSG);
124 /* usual parameter, should be successful */
125 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
126 melog(SRTCM_CFG_MSG);
133 * functional test for rte_meter_trtcm_config
136 tm_test_trtcm_config(void)
138 struct rte_meter_trtcm tm;
139 struct rte_meter_trtcm_params tparams1;
140 #define TRTCM_CFG_MSG "trtcm_config"
142 /* invalid parameter test */
143 if(rte_meter_trtcm_config(NULL, NULL) == 0)
144 melog(TRTCM_CFG_MSG);
145 if(rte_meter_trtcm_config(&tm, NULL) == 0)
146 melog(TRTCM_CFG_MSG);
147 if(rte_meter_trtcm_config(NULL, &tparams) == 0)
148 melog(TRTCM_CFG_MSG);
150 /* cir, cbs, pir and pbs never be zero */
153 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
154 melog(TRTCM_CFG_MSG);
158 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
159 melog(TRTCM_CFG_MSG);
163 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
164 melog(TRTCM_CFG_MSG);
168 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
169 melog(TRTCM_CFG_MSG);
171 /* pir should be greater or equal to cir */
173 tparams1.pir = tparams1.cir - 1;
174 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
175 melog(TRTCM_CFG_MSG" pir < cir test");
177 /* usual parameter, should be successful */
178 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
179 melog(TRTCM_CFG_MSG);
185 * functional test for rte_meter_srtcm_color_blind_check
188 tm_test_srtcm_color_blind_check(void)
190 #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
191 struct rte_meter_srtcm sm;
193 uint64_t hz = rte_get_tsc_hz();
196 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
197 melog(SRTCM_BLIND_CHECK_MSG);
198 time = rte_get_tsc_cycles() + hz;
199 if(rte_meter_srtcm_color_blind_check(
200 &sm, time, TM_TEST_SRTCM_CBS_DF - 1)
201 != e_RTE_METER_GREEN)
202 melog(SRTCM_BLIND_CHECK_MSG" GREEN");
205 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
206 melog(SRTCM_BLIND_CHECK_MSG);
207 time = rte_get_tsc_cycles() + hz;
208 if(rte_meter_srtcm_color_blind_check(
209 &sm, time, TM_TEST_SRTCM_CBS_DF + 1)
210 != e_RTE_METER_YELLOW)
211 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
213 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
214 melog(SRTCM_BLIND_CHECK_MSG);
215 time = rte_get_tsc_cycles() + hz;
216 if(rte_meter_srtcm_color_blind_check(
217 &sm, time, (uint32_t)sm.ebs - 1) != e_RTE_METER_YELLOW)
218 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
221 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
222 melog(SRTCM_BLIND_CHECK_MSG);
223 time = rte_get_tsc_cycles() + hz;
224 if(rte_meter_srtcm_color_blind_check(
225 &sm, time, TM_TEST_SRTCM_EBS_DF + 1)
227 melog(SRTCM_BLIND_CHECK_MSG" RED");
234 * functional test for rte_meter_trtcm_color_blind_check
237 tm_test_trtcm_color_blind_check(void)
239 #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
242 struct rte_meter_trtcm tm;
243 uint64_t hz = rte_get_tsc_hz();
246 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
247 melog(TRTCM_BLIND_CHECK_MSG);
248 time = rte_get_tsc_cycles() + hz;
249 if(rte_meter_trtcm_color_blind_check(
250 &tm, time, TM_TEST_TRTCM_CBS_DF - 1)
251 != e_RTE_METER_GREEN)
252 melog(TRTCM_BLIND_CHECK_MSG" GREEN");
255 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
256 melog(TRTCM_BLIND_CHECK_MSG);
257 time = rte_get_tsc_cycles() + hz;
258 if(rte_meter_trtcm_color_blind_check(
259 &tm, time, TM_TEST_TRTCM_CBS_DF + 1)
260 != e_RTE_METER_YELLOW)
261 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
263 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
264 melog(TRTCM_BLIND_CHECK_MSG);
265 time = rte_get_tsc_cycles() + hz;
266 if(rte_meter_trtcm_color_blind_check(
267 &tm, time, TM_TEST_TRTCM_PBS_DF - 1)
268 != e_RTE_METER_YELLOW)
269 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
272 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
273 melog(TRTCM_BLIND_CHECK_MSG);
274 time = rte_get_tsc_cycles() + hz;
275 if(rte_meter_trtcm_color_blind_check(
276 &tm, time, TM_TEST_TRTCM_PBS_DF + 1)
278 melog(TRTCM_BLIND_CHECK_MSG" RED");
285 * @in[4] : the flags packets carries.
286 * @in[4] : the flags function expect to return.
287 * It will do blind check at the time of 1 second from beginning.
288 * At the time, it will use packets length of cbs -1, cbs + 1,
289 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
290 * aware check, expect flag out[0], out[1], out[2] and out[3]
294 tm_test_srtcm_aware_check
295 (enum rte_meter_color in[4], enum rte_meter_color out[4])
297 #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
298 struct rte_meter_srtcm sm;
300 uint64_t hz = rte_get_tsc_hz();
302 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
303 melog(SRTCM_AWARE_CHECK_MSG);
304 time = rte_get_tsc_cycles() + hz;
305 if(rte_meter_srtcm_color_aware_check(
306 &sm, time, TM_TEST_SRTCM_CBS_DF - 1, in[0]) != out[0])
307 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
309 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
310 melog(SRTCM_AWARE_CHECK_MSG);
311 time = rte_get_tsc_cycles() + hz;
312 if(rte_meter_srtcm_color_aware_check(
313 &sm, time, TM_TEST_SRTCM_CBS_DF + 1, in[1]) != out[1])
314 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
316 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
317 melog(SRTCM_AWARE_CHECK_MSG);
318 time = rte_get_tsc_cycles() + hz;
319 if(rte_meter_srtcm_color_aware_check(
320 &sm, time, TM_TEST_SRTCM_EBS_DF - 1, in[2]) != out[2])
321 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
323 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
324 melog(SRTCM_AWARE_CHECK_MSG);
325 time = rte_get_tsc_cycles() + hz;
326 if(rte_meter_srtcm_color_aware_check(
327 &sm, time, TM_TEST_SRTCM_EBS_DF + 1, in[3]) != out[3])
328 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
335 * functional test for rte_meter_srtcm_color_aware_check
338 tm_test_srtcm_color_aware_check(void)
340 enum rte_meter_color in[4], out[4];
343 * test 4 points that will produce green, yellow, yellow, red flag
344 * if using blind check
347 /* previouly have a green, test points should keep unchanged */
348 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_GREEN;
349 out[0] = e_RTE_METER_GREEN;
350 out[1] = e_RTE_METER_YELLOW;
351 out[2] = e_RTE_METER_YELLOW;
352 out[3] = e_RTE_METER_RED;
353 if(tm_test_srtcm_aware_check(in, out) != 0)
357 * previously have a yellow, green & yellow = yellow
360 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_YELLOW;
361 out[0] = e_RTE_METER_YELLOW;
362 out[1] = e_RTE_METER_YELLOW;
363 out[2] = e_RTE_METER_YELLOW;
364 out[3] = e_RTE_METER_RED;
365 if(tm_test_srtcm_aware_check(in, out) != 0)
369 * previously have a red, red & green = red
372 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_RED;
373 out[0] = e_RTE_METER_RED;
374 out[1] = e_RTE_METER_RED;
375 out[2] = e_RTE_METER_RED;
376 out[3] = e_RTE_METER_RED;
377 if(tm_test_srtcm_aware_check(in, out) != 0)
384 * @in[4] : the flags packets carries.
385 * @in[4] : the flags function expect to return.
386 * It will do blind check at the time of 1 second from beginning.
387 * At the time, it will use packets length of cbs -1, cbs + 1,
388 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
389 * aware check, expect flag out[0], out[1], out[2] and out[3]
392 tm_test_trtcm_aware_check
393 (enum rte_meter_color in[4], enum rte_meter_color out[4])
395 #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
396 struct rte_meter_trtcm tm;
398 uint64_t hz = rte_get_tsc_hz();
400 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
401 melog(TRTCM_AWARE_CHECK_MSG);
402 time = rte_get_tsc_cycles() + hz;
403 if(rte_meter_trtcm_color_aware_check(
404 &tm, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
405 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
407 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
408 melog(TRTCM_AWARE_CHECK_MSG);
409 time = rte_get_tsc_cycles() + hz;
410 if(rte_meter_trtcm_color_aware_check(
411 &tm, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
412 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
414 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
415 melog(TRTCM_AWARE_CHECK_MSG);
416 time = rte_get_tsc_cycles() + hz;
417 if(rte_meter_trtcm_color_aware_check(
418 &tm, time, TM_TEST_TRTCM_PBS_DF - 1, in[2]) != out[2])
419 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
421 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
422 melog(TRTCM_AWARE_CHECK_MSG);
423 time = rte_get_tsc_cycles() + hz;
424 if(rte_meter_trtcm_color_aware_check(
425 &tm, time, TM_TEST_TRTCM_PBS_DF + 1, in[3]) != out[3])
426 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
433 * functional test for rte_meter_trtcm_color_aware_check
437 tm_test_trtcm_color_aware_check(void)
439 enum rte_meter_color in[4], out[4];
441 * test 4 points that will produce green, yellow, yellow, red flag
442 * if using blind check
445 /* previouly have a green, test points should keep unchanged */
446 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_GREEN;
447 out[0] = e_RTE_METER_GREEN;
448 out[1] = e_RTE_METER_YELLOW;
449 out[2] = e_RTE_METER_YELLOW;
450 out[3] = e_RTE_METER_RED;
451 if(tm_test_trtcm_aware_check(in, out) != 0)
454 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_YELLOW;
455 out[0] = e_RTE_METER_YELLOW;
456 out[1] = e_RTE_METER_YELLOW;
457 out[2] = e_RTE_METER_YELLOW;
458 out[3] = e_RTE_METER_RED;
459 if(tm_test_trtcm_aware_check(in, out) != 0)
462 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_RED;
463 out[0] = e_RTE_METER_RED;
464 out[1] = e_RTE_METER_RED;
465 out[2] = e_RTE_METER_RED;
466 out[3] = e_RTE_METER_RED;
467 if(tm_test_trtcm_aware_check(in, out) != 0)
474 * test main entrance for library meter
479 if(tm_test_srtcm_config() != 0 )
482 if(tm_test_trtcm_config() != 0 )
485 if(tm_test_srtcm_color_blind_check() != 0)
488 if(tm_test_trtcm_color_blind_check()!= 0)
491 if(tm_test_srtcm_color_aware_check()!= 0)
494 if(tm_test_trtcm_color_aware_check()!= 0)
501 #else /* RTE_LIBRTE_METER */
506 printf("The meter library is not included in this build\n");
509 #endif /* RTE_LIBRTE_METER */