A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fdtbfq-ff-mac-scheduler.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
19  * Modification: Dizhi Zhou <dizhi.zhou@gmail.com> // modify codes related to downlink scheduler
20  */
21 
22 #include <ns3/log.h>
23 #include <ns3/pointer.h>
24 #include <ns3/math.h>
25 
26 #include <ns3/simulator.h>
27 #include <ns3/lte-amc.h>
28 #include <ns3/fdtbfq-ff-mac-scheduler.h>
29 #include <ns3/lte-vendor-specific-parameters.h>
30 #include <ns3/boolean.h>
31 #include <ns3/integer.h>
32 #include <set>
33 
34 NS_LOG_COMPONENT_DEFINE ("FdTbfqFfMacScheduler");
35 
36 namespace ns3 {
37 
38 int FdTbfqType0AllocationRbg[4] = {
39  10, // RGB size 1
40  26, // RGB size 2
41  63, // RGB size 3
42  110 // RGB size 4
43 }; // see table 7.1.6.1-1 of 36.213
44 
45 
46 NS_OBJECT_ENSURE_REGISTERED (FdTbfqFfMacScheduler);
47 
48 
49 
51 {
52 public:
54 
55  // inherited from FfMacCschedSapProvider
56  virtual void CschedCellConfigReq (const struct CschedCellConfigReqParameters& params);
57  virtual void CschedUeConfigReq (const struct CschedUeConfigReqParameters& params);
58  virtual void CschedLcConfigReq (const struct CschedLcConfigReqParameters& params);
59  virtual void CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params);
60  virtual void CschedUeReleaseReq (const struct CschedUeReleaseReqParameters& params);
61 
62 private:
64  FdTbfqFfMacScheduler* m_scheduler;
65 };
66 
67 FdTbfqSchedulerMemberCschedSapProvider::FdTbfqSchedulerMemberCschedSapProvider ()
68 {
69 }
70 
71 FdTbfqSchedulerMemberCschedSapProvider::FdTbfqSchedulerMemberCschedSapProvider (FdTbfqFfMacScheduler* scheduler) : m_scheduler (scheduler)
72 {
73 }
74 
75 
76 void
78 {
79  m_scheduler->DoCschedCellConfigReq (params);
80 }
81 
82 void
83 FdTbfqSchedulerMemberCschedSapProvider::CschedUeConfigReq (const struct CschedUeConfigReqParameters& params)
84 {
85  m_scheduler->DoCschedUeConfigReq (params);
86 }
87 
88 
89 void
90 FdTbfqSchedulerMemberCschedSapProvider::CschedLcConfigReq (const struct CschedLcConfigReqParameters& params)
91 {
92  m_scheduler->DoCschedLcConfigReq (params);
93 }
94 
95 void
96 FdTbfqSchedulerMemberCschedSapProvider::CschedLcReleaseReq (const struct CschedLcReleaseReqParameters& params)
97 {
98  m_scheduler->DoCschedLcReleaseReq (params);
99 }
100 
101 void
102 FdTbfqSchedulerMemberCschedSapProvider::CschedUeReleaseReq (const struct CschedUeReleaseReqParameters& params)
103 {
104  m_scheduler->DoCschedUeReleaseReq (params);
105 }
106 
107 
108 
109 
111 {
112 public:
114 
115  // inherited from FfMacSchedSapProvider
116  virtual void SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params);
117  virtual void SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params);
118  virtual void SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params);
119  virtual void SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params);
120  virtual void SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params);
121  virtual void SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params);
122  virtual void SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params);
123  virtual void SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params);
124  virtual void SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params);
125  virtual void SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params);
126  virtual void SchedUlCqiInfoReq (const struct SchedUlCqiInfoReqParameters& params);
127 
128 
129 private:
131  FdTbfqFfMacScheduler* m_scheduler;
132 };
133 
134 
135 
136 FdTbfqSchedulerMemberSchedSapProvider::FdTbfqSchedulerMemberSchedSapProvider ()
137 {
138 }
139 
140 
141 FdTbfqSchedulerMemberSchedSapProvider::FdTbfqSchedulerMemberSchedSapProvider (FdTbfqFfMacScheduler* scheduler)
142  : m_scheduler (scheduler)
143 {
144 }
145 
146 void
147 FdTbfqSchedulerMemberSchedSapProvider::SchedDlRlcBufferReq (const struct SchedDlRlcBufferReqParameters& params)
148 {
149  m_scheduler->DoSchedDlRlcBufferReq (params);
150 }
151 
152 void
153 FdTbfqSchedulerMemberSchedSapProvider::SchedDlPagingBufferReq (const struct SchedDlPagingBufferReqParameters& params)
154 {
155  m_scheduler->DoSchedDlPagingBufferReq (params);
156 }
157 
158 void
159 FdTbfqSchedulerMemberSchedSapProvider::SchedDlMacBufferReq (const struct SchedDlMacBufferReqParameters& params)
160 {
161  m_scheduler->DoSchedDlMacBufferReq (params);
162 }
163 
164 void
165 FdTbfqSchedulerMemberSchedSapProvider::SchedDlTriggerReq (const struct SchedDlTriggerReqParameters& params)
166 {
167  m_scheduler->DoSchedDlTriggerReq (params);
168 }
169 
170 void
171 FdTbfqSchedulerMemberSchedSapProvider::SchedDlRachInfoReq (const struct SchedDlRachInfoReqParameters& params)
172 {
173  m_scheduler->DoSchedDlRachInfoReq (params);
174 }
175 
176 void
177 FdTbfqSchedulerMemberSchedSapProvider::SchedDlCqiInfoReq (const struct SchedDlCqiInfoReqParameters& params)
178 {
179  m_scheduler->DoSchedDlCqiInfoReq (params);
180 }
181 
182 void
183 FdTbfqSchedulerMemberSchedSapProvider::SchedUlTriggerReq (const struct SchedUlTriggerReqParameters& params)
184 {
185  m_scheduler->DoSchedUlTriggerReq (params);
186 }
187 
188 void
189 FdTbfqSchedulerMemberSchedSapProvider::SchedUlNoiseInterferenceReq (const struct SchedUlNoiseInterferenceReqParameters& params)
190 {
191  m_scheduler->DoSchedUlNoiseInterferenceReq (params);
192 }
193 
194 void
195 FdTbfqSchedulerMemberSchedSapProvider::SchedUlSrInfoReq (const struct SchedUlSrInfoReqParameters& params)
196 {
197  m_scheduler->DoSchedUlSrInfoReq (params);
198 }
199 
200 void
201 FdTbfqSchedulerMemberSchedSapProvider::SchedUlMacCtrlInfoReq (const struct SchedUlMacCtrlInfoReqParameters& params)
202 {
203  m_scheduler->DoSchedUlMacCtrlInfoReq (params);
204 }
205 
206 void
207 FdTbfqSchedulerMemberSchedSapProvider::SchedUlCqiInfoReq (const struct SchedUlCqiInfoReqParameters& params)
208 {
209  m_scheduler->DoSchedUlCqiInfoReq (params);
210 }
211 
212 
213 
214 
215 
217  : m_cschedSapUser (0),
218  m_schedSapUser (0),
219  m_timeWindow (99.0),
220  m_nextRntiUl (0),
221  bankSize (0)
222 {
223  m_amc = CreateObject <LteAmc> ();
224  m_cschedSapProvider = new FdTbfqSchedulerMemberCschedSapProvider (this);
225  m_schedSapProvider = new FdTbfqSchedulerMemberSchedSapProvider (this);
226 }
227 
229 {
230  NS_LOG_FUNCTION (this);
231 }
232 
233 void
235 {
236  NS_LOG_FUNCTION (this);
237  m_dlHarqProcessesDciBuffer.clear ();
238  m_dlHarqProcessesTimer.clear ();
239  m_dlHarqProcessesRlcPduListBuffer.clear ();
240  m_dlInfoListBuffered.clear ();
241  m_ulHarqCurrentProcessId.clear ();
242  m_ulHarqProcessesStatus.clear ();
243  m_ulHarqProcessesDciBuffer.clear ();
244  delete m_cschedSapProvider;
245  delete m_schedSapProvider;
246 }
247 
248 TypeId
249 FdTbfqFfMacScheduler::GetTypeId (void)
250 {
251  static TypeId tid = TypeId ("ns3::FdTbfqFfMacScheduler")
253  .AddConstructor<FdTbfqFfMacScheduler> ()
254  .AddAttribute ("CqiTimerThreshold",
255  "The number of TTIs a CQI is valid (default 1000 - 1 sec.)",
256  UintegerValue (1000),
257  MakeUintegerAccessor (&FdTbfqFfMacScheduler::m_cqiTimersThreshold),
258  MakeUintegerChecker<uint32_t> ())
259  .AddAttribute ("DebtLimit",
260  "Flow debt limit (default -625000 bytes)",
261  IntegerValue (-625000),
262  MakeIntegerAccessor (&FdTbfqFfMacScheduler::m_debtLimit),
263  MakeIntegerChecker<int> ())
264  .AddAttribute ("CreditLimit",
265  "Flow credit limit (default 625000 bytes)",
266  UintegerValue (625000),
267  MakeUintegerAccessor (&FdTbfqFfMacScheduler::m_creditLimit),
268  MakeUintegerChecker<uint32_t> ())
269  .AddAttribute ("TokenPoolSize",
270  "The maximum value of flow token pool (default 1 bytes)",
271  UintegerValue (1),
272  MakeUintegerAccessor (&FdTbfqFfMacScheduler::m_tokenPoolSize),
273  MakeUintegerChecker<uint32_t> ())
274  .AddAttribute ("CreditableThreshold",
275  "Threshold of flow credit (default 0 bytes)",
276  UintegerValue (0),
277  MakeUintegerAccessor (&FdTbfqFfMacScheduler::m_creditableThreshold),
278  MakeUintegerChecker<uint32_t> ())
279 
280  .AddAttribute ("HarqEnabled",
281  "Activate/Deactivate the HARQ [by default is active].",
282  BooleanValue (true),
283  MakeBooleanAccessor (&FdTbfqFfMacScheduler::m_harqOn),
284  MakeBooleanChecker ())
285  .AddAttribute ("UlGrantMcs",
286  "The MCS of the UL grant, must be [0..15] (default 0)",
287  UintegerValue (0),
288  MakeUintegerAccessor (&FdTbfqFfMacScheduler::m_ulGrantMcs),
289  MakeUintegerChecker<uint8_t> ())
290  ;
291  return tid;
292 }
293 
294 
295 
296 void
298 {
299  m_cschedSapUser = s;
300 }
301 
302 void
304 {
305  m_schedSapUser = s;
306 }
307 
310 {
311  return m_cschedSapProvider;
312 }
313 
316 {
317  return m_schedSapProvider;
318 }
319 
320 void
321 FdTbfqFfMacScheduler::DoCschedCellConfigReq (const struct FfMacCschedSapProvider::CschedCellConfigReqParameters& params)
322 {
323  NS_LOG_FUNCTION (this);
324  // Read the subset of parameters used
325  m_cschedCellConfig = params;
326  m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
328  cnf.m_result = SUCCESS;
329  m_cschedSapUser->CschedUeConfigCnf (cnf);
330  return;
331 }
332 
333 void
334 FdTbfqFfMacScheduler::DoCschedUeConfigReq (const struct FfMacCschedSapProvider::CschedUeConfigReqParameters& params)
335 {
336  NS_LOG_FUNCTION (this << " RNTI " << params.m_rnti << " txMode " << (uint16_t)params.m_transmissionMode);
337  std::map <uint16_t,uint8_t>::iterator it = m_uesTxMode.find (params.m_rnti);
338  if (it == m_uesTxMode.end ())
339  {
340  m_uesTxMode.insert (std::pair <uint16_t, double> (params.m_rnti, params.m_transmissionMode));
341  // generate HARQ buffers
342  m_dlHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
343  DlHarqProcessesStatus_t dlHarqPrcStatus;
344  dlHarqPrcStatus.resize (8,0);
345  m_dlHarqProcessesStatus.insert (std::pair <uint16_t, DlHarqProcessesStatus_t> (params.m_rnti, dlHarqPrcStatus));
346  DlHarqProcessesTimer_t dlHarqProcessesTimer;
347  dlHarqProcessesTimer.resize (8,0);
348  m_dlHarqProcessesTimer.insert (std::pair <uint16_t, DlHarqProcessesTimer_t> (params.m_rnti, dlHarqProcessesTimer));
349  DlHarqProcessesDciBuffer_t dlHarqdci;
350  dlHarqdci.resize (8);
351  m_dlHarqProcessesDciBuffer.insert (std::pair <uint16_t, DlHarqProcessesDciBuffer_t> (params.m_rnti, dlHarqdci));
352  DlHarqRlcPduListBuffer_t dlHarqRlcPdu;
353  dlHarqRlcPdu.resize (2);
354  dlHarqRlcPdu.at (0).resize (8);
355  dlHarqRlcPdu.at (1).resize (8);
356  m_dlHarqProcessesRlcPduListBuffer.insert (std::pair <uint16_t, DlHarqRlcPduListBuffer_t> (params.m_rnti, dlHarqRlcPdu));
357  m_ulHarqCurrentProcessId.insert (std::pair <uint16_t,uint8_t > (params.m_rnti, 0));
358  UlHarqProcessesStatus_t ulHarqPrcStatus;
359  ulHarqPrcStatus.resize (8,0);
360  m_ulHarqProcessesStatus.insert (std::pair <uint16_t, UlHarqProcessesStatus_t> (params.m_rnti, ulHarqPrcStatus));
361  UlHarqProcessesDciBuffer_t ulHarqdci;
362  ulHarqdci.resize (8);
363  m_ulHarqProcessesDciBuffer.insert (std::pair <uint16_t, UlHarqProcessesDciBuffer_t> (params.m_rnti, ulHarqdci));
364  }
365  else
366  {
367  (*it).second = params.m_transmissionMode;
368  }
369  return;
370 }
371 
372 void
373 FdTbfqFfMacScheduler::DoCschedLcConfigReq (const struct FfMacCschedSapProvider::CschedLcConfigReqParameters& params)
374 {
375  NS_LOG_FUNCTION (this << " New LC, rnti: " << params.m_rnti);
376 
377  std::map <uint16_t, fdtbfqsFlowPerf_t>::iterator it;
378  for (uint16_t i = 0; i < params.m_logicalChannelConfigList.size (); i++)
379  {
380  it = m_flowStatsDl.find (params.m_rnti);
381 
382  if (it == m_flowStatsDl.end ())
383  {
384  uint64_t mbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateDl / 8; // byte/s
385  uint64_t mbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateUl / 8; // byte/s
386 
387  fdtbfqsFlowPerf_t flowStatsDl;
388  flowStatsDl.flowStart = Simulator::Now ();
389  flowStatsDl.packetArrivalRate = 0;
390  flowStatsDl.tokenGenerationRate = mbrDlInBytes;
391  flowStatsDl.tokenPoolSize = 0;
392  flowStatsDl.maxTokenPoolSize = m_tokenPoolSize;
393  flowStatsDl.counter = 0;
394  flowStatsDl.burstCredit = m_creditLimit; // bytes
395  flowStatsDl.debtLimit = m_debtLimit; // bytes
396  flowStatsDl.creditableThreshold = m_creditableThreshold;
397  m_flowStatsDl.insert (std::pair<uint16_t, fdtbfqsFlowPerf_t> (params.m_rnti, flowStatsDl));
398  fdtbfqsFlowPerf_t flowStatsUl;
399  flowStatsUl.flowStart = Simulator::Now ();
400  flowStatsUl.packetArrivalRate = 0;
401  flowStatsUl.tokenGenerationRate = mbrUlInBytes;
402  flowStatsUl.tokenPoolSize = 0;
403  flowStatsUl.maxTokenPoolSize = m_tokenPoolSize;
404  flowStatsUl.counter = 0;
405  flowStatsUl.burstCredit = m_creditLimit; // bytes
406  flowStatsUl.debtLimit = m_debtLimit; // bytes
407  flowStatsUl.creditableThreshold = m_creditableThreshold;
408  m_flowStatsUl.insert (std::pair<uint16_t, fdtbfqsFlowPerf_t> (params.m_rnti, flowStatsUl));
409  }
410  else
411  {
412  //NS_LOG_ERROR ("RNTI already exists");
413 
414  // update MBR and GBR from UeManager::SetupDataRadioBearer ()
415  uint64_t mbrDlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateDl / 8; // byte/s
416  uint64_t mbrUlInBytes = params.m_logicalChannelConfigList.at (i).m_eRabMaximulBitrateUl / 8; // byte/s
417  m_flowStatsDl[(*it).first].tokenGenerationRate = mbrDlInBytes;
418  m_flowStatsUl[(*it).first].tokenGenerationRate = mbrUlInBytes;
419 
420  }
421  }
422 
423  return;
424 }
425 
426 void
427 FdTbfqFfMacScheduler::DoCschedLcReleaseReq (const struct FfMacCschedSapProvider::CschedLcReleaseReqParameters& params)
428 {
429  NS_LOG_FUNCTION (this);
430  for (uint16_t i = 0; i < params.m_logicalChannelIdentity.size (); i++)
431  {
432  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
433  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
434  while (it!=m_rlcBufferReq.end ())
435  {
436  if (((*it).first.m_rnti == params.m_rnti) && ((*it).first.m_lcId == params.m_logicalChannelIdentity.at (i)))
437  {
438  temp = it;
439  it++;
440  m_rlcBufferReq.erase (temp);
441  }
442  else
443  {
444  it++;
445  }
446  }
447  }
448  return;
449 }
450 
451 void
452 FdTbfqFfMacScheduler::DoCschedUeReleaseReq (const struct FfMacCschedSapProvider::CschedUeReleaseReqParameters& params)
453 {
454  NS_LOG_FUNCTION (this);
455 
456  m_uesTxMode.erase (params.m_rnti);
457  m_dlHarqCurrentProcessId.erase (params.m_rnti);
458  m_dlHarqProcessesStatus.erase (params.m_rnti);
459  m_dlHarqProcessesTimer.erase (params.m_rnti);
460  m_dlHarqProcessesDciBuffer.erase (params.m_rnti);
461  m_dlHarqProcessesRlcPduListBuffer.erase (params.m_rnti);
462  m_ulHarqCurrentProcessId.erase (params.m_rnti);
463  m_ulHarqProcessesStatus.erase (params.m_rnti);
464  m_ulHarqProcessesDciBuffer.erase (params.m_rnti);
465  m_flowStatsDl.erase (params.m_rnti);
466  m_flowStatsUl.erase (params.m_rnti);
467  m_ceBsrRxed.erase (params.m_rnti);
468  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it = m_rlcBufferReq.begin ();
469  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator temp;
470  while (it!=m_rlcBufferReq.end ())
471  {
472  if ((*it).first.m_rnti == params.m_rnti)
473  {
474  temp = it;
475  it++;
476  m_rlcBufferReq.erase (temp);
477  }
478  else
479  {
480  it++;
481  }
482  }
483  if (m_nextRntiUl == params.m_rnti)
484  {
485  m_nextRntiUl = 0;
486  }
487 
488  return;
489 }
490 
491 
492 void
493 FdTbfqFfMacScheduler::DoSchedDlRlcBufferReq (const struct FfMacSchedSapProvider::SchedDlRlcBufferReqParameters& params)
494 {
495  NS_LOG_FUNCTION (this << params.m_rnti << (uint32_t) params.m_logicalChannelIdentity);
496  // API generated by RLC for updating RLC parameters on a LC (tx and retx queues)
497 
498  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
499 
500  LteFlowId_t flow (params.m_rnti, params.m_logicalChannelIdentity);
501 
502  it = m_rlcBufferReq.find (flow);
503 
504  if (it == m_rlcBufferReq.end ())
505  {
506  m_rlcBufferReq.insert (std::pair <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters> (flow, params));
507  }
508  else
509  {
510  (*it).second = params;
511  }
512 
513  return;
514 }
515 
516 void
517 FdTbfqFfMacScheduler::DoSchedDlPagingBufferReq (const struct FfMacSchedSapProvider::SchedDlPagingBufferReqParameters& params)
518 {
519  NS_LOG_FUNCTION (this);
520  NS_FATAL_ERROR ("method not implemented");
521  return;
522 }
523 
524 void
525 FdTbfqFfMacScheduler::DoSchedDlMacBufferReq (const struct FfMacSchedSapProvider::SchedDlMacBufferReqParameters& params)
526 {
527  NS_LOG_FUNCTION (this);
528  NS_FATAL_ERROR ("method not implemented");
529  return;
530 }
531 
532 int
533 FdTbfqFfMacScheduler::GetRbgSize (int dlbandwidth)
534 {
535  for (int i = 0; i < 4; i++)
536  {
537  if (dlbandwidth < FdTbfqType0AllocationRbg[i])
538  {
539  return (i + 1);
540  }
541  }
542 
543  return (-1);
544 }
545 
546 
547 int
548 FdTbfqFfMacScheduler::LcActivePerFlow (uint16_t rnti)
549 {
550  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
551  int lcActive = 0;
552  for (it = m_rlcBufferReq.begin (); it != m_rlcBufferReq.end (); it++)
553  {
554  if (((*it).first.m_rnti == rnti) && (((*it).second.m_rlcTransmissionQueueSize > 0)
555  || ((*it).second.m_rlcRetransmissionQueueSize > 0)
556  || ((*it).second.m_rlcStatusPduSize > 0) ))
557  {
558  lcActive++;
559  }
560  if ((*it).first.m_rnti > rnti)
561  {
562  break;
563  }
564  }
565  return (lcActive);
566 
567 }
568 
569 
570 uint8_t
572 {
573  NS_LOG_FUNCTION (this << rnti);
574 
575  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
576  if (it == m_dlHarqCurrentProcessId.end ())
577  {
578  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
579  }
580  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
581  if (itStat == m_dlHarqProcessesStatus.end ())
582  {
583  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
584  }
585  uint8_t i = (*it).second;
586  do
587  {
588  i = (i + 1) % HARQ_PROC_NUM;
589  }
590  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
591  if ((*itStat).second.at (i) == 0)
592  {
593  return (true);
594  }
595  else
596  {
597  return (false); // return a not valid harq proc id
598  }
599 }
600 
601 
602 
603 uint8_t
605 {
606  NS_LOG_FUNCTION (this << rnti);
607 
608  if (m_harqOn == false)
609  {
610  return (0);
611  }
612 
613 
614  std::map <uint16_t, uint8_t>::iterator it = m_dlHarqCurrentProcessId.find (rnti);
615  if (it == m_dlHarqCurrentProcessId.end ())
616  {
617  NS_FATAL_ERROR ("No Process Id found for this RNTI " << rnti);
618  }
619  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find (rnti);
620  if (itStat == m_dlHarqProcessesStatus.end ())
621  {
622  NS_FATAL_ERROR ("No Process Id Statusfound for this RNTI " << rnti);
623  }
624  uint8_t i = (*it).second;
625  do
626  {
627  i = (i + 1) % HARQ_PROC_NUM;
628  }
629  while ( ((*itStat).second.at (i) != 0)&&(i != (*it).second));
630  if ((*itStat).second.at (i) == 0)
631  {
632  (*it).second = i;
633  (*itStat).second.at (i) = 1;
634  }
635  else
636  {
637  NS_FATAL_ERROR ("No HARQ process available for RNTI " << rnti << " check before update with HarqProcessAvailability");
638  }
639 
640  return ((*it).second);
641 }
642 
643 
644 void
646 {
647  NS_LOG_FUNCTION (this);
648 
649  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itTimers;
650  for (itTimers = m_dlHarqProcessesTimer.begin (); itTimers != m_dlHarqProcessesTimer.end (); itTimers ++)
651  {
652  for (uint16_t i = 0; i < HARQ_PROC_NUM; i++)
653  {
654  if ((*itTimers).second.at (i) == HARQ_DL_TIMEOUT)
655  {
656  // reset HARQ process
657 
658  NS_LOG_DEBUG (this << " Reset HARQ proc " << i << " for RNTI " << (*itTimers).first);
659  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator itStat = m_dlHarqProcessesStatus.find ((*itTimers).first);
660  if (itStat == m_dlHarqProcessesStatus.end ())
661  {
662  NS_FATAL_ERROR ("No Process Id Status found for this RNTI " << (*itTimers).first);
663  }
664  (*itStat).second.at (i) = 0;
665  (*itTimers).second.at (i) = 0;
666  }
667  else
668  {
669  (*itTimers).second.at (i)++;
670  }
671  }
672  }
673 
674 }
675 
676 
677 void
678 FdTbfqFfMacScheduler::DoSchedDlTriggerReq (const struct FfMacSchedSapProvider::SchedDlTriggerReqParameters& params)
679 {
680  NS_LOG_FUNCTION (this << " Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
681  // API generated by RLC for triggering the scheduling of a DL subframe
682 
683 
684  // evaluate the relative channel quality indicator for each UE per each RBG
685  // (since we are using allocation type 0 the small unit of allocation is RBG)
686  // Resource allocation type 0 (see sec 7.1.6.1 of 36.213)
687 
688  RefreshDlCqiMaps ();
689 
690  int rbgSize = GetRbgSize (m_cschedCellConfig.m_dlBandwidth);
691  int rbgNum = m_cschedCellConfig.m_dlBandwidth / rbgSize;
692  std::map <uint16_t, std::vector <uint16_t> > allocationMap; // RBs map per RNTI
693  std::vector <bool> rbgMap; // global RBGs map
694  uint16_t rbgAllocatedNum = 0;
695  std::set <uint16_t> rntiAllocated;
696  rbgMap.resize (m_cschedCellConfig.m_dlBandwidth / rbgSize, false);
698 
699  // RACH Allocation
700  m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
701  uint16_t rbStart = 0;
702  std::vector <struct RachListElement_s>::iterator itRach;
703  for (itRach = m_rachList.begin (); itRach != m_rachList.end (); itRach++)
704  {
705  NS_ASSERT_MSG (m_amc->GetTbSizeFromMcs (m_ulGrantMcs, m_cschedCellConfig.m_ulBandwidth) > (*itRach).m_estimatedSize, " Default UL Grant MCS does not allow to send RACH messages");
706  BuildRarListElement_s newRar;
707  newRar.m_rnti = (*itRach).m_rnti;
708  // DL-RACH Allocation
709  // Ideal: no needs of configuring m_dci
710  // UL-RACH Allocation
711  newRar.m_grant.m_rnti = newRar.m_rnti;
712  newRar.m_grant.m_mcs = m_ulGrantMcs;
713  uint16_t rbLen = 1;
714  uint16_t tbSizeBits = 0;
715  // find lowest TB size that fits UL grant estimated size
716  while ((tbSizeBits < (*itRach).m_estimatedSize) && (rbStart + rbLen < m_cschedCellConfig.m_ulBandwidth))
717  {
718  rbLen++;
719  tbSizeBits = m_amc->GetTbSizeFromMcs (m_ulGrantMcs, rbLen);
720  }
721  if (tbSizeBits < (*itRach).m_estimatedSize)
722  {
723  // no more allocation space: finish allocation
724  break;
725  }
726  newRar.m_grant.m_rbStart = rbStart;
727  newRar.m_grant.m_rbLen = rbLen;
728  newRar.m_grant.m_tbSize = tbSizeBits / 8;
729  newRar.m_grant.m_hopping = false;
730  newRar.m_grant.m_tpc = 0;
731  newRar.m_grant.m_cqiRequest = false;
732  newRar.m_grant.m_ulDelay = false;
733  NS_LOG_INFO (this << " UL grant allocated to RNTI " << (*itRach).m_rnti << " rbStart " << rbStart << " rbLen " << rbLen << " MCS " << m_ulGrantMcs << " tbSize " << newRar.m_grant.m_tbSize);
734  for (uint16_t i = rbStart; i < rbStart + rbLen; i++)
735  {
736  m_rachAllocationMap.at (i) = (*itRach).m_rnti;
737  }
738  rbStart = rbStart + rbLen;
739 
740  ret.m_buildRarList.push_back (newRar);
741  }
742  m_rachList.clear ();
743 
744 
745  // Process DL HARQ feedback
747  // retrieve past HARQ retx buffered
748  if (m_dlInfoListBuffered.size () > 0)
749  {
750  if (params.m_dlInfoList.size () > 0)
751  {
752  NS_LOG_INFO (this << " Received DL-HARQ feedback");
753  m_dlInfoListBuffered.insert (m_dlInfoListBuffered.end (), params.m_dlInfoList.begin (), params.m_dlInfoList.end ());
754  }
755  }
756  else
757  {
758  if (params.m_dlInfoList.size () > 0)
759  {
760  m_dlInfoListBuffered = params.m_dlInfoList;
761  }
762  }
763  if (m_harqOn == false)
764  {
765  // Ignore HARQ feedback
766  m_dlInfoListBuffered.clear ();
767  }
768  std::vector <struct DlInfoListElement_s> dlInfoListUntxed;
769  for (uint16_t i = 0; i < m_dlInfoListBuffered.size (); i++)
770  {
771  std::set <uint16_t>::iterator itRnti = rntiAllocated.find (m_dlInfoListBuffered.at (i).m_rnti);
772  if (itRnti != rntiAllocated.end ())
773  {
774  // RNTI already allocated for retx
775  continue;
776  }
777  uint8_t nLayers = m_dlInfoListBuffered.at (i).m_harqStatus.size ();
778  std::vector <bool> retx;
779  NS_LOG_INFO (this << " Processing DLHARQ feedback");
780  if (nLayers == 1)
781  {
782  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
783  retx.push_back (false);
784  }
785  else
786  {
787  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (0) == DlInfoListElement_s::NACK);
788  retx.push_back (m_dlInfoListBuffered.at (i).m_harqStatus.at (1) == DlInfoListElement_s::NACK);
789  }
790  if (retx.at (0) || retx.at (1))
791  {
792  // retrieve HARQ process information
793  uint16_t rnti = m_dlInfoListBuffered.at (i).m_rnti;
794  uint8_t harqId = m_dlInfoListBuffered.at (i).m_harqProcessId;
795  NS_LOG_INFO (this << " HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId);
796  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itHarq = m_dlHarqProcessesDciBuffer.find (rnti);
797  if (itHarq == m_dlHarqProcessesDciBuffer.end ())
798  {
799  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << rnti);
800  }
801 
802  DlDciListElement_s dci = (*itHarq).second.at (harqId);
803  int rv = 0;
804  if (dci.m_rv.size () == 1)
805  {
806  rv = dci.m_rv.at (0);
807  }
808  else
809  {
810  rv = (dci.m_rv.at (0) > dci.m_rv.at (1) ? dci.m_rv.at (0) : dci.m_rv.at (1));
811  }
812 
813  if (rv == 3)
814  {
815  // maximum number of retx reached -> drop process
816  NS_LOG_INFO ("Maximum number of retransmissions reached -> drop process");
817  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (rnti);
818  if (it == m_dlHarqProcessesStatus.end ())
819  {
820  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << m_dlInfoListBuffered.at (i).m_rnti);
821  }
822  (*it).second.at (harqId) = 0;
823  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
824  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
825  {
826  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
827  }
828  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
829  {
830  (*itRlcPdu).second.at (k).at (harqId).clear ();
831  }
832  continue;
833  }
834  // check the feasibility of retransmitting on the same RBGs
835  // translate the DCI to Spectrum framework
836  std::vector <int> dciRbg;
837  uint32_t mask = 0x1;
838  NS_LOG_INFO ("Original RBGs " << dci.m_rbBitmap << " rnti " << dci.m_rnti);
839  for (int j = 0; j < 32; j++)
840  {
841  if (((dci.m_rbBitmap & mask) >> j) == 1)
842  {
843  dciRbg.push_back (j);
844  NS_LOG_INFO ("\t" << j);
845  }
846  mask = (mask << 1);
847  }
848  bool free = true;
849  for (uint8_t j = 0; j < dciRbg.size (); j++)
850  {
851  if (rbgMap.at (dciRbg.at (j)) == true)
852  {
853  free = false;
854  break;
855  }
856  }
857  if (free)
858  {
859  // use the same RBGs for the retx
860  // reserve RBGs
861  for (uint8_t j = 0; j < dciRbg.size (); j++)
862  {
863  rbgMap.at (dciRbg.at (j)) = true;
864  NS_LOG_INFO ("RBG " << dciRbg.at (j) << " assigned");
865  rbgAllocatedNum++;
866  }
867 
868  NS_LOG_INFO (this << " Send retx in the same RBGs");
869  }
870  else
871  {
872  // find RBGs for sending HARQ retx
873  uint8_t j = 0;
874  uint8_t rbgId = (dciRbg.at (dciRbg.size () - 1) + 1) % rbgNum;
875  uint8_t startRbg = dciRbg.at (dciRbg.size () - 1);
876  std::vector <bool> rbgMapCopy = rbgMap;
877  while ((j < dciRbg.size ())&&(startRbg != rbgId))
878  {
879  if (rbgMapCopy.at (rbgId) == false)
880  {
881  rbgMapCopy.at (rbgId) = true;
882  dciRbg.at (j) = rbgId;
883  j++;
884  }
885  rbgId++;
886  }
887  if (j == dciRbg.size ())
888  {
889  // find new RBGs -> update DCI map
890  uint32_t rbgMask = 0;
891  for (uint16_t k = 0; k < dciRbg.size (); k++)
892  {
893  rbgMask = rbgMask + (0x1 << dciRbg.at (k));
894  rbgAllocatedNum++;
895  }
896  dci.m_rbBitmap = rbgMask;
897  rbgMap = rbgMapCopy;
898  NS_LOG_INFO (this << " Move retx in RBGs " << dciRbg.size ());
899  }
900  else
901  {
902  // HARQ retx cannot be performed on this TTI -> store it
903  dlInfoListUntxed.push_back (params.m_dlInfoList.at (i));
904  NS_LOG_INFO (this << " No resource for this retx -> buffer it");
905  }
906  }
907  // retrieve RLC PDU list for retx TBsize and update DCI
908  BuildDataListElement_s newEl;
909  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (rnti);
910  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
911  {
912  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << rnti);
913  }
914  for (uint8_t j = 0; j < nLayers; j++)
915  {
916  if (retx.at (j))
917  {
918  if (j >= dci.m_ndi.size ())
919  {
920  // for avoiding errors in MIMO transient phases
921  dci.m_ndi.push_back (0);
922  dci.m_rv.push_back (0);
923  dci.m_mcs.push_back (0);
924  dci.m_tbsSize.push_back (0);
925  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no txed (MIMO transition)");
926  }
927  else
928  {
929  dci.m_ndi.at (j) = 0;
930  dci.m_rv.at (j)++;
931  (*itHarq).second.at (harqId).m_rv.at (j)++;
932  NS_LOG_INFO (this << " layer " << (uint16_t)j << " RV " << (uint16_t)dci.m_rv.at (j));
933  }
934  }
935  else
936  {
937  // empty TB of layer j
938  dci.m_ndi.at (j) = 0;
939  dci.m_rv.at (j) = 0;
940  dci.m_mcs.at (j) = 0;
941  dci.m_tbsSize.at (j) = 0;
942  NS_LOG_INFO (this << " layer " << (uint16_t)j << " no retx");
943  }
944  }
945  for (uint16_t k = 0; k < (*itRlcPdu).second.at (0).at (dci.m_harqProcess).size (); k++)
946  {
947  std::vector <struct RlcPduListElement_s> rlcPduListPerLc;
948  for (uint8_t j = 0; j < nLayers; j++)
949  {
950  if (retx.at (j))
951  {
952  if (j < dci.m_ndi.size ())
953  {
954  rlcPduListPerLc.push_back ((*itRlcPdu).second.at (j).at (dci.m_harqProcess).at (k));
955  }
956  }
957  }
958 
959  if (rlcPduListPerLc.size () > 0)
960  {
961  newEl.m_rlcPduList.push_back (rlcPduListPerLc);
962  }
963  }
964  newEl.m_rnti = rnti;
965  newEl.m_dci = dci;
966  (*itHarq).second.at (harqId).m_rv = dci.m_rv;
967  // refresh timer
968  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (rnti);
969  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
970  {
971  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)rnti);
972  }
973  (*itHarqTimer).second.at (harqId) = 0;
974  ret.m_buildDataList.push_back (newEl);
975  rntiAllocated.insert (rnti);
976  }
977  else
978  {
979  // update HARQ process status
980  NS_LOG_INFO (this << " HARQ received ACK for UE " << m_dlInfoListBuffered.at (i).m_rnti);
981  std::map <uint16_t, DlHarqProcessesStatus_t>::iterator it = m_dlHarqProcessesStatus.find (m_dlInfoListBuffered.at (i).m_rnti);
982  if (it == m_dlHarqProcessesStatus.end ())
983  {
984  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << m_dlInfoListBuffered.at (i).m_rnti);
985  }
986  (*it).second.at (m_dlInfoListBuffered.at (i).m_harqProcessId) = 0;
987  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find (m_dlInfoListBuffered.at (i).m_rnti);
988  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
989  {
990  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << m_dlInfoListBuffered.at (i).m_rnti);
991  }
992  for (uint16_t k = 0; k < (*itRlcPdu).second.size (); k++)
993  {
994  (*itRlcPdu).second.at (k).at (m_dlInfoListBuffered.at (i).m_harqProcessId).clear ();
995  }
996  }
997  }
998  m_dlInfoListBuffered.clear ();
999  m_dlInfoListBuffered = dlInfoListUntxed;
1000 
1001 
1002  // update token pool, counter and bank size
1003  std::map <uint16_t, fdtbfqsFlowPerf_t>::iterator itStats;
1004  for (itStats = m_flowStatsDl.begin (); itStats != m_flowStatsDl.end (); itStats++)
1005  {
1006  if ( (*itStats).second.tokenGenerationRate / 1000 + (*itStats).second.tokenPoolSize > (*itStats).second.maxTokenPoolSize )
1007  {
1008  (*itStats).second.counter += (*itStats).second.tokenGenerationRate / 1000 - ( (*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize );
1009  (*itStats).second.tokenPoolSize = (*itStats).second.maxTokenPoolSize;
1010  bankSize += (*itStats).second.tokenGenerationRate / 1000 - ( (*itStats).second.maxTokenPoolSize - (*itStats).second.tokenPoolSize );
1011  }
1012  else
1013  {
1014  (*itStats).second.tokenPoolSize += (*itStats).second.tokenGenerationRate / 1000;
1015  }
1016  }
1017 
1018  std::set <uint16_t> allocatedRnti; // store UEs which are already assigned RBGs
1019  std::set <uint8_t> allocatedRbg; // store RBGs which are already allocated to UE
1020 
1021  int totalRbg = 0;
1022  while (totalRbg < rbgNum)
1023  {
1024  // select UE with largest metric
1025  std::map <uint16_t, fdtbfqsFlowPerf_t>::iterator it;
1026  std::map <uint16_t, fdtbfqsFlowPerf_t>::iterator itMax = m_flowStatsDl.end ();
1027  double metricMax = 0.0;
1028  bool firstRnti = true;
1029  for (it = m_flowStatsDl.begin (); it != m_flowStatsDl.end (); it++)
1030  {
1031  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1032  if ((itRnti != rntiAllocated.end ())||(!HarqProcessAvailability ((*it).first)))
1033  {
1034  // UE already allocated for HARQ or without HARQ process available -> drop it
1035  if (itRnti != rntiAllocated.end ())
1036  {
1037  NS_LOG_DEBUG (this << " RNTI discared for HARQ tx" << (uint16_t)(*it).first);
1038  }
1039  if (!HarqProcessAvailability ((*it).first))
1040  {
1041  NS_LOG_DEBUG (this << " RNTI discared for HARQ id" << (uint16_t)(*it).first);
1042  }
1043  continue;
1044  }
1045 
1046  if (LcActivePerFlow ((*it).first) == 0)
1047  {
1048  continue;
1049  }
1050 
1051  std::set <uint16_t>::iterator rnti;
1052  rnti = allocatedRnti.find((*it).first);
1053  if (rnti != allocatedRnti.end ()) // already allocated RBGs to this UE
1054  {
1055  continue;
1056  }
1057 
1058  double metric = ( ( (double)(*it).second.counter ) / ( (double)(*it).second.tokenGenerationRate ) );
1059 
1060  if (firstRnti == true)
1061  {
1062  metricMax = metric;
1063  itMax = it;
1064  firstRnti = false;
1065  continue;
1066  }
1067  if (metric > metricMax)
1068  {
1069  metricMax = metric;
1070  itMax = it;
1071  }
1072  } // end for m_flowStatsDl
1073 
1074  if (itMax == m_flowStatsDl.end())
1075  {
1076  // all UEs are allocated RBG or all UEs already allocated for HARQ or without HARQ process available
1077  break;
1078  }
1079 
1080  // mark this UE as "allocated"
1081  allocatedRnti.insert((*itMax).first);
1082 
1083  // calculate the maximum number of byte that the scheduler can assigned to this UE
1084  uint32_t budget = 0;
1085  if ( bankSize > 0 )
1086  {
1087  budget = (*itMax).second.counter - (*itMax).second.debtLimit;
1088  if ( budget > (*itMax).second.burstCredit )
1089  budget = (*itMax).second.burstCredit;
1090  if ( budget > bankSize )
1091  budget = bankSize;
1092  }
1093  budget = budget + (*itMax).second.tokenPoolSize;
1094 
1095  // calcualte how much bytes this UE actally need
1096  if (budget == 0)
1097  {
1098  // there are no tokens for this UE
1099  continue;
1100  }
1101  else
1102  {
1103  // calculate rlc buffer size
1104  uint32_t rlcBufSize = 0;
1105  uint8_t lcid = 0;
1106  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itRlcBuf;
1107  for (itRlcBuf = m_rlcBufferReq.begin (); itRlcBuf != m_rlcBufferReq.end (); itRlcBuf++)
1108  {
1109  if ( (*itRlcBuf).first.m_rnti == (*itMax).first )
1110  lcid = (*itRlcBuf).first.m_lcId;
1111  }
1112  LteFlowId_t flow ((*itMax).first, lcid);
1113  itRlcBuf = m_rlcBufferReq.find (flow);
1114  if (itRlcBuf!=m_rlcBufferReq.end ())
1115  rlcBufSize = (*itRlcBuf).second.m_rlcTransmissionQueueSize + (*itRlcBuf).second.m_rlcRetransmissionQueueSize + (*itRlcBuf).second.m_rlcStatusPduSize;
1116  if ( budget > rlcBufSize )
1117  budget = rlcBufSize;
1118  }
1119 
1120  // assign RBGs to this UE
1121  uint32_t bytesTxed = 0;
1122  uint32_t bytesTxedTmp = 0;
1123  int rbgIndex = 0;
1124  while ( bytesTxed <= budget )
1125  {
1126  totalRbg++;
1127 
1128  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1129  itCqi = m_a30CqiRxed.find ((*itMax).first);
1130  std::map <uint16_t,uint8_t>::iterator itTxMode;
1131  itTxMode = m_uesTxMode.find ((*itMax).first);
1132  if (itTxMode == m_uesTxMode.end ())
1133  {
1134  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*it).first);
1135  }
1136  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1137 
1138  // find RBG with largest achievableRate
1139  double achievableRateMax = 0.0;
1140  rbgIndex = rbgNum;
1141  for (int k = 0; k < rbgNum; k++)
1142  {
1143  std::set <uint8_t>::iterator rbg;
1144  rbg = allocatedRbg.find (k);
1145  if (rbg != allocatedRbg.end ()) // RBGs are already allocated to this UE
1146  continue;
1147 
1148  if ( rbgMap.at (k) == true) // this RBG is allocated in RACH procedure
1149  continue;
1150 
1151  std::vector <uint8_t> sbCqi;
1152  if (itCqi == m_a30CqiRxed.end ())
1153  {
1154  for (uint8_t k = 0; k < nLayer; k++)
1155  {
1156  sbCqi.push_back (1); // start with lowest value
1157  }
1158  }
1159  else
1160  {
1161  sbCqi = (*itCqi).second.m_higherLayerSelected.at (k).m_sbCqi;
1162  }
1163  uint8_t cqi1 = sbCqi.at (0);
1164  uint8_t cqi2 = 1;
1165  if (sbCqi.size () > 1)
1166  {
1167  cqi2 = sbCqi.at (1);
1168  }
1169 
1170  if ((cqi1 > 0)||(cqi2 > 0)) // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1171  {
1172  if (LcActivePerFlow ((*itMax).first) > 0)
1173  {
1174  // this UE has data to transmit
1175  double achievableRate = 0.0;
1176  for (uint8_t j = 0; j < nLayer; j++)
1177  {
1178  uint8_t mcs = 0;
1179  if (sbCqi.size () > j)
1180  {
1181  mcs = m_amc->GetMcsFromCqi (sbCqi.at (j));
1182  }
1183  else
1184  {
1185  // no info on this subband -> worst MCS
1186  mcs = 0;
1187  }
1188  achievableRate += ((m_amc->GetTbSizeFromMcs (mcs, rbgSize) / 8) / 0.001); // = TB size / TTI
1189  }
1190 
1191  if ( achievableRate > achievableRateMax )
1192  {
1193  achievableRateMax = achievableRate;
1194  rbgIndex = k;
1195  }
1196  } // end of LcActivePerFlow
1197  } // end of cqi
1198  } // end of for rbgNum
1199 
1200  if ( rbgIndex == rbgNum) // impossible
1201  {
1202  // all RBGs are already assigned
1203  totalRbg = rbgNum;
1204  break;
1205  }
1206  else
1207  {
1208  // mark this UE as "allocated"
1209  allocatedRbg.insert (rbgIndex);
1210  }
1211 
1212  // assign this RBG to UE
1213  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1214  itMap = allocationMap.find ((*itMax).first);
1215  uint16_t RbgPerRnti;
1216  if (itMap == allocationMap.end ())
1217  {
1218  // insert new element
1219  std::vector <uint16_t> tempMap;
1220  tempMap.push_back (rbgIndex);
1221  allocationMap.insert (std::pair <uint16_t, std::vector <uint16_t> > ((*itMax).first, tempMap));
1222  itMap = allocationMap.find ((*itMax).first); // point itMap to the first RBGs assigned to this UE
1223  }
1224  else
1225  {
1226  (*itMap).second.push_back (rbgIndex);
1227  }
1228  rbgMap.at (rbgIndex) = true; // Mark this RBG as allocated
1229 
1230  RbgPerRnti = (*itMap).second.size();
1231 
1232  // calculate tb size
1233  std::vector <uint8_t> worstCqi (2, 15);
1234  if (itCqi != m_a30CqiRxed.end ())
1235  {
1236  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1237  {
1238  if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1239  {
1240  for (uint8_t j = 0; j < nLayer; j++)
1241  {
1242  if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1243  {
1244  if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1245  {
1246  worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1247  }
1248  }
1249  else
1250  {
1251  // no CQI for this layer of this suband -> worst one
1252  worstCqi.at (j) = 1;
1253  }
1254  }
1255  }
1256  else
1257  {
1258  for (uint8_t j = 0; j < nLayer; j++)
1259  {
1260  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1261  }
1262  }
1263  }
1264  }
1265  else
1266  {
1267  for (uint8_t j = 0; j < nLayer; j++)
1268  {
1269  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1270  }
1271  }
1272 
1273  bytesTxedTmp = bytesTxed;
1274  bytesTxed = 0;
1275  for (uint8_t j = 0; j < nLayer; j++)
1276  {
1277  int tbSize = (m_amc->GetTbSizeFromMcs (m_amc->GetMcsFromCqi (worstCqi.at (j)), RbgPerRnti * rbgSize) / 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1278  bytesTxed += tbSize;
1279  }
1280 
1281  } // end of while()
1282 
1283  // remove and unmark last RBG assigned to UE
1284  if ( bytesTxed > budget )
1285  {
1286  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
1287  itMap = allocationMap.find ((*itMax).first);
1288  (*itMap).second.pop_back ();
1289  allocatedRbg.erase (rbgIndex);
1290  bytesTxed = bytesTxedTmp; // recovery bytesTxed
1291  totalRbg--;
1292  rbgMap.at (rbgIndex) = false; // unmark this RBG
1293  }
1294 
1295  // update UE stats
1296  if ( bytesTxed <= (*itMax).second.tokenPoolSize )
1297  {
1298  (*itMax).second.tokenPoolSize -= bytesTxed;
1299  }
1300  else
1301  {
1302  (*itMax).second.counter = (*itMax).second.counter - ( bytesTxed - (*itMax).second.tokenPoolSize );
1303  (*itMax).second.tokenPoolSize = 0;
1304  if (bankSize <= ( bytesTxed - (*itMax).second.tokenPoolSize ))
1305  bankSize = 0;
1306  else
1307  bankSize = bankSize - ( bytesTxed - (*itMax).second.tokenPoolSize );
1308  }
1309  } // end of RBGs
1310 
1311  // generate the transmission opportunities by grouping the RBGs of the same RNTI and
1312  // creating the correspondent DCIs
1313  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap = allocationMap.begin ();
1314  while (itMap != allocationMap.end ())
1315  {
1316  // create new BuildDataListElement_s for this LC
1317  BuildDataListElement_s newEl;
1318  newEl.m_rnti = (*itMap).first;
1319  // create the DlDciListElement_s
1320  DlDciListElement_s newDci;
1321  newDci.m_rnti = (*itMap).first;
1322  newDci.m_harqProcess = UpdateHarqProcessId ((*itMap).first);
1323 
1324  uint16_t lcActives = LcActivePerFlow ((*itMap).first);
1325  NS_LOG_INFO (this << "Allocate user " << newEl.m_rnti << " rbg " << lcActives);
1326  uint16_t RgbPerRnti = (*itMap).second.size ();
1327  std::map <uint16_t,SbMeasResult_s>::iterator itCqi;
1328  itCqi = m_a30CqiRxed.find ((*itMap).first);
1329  std::map <uint16_t,uint8_t>::iterator itTxMode;
1330  itTxMode = m_uesTxMode.find ((*itMap).first);
1331  if (itTxMode == m_uesTxMode.end ())
1332  {
1333  NS_FATAL_ERROR ("No Transmission Mode info on user " << (*itMap).first);
1334  }
1335  int nLayer = TransmissionModesLayers::TxMode2LayerNum ((*itTxMode).second);
1336  std::vector <uint8_t> worstCqi (2, 15);
1337  if (itCqi != m_a30CqiRxed.end ())
1338  {
1339  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1340  {
1341  if ((*itCqi).second.m_higherLayerSelected.size () > (*itMap).second.at (k))
1342  {
1343  NS_LOG_INFO (this << " RBG " << (*itMap).second.at (k) << " CQI " << (uint16_t)((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (0)) );
1344  for (uint8_t j = 0; j < nLayer; j++)
1345  {
1346  if ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.size () > j)
1347  {
1348  if (((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j)) < worstCqi.at (j))
1349  {
1350  worstCqi.at (j) = ((*itCqi).second.m_higherLayerSelected.at ((*itMap).second.at (k)).m_sbCqi.at (j));
1351  }
1352  }
1353  else
1354  {
1355  // no CQI for this layer of this suband -> worst one
1356  worstCqi.at (j) = 1;
1357  }
1358  }
1359  }
1360  else
1361  {
1362  for (uint8_t j = 0; j < nLayer; j++)
1363  {
1364  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1365  }
1366  }
1367  }
1368  }
1369  else
1370  {
1371  for (uint8_t j = 0; j < nLayer; j++)
1372  {
1373  worstCqi.at (j) = 1; // try with lowest MCS in RBG with no info on channel
1374  }
1375  }
1376  for (uint8_t j = 0; j < nLayer; j++)
1377  {
1378  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " CQI selected " << (uint16_t)worstCqi.at (j));
1379  }
1380  uint32_t bytesTxed = 0;
1381  for (uint8_t j = 0; j < nLayer; j++)
1382  {
1383  newDci.m_mcs.push_back (m_amc->GetMcsFromCqi (worstCqi.at (j)));
1384  int tbSize = (m_amc->GetTbSizeFromMcs (newDci.m_mcs.at (j), RgbPerRnti * rbgSize) / 8); // (size of TB in bytes according to table 7.1.7.2.1-1 of 36.213)
1385  newDci.m_tbsSize.push_back (tbSize);
1386  NS_LOG_INFO (this << " Layer " << (uint16_t)j << " MCS selected" << m_amc->GetMcsFromCqi (worstCqi.at (j)));
1387  bytesTxed += tbSize;
1388  }
1389 
1390  newDci.m_resAlloc = 0; // only allocation type 0 at this stage
1391  newDci.m_rbBitmap = 0; // TBD (32 bit bitmap see 7.1.6 of 36.213)
1392  uint32_t rbgMask = 0;
1393  for (uint16_t k = 0; k < (*itMap).second.size (); k++)
1394  {
1395  rbgMask = rbgMask + (0x1 << (*itMap).second.at (k));
1396  NS_LOG_INFO (this << " Allocated RBG " << (*itMap).second.at (k));
1397  }
1398  newDci.m_rbBitmap = rbgMask; // (32 bit bitmap see 7.1.6 of 36.213)
1399 
1400  // create the rlc PDUs -> equally divide resources among actives LCs
1401  std::map <LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator itBufReq;
1402  for (itBufReq = m_rlcBufferReq.begin (); itBufReq != m_rlcBufferReq.end (); itBufReq++)
1403  {
1404  if (((*itBufReq).first.m_rnti == (*itMap).first)
1405  && (((*itBufReq).second.m_rlcTransmissionQueueSize > 0)
1406  || ((*itBufReq).second.m_rlcRetransmissionQueueSize > 0)
1407  || ((*itBufReq).second.m_rlcStatusPduSize > 0) ))
1408  {
1409  std::vector <struct RlcPduListElement_s> newRlcPduLe;
1410  for (uint8_t j = 0; j < nLayer; j++)
1411  {
1412  RlcPduListElement_s newRlcEl;
1413  newRlcEl.m_logicalChannelIdentity = (*itBufReq).first.m_lcId;
1414  newRlcEl.m_size = newDci.m_tbsSize.at (j) / lcActives;
1415  NS_LOG_INFO (this << " LCID " << (uint32_t) newRlcEl.m_logicalChannelIdentity << " size " << newRlcEl.m_size << " layer " << (uint16_t)j);
1416  newRlcPduLe.push_back (newRlcEl);
1417  UpdateDlRlcBufferInfo (newDci.m_rnti, newRlcEl.m_logicalChannelIdentity, newRlcEl.m_size);
1418  if (m_harqOn == true)
1419  {
1420  // store RLC PDU list for HARQ
1421  std::map <uint16_t, DlHarqRlcPduListBuffer_t>::iterator itRlcPdu = m_dlHarqProcessesRlcPduListBuffer.find ((*itMap).first);
1422  if (itRlcPdu == m_dlHarqProcessesRlcPduListBuffer.end ())
1423  {
1424  NS_FATAL_ERROR ("Unable to find RlcPdcList in HARQ buffer for RNTI " << (*itMap).first);
1425  }
1426  (*itRlcPdu).second.at (j).at (newDci.m_harqProcess).push_back (newRlcEl);
1427  }
1428  }
1429  newEl.m_rlcPduList.push_back (newRlcPduLe);
1430  }
1431  if ((*itBufReq).first.m_rnti > (*itMap).first)
1432  {
1433  break;
1434  }
1435  }
1436  for (uint8_t j = 0; j < nLayer; j++)
1437  {
1438  newDci.m_ndi.push_back (1);
1439  newDci.m_rv.push_back (0);
1440  }
1441 
1442  newEl.m_dci = newDci;
1443 
1444  if (m_harqOn == true)
1445  {
1446  // store DCI for HARQ
1447  std::map <uint16_t, DlHarqProcessesDciBuffer_t>::iterator itDci = m_dlHarqProcessesDciBuffer.find (newEl.m_rnti);
1448  if (itDci == m_dlHarqProcessesDciBuffer.end ())
1449  {
1450  NS_FATAL_ERROR ("Unable to find RNTI entry in DCI HARQ buffer for RNTI " << newEl.m_rnti);
1451  }
1452  (*itDci).second.at (newDci.m_harqProcess) = newDci;
1453  // refresh timer
1454  std::map <uint16_t, DlHarqProcessesTimer_t>::iterator itHarqTimer = m_dlHarqProcessesTimer.find (newEl.m_rnti);
1455  if (itHarqTimer== m_dlHarqProcessesTimer.end ())
1456  {
1457  NS_FATAL_ERROR ("Unable to find HARQ timer for RNTI " << (uint16_t)newEl.m_rnti);
1458  }
1459  (*itHarqTimer).second.at (newDci.m_harqProcess) = 0;
1460  }
1461 
1462  // ...more parameters -> ingored in this version
1463 
1464  ret.m_buildDataList.push_back (newEl);
1465 
1466  itMap++;
1467  } // end while allocation
1468  ret.m_nrOfPdcchOfdmSymbols = 1; // TODO: check correct value according the DCIs txed
1469 
1470  m_schedSapUser->SchedDlConfigInd (ret);
1471 
1472 
1473  return;
1474 }
1475 
1476 void
1477 FdTbfqFfMacScheduler::DoSchedDlRachInfoReq (const struct FfMacSchedSapProvider::SchedDlRachInfoReqParameters& params)
1478 {
1479  NS_LOG_FUNCTION (this);
1480 
1481  m_rachList = params.m_rachList;
1482 
1483  return;
1484 }
1485 
1486 void
1487 FdTbfqFfMacScheduler::DoSchedDlCqiInfoReq (const struct FfMacSchedSapProvider::SchedDlCqiInfoReqParameters& params)
1488 {
1489  NS_LOG_FUNCTION (this);
1490 
1491  for (unsigned int i = 0; i < params.m_cqiList.size (); i++)
1492  {
1493  if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::P10 )
1494  {
1495  // wideband CQI reporting
1496  std::map <uint16_t,uint8_t>::iterator it;
1497  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1498  it = m_p10CqiRxed.find (rnti);
1499  if (it == m_p10CqiRxed.end ())
1500  {
1501  // create the new entry
1502  m_p10CqiRxed.insert ( std::pair<uint16_t, uint8_t > (rnti, params.m_cqiList.at (i).m_wbCqi.at (0)) ); // only codeword 0 at this stage (SISO)
1503  // generate correspondent timer
1504  m_p10CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1505  }
1506  else
1507  {
1508  // update the CQI value and refresh correspondent timer
1509  (*it).second = params.m_cqiList.at (i).m_wbCqi.at (0);
1510  // update correspondent timer
1511  std::map <uint16_t,uint32_t>::iterator itTimers;
1512  itTimers = m_p10CqiTimers.find (rnti);
1513  (*itTimers).second = m_cqiTimersThreshold;
1514  }
1515  }
1516  else if ( params.m_cqiList.at (i).m_cqiType == CqiListElement_s::A30 )
1517  {
1518  // subband CQI reporting high layer configured
1519  std::map <uint16_t,SbMeasResult_s>::iterator it;
1520  uint16_t rnti = params.m_cqiList.at (i).m_rnti;
1521  it = m_a30CqiRxed.find (rnti);
1522  if (it == m_a30CqiRxed.end ())
1523  {
1524  // create the new entry
1525  m_a30CqiRxed.insert ( std::pair<uint16_t, SbMeasResult_s > (rnti, params.m_cqiList.at (i).m_sbMeasResult) );
1526  m_a30CqiTimers.insert ( std::pair<uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
1527  }
1528  else
1529  {
1530  // update the CQI value and refresh correspondent timer
1531  (*it).second = params.m_cqiList.at (i).m_sbMeasResult;
1532  std::map <uint16_t,uint32_t>::iterator itTimers;
1533  itTimers = m_a30CqiTimers.find (rnti);
1534  (*itTimers).second = m_cqiTimersThreshold;
1535  }
1536  }
1537  else
1538  {
1539  NS_LOG_ERROR (this << " CQI type unknown");
1540  }
1541  }
1542 
1543  return;
1544 }
1545 
1546 
1547 double
1548 FdTbfqFfMacScheduler::EstimateUlSinr (uint16_t rnti, uint16_t rb)
1549 {
1550  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find (rnti);
1551  if (itCqi == m_ueCqi.end ())
1552  {
1553  // no cqi info about this UE
1554  return (NO_SINR);
1555 
1556  }
1557  else
1558  {
1559  // take the average SINR value among the available
1560  double sinrSum = 0;
1561  int sinrNum = 0;
1562  for (uint32_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1563  {
1564  double sinr = (*itCqi).second.at (i);
1565  if (sinr != NO_SINR)
1566  {
1567  sinrSum += sinr;
1568  sinrNum++;
1569  }
1570  }
1571  double estimatedSinr = sinrSum / (double)sinrNum;
1572  // store the value
1573  (*itCqi).second.at (rb) = estimatedSinr;
1574  return (estimatedSinr);
1575  }
1576 }
1577 
1578 void
1579 FdTbfqFfMacScheduler::DoSchedUlTriggerReq (const struct FfMacSchedSapProvider::SchedUlTriggerReqParameters& params)
1580 {
1581  NS_LOG_FUNCTION (this << " UL - Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf) << " size " << params.m_ulInfoList.size ());
1582 
1583  RefreshUlCqiMaps ();
1584 
1585  // Generate RBs map
1586  FfMacSchedSapUser::SchedUlConfigIndParameters ret;
1587  std::vector <bool> rbMap;
1588  uint16_t rbAllocatedNum = 0;
1589  std::set <uint16_t> rntiAllocated;
1590  std::vector <uint16_t> rbgAllocationMap;
1591  // update with RACH allocation map
1592  rbgAllocationMap = m_rachAllocationMap;
1593  //rbgAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1594  m_rachAllocationMap.clear ();
1595  m_rachAllocationMap.resize (m_cschedCellConfig.m_ulBandwidth, 0);
1596 
1597  rbMap.resize (m_cschedCellConfig.m_ulBandwidth, false);
1598  // remove RACH allocation
1599  for (uint16_t i = 0; i < m_cschedCellConfig.m_ulBandwidth; i++)
1600  {
1601  if (rbgAllocationMap.at (i) != 0)
1602  {
1603  rbMap.at (i) = true;
1604  NS_LOG_DEBUG (this << " Allocated for RACH " << i);
1605  }
1606  }
1607 
1608 
1609  if (m_harqOn == true)
1610  {
1611  // Process UL HARQ feedback
1612  // update UL HARQ proc id
1613  std::map <uint16_t, uint8_t>::iterator itProcId;
1614  for (itProcId = m_ulHarqCurrentProcessId.begin (); itProcId != m_ulHarqCurrentProcessId.end (); itProcId++)
1615  {
1616  (*itProcId).second = ((*itProcId).second + 1) % HARQ_PROC_NUM;
1617  }
1618 
1619  for (uint16_t i = 0; i < params.m_ulInfoList.size (); i++)
1620  {
1621  if (params.m_ulInfoList.at (i).m_receptionStatus == UlInfoListElement_s::NotOk)
1622  {
1623  // retx correspondent block: retrieve the UL-DCI
1624  uint16_t rnti = params.m_ulInfoList.at (i).m_rnti;
1625  itProcId = m_ulHarqCurrentProcessId.find (rnti);
1626  if (itProcId == m_ulHarqCurrentProcessId.end ())
1627  {
1628  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1629  }
1630  uint8_t harqId = (uint8_t)((*itProcId).second - HARQ_PERIOD) % HARQ_PROC_NUM;
1631  NS_LOG_INFO (this << " UL-HARQ retx RNTI " << rnti << " harqId " << (uint16_t)harqId << " i " << i << " size " << params.m_ulInfoList.size ());
1632  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itHarq = m_ulHarqProcessesDciBuffer.find (rnti);
1633  if (itHarq == m_ulHarqProcessesDciBuffer.end ())
1634  {
1635  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1636  continue;
1637  }
1638  UlDciListElement_s dci = (*itHarq).second.at (harqId);
1639  std::map <uint16_t, UlHarqProcessesStatus_t>::iterator itStat = m_ulHarqProcessesStatus.find (rnti);
1640  if (itStat == m_ulHarqProcessesStatus.end ())
1641  {
1642  NS_LOG_ERROR ("No info find in HARQ buffer for UE (might change eNB) " << rnti);
1643  }
1644  if ((*itStat).second.at (harqId) >= 3)
1645  {
1646  NS_LOG_INFO ("Max number of retransmissions reached (UL)-> drop process");
1647  continue;
1648  }
1649  bool free = true;
1650  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1651  {
1652  if (rbMap.at (j) == true)
1653  {
1654  free = false;
1655  NS_LOG_INFO (this << " BUSY " << j);
1656  }
1657  }
1658  if (free)
1659  {
1660  // retx on the same RBs
1661  for (int j = dci.m_rbStart; j < dci.m_rbStart + dci.m_rbLen; j++)
1662  {
1663  rbMap.at (j) = true;
1664  rbgAllocationMap.at (j) = dci.m_rnti;
1665  NS_LOG_INFO ("\tRB " << j);
1666  rbAllocatedNum++;
1667  }
1668  NS_LOG_INFO (this << " Send retx in the same RBs " << (uint16_t)dci.m_rbStart << " to " << dci.m_rbStart + dci.m_rbLen << " RV " << (*itStat).second.at (harqId) + 1);
1669  }
1670  else
1671  {
1672  NS_LOG_INFO ("Cannot allocate retx due to RACH allocations for UE " << rnti);
1673  continue;
1674  }
1675  dci.m_ndi = 0;
1676  // Update HARQ buffers with new HarqId
1677  (*itStat).second.at ((*itProcId).second) = (*itStat).second.at (harqId) + 1;
1678  (*itStat).second.at (harqId) = 0;
1679  (*itHarq).second.at ((*itProcId).second) = dci;
1680  ret.m_dciList.push_back (dci);
1681  rntiAllocated.insert (dci.m_rnti);
1682  }
1683  else
1684  {
1685  NS_LOG_INFO (this << " HARQ-ACK feedback from RNTI " << params.m_ulInfoList.at (i).m_rnti);
1686  }
1687  }
1688  }
1689 
1690  std::map <uint16_t,uint32_t>::iterator it;
1691  int nflows = 0;
1692 
1693  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1694  {
1695  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1696  // select UEs with queues not empty and not yet allocated for HARQ
1697  if (((*it).second > 0)&&(itRnti == rntiAllocated.end ()))
1698  {
1699  nflows++;
1700  }
1701  }
1702 
1703  if (nflows == 0)
1704  {
1705  if (ret.m_dciList.size () > 0)
1706  {
1707  m_schedSapUser->SchedUlConfigInd (ret);
1708  }
1709 
1710  return; // no flows to be scheduled
1711  }
1712 
1713 
1714  // Divide the remaining resources equally among the active users starting from the subsequent one served last scheduling trigger
1715  uint16_t rbPerFlow = (m_cschedCellConfig.m_ulBandwidth) / (nflows + rntiAllocated.size ());
1716  if (rbPerFlow < 3)
1717  {
1718  rbPerFlow = 3; // at least 3 rbg per flow (till available resource) to ensure TxOpportunity >= 7 bytes
1719  }
1720  int rbAllocated = 0;
1721 
1722  std::map <uint16_t, fdtbfqsFlowPerf_t>::iterator itStats;
1723  if (m_nextRntiUl != 0)
1724  {
1725  for (it = m_ceBsrRxed.begin (); it != m_ceBsrRxed.end (); it++)
1726  {
1727  if ((*it).first == m_nextRntiUl)
1728  {
1729  break;
1730  }
1731  }
1732  if (it == m_ceBsrRxed.end ())
1733  {
1734  NS_LOG_ERROR (this << " no user found");
1735  }
1736  }
1737  else
1738  {
1739  it = m_ceBsrRxed.begin ();
1740  m_nextRntiUl = (*it).first;
1741  }
1742  do
1743  {
1744  std::set <uint16_t>::iterator itRnti = rntiAllocated.find ((*it).first);
1745  if ((itRnti != rntiAllocated.end ())||((*it).second == 0))
1746  {
1747  // UE already allocated for UL-HARQ -> skip it
1748  it++;
1749  if (it == m_ceBsrRxed.end ())
1750  {
1751  // restart from the first
1752  it = m_ceBsrRxed.begin ();
1753  }
1754  continue;
1755  }
1756  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1757  {
1758  // limit to physical resources last resource assignment
1759  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1760  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1761  if (rbPerFlow < 3)
1762  {
1763  // terminate allocation
1764  rbPerFlow = 0;
1765  }
1766  }
1767 
1768  UlDciListElement_s uldci;
1769  uldci.m_rnti = (*it).first;
1770  uldci.m_rbLen = rbPerFlow;
1771  bool allocated = false;
1772  NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow);
1773  while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0))
1774  {
1775  // check availability
1776  bool free = true;
1777  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1778  {
1779  if (rbMap.at (j) == true)
1780  {
1781  free = false;
1782  break;
1783  }
1784  }
1785  if (free)
1786  {
1787  uldci.m_rbStart = rbAllocated;
1788 
1789  for (uint16_t j = rbAllocated; j < rbAllocated + rbPerFlow; j++)
1790  {
1791  rbMap.at (j) = true;
1792  // store info on allocation for managing ul-cqi interpretation
1793  rbgAllocationMap.at (j) = (*it).first;
1794  }
1795  rbAllocated += rbPerFlow;
1796  allocated = true;
1797  break;
1798  }
1799  rbAllocated++;
1800  if (rbAllocated + rbPerFlow - 1 > m_cschedCellConfig.m_ulBandwidth)
1801  {
1802  // limit to physical resources last resource assignment
1803  rbPerFlow = m_cschedCellConfig.m_ulBandwidth - rbAllocated;
1804  // at least 3 rbg per flow to ensure TxOpportunity >= 7 bytes
1805  if (rbPerFlow < 3)
1806  {
1807  // terminate allocation
1808  rbPerFlow = 0;
1809  }
1810  }
1811  }
1812  if (!allocated)
1813  {
1814  // unable to allocate new resource: finish scheduling
1815  m_nextRntiUl = (*it).first;
1816  if (ret.m_dciList.size () > 0)
1817  {
1818  m_schedSapUser->SchedUlConfigInd (ret);
1819  }
1820  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1821  return;
1822  }
1823 
1824 
1825 
1826  std::map <uint16_t, std::vector <double> >::iterator itCqi = m_ueCqi.find ((*it).first);
1827  int cqi = 0;
1828  if (itCqi == m_ueCqi.end ())
1829  {
1830  // no cqi info about this UE
1831  uldci.m_mcs = 0; // MCS 0 -> UL-AMC TBD
1832  }
1833  else
1834  {
1835  // take the lowest CQI value (worst RB)
1836  double minSinr = (*itCqi).second.at (uldci.m_rbStart);
1837  if (minSinr == NO_SINR)
1838  {
1839  minSinr = EstimateUlSinr ((*it).first, uldci.m_rbStart);
1840  }
1841  for (uint16_t i = uldci.m_rbStart; i < uldci.m_rbStart + uldci.m_rbLen; i++)
1842  {
1843  double sinr = (*itCqi).second.at (i);
1844  if (sinr == NO_SINR)
1845  {
1846  sinr = EstimateUlSinr ((*it).first, i);
1847  }
1848  if ((*itCqi).second.at (i) < minSinr)
1849  {
1850  minSinr = (*itCqi).second.at (i);
1851  }
1852  }
1853 
1854  // translate SINR -> cqi: WILD ACK: same as DL
1855  double s = log2 ( 1 + (
1856  pow (10, minSinr / 10 ) /
1857  ( (-log (5.0 * 0.00005 )) / 1.5) ));
1858  cqi = m_amc->GetCqiFromSpectralEfficiency (s);
1859  if (cqi == 0)
1860  {
1861  it++;
1862  if (it == m_ceBsrRxed.end ())
1863  {
1864  // restart from the first
1865  it = m_ceBsrRxed.begin ();
1866  }
1867  continue; // CQI == 0 means "out of range" (see table 7.2.3-1 of 36.213)
1868  }
1869  uldci.m_mcs = m_amc->GetMcsFromCqi (cqi);
1870  }
1871 
1872  uldci.m_tbSize = (m_amc->GetTbSizeFromMcs (uldci.m_mcs, rbPerFlow) / 8);
1873  UpdateUlRlcBufferInfo (uldci.m_rnti, uldci.m_tbSize);
1874  uldci.m_ndi = 1;
1875  uldci.m_cceIndex = 0;
1876  uldci.m_aggrLevel = 1;
1877  uldci.m_ueTxAntennaSelection = 3; // antenna selection OFF
1878  uldci.m_hopping = false;
1879  uldci.m_n2Dmrs = 0;
1880  uldci.m_tpc = 0; // no power control
1881  uldci.m_cqiRequest = false; // only period CQI at this stage
1882  uldci.m_ulIndex = 0; // TDD parameter
1883  uldci.m_dai = 1; // TDD parameter
1884  uldci.m_freqHopping = 0;
1885  uldci.m_pdcchPowerOffset = 0; // not used
1886  ret.m_dciList.push_back (uldci);
1887  // store DCI for HARQ_PERIOD
1888  uint8_t harqId = 0;
1889  if (m_harqOn == true)
1890  {
1891  std::map <uint16_t, uint8_t>::iterator itProcId;
1892  itProcId = m_ulHarqCurrentProcessId.find (uldci.m_rnti);
1893  if (itProcId == m_ulHarqCurrentProcessId.end ())
1894  {
1895  NS_FATAL_ERROR ("No info find in HARQ buffer for UE " << uldci.m_rnti);
1896  }
1897  harqId = (*itProcId).second;
1898  std::map <uint16_t, UlHarqProcessesDciBuffer_t>::iterator itDci = m_ulHarqProcessesDciBuffer.find (uldci.m_rnti);
1899  if (itDci == m_ulHarqProcessesDciBuffer.end ())
1900  {
1901  NS_FATAL_ERROR ("Unable to find RNTI entry in UL DCI HARQ buffer for RNTI " << uldci.m_rnti);
1902  }
1903  (*itDci).second.at (harqId) = uldci;
1904  }
1905 
1906  NS_LOG_INFO (this << " UE Allocation RNTI " << (*it).first << " startPRB " << (uint32_t)uldci.m_rbStart << " nPRB " << (uint32_t)uldci.m_rbLen << " CQI " << cqi << " MCS " << (uint32_t)uldci.m_mcs << " TBsize " << uldci.m_tbSize << " RbAlloc " << rbAllocated << " harqId " << (uint16_t)harqId);
1907 
1908  it++;
1909  if (it == m_ceBsrRxed.end ())
1910  {
1911  // restart from the first
1912  it = m_ceBsrRxed.begin ();
1913  }
1914  if ((rbAllocated == m_cschedCellConfig.m_ulBandwidth) || (rbPerFlow == 0))
1915  {
1916  // Stop allocation: no more PRBs
1917  m_nextRntiUl = (*it).first;
1918  break;
1919  }
1920  }
1921  while (((*it).first != m_nextRntiUl)&&(rbPerFlow!=0));
1922 
1923 
1924  m_allocationMaps.insert (std::pair <uint16_t, std::vector <uint16_t> > (params.m_sfnSf, rbgAllocationMap));
1925  m_schedSapUser->SchedUlConfigInd (ret);
1926 
1927  return;
1928 }
1929 
1930 void
1931 FdTbfqFfMacScheduler::DoSchedUlNoiseInterferenceReq (const struct FfMacSchedSapProvider::SchedUlNoiseInterferenceReqParameters& params)
1932 {
1933  NS_LOG_FUNCTION (this);
1934  return;
1935 }
1936 
1937 void
1938 FdTbfqFfMacScheduler::DoSchedUlSrInfoReq (const struct FfMacSchedSapProvider::SchedUlSrInfoReqParameters& params)
1939 {
1940  NS_LOG_FUNCTION (this);
1941  return;
1942 }
1943 
1944 void
1945 FdTbfqFfMacScheduler::DoSchedUlMacCtrlInfoReq (const struct FfMacSchedSapProvider::SchedUlMacCtrlInfoReqParameters& params)
1946 {
1947  NS_LOG_FUNCTION (this);
1948 
1949  std::map <uint16_t,uint32_t>::iterator it;
1950 
1951  for (unsigned int i = 0; i < params.m_macCeList.size (); i++)
1952  {
1953  if ( params.m_macCeList.at (i).m_macCeType == MacCeListElement_s::BSR )
1954  {
1955  // buffer status report
1956  // note that this scheduler does not differentiate the
1957  // allocation according to which LCGs have more/less bytes
1958  // to send.
1959  // Hence the BSR of different LCGs are just summed up to get
1960  // a total queue size that is used for allocation purposes.
1961 
1962  uint32_t buffer = 0;
1963  for (uint8_t lcg = 0; lcg < 4; ++lcg)
1964  {
1965  uint8_t bsrId = params.m_macCeList.at (i).m_macCeValue.m_bufferStatus.at (lcg);
1966  buffer += BufferSizeLevelBsr::BsrId2BufferSize (bsrId);
1967  }
1968 
1969  uint16_t rnti = params.m_macCeList.at (i).m_rnti;
1970  NS_LOG_LOGIC (this << "RNTI=" << rnti << " buffer=" << buffer);
1971  it = m_ceBsrRxed.find (rnti);
1972  if (it == m_ceBsrRxed.end ())
1973  {
1974  // create the new entry
1975  m_ceBsrRxed.insert ( std::pair<uint16_t, uint32_t > (rnti, buffer));
1976  }
1977  else
1978  {
1979  // update the buffer size value
1980  (*it).second = buffer;
1981  }
1982  }
1983  }
1984 
1985  return;
1986 }
1987 
1988 void
1989 FdTbfqFfMacScheduler::DoSchedUlCqiInfoReq (const struct FfMacSchedSapProvider::SchedUlCqiInfoReqParameters& params)
1990 {
1991  NS_LOG_FUNCTION (this);
1992 // retrieve the allocation for this subframe
1993  switch (m_ulCqiFilter)
1994  {
1995  case FfMacScheduler::SRS_UL_CQI:
1996  {
1997  // filter all the CQIs that are not SRS based
1998  if (params.m_ulCqi.m_type != UlCqi_s::SRS)
1999  {
2000  return;
2001  }
2002  }
2003  break;
2004  case FfMacScheduler::PUSCH_UL_CQI:
2005  {
2006  // filter all the CQIs that are not SRS based
2007  if (params.m_ulCqi.m_type != UlCqi_s::PUSCH)
2008  {
2009  return;
2010  }
2011  }
2012  case FfMacScheduler::ALL_UL_CQI:
2013  break;
2014 
2015  default:
2016  NS_FATAL_ERROR ("Unknown UL CQI type");
2017  }
2018 
2019  switch (params.m_ulCqi.m_type)
2020  {
2021  case UlCqi_s::PUSCH:
2022  {
2023  std::map <uint16_t, std::vector <uint16_t> >::iterator itMap;
2024  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2025  NS_LOG_DEBUG (this << " Collect PUSCH CQIs of Frame no. " << (params.m_sfnSf >> 4) << " subframe no. " << (0xF & params.m_sfnSf));
2026  itMap = m_allocationMaps.find (params.m_sfnSf);
2027  if (itMap == m_allocationMaps.end ())
2028  {
2029  return;
2030  }
2031  for (uint32_t i = 0; i < (*itMap).second.size (); i++)
2032  {
2033  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
2034  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (i));
2035  itCqi = m_ueCqi.find ((*itMap).second.at (i));
2036  if (itCqi == m_ueCqi.end ())
2037  {
2038  // create a new entry
2039  std::vector <double> newCqi;
2040  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2041  {
2042  if (i == j)
2043  {
2044  newCqi.push_back (sinr);
2045  }
2046  else
2047  {
2048  // initialize with NO_SINR value.
2049  newCqi.push_back (NO_SINR);
2050  }
2051 
2052  }
2053  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > ((*itMap).second.at (i), newCqi));
2054  // generate correspondent timer
2055  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > ((*itMap).second.at (i), m_cqiTimersThreshold));
2056  }
2057  else
2058  {
2059  // update the value
2060  (*itCqi).second.at (i) = sinr;
2061  NS_LOG_DEBUG (this << " RNTI " << (*itMap).second.at (i) << " RB " << i << " SINR " << sinr);
2062  // update correspondent timer
2063  std::map <uint16_t, uint32_t>::iterator itTimers;
2064  itTimers = m_ueCqiTimers.find ((*itMap).second.at (i));
2065  (*itTimers).second = m_cqiTimersThreshold;
2066 
2067  }
2068 
2069  }
2070  // remove obsolete info on allocation
2071  m_allocationMaps.erase (itMap);
2072  }
2073  break;
2074  case UlCqi_s::SRS:
2075  {
2076  // get the RNTI from vendor specific parameters
2077  uint16_t rnti = 0;
2078  NS_ASSERT (params.m_vendorSpecificList.size () > 0);
2079  for (uint16_t i = 0; i < params.m_vendorSpecificList.size (); i++)
2080  {
2081  if (params.m_vendorSpecificList.at (i).m_type == SRS_CQI_RNTI_VSP)
2082  {
2083  Ptr<SrsCqiRntiVsp> vsp = DynamicCast<SrsCqiRntiVsp> (params.m_vendorSpecificList.at (i).m_value);
2084  rnti = vsp->GetRnti ();
2085  }
2086  }
2087  std::map <uint16_t, std::vector <double> >::iterator itCqi;
2088  itCqi = m_ueCqi.find (rnti);
2089  if (itCqi == m_ueCqi.end ())
2090  {
2091  // create a new entry
2092  std::vector <double> newCqi;
2093  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2094  {
2095  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
2096  newCqi.push_back (sinr);
2097  NS_LOG_INFO (this << " RNTI " << rnti << " new SRS-CQI for RB " << j << " value " << sinr);
2098 
2099  }
2100  m_ueCqi.insert (std::pair <uint16_t, std::vector <double> > (rnti, newCqi));
2101  // generate correspondent timer
2102  m_ueCqiTimers.insert (std::pair <uint16_t, uint32_t > (rnti, m_cqiTimersThreshold));
2103  }
2104  else
2105  {
2106  // update the values
2107  for (uint32_t j = 0; j < m_cschedCellConfig.m_ulBandwidth; j++)
2108  {
2109  double sinr = LteFfConverter::fpS11dot3toDouble (params.m_ulCqi.m_sinr.at (j));
2110  (*itCqi).second.at (j) = sinr;
2111  NS_LOG_INFO (this << " RNTI " << rnti << " update SRS-CQI for RB " << j << " value " << sinr);
2112  }
2113  // update correspondent timer
2114  std::map <uint16_t, uint32_t>::iterator itTimers;
2115  itTimers = m_ueCqiTimers.find (rnti);
2116  (*itTimers).second = m_cqiTimersThreshold;
2117 
2118  }
2119 
2120 
2121  }
2122  break;
2123  case UlCqi_s::PUCCH_1:
2124  case UlCqi_s::PUCCH_2:
2125  case UlCqi_s::PRACH:
2126  {
2127  NS_FATAL_ERROR ("FdTbfqFfMacScheduler supports only PUSCH and SRS UL-CQIs");
2128  }
2129  break;
2130  default:
2131  NS_FATAL_ERROR ("Unknown type of UL-CQI");
2132  }
2133  return;
2134 }
2135 
2136 void
2137 FdTbfqFfMacScheduler::RefreshDlCqiMaps (void)
2138 {
2139  // refresh DL CQI P01 Map
2140  std::map <uint16_t,uint32_t>::iterator itP10 = m_p10CqiTimers.begin ();
2141  while (itP10 != m_p10CqiTimers.end ())
2142  {
2143  NS_LOG_INFO (this << " P10-CQI for user " << (*itP10).first << " is " << (uint32_t)(*itP10).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2144  if ((*itP10).second == 0)
2145  {
2146  // delete correspondent entries
2147  std::map <uint16_t,uint8_t>::iterator itMap = m_p10CqiRxed.find ((*itP10).first);
2148  NS_ASSERT_MSG (itMap != m_p10CqiRxed.end (), " Does not find CQI report for user " << (*itP10).first);
2149  NS_LOG_INFO (this << " P10-CQI expired for user " << (*itP10).first);
2150  m_p10CqiRxed.erase (itMap);
2151  std::map <uint16_t,uint32_t>::iterator temp = itP10;
2152  itP10++;
2153  m_p10CqiTimers.erase (temp);
2154  }
2155  else
2156  {
2157  (*itP10).second--;
2158  itP10++;
2159  }
2160  }
2161 
2162  // refresh DL CQI A30 Map
2163  std::map <uint16_t,uint32_t>::iterator itA30 = m_a30CqiTimers.begin ();
2164  while (itA30 != m_a30CqiTimers.end ())
2165  {
2166  NS_LOG_INFO (this << " A30-CQI for user " << (*itA30).first << " is " << (uint32_t)(*itA30).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2167  if ((*itA30).second == 0)
2168  {
2169  // delete correspondent entries
2170  std::map <uint16_t,SbMeasResult_s>::iterator itMap = m_a30CqiRxed.find ((*itA30).first);
2171  NS_ASSERT_MSG (itMap != m_a30CqiRxed.end (), " Does not find CQI report for user " << (*itA30).first);
2172  NS_LOG_INFO (this << " A30-CQI expired for user " << (*itA30).first);
2173  m_a30CqiRxed.erase (itMap);
2174  std::map <uint16_t,uint32_t>::iterator temp = itA30;
2175  itA30++;
2176  m_a30CqiTimers.erase (temp);
2177  }
2178  else
2179  {
2180  (*itA30).second--;
2181  itA30++;
2182  }
2183  }
2184 
2185  return;
2186 }
2187 
2188 
2189 void
2190 FdTbfqFfMacScheduler::RefreshUlCqiMaps (void)
2191 {
2192  // refresh UL CQI Map
2193  std::map <uint16_t,uint32_t>::iterator itUl = m_ueCqiTimers.begin ();
2194  while (itUl != m_ueCqiTimers.end ())
2195  {
2196  NS_LOG_INFO (this << " UL-CQI for user " << (*itUl).first << " is " << (uint32_t)(*itUl).second << " thr " << (uint32_t)m_cqiTimersThreshold);
2197  if ((*itUl).second == 0)
2198  {
2199  // delete correspondent entries
2200  std::map <uint16_t, std::vector <double> >::iterator itMap = m_ueCqi.find ((*itUl).first);
2201  NS_ASSERT_MSG (itMap != m_ueCqi.end (), " Does not find CQI report for user " << (*itUl).first);
2202  NS_LOG_INFO (this << " UL-CQI exired for user " << (*itUl).first);
2203  (*itMap).second.clear ();
2204  m_ueCqi.erase (itMap);
2205  std::map <uint16_t,uint32_t>::iterator temp = itUl;
2206  itUl++;
2207  m_ueCqiTimers.erase (temp);
2208  }
2209  else
2210  {
2211  (*itUl).second--;
2212  itUl++;
2213  }
2214  }
2215 
2216  return;
2217 }
2218 
2219 void
2220 FdTbfqFfMacScheduler::UpdateDlRlcBufferInfo (uint16_t rnti, uint8_t lcid, uint16_t size)
2221 {
2222  std::map<LteFlowId_t, FfMacSchedSapProvider::SchedDlRlcBufferReqParameters>::iterator it;
2223  LteFlowId_t flow (rnti, lcid);
2224  it = m_rlcBufferReq.find (flow);
2225  if (it != m_rlcBufferReq.end ())
2226  {
2227  NS_LOG_INFO (this << " UE " << rnti << " LC " << (uint16_t)lcid << " txqueue " << (*it).second.m_rlcTransmissionQueueSize << " retxqueue " << (*it).second.m_rlcRetransmissionQueueSize << " status " << (*it).second.m_rlcStatusPduSize << " decrease " << size);
2228  // Update queues: RLC tx order Status, ReTx, Tx
2229  // Update status queue
2230  if (((*it).second.m_rlcStatusPduSize > 0) && (size >= (*it).second.m_rlcStatusPduSize))
2231  {
2232  (*it).second.m_rlcStatusPduSize = 0;
2233  }
2234  else if (((*it).second.m_rlcRetransmissionQueueSize > 0) && (size >= (*it).second.m_rlcRetransmissionQueueSize))
2235  {
2236  (*it).second.m_rlcRetransmissionQueueSize = 0;
2237  }
2238  else if ((*it).second.m_rlcTransmissionQueueSize > 0)
2239  {
2240  // update transmission queue
2241  if ((*it).second.m_rlcTransmissionQueueSize <= size)
2242  {
2243  (*it).second.m_rlcTransmissionQueueSize = 0;
2244  }
2245  else
2246  {
2247  size -= 2; // remove minimun RLC overhead due to header
2248  (*it).second.m_rlcTransmissionQueueSize -= size;
2249  }
2250  }
2251  }
2252  else
2253  {
2254  NS_LOG_ERROR (this << " Does not find DL RLC Buffer Report of UE " << rnti);
2255  }
2256 }
2257 
2258 void
2259 FdTbfqFfMacScheduler::UpdateUlRlcBufferInfo (uint16_t rnti, uint16_t size)
2260 {
2261 
2262  size = size - 2; // remove the minimum RLC overhead
2263  std::map <uint16_t,uint32_t>::iterator it = m_ceBsrRxed.find (rnti);
2264  if (it != m_ceBsrRxed.end ())
2265  {
2266  NS_LOG_INFO (this << " UE " << rnti << " size " << size << " BSR " << (*it).second);
2267  if ((*it).second >= size)
2268  {
2269  (*it).second -= size;
2270  }
2271  else
2272  {
2273  (*it).second = 0;
2274  }
2275  }
2276  else
2277  {
2278  NS_LOG_ERROR (this << " Does not find BSR report info of UE " << rnti);
2279  }
2280 
2281 }
2282 
2283 void
2284 FdTbfqFfMacScheduler::TransmissionModeConfigurationUpdate (uint16_t rnti, uint8_t txMode)
2285 {
2286  NS_LOG_FUNCTION (this << " RNTI " << rnti << " txMode " << (uint16_t)txMode);
2287  FfMacCschedSapUser::CschedUeConfigUpdateIndParameters params;
2288  params.m_rnti = rnti;
2289  params.m_transmissionMode = txMode;
2290  m_cschedSapUser->CschedUeConfigUpdateInd (params);
2291 }
2292 
2293 
2294 }
virtual void SetFfMacCschedSapUser(FfMacCschedSapUser *s)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
Hold a bool native type.
Definition: boolean.h:38
#define NS_ASSERT(condition)
Definition: assert.h:64
Hold a signed integer type.
Definition: integer.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
Provides the CSCHED SAP.
#define NS_LOG_INFO(msg)
Definition: log.h:264
See section 4.3.10 buildRARListElement.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
virtual void SetFfMacSchedSapUser(FfMacSchedSapUser *s)
uint8_t HarqProcessAvailability(uint16_t rnti)
Return the availability of free process for the RNTI specified.
Hold an unsigned integer type.
Definition: uinteger.h:46
Provides the SCHED SAP.
virtual FfMacCschedSapProvider * GetFfMacCschedSapProvider()
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
Implements the SCHED SAP and CSCHED SAP for a Frequency Domain Token Bank Fair Queue scheduler...
virtual void CschedCellConfigReq(const struct CschedCellConfigReqParameters &params)
CSCHED_CELL_CONFIG_REQ.
void RefreshHarqProcesses()
Refresh HARQ processes according to the timers.
static Time Now(void)
Definition: simulator.cc:179
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
#define NS_LOG_ERROR(msg)
Definition: log.h:237
virtual FfMacSchedSapProvider * GetFfMacSchedSapProvider()
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
uint8_t UpdateHarqProcessId(uint16_t rnti)
Update and return a new process Id for the RNTI specified.