add dox doc and DefaultValue support to OnOffApplication
parent
bae023c075
commit
866c4cd4ec
|
@ -92,6 +92,8 @@ int main (int argc, char *argv[])
|
|||
// instantiate, when the queue factory is invoked in the topology code
|
||||
Bind ("Queue", "DropTailQueue");
|
||||
|
||||
Bind ("on-off-app-packet-size", "210");
|
||||
|
||||
//Bind ("DropTailQueue::m_maxPackets", 30);
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
|
@ -147,9 +149,7 @@ int main (int argc, char *argv[])
|
|||
Ipv4Address("10.1.3.2"),
|
||||
80,
|
||||
ConstantVariable(1),
|
||||
ConstantVariable(0),
|
||||
DataRate(448000),
|
||||
210);
|
||||
ConstantVariable(0));
|
||||
// Start the application
|
||||
ooff->Start(Seconds(1.0));
|
||||
ooff->Stop (Seconds(10.0));
|
||||
|
@ -160,9 +160,7 @@ int main (int argc, char *argv[])
|
|||
Ipv4Address("10.1.2.1"),
|
||||
80,
|
||||
ConstantVariable(1),
|
||||
ConstantVariable(0),
|
||||
DataRate(448000),
|
||||
210);
|
||||
ConstantVariable(0));
|
||||
// Start the application
|
||||
ooff->Start(Seconds(1.1));
|
||||
ooff->Stop (Seconds(10.0));
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "ns3/socket.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/i-udp.h"
|
||||
#include "ns3/default-value.h"
|
||||
#include "onoff-application.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -38,31 +39,58 @@ namespace ns3 {
|
|||
|
||||
// Defaults for rate/size
|
||||
DataRate OnOffApplication::g_defaultRate = DataRate(500000);
|
||||
uint32_t OnOffApplication::g_defaultSize = 512;
|
||||
static IntegerDefaultValue<uint32_t> g_defaultSize ("on-off-app-packet-size",
|
||||
"The size of packets send by OnOffApplication instances",
|
||||
512, 1);
|
||||
|
||||
// Constructors
|
||||
|
||||
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
||||
const Ipv4Address rip, // Remote IP addr
|
||||
uint16_t rport, // Remote port
|
||||
const RandomVariable& ontime,
|
||||
const RandomVariable& offtime,
|
||||
DataRate rate,
|
||||
uint32_t size)
|
||||
: Application(n),
|
||||
m_socket(0), // Socket allocated on Start
|
||||
m_peerIP(rip),
|
||||
m_peerPort(rport),
|
||||
m_connected(false),
|
||||
m_onTime(ontime.Copy()),
|
||||
m_offTime(offtime.Copy()),
|
||||
m_cbrRate(rate),
|
||||
m_pktSize(size),
|
||||
m_residualBits(0),
|
||||
m_lastStartTime((HighPrecision)0),
|
||||
m_maxBytes(0xffffffff),
|
||||
m_totBytes(0)
|
||||
{}
|
||||
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
||||
const Ipv4Address rip,
|
||||
uint16_t rport,
|
||||
const RandomVariable& ontime,
|
||||
const RandomVariable& offtime)
|
||||
: Application(n),
|
||||
m_cbrRate (g_defaultRate)
|
||||
{
|
||||
Construct (n, rip, rport, ontime, offtime,
|
||||
g_defaultSize.GetValue ());
|
||||
}
|
||||
|
||||
OnOffApplication::OnOffApplication(Ptr<INode> n,
|
||||
const Ipv4Address rip,
|
||||
uint16_t rport,
|
||||
const RandomVariable& ontime,
|
||||
const RandomVariable& offtime,
|
||||
DataRate rate,
|
||||
uint32_t size)
|
||||
: Application(n),
|
||||
m_cbrRate (rate)
|
||||
{
|
||||
Construct (n, rip, rport, ontime, offtime, size);
|
||||
}
|
||||
|
||||
void
|
||||
OnOffApplication::Construct (Ptr<INode> n,
|
||||
const Ipv4Address rip,
|
||||
uint16_t rport,
|
||||
const RandomVariable& onTime,
|
||||
const RandomVariable& offTime,
|
||||
uint32_t size)
|
||||
{
|
||||
m_socket = 0;
|
||||
m_peerIp = rip;
|
||||
m_peerPort = rport;
|
||||
m_connected = false;
|
||||
m_onTime = onTime.Copy ();
|
||||
m_offTime = offTime.Copy ();
|
||||
m_pktSize = size;
|
||||
m_residualBits = 0;
|
||||
m_lastStartTime = Seconds (0);
|
||||
m_maxBytes = 0xffffffff;
|
||||
m_totBytes = 0;
|
||||
}
|
||||
|
||||
|
||||
OnOffApplication::~OnOffApplication()
|
||||
{}
|
||||
|
@ -73,6 +101,12 @@ OnOffApplication::SetMaxBytes(uint32_t maxBytes)
|
|||
m_maxBytes = maxBytes;
|
||||
}
|
||||
|
||||
void
|
||||
OnOffApplication::SetDefaultSize (uint32_t size)
|
||||
{
|
||||
g_defaultSize.SetValue (size);
|
||||
}
|
||||
|
||||
void
|
||||
OnOffApplication::DoDispose (void)
|
||||
{
|
||||
|
@ -97,7 +131,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Star
|
|||
Ptr<IUdp> udp = GetINode ()->QueryInterface<IUdp> (IUdp::iid);
|
||||
m_socket = udp->CreateSocket ();
|
||||
m_socket->Bind ();
|
||||
m_socket->Connect (m_peerIP, m_peerPort);
|
||||
m_socket->Connect (m_peerIp, m_peerPort);
|
||||
}
|
||||
// Insure no pending event
|
||||
StopApplication();
|
||||
|
|
|
@ -38,24 +38,52 @@ class RandomVariable;
|
|||
class Socket;
|
||||
class DataRate;
|
||||
|
||||
class OnOffApplication : public Application {
|
||||
|
||||
/**
|
||||
* \brief Generate traffic to a single destination according to an
|
||||
* OnOff pattern.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class OnOffApplication : public Application
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \param n node associated to this application
|
||||
* \param rip remote ip address
|
||||
* \param rport remove port number
|
||||
* \param ontime on time random variable
|
||||
* \param offtime off time random variable
|
||||
*/
|
||||
OnOffApplication(Ptr<INode> n,
|
||||
const Ipv4Address, // Peer IP address
|
||||
uint16_t, // Peer port
|
||||
const RandomVariable&, // Random variable for On time
|
||||
const RandomVariable&, // Random variable for Off time
|
||||
DataRate = g_defaultRate, // Data rate when on
|
||||
uint32_t = g_defaultSize); // Size of packets
|
||||
const Ipv4Address rip,
|
||||
uint16_t rport,
|
||||
const RandomVariable& ontime,
|
||||
const RandomVariable& offtime);
|
||||
|
||||
virtual ~OnOffApplication(); // Destructor
|
||||
/**
|
||||
* \param n node associated to this application
|
||||
* \param rip remote ip address
|
||||
* \param rport remove port number
|
||||
* \param ontime on time random variable
|
||||
* \param offtime off time random variable
|
||||
* \param rate data rate when on
|
||||
* \param size size of packets when sending data.
|
||||
*/
|
||||
OnOffApplication(Ptr<INode> n,
|
||||
const Ipv4Address rip,
|
||||
uint16_t rport,
|
||||
const RandomVariable& ontime,
|
||||
const RandomVariable& offtime,
|
||||
DataRate rate,
|
||||
uint32_t size);
|
||||
|
||||
virtual ~OnOffApplication();
|
||||
|
||||
void SetMaxBytes(uint32_t maxBytes);
|
||||
|
||||
static void DefaultRate(uint64_t r) { g_defaultRate = r;}
|
||||
|
||||
static void DefaultSize(uint32_t s) { g_defaultSize = s;}
|
||||
static void SetDefaultSize (uint32_t size);
|
||||
|
||||
protected:
|
||||
virtual void DoDispose (void);
|
||||
|
@ -64,13 +92,21 @@ private:
|
|||
virtual void StartApplication (void); // Called at time specified by Start
|
||||
virtual void StopApplication (void); // Called at time specified by Stop
|
||||
|
||||
void Construct (Ptr<INode> n,
|
||||
const Ipv4Address rip,
|
||||
uint16_t rport,
|
||||
const RandomVariable& ontime,
|
||||
const RandomVariable& offtime,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
// Event handlers
|
||||
void StartSending();
|
||||
void StopSending();
|
||||
void SendPacket();
|
||||
|
||||
Ptr<Socket> m_socket; // Associated socket
|
||||
Ipv4Address m_peerIP; // Peer IP address
|
||||
Ipv4Address m_peerIp; // Peer IP address
|
||||
uint16_t m_peerPort; // Peer port
|
||||
bool m_connected; // True if connected
|
||||
RandomVariable* m_onTime; // rng for On Time
|
||||
|
@ -87,7 +123,6 @@ private:
|
|||
|
||||
public:
|
||||
static DataRate g_defaultRate; // Default sending rate when on
|
||||
static uint32_t g_defaultSize; // Default packet size
|
||||
|
||||
private:
|
||||
void ScheduleNextTx();
|
||||
|
|
Loading…
Reference in New Issue