src/lte/model/lte-common.cc
author Marco Miozzo <marco.miozzo@cttc.es>
Thu, 08 Mar 2012 12:03:44 +0100
changeset 8674 2bd42ffd4fe8
parent 8580 69e6897f7bc9
child 8680 6f04863cf772
permissions -rw-r--r--
Introduce sanity checks on LteFfConverter::double2fpS11dot3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     2
/*
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     3
 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     4
 *
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     7
 * published by the Free Software Foundation;
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     8
 *
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    12
 * GNU General Public License for more details.
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    13
 *
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    17
 *
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    18
 * Author: Manuel Requena <manuel.requena@cttc.es>
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    19
 * Author: Marco Miozzo <marco.miozzo@cttc.es>
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    20
 */
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    21
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    22
#include "lte-common.h"
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    23
#include <ns3/log.h>
8580
69e6897f7bc9 array boundary checking in lte-common.cc
Nicola Baldo <nbaldo@cttc.es>
parents: 8435
diff changeset
    24
#include <ns3/abort.h>
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    25
8580
69e6897f7bc9 array boundary checking in lte-common.cc
Nicola Baldo <nbaldo@cttc.es>
parents: 8435
diff changeset
    26
NS_LOG_COMPONENT_DEFINE ("LteCommon");
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    27
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    28
namespace ns3 {
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    29
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    30
7971
3cc205853837 lteFlowId_t --> LteFlowId_t
Nicola Baldo <nbaldo@cttc.es>
parents: 7947
diff changeset
    31
LteFlowId_t::LteFlowId_t ()
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    32
{
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    33
}
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    34
7971
3cc205853837 lteFlowId_t --> LteFlowId_t
Nicola Baldo <nbaldo@cttc.es>
parents: 7947
diff changeset
    35
LteFlowId_t::LteFlowId_t (const uint16_t a, const uint8_t b)
8148
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    36
  : m_rnti (a),
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    37
    m_lcId (b)
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    38
{
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    39
}
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    40
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    41
bool
7971
3cc205853837 lteFlowId_t --> LteFlowId_t
Nicola Baldo <nbaldo@cttc.es>
parents: 7947
diff changeset
    42
operator == (const LteFlowId_t &a, const LteFlowId_t &b)
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    43
{
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    44
  return ( (a.m_rnti == b.m_rnti) && (a.m_lcId == b.m_lcId) );
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    45
}
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    46
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    47
bool
7971
3cc205853837 lteFlowId_t --> LteFlowId_t
Nicola Baldo <nbaldo@cttc.es>
parents: 7947
diff changeset
    48
operator < (const LteFlowId_t& a, const LteFlowId_t& b)
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    49
{
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    50
  return ( (a.m_rnti < b.m_rnti) || ( (a.m_rnti == b.m_rnti) && (a.m_lcId < b.m_lcId) ) );
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    51
}
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    52
8266
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    53
ImsiLcidPair_t::ImsiLcidPair_t ()
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    54
{
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    55
}
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    56
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    57
ImsiLcidPair_t::ImsiLcidPair_t (const uint64_t a, const uint8_t b)
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    58
  : m_imsi (a),
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    59
    m_lcId (b)
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    60
{
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    61
}
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    62
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    63
bool
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    64
operator == (const ImsiLcidPair_t &a, const ImsiLcidPair_t &b)
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    65
{
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    66
  return ((a.m_imsi == b.m_imsi) && (a.m_lcId == b.m_lcId));
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    67
}
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    68
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    69
bool
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    70
operator < (const ImsiLcidPair_t& a, const ImsiLcidPair_t& b)
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    71
{
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    72
  return ((a.m_imsi < b.m_imsi) || ((a.m_imsi == b.m_imsi) && (a.m_lcId
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    73
                                                               < b.m_lcId)));
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    74
}
3a30a2b5c94c Refactoring of the statistics classes to avoid continious calls to the attribute system.
jaumenin
parents: 8148
diff changeset
    75
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
    76
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    77
uint16_t
8148
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    78
LteFfConverter::double2fpS11dot3 (double val)
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    79
{
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    80
  // convert from double to fixed point notation Sxxxxxxxxxxx.xxx
8674
2bd42ffd4fe8 Introduce sanity checks on LteFfConverter::double2fpS11dot3
Marco Miozzo <marco.miozzo@cttc.es>
parents: 8580
diff changeset
    81
  // truncate val to notation limits
2bd42ffd4fe8 Introduce sanity checks on LteFfConverter::double2fpS11dot3
Marco Miozzo <marco.miozzo@cttc.es>
parents: 8580
diff changeset
    82
  if (val > 4095.88) val = 4095.88;
2bd42ffd4fe8 Introduce sanity checks on LteFfConverter::double2fpS11dot3
Marco Miozzo <marco.miozzo@cttc.es>
parents: 8580
diff changeset
    83
  if (val < -4096) val = -4096;
8148
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    84
  int16_t valFp = (int16_t)(val * pow (2, 3));
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    85
  return (valFp);
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    86
}
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    87
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    88
double
8148
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    89
LteFfConverter::fpS11dot3toDouble (uint16_t val)
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    90
{
8148
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    91
  // convert from fixed point notation Sxxxxxxxxxxx.xxx to double
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    92
  double valD = ((int16_t)val) / pow (2, 3);
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    93
  return (valD);
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    94
}
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    95
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    96
double 
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    97
LteFfConverter::getMinFpS11dot3Value ()
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
    98
{
8148
09e2d03022a2 run check-style on src/lte/model
Nicola Baldo <nbaldo@cttc.es>
parents: 7971
diff changeset
    99
  return (-4096);        // -4096 = 0x8000 = 1000 0000 0000 0000 b
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
   100
}
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
   101
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
   102
//static double g_lowestFpS11dot3Value = -4096; // 0x8001 (1000 0000 0000 0000)
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
   103
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
   104
8435
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   105
uint32_t BufferSizeLevelBsrTable[64] = {
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   106
  
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   107
  0, 10, 12, 14, 17, 19, 22, 26, 31, 36, 42, 49, 57, 67, 78, 91, 
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   108
  107, 125, 146, 171, 200, 234, 274, 321, 376, 440, 515, 603, 
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   109
  706, 826, 967, 1132, 1326, 1552, 1817, 2127, 2490, 2915, 3413,
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   110
  3995, 4677, 5476, 6411, 7505, 8787, 10287, 12043, 14099, 16507,
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   111
  19325, 22624, 26487, 31009, 36304, 42502, 49759, 58255,
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   112
  68201, 79846, 93749, 109439, 128125, 150000, 150000
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   113
  
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   114
};
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   115
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   116
uint32_t
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   117
BufferSizeLevelBsr::BsrId2BufferSize (uint8_t val)
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   118
{
8580
69e6897f7bc9 array boundary checking in lte-common.cc
Nicola Baldo <nbaldo@cttc.es>
parents: 8435
diff changeset
   119
  NS_ABORT_MSG_UNLESS (val >= 0 && val < 64, "val = " << val << " is out of range");
8435
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   120
  return BufferSizeLevelBsrTable[val];
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   121
}
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   122
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   123
uint8_t
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   124
BufferSizeLevelBsr::BufferSize2BsrId (uint32_t val)
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   125
{
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   126
  int index = 0;
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   127
  if (BufferSizeLevelBsrTable[63] < val)
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   128
    {
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   129
      index = 63;
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   130
    }
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   131
  else
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   132
    {
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   133
      while (BufferSizeLevelBsrTable[index] < val)
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   134
        {
8580
69e6897f7bc9 array boundary checking in lte-common.cc
Nicola Baldo <nbaldo@cttc.es>
parents: 8435
diff changeset
   135
          NS_ASSERT (index < 64);
8435
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   136
          index++;
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   137
        }
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   138
    }
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   139
    
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   140
  return (index);
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   141
}
6b0542a91970 Transmission queue head-of-line delay and queue size at MAC Scheduler
mmiozzo
parents: 8266
diff changeset
   142
7947
4ed7cfac199d PUSCH UL-CQ Integrated in PFS
mmiozzo
parents: 7938
diff changeset
   143
7938
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
   144
}; // namespace ns3
7c5f7e3b4054 add new file for lte common stuff
mrequena
parents:
diff changeset
   145