# Underwater Wireless Communications for Cooperative Robotics with UWSim-NET
## 2 UWSim-NET
### DCComms Network Simulator  
The modeling of the data link and physical layers of the underwater communication system is in charge of the DCComms Network Simulator module. An accurate modeling of signal propagation (acoustic, RF, VLC, etc.) in sea water requires the characterization of physical parameters such as temperature, salinity, etc. Such a simulation is far from the scope of UWSim-NET purposes. Instead, UWSim-NET pretends to model communication impairments caused signal propagation in physical media as propagation delay and packet loss due to signal attenuation, which depend on the distance between transmission and reception devices. Periodic requests to the transformations tree (TF) system in ROS permit tracking the positions of the devices, and to calculate the distances among them.  
* Propagation delay is calculated considering this distance and the propagation speed in the physical medium.
* The likelihood of losing a packet is determined by means of the length of each packet, and a user provided mathematical expression that relates this distance and the BER. Lost packets are randomly discarded according to it.  
UWSim-NET also accounts for the communication impairments introduced by real devices as packet collisions and the time the modern requires to process and transmit (receive) each packet, which is modeled by means of an intrinsic delay and a jitter. The communication impairments considered in UWSim-NET are:  
* The time the modern requires to process one packet is modeled by the addition of a fixed intrinsic delay and a Gaussian random delay (jitter): Different intrinsic delays can be defined for the transmission and the reception of a packet.
* Transmit and receive delays: The small transmission rates of underwater modems, typically of several kilobits per second (kbps), causes that the times required to transmit or receive a packet being non-negligible. These delays are modeled considering the bitrate of the modem and the length of each data packet.
* Packet collisions: In the case a new packet arrives in a device during the transmission or reception of another packet, both packets are marked as collisions and discarded.
* Transmission FIFO stack: This is where transmission messages are stored temporarily when the device is busy. It has a finite size. Messages arriving when the transmission FIFO is full are thrown away, as occurs in real devices.
* Communication Range: Some modems specify a maximum and minimum distances that guarantee the correct performance of the device. The user can specify these distances and the UWSim-NET will discard all packets sent between two devices whose separation is outside these limits.  
The incorporation of NS3 and AquaSim-NG permits UWSim-NET to use the MAC protocols implemented in AquaSim-NG. The two MAC protocols used in the experiments shown in this manuscript are:  
* CS-ALOHA is a carrier sense version of the ALOHA MAC protocol. When the transmitter detects that the channel is empty, it starts to send the message. The receiver responds with an acknowledgement (ACK) after a successful read. If the transmitter does not receive the ACK within a predefined time, it considers that that the transmission failed and tries to retransmit the message.  
* SFAMA (Slotted Floor Acquisition Multiple Access) divides the time into slots of fixed duration. Slot duration is related with the delay at the maximum communication distance in order to prevent the overlap of RTS messages sent by different ROVs. At the beginning of a slot, the transmitter sends a Request To Send (RTS) message and waits for the Clear To Send (CTS) message sent by the receiver on the reception of CTS. Then, the transmitter starts to send a variable length DATA message. If the transmitter does not receive the CTS message, it assumes that a collision has happened and waits for a number of slots (backoff) before the retransmission of the RTS.