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) 2007 Emmanuelle Laprise | 3 * Copyright (c) 2007 Emmanuelle Laprise |
4 * Copyright (c) 2011 University of Rijeka | |
5 * | 4 * |
6 * 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 |
7 * 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 |
8 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
9 * | 8 * |
10 * 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, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
14 * | 13 * |
15 * 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 |
16 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
17 * 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 |
18 * | 17 * |
19 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> | 18 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> |
20 * Vedran Miletić <rivanvx@gmail.com> | 19 * Vedran Miletić <rivanvx@gmail.com> |
21 */ | 20 */ |
22 | 21 |
23 #include <cmath> | |
24 | |
25 #include "csma-channel.h" | 22 #include "csma-channel.h" |
26 #include "csma-net-device.h" | 23 #include "csma-net-device.h" |
27 #include "ns3/boolean.h" | |
28 #include "ns3/double.h" | |
29 #include "ns3/log.h" | |
30 #include "ns3/packet.h" | 24 #include "ns3/packet.h" |
31 #include "ns3/simulator.h" | 25 #include "ns3/simulator.h" |
26 #include "ns3/log.h" | |
27 #include "ns3/double.h" | |
32 | 28 |
33 NS_LOG_COMPONENT_DEFINE ("CsmaChannel"); | 29 NS_LOG_COMPONENT_DEFINE ("CsmaChannel"); |
34 | 30 |
35 namespace ns3 { | 31 namespace ns3 { |
36 | |
37 NS_OBJECT_ENSURE_REGISTERED (CsmaNetDeviceRecord); | |
38 | |
39 TypeId | |
40 CsmaNetDeviceRecord::GetTypeId (void) | |
41 { | |
42 static TypeId tid = TypeId ("ns3::CsmaNetDeviceRecord") | |
43 .SetParent<Object> () | |
44 .AddConstructor<CsmaNetDeviceRecord> () | |
45 .AddAttribute ("Position", "Position on the wire, value between 0.0 and 1.0" , | |
46 DoubleValue (0.0), | |
47 MakeDoubleAccessor (&CsmaNetDeviceRecord::m_position), | |
48 MakeDoubleChecker<double> ()) | |
49 ; | |
50 return tid; | |
51 } | |
52 | |
53 CsmaNetDeviceRecord::CsmaNetDeviceRecord () | |
54 : | |
55 m_devicePtr (0), | |
56 m_active (false) | |
57 { | |
58 NS_LOG_FUNCTION_NOARGS (); | |
59 //NS_LOG_LOGIC ("VEDRANM ovo se dogodi i to nije ocekivano."); // SADA IPAK JE :D | |
60 } | |
61 | |
62 /* | |
63 // ns-3 sustav atributa postavlja vrijednosti _nakon_ cijelog konstruktora | |
64 CsmaNetDeviceRecord::CsmaNetDeviceRecord (Ptr<CsmaNetDevice> device, double posi tion) | |
65 : | |
66 m_devicePtr (device), | |
67 m_position (position), | |
68 m_active (true) | |
69 { | |
70 NS_LOG_FUNCTION_NOARGS (); | |
71 NS_LOG_LOGIC ("VEDRANM ovo se dogodi " m_devicePtr << " " << device " " << pos ition); | |
72 NS_LOG_LOGIC (m_active); | |
73 NS_LOG_LOGIC ("KRAJ"); | |
74 } | |
75 */ | |
76 | |
77 CsmaNetDeviceRecord::~CsmaNetDeviceRecord () | |
78 { | |
79 } | |
80 | |
81 bool | |
82 CsmaNetDeviceRecord::IsActive (void) | |
83 { | |
84 return m_active; | |
85 } | |
86 | |
87 void | |
88 CsmaNetDeviceRecord::SetActive (void) | |
89 { | |
90 m_active = true; | |
91 } | |
92 | |
93 void | |
94 CsmaNetDeviceRecord::SetInActive (void) | |
95 { | |
96 m_active = false; | |
97 } | |
98 | |
99 void | |
100 CsmaNetDeviceRecord::SetPosition (double position) | |
101 { | |
102 NS_LOG_FUNCTION (position); | |
103 | |
104 m_position = position; | |
105 | |
106 NS_LOG_LOGIC ("m_position = " << position); | |
107 } | |
108 | |
109 double | |
110 CsmaNetDeviceRecord::GetPosition (void) | |
111 { | |
112 NS_LOG_FUNCTION_NOARGS (); | |
113 | |
114 return m_position; | |
115 } | |
116 | |
117 | 32 |
118 NS_OBJECT_ENSURE_REGISTERED (CsmaChannel); | 33 NS_OBJECT_ENSURE_REGISTERED (CsmaChannel); |
119 | 34 |
120 TypeId | 35 TypeId |
121 CsmaChannel::GetTypeId (void) | 36 CsmaChannel::GetTypeId (void) |
122 { | 37 { |
123 static TypeId tid = TypeId ("ns3::CsmaChannel") | 38 static TypeId tid = TypeId ("ns3::CsmaChannel") |
124 .SetParent<Channel> () | 39 .SetParent<Channel> () |
125 .AddConstructor<CsmaChannel> () | 40 .AddConstructor<CsmaChannel> () |
126 .AddAttribute ("DataRate",· | 41 .AddAttribute ("DataRate",· |
127 "The transmission data rate to be provided to devices connect ed to the channel", | 42 "The transmission data rate to be provided to devices connect ed to the channel", |
128 DataRateValue (DataRate (0xffffffff)), | 43 DataRateValue (DataRate (0xffffffff)), |
129 MakeDataRateAccessor (&CsmaChannel::m_bps), | 44 MakeDataRateAccessor (&CsmaChannel::m_bps), |
130 MakeDataRateChecker ()) | 45 MakeDataRateChecker ()) |
131 .AddAttribute ("Delay", "Propagation delay through the entire length of the channel", | 46 .AddAttribute ("Delay", "Transmission delay through the channel", |
132 TimeValue (Seconds (0)), | 47 TimeValue (Seconds (0)), |
133 MakeTimeAccessor (&CsmaChannel::m_delay), | 48 MakeTimeAccessor (&CsmaChannel::m_delay), |
134 MakeTimeChecker ()) | 49 MakeTimeChecker ()) |
135 .AddAttribute ("PositioningEnabled", "Is device positioning on the wire enab led", | 50 .AddAttribute ("Length", "Physical length of the wire", |
136 BooleanValue (false), | 51 » » DoubleValue (0.0), |
137 MakeBooleanAccessor (&CsmaChannel::m_positioningEnabled), | 52 » » MakeDoubleAccessor (&CsmaChannel::m_length), |
138 MakeBooleanChecker ()) | 53 » » MakeDoubleChecker<double> ()) |
139 /* .AddAttribute ("Length", "Physical length of the wire", | |
140 DoubleValue (0.0), | |
141 MakeDoubleAccessor (&CsmaChannel::m_length), | |
142 MakeDoubleChecker<double> ()) | |
143 */ | |
144 | |
145 | |
146 ; | 54 ; |
147 return tid; | 55 return tid; |
148 } | 56 } |
149 | 57 |
150 CsmaChannel::CsmaChannel () | 58 CsmaChannel::CsmaChannel () |
151 : | 59 : |
152 Channel () | 60 Channel () |
153 /* m_state (CH_IDLE) | |
154 m_state*/ | |
155 { | 61 { |
156 NS_LOG_FUNCTION_NOARGS (); | 62 NS_LOG_FUNCTION_NOARGS (); |
63 m_state = IDLE; | |
157 m_deviceList.clear (); | 64 m_deviceList.clear (); |
158 } | 65 } |
159 | 66 |
67 CsmaChannel::~CsmaChannel () | |
68 { | |
69 NS_LOG_FUNCTION (this); | |
70 m_deviceList.clear (); | |
71 } | |
72 | |
160 int32_t | 73 int32_t |
161 CsmaChannel::Attach (Ptr<CsmaNetDevice> device, double position) | 74 CsmaChannel::Attach (Ptr<CsmaNetDevice> device, double distance) |
162 { | 75 { |
163 NS_LOG_FUNCTION (this << device); | 76 NS_LOG_FUNCTION (this << device); |
164 NS_ASSERT (device != 0); | 77 NS_ASSERT (device != 0); |
165 | 78 |
166 Ptr<CsmaNetDeviceRecord> deviceRecord = CreateObject<CsmaNetDeviceRecord> (); | 79 CsmaDeviceRec rec (device, distance); |
167 | 80 |
168 NS_ASSERT (deviceRecord != 0); | 81 m_deviceList.push_back (rec); |
169 deviceRecord->m_devicePtr = device; | |
170 deviceRecord->SetPosition (position); | |
171 deviceRecord->SetActive (); | |
172 | |
173 device->SetDeviceRecord (deviceRecord); | |
174 //deviceRecord->SetPosition (100); // VEDRANM debug | |
175 NS_LOG_DEBUG ("VEDRANM position u Attach " << position); | |
176 NS_LOG_DEBUG ("VEDRANM position u DeviceRecord " << deviceRecord->GetPosition ()); | |
177 NS_LOG_DEBUG ("VEDRANM position u m_deviceRecord " << device->GetDeviceRecord ()->GetPosition ()); | |
178 | |
179 m_deviceList.push_back (deviceRecord); | |
180 return (m_deviceList.size () - 1); | 82 return (m_deviceList.size () - 1); |
181 } | 83 } |
182 | 84 |
183 bool | 85 bool |
184 CsmaChannel::Reattach (Ptr<CsmaNetDevice> device) | 86 CsmaChannel::Reattach (Ptr<CsmaNetDevice> device) |
185 { | 87 { |
186 NS_LOG_FUNCTION (this << device); | 88 NS_LOG_FUNCTION (this << device); |
187 NS_ASSERT (device != 0); | 89 NS_ASSERT (device != 0); |
188 | 90 |
189 for (std::vector<Ptr<CsmaNetDeviceRecord> >::iterator it = m_deviceList.begin (); it != m_deviceList.end (); it++) | 91 std::vector<CsmaDeviceRec>::iterator it; |
190 { | 92 for (it = m_deviceList.begin (); it < m_deviceList.end ( ); it++) |
191 if ((*it)->m_devicePtr == device) | 93 { |
192 { | 94 if (it->devicePtr == device) |
193 if (!(*it)->IsActive ()) | 95 { |
96 if (!it->active) | |
194 { | 97 { |
195 (*it)->SetActive (); | 98 it->active = true; |
196 return true; | 99 return true; |
197 } | 100 } |
198 else· | 101 else· |
199 { | 102 { |
200 return false; | 103 return false; |
201 } | 104 } |
202 } | 105 } |
203 } | 106 } |
204 return false; | 107 return false; |
205 } | 108 } |
206 | 109 |
207 bool | 110 bool |
208 CsmaChannel::Reattach (uint32_t deviceId) | 111 CsmaChannel::Reattach (uint32_t deviceId) |
209 { | 112 { |
210 NS_LOG_FUNCTION (this << deviceId); | 113 NS_LOG_FUNCTION (this << deviceId); |
211 | 114 |
212 if (deviceId < m_deviceList.size ()) | 115 if (deviceId < m_deviceList.size ()) |
213 { | 116 { |
214 return false; | 117 return false; |
215 } | 118 } |
216 | 119 |
217 if (m_deviceList[deviceId]->IsActive ()) | 120 if (m_deviceList[deviceId].active) |
218 { | 121 { |
219 return false; | 122 return false; |
220 }· | 123 }· |
221 else· | 124 else· |
222 { | 125 { |
223 m_deviceList[deviceId]->SetActive (); | 126 m_deviceList[deviceId].active = true; |
224 return true; | 127 return true; |
225 } | 128 } |
226 } | 129 } |
227 | 130 |
228 bool | 131 bool |
229 CsmaChannel::Detach (Ptr<CsmaNetDevice> device) | |
230 { | |
231 NS_LOG_FUNCTION (this << device); | |
232 NS_ASSERT (device != 0); | |
233 | |
234 for (std::vector<Ptr<CsmaNetDeviceRecord> >::iterator it = m_deviceList.begin (); it != m_deviceList.end (); it++) | |
235 { | |
236 if (((*it)->m_devicePtr == device) && ((*it)->IsActive ())) | |
237 { | |
238 (*it)->SetInActive (); // VEDRANM FIXME a provjera jel šalje? | |
239 return true; | |
240 } | |
241 } | |
242 return false; | |
243 } | |
244 | |
245 bool | |
246 CsmaChannel::Detach (uint32_t deviceId) | 132 CsmaChannel::Detach (uint32_t deviceId) |
247 { | 133 { |
248 NS_LOG_FUNCTION (this << deviceId); | 134 NS_LOG_FUNCTION (this << deviceId); |
249 | 135 |
250 if (deviceId < m_deviceList.size ()) | 136 if (deviceId < m_deviceList.size ()) |
251 { | 137 { |
252 if (!m_deviceList[deviceId]->IsActive ()) | 138 if (!m_deviceList[deviceId].active) |
253 { | 139 { |
254 NS_LOG_WARN ("CsmaChannel::Detach(): Device is already detached (" << deviceId << ")"); | 140 NS_LOG_WARN ("CsmaChannel::Detach(): Device is already detached (" << deviceId << ")"); |
255 return false; | 141 return false; |
256 } | 142 } |
257 | 143 |
258 m_deviceList[deviceId]->SetInActive (); | 144 m_deviceList[deviceId].active = false; |
259 /* | 145 |
260 if ((m_state == TRANSMITTING) && (m_currentSrc == deviceId)) // VEDRANM mi jenjaj | 146 if ((m_state == OCCUPIED) && (m_currentSrc == deviceId)) |
261 { | 147 { |
262 NS_LOG_WARN ("CsmaChannel::Detach(): Device is currently" << "transmit ting (" << deviceId << ")"); | 148 NS_LOG_WARN ("CsmaChannel::Detach(): Device is currently" << "transmit ting (" << deviceId << ")"); |
263 } | 149 } |
264 */ | 150 |
265 return true; | 151 return true; |
266 }· | 152 }· |
267 else· | 153 else· |
268 { | 154 { |
269 return false; | 155 return false; |
270 } | 156 } |
271 } | 157 } |
272 | 158 |
273 bool | 159 bool |
274 CsmaChannel::IsActive (uint32_t deviceId) | 160 CsmaChannel::Detach (Ptr<CsmaNetDevice> device) |
275 { | 161 { |
276 return (m_deviceList[deviceId]->IsActive ()); | 162 NS_LOG_FUNCTION (this << device); |
277 } | 163 NS_ASSERT (device != 0); |
278 | 164 |
279 bool | 165 std::vector<CsmaDeviceRec>::iterator it; |
280 CsmaChannel::Transmit (Ptr<Packet> p, uint32_t srcId) | 166 for (it = m_deviceList.begin (); it < m_deviceList.end (); it++)· |
167 { | |
168 if ((it->devicePtr == device) && (it->active))· | |
169 { | |
170 it->active = false; | |
171 return true; | |
172 } | |
173 } | |
174 return false; | |
175 } | |
176 | |
177 bool | |
178 CsmaChannel::TransmitStart (Ptr<Packet> p, uint32_t srcId) | |
281 { | 179 { |
282 NS_LOG_FUNCTION (this << p << srcId); | 180 NS_LOG_FUNCTION (this << p << srcId); |
283 NS_LOG_INFO ("UID is " << p->GetUid () << ")"); | 181 NS_LOG_INFO ("UID is " << p->GetUid () << ")"); |
284 | 182 |
285 /* FIXME | 183 if (m_state != IDLE) |
286 assert(m_state != CH_IDLE, "CsmaChannel::TransmitStart(): State is not CH_IDLE "); | 184 { |
287 assert(!IsActive (srcId), "CsmaChannel::TransmitStart(): Seclected source is n ot currently attached to network"); | 185 NS_LOG_WARN ("CsmaChannel::TransmitStart(): State is not IDLE"); |
288 */ | 186 return false; |
289 | 187 } |
290 /* | 188 |
291 if (m_state != CH_IDLE) | |
292 { | |
293 NS_LOG_WARN ("CsmaChannel::TransmitStart(): State is not CH_IDLE"); | |
294 return false; | |
295 } | |
296 */ | |
297 if (!IsActive (srcId)) | 189 if (!IsActive (srcId)) |
298 { | 190 { |
299 NS_LOG_ERROR ("CsmaChannel::TransmitStart(): Seclected source is not curre ntly attached to network"); | 191 NS_LOG_ERROR ("CsmaChannel::TransmitStart(): Seclected source is not curre ntly attached to network"); |
300 return false; | 192 return false; |
301 } | 193 } |
302 | 194 |
303 /* | |
304 NS_LOG_LOGIC ("switch to TRANSMITTING"); | 195 NS_LOG_LOGIC ("switch to TRANSMITTING"); |
305 m_currentPkt = p; | 196 m_currentPkt = p; |
306 m_currentSrc = srcId; | 197 m_currentSrc = srcId; |
307 m_state = TRANSMITTING; // VEDRANM mijenjaj | 198 m_state = OCCUPIED; |
308 */ | 199 return true; |
200 } | |
201 | |
202 bool | |
203 CsmaChannel::IsActive (uint32_t deviceId) | |
204 { | |
205 return (m_deviceList[deviceId].active); | |
206 } | |
207 | |
208 bool | |
209 CsmaChannel::TransmitEnd () | |
210 { | |
211 NS_LOG_FUNCTION (this << m_currentPkt << m_currentSrc); | |
212 NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")"); | |
213 | |
214 NS_ASSERT (m_state == OCCUPIED); | |
215 | |
216 bool retVal = true; | |
217 | |
218 if (!IsActive (m_currentSrc)) | |
219 { | |
220 NS_LOG_ERROR ("CsmaChannel::TransmitEnd(): Seclected source was detached b efore the end of the transmission"); | |
221 retVal = false; | |
222 } | |
223 | |
224 NS_LOG_LOGIC ("From one to other end of the wire delay is " << m_delay.GetSeco nds () << " s"); | |
225 | |
226 | |
227 NS_LOG_LOGIC ("Receive"); | |
309 | 228 |
310 // Make all attached devices start receiving after signal has | 229 // Make all attached devices start receiving after signal has |
311 // propagated far enough so that device can see it | 230 // propagated far enough so that device can see it |
312 Time tEventProp; | 231 Time tEventTx = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ())); |
313 Time tEventTx = Seconds (m_bps.CalculateTxTime (p->GetSize ())); | 232 NS_LOG_DEBUG ("CSMA channel packet transmission time is " << tEventTx.GetSecon ds () << "s"); |
314 for (std::vector<Ptr<CsmaNetDeviceRecord> >::iterator it = m_deviceList.begin (); it != m_deviceList.end (); it++) | 233 for (std::vector<CsmaDeviceRec>::iterator it = m_deviceList.begin (); it < m_d eviceList.end (); it++) |
315 { | 234 { |
316 // Device doesn't send to itself | 235 // Device doesn't send to itself |
317 if (GetDeviceNum ((*it)->m_devicePtr) != srcId && (*it)->IsActive ()) | 236 if (GetDeviceNum (it->devicePtr) != m_currentSrc && it->IsActive ()) |
318 { | 237 { |
319 // We assume same delay for all devices on channel | 238 » // Compute propagation time based on device distance from wire end |
320 // that doesn't support positioning | 239 » Time tEventProp = std::abs ((m_deviceList[m_currentSrc].position - it- >position) / m_length) * m_delay; |
321 if (m_positioningEnabled) | 240 » NS_LOG_DEBUG ("CSMA channel propagation time for device " << it->devic ePtr << " is " << tEventProp.GetSeconds () << "s"); |
322 { | 241 Simulator::ScheduleWithContext (it->devicePtr->GetNode ()->GetId (), |
323 tEventProp = Seconds (std::abs (m_deviceList[srcId]->GetPosition ( ) - (*it)->GetPosition ()) * m_delay.GetSeconds ()); | |
Lalith Suresh
2011/10/29 14:07:59
Since GetPosition() returns a value between 0 and
Mehdi Moussouni
2014/06/26 18:31:06
Done.
Mehdi Moussouni
2014/06/26 18:31:06
Hello,
I think no because we know the propagation
| |
324 NS_LOG_DEBUG ("VEDRANM vrijeme " << m_deviceList[srcId]->GetPositi on () << "->" << (*it)->GetPosition () <<": " << tEventProp); | |
325 //VEDRANM HMM ovo ne treba jer smo u klasi kanala Seconds (std::ab s (m_channel->GetCsmaDevice(m_deviceId)->GetDistance () - m_channel->GetCsmaDevi ce(i)->GetDistance ()) / (m_channel->GetLength () * m_channel->GetDelay ().GetSe conds ())) | |
326 } | |
327 else | |
328 { | |
329 //tEventProp = Seconds (m_delay.GetSeconds ()); // VEDRANM ??? | |
330 tEventProp = m_delay; | |
331 } | |
332 NS_LOG_DEBUG ("VEDRANM tEventProp " << tEventProp); | |
333 Simulator::Schedule (tEventProp, &CsmaNetDevice::ReceiveStartEvent, (* it)->m_devicePtr); | |
334 Simulator::ScheduleWithContext ((*it)->m_devicePtr->GetNode ()->GetId (), | |
335 tEventProp + tEventTx, | 242 tEventProp + tEventTx, |
336 &CsmaNetDevice::Receive, (*it)->m_devi cePtr, | 243 &CsmaNetDevice::Receive, it->devicePtr , |
337 p->Copy (), m_deviceList[srcId]->m_dev icePtr); | 244 m_currentPkt->Copy (), m_deviceList[m_ currentSrc].devicePtr); |
338 Simulator::Schedule (tEventProp + tEventTx, &CsmaNetDevice::ReceiveCom pleteEvent, (*it)->m_devicePtr); | 245 } |
339 } | 246 } |
340 } | 247 |
341 | 248 // also schedule for the tx side to go back to IDLE |
342 return true; | 249 Simulator::Schedule (m_delay, &CsmaChannel::PropagationCompleteEvent, |
343 } | 250 this); |
344 | |
345 /* | |
346 bool | |
347 CsmaChannel::TransmitEnd () | |
348 { | |
349 //NS_LOG_FUNCTION (this << m_currentPkt << m_currentSrc); | |
350 //NS_LOG_INFO ("currentPkt UID = " << m_currentPkt->GetUid ()); | |
351 | |
352 //NS_ASSERT (m_state == TRANSMITTING); // VEDRANM mijenjaj | |
353 //m_state = CH_BUSY; | |
354 | |
355 bool retVal = true; | |
356 | |
357 if (!IsActive (m_currentSrc)) | |
358 { | |
359 NS_LOG_ERROR ("CsmaChannel::TransmitEnd(): Seclected source was detached b efore the end of the transmission"); | |
360 retVal = false; | |
361 } | |
362 | |
363 NS_LOG_LOGIC ("Schedule event in " << m_delay.GetSeconds () << " sec"); | |
364 | |
365 // VEDRANM mijenjaj ovo definitivno treba, tko prima i kada? | |
366 NS_LOG_LOGIC ("Receive packet."); | |
367 | |
368 // VEDRANM daj ovo napravi za sve devices | |
369 // VEDRANM also schedule for the Tx side to go back to TX_IDLE | |
370 //Simulator::Schedule (tEventProp + tEventTx, &CsmaNetDevice::ReceiveCompleteE vent, m_channel->GetCsmaDevice (i)); | |
371 //Simulator::Schedule (m_delay, &CsmaChannel::PropagationCompleteEvent, this); | |
372 return retVal; | 251 return retVal; |
373 } | 252 } |
374 */ | 253 |
375 | |
376 /* | |
377 void | 254 void |
378 CsmaChannel::PropagationCompleteEvent () | 255 CsmaChannel::PropagationCompleteEvent () |
379 { | 256 { |
380 NS_LOG_FUNCTION (this << m_currentPkt); | 257 NS_LOG_FUNCTION (this << m_currentPkt); |
381 NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")"); | 258 NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")"); |
382 | 259 |
383 NS_ASSERT (m_state == CH_BUSY); | 260 NS_ASSERT (m_state == OCCUPIED); |
384 m_state = CH_IDLE; | 261 m_state = IDLE; |
385 } | 262 } |
386 */ | |
387 | 263 |
388 uint32_t | 264 uint32_t |
389 CsmaChannel::GetNActDevices (void) | 265 CsmaChannel::GetNumActDevices (void) |
390 { | 266 { |
391 NS_LOG_FUNCTION_NOARGS (); | 267 int numActDevices = 0; |
392 int nActDevices = 0; | 268 std::vector<CsmaDeviceRec>::iterator it; |
393 for (std::vector<Ptr<CsmaNetDeviceRecord> >::iterator it = m_deviceList.begin (); it != m_deviceList.end (); it++)· | 269 for (it = m_deviceList.begin (); it < m_deviceList.end (); it++)· |
394 { | 270 { |
395 if ((*it)->IsActive ()) | 271 if (it->active) |
396 { | 272 { |
397 nActDevices++; | 273 numActDevices++; |
398 } | 274 } |
399 } | 275 } |
400 return nActDevices; | 276 return numActDevices; |
401 } | 277 } |
402 | 278 |
403 uint32_t | 279 uint32_t |
404 CsmaChannel::GetNDevices (void) const | 280 CsmaChannel::GetNDevices (void) const |
405 { | 281 { |
406 NS_LOG_FUNCTION_NOARGS (); | |
407 return (m_deviceList.size ()); | 282 return (m_deviceList.size ()); |
408 } | 283 } |
409 | 284 |
410 Ptr<CsmaNetDevice> | 285 Ptr<CsmaNetDevice> |
411 CsmaChannel::GetCsmaDevice (uint32_t i) const | 286 CsmaChannel::GetCsmaDevice (uint32_t i) const |
412 { | 287 { |
413 NS_LOG_FUNCTION (this << i); | 288 Ptr<CsmaNetDevice> netDevice = m_deviceList[i].devicePtr; |
414 Ptr<CsmaNetDevice> netDevice = m_deviceList[i]->m_devicePtr; | |
415 return netDevice; | 289 return netDevice; |
416 } | 290 } |
417 | 291 |
418 uint32_t | 292 int32_t |
419 CsmaChannel::GetDeviceNum (Ptr<CsmaNetDevice> device) | 293 CsmaChannel::GetDeviceNum (Ptr<CsmaNetDevice> device) |
420 { | 294 { |
421 NS_LOG_FUNCTION (this << device); | 295 std::vector<CsmaDeviceRec>::iterator it; |
422 int i = 0; | 296 int i = 0; |
423 for (std::vector<Ptr<CsmaNetDeviceRecord> >::iterator it = m_deviceList.begin (); it != m_deviceList.end (); it++)· | 297 for (it = m_deviceList.begin (); it < m_deviceList.end (); it++)· |
424 { | 298 { |
425 if ((*it)->m_devicePtr == device) | 299 if (it->devicePtr == device) |
426 { | 300 { |
427 if ((*it)->IsActive ()) | 301 if (it->active) |
428 { | 302 { |
429 return i; | 303 return i; |
430 } | 304 } |
431 else | 305 else |
432 { | 306 { |
433 return -2; | 307 return -2; |
434 } | 308 } |
435 } | 309 } |
436 i++; | 310 i++; |
437 } | 311 } |
438 return -1; | 312 return -1; |
439 } | 313 } |
440 | 314 |
441 /* | |
442 bool | 315 bool |
443 CsmaChannel::IsBusy (void) | 316 CsmaChannel::IsBusy (void) |
444 { | 317 { |
445 NS_LOG_FUNCTION_NOARGS (); | 318 if (m_state == IDLE) |
446 | 319 { |
447 if (m_state == CH_IDLE) | 320 return false; |
448 { | 321 } |
449 return false; | 322 else |
450 } | |
451 else | |
452 { | 323 { |
453 return true; | 324 return true; |
454 } | 325 } |
455 uint32_t brojac = 0; | 326 } |
456 for (std::vector<Ptr<CsmaNetDeviceRecord> >::iterator it = m_deviceList.begin (); it != m_deviceList.end (); it++)· | |
457 { | |
458 if (it->GetCarrierSense == CS_BUSY) | |
459 { | |
460 brojac++; | |
461 } | |
462 } | |
463 if (brojac > 0) | |
464 { | |
465 ······ | |
466 } | |
467 } | |
468 */ | |
469 | 327 |
470 DataRate | 328 DataRate |
471 CsmaChannel::GetDataRate (void) | 329 CsmaChannel::GetDataRate (void) |
472 { | 330 { |
473 NS_LOG_FUNCTION_NOARGS (); | |
474 return m_bps; | 331 return m_bps; |
475 } | 332 } |
476 | 333 |
477 Time | 334 Time |
478 CsmaChannel::GetDelay (void) | 335 CsmaChannel::GetDelay (void) |
479 { | 336 { |
480 NS_LOG_FUNCTION_NOARGS (); | |
481 return m_delay; | 337 return m_delay; |
482 } | 338 } |
483 | 339 |
484 /*double | 340 WireState |
485 CsmaChannel::GetLength (void) | |
486 { | |
487 NS_LOG_FUNCTION_NOARGS (); | |
488 return m_length; | |
489 } | |
490 */ | |
491 /* | |
492 CsmaChannel::WireState | |
493 CsmaChannel::GetState (void) | 341 CsmaChannel::GetState (void) |
494 { | 342 { |
495 NS_LOG_FUNCTION_NOARGS (); | |
496 return m_state; | 343 return m_state; |
497 } | 344 } |
498 */ | |
499 | 345 |
500 Ptr<NetDevice> | 346 Ptr<NetDevice> |
501 CsmaChannel::GetDevice (uint32_t i) const | 347 CsmaChannel::GetDevice (uint32_t i) const |
502 { | 348 { |
503 NS_LOG_FUNCTION (this << i); | |
504 return GetCsmaDevice (i); | 349 return GetCsmaDevice (i); |
505 } | 350 } |
506 | 351 |
352 CsmaDeviceRec::CsmaDeviceRec () | |
353 { | |
354 active = false; | |
355 } | |
356 | |
357 CsmaDeviceRec::CsmaDeviceRec (Ptr<CsmaNetDevice> device, double distance) | |
358 { | |
359 devicePtr = device;· | |
360 active = true; | |
361 position = distance; | |
362 } | |
363 | |
364 CsmaDeviceRec::CsmaDeviceRec (CsmaDeviceRec const &deviceRec) | |
365 { | |
366 devicePtr = deviceRec.devicePtr; | |
367 active = deviceRec.active; | |
368 position = deviceRec.position; | |
369 } | |
370 | |
371 bool | |
372 CsmaDeviceRec::IsActive ()· | |
373 { | |
374 return active; | |
375 } | |
376 | |
507 } // namespace ns3 | 377 } // namespace ns3 |
LEFT | RIGHT |