[Click] Patch: time handler in Script

Bart Braem bart.braem at ua.ac.be
Fri Jun 13 05:58:05 EDT 2008


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
-- 
Bart Braem
PATS research group - IBBT
Dept. of Mathematics and Computer Sciences
University of Antwerp
Campus Middelheim, G2.36
Middelheimlaan 1
B-2020 Antwerpen, Belgium
Phone: +32 (0)3 265.32.91
Fax: +32 (0)3 265.37.77
Web: www.pats.ua.ac.be



More information about the click mailing list