packet_generator.cpp
Go to the documentation of this file.
#include <itpp/protocol/packet_generator.h>
namespace itpp
{
Packet_Generator::Packet_Generator(const int Packet_size, const unsigned long int Max_packets)
{
keep_running = false;
start.forward(this, &Packet_Generator::handle_start);
next.forward(this, &Packet_Generator::handle_next);
output.connect(&next);
set_parameters(Packet_size, Max_packets);
}
Packet_Generator::~Packet_Generator() { }
void Packet_Generator::set_parameters(const int Packet_size, const unsigned long int Max_packets)
{
it_assert(Packet_size > 0, "Packet_Generator::set_parameters(): ");
packet_size = Packet_size;
max_packets = Max_packets;
id = 0;
}
int Packet_Generator::get_packet_size()
{
return packet_size;
}
int Packet_Generator::get_max_packets()
{
return max_packets;
}
void Packet_Generator::handle_next(Packet*)
{
if (keep_running) {
output(new Packet(8*packet_size), delta_t());
id++;
if (max_packets && id >= max_packets)
start(false);
}
}
void Packet_Generator::handle_start(const bool run)
{
if (run && !keep_running) {
keep_running = run;
handle_next(NULL);
}
keep_running = run;
}
// ---------------------------- Poisson_Packet_Generator -------------------------------------------------
Poisson_Packet_Generator::Poisson_Packet_Generator(const double Avg_bit_rate,
const int Packet_size,
const unsigned long int Max_packets): Packet_Generator(Packet_size, Max_packets)
{
set_parameters(Avg_bit_rate, Packet_size, Max_packets);
}
Poisson_Packet_Generator::~Poisson_Packet_Generator() {}
void Poisson_Packet_Generator::set_parameters(const double Avg_bit_rate,
const int Packet_size,
const unsigned long int Max_packets)
{
Packet_Generator::set_parameters(Packet_size, Max_packets);
it_assert(Avg_bit_rate > 0.0, "Packet_Generator::set_parameters(): ");
avg_bit_rate = Avg_bit_rate;
avg_delta_t = 8.0 * get_packet_size() / avg_bit_rate;
ee.setup(1.0);
}
double Poisson_Packet_Generator::get_avg_bit_rate()
{
return avg_bit_rate;
}
Ttype Poisson_Packet_Generator::delta_t()
{
return ee()*avg_delta_t;
}
// ---------------------------- Constant_Rate_Packet_Generator -------------------------------------------------
Constant_Rate_Packet_Generator::Constant_Rate_Packet_Generator(const double Avg_rate, const int Packet_size, const unsigned long int Max_packets): Poisson_Packet_Generator(Avg_rate, Packet_size, Max_packets) {}
Constant_Rate_Packet_Generator::~Constant_Rate_Packet_Generator() {}
Ttype Constant_Rate_Packet_Generator::delta_t()
{
return avg_delta_t;
}
// ---------------------------- Burst_WWW_Packet_Generator -------------------------------------------------
Burst_WWW_Packet_Generator::Burst_WWW_Packet_Generator(const double Avg_bit_rate, const int Packet_size, const int Max_packets): Poisson_Packet_Generator(Avg_bit_rate, Packet_size, Max_packets)
{
Navg = 50; // Average number of packets per burst [packets].
Ti = 1.1960e-4; // Average inter-arrival time between packets in burst [s].
Tr = Navg * Packet_size * 8.0 / Avg_bit_rate - Ti * (Navg - 1); // Average time between bursts.
N = 0;
}
Burst_WWW_Packet_Generator::~Burst_WWW_Packet_Generator()
{
}
Ttype Burst_WWW_Packet_Generator::delta_t()
{
if (N == 0) { // Start of a new burst.
N = Navg;
N--; // First packet is triggered at ...
return ee()*Tr; // ... start time of next burst.
}
else { // Within a burst.
N--; // One packet less in the burst ...
return ee()*Ti; // ... arrival time for next packet within the burst.
}
}
// ----------------------------Sink -------------------------------------------------
Sink::Sink(const unsigned long int Max_packets)
{
it_assert(Max_packets > 0, "Sink::Sink(): ");
max_packets = Max_packets;
Ncp = 0;
Nbytes = 0;
packet_input.forward(this, &Sink::handle_packet_input);
start_time = Event_Queue::now();
}
Sink::~Sink()
{
std::cout << "Time = " << Event_Queue::now() << ", Sink : " << std::endl;
std::cout << "Received " << Ncp << " packets in sequence." << std::endl;
std::cout << "Receive average bit rate = " << Nbytes*8.0 / (Event_Queue::now() - start_time) << " [bits/second]." << std::endl;
}
void Sink::handle_packet_input(Packet *P)
{
it_assert(P != NULL, "Sink::handle_packet_input(): ");
Ncp++;
Nbytes += (P->bit_size() / 8);
delete P;
if (Ncp >= max_packets) {
std::cout << "Time = " << Event_Queue::now() << ", Sink : " << std::endl;
std::cout << "Simulation stopped because : Ncp > max_packets" << std::endl;
Event_Queue::stop();
}
}
} // namespace itpp
itpp::Burst_WWW_Packet_Generator::Ti
double Ti
ADD DOCUMENTATION HERE.
Definition packet_generator.h:144
itpp::Burst_WWW_Packet_Generator::Tr
double Tr
ADD DOCUMENTATION HERE.
Definition packet_generator.h:146
itpp::Burst_WWW_Packet_Generator::delta_t
virtual Ttype delta_t()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:146
itpp::Burst_WWW_Packet_Generator::~Burst_WWW_Packet_Generator
virtual ~Burst_WWW_Packet_Generator()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:141
itpp::Burst_WWW_Packet_Generator::N
int N
ADD DOCUMENTATION HERE.
Definition packet_generator.h:140
itpp::Burst_WWW_Packet_Generator::Navg
int Navg
ADD DOCUMENTATION HERE.
Definition packet_generator.h:142
itpp::Burst_WWW_Packet_Generator::Burst_WWW_Packet_Generator
Burst_WWW_Packet_Generator(const double Avg_bit_rate=1.0, const int Packet_size=150, const int Max_packets=0)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:133
itpp::Constant_Rate_Packet_Generator::~Constant_Rate_Packet_Generator
virtual ~Constant_Rate_Packet_Generator()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:122
itpp::Constant_Rate_Packet_Generator::delta_t
virtual Ttype delta_t()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:124
itpp::Constant_Rate_Packet_Generator::Constant_Rate_Packet_Generator
Constant_Rate_Packet_Generator(const double Avg_bit_rate=1.0, const int Packet_size=150, const unsigned long int Max_packets=0)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:120
itpp::Event_Queue::stop
static void stop()
Stop execution of events.
Definition events.cpp:73
itpp::Event_Queue::now
static Ttype now()
Return current time.
Definition events.h:139
itpp::Packet_Generator::delta_t
virtual Ttype delta_t()=0
ADD DOCUMENTATION HERE.
itpp::Packet_Generator::set_parameters
void set_parameters(const int Packet_size, const unsigned long int Max_packets)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:46
itpp::Packet_Generator::get_packet_size
int get_packet_size()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:54
itpp::Packet_Generator::output
Signal< Packet * > output
ADD DOCUMENTATION HERE.
Definition packet_generator.h:62
itpp::Packet_Generator::get_max_packets
int get_max_packets()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:59
itpp::Packet_Generator::start
Slot< Packet_Generator, bool > start
ADD DOCUMENTATION HERE.
Definition packet_generator.h:64
itpp::Packet_Generator::Packet_Generator
Packet_Generator(const int Packet_size=150, const unsigned long int Max_packets=0)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:35
itpp::Packet_Generator::~Packet_Generator
virtual ~Packet_Generator()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:44
itpp::Packet
Definition packet.h:56
itpp::Packet::bit_size
int bit_size()
get size of packet in bits
Definition packet.h:67
itpp::Poisson_Packet_Generator::get_avg_bit_rate
double get_avg_bit_rate()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:106
itpp::Poisson_Packet_Generator::~Poisson_Packet_Generator
virtual ~Poisson_Packet_Generator()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:93
itpp::Poisson_Packet_Generator::avg_delta_t
double avg_delta_t
ADD DOCUMENTATION HERE.
Definition packet_generator.h:103
itpp::Poisson_Packet_Generator::avg_bit_rate
double avg_bit_rate
ADD DOCUMENTATION HERE.
Definition packet_generator.h:105
itpp::Poisson_Packet_Generator::Poisson_Packet_Generator
Poisson_Packet_Generator(const double Avg_bit_rate=1.0, const int Packet_size=150, const unsigned long int Max_packets=0)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:86
itpp::Poisson_Packet_Generator::set_parameters
void set_parameters(const double Avg_bit_rate, const int Packet_size, const unsigned long int Max_packets)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:95
itpp::Poisson_Packet_Generator::delta_t
virtual Ttype delta_t()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:112
itpp::Poisson_Packet_Generator::ee
Exponential_RNG ee
ADD DOCUMENTATION HERE.
Definition packet_generator.h:107
itpp::Sink::~Sink
~Sink()
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:172
itpp::Sink::Sink
Sink(const unsigned long int Max_packets=1000)
ADD DOCUMENTATION HERE.
Definition packet_generator.cpp:162
itpp::Sink::packet_input
Slot< Sink, Packet * > packet_input
ADD DOCUMENTATION HERE.
Definition packet_generator.h:162
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition itassert.h:94
itpp
itpp namespace
Definition itmex.h:37
itpp::Ttype
double Ttype
64-bit floating point time
Definition events.h:54
packet_generator.h
Definition of a Packet generator class.

Generated on for IT++ by Doxygen 1.15.0