LteAllocationModule.h Source File

Simu5G: LteAllocationModule.h Source File
Simu5G
LteAllocationModule.h
1//
2// Simu5G
3//
4// Copyright (C) 2012-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef _LTE_LTEALLOCATIONMODULE_H_
14#define _LTE_LTEALLOCATIONMODULE_H_
15
16#include "simu5g/common/LteCommon.h"
17#include "simu5g/stack/mac/allocator/LteAllocatorUtils.h"
18
19#include "simu5g/stack/mac/LteMacEnb.h"
20
21namespace simu5g {
22
23using namespace omnetpp;
24
25class LteMacEnb;
26
27class LteAllocationModule
28{
29 // Members *********************************************************************************
30
31 // --- General Parameters ------------------------------------------------------------------
32
33 protected:
34
36 opp_component_ptr<LteMacEnb> mac_;
37
39 unsigned int bands_ = 0;
40
42 Direction dir_;
43
45 bool usedInLastSlot_ = false;
46
47 /*
48 * We will consider the following two planes
49 *
50 * plane
51 * [0] represents the main OFDMA space
52 * [1] the space obtained by summing all the Mu-Mimo spaces
53 */
54
55 // *************************** RESOURCE BLOCKS MATRIX ***************************
61 std::vector<std::vector<unsigned int>> totalRbsMatrix_;
62
68 std::vector<std::vector<unsigned int>> allocatedRbsMatrix_;
69
75 std::vector<std::vector<std::vector<unsigned int>>> freeRbsMatrix_;
76
77 /************************************************************
78 * From UE to Logical Band
79 ************************************************************/
80
81 public:
82
83 // Amount of bytes served by a single set of allocated blocks
84 struct AllocationElem
85 {
87 unsigned int resourceBlocks_;
89 unsigned int bytes_;
90 };
91
92 typedef std::list<AllocationElem> AllocationList;
93
94 typedef std::map<Band, AllocationList> PerBandAllocationMap;
95
96 typedef std::map<Band, unsigned int> PerBandAllocatedRbsMap;
97
99 struct AllocatedRbsPerUeInfo
100 {
102 unsigned int allocatedBlocks_ = 0;
104 unsigned int allocatedBytes_ = 0;
105
106 // amount of blocks allocated for this UE for each remote and for each band
107 std::map<Remote, PerBandAllocatedRbsMap> ueAllocatedRbsMap_;
109 std::map<Remote, PerBandAllocationMap> allocationMap_;
110 // amount of blocks allocated for this UE for each remote
111 std::map<Remote, unsigned int> antennaAllocatedRbs_;
112
113 // antennas available for this user
114 RemoteSet availableAntennaSet_;
115
116 // first available antenna
117 Remote currentAntenna_ = MACRO;
118
119 public:
120
121 AllocatedRbsPerUeInfo()
122 {
123 availableAntennaSet_.insert(MACRO);
124 }
125 };
126
127 typedef std::map<MacNodeId, AllocatedRbsPerUeInfo> AllocatedRbsPerUeMap;
128
129 // b) Variables
130
131 protected:
132
134 AllocatedRbsPerUeMap allocatedRbsUe_;
135
136 private:
137 virtual void ensureNodeInitialized(const MacNodeId nodeId);
138
139 /************************************************************
140 * From Logical Bands to UE
141 ************************************************************/
142
143 public:
144
145 typedef std::map<MacNodeId, unsigned int> UeAllocatedBlocksMap;
146 typedef std::map<MacNodeId, unsigned int> UeAllocatedBytesMap;
147
149 struct AllocatedRbsPerBandInfo
150 {
152 UeAllocatedBlocksMap ueAllocatedRbsMap_;
154 UeAllocatedBytesMap ueAllocatedBytesMap_;
155
157 unsigned int allocated_ = 0;
158
159 AllocatedRbsPerBandInfo()
160 {
161 }
162
163 friend std::ostream& operator<<(std::ostream& os, const AllocatedRbsPerBandInfo& e) {
164 os << "allocated=" << e.allocated_ << " ueRbs=" << e.ueAllocatedRbsMap_.size()
165 << " ueBytes=" << e.ueAllocatedBytesMap_.size();
166 return os;
167 }
168 };
169
170 typedef std::map<Band, AllocatedRbsPerBandInfo> AllocatedRbsPerBandMap;
171
172 protected:
173
177 std::vector<std::vector<AllocatedRbsPerBandMap>> allocatedRbsPerBand_;
178
179 /*
180 * Stores the block-allocation info of the previous TTI in order to use it for interference computation
181 */
182 std::vector<std::vector<AllocatedRbsPerBandMap>> prevAllocatedRbsPerBand_;
183
184 public:
185
187 LteAllocationModule(LteMacEnb *mac, const Direction direction);
188
190 virtual ~LteAllocationModule() {}
191
192 // init Allocation Module structure
193 virtual void init(const unsigned int resourceBlocks, const unsigned int bands);
194
195 // reset Allocation Module structure
196 virtual void reset(const unsigned int resourceBlocks, const unsigned int bands);
197
198 // ************** Resource Blocks Allocation Status **************
199 // Returns the amount of available blocks in the whole system
200 virtual unsigned int computeTotalRbs();
201
202 // returns the amount of free blocks for the given band in the given plane
203 virtual unsigned int availableBlocks(const MacNodeId nodeId, const Plane plane, const Band band);
204
205 // returns the amount of free blocks for the given band and for the given antenna
206 virtual unsigned int availableBlocks(const MacNodeId nodeId, const Remote antenna, const Band band);
207 // ***************************************************************
208
209 // ************** Resource Blocks Allocation Methods **************
210 // tries to satisfy the resource block request in the given band and for the given antenna
211 bool addBlocks(const Remote antenna, const Band band, const MacNodeId nodeId, const unsigned int blocks,
212 const unsigned int bytes);
213
214 // tries to satisfy the resource block request in the first available antenna
215 virtual bool addBlocks(const Band band, const MacNodeId nodeId, const unsigned int blocks, const unsigned int bytes);
216
217 // remove resource Blocks previously allocated in a band by a UE
218 virtual unsigned int removeBlocks(const Remote antenna, const Band band, const MacNodeId nodeId);
219 // ****************************************************************
220
221 // --- Get (Parameters) --------------------------------------------------------------------
222
223 // Simple block-amount returning methods
224
232 unsigned int getBlocks(const Remote antenna, const Band band, const MacNodeId nodeId)
233 {
234 Plane plane = MAIN_PLANE;
235 return allocatedRbsPerBand_[plane][antenna][band].ueAllocatedRbsMap_[nodeId];
236 }
237
238 /*
239 * Returns the amount of blocks allocated in a Band
240 */
241 virtual unsigned int getAllocatedBlocks(Plane plane, const Remote antenna, const Band band);
242 virtual unsigned int getInterferingBlocks(Plane plane, const Remote antenna, const Band band);
243
244 unsigned int getBytes(const Remote antenna, const Band band, const MacNodeId nodeId)
245 {
246 Plane plane = MAIN_PLANE;
247 return allocatedRbsPerBand_[plane][antenna][band].ueAllocatedBytesMap_[nodeId];
248 }
249
250 // computes the amount of blocks allocated by the given UE
251 unsigned int getBlocks(const MacNodeId nodeId)
252 {
253 return allocatedRbsUe_[nodeId].allocatedBlocks_;
254 }
255
256 // computes the amount of blocks allocated for the given plane and the given antenna
257 unsigned int getBlocks(const Plane plane, const Remote antenna)
258 {
259 return allocatedRbsMatrix_[plane][antenna];
260 }
261
262 virtual unsigned int rbOccupation(const MacNodeId nodeId, RbMap& rbMap);
263
264 // --------- Map Iteration Methods --------->
265 AllocatedRbsPerUeMap::const_iterator getAllocatedBlocksUeBegin()
266 {
267 return allocatedRbsUe_.begin();
268 }
269
270 AllocatedRbsPerUeMap::const_iterator getAllocatedBlocksUeEnd()
271 {
272 return allocatedRbsUe_.end();
273 }
274
275 std::vector<std::vector<unsigned int>>::const_iterator getAllocatedBlocksBegin()
276 {
277 return allocatedRbsMatrix_.begin();
278 }
279
280 std::vector<std::vector<unsigned int>>::const_iterator getAllocatedBlocksEnd()
281 {
282 return allocatedRbsMatrix_.end();
283 }
284
285 // Band Allocation Map
286 AllocationList::const_iterator getAllocatedBlocksUeAllocationListBegin(const Remote antenna, const Band b,
287 const MacNodeId nodeId)
288 {
289 return allocatedRbsUe_[nodeId].allocationMap_[antenna][b].begin();
290 }
291
292 AllocationList::const_iterator getAllocatedBlocksUeAllocationListEnd(const Remote antenna, const Band b,
293 const MacNodeId nodeId)
294 {
295 return allocatedRbsUe_[nodeId].allocationMap_[antenna][b].end();
296 }
297
298 /*
299 * Support for allocation with frequency reuse
300 */
301
302 // Store the Allocation based on passed parameters
303 virtual void storeAllocation(std::vector<std::vector<AllocatedRbsPerBandMapA>> allocatedRbsPerBand, std::set<Band> *untouchableBands = nullptr)
304 {
305 return;
306 }
307
308 // Get the bands already allocated
309 virtual std::set<Band> getAllocatorOccupiedBands()
310 {
311 std::set<Band> bandVector;
312 return bandVector;
313 }
314
315 // returns the number of logical bands
316 unsigned int getNumBands()
317 {
318 return bands_;
319 }
320
321};
322
323} //namespace
324
325#endif
326
Definition AlertReceiver.h:24
unsigned short Band
Logical band.
Definition LteTypes.h:140
std::map< Remote, std::map< Band, unsigned int > > RbMap
Definition LteTypes.h:145
This structure contains information for a single band.
Definition LteAllocationModule.h:150
UeAllocatedBlocksMap ueAllocatedRbsMap_
Stores for each UE the amount of blocks allocated in the structure band.
Definition LteAllocationModule.h:152
UeAllocatedBytesMap ueAllocatedBytesMap_
Stores for each UE the amount of bytes allocated in the structure band.
Definition LteAllocationModule.h:154
unsigned int allocated_
Stores the amount of blocks allocated to every UE in the structure band.
Definition LteAllocationModule.h:157
std::map< Remote, PerBandAllocationMap > allocationMap_
When an allocation is performed, the amount of blocks requested and the amount of bytes is registered...
Definition LteAllocationModule.h:109
unsigned int allocatedBlocks_
Stores the amount of blocks allocated in every band by the structure UE.
Definition LteAllocationModule.h:102
unsigned int allocatedBytes_
Stores the amount of bytes allocated to every UE in the structure band.
Definition LteAllocationModule.h:104