Research Article

A Network Coding-Based Braided Multipath Routing Protocol for Wireless Sensor Networks

Algorithm 6

Transmissions procedure for each node u.
(1) Upon receiving a packet{OriginID, Flag, SenderID,MainrouterID, Seqnum, PayLoad}
(2) If u is the sink then
(3)  If has enough packets
(4)   call the decoding procedure;
(5)  Else
(6)   waiting for next package;
(7)  End if
(8) Else if senderID is in myChildren set then
(9)  If flag equals 1 then
(10)   If senderID is the first one in the parentlist of senderID then
(11)    If has enough packets
(12)     update flag and mainrouterID with 1 and u, respectively;
(13)    Else
(14)     reencode the packets and generate new packets, update flag and mainrouterID with 1 and u, respectively;
(15)    End if
(16)   Else
(17)    If has enough packets
(18)     update flag and mainrouterID with 0 and the first ID in the parentlist of senderID, respectively;
(19)    Else
(20)     reencode the packets and generate new packets, update flag and mainrouterID with 0 and the first ID in the parentlist of senderID, respectively;
(21)    End if
(22)   End if
(23) Else if mainrouterID is in myChildren set then
(24)  If senderID is the first one in the parentlist of mainrouterID then
(25)   If has enough packets
(26)    update flag and mainrouterID with 1 and u, respectively;
(27)   Else
(28)    reencode the packets and generate new packets, update flag and mainrouterID with 1 and u, respectively;
(29)   End if
(30)  Else
(31)   If has enough packets
(32)    update flag and mainrouterID with 0 and the first ID in the parentlist of senderID, respectively;
(33)   Else
(34)    reencode the packets and generate new packets, update flag and mainrouterID with 0 and the first ID in the parentlist of senderID, respectively;
(35)   End if
(36)  End if
(37) End if
(38)  generate new packets {originID, flag, mainrouterID,senderID, seqnum, payload(i)} and broadcast them;
(39)  Else
(40)   discard this packet;
(41) End if
(42) End upon