diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-08-13 02:11:22 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-09-21 09:59:10 +0200 |
commit | 249891474f6820ab1d829601188b5e3ce82c5f0f (patch) | |
tree | 67dc0d56e15154ee315c09986b046c968d46e5df | |
parent | 958149795f680f77f73ca44f78279f55265728c0 (diff) |
trafgen: parser: Add 'drnd()' function for proto fields
Add syntax for specify dynamic random function for proto field:
drnd() | drnd(min, max)
EXAMPLE:
{ udp(sport=drnd()) }
{ udp(sport=drnd(1000, 2000)) }
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen_parser.y | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y index 9b313d1..7e41bff 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -76,6 +76,7 @@ enum field_expr_type_t { FIELD_EXPR_IP4_ADDR, FIELD_EXPR_IP6_ADDR, FIELD_EXPR_INC, + FIELD_EXPR_RND, }; struct proto_field_expr { @@ -429,6 +430,7 @@ static void proto_field_expr_eval(void) break; case FIELD_EXPR_INC: + case FIELD_EXPR_RND: if (field_expr.val.func.min && field_expr.val.func.min >= field_expr.val.func.max) panic("dinc(): min(%u) can't be >= max(%u)\n", @@ -738,6 +740,13 @@ field_expr field_expr.val.func.min = $3; field_expr.val.func.max = $5; field_expr.val.func.inc = $7; } + | K_DRND '(' ')' { field_expr.type = FIELD_EXPR_RND; + field_expr.val.func.type = PROTO_FIELD_FUNC_RND; } + | K_DRND '(' number delimiter number ')' + { field_expr.type = FIELD_EXPR_RND; + field_expr.val.func.type = PROTO_FIELD_FUNC_RND; + field_expr.val.func.min = $3; + field_expr.val.func.max = $5; } ; eth_proto |