overloading compound elements

Eddie Kohler eddietwo at naugabutt.lcs.mit.edu
Sun Nov 19 17:52:27 EST 2000


Hello all,

I've checked in an extension to the compound element mechanism. Now you can
have an overloaded compound element with multiple definitions. A particular
definition is chosen based on number of input ports, number of output
ports, number of configuration arguments, or some combination.

For example, this element works like a replacement for Queue, and like
Queue, it has an optional configuration argument:

       elementclass MyQueue {

         /* this version has no config arguments */
	 input -> Queue -> Shaper(10000) -> output

       ||              /* <--- || introduces a new overloaded def */

         /* this version has one config argument */
	 $capacity |
	 input -> Queue($capacity) -> Shaper(10000) -> output

       }

       a :: MyQueue;        /* uses first def */
       b :: MyQueue(1024);  /* uses second def */

This elemnet has an optional second output port:

       elementclass Foo {

         /* this version has one output */
	 input -> c::CheckIPHeader -> output;
	 c[1] -> Print(bad) -> Discard;

       ||

         /* this version has two outputs */
	 input -> c::CheckIPHeader -> output;
	 c[1] -> Print(bad) -> [1]output;

       }

You can also add new definitions to an existing element with this syntax:

       elementclass MyQueue {

         ... ||     /* <-- that syntax means "add to existing MyQueue" */

         /* this version has two config arguments */
	 $capacity, $rate |
	 input -> Queue($capacity) -> Shaper($rate) -> output

       }

       a :: MyQueue;		/* uses first def from before */
       b :: MyQueue(1024);	/* uses second def from before */
       c :: MyQueue(1024, 1000); /* uses the def we just added */

Pleas elet me know if there are any problems with the stuff I had to do to
make this work, or if you have suggestions.

love,
ed



More information about the click mailing list