src/network/utils/error-model.cc
author Josh Pelkey <jpelkey@gatech.edu>
Fri, 13 May 2011 14:57:43 -0400
changeset 7182 5ecfee5d17de
parent 6823 a27f86fb4e55
child 7256 b04ba6772f8c
permissions -rw-r--r--
network coding style changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 University of Washington
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Tom Henderson <tomhend@u.washington.edu>
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 * This code has been ported from ns-2 (queue/errmodel.{cc,h}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
 */
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include <math.h>
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "error-model.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/packet.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "ns3/assert.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/log.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "ns3/random-variable.h"
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    30
#include "ns3/boolean.h"
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    31
#include "ns3/enum.h"
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    32
#include "ns3/double.h"
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("ErrorModel");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
namespace ns3 {
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    38
NS_OBJECT_ENSURE_REGISTERED (ErrorModel);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    40
TypeId ErrorModel::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    41
{ 
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    42
  static TypeId tid = TypeId ("ns3::ErrorModel")
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    43
    .SetParent<Object> ()
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    44
    .AddAttribute ("IsEnabled", "Whether this ErrorModel is enabled or not.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    45
                   BooleanValue (true),
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    46
                   MakeBooleanAccessor (&ErrorModel::m_enable),
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    47
                   MakeBooleanChecker ())
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
    48
  ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    49
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    50
}
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
ErrorModel::ErrorModel () :
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
  m_enable (true) 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    55
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
ErrorModel::~ErrorModel ()
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    60
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
bool
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
    64
ErrorModel::IsCorrupt (Ptr<Packet> p)
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    66
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  bool result;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  // Insert any pre-conditions here
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
  result = DoCorrupt (p);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
  // Insert any post-conditions here
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
  return result;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
void
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
ErrorModel::Reset (void)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    77
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
  DoReset ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
void
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
ErrorModel::Enable (void)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    84
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
  m_enable = true;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
void
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
ErrorModel::Disable (void)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    91
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
  m_enable = false;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
bool
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
ErrorModel::IsEnabled (void) const
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    98
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
  return m_enable;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
// RateErrorModel
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
   106
NS_OBJECT_ENSURE_REGISTERED (RateErrorModel);
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
   107
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   108
TypeId RateErrorModel::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   109
{ 
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
   110
  static TypeId tid = TypeId ("ns3::RateErrorModel")
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
   111
    .SetParent<ErrorModel> ()
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   112
    .AddConstructor<RateErrorModel> ()
2493
2cd8723ece97 use names closer to those used in the previous DefaultValues.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   113
    .AddAttribute ("ErrorUnit", "The error unit",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   114
                   EnumValue (EU_BYTE),
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   115
                   MakeEnumAccessor (&RateErrorModel::m_unit),
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   116
                   MakeEnumChecker (EU_BYTE, "EU_BYTE",
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   117
                                    EU_PKT, "EU_PKT",
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   118
                                    EU_BIT, "EU_BIT"))
2493
2cd8723ece97 use names closer to those used in the previous DefaultValues.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   119
    .AddAttribute ("ErrorRate", "The error rate.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   120
                   DoubleValue (0.0),
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   121
                   MakeDoubleAccessor (&RateErrorModel::m_rate),
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   122
                   MakeDoubleChecker<double> ())
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   123
    .AddAttribute ("RanVar", "The decision variable attached to this error model.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   124
                   RandomVariableValue (UniformVariable (0.0, 1.0)),
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   125
                   MakeRandomVariableAccessor (&RateErrorModel::m_ranvar),
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   126
                   MakeRandomVariableChecker ())
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   127
  ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   128
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   129
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   130
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   131
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   132
RateErrorModel::RateErrorModel ()
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   134
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
RateErrorModel::~RateErrorModel () 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   139
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
enum ErrorUnit 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
RateErrorModel::GetUnit (void) const 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   145
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  return m_unit; 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
void 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
RateErrorModel::SetUnit (enum ErrorUnit error_unit) 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   152
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
  m_unit = error_unit; 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
double
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
RateErrorModel::GetRate (void) const 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   159
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
  return m_rate; 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
void 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
RateErrorModel::SetRate (double rate)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   166
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  m_rate = rate;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
void 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
RateErrorModel::SetRandomVariable (const RandomVariable &ranvar)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   173
  NS_LOG_FUNCTION_NOARGS ();
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2254
diff changeset
   174
  m_ranvar = ranvar;
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
bool 
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   178
RateErrorModel::DoCorrupt (Ptr<Packet> p) 
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   180
  NS_LOG_FUNCTION_NOARGS ();
3371
e472358ea634 do not make m_enable protected
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   181
  if (!IsEnabled ())
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
    {
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   183
      return false;
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
    }
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
  switch (m_unit) 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
    {
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
    case EU_PKT:
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
      return DoCorruptPkt (p);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
    case EU_BYTE:
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
      return DoCorruptByte (p);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
    case EU_BIT:
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
      return DoCorruptBit (p);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
    default:
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
      NS_ASSERT_MSG (false, "m_unit not supported yet");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
      break;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
    }
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
  return false;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
bool
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   201
RateErrorModel::DoCorruptPkt (Ptr<Packet> p)
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   203
  NS_LOG_FUNCTION_NOARGS ();
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2254
diff changeset
   204
  return (m_ranvar.GetValue () < m_rate);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
bool
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   208
RateErrorModel::DoCorruptByte (Ptr<Packet> p)
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   210
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
  // compute pkt error rate, assume uniformly distributed byte error
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   212
  double per = 1 - pow (1.0 - m_rate, p->GetSize ());
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2254
diff changeset
   213
  return (m_ranvar.GetValue () < per);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
bool
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   217
RateErrorModel::DoCorruptBit(Ptr<Packet> p)
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   219
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
  // compute pkt error rate, assume uniformly distributed bit error
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   221
  double per = 1 - pow (1.0 - m_rate, (8 * p->GetSize ()) );
2383
a0e0ec096169 bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2254
diff changeset
   222
  return (m_ranvar.GetValue () < per);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
void 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
RateErrorModel::DoReset (void) 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   228
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
  /* re-initialize any state; no-op for now */ 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
// ListErrorModel
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
   236
NS_OBJECT_ENSURE_REGISTERED (ListErrorModel);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   238
TypeId ListErrorModel::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   239
{ 
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
   240
  static TypeId tid = TypeId ("ns3::ListErrorModel")
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
   241
    .SetParent<ErrorModel> ()
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
   242
    .AddConstructor<ListErrorModel> ()
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   243
  ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
   244
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   245
}
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   247
ListErrorModel::ListErrorModel ()
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   249
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
ListErrorModel::~ListErrorModel () 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   254
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
std::list<uint32_t> 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
ListErrorModel::GetList (void) const 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   260
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
  return m_packetList; 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
void 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
ListErrorModel::SetList (const std::list<uint32_t> &packetlist)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   267
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
  m_packetList = packetlist;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
// When performance becomes a concern, the list provided could be 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
// converted to a dynamically-sized array of uint32_t to avoid 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
// list iteration below.
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
bool 
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   275
ListErrorModel::DoCorrupt (Ptr<Packet> p) 
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   277
  NS_LOG_FUNCTION_NOARGS ();
3371
e472358ea634 do not make m_enable protected
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   278
  if (!IsEnabled ())
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
    {
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   280
      return false;
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
    }
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   282
  uint32_t uid = p->GetUid ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
  for (PacketListCI i = m_packetList.begin (); 
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   284
       i != m_packetList.end (); i++)
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
    {
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
      if (uid == *i)
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   287
        {
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   288
          return true;
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   289
        }
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
    }
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
  return false;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
void 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
ListErrorModel::DoReset (void) 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   297
  NS_LOG_FUNCTION_NOARGS ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
  m_packetList.clear();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
6288
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   301
//
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   302
// ReceiveListErrorModel
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   303
//
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   304
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   305
NS_OBJECT_ENSURE_REGISTERED (ReceiveListErrorModel);
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   306
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   307
TypeId ReceiveListErrorModel::GetTypeId (void)
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   308
{ 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   309
  static TypeId tid = TypeId ("ns3::ReceiveListErrorModel")
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   310
    .SetParent<ErrorModel> ()
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   311
    .AddConstructor<ReceiveListErrorModel> ()
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   312
  ;
6288
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   313
  return tid;
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   314
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   315
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   316
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   317
ReceiveListErrorModel::ReceiveListErrorModel () :
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   318
  m_timesInvoked (0)
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   319
{
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   320
  NS_LOG_FUNCTION_NOARGS ();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   321
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   322
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   323
ReceiveListErrorModel::~ReceiveListErrorModel () 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   324
{
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   325
  NS_LOG_FUNCTION_NOARGS ();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   326
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   327
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   328
std::list<uint32_t> 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   329
ReceiveListErrorModel::GetList (void) const 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   330
{ 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   331
  NS_LOG_FUNCTION_NOARGS ();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   332
  return m_packetList; 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   333
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   334
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   335
void 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   336
ReceiveListErrorModel::SetList (const std::list<uint32_t> &packetlist)
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   337
{ 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   338
  NS_LOG_FUNCTION_NOARGS ();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   339
  m_packetList = packetlist;
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   340
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   341
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   342
bool 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   343
ReceiveListErrorModel::DoCorrupt (Ptr<Packet> p) 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   344
{ 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   345
  NS_LOG_FUNCTION_NOARGS ();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   346
  if (!IsEnabled ())
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   347
    {
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   348
      return false;
6288
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   349
    }
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   350
  m_timesInvoked += 1;
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   351
  for (PacketListCI i = m_packetList.begin (); 
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   352
       i != m_packetList.end (); i++)
6288
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   353
    {
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   354
      if (m_timesInvoked - 1 == *i)
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   355
        {
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   356
          return true;
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   357
        }
6288
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   358
    }
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   359
  return false;
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   360
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   361
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   362
void 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   363
ReceiveListErrorModel::DoReset (void) 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   364
{ 
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   365
  NS_LOG_FUNCTION_NOARGS ();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   366
  m_packetList.clear();
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   367
}
1bc85b014aaf move receive-list-error-model to src/common/error-model
Josh Pelkey <jpelkey@gatech.edu>
parents: 3371
diff changeset
   368
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
} //namespace ns3