Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2009 CTTC | 3 * Copyright (c) 2009 CTTC |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Nicola Baldo <nbaldo@cttc.es> | 18 * Author: Nicola Baldo <nbaldo@cttc.es> |
19 */ | 19 */ |
20 | 20 |
21 #include <ns3/multi-model-spectrum-channel.h> | |
22 #include <ns3/object.h> | 21 #include <ns3/object.h> |
23 #include <ns3/simulator.h> | 22 #include <ns3/simulator.h> |
24 #include <ns3/log.h> | 23 #include <ns3/log.h> |
25 #include <ns3/packet.h> | 24 #include <ns3/packet.h> |
26 #include <ns3/net-device.h> | 25 #include <ns3/net-device.h> |
26 #include <ns3/node.h> | |
27 #include <ns3/mobility-model.h> | 27 #include <ns3/mobility-model.h> |
28 #include <ns3/spectrum-phy.h> | 28 #include <ns3/spectrum-phy.h> |
29 #include <ns3/spectrum-converter.h> | |
29 #include <iostream> | 30 #include <iostream> |
31 #include <utility> | |
32 #include "multi-model-spectrum-channel.h" | |
33 | |
30 | 34 |
31 NS_LOG_COMPONENT_DEFINE ("MultiModelSpectrumChannel"); | 35 NS_LOG_COMPONENT_DEFINE ("MultiModelSpectrumChannel"); |
32 | 36 |
Gary Pei
2010/04/02 21:25:25
I don't believe the test codes cover this MultiMod
Nicola Baldo
2010/05/21 15:08:44
there are test cases for SpectrumConverter in spec
| |
33 | 37 |
34 namespace ns3 { | 38 namespace ns3 { |
35 | 39 |
36 | 40 |
37 NS_OBJECT_ENSURE_REGISTERED (MultiModelSpectrumChannel); | 41 NS_OBJECT_ENSURE_REGISTERED (MultiModelSpectrumChannel); |
38 | 42 |
39 | 43 |
40 std::ostream& operator<< (std::ostream& lhs, SpectrumModelInfoMap& rhs) | 44 std::ostream& operator<< (std::ostream& lhs, TxSpectrumModelInfoMap_t& rhs) |
41 { | 45 { |
42 for (SpectrumModelInfoMap::iterator it = rhs.begin (); | 46 for (TxSpectrumModelInfoMap_t::iterator it = rhs.begin (); |
43 it != rhs.end (); | 47 it != rhs.end (); |
44 ++it) | 48 ++it) |
45 { | 49 { |
46 std::map<SpectrumModelUid_t, Ptr<SpectrumConverter> >::iterator jt; | 50 SpectrumConverterMap_t::iterator jt; |
47 for (jt = it->second.m_convertersToSpectrumModel.begin (); | 51 for (jt = it->second.m_spectrumConverterMap.begin (); |
48 jt != it->second.m_convertersToSpectrumModel.end (); | 52 jt != it->second.m_spectrumConverterMap.end (); |
49 ++jt) | 53 ++jt) |
50 { | 54 { |
51 lhs << "(" << it->first << "," << jt->first << ") "; | 55 lhs << "(" << it->first << "," << jt->first << ") "; |
52 } | 56 } |
53 } | 57 } |
54 return lhs; | 58 return lhs; |
55 } | 59 } |
56 | 60 |
57 | 61 TxSpectrumModelInfo::TxSpectrumModelInfo (Ptr<const SpectrumModel> txSpectrumMod el) |
58 | 62 : m_txSpectrumModel (txSpectrumModel) |
59 SpectrumModelInfo::SpectrumModelInfo (Ptr<const SpectrumModel> spectrumModel, Pt r<SpectrumPhy> phy) | 63 { |
60 : m_spectrumModel (spectrumModel) | 64 } |
61 { | 65 |
62 m_phyList.push_back (phy); | 66 |
63 } | 67 RxSpectrumModelInfo::RxSpectrumModelInfo (Ptr<const SpectrumModel> rxSpectrumMod el) |
68 : m_rxSpectrumModel (rxSpectrumModel) | |
69 { | |
70 } | |
71 | |
64 | 72 |
65 MultiModelSpectrumChannel::MultiModelSpectrumChannel () | 73 MultiModelSpectrumChannel::MultiModelSpectrumChannel () |
66 : m_PropagationDelay (0), | 74 : m_PropagationDelay (0), |
67 m_PropagationLoss (0) | 75 m_PropagationLoss (0) |
68 { | 76 { |
69 | 77 |
70 } | 78 } |
71 | 79 |
72 | 80 |
73 TypeId | 81 TypeId |
74 MultiModelSpectrumChannel::GetTypeId (void) | 82 MultiModelSpectrumChannel::GetTypeId (void) |
75 { | 83 { |
76 static TypeId tid = TypeId ("ns3::MultiModelSpectrumChannel") | 84 static TypeId tid = TypeId ("ns3::MultiModelSpectrumChannel") |
77 .SetParent<SpectrumChannel> () | 85 .SetParent<SpectrumChannel> () |
78 .AddConstructor<MultiModelSpectrumChannel> () | 86 .AddConstructor<MultiModelSpectrumChannel> () |
79 ; | 87 ; |
80 return tid; | 88 return tid; |
81 } | 89 } |
82 | 90 |
83 | 91 |
84 | 92 |
85 void | 93 void |
86 MultiModelSpectrumChannel::Add (Ptr<SpectrumPhy> phy) | 94 MultiModelSpectrumChannel::AddRx (Ptr<SpectrumPhy> phy) |
87 { | 95 { |
88 NS_LOG_FUNCTION (this << phy); | 96 NS_LOG_FUNCTION (this << phy); |
97 | |
98 Ptr<const SpectrumModel> rxSpectrumModel = phy->GetRxSpectrumModel (); | |
99 | |
100 NS_ASSERT_MSG ((0 != rxSpectrumModel), "phy->GetRxSpectrumModel () returned 0. Please check that the RxSpectrumModel is already set for the phy before calling MultiModelSpectrumChannel::AddRx (phy)"); | |
101 | |
102 SpectrumModelUid_t rxSpectrumModelUid = rxSpectrumModel->GetUid (); | |
103 ···· | |
89 std::vector<Ptr<SpectrumPhy> >::const_iterator it; | 104 std::vector<Ptr<SpectrumPhy> >::const_iterator it; |
90 | 105 |
91 // make sure this phy had not been already added | 106 // make sure this phy had not been already added |
92 for ( it = m_phyVector.begin (); it != m_phyVector.end (); ++it) | 107 for ( it = m_phyVector.begin (); it != m_phyVector.end (); ++it) |
93 { | 108 { |
94 NS_ASSERT (*it != phy); | 109 NS_ASSERT (*it != phy); |
95 } | 110 } |
96 m_phyVector.push_back (phy); | 111 m_phyVector.push_back (phy); |
97 } | 112 ···· |
98 | 113 RxSpectrumModelInfoMap_t::iterator rxInfoIterator = m_rxSpectrumModelInfoMap.f ind (rxSpectrumModelUid); |
99 void | 114 |
100 MultiModelSpectrumChannel::CheckAddSpectrumModel (Ptr<SpectrumPhy> phy, Ptr<cons t SpectrumModel> thisSpectrumModel) | 115 if (rxInfoIterator == m_rxSpectrumModelInfoMap.end ()) |
101 { | 116 { |
102 NS_LOG_FUNCTION (this << phy << thisSpectrumModel); | 117 // spectrum model unknown, add it to the list of RxSpectrumModels |
103 | 118 std::pair<RxSpectrumModelInfoMap_t::iterator, bool> ret; |
104 SpectrumModelUid_t thisSpectrumModelUid = thisSpectrumModel->GetUid (); | 119 ret = m_rxSpectrumModelInfoMap.insert (std::make_pair (rxSpectrumModelUid, RxSpectrumModelInfo (rxSpectrumModel)));············ |
105 | 120 NS_ASSERT (ret.second); |
106 SpectrumModelInfoMap::iterator it; | 121 // also add the phy to the newly created list of SpectrumPhy for this RxSp ectrumModel |
107 it = m_SpectrumModelInfoByUid.find (thisSpectrumModelUid); | 122 ret.first->second.m_rxPhyList.push_back (phy); |
108 | 123 ······ |
109 if (it != m_SpectrumModelInfoByUid.end ()) | 124 // and create the necessary converters for all the TX spectrum models that we know of |
110 { | 125 for (TxSpectrumModelInfoMap_t::iterator txInfoIterator = m_txSpectrumModel InfoMap.begin (); |
111 NS_LOG_LOGIC ("SpectrumModelUid " << thisSpectrumModelUid << " already pre sent"); | 126 txInfoIterator != m_txSpectrumModelInfoMap.end (); |
112 // we already have converters for this SpectrumModel | 127 ++txInfoIterator) |
113 // make sure this had not been added before | 128 { |
114 // WARNING this assertion probably is computationally intensive. | 129 Ptr<const SpectrumModel> txSpectrumModel = txInfoIterator->second.m_tx SpectrumModel; |
115 // NS_ASSERT(it->second.m_phyList.find (phy) == m_phyList.end ()); | 130 SpectrumModelUid_t txSpectrumModelUid = txSpectrumModel->GetUid (); |
116 it->second.m_phyList.push_back (phy); | 131 NS_LOG_LOGIC ("Creating converters between SpectrumModelUids " << txSp ectrumModelUid << " and " << rxSpectrumModelUid ); |
132 SpectrumConverter converter (txSpectrumModel, rxSpectrumModel); | |
133 std::pair<SpectrumConverterMap_t::iterator, bool> ret2; | |
134 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std::make _pair (rxSpectrumModelUid, converter));····················· | |
135 NS_ASSERT (ret2.second); | |
136 } | |
117 } | 137 } |
118 else | 138 else |
119 { | 139 { |
120 // new SpectrumModel | 140 // spectrum model is already known, just add the device to the correspondi ng list |
121 NS_LOG_LOGIC ("Adding SpectrumModelUid " << thisSpectrumModelUid ); | 141 rxInfoIterator->second.m_rxPhyList.push_back (phy); |
122 SpectrumModelInfo newFreqInfo (thisSpectrumModel, phy); | 142 } |
123 | 143 ·· |
124 for (it = m_SpectrumModelInfoByUid.begin (); | 144 } |
125 it != m_SpectrumModelInfoByUid.end (); | 145 |
126 ++it) | 146 |
127 { | 147 TxSpectrumModelInfoMap_t::const_iterator |
128 NS_LOG_LOGIC ("Creating converters between SpectrumModelUids " << this SpectrumModelUid << " and " << it->second.m_spectrumModel->GetUid () << " (" << it->first << ")"); | 148 MultiModelSpectrumChannel::FindAndEventuallyAddTxSpectrumModel (Ptr<const Spectr umModel> txSpectrumModel) |
129 Ptr<SpectrumConverter> converter; | 149 { |
130 | 150 NS_LOG_FUNCTION (this << txSpectrumModel); |
131 // create a converter from existing SpectrumModel to this SpectrumMode l | 151 SpectrumModelUid_t txSpectrumModelUid = txSpectrumModel->GetUid (); |
132 converter = Create<SpectrumConverter> (it->second.m_spectrumModel, thi sSpectrumModel); | 152 TxSpectrumModelInfoMap_t::iterator txInfoIterator = m_txSpectrumModelInfoMap.f ind (txSpectrumModelUid); |
133 it->second.m_convertersToSpectrumModel.insert (std::pair<SpectrumModel Uid_t, Ptr<SpectrumConverter> > (thisSpectrumModelUid, converter)); | 153 ·· |
134 NS_LOG_LOGIC ("converter map size: " << it->second.m_convertersToSpect rumModel.size ()); | 154 if (txInfoIterator == m_txSpectrumModelInfoMap.end ()) |
135 | 155 {····· |
136 // create a converter from this SpectrumModel to the existing Spectrum Model | 156 // first time we see this TX SpectrumModel |
137 converter = Create<SpectrumConverter> (thisSpectrumModel, it->second.m _spectrumModel); | 157 // we add it to the list |
138 newFreqInfo.m_convertersToSpectrumModel.insert (std::pair<SpectrumMode lUid_t, Ptr<SpectrumConverter> > (it->second.m_spectrumModel->GetUid (), convert er)); | 158 std::pair<TxSpectrumModelInfoMap_t::iterator, bool> ret; |
139 NS_LOG_LOGIC ("converter map size: " << newFreqInfo.m_convertersToSpec trumModel.size ()); | 159 ret = m_txSpectrumModelInfoMap.insert (std::make_pair (txSpectrumModelUid, TxSpectrumModelInfo (txSpectrumModel))); |
140 } | 160 NS_ASSERT (ret.second);· |
141 | 161 txInfoIterator = ret.first; |
142 m_SpectrumModelInfoByUid.insert (std::pair<SpectrumModelUid_t, SpectrumMod elInfo> (thisSpectrumModelUid, newFreqInfo)); | 162 ······ |
143 } | 163 // and we create the converters for all the RX SpectrumModels that we know of |
144 NS_LOG_LOGIC ("FreqInfoMap: " << m_SpectrumModelInfoByUid); | 164 for (RxSpectrumModelInfoMap_t::const_iterator rxInfoIterator = m_rxSpectru mModelInfoMap.begin (); |
145 } | 165 rxInfoIterator != m_rxSpectrumModelInfoMap.end (); |
146 | 166 ++rxInfoIterator) |
147 | 167 { |
148 void | 168 Ptr<const SpectrumModel> rxSpectrumModel = rxInfoIterator->second.m_rx SpectrumModel; |
149 MultiModelSpectrumChannel::StartTx (Ptr<const Packet> p, Ptr <SpectrumValue> ori ginalTxPowerSpectrum, SpectrumType st, Time duration, Ptr<SpectrumPhy> senderphy ) | 169 SpectrumModelUid_t rxSpectrumModelUid = rxSpectrumModel->GetUid (); |
150 { | 170 |
151 NS_LOG_FUNCTION (this << p << *originalTxPowerSpectrum << duration << senderph y); | 171 if (rxSpectrumModelUid != txSpectrumModelUid) |
152 | 172 { |
153 NS_ASSERT (senderphy); | 173 NS_LOG_LOGIC ("Creating converters between SpectrumModelUids " << txSpectrumModelUid << " and " << rxSpectrumModelUid ); |
174 | |
175 SpectrumConverter converter (txSpectrumModel, rxSpectrumModel); | |
176 std::pair<SpectrumConverterMap_t::iterator, bool> ret2; | |
177 ret2 = txInfoIterator->second.m_spectrumConverterMap.insert (std:: make_pair (rxSpectrumModelUid, converter));····················· | |
178 NS_ASSERT (ret2.second); | |
179 } | |
180 }················ | |
181 } | |
182 else | |
183 { | |
184 NS_LOG_LOGIC ("SpectrumModelUid " << txSpectrumModelUid << " already prese nt");····· | |
185 } | |
186 return txInfoIterator; | |
187 } | |
188 | |
189 | |
190 void | |
191 MultiModelSpectrumChannel::StartTx (Ptr<const Packet> p, Ptr <SpectrumValue> ori ginalTxPowerSpectrum, SpectrumType st, Time duration, Ptr<SpectrumPhy> txPhy) | |
192 { | |
193 NS_LOG_FUNCTION (this << p << *originalTxPowerSpectrum << duration << txPhy); | |
194 | |
195 NS_ASSERT (txPhy); | |
154 NS_ASSERT (originalTxPowerSpectrum); | 196 NS_ASSERT (originalTxPowerSpectrum); |
155 CheckAddSpectrumModel (senderphy, originalTxPowerSpectrum->GetSpectrumModel () ); | 197 ·· |
156 | 198 |
157 Ptr<MobilityModel> senderMobility = senderphy->GetMobility ()->GetObject<Mobil ityModel> (); | 199 Ptr<MobilityModel> txMobility = txPhy->GetMobility ()->GetObject<MobilityModel > (); |
158 SpectrumModelUid_t fromFreqUid = originalTxPowerSpectrum->GetSpectrumModelUid (); | 200 SpectrumModelUid_t txSpectrumModelUid = originalTxPowerSpectrum->GetSpectrumMo delUid (); |
159 NS_LOG_LOGIC (" fromSpectrumModelUid " << fromFreqUid); | 201 NS_LOG_LOGIC (" txSpectrumModelUid " << txSpectrumModelUid); |
160 | 202 |
161 SpectrumModelInfoMap::const_iterator it; | 203 // |
162 SpectrumModelInfoMap::const_iterator my = m_SpectrumModelInfoByUid.find (fromF reqUid); | 204 TxSpectrumModelInfoMap_t::const_iterator txInfoIteratorerator = FindAndEventua llyAddTxSpectrumModel (originalTxPowerSpectrum->GetSpectrumModel ()); |
163 NS_ASSERT (my != m_SpectrumModelInfoByUid.end ()); | 205 NS_ASSERT (txInfoIteratorerator != m_txSpectrumModelInfoMap.end ()); |
164 | 206 |
165 for (it = m_SpectrumModelInfoByUid.begin (); | 207 NS_LOG_LOGIC ("converter map for TX SpectrumModel with Uid " << txInfoIterator erator->first); |
166 it != m_SpectrumModelInfoByUid.end (); | 208 NS_LOG_LOGIC ("converter map size: " << txInfoIteratorerator->second.m_spectru mConverterMap.size ()); |
167 ++it) | 209 NS_LOG_LOGIC ("converter map first element: " << txInfoIteratorerator->second. m_spectrumConverterMap.begin ()->first); |
168 { | 210 |
169 SpectrumModelUid_t toFreqUid = it->second.m_spectrumModel->GetUid (); | 211 for (RxSpectrumModelInfoMap_t::const_iterator rxInfoIterator = m_rxSpectrumMod elInfoMap.begin (); |
170 NS_LOG_LOGIC (" toSpectrumModelUids " << toFreqUid); | 212 rxInfoIterator != m_rxSpectrumModelInfoMap.end (); |
171 | 213 ++rxInfoIterator) |
172 Ptr <SpectrumValue> txPowerSpectrum; | 214 { |
173 | 215 SpectrumModelUid_t rxSpectrumModelUid = rxInfoIterator->second.m_rxSpectru mModel->GetUid (); |
174 if (fromFreqUid == toFreqUid) | 216 NS_LOG_LOGIC (" rxSpectrumModelUids " << rxSpectrumModelUid); |
217 | |
218 Ptr <SpectrumValue> convertedTxPowerSpectrum; | |
219 | |
220 if (txSpectrumModelUid == rxSpectrumModelUid) | |
175 { | 221 { |
176 NS_LOG_LOGIC ("no conversion needed"); | 222 NS_LOG_LOGIC ("no conversion needed"); |
177 txPowerSpectrum = originalTxPowerSpectrum; | 223 convertedTxPowerSpectrum = originalTxPowerSpectrum; |
178 } | 224 } |
179 else | 225 else |
180 { | 226 { |
181 NS_LOG_LOGIC (" converting txPowerSpectrum SpectrumModelUids" << fromF reqUid | 227 NS_LOG_LOGIC (" converting txPowerSpectrum SpectrumModelUids" << txSpe ctrumModelUid << " --> " << rxSpectrumModelUid); |
182 << " --> " << toFreqUid); | 228 SpectrumConverterMap_t::const_iterator rxConverterIterator = txInfoIte ratorerator->second.m_spectrumConverterMap.find (rxSpectrumModelUid); |
183 | 229 NS_ASSERT (rxConverterIterator != txInfoIteratorerator->second.m_spect rumConverterMap.end ()); |
184 std::map<SpectrumModelUid_t, Ptr<SpectrumConverter> >::const_iterator convit; | 230 convertedTxPowerSpectrum = rxConverterIterator->second.Convert (origin alTxPowerSpectrum); |
185 | 231 } |
186 NS_LOG_LOGIC ("converter map from SpectrumModelUid: " << it->first); | 232 |
187 NS_LOG_LOGIC ("converter map size: " << it->second.m_convertersToSpect rumModel.size ()); | 233 std::list<Ptr<SpectrumPhy> >::const_iterator rxPhyIterator = rxInfoIterato r->second.m_rxPhyList.begin (); |
188 NS_LOG_LOGIC ("converter map first element: " << it->second.m_converte rsToSpectrumModel.begin ()->first); | 234 while (rxPhyIterator != rxInfoIterator->second.m_rxPhyList.end ()) |
189 | 235 { |
190 convit = my->second.m_convertersToSpectrumModel.find (toFreqUid); | 236 NS_ASSERT_MSG ((*rxPhyIterator)->GetRxSpectrumModel ()->GetUid () == r xSpectrumModelUid, |
191 NS_ASSERT (convit != my->second.m_convertersToSpectrumModel.end ()); | 237 "MultiModelSpectrumChannel only supports devices that u se a single RxSpectrumModel that does not change for the whole simulation"); |
192 Ptr<SpectrumConverter> converter = convit->second; | 238 ·········· |
193 txPowerSpectrum = converter->Convert (originalTxPowerSpectrum); | 239 if ((*rxPhyIterator) != txPhy) |
194 } | |
195 | |
196 std::list<Ptr<SpectrumPhy> >::const_iterator recvphyit = it->second.m_phyL ist.begin (); | |
197 while (recvphyit != it->second.m_phyList.end ()) | |
198 { | |
199 if ((*recvphyit) != senderphy) | |
200 { | 240 { |
201 Ptr <SpectrumValue> rxPowerSpectrum; | 241 Ptr <SpectrumValue> rxPowerSpectrum; |
202 Time delay; | 242 Time delay; |
203 Ptr<MobilityModel> receiverMobility = (*recvphyit)->GetMobility () ->GetObject<MobilityModel> (); | 243 Ptr<MobilityModel> receiverMobility = (*rxPhyIterator)->GetMobilit y ()->GetObject<MobilityModel> (); |
204 | 244 |
205 if (senderMobility && receiverMobility) | 245 if (txMobility && receiverMobility) |
206 { | 246 { |
207 | |
208 | |
209 if (m_PropagationLoss) | 247 if (m_PropagationLoss) |
210 { | 248 { |
211 rxPowerSpectrum = m_PropagationLoss->CalcRxPowerSpectralDe nsity (txPowerSpectrum, senderMobility, receiverMobility); | 249 rxPowerSpectrum = m_PropagationLoss->CalcRxPowerSpectralDe nsity (convertedTxPowerSpectrum, txMobility, receiverMobility); |
212 } | 250 } |
213 else | 251 else |
214 { | 252 { |
215 // rxPowerSpectrum = Copy<SpectrumValue> (txPowerSpectrum) ; | 253 // rxPowerSpectrum = Copy<SpectrumValue> (convertedTxPower Spectrum); |
216 rxPowerSpectrum = txPowerSpectrum->Copy (); | 254 rxPowerSpectrum = convertedTxPowerSpectrum->Copy (); |
217 } | 255 } |
218 | 256 |
219 if (m_PropagationDelay) | 257 if (m_PropagationDelay) |
220 { | 258 { |
221 delay = m_PropagationDelay->GetDelay (senderMobility, rece iverMobility); | 259 delay = m_PropagationDelay->GetDelay (txMobility, receiver Mobility); |
222 } | 260 } |
223 else | 261 else |
224 { | 262 { |
225 delay = MicroSeconds (0); | 263 delay = MicroSeconds (0); |
226 } | 264 } |
227 } | 265 } |
228 else | 266 else |
229 { | 267 { |
230 // rxPowerSpectrum = Copy<SpectrumValue> (txPowerSpectrum); | 268 // rxPowerSpectrum = Copy<SpectrumValue> (convertedTxPowerSpec trum); |
231 rxPowerSpectrum = txPowerSpectrum->Copy (); | 269 rxPowerSpectrum = convertedTxPowerSpectrum->Copy (); |
232 delay = MicroSeconds (0); | 270 delay = MicroSeconds (0); |
233 } | 271 } |
234 | 272 |
235 Ptr<Packet> copy = p->Copy (); | 273 Ptr<Packet> pktCopy = p->Copy (); |
236 | 274 Ptr<Object> netDevObj = (*rxPhyIterator)->GetDevice (); |
237 if (delay.IsPositive ()) | 275 if (netDevObj) |
238 { | 276 { |
239 Simulator::Schedule (delay, &MultiModelSpectrumChannel::StartR x, this, | 277 // the receiver has a NetDevice, so we expect that it is attac hed to a Node |
240 copy, rxPowerSpectrum, st, duration, *rec vphyit); | 278 uint32_t dstNode = netDevObj->GetObject<NetDevice> ()->GetNod e ()->GetId (); |
279 Simulator::ScheduleWithContext (dstNode, delay, &MultiModelSpe ctrumChannel::StartRx, this, | |
280 pktCopy, rxPowerSpectrum, st, duration, *rxPhyIterator); | |
241 } | 281 } |
242 else | 282 else |
243 { | 283 { |
244 Simulator::ScheduleNow (&MultiModelSpectrumChannel::StartRx, t his, | 284 // the receiver is not attached to a NetDevice, so we cannot a ssume that it is attached to a node |
245 copy, rxPowerSpectrum, st, duration, * recvphyit); | 285 Simulator::Schedule (delay, &MultiModelSpectrumChannel::StartR x, this, |
286 pktCopy, rxPowerSpectrum, st, duration, * rxPhyIterator); | |
246 } | 287 } |
247 | 288 }········· |
248 } | 289 ++rxPhyIterator; |
249 else // ((*recvphyit) == senderphy) | |
250 { | |
251 // Sanity check. We want to make sure that the spectrum | |
252 // model which was passed to Add() is (still) the same used by the sender. | |
253 NS_ASSERT (toFreqUid == fromFreqUid); | |
254 } | |
255 ++recvphyit; | |
256 } | 290 } |
257 | 291 |
258 } | 292 } |
259 | 293 |
260 } | 294 } |
261 | 295 |
262 void | 296 void |
263 MultiModelSpectrumChannel::StartRx (Ptr<Packet> p, Ptr <SpectrumValue> rxPsd, Sp ectrumType st, Time duration, Ptr<SpectrumPhy> receiver) | 297 MultiModelSpectrumChannel::StartRx (Ptr<Packet> p, Ptr <SpectrumValue> rxPsd, Sp ectrumType st, Time duration, Ptr<SpectrumPhy> receiver) |
264 { | 298 { |
265 NS_LOG_FUNCTION (this); | 299 NS_LOG_FUNCTION (this); |
(...skipping 26 matching lines...) Expand all Loading... | |
292 } | 326 } |
293 | 327 |
294 void | 328 void |
295 MultiModelSpectrumChannel::SetPropagationDelayModel (Ptr<PropagationDelayModel> delay) | 329 MultiModelSpectrumChannel::SetPropagationDelayModel (Ptr<PropagationDelayModel> delay) |
296 { | 330 { |
297 NS_ASSERT (m_PropagationDelay == 0); | 331 NS_ASSERT (m_PropagationDelay == 0); |
298 m_PropagationDelay = delay; | 332 m_PropagationDelay = delay; |
299 } | 333 } |
300 | 334 |
301 | 335 |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | |
308 | |
309 | |
310 } // namespace ns3 | 336 } // namespace ns3 |
LEFT | RIGHT |