# Gateway-Assisted Retransmission for Lightweight and Reliable IoT Communications
## 4 Simulation Model  
In this section, we describe our simulation model. Our simulation model for each method is implemented as an OMNet++ module [11]. IoT devices, gateways, and servers are three entities in our simulation. In the following experiments, the gateway connects to 30 IoT devices. For illustration purposes, we describe the simulation flow chart for IoT devices in GaCoAP. The simulation flow charts for gateways and servers are simpler, and are thus ignored in this paper. Figure 4 is the simulation flow chart for IoT devices in GaCoAP. There are several variables used in the simulation. **num_retrans** is the current number of retransmissions. **max_retrans** is the maximum number of retransmissions. **numMessage** is the number of messages published from the device. **numThrow** is the number of messages thrown out. **numFailed** is the number of messages that cannot be sent successfully. **totalRetry** is the total number of retransmissions. **numACK** is the number of ACKs successfully received by the device. **PUBLISH_serialNum** is the serial number of current PUBLISH messages. **RECEACK_serialNum** is the serial number of each received ACK message. **BUSY** parameter is used to indicate whether the device is waiting for ACK or not. If it is waiting for the ACK of the first transmitted message, BUSY is set to 1. If it is waiting for the ACK of the retransmitted message, BUSY is set to 2. Otherwise, BUSY is set to 0; **RETRANSMISSION** parameter is used to indicate whether this message is the retransmitted message or a newly generated message. If the message is a retransmitted message, RETRANSMISSION is set to true. Figure 3: The procedure of our scheme. Steps in the simulation model are described as follows:  
1. Devices initialize the setting. For example, numMessage is set to 0. 2. Generate the first PUBLISH message, which is treated as an event. Then, insert this event into the event list. 3. Delete the first event \(e\) from the event list. This event now needs to be processed. 4. Extract _e.type_ to see what type this event is. If the type is PUBLISH, go to Step 5. If the type is TIMEOUT, go to Step 9. If the type is RECEACK, to to Step 13. 5. Parameters numMessage and PUBLISH_serialNum is increased by 1. Generate the next PUBLISH message and insert it to event list. Figure 4: Simulation flow chart. * Check BUSY status. If BUSY is 0, the device sends the message at Step 7. The condition BUSY = 2 means that the device is waiting for an ACK of retransmitted message. By applying RRP policy, the device stops waiting and sends the newly generated message. When the device sends the message, BUSY is set to 1. Set the initial RTO to the default value or the value calculated before. Generate the TIMEOUT event based on RTO and insert it into the event list, and also generate the RECEACK event and insert it into the event list. Set the RECEACK_serialNum of the RECEACK event to PUBLISH_serialNum. If BUSY is 1, numThrow is increased by 1, which means that this message is thrown out. Go to Step 18. * If the type is TIMEOUT, check whether the corresponding RECEACK event occurs or not. If the ACK is received, go to Step 18; otherwise, go to Step 10. * Check whether the device can retransmit the message. If \(num\_retrans<max\_retrans\), go to Step 12 for retransmission; otherwise, go to Step 11. * The device has no quota to retransmit the message, so this message is not sent successfully. numFailed is increased by 1 and num_retrans is set to 0. Go to Step 18. * BUSY is set to 2 and the RTO is set up. num_retrans and totalRetry, are increased by 1. Generate the TIMEOUT and RECEACK events and insert them to the event list. Set the RECEACK_serialNum of the RECEACK event to PUBLISH_serialNum. Go to Step 18. * If the type is RECEACK, check whether this ACK belongs to the device itself. If this ACK does not belong to the device, go to Step 14; otherwise, go to Step 16. * If the received RTO is larger than current RTO in device at Step 14, update the RTO with the newly received one, and then go to Step 18.