A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
propagation-delay-model.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include "propagation-delay-model.h"
21 #include "ns3/mobility-model.h"
22 #include "ns3/double.h"
23 #include "ns3/string.h"
24 #include "ns3/pointer.h"
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (PropagationDelayModel);
29 
30 TypeId
31 PropagationDelayModel::GetTypeId (void)
32 {
33  static TypeId tid = TypeId ("ns3::PropagationDelayModel")
34  .SetParent<Object> ()
35  ;
36  return tid;
37 }
38 
39 PropagationDelayModel::~PropagationDelayModel ()
40 {
41 }
42 
43 int64_t
45 {
46  return DoAssignStreams (stream);
47 }
48 
49 // ------------------------------------------------------------------------- //
50 
51 NS_OBJECT_ENSURE_REGISTERED (RandomPropagationDelayModel);
52 
53 TypeId
54 RandomPropagationDelayModel::GetTypeId (void)
55 {
56  static TypeId tid = TypeId ("ns3::RandomPropagationDelayModel")
58  .AddConstructor<RandomPropagationDelayModel> ()
59  .AddAttribute ("Variable",
60  "The random variable which generates random delays (s).",
61  StringValue ("ns3::UniformRandomVariable"),
62  MakePointerAccessor (&RandomPropagationDelayModel::m_variable),
63  MakePointerChecker<RandomVariableStream> ())
64  ;
65  return tid;
66 }
67 
69 {
70 }
71 RandomPropagationDelayModel::~RandomPropagationDelayModel ()
72 {
73 }
74 Time
76 {
77  return Seconds (m_variable->GetValue ());
78 }
79 
80 int64_t
82 {
83  m_variable->SetStream (stream);
84  return 1;
85 }
86 
87 NS_OBJECT_ENSURE_REGISTERED (ConstantSpeedPropagationDelayModel);
88 
89 TypeId
90 ConstantSpeedPropagationDelayModel::GetTypeId (void)
91 {
92  static TypeId tid = TypeId ("ns3::ConstantSpeedPropagationDelayModel")
94  .AddConstructor<ConstantSpeedPropagationDelayModel> ()
95  .AddAttribute ("Speed", "The speed (m/s)",
96  DoubleValue (300000000.0),
97  MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed),
98  MakeDoubleChecker<double> ())
99  ;
100  return tid;
101 }
102 
104 {
105 }
106 Time
108 {
109  double distance = a->GetDistanceFrom (b);
110  double seconds = distance / m_speed;
111  return Seconds (seconds);
112 }
113 void
115 {
116  m_speed = speed;
117 }
118 double
120 {
121  return m_speed;
122 }
123 
124 int64_t
126 {
127  return 0;
128 }
129 
130 
131 } // namespace ns3
keep track of time unit.
Definition: nstime.h:149
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
hold variables of type string
Definition: string.h:19
virtual Time GetDelay(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual Time GetDelay(Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
virtual int64_t DoAssignStreams(int64_t stream)=0
calculate a propagation delay.
the propagation speed is constant
int64_t AssignStreams(int64_t stream)
virtual int64_t DoAssignStreams(int64_t stream)
the propagation delay is random
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
virtual int64_t DoAssignStreams(int64_t stream)
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471