Actually I need to store Node Cache at each node , each node should have to 
maintain 
its neighbor node and request id (it extracts this info from route request, 
route reply
 and source routing).
for eg cache header has [ reqid, node count and next hop] , if route 
request was received by X node, it has to check its cache for reqid, if 
reqid=received message->reqid( then it has already seen this request,
 so it does not broadcast and only stores the node address which has 
transmitted this], How can I do this is in this code?

node Y transmits -- nodeid ->6  / transmitting node id, which is nodeid of Y
                   reqid ->100;
                   route_record=[ 1 4 5];
                   src=1 //original sender id
                  desn=10; // destination id

node X has cache of 
                 reqid->0;
                 next_hop[];

After receiving, it should update its cache as
                reqid->100;
                next_hop=[6];
and it has to broadcast the received route request.













implementation {

bool busy;
message_t pkt; 
uint8_t counter = 0;
uint8_t route_id=0;
uint8_t reply_id=1;


   event void Boot.booted() {
   call AMControl.start();
   }

event void AMControl.startDone(error_t err) { 
/// if no route to destination, it starts with route discovery phase//

   if (err == SUCCESS){ 
   RouteDiscovery_t *rreq = (RouteDiscovery_t*)(call  Packet.getPayload(&pkt,  
sizeof (RouteDiscovery_t)));

        // logics are added here

       if (call rreqsend.send(AM_BROADCAST_ADDR, &pkt, 
sizeof(RouteDiscovery_t)) == SUCCESS) {
       busy = TRUE;
       }
  }
}

 event void rreqsend.sendDone(message_t *msg, error_t error) {
if (&pkt == msg) {
  busy = FALSE;
}

}


event void AMControl.stopDone(error_t err) {

}




  //// processing the received route request ///


event message_t* pktreceive.receive(message_t* msg, void* payload, uint8_t len) 
{

    uint8_t array_postn;
    uint8_t nodecount =0;

    RouteDiscovery_t *rd_msg = (RouteDiscovery_t*) payload;

    NodeCache_t *cache = (NodeCache_t*)(call  Packet.getPayload(&pkt,  sizeof 
(NodeCache_t)));

 ////^^^fix this please, i need to store node cache at each node

 if (rd_msg->type==RREQ_phase){
                if (rd_msg->src==TOS_NODE_ID){ // original sender receives the 
request
                return msg;
                }

        /////check node cache and store it in cache if needed       

       if(cache->reqid==rd_msg->reqid){ // duplicate route request 
          nodecount=cache->node_count;  // first store how many nodes are in 
the array
          cache->next_hop[nodecount]=rd_msg->nodeid;
          cache->node_count=++nodecount;
       }
       else{// new request receiving 
            cache->reqid=rd_msg->reqid; 


            cache->next_hop[0]=rd_msg->nodeid;
            cache->node_count=++nodecount;

           if (rd_msg->desn!=TOS_NODE_ID)   {
          //broadcast the route request pkt by appending its nodeid
           array_postn=rd_msg->numhops;
           RouteDiscovery_t *r_req = (RouteDiscovery_t*)(call  
Packet.getPayload(&pkt,  sizeof (RouteDiscovery_t)));    
         //logics are added
           }
           else if (rd_msg->desn=TOS_NODE_ID)   {
           // create route reply packet and broadcast
           int i;
           array_postn=rd_msg->numhops;
           RouteDiscovery_t *rrep = (RouteDiscovery_t*)(call  
Packet.getPayload(&pkt,  sizeof (RouteDiscovery_t))); 
          //logics are added
           }
               if (call rd_bcst.send(AM_BROADCAST_ADDR, &pkt, 
sizeof(RouteDiscovery_t)) == SUCCESS) {
              busy = TRUE;
              }
      }



    }
    else if (rd_msg->type==RREP_phase){            
                 if (rd_msg->src==TOS_NODE_ID){
                 return msg;
                 }
         /////check node cache and store it in cache if needed 
        int i;
       if(cache->repid==rd_msg->repid){ // duplicate route reply
              nodecount=cache->node_count; 

             for (i=0; i<nodecount; i++)
             {
                if (cache->next_hop[i]==rd_msg->nodeid){
                    cache->node_count=nodecount;
                }else{
                     cache->next_hop[nodecount]=rd_msg->nodeid;
                     cache->node_count=++nodecount;
                }
             }

       }
       else{ // new route reply received
            nodecount=cache->node_count; 

         for (i=0; i<nodecount; i++)
         {
                if (cache->next_hop[i]==rd_msg->nodeid){
                    cache->node_count=nodecount;
                }else{
                     cache->next_hop[nodecount]=rd_msg->nodeid;
                     cache->node_count=++nodecount;
                }
          }

             if (rd_msg->desn!=TOS_NODE_ID) {
             //simply broadcast the route reply packet
             int i;
             array_postn=rd_msg->numhops;
             RouteDiscovery_t *rp_bcst = (RouteDiscovery_t*)(call  
Packet.getPayload(&pkt,  sizeof (RouteDiscovery_t)));    
           //logics are added

             }
             else if (rd_msg->desn=TOS_NODE_ID) { // source receives the route 
reply
             // store it in routing table
            RoutingTable_t *rt_table= NULL;
           /// Fix this, Please I need to store routing table 

             }
           if (call rd_bcst.send(AM_BROADCAST_ADDR, &pkt, 
sizeof(RouteDiscovery_t)) == SUCCESS) {
             busy = TRUE;
           }

         }
    }

return msg;

   }

      event void rd_bcst.sendDone(message_t *msg, error_t error) {
         if (&pkt == msg) {
         busy = FALSE;

         }
      }
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to