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) 2006 Georgia Tech Research Corporation | 3 // Copyright (c) 2006 Georgia Tech Research Corporation |
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 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 MakeUintegerChecker<uint64_t> ()) | 84 MakeUintegerChecker<uint64_t> ()) |
85 .AddAttribute ("Protocol", "The type of protocol to use. This should be " | 85 .AddAttribute ("Protocol", "The type of protocol to use. This should be " |
86 "a subclass of ns3::SocketFactory", | 86 "a subclass of ns3::SocketFactory", |
87 TypeIdValue (UdpSocketFactory::GetTypeId ()), | 87 TypeIdValue (UdpSocketFactory::GetTypeId ()), |
88 MakeTypeIdAccessor (&OnOffApplication::m_tid), | 88 MakeTypeIdAccessor (&OnOffApplication::m_tid), |
89 // This should check for SocketFactory as a parent | 89 // This should check for SocketFactory as a parent |
90 MakeTypeIdChecker ()) | 90 MakeTypeIdChecker ()) |
91 .AddTraceSource ("Tx", "A new packet is created and is sent", | 91 .AddTraceSource ("Tx", "A new packet is created and is sent", |
92 MakeTraceSourceAccessor (&OnOffApplication::m_txTrace), | 92 MakeTraceSourceAccessor (&OnOffApplication::m_txTrace), |
93 "ns3::Packet::TracedCallback") | 93 "ns3::Packet::TracedCallback") |
| 94 .AddTraceSource ("TxWithAddresses", "A new packet is created and is sent", |
| 95 MakeTraceSourceAccessor (&OnOffApplication::m_txTraceWithAd
dresses), |
| 96 "ns3::Packet::TwoAddressTracedCallback") |
94 ; | 97 ; |
95 return tid; | 98 return tid; |
96 } | 99 } |
97 | 100 |
98 | 101 |
99 OnOffApplication::OnOffApplication () | 102 OnOffApplication::OnOffApplication () |
100 : m_socket (0), | 103 : m_socket (0), |
101 m_connected (false), | 104 m_connected (false), |
102 m_residualBits (0), | 105 m_residualBits (0), |
103 m_lastStartTime (Seconds (0)), | 106 m_lastStartTime (Seconds (0)), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 206 |
204 void OnOffApplication::CancelEvents () | 207 void OnOffApplication::CancelEvents () |
205 { | 208 { |
206 NS_LOG_FUNCTION (this); | 209 NS_LOG_FUNCTION (this); |
207 | 210 |
208 if (m_sendEvent.IsRunning () && m_cbrRateFailSafe == m_cbrRate ) | 211 if (m_sendEvent.IsRunning () && m_cbrRateFailSafe == m_cbrRate ) |
209 { // Cancel the pending send packet event | 212 { // Cancel the pending send packet event |
210 // Calculate residual bits since last packet sent | 213 // Calculate residual bits since last packet sent |
211 Time delta (Simulator::Now () - m_lastStartTime); | 214 Time delta (Simulator::Now () - m_lastStartTime); |
212 int64x64_t bits = delta.To (Time::S) * m_cbrRate.GetBitRate (); | 215 int64x64_t bits = delta.To (Time::S) * m_cbrRate.GetBitRate (); |
213 m_residualBits += static_cast<uint32_t>(bits.GetHigh ()); | 216 m_residualBits += static_cast<uint32_t> (bits.GetHigh ()); |
214 } | 217 } |
215 m_cbrRateFailSafe = m_cbrRate; | 218 m_cbrRateFailSafe = m_cbrRate; |
216 Simulator::Cancel (m_sendEvent); | 219 Simulator::Cancel (m_sendEvent); |
217 Simulator::Cancel (m_startStopEvent); | 220 Simulator::Cancel (m_startStopEvent); |
218 } | 221 } |
219 | 222 |
220 // Event handlers | 223 // Event handlers |
221 void OnOffApplication::StartSending () | 224 void OnOffApplication::StartSending () |
222 { | 225 { |
223 NS_LOG_FUNCTION (this); | 226 NS_LOG_FUNCTION (this); |
(...skipping 13 matching lines...) Expand all Loading... |
237 // Private helpers | 240 // Private helpers |
238 void OnOffApplication::ScheduleNextTx () | 241 void OnOffApplication::ScheduleNextTx () |
239 { | 242 { |
240 NS_LOG_FUNCTION (this); | 243 NS_LOG_FUNCTION (this); |
241 | 244 |
242 if (m_maxBytes == 0 || m_totBytes < m_maxBytes) | 245 if (m_maxBytes == 0 || m_totBytes < m_maxBytes) |
243 { | 246 { |
244 uint32_t bits = m_pktSize * 8 - m_residualBits; | 247 uint32_t bits = m_pktSize * 8 - m_residualBits; |
245 NS_LOG_LOGIC ("bits = " << bits); | 248 NS_LOG_LOGIC ("bits = " << bits); |
246 Time nextTime (Seconds (bits / | 249 Time nextTime (Seconds (bits / |
247 static_cast<double>(m_cbrRate.GetBitRate ()))); //
Time till next packet | 250 static_cast<double> (m_cbrRate.GetBitRate ()))); /
/ Time till next packet |
248 NS_LOG_LOGIC ("nextTime = " << nextTime); | 251 NS_LOG_LOGIC ("nextTime = " << nextTime); |
249 m_sendEvent = Simulator::Schedule (nextTime, | 252 m_sendEvent = Simulator::Schedule (nextTime, |
250 &OnOffApplication::SendPacket, this); | 253 &OnOffApplication::SendPacket, this); |
251 } | 254 } |
252 else | 255 else |
253 { // All done, cancel any pending events | 256 { // All done, cancel any pending events |
254 StopApplication (); | 257 StopApplication (); |
255 } | 258 } |
256 } | 259 } |
257 | 260 |
(...skipping 18 matching lines...) Expand all Loading... |
276 | 279 |
277 void OnOffApplication::SendPacket () | 280 void OnOffApplication::SendPacket () |
278 { | 281 { |
279 NS_LOG_FUNCTION (this); | 282 NS_LOG_FUNCTION (this); |
280 | 283 |
281 NS_ASSERT (m_sendEvent.IsExpired ()); | 284 NS_ASSERT (m_sendEvent.IsExpired ()); |
282 Ptr<Packet> packet = Create<Packet> (m_pktSize); | 285 Ptr<Packet> packet = Create<Packet> (m_pktSize); |
283 m_txTrace (packet); | 286 m_txTrace (packet); |
284 m_socket->Send (packet); | 287 m_socket->Send (packet); |
285 m_totBytes += m_pktSize; | 288 m_totBytes += m_pktSize; |
| 289 Address localAddress; |
| 290 m_socket->GetSockName (localAddress); |
286 if (InetSocketAddress::IsMatchingType (m_peer)) | 291 if (InetSocketAddress::IsMatchingType (m_peer)) |
287 { | 292 { |
288 NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () | 293 NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () |
289 << "s on-off application sent " | 294 << "s on-off application sent " |
290 << packet->GetSize () << " bytes to " | 295 << packet->GetSize () << " bytes to " |
291 << InetSocketAddress::ConvertFrom(m_peer).GetIpv4 () | 296 << InetSocketAddress::ConvertFrom(m_peer).GetIpv4 () |
292 << " port " << InetSocketAddress::ConvertFrom (m_peer).GetPor
t () | 297 << " port " << InetSocketAddress::ConvertFrom (m_peer).GetPor
t () |
293 << " total Tx " << m_totBytes << " bytes"); | 298 << " total Tx " << m_totBytes << " bytes"); |
| 299 m_txTraceWithAddresses (packet, localAddress, InetSocketAddress::ConvertFr
om (m_peer)); |
294 } | 300 } |
295 else if (Inet6SocketAddress::IsMatchingType (m_peer)) | 301 else if (Inet6SocketAddress::IsMatchingType (m_peer)) |
296 { | 302 { |
297 NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () | 303 NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () |
298 << "s on-off application sent " | 304 << "s on-off application sent " |
299 << packet->GetSize () << " bytes to " | 305 << packet->GetSize () << " bytes to " |
300 << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6 () | 306 << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6 () |
301 << " port " << Inet6SocketAddress::ConvertFrom (m_peer).GetPo
rt () | 307 << " port " << Inet6SocketAddress::ConvertFrom (m_peer).GetPo
rt () |
302 << " total Tx " << m_totBytes << " bytes"); | 308 << " total Tx " << m_totBytes << " bytes"); |
| 309 m_txTraceWithAddresses (packet, localAddress, Inet6SocketAddress::ConvertF
rom(m_peer)); |
303 } | 310 } |
304 m_lastStartTime = Simulator::Now (); | 311 m_lastStartTime = Simulator::Now (); |
305 m_residualBits = 0; | 312 m_residualBits = 0; |
306 ScheduleNextTx (); | 313 ScheduleNextTx (); |
307 } | 314 } |
308 | 315 |
309 | 316 |
310 void OnOffApplication::ConnectionSucceeded (Ptr<Socket> socket) | 317 void OnOffApplication::ConnectionSucceeded (Ptr<Socket> socket) |
311 { | 318 { |
312 NS_LOG_FUNCTION (this << socket); | 319 NS_LOG_FUNCTION (this << socket); |
313 m_connected = true; | 320 m_connected = true; |
314 } | 321 } |
315 | 322 |
316 void OnOffApplication::ConnectionFailed (Ptr<Socket> socket) | 323 void OnOffApplication::ConnectionFailed (Ptr<Socket> socket) |
317 { | 324 { |
318 NS_LOG_FUNCTION (this << socket); | 325 NS_LOG_FUNCTION (this << socket); |
319 } | 326 } |
320 | 327 |
321 | 328 |
322 } // Namespace ns3 | 329 } // Namespace ns3 |
LEFT | RIGHT |