# Internet of Bikes: A DTN Protocol with Data Aggregation for Urban Data Collection
## 8 Performance Improvement of IoB-DTN Based on Data Aggregation Mechanism  
In this section, we investigate an efficient multi-hop IoB-DTN protocol based on data aggregation approach being applied to mobile network IoT devices running a data collection application in order to enhance its performances. The idea is to combine data packets of different nodes into a single packet. This mechanism is performed during the generation and the reception of a new data packet, which are depicted in Algorithms 2 and 3, respectively. We propose three variants of IoB-DTN protocol:  
* _Spatial aggregation (IoB-SA)_: Data packets are aggregated if they were generated in the same area whose its range is defined in meters.  
Figure 23: Average effective duty cycle.  
Figure 22: Average throughput.  
* _Temporal aggregation (IoB-TA)_: Data packets are aggregated if they were generated less than a period defined in seconds earlier or later than the reference packet.
* _Spatiotemporal aggregation (IoB-STA)_: Data packets are aggregated if they satisfy the two preceding conditions.  
```
1:At each sensor reading period
2:Generate a packet \(p\) with the readings
3:if (\(\Delta\) (\(p\), \(p^{\prime}\)) < (\(\Delta\) area \(\mid\mid\Delta\) period \(\mid\mid\) (\(\Delta\) area + \(\Delta\) period) ) ) then
4: Aggregate \(p\) with the packet \(p^{\prime}\)
5:else
6:if Buffer management provides a slot then
7: Store \(p\cup N^{0}\) in the buffer [\(N^{0}\) copies of \(p\) are stored]
8:endif
9:endif
```  
**Algorithm 2**_Generation phase_: IoB-DTN based on data aggregation.  
```
1:On reception of packet \(p\cup N\cup L\) (list of neighbors)
2:\(pos\leftarrow\) self position in \(L\)
3:\(N^{\prime}\leftarrow\frac{N}{2^{pos+1}}\)
4:if (\(\Delta\) (\(p\), \(p^{\prime}\)) < (\(\Delta\) area \(\mid\mid\Delta\) period \(\mid\) (\(\Delta\) area + \(\Delta\) period) ) ) then
5: Aggregate \(p\) with the packet \(p^{\prime}\)
6:else
7:if Buffer management provides a slot and \(N^{\prime}\geq 1\) then
8: Store \(p\cup N^{\prime}\)
9: Send ACK for receiving \(N^{\prime}\) copies of \(p\)
10:else
11: Packet is rejected, no ACK is sent
12:endif
13:endif
```  
**Algorithm 3**_Reception phase_: IoB-DTN based on data aggregation.  
Based on the previous section, we suppose here that the data packet has size of 20 bytes that could be forwarded by a low-power long-range technology as LoRa/LoRaWAN. Considering the 802.11p packet size having as a value 160 bytes, we can identify two approaches:  
* _Without size reduction aggregation_: Each node can combine up to seven data packets into the same packet coming from various neighbors nodes without data processing.
* _With size reduction aggregation_: Each node receives more than seven data packets to be combined into the same packet, and compresses their readings. In other words, each node performs the basic aggregation functions to process data to limit the number of data packets aggregated into the same packet. To accomplish that, simple functions are used such as the Average, SUM, COUNT, MAX, MIN, etc. The use of this operation depends on the type of data collection application. This paper does not consider the aggregation function since our protocols are independent of it.  
Next, we gives a performance evaluation of IoB-DTN protocol based on data aggregation approach. More precisely, we compare the three variants of IoB mentioned before. We assess four metrics: delivery rate, delivery delay, throughput and energy consumption. We remember that we present the average results for ten scenarios simulated by varying the paths of bicycles in each scenario.