(1) /* service requests received from higher layers */ |
(2) for each ( received from higher layers) { |
(3) var = danceFloor · getForager ; |
(4) if ( != NULL) { |
(5) encapsulate into the payload of ; |
(6) send to entranceFloor; |
(7) } |
(8) else { |
(9) insert into the packet queue; |
(10) create a new scout with ID, initial TTL; |
(11) encapsulate into the header of ; |
(12) set timer of ; |
(13) send to entranceFloor; |
(14) } |
(15) } |
(16) |
(17) /* packets coming from entrance floor */ |
(18) for each ( received from entrance) { |
(19) if ( is a forager) { |
(20) danceFloor · addForager ; |
(21) extract from the payload of forager; |
(22) deliver to higher layers; |
(23) } |
(24) else if ( is a scout) { |
(25) for each ( gathered by ) { |
(26) create a forager foreach ; |
(27) danceFloor · addForager ; |
(28) } |
(29) kill ; |
(30) } |
(31) for each ( add to dance floor) { |
(32) var packers = getNumberPacketInQueueForForager(); |
(33) while (packers > 0 && > 0) { |
(34) encapsulate into payload of ; |
(35) send to entrance; |
(36) decrease packers; |
(37) } |
(38) } |
(39) } |
(40) |
(41) /* check scout return */ |
(42) if (timer expired and scout not returned) { |
(43) compute newTTL of and assign it a newID; |
(44) set timer of ; |
(45) send it to entrance; |
(46) } |