# Rethinking Modbus-UDP for Real-Time IIoT Systems
## 3 Protocol Specification
### MBAP Header and TID  
The layout of the Modbus-UDP MBAP header, shown in the top half of Figure 4, is the same as in Modbus-TCP [8]. Multi-byte fields must be transmitted in network byte order, that is, big endian. The protocol identifier and length are used in accordance with [8]. Protocol identifier zero indicates a standard Modbus message, while other values indicate \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & \multicolumn{4}{c}{**RH Transaction**} & \multicolumn{4}{c}{**WM Transaction**} \\ \cline{2-7} \multirow{2}{*}{\(N\)} & **Request** & **Response** & **Total** & **Request** & **Response** & **Total** \\  & \(L_{1}^{\text{(RH,S)}}\) & \(L_{1}^{\text{(RH,R)}}\) & \(L_{1}^{\text{(RH)}}\) & \(L_{1}^{\text{(WM,S)}}\) & \(L_{1}^{\text{(WM,R)}}\) & \(L_{1}^{\text{(WM)}}\) \\ \hline
1 & 72 & 72 & 144 & 73 & 72 & 145 \\
60 & 72 & 187 & 259 & 191 & 72 & 263 \\
120 & 72 & 307 & 379 & 311 & 72 & 383 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: L1 packet length \(L_{1}\) of RH and WM transactions, in bytes. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & \multicolumn{4}{c}{**RH Transaction**} & \multicolumn{4}{c}{**WM Transaction**} \\ \cline{2-7} \multirow{2}{*}{\(N\)} & **Request** & **Response** & **Total** & **Request** & **Response** & **Total** \\  & \(L_{7}^{\text{(RH,S)}}\) & \(L_{7}^{\text{(RH,R)}}\) & \(L_{7}^{\text{(RH)}}\) & \(L_{7}^{\text{(WM,S)}}\) & \(L_{7}^{\text{(WM,R)}}\) & \(L_{7}^{\text{(WM)}}\) \\ \hline
1 & 12 & 11 & 23 & 15 & 12 & 27 \\
60 & 12 & 129 & 141 & 133 & 12 & 145 \\
120 & 12 & 249 & 261 & 253 & 12 & 265 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: L4 payload length \(L_{7}\) of RH and WM transactions, in bytes. messages belonging to other protocols. Protocol multiplexing is performed with the same mechanism also defined in [8]. The TID is defined in a backward-compatible way. However, as described in the following, Modbus-UDP attaches additional semantics to it. Finally, the unit identifier is used to identify the target Modbus slave (for requests) or the sending slave (for responses) regardless of whether the slave is directly attached to an Ethernet segment or is a remote slave accessible through a gateway. Unit identifier zero marks broadcast traffic as in the original Modbus specification for RS485 and RS232 buses [2]. The bottom half of Figure 4 shows the TID format. In the figure, bits are laid out from left to right in decreasing order of significance according to the host bit ordering. It is assumed that all hosts participating in the Modbus-UDP protocol have the same bit numbering scheme, so no bit flipping is necessary for interoperability, although their endianness may vary. The _Type_ field identifies the class of a transaction. It is two bits wide and can assume three distinct non-zero values. The reserved value 00\({}_{2}\) shall never be used, to guarantee that no valid TID will ever be zero and simplify the TID checks to be described in Section 3.4. The value 01\({}_{2}\) identifies a unicast numbered transaction. In this kind of transaction, the master generates a fresh TID and puts it in its request. Only the addressed slave is supposed to respond, using the same TID it received from the master, so that the TID can be used to pair requests and responses. The value 11\({}_{2}\) is used for broadcast, unnumbered requests, to which either no responses are expected or responses are not in a one-to-one relationship with requests. For this class of requests and possible responses, the TID is not used to pair requests and responses, and the _Sequence Number_ is always zero. The value 10\({}_{2}\) is reserved for future use. The _Master ID_ field is three bits wide and tells apart TIDs sent independently by different masters when Modbus-UDP is used in a multi-master configuration, such as the ones supported by Modbus-RTU [2] and Modbus-CAN [7] by means of the master election protocol proposed and analyzed in [13; 39]. The Master ID field must have a unique value for each master, and it is wide enough to support up to 8 masters.