27 #include "ns3/inet-socket-address.h" |
27 #include "ns3/inet-socket-address.h" |
28 #include "ns3/inet6-socket-address.h" |
28 #include "ns3/inet6-socket-address.h" |
29 #include "ns3/node.h" |
29 #include "ns3/node.h" |
30 #include "ns3/nstime.h" |
30 #include "ns3/nstime.h" |
31 #include "ns3/data-rate.h" |
31 #include "ns3/data-rate.h" |
32 #include "ns3/random-variable.h" |
32 #include "ns3/random-variable-stream.h" |
33 #include "ns3/socket.h" |
33 #include "ns3/socket.h" |
34 #include "ns3/simulator.h" |
34 #include "ns3/simulator.h" |
35 #include "ns3/socket-factory.h" |
35 #include "ns3/socket-factory.h" |
36 #include "ns3/packet.h" |
36 #include "ns3/packet.h" |
37 #include "ns3/uinteger.h" |
37 #include "ns3/uinteger.h" |
38 #include "ns3/trace-source-accessor.h" |
38 #include "ns3/trace-source-accessor.h" |
39 #include "onoff-application.h" |
39 #include "onoff-application.h" |
40 #include "ns3/udp-socket-factory.h" |
40 #include "ns3/udp-socket-factory.h" |
|
41 #include "ns3/string.h" |
|
42 #include "ns3/pointer.h" |
41 |
43 |
42 NS_LOG_COMPONENT_DEFINE ("OnOffApplication"); |
44 NS_LOG_COMPONENT_DEFINE ("OnOffApplication"); |
43 |
45 |
44 using namespace std; |
46 using namespace std; |
45 |
47 |
63 MakeUintegerChecker<uint32_t> (1)) |
65 MakeUintegerChecker<uint32_t> (1)) |
64 .AddAttribute ("Remote", "The address of the destination", |
66 .AddAttribute ("Remote", "The address of the destination", |
65 AddressValue (), |
67 AddressValue (), |
66 MakeAddressAccessor (&OnOffApplication::m_peer), |
68 MakeAddressAccessor (&OnOffApplication::m_peer), |
67 MakeAddressChecker ()) |
69 MakeAddressChecker ()) |
68 .AddAttribute ("OnTime", "A RandomVariable used to pick the duration of the 'On' state.", |
70 .AddAttribute ("OnTime", "A RandomVariableStream used to pick the duration of the 'On' state.", |
69 RandomVariableValue (ConstantVariable (1.0)), |
71 StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), |
70 MakeRandomVariableAccessor (&OnOffApplication::m_onTime), |
72 MakePointerAccessor (&OnOffApplication::m_onTime), |
71 MakeRandomVariableChecker ()) |
73 MakePointerChecker <RandomVariableStream>()) |
72 .AddAttribute ("OffTime", "A RandomVariable used to pick the duration of the 'Off' state.", |
74 .AddAttribute ("OffTime", "A RandomVariableStream used to pick the duration of the 'Off' state.", |
73 RandomVariableValue (ConstantVariable (1.0)), |
75 StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), |
74 MakeRandomVariableAccessor (&OnOffApplication::m_offTime), |
76 MakePointerAccessor (&OnOffApplication::m_offTime), |
75 MakeRandomVariableChecker ()) |
77 MakePointerChecker <RandomVariableStream>()) |
76 .AddAttribute ("MaxBytes", |
78 .AddAttribute ("MaxBytes", |
77 "The total number of bytes to send. Once these bytes are sent, " |
79 "The total number of bytes to send. Once these bytes are sent, " |
78 "no packet is sent again, even in on state. The value zero means " |
80 "no packet is sent again, even in on state. The value zero means " |
79 "that there is no limit.", |
81 "that there is no limit.", |
80 UintegerValue (0), |
82 UintegerValue (0), |
222 |
233 |
223 void OnOffApplication::ScheduleStartEvent () |
234 void OnOffApplication::ScheduleStartEvent () |
224 { // Schedules the event to start sending data (switch to the "On" state) |
235 { // Schedules the event to start sending data (switch to the "On" state) |
225 NS_LOG_FUNCTION_NOARGS (); |
236 NS_LOG_FUNCTION_NOARGS (); |
226 |
237 |
227 Time offInterval = Seconds (m_offTime.GetValue ()); |
238 Time offInterval = Seconds (m_offTime->GetValue ()); |
228 NS_LOG_LOGIC ("start at " << offInterval); |
239 NS_LOG_LOGIC ("start at " << offInterval); |
229 m_startStopEvent = Simulator::Schedule (offInterval, &OnOffApplication::StartSending, this); |
240 m_startStopEvent = Simulator::Schedule (offInterval, &OnOffApplication::StartSending, this); |
230 } |
241 } |
231 |
242 |
232 void OnOffApplication::ScheduleStopEvent () |
243 void OnOffApplication::ScheduleStopEvent () |
233 { // Schedules the event to stop sending data (switch to "Off" state) |
244 { // Schedules the event to stop sending data (switch to "Off" state) |
234 NS_LOG_FUNCTION_NOARGS (); |
245 NS_LOG_FUNCTION_NOARGS (); |
235 |
246 |
236 Time onInterval = Seconds (m_onTime.GetValue ()); |
247 Time onInterval = Seconds (m_onTime->GetValue ()); |
237 NS_LOG_LOGIC ("stop at " << onInterval); |
248 NS_LOG_LOGIC ("stop at " << onInterval); |
238 m_startStopEvent = Simulator::Schedule (onInterval, &OnOffApplication::StopSending, this); |
249 m_startStopEvent = Simulator::Schedule (onInterval, &OnOffApplication::StopSending, this); |
239 } |
250 } |
240 |
251 |
241 |
252 |