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