Research Article

Enabling Cyber Physical Systems with Wireless Sensor Networking Technologies, Multiagent System Paradigm, and Natural Ecosystems

Algorithm 2

Algorithm for creating part of an SSN in a given area of interest.
createSSN(AoI)
//AoIs is the set of areas of interest
sensor s within an AoI, do
//the sensor checks the type of the message received
  if (JoinService() message is received) {
 save sender as previous hop
 save sender id, role and type
 if (JoinService() is received for the first time by s) {
set role s
send ReplyJoinService()
broadcast JoinService()
set timer to predefined value
 }
 else //message was received before
send ReplyJoinService
  }
  else if(ReplyJoinService() message is received) {
save sender as next hop
save sender id, role and type
  }
  else //RollBack message is received
aggregate paths from s to leaves
Wait for new messages and repeat steps
if no new message (Join/Rep/RollBack) after timer expired
   send RollBack(path, ids) to the CH sensor to which s belongs