[Click] process two packets

Ian Rose ianrose at eecs.harvard.edu
Tue May 3 09:17:02 EDT 2011


Sure.  As a dumb example, You could create an element with 2 inputs that 
swaps the timestamps across pairs of packets as they are received before 
outputting them on 2 outputs.  The code might work something like this 
(warning: written totally from memory, not compiled, sure to contain bugs):

// class variables:
Packet *p1 = NULL, *p2 = NULL;

// main logic in push() method
void MyElement::push(int port, Packet *p)
{
   if (port == 0) {
     if (p1 != NULL) {
       // ERROR: 2 packets in a row received from port 0
       return;
     } else {
       p1 = p;
     }
   } else if (port == 1) {
     if (p2 != NULL) {
       // ERROR: 2 packets in a row received from port 1
       return;
     } else {
       p2 = p;
     }
   } else {
     // ERROR: bad port - misconfigured?
     return;
   }

   if ((p1 != NULL) && (p2 != NULL)) {
     // swap timestamps
     Timestamp t = p1->timestamp_anno();
     p1->set_timestamp_anno(p2->timestamp_anno());
     p2->set_timestamp_anno(t);

     // output both (modified) packets
     output(0).push(p1);
     output(1).push(p2);

     // clear variables -- ready to receive another pair
     p1 = NULL;
     p2 = NULL;
   }
}

Note that the code is simple and assumes that packets arrive exactly as 
pairs (input0 and input1).  So this is ok:

packet on input0   \ __ a pair
packet on input1   /
packet on input0   \ __ a pair
packet on input1   /
packet on input1   \ __ a pair
packet on input0   /
(etc)

But this fails:

packet on input0   \ __ NOT a pair!
packet on input0   /


Hope that makes sense,
- Ian


On 05/03/2011 05:45 AM, Jessica Shahper wrote:
> Hi all,
>
> As far I have seen, the elements in click can work on a single packet at a time,
> what if I want to create an element that can compare the contents in a header
> and can even mix the contents of several packets together?
> Is it possible to design a new element that can take several packets through
> different inputs and can work on them at a time?
>
> Regards-
> Jessica
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click


More information about the click mailing list