# Internet of Bikes: A DTN Protocol with Data Aggregation for Urban Data Collection
## 4 IoB-DTN: Internet of Bikes-DTN Protocol  
This section introduces the IoB-DTN protocol. It is based on the DTN paradigm which is designed for networks that may lack continuous connectivity. To cope with the intermittent connection between bicycles, the store-carry-forward mechanism is applied [43]. The data are forwarded to intermediate nodes where they are kept and sent at a later time to another intermediate nodes or to the final destination.  
Unlike the mobility models of other transport systems that are expected and occasional, our mobility pattern of our smart biking network is human created. From this perspective, IoB-DTN protocol is based on replication-based routing protocols, called flooding approaches, that do not require knowledge about the network topology to route data [44]. Flooding approaches rely mostly on replication. Multiple copies of each message are diffused to a set of nodes, called relays, with the purpose of maximizing the delivery probability of packets. Notably, IoB-DTN is a lightweight variant of Binary Spray and Wait DTN routing protocol [45] in which the number of copies sprayed in the network is limited. Hereby, it reduces energy consumption of nodes. Binary Spray and Wait protocol is an improvement over Spray and Wait [45]. The source of a message initially starts with L copies; any node that has at least two copies and encounters another node having no copies forwards n/2 stored copies and keeps n/2 for itself. When it is left with only one copy, the last copy is transmitted to final destination.  
The description in details of IoB-DTN protocol is given in Algorithm 1. In IoB-DTN, each node generates periodically a packet \(P\) with the readings. The packet \(P\) and its initial number of copies \(N\) are stored in the buffer if the buffer management policy used provides a slot. When the duty cycle is over, each node verifies the existence of a base station in its vicinity. If the node lies in the area of one or more base stations, it forwards all data stored in its buffer to only them. If not, it sends packets having more than one copy, their number of copies and its neighbors list to neighbors nodes. When receiving a packet, each node determines its position in the neighbors list of the source node in order to calculate the new number of copies \(N^{\prime}\) to be kept. The received packet is then stored in the buffer with \(N^{\prime}\), if it is at least equal to one, and an acknowledgement (ACK) is sent to the source node. At the reception of an ACK, each node deletes the corresponding packet if the sender node is a base station, alternatively it updates the number of copies \(N^{\prime}\).  
Figure 1: Illustration of our smart bike sharing system.  
```
1:At each sensor reading period
2:Generate a packet \(p\) with the readings
3:if Buffer management provides a slot then
4: Store \(p\cup N^{0}\) in the buffer [\(N^{0}\) copies of \(p\) are stored]
5:endif
6:
7:When duty cycle is over
8:\(\mathcal{L}\leftarrow\) the list of neighbors
9:if a base station is in \(\mathcal{L}\)then
10: Send all packets in buffer
11:else
12:for all packet \(p\cup N\) in buffer do
13:if N (number of copies) > 1 then
14: Send \(p\cup N\cup\mathcal{L}\)
15:endif
16:endfor
17:endif
18:Wait for next duty cycle
19:
20:On reception of packet \(p\cup N\cup\mathcal{L}\)
21:\(pos\leftarrow\) self position in \(\mathcal{L}\)
22:\(N^{\prime}\leftarrow\frac{N}{2^{\prime\prime\prime\prime}+1}\)
23:if Buffer management provides a slot and \(N^{\prime}\geq 1\)then
24: Store \(p\cup N^{\prime}\)
25: Send ACK for receiving \(N^{\prime}\) copies of \(p\)
26:else
27: Packet is rejected, no ACK is sent
28:endif
29:
30:On reception of an ACK of \(p\) and \(N^{\prime}\)
31:if sender node is a base station then
32: Delete \(p\) from buffer
33:else
34: Update the number of copies of \(p:N^{\prime\prime}\gets N-N^{\prime}\)
35:endif
```  
**Algorithm 1** IoB-DTN protocol.