src/lte/model/lte-rlc-sequence-number.h
author Nicola Baldo <nbaldo@cttc.es>
Mon, 04 Feb 2013 18:47:25 +0100
changeset 9653 382d27da8905
parent 8707 3467d7d58a21
child 10769 2a65963e27ac
child 11319 6ea293901c3f
permissions -rw-r--r--
merged lena-dev with ns-3-dev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8572
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     2
/*
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     3
 * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     4
 *
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     8
 *
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    12
 * GNU General Public License for more details.
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    13
 *
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    17
 *
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    18
 * Author: Manuel Requena <manuel.requena@cttc.es>
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    19
 */
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    20
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    21
#ifndef LTE_RLC_SEQUENCE_NUMBER_H
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    22
#define LTE_RLC_SEQUENCE_NUMBER_H
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    23
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    24
#include <limits>
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    25
#include <iostream>
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    26
#include <stdint.h>
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    27
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    28
// #include "ns3/lte-rlc.h"
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    29
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    30
namespace ns3 {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    31
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    32
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    33
class SequenceNumber10
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    34
{
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    35
public:
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    36
  SequenceNumber10 ()
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    37
    : m_value (0),
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    38
      m_modulusBase (0)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    39
  {}
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    40
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    41
  explicit SequenceNumber10 (uint16_t value)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    42
    : m_value (value % 1024),
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    43
      m_modulusBase (0)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    44
  {}
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    45
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    46
  SequenceNumber10 (SequenceNumber10 const &value)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    47
    : m_value (value.m_value),
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    48
      m_modulusBase (value.m_modulusBase)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    49
  {}
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    50
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    51
  SequenceNumber10& operator= (uint16_t value)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    52
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    53
    m_value = value % 1024;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    54
    return *this;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    55
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    56
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    57
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    58
  /**
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    59
   * \brief Extracts the numeric value of the sequence number
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    60
   * \returns the sequence number value
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    61
   */
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    62
  uint16_t GetValue () const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    63
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    64
    return m_value;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    65
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    66
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    67
  void SetModulusBase (SequenceNumber10 modulusBase)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    68
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    69
    m_modulusBase = modulusBase.m_value;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    70
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    71
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    72
  void SetModulusBase (uint16_t modulusBase)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    73
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    74
    m_modulusBase = modulusBase;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    75
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    76
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    77
   // postfix ++
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    78
  SequenceNumber10 operator++ (int)
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    79
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    80
    SequenceNumber10 retval (m_value);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    81
    m_value = (m_value + 1) % 1024;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    82
    return retval;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    83
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    84
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    85
  SequenceNumber10 operator + (uint16_t delta) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    86
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    87
    SequenceNumber10 ret ((m_value + delta) % 1024);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    88
    ret.SetModulusBase (m_modulusBase);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    89
    return ret;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    90
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    91
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    92
  SequenceNumber10 operator - (uint16_t delta) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    93
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    94
    SequenceNumber10 ret ((m_value - delta) % 1024);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    95
    ret.SetModulusBase (m_modulusBase);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    96
    return ret;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    97
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    98
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
    99
  uint16_t operator - (const SequenceNumber10 &other) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   100
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   101
    uint16_t diff = m_value - other.m_value;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   102
    return (diff);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   103
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   104
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   105
  bool operator > (const SequenceNumber10 &other) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   106
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   107
    SequenceNumber10 v1 ((m_value - m_modulusBase) % 1024);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   108
    SequenceNumber10 v2 ((other.m_value - other.m_modulusBase) % 1024);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   109
    return ( v1.GetValue () > v2.GetValue () );
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   110
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   111
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   112
  bool operator == (const SequenceNumber10 &other) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   113
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   114
    return (m_value == other.m_value);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   115
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   116
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   117
  bool operator != (const SequenceNumber10 &other) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   118
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   119
    return (m_value != other.m_value);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   120
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   121
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   122
  bool operator <= (const SequenceNumber10 &other) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   123
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   124
    return (!this->operator> (other));
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   125
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   126
8611
e83faf79de19 Add new operator >= to SequenceNumber10
Manuel Requena <manuel.requena@cttc.es>
parents: 8572
diff changeset
   127
  bool operator >= (const SequenceNumber10 &other) const
e83faf79de19 Add new operator >= to SequenceNumber10
Manuel Requena <manuel.requena@cttc.es>
parents: 8572
diff changeset
   128
  {
e83faf79de19 Add new operator >= to SequenceNumber10
Manuel Requena <manuel.requena@cttc.es>
parents: 8572
diff changeset
   129
    return (this->operator> (other) || this->operator== (other));
e83faf79de19 Add new operator >= to SequenceNumber10
Manuel Requena <manuel.requena@cttc.es>
parents: 8572
diff changeset
   130
  }
e83faf79de19 Add new operator >= to SequenceNumber10
Manuel Requena <manuel.requena@cttc.es>
parents: 8572
diff changeset
   131
8572
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   132
  bool operator < (const SequenceNumber10 &other) const
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   133
  {
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   134
    return !this->operator> (other) && m_value != other.m_value;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   135
  }
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   136
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   137
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   138
  friend std::ostream & operator<< (std::ostream& os, const SequenceNumber10 &val);
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   139
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   140
private:
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   141
  uint16_t m_value;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   142
  uint16_t m_modulusBase;
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   143
};
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   144
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   145
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   146
} // namespace ns3
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   147
ada66b065cc2 Fix processing of the sequence number
Manuel Requena <manuel.requena@cttc.es>
parents:
diff changeset
   148
#endif // LTE_RLC_SEQUENCE_NUMBER_H