# A Distributed Token Passing Protocol for Time Constrained Data Gathering in VANETs
## 3 Proposed Approach
### Phase I: Token Processing  
We start the protocol design by illustrating the token packet structure, as shown in Figure 3 along with its fields. We define each field and its length (in bit [b] or Byte [B]). There are three possible packets that have a common field (_Type (Tp)_) formed by two bits, which identifies the current packet. In particular, if this value is 00, the packet is the token; if it is 01, the packet is a Neighbour Discovery Broadcast (NDB) message, while, if it is 10, the packet is a Neighbour Discovery Response (NDR) message. The 11 value is not yet assigned. In addition, a _PADDING_ field is inserted: it is either 30 bits for NDB and NDR packets or eight bits for the token. In both cases, this field is set to 0. When nodes receive a packet, parsing the first two bits, they identify the message and can perform the correct operation. Regarding the token packet, we set the following fields:  
* _Link (L)_[1b]: this field contains the token route. If it is 0, the token is in the Discovery Path (DP), if it is 1, the token is in Return Path (RP). In the DP mode, the token discovers the route and searches the best next TO, while in the RP mode the token returns to the Traffic Light (TL) following an optimised route evaluated in the discovery mode. * _Token ID (TID)_[5b]: this field contains the token _unique_ identifier (ID). * _Traffic light ID_[2B]: this field contains the RSU traffic light unique identifier. Figure 2: Token passing scheme for Discovering Phase. * _Max Available Hop (MAH)_[2B]: this field contains the maximum number of hops in discovery mode. This value is given by Algorithm 1. The TL evaluates the maximum hop number divided the amount of time for the neighbour discovery (ND). If the evaluated time to perform the discovery path and the estimated return path (the RP hops number is less than or equal to the DP hops number) (We assume that in the discovery path the ND time duration is much bigger than the transmission time.) is bigger than the amount of time, it decreases the MAH by one and re-calculates the time. * _Hop Counter (HC)_[2B]: this field contains the token hop number. When a node receives the token, it increases this field by one if the token is in DP mode, while it decreases this field by one if the token is in RP mode. * _Time Token Emission (TTE)_[2B]: this field contains the seconds that have elapsed since an epoch (For example, we can define an our own reference data, i.e., Monday, 1 January 2019, 00:00:00 UTC.). * _ND time duration_[2B]: this field contains the time (in _ms_) used for the ND. * _Next TO ID_[2B]: this field contains the _next_ TO identifier. * _Amount Time (AmTime)_[1B]: this field contains the amount of time to perform token passing (in seconds). Within this time, the token must return to the TL. It is worth noticing that TTE could be different with respect to the red time start to allow the vehicles queue to be formed. * _Visiting Nodes ID (VNsID)_ [variable length]: this field contains all the nodes visited in DP mode, or all the nodes that will be visited in RP mode. The field length is extracted by the _Hop Counter_ field. The queue is managed according to the last in first out (LIFO) discipline in DP mode and first in first out (FIFO) in RP mode. In other terms, in the discovery mode, the first ID is the first node visited by the token, in return mode, the first ID is the next TO. * _Data_ [variable length]: this field contains the data processed by the devices visited by the token. Within this phase, the device selected as the actual TO checks the \(L\) field and, according to Algorithm 2, it enters the correct phase. ```
1:Max Hop = floor(AmTime / ND time duration)
2:repeat
3:ifAmTime - (Max Hop\(\times\)ND time duration + (Max Hop - 1)\(\times\)TX time duration) then
4: exit
5:else
6:Max Hop \(\leftarrow\) Max Hop - 1
7:until Max Hop is 0
8: Set Max Hop in token packet

Figure 3: Token packet structure. ### Phase II: Neighbor Discovery

This phase is performed only under specific conditions, i.e., if the token is in Discovering Mode.