[Click] Patch: time handler in Script
Eddie Kohler
kohler at cs.ucla.edu
Mon Jun 16 12:21:23 EDT 2008
Hi Bart,
This is a great idea, but my first reaction was that maybe the handler should
be called "now" (that is the Timestamp method's name). Do you agree or
disagree? Let me know!
Eddie
Bart Braem wrote:
> Hello,
>
> We discovered that having a time read handler would be interesting in
> Script elements. You could then do things like:
>
> q :: Queue;
> ICMPPingSource(1.2.3.4, 2.3.4.5) -> q;
> q-> Discard;
> rtt :: Script(label start, set y $(q.length), set x $(time), print $x
> --- Q size: $y , wait 2, goto start);
>
> The patch to include this in Script is as follows (output of git diff):
>
> diff --git a/elements/standard/script.cc b/elements/standard/script.cc
> index f450d1f..042b8ac 100644
> --- a/elements/standard/script.cc
> +++ b/elements/standard/script.cc
> @@ -627,7 +627,7 @@ Script::Expander::expand(const String &vname, int
> vartype, int quote, StringAccu
>
> enum {
> ST_STEP = 0, ST_RUN, ST_GOTO,
> - AR_ADD = 0, AR_SUB, AR_MUL, AR_DIV, AR_IDIV,
> + AR_ADD = 0, AR_SUB, AR_MUL, AR_DIV, AR_IDIV, AR_TIME,
> AR_LT, AR_EQ, AR_GT, AR_GE, AR_NE, AR_LE, // order is important
> AR_FIRST, AR_NOT, AR_SPRINTF, ar_random
> };
> @@ -774,6 +774,10 @@ Script::arithmetic_handler(int, String &str,
> Element *e, const Handler *h, Error
> return 0;
> }
>
> + case AR_TIME:
> + str = Timestamp::now().unparse();
> + return 0;
> +
> case AR_LT:
> case AR_EQ:
> case AR_GT:
> @@ -948,6 +952,7 @@ Script::add_handlers()
> set_handler("ne", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_NE, 0);
> set_handler("gt", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_GT, 0);
> set_handler("ge", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_GE, 0);
> + set_handler("time", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_TIME, 0);
> set_handler("lt", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_LT, 0);
> set_handler("le", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_LE, 0);
> set_handler("not", Handler::OP_READ | Handler::READ_PARAM,
> arithmetic_handler, AR_NOT, 0);
>
> We have patches for Click-1.5 and Click-1.6 as well.
>
> Regards,
> Bart
More information about the click
mailing list