Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2009 University of Washington | |
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 as published by | |
7 * the Free Software Foundation, either version 3 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 * | |
18 * Author: Leonard Tracy <lentracy@u.washington.edu> | |
19 * | |
20 * | |
21 */ | |
22 | |
23 #include "ns3/object.h" | |
24 #include "ns3/packet.h" | |
25 #include "ns3/simulator.h" | |
26 #include "ns3/mobility-model.h" | |
27 #include "ns3/net-device.h" | |
28 #include "ns3/node.h" | |
29 #include "ns3/log.h" | |
30 #include "ns3/pointer.h" | |
31 #include "ns3/log.h" | |
32 | |
33 #include "uan-channel.h" | |
34 #include "uan-phy.h" | |
35 #include "uan-prop-model.h" | |
36 #include "uan-tx-mode.h" | |
37 #include "uan-net-device.h" | |
38 #include "uan-transducer.h" | |
39 #include "uan-noise-model-default.h" | |
40 #include "uan-prop-model-ideal.h" | |
41 | |
42 NS_LOG_COMPONENT_DEFINE("UanChannel"); | |
43 namespace ns3 | |
44 { | |
45 | |
46 NS_OBJECT_ENSURE_REGISTERED( UanChannel); | |
47 | |
48 TypeId | |
49 UanChannel::GetTypeId () | |
50 { | |
51 static TypeId tid = | |
52 TypeId ("ns3::UanChannel") | |
53 .SetParent<Channel> () | |
54 .AddConstructor<UanChannel> () | |
55 .AddAttribute ("PropagationModel", | |
56 "A pointer to the propagation model.", | |
57 PointerValue (CreateObject<UanPropModelIdeal> ()), | |
58 MakePointerAccessor (&UanChannel::m_prop), | |
59 MakePointerChecker<UanPropagationModel> ()) | |
60 .AddAttribute ("NoiseModel", | |
61 "A pointer to the model of the channel ambient noise.", | |
62 PointerValue (CreateObject<UanNoiseModelDefault> ()), | |
63 MakePointerAccessor (&UanChannel::m_noise), | |
64 MakePointerChecker<UanNoiseModel> ()) | |
65 ; | |
66 | |
67 return tid; | |
68 } | |
69 | |
70 UanChannel::UanChannel () : | |
craigdo1
2009/07/11 00:10:52
Not sure if actually in coding std, but ':' typica
| |
71 m_prop (0) | |
craigdo1
2009/07/11 00:10:52
m_prop is zeroed. Why not m_noise?
| |
72 { | |
73 } | |
74 | |
75 UanChannel::~UanChannel () | |
76 { | |
craigdo1
2009/07/11 00:10:52
m_prop and m_noise are Ptr<> ... where are they re
Andrey Mazo
2009/11/15 13:32:11
It's a part of another discussion (bug 721).
| |
77 } | |
78 void | |
79 UanChannel::DoDispose () | |
80 { | |
81 UanDeviceList::iterator it = m_devList.begin (); | |
82 for(; it != m_devList.end (); it++) | |
83 { | |
84 it->first = 0; | |
85 it->second = 0; | |
86 } | |
87 m_devList.clear (); | |
88 Channel::DoDispose (); | |
89 } | |
90 void | |
91 UanChannel::SetPropagationModel (Ptr<UanPropagationModel> prop) | |
92 { | |
93 NS_LOG_DEBUG ("Set Prop Model " << this); | |
94 m_prop = prop; | |
95 } | |
96 | |
97 uint32_t | |
98 UanChannel::GetNDevices () const | |
99 { | |
100 return m_devList.size (); | |
101 } | |
102 | |
103 Ptr<NetDevice> | |
104 UanChannel::GetDevice (uint32_t i) const | |
105 { | |
106 return m_devList[i].first; | |
107 } | |
108 | |
109 void | |
110 UanChannel::AddDevice (Ptr<UanNetDevice> dev, Ptr<UanTransducer> trans) | |
111 { | |
112 NS_LOG_DEBUG ("Adding dev/trans pair number " << m_devList.size ()); | |
113 m_devList.push_back (std::make_pair (dev, trans)); | |
114 } | |
115 | |
116 void | |
117 UanChannel::TxPacket (Ptr<UanTransducer> src, Ptr<Packet> packet, | |
118 double txPowerDb, UanTxMode txMode) | |
119 { | |
120 Ptr<MobilityModel> senderMobility = 0; | |
121 | |
122 NS_LOG_DEBUG ("Channel scheduling"); | |
123 for (UanDeviceList::const_iterator i = m_devList.begin (); i | |
124 != m_devList.end (); i++) | |
125 { | |
126 | |
127 if (src == i->second) | |
128 { | |
129 senderMobility = i->first->GetNode ()->GetObject<MobilityModel> (); | |
130 break; | |
131 } | |
132 } | |
133 NS_ASSERT (senderMobility != 0); | |
134 int j = 0; | |
Andrey Mazo
2009/11/15 13:32:11
Should be uint32_t, as SendUp (uint32_t, Ptr<Packe
| |
135 UanDeviceList::const_iterator i = m_devList.begin (); | |
136 for (; i != m_devList.end (); i++) | |
137 { | |
138 if (src != i->second) | |
139 { | |
140 NS_LOG_DEBUG ("Scheduling " << i->first->GetMac ()->GetAddress ()); | |
141 Ptr<MobilityModel> rcvrMobility = i->first->GetNode ()->GetObject<Mobi lityModel> (); | |
142 Time delay = m_prop->GetDelay (senderMobility, rcvrMobility, txMode); | |
143 UanPdp pdp = m_prop->GetPdp (senderMobility, rcvrMobility, txMode); | |
144 double rxPowerDb = txPowerDb + m_prop->GetPathLossDb (senderMobility, | |
145 rcvrMobility, | |
146 txMode); | |
147 | |
148 NS_LOG_DEBUG ("txPowerDb=" << txPowerDb << "dB, rxPowerDb=" | |
149 << rxPowerDb << "distance=" | |
150 << senderMobility->GetDistanceFrom (rcvrMobility) | |
151 << "m, delay=" << delay); | |
152 | |
153 Ptr<Packet> copy = packet->Copy (); | |
154 Simulator::Schedule (delay, | |
155 &UanChannel::SendUp, | |
156 this, | |
157 j, | |
158 copy, | |
159 rxPowerDb, | |
160 txMode, | |
161 pdp); | |
162 } | |
163 j++; | |
164 } | |
165 } | |
166 | |
167 void | |
168 UanChannel::SetNoiseModel (Ptr<UanNoiseModel> noise) | |
169 { | |
170 NS_ASSERT (noise); | |
171 m_noise = noise; | |
172 NS_LOG_DEBUG ("Noise test: " << m_noise->GetNoiseDbHz (22) << std::endl); | |
173 | |
174 } | |
175 void | |
176 UanChannel::SendUp (uint32_t i, Ptr<Packet> packet, double rxPowerDb, | |
177 UanTxMode txMode, UanPdp pdp) | |
178 { | |
179 NS_LOG_DEBUG ("Channel: In sendup"); | |
180 m_devList[i].second->Receive (packet, rxPowerDb, txMode, pdp); | |
181 } | |
182 | |
183 double | |
184 UanChannel::GetNoiseDbHz (double fKhz) | |
185 { | |
186 NS_ASSERT (m_noise); | |
187 double noise = m_noise->GetNoiseDbHz (fKhz); | |
188 return noise; | |
189 } | |
190 | |
191 } // namespace ns3 | |
OLD | NEW |