Procedure routing_algorithm(packet){
// If the node receives RREP packet
 if (receive the RREP){
   = packet.sink;
  if(k ==Sink_num){
    if(node.hop== ) //the node.hop in the
Sink
     update the route to the Sink and set
lifetime for the route
    else
     if(node. hop > packet.hop+1)
      update the rout to the Sink k and set
lifetime for the routing
  }
  else{
    To listening() mode and update the rout to
the sink k
    wait for a short time and then broadcast
RREQ packet again
  }
 else
  wait for a short time and then broadcast RREQ
again
 // If the node receives RREQ packet
 if(receive the RREQ){
   = packet.sink;
  if(node.hop!= ∞){ // the node.hop in the Sink
   if(the packet.hop > the node.hop + 1)
    Initialize the RREP packet
  // broadcast the RREP
  }
 }
}
//the listening() mode
if(the neighbor node receives RREP){
k= packet.sink;
   if(the node.hop > the packet.hop + 1){ // the
node.hop to the Sink k
    update the route to the Sink k and set the
lifetime for the route
 }
}
Algorithm 2: Routing establishment and maintenance.