A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-harq-phy.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 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  */
20 
21 
22 #include <ns3/lte-harq-phy.h>
23 #include <ns3/log.h>
24 #include <ns3/assert.h>
25 
26 NS_LOG_COMPONENT_DEFINE ("LteHarqPhy");
27 
28 namespace ns3 {
29 
30 //NS_OBJECT_ENSURE_REGISTERED (LteHarqPhy);
31 
32 
33 LteHarqPhy::LteHarqPhy ()
34 {
35  // Create DL Decodification HARQ buffers
36  std::vector <HarqProcessInfoList_t> dlHarqLayer0;
37  dlHarqLayer0.resize (8);
38  std::vector <HarqProcessInfoList_t> dlHarqLayer1;
39  dlHarqLayer1.resize (8);
40  m_miDlHarqProcessesInfoMap.push_back (dlHarqLayer0);
41  m_miDlHarqProcessesInfoMap.push_back (dlHarqLayer1);
42 }
43 
44 
45 LteHarqPhy::~LteHarqPhy ()
46 {
47  m_miDlHarqProcessesInfoMap.clear ();
48  m_miUlHarqProcessesInfoMap.clear ();
49 }
50 
51 
52 void
53 LteHarqPhy::SubframeIndication (uint32_t frameNo, uint32_t subframeNo)
54 {
55  NS_LOG_FUNCTION (this);
56 
57  // left shift UL HARQ buffers
58  std::map <uint16_t, std::vector <HarqProcessInfoList_t> >:: iterator it;
59  for (it = m_miUlHarqProcessesInfoMap.begin (); it != m_miUlHarqProcessesInfoMap.end (); it++)
60  {
61  (*it).second.erase ((*it).second.begin ());
62  HarqProcessInfoList_t h;
63  (*it).second.push_back (h);
64  }
65 
66 }
67 
68 
69 double
70 LteHarqPhy::GetAccumulatedMiDl (uint8_t harqProcId, uint8_t layer)
71 {
72  NS_LOG_FUNCTION (this << (uint32_t)harqProcId << (uint16_t)layer);
73  HarqProcessInfoList_t list = m_miDlHarqProcessesInfoMap.at (layer).at (harqProcId);
74  double mi = 0.0;
75  for (uint8_t i = 0; i < list.size (); i++)
76  {
77  mi += list.at (i).m_mi;
78  }
79  return (mi);
80 }
81 
82 HarqProcessInfoList_t
83 LteHarqPhy::GetHarqProcessInfoDl (uint8_t harqProcId, uint8_t layer)
84 {
85  NS_LOG_FUNCTION (this << (uint32_t)harqProcId << (uint16_t)layer);
86  return (m_miDlHarqProcessesInfoMap.at (layer).at (harqProcId));
87 }
88 
89 
90 double
92 {
93  NS_LOG_FUNCTION (this << rnti);
94 
95  std::map <uint16_t, std::vector <HarqProcessInfoList_t> >::iterator it;
96  it = m_miUlHarqProcessesInfoMap.find (rnti);
97  NS_ASSERT_MSG (it!=m_miUlHarqProcessesInfoMap.end (), " Does not find MI for RNTI");
98  HarqProcessInfoList_t list = (*it).second.at (0);
99  double mi = 0.0;
100  for (uint8_t i = 0; i < list.size (); i++)
101  {
102  mi += list.at (i).m_mi;
103  }
104  return (mi);
105 }
106 
107 HarqProcessInfoList_t
108 LteHarqPhy::GetHarqProcessInfoUl (uint16_t rnti, uint8_t harqProcId)
109 {
110  NS_LOG_FUNCTION (this << rnti << (uint16_t)harqProcId);
111  std::map <uint16_t, std::vector <HarqProcessInfoList_t> >::iterator it;
112  it = m_miUlHarqProcessesInfoMap.find (rnti);
113  if (it==m_miUlHarqProcessesInfoMap.end ())
114  {
115  // new entry
116  std::vector <HarqProcessInfoList_t> harqList;
117  harqList.resize (8);
118  m_miUlHarqProcessesInfoMap.insert (std::pair <uint16_t, std::vector <HarqProcessInfoList_t> > (rnti, harqList));
119  return (harqList.at (harqProcId));
120  }
121  else
122  {
123  return ((*it).second.at (harqProcId));
124  }
125 }
126 
127 
128 
129 void
130 LteHarqPhy::UpdateDlHarqProcessStatus (uint8_t id, uint8_t layer, double mi, uint16_t infoBytes, uint16_t codeBytes)
131 {
132  NS_LOG_FUNCTION (this << (uint16_t) id << mi);
133  if (m_miDlHarqProcessesInfoMap.at (layer).at (id).size () == 3) // MAX HARQ RETX
134  {
135  // HARQ should be disabled -> discard info
136  return;
137  }
139  el.m_mi = mi;
140  el.m_infoBits = infoBytes * 8;
141  el.m_codeBits = codeBytes * 8;
142  m_miDlHarqProcessesInfoMap.at (layer).at (id).push_back (el);
143 }
144 
145 
146 void
148 {
149  NS_LOG_FUNCTION (this << (uint16_t) id);
150  for (uint8_t i = 0; i < m_miDlHarqProcessesInfoMap.size (); i++)
151  {
152  m_miDlHarqProcessesInfoMap.at (i).at (id).clear ();
153  }
154 
155 }
156 
157 
158 void
159 LteHarqPhy::UpdateUlHarqProcessStatus (uint16_t rnti, double mi, uint16_t infoBytes, uint16_t codeBytes)
160 {
161  NS_LOG_FUNCTION (this << rnti << mi);
162  std::map <uint16_t, std::vector <HarqProcessInfoList_t> >::iterator it;
163  it = m_miUlHarqProcessesInfoMap.find (rnti);
164  if (it==m_miUlHarqProcessesInfoMap.end ())
165  {
166  // new entry
167  std::vector <HarqProcessInfoList_t> harqList;
168  harqList.resize (8);
170  el.m_mi = mi;
171  el.m_infoBits = infoBytes * 8;
172  el.m_codeBits = codeBytes * 8;
173  harqList.at (7).push_back (el);
174  m_miUlHarqProcessesInfoMap.insert (std::pair <uint16_t, std::vector <HarqProcessInfoList_t> > (rnti, harqList));
175  }
176  else
177  {
178  if ((*it).second.at (7).size () == 3) // MAX HARQ RETX
179  {
180  // HARQ should be disabled -> discard info
181  return;
182  }
184  el.m_mi = mi;
185  el.m_infoBits = infoBytes * 8;
186  el.m_codeBits = codeBytes * 8;
187  (*it).second.at (7).push_back (el);
188  }
189 }
190 
191 void
192 LteHarqPhy::ResetUlHarqProcessStatus (uint16_t rnti, uint8_t id)
193 {
194  NS_LOG_FUNCTION (this << rnti << (uint16_t)id);
195  std::map <uint16_t, std::vector <HarqProcessInfoList_t> >::iterator it;
196  it = m_miUlHarqProcessesInfoMap.find (rnti);
197  if (it==m_miUlHarqProcessesInfoMap.end ())
198  {
199  // new entry
200  std::vector <HarqProcessInfoList_t> harqList;
201  harqList.resize (8);
202  m_miUlHarqProcessesInfoMap.insert (std::pair <uint16_t, std::vector <HarqProcessInfoList_t> > (rnti, harqList));
203  }
204  else
205  {
206  (*it).second.at (id).clear ();
207  }
208 }
209 
210 
211 
212 
213 } // end namespace
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
HarqProcessInfoList_t GetHarqProcessInfoDl(uint8_t harqProcId, uint8_t layer)
Return the info of the HARQ procId in case of retranmissions for DL (asynchronous) ...
Definition: lte-harq-phy.cc:83
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
double GetAccumulatedMiDl(uint8_t harqProcId, uint8_t layer)
Return the cumulated MI of the HARQ procId in case of retranmissions for DL (asynchronous) ...
Definition: lte-harq-phy.cc:70
void UpdateUlHarqProcessStatus(uint16_t rnti, double mi, uint16_t infoBytes, uint16_t codeBytes)
Update the MI value associated to the decodification of an HARQ process for DL (asynchronous) ...
void UpdateDlHarqProcessStatus(uint8_t id, uint8_t layer, double mi, uint16_t infoBytes, uint16_t codeBytes)
Update the Info associated to the decodification of an HARQ process for DL (asynchronous) ...
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void ResetUlHarqProcessStatus(uint16_t rnti, uint8_t id)
Reset the info associated to the decodification of an HARQ process for DL (asynchronous) ...
double GetAccumulatedMiUl(uint16_t rnti)
Return the cumulated MI of the HARQ procId in case of retranmissions for UL (synchronous) ...
Definition: lte-harq-phy.cc:91
void ResetDlHarqProcessStatus(uint8_t id)
Reset the info associated to the decodification of an HARQ process for DL (asynchronous) ...
HarqProcessInfoList_t GetHarqProcessInfoUl(uint16_t rnti, uint8_t harqProcId)
Return the info of the HARQ procId in case of retranmissions for UL (asynchronous) ...