[Click] Flow-based router context

Eddie Kohler kohler at icir.org
Fri Aug 29 11:38:55 EDT 2003


Hi,

Here's the relevant code from RED. I'll go through it line by line.

        Vector<Element *> _queue_elements;
This will store the list of downstream or upstream queues.

	CastElementFilter filter("Storage");
This filter acts as a predicate, returning true when it encounters an element
that can be cast to "Storage". RED wants "Storage" since that is the
superclass of anything that stores packets (but you could put SimpleQueue
there instead).

The next lines actually search the router using flow-based router context.
I'll concentrate on the second call, which looks upstream, since that's
what you'll be using.
	int ok;
	if (output_is_push(0))
	    ok = router()->downstream_elements(this, 0, &filter, _queue_elements);
	else
	    ok = router()->upstream_elements(this, 0, &filter, _queue_elements);
This call searches "upstream" of the current element's input port #0 (the
first two arguments, "this, 0"), appending every upstream element to the
_queue_elements list. The search stops at elements that match "&filter" --
that is, at "Storage" elements.

	if (ok < 0)
	    return errh->error("flow-based router context failure");
Check for errors.

	filter.filter(_queue_elements);
If there are no errors, this last line removes from _queue_elements
everything except the Storage elements themselves.

And you're done!

Eddie


More information about the click mailing list