# MAC/PHY Comprehensive Visible Light Communication Networks Simulation
## 4 Proposed Simulation Scheme
### Physical Layer Sub-Module  
The PHY sub-module evaluates the communication link using the results of the channel simulation process using Equations (8) and (10). First of all, the received power is compared to the endpoint sensitivity. If the power is lower than this threshold, this module marks the packet as lost. On the other hand, it is checked by the collision detection block of the submodule, and it is determined if the packet has been correctly received. Using the SNR, the Bit Error Rate (BER) can be easily calculated depending on the configuration of the VLC PHY transmission mode. For a given packet length \(N_{packet}\), the number of errors \(N_{e}\) in the frame follows a Binomial distribution (Equation (11)):  
\[N_{e}\sim B(N_{packet},BER). \tag{11}\]  
Depending on the error-correction scheme of the transmission mode, the packet would be marked as correctly received or not, appropriately informing the upper layer.  
The MAC layer sub-module performs the logical decisions that each node makes during the protocol execution. The sub-modules of both the coordinator and user nodes behave differently. One of the most relevant discrepancies is the synchronization block. The coordinator's sync block transmits beacon frames continuously to provide a time reference to the users, whilst the user's sync block receives these beacon frames and operates accordingly. When it is not possible to receive a beacon (due to collisions or poor channel performance) this sub-module stays idle.  
When a frame arrives from the physical layer, the MAC layer checks the frame type. This stage categorizes the frame by its function (Data, ACK, Command, or Beacon) and relies it to the correct block to be processed. Command frames are dispatched to the MAC control block, the actions performed by this block depend on the message itself, and are related to different mechanisms of the standard that were described in Section 3. On the other hand, data frames need to be handled simultaneously by the temporal filter block and the ID control block. The temporal Filter block verifies that user packets are in their correct superframe window. If they arrive when the packet is not supposed to, they are discarded. The ID control block verifies the ID of the sender and recipient. The coordinator's block checks if the sender is allowed to use this access point. In case that the recipient is associated with it, the frame is sent using the VLC channel, otherwise it is passed to upper layers. At this point, the statistics generated during the packet transmission are collected. Finally, the output control block handles the data transmission, and it can operate in CAP or CFP mode according to the user's resources. This block  
Figure 6: Block diagram of the physical layer sub-module.  
executes the random back-off mechanism and queues packets. Figure 7 illustrates the organization diagram of this sub-module.  
In the simulator, it is possible to add more communication layers. Nevertheless, in this work, a network encompassing just the MAC and PHY layers has been evaluated. The rest of the layers were simplified, only generating data to be transmitted and collecting metrics for the evaluation.