[Tinyos-devel] DisseminationEngineImplP.nc , sendObject function

Philip Levis pal at cs.stanford.edu
Tue May 5 21:19:20 PDT 2009


On May 4, 2009, at 4:59 PM, Marcin Szczodrak wrote:

> Hi All,
>
> I was working on the Drip protocol and found something that may be a  
> bug.
> In tinyos-2.1.0/tos/lib/net/drip/DisseminationEngineImplP.nc  ,
> function sendObject sends empty messages with sequence number equal to
> DISSEMINATION_SEQNO_UNKNOWN, as result
> of Trickle's Timer being fired. However, these messages have been not
> initialized for dissemination by the application, and I guess they
> should not be disseminated. They simply waste energy. The problematic
> lines are the 149-152 , of the original version of code pasted below.
> I would like suggest to change them as in the modified version of the
> pasted code in lines 149-155. This will avoid sending empty messages.
>
> -Marcin
>
> // ORIGINAL
> 130   void sendObject( uint16_t key ) {
> 131     void* object;
> 132     uint8_t objectSize = 0;
> 133
> 134     dissemination_message_t* dMsg =
> 135       (dissemination_message_t*) call AMSend.getPayload(
> &m_buf,sizeof(dissemination_message_t) );
> 136     if (dMsg != NULL) {
> 137       m_bufBusy = TRUE;
> 138
> 139       dMsg->key = key;
> 140       dMsg->seqno = call DisseminationCache.requestSeqno[ key ]();
> 141
> 142       if ( dMsg->seqno != DISSEMINATION_SEQNO_UNKNOWN ) {
> 143         object = call DisseminationCache.requestData[ key ] 
> ( &objectSize );
> 144         if ((objectSize + sizeof(dissemination_message_t)) >
> 145             call AMSend.maxPayloadLength()) {
> 146           objectSize = call AMSend.maxPayloadLength() -
> sizeof(dissemination_message_t);
> 147         }
> 148         memcpy( dMsg->data, object, objectSize );
> 149       }
> 150       call AMSend.send( AM_BROADCAST_ADDR,
> 151                         &m_buf, sizeof( dissemination_message_t )
> + objectSize );
> 152     }
> 153   }
>
>
> // MODIFIED
> 130   void sendObject( uint16_t key ) {
> 131     void* object;
> 132     uint8_t objectSize = 0;
> 133
> 134     dissemination_message_t* dMsg =
> 135       (dissemination_message_t*) call AMSend.getPayload( &m_buf,
> sizeof(dissemination_message_t) );
> 136     if (dMsg != NULL) {
> 137       m_bufBusy = TRUE;
> 138
> 139       dMsg->key = key;
> 140       dMsg->seqno = call DisseminationCache.requestSeqno[ key ]();
> 141
> 142       if ( dMsg->seqno != DISSEMINATION_SEQNO_UNKNOWN ) {
> 143         object = call DisseminationCache.requestData[ key ] 
> ( &objectSize );
> 144         if ((objectSize + sizeof(dissemination_message_t)) >
> 145             call AMSend.maxPayloadLength()) {
> 146           objectSize = call AMSend.maxPayloadLength() -
> sizeof(dissemination_message_t);
> 147         }
> 148         memcpy( dMsg->data, object, objectSize );
> 149
> 150         call AMSend.send( AM_BROADCAST_ADDR,
> 151                           &m_buf, sizeof( dissemination_message_t)
> + objectSize );
> 152       } else {
> 153         m_bufBusy = FALSE;
> 154       }
> 155     }
> 156   }

Your fix looks right -- I'll check with Gilman Tolle.

Phil


More information about the Tinyos-devel mailing list