## 4 The Proposed Model
### ABT-RRMAC Implementation  
The ABT-RRMAC algorithm is implemented in the Omnet++ network simulator in the _DcfUpperMAC_ module, which is the main class in which the most important operations at the MAC layer are provided, such as frame and collision management; therefore, as explained in [24], the sectorization of the plane is managed by the SAS antenna module (_PlasedArray_ module). The following pseudo-code (Algorithm 1) enhances the original round-robin MAC formulation:  
Figure 8: Adaptive beamforming time RR-MAC example. ```
1:procedureInit(\(numSectors\))
2:\(numQueues\gets numSectors\)
3:CreateQueues(numQueues)
4:endprocedure
5:procedureassignSectorTime(\(trainingPeriod\), \(updatePeriod\), \(numQueues\))
6:ifSim.Time () < trainingPeriod \(|\) | Sim.Time()< updatePeriod then
7:\(averageSectorsTime=0\);
8:for i = 1; i< numQueues; i++ do
9:\(sectorTime[i]=T_{s}\);
10:endfor
11:else
12:\(averageSectorsTime=computeAverageSectorsTime()\)
13:for i = 1; i< numQueues; i++ do
14:\(sectorTime[i]=\frac{MT_{s}}{\sum_{i=1}^{N}size_{t_{i}}}\times averageSectorsTime\);
15:endfor
16:endif
17:endprocedure
18:procedurestartTransmit(frame)
19:intframeSector=getFrameSector(frame);
20:intcurrentActiveSector=getCurrentActiveSector();
21:ifcurrentActiveSector!= frameSector then
22:\(queueSector[frameSector].insert(frame)//queuetheframe\)
23:else
24:\(transmissionQueue\).insert(frame);
25:\(transmitFrame\gets queueSector[activeSector].front()\)
26:\(queueSector[activeSector].pop()\)
27:configureAntenna(activeSector)
28:endif
29:endprocedure
30:procedurestartReceptionState
31:configureAntenna(omnidirectional)
32:MAC in reception Mode
33:scheduleEvent(\(CSMATime\))
34:endprocedure
35:procedurereceptionFrame(frame)
36:\(orientation\leftarrow\textsc{getOrientation}(frame)\)
37:\(sector\leftarrow\textsc{getSector}(orientation)\)
38:\(configureAntenna(sector)\)
39:endprocedure
40:procedure
41:procedurereceiveFrameFromUpperLayers(frame)
42:\(sector\leftarrow\textsc{getSector}(frame)\)
43:\(queueSector[sector].push\_back(frame)\)
44:endprocedure
45:procedureMacProccess
46:Init(\(NumSectors\))
47:startReceptionState
48:loop
49:WaitEvent
50:ifEvent Is Upper Frame then
51:receiveFrameFromUpperLayers(frame)
52:elseifEvent Is Lower Frame then
53:receitionFrame(frame)
54:elseifEnd Transmission then
55:startReceptionState
56:elseifEnd\(CSMA\wedge QueueSector\
eq empty\)then
57:startTransmit(frame)
58:else
59:startReceptionState
60:endif
61:endloop
62:endprocedure
```  
**Algorithm 1** ABT-RRMAC pseudo-codeAt the beginning of the process, after the plane is sectorized into equal width sectors, the same quantum of time is assigned for all sectors (round-robin). If the _trainingPeriod_ has elapsed, the _averageSectorsTime_ denoting the mean beamforming time averaged by all sectors can be computed; remember that this parameter is updated periodically after an _updatePeriod_ (that we set to 10 s) has passed; from the first time that the _averageSectorsTime_ is computed, the beamforming times of the sectors are assigned according to expressions defined in Section 4.2. The whole of these operations are included in the _AssignSectorTime_ function. The transmission of frames is ruled by the _StartTransmit_ function in which the system checks if the sector for which is destined the current frame is the _current active sector_. If true, it inserts the frame in the transmission queue and transmits the frame; otherwise, the frame is queued in its waiting sector queue and delayed until its sector is no longer the current active sector. The reception of the frame is performed by the _ReceptionFrame_ and _ReceiveFromUpperLayers_ functions in which the receiver antenna is configured in omnidirectional mode and the information about the orientation of the transmitter antenna is retrieved in order to achieve synchronization during the communication process. Other coordination functions are performed by the _MacProcess_ procedure.