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/random-variable.h" |
|
22 #include "ns3/mobility-model.h" |
|
23 #include "ns3/double.h" |
|
24 |
|
25 namespace ns3 { |
|
26 |
|
27 NS_OBJECT_ENSURE_REGISTERED (PropagationDelayModel); |
|
28 |
|
29 TypeId |
|
30 PropagationDelayModel::GetTypeId (void) |
|
31 { |
|
32 static TypeId tid = TypeId ("ns3::PropagationDelayModel") |
|
33 .SetParent<Object> () |
|
34 ; |
|
35 return tid; |
|
36 } |
|
37 |
|
38 PropagationDelayModel::~PropagationDelayModel () |
|
39 {} |
|
40 |
|
41 NS_OBJECT_ENSURE_REGISTERED (RandomPropagationDelayModel); |
|
42 |
|
43 TypeId |
|
44 RandomPropagationDelayModel::GetTypeId (void) |
|
45 { |
|
46 static TypeId tid = TypeId ("ns3::RandomPropagationDelayModel") |
|
47 .SetParent<PropagationDelayModel> () |
|
48 .AddConstructor<RandomPropagationDelayModel> () |
|
49 .AddAttribute ("Variable", |
|
50 "The random variable which generates random delays (s).", |
|
51 RandomVariableValue (UniformVariable (0.0, 1.0)), |
|
52 MakeRandomVariableAccessor (&RandomPropagationDelayModel::m_variable), |
|
53 MakeRandomVariableChecker ()) |
|
54 ; |
|
55 return tid; |
|
56 } |
|
57 |
|
58 RandomPropagationDelayModel::RandomPropagationDelayModel () |
|
59 {} |
|
60 RandomPropagationDelayModel::~RandomPropagationDelayModel () |
|
61 {} |
|
62 Time |
|
63 RandomPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const |
|
64 { |
|
65 return Seconds (m_variable.GetValue ()); |
|
66 } |
|
67 |
|
68 NS_OBJECT_ENSURE_REGISTERED (ConstantSpeedPropagationDelayModel); |
|
69 |
|
70 TypeId |
|
71 ConstantSpeedPropagationDelayModel::GetTypeId (void) |
|
72 { |
|
73 static TypeId tid = TypeId ("ns3::ConstantSpeedPropagationDelayModel") |
|
74 .SetParent<PropagationDelayModel> () |
|
75 .AddConstructor<ConstantSpeedPropagationDelayModel> () |
|
76 .AddAttribute ("Speed", "The speed (m/s)", |
|
77 DoubleValue (300000000.0), |
|
78 MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed), |
|
79 MakeDoubleChecker<double> ()) |
|
80 ; |
|
81 return tid; |
|
82 } |
|
83 |
|
84 ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel () |
|
85 {} |
|
86 Time |
|
87 ConstantSpeedPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const |
|
88 { |
|
89 double distance = a->GetDistanceFrom (b); |
|
90 double seconds = distance / m_speed; |
|
91 return Seconds (seconds); |
|
92 } |
|
93 void |
|
94 ConstantSpeedPropagationDelayModel::SetSpeed (double speed) |
|
95 { |
|
96 m_speed = speed; |
|
97 } |
|
98 double |
|
99 ConstantSpeedPropagationDelayModel::GetSpeed (void) const |
|
100 { |
|
101 return m_speed; |
|
102 } |
|
103 |
|
104 } // namespace ns3 |
|