src/devices/wifi/propagation-delay-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 19 Mar 2008 15:30:18 -0700
changeset 2625 90ba95050923
parent 2561 fb49fd82cbfd
child 2940 8fb456039670
permissions -rw-r--r--
fix typename
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2034
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     2
/*
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     3
 * Copyright (c) 2005,2006,2007 INRIA
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     4
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as 
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     7
 * published by the Free Software Foundation;
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     8
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    12
 * GNU General Public License for more details.
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    13
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    14
 * You should have received a copy of the GNU General Public License
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    15
 * along with this program; if not, write to the Free Software
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    17
 *
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8664ab76ff85 add missing headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2031
diff changeset
    19
 */
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "propagation-delay-model.h"
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "ns3/random-variable.h"
2031
567dbc2475fc replace distance by a pair of mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1958
diff changeset
    22
#include "ns3/mobility-model.h"
2549
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    23
#include "ns3/double.h"
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
namespace ns3 {
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
PropagationDelayModel::~PropagationDelayModel ()
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
{}
2549
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    29
2625
90ba95050923 fix typename
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2561
diff changeset
    30
NS_OBJECT_ENSURE_REGISTERED (RandomPropagationDelayModel);
90ba95050923 fix typename
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2561
diff changeset
    31
2549
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    32
TypeId 
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    33
RandomPropagationDelayModel::GetTypeId (void)
1957
9ce0828c6a19 add default value support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1882
diff changeset
    34
{
2625
90ba95050923 fix typename
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2561
diff changeset
    35
  static TypeId tid = TypeId ("ns3::RandomPropagationDelayModel")
2549
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    36
    .SetParent<PropagationDelayModel> ()
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    37
    .AddConstructor<RandomPropagationDelayModel> ()
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    38
    .AddAttribute ("Variable",
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    39
                   "The random variable which generates random delays (s).",
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    40
                   UniformVariable (0.0, 1.0),
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    41
                   MakeRandomVariableAccessor (&RandomPropagationDelayModel::m_variable),
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    42
                   MakeRandomVariableChecker ())
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    43
    ;
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    44
  return tid;
1957
9ce0828c6a19 add default value support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1882
diff changeset
    45
}
9ce0828c6a19 add default value support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1882
diff changeset
    46
9ce0828c6a19 add default value support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1882
diff changeset
    47
RandomPropagationDelayModel::RandomPropagationDelayModel ()
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
{}
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
RandomPropagationDelayModel::~RandomPropagationDelayModel ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    50
{}
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
Time 
2031
567dbc2475fc replace distance by a pair of mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1958
diff changeset
    52
RandomPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    54
  return Seconds (m_variable.GetValue ());
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
}
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
2625
90ba95050923 fix typename
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2561
diff changeset
    57
NS_OBJECT_ENSURE_REGISTERED (ConstantSpeedPropagationDelayModel);
90ba95050923 fix typename
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2561
diff changeset
    58
2549
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    59
TypeId
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    60
ConstantSpeedPropagationDelayModel::GetTypeId (void)
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    61
{
2625
90ba95050923 fix typename
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2561
diff changeset
    62
  static TypeId tid = TypeId ("ns3::ConstantSpeedPropagationDelayModel")
2561
fb49fd82cbfd avoid infinite loop.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2549
diff changeset
    63
    .SetParent<PropagationDelayModel> ()
fb49fd82cbfd avoid infinite loop.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2549
diff changeset
    64
    .AddConstructor<ConstantSpeedPropagationDelayModel> ()
2549
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    65
    .AddAttribute ("Speed", "The speed (m/s)",
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    66
                   Double (300000000.0),
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    67
                   MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed),
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    68
                   MakeDoubleChecker<double> ())
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    69
    ;
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    70
  return tid;
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    71
}
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    72
fe90cf0b2c63 port propagation models and channel to attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    73
ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel ()
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
{}
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
Time 
2031
567dbc2475fc replace distance by a pair of mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1958
diff changeset
    76
ConstantSpeedPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
{
2031
567dbc2475fc replace distance by a pair of mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1958
diff changeset
    78
  double distance = a->GetDistanceFrom (b);
1882
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
  double seconds = distance / m_speed;
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
  return Seconds (seconds);
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
}
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
void 
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
ConstantSpeedPropagationDelayModel::SetSpeed (double speed)
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
{
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
  m_speed = speed;
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
}
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
double 
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
ConstantSpeedPropagationDelayModel::GetSpeed (void) const
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
{
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
  return m_speed;
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
}
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
061f7f7f9992 start of work towards port of wifi code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
} // namespace ns3