[Click] process two packets

Ian Rose ianrose at eecs.harvard.edu
Tue May 3 09:50:31 EDT 2011


yes!  good bug catch!


On 05/03/2011 09:44 AM, Beyers Cronje wrote:
> Just a note on a bug in Ian's code. The two error checks in the beginning to
> check if p1 or p2 is NULL, you have to kill the packet before returning. You
> always MUST do one of these steps in a push path:
>
> 1) Push the packet and return
> 2) Kill the packet and return
> 3) Store the packet for later use, upon which you have to do (1) or (2)
> above when processing the stored packet.
>
> Returning push without killing or pushing the packet results in a memory
> leak.
>
> Beyers
>
> On Tue, May 3, 2011 at 3:17 PM, Ian Rose<ianrose at eecs.harvard.edu>  wrote:
>
>> 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
>> _______________________________________________
>> click mailing list
>> click at amsterdam.lcs.mit.edu
>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click


More information about the click mailing list