[Click] Information sharing in Click

Eddie Kohler kohler at cs.ucla.edu
Mon Aug 27 18:35:50 EDT 2007


I would NOT recommend subclassing Packet.  Bad idea!  You'd have to do 
all sorts of crazy stuff like make clone() and ~Packet() virtual 
functions, and your code would NEVER work in kernel.  Barf.

Some common ways to implement this type of information sharing are (in 
addition to, or in common with, ways suggested by others):

(1) For small amounts of information, store the information in the 
packet's annotation area.  See include/click/packet_anno.hh.  Feel free 
to overlap your annotations with other annotations that you aren't 
currently using.  There are 24 bytes of annotation available.

(2) For larger amounts of information, consider adding a single 4-byte 
annotation that "numbers" the packet.  Then add an information element 
that stores the information for each packet "number" in a recyclable 
buffer.  Your other elements will query the information element when 
necessary.  They will get a pointer to the information element at 
configuration time, then call its methods directly.  For examples of 
this style, check out elements/analysis/aggregateipflows.hh, and its 
users, such as ToIPFlowDumps (elements/analysis) and the elements in the 
"models" package.

(3) A new header, at the beginning or end of the packet, as Nick suggests.

Eddie



Nicholas Weaver wrote:
> On Thu, Aug 02, 2007 at 07:19:34PM +0200, Beyers Cronje composed:
>> Hi Adam,
>>
>> The way I do it is via handler calls. So a downstream element will call an
>> upstream element's read/write handler. Alternatively you could use the
>> header space of a packet to include custom data per packet. Or you could
>> extend the packet annotations for your purposes.
> 
> The problem with handler information is that it sounds like Adam wants
> to annotate significant information onto each packet.
> 
> Thus the options seem to be:
> 
> a) prepend an additional header and define some structure for the
> Bucket o Bits for this information.
> 
> b) Subclass Packet
> 
> Subclassing packet makes more sense IFF the packets are created only
> by an element you define so they can create the subclass.
> 


More information about the click mailing list