54 : TclClass(
"Module/UW/APPLICATION")
87 , drop_out_of_order(0)
89 , chkTimerPeriod(this)
90 , socket_active(false)
114 bind(
"debug_", (
int *) &
debug_);
115 bind(
"period_", (
double *) &
PERIOD);
116 bind(
"node_ID_", (
int *) &
node_id);
117 bind(
"EXP_ID_", (
int *) &
exp_id);
120 bind(
"destAddr_", (
int *) &
dst_addr);
121 bind(
"destPort_", (
int *) &
port_num);
122 bind(
"Socket_Port_", (
int *) &
servPort);
127 for (
int i = 0; i < USHRT_MAX; i++) {
140 Tcl &tcl = Tcl::instance();
143 if (strcasecmp(argv[1],
"start") == 0) {
158 }
else if (strcasecmp(argv[1],
"stop") == 0) {
161 }
else if (strcasecmp(argv[1],
"getsentpkts") == 0) {
164 }
else if (strcasecmp(argv[1],
"lostpkts") == 0) {
167 }
else if (strcasecmp(argv[1],
"getrecvpkts") == 0) {
170 }
else if (strcasecmp(argv[1],
"outofsequencepkts") == 0) {
173 }
else if (strcasecmp(argv[1],
"notknownpktrx") == 0) {
176 }
else if (strcasecmp(argv[1],
"getrecvpktsqueue") == 0) {
179 }
else if (strcasecmp(argv[1],
"getrtt") == 0) {
180 tcl.resultf(
"%f",
GetRTT());
182 }
else if (strcasecmp(argv[1],
"getrttstd") == 0) {
185 }
else if (strcasecmp(argv[1],
"getftt") == 0) {
186 tcl.resultf(
"%f",
GetFTT());
188 }
else if (strcasecmp(argv[1],
"getfttstd") == 0) {
191 }
else if (strcasecmp(argv[1],
"getper") == 0) {
192 tcl.resultf(
"%f",
GetPER());
194 }
else if (strcasecmp(argv[1],
"getthr") == 0) {
195 tcl.resultf(
"%f",
GetTHR());
197 }
else if (strcasecmp(argv[1],
"print_log") == 0) {
198 std::stringstream stat_file;
199 stat_file <<
"UWAPPLICATION_LOG_NODE_ID_" <<
node_id <<
"_EXP_ID_"
201 out_log.open(stat_file.str().c_str(), std::ios_base::app);
203 <<
"::UWAPPLICATION::FILE_CREATED" << endl;
207 }
else if (argc == 3) {
208 if (strcasecmp(argv[1],
"SetSocketProtocol") == 0) {
209 string protocol = argv[2];
210 if (strcasecmp(protocol.c_str(),
"UDP") == 0) {
213 }
else if (strcasecmp(protocol.c_str(),
"TCP") == 0) {
223 return Module::command(argc, argv);
231 return Module::crLayCommand(m);
240 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
241 <<
"::UWAPPLICATION::RECV_PACKET_WITHOUT_SOCKET_MODE"
245 <<
"::UWAPPLICATION::RECV_PACKET_WITHOUT_SOCKET_MODE"
252 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
253 <<
"::UWAPPLICATION::RECV_PACKET_USING_TCP" << endl;
256 <<
"::UWAPPLICATION::RECV_PACKET_USING_TCP" << endl;
260 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
261 <<
"::UWAPPLICATION::RECV_PACKET_USING_UDP" << endl;
264 <<
"::UWAPPLICATION::RECV_PACKET_USING_UDP" << endl;
273 hdr_cmn *ch = hdr_cmn::access(p);
278 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
279 <<
"::UWAPPLICATION::DROP_PACKET_NOT_APPLICATION_TYPE"
283 <<
"::UWAPPLICATION::DROP_PACKET_NOT_APPLICATION_TYPE"
296 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
297 <<
"::UWAPPLICATION::DROP_PACKET_PACKET_ALREADY_"
299 << (int) uwApph->
sn_ << endl;
302 <<
"::UWAPPLICATION::DROP_PACKET_PACKET_ALREADY_"
304 << (int) uwApph->
sn_ << endl;
323 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
324 <<
"::UWAPPLICATION::DROP_PACKET_PACKET_OOS_ID_"
325 << (int) uwApph->
sn_ <<
"_LAST_SN_" <<
hrsn << endl;
328 <<
"::UWAPPLICATION::DROP_PACKET_PACKET_OOS_ID_"
329 << (int) uwApph->
sn_ <<
"_LAST_SN_" <<
hrsn << endl;
336 rftt = Scheduler::instance().clock() - ch->timestamp();
350 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
351 <<
"::UWAPPLICATION::PACKET_LOST_ID_RECEIVED"
352 << (int) uwApph->
sn_ <<
"_ID_EXPECTED_" <<
esn
356 <<
"::UWAPPLICATION::PACKET_LOST_ID_RECEIVED"
357 << (int) uwApph->
sn_ <<
"_ID_EXPECTED_" <<
esn << endl;
362 double dt = Scheduler::instance().clock() -
lrtime;
367 lrtime = Scheduler::instance().clock();
370 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
371 <<
"::UWAPPLICATION::PAYLOAD_RECEIVED--> ";
377 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
378 <<
"::UWAPPLICATION::SN_RECEIVED_" << (int) uwApph->
sn_
381 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
382 <<
"::UWAPPLICATION::PAYLOAD_SIZE_RECEIVED_"
385 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
386 <<
"::UWAPPLICATION::PAYLOAD_RECEIVED_" << uwApph->
payload_msg
391 <<
"::UWAPPLICATION::PAYLOAD_SIZE_RECEIVED_"
395 <<
"::UWAPPLICATION::SN_RECEIVED_" << (int) uwApph->
sn_ << endl;
399 <<
"::UWAPPLICATION::PAYLOAD_RECEIVED--> ";
415 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
416 <<
"::UWAPPLICATION::START_GENERATION_DATA" << endl;
419 <<
"::UWAPPLICATION::START_GENERATION_DATA" << endl;
426 Packet *p = Packet::alloc();
430 hdr_cmn *ch = hdr_cmn::access(p);
441 ch->direction() = hdr_cmn::DOWN;
465 (*uwApph).payload_msg[i] = RNG::defaultrng()->uniform(26) +
'a';
468 (*uwApph).payload_msg[i] =
'0';
472 (*uwApph).payload_msg[i] = RNG::defaultrng()->uniform(26) +
'a';
477 ch->timestamp() = Scheduler::instance().clock();
481 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
482 <<
"::UWAPPLICATION::INIT_PACKET::UID_" << ch->uid_ << endl;
484 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
485 <<
"::UWAPPLICATION::INIT_PACKET::DEST_"
486 << (int) uwiph->
daddr() << endl;
488 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
489 <<
"::UWAPPLICATION::INIT_PACKET::SIZE_"
492 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
493 <<
"::UWAPPLICATION::INIT_PACKET::SN_" << (int) uwApph->
sn_
496 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
497 <<
"::UWAPPLICATION::INIT_PACKET::SEND_DOWN_PACKET" << endl;
501 <<
"::UWAPPLICATION::INIT_PACKET::UID_" << ch->uid_ << endl;
504 <<
"::UWAPPLICATION::INIT_PACKET::DEST_" << (int) uwiph->
daddr()
508 <<
"::UWAPPLICATION::INIT_PACKET::SIZE_"
512 <<
"::UWAPPLICATION::INIT_PACKET::SN_" << (int) uwApph->
sn_
516 <<
"::UWAPPLICATION::INIT_PACKET::SEND_DOWN_PACKET" << endl;
541 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
542 <<
"::UWAPPLICATION::ERROR_TIMER SET TO NEGATIVE VALUE"
548 double u = RNG::defaultrng()->uniform_double();
549 double lambda = 1.0 /
PERIOD;
552 <<
"[" <<
getEpoch() <<
"]::" << NOW
553 <<
"::UWAPPLICATION::PACKET_GENERATED_WITH_POISSON_PERIOD_"
557 <<
"::UWAPPLICATION::PACKET_GENERATED_WITH_POISSON_PERIOD_"
559 return (-log(u) / lambda);
563 std::cout <<
"[" <<
getEpoch() <<
"]::" << NOW
564 <<
"::UWAPPLICATION::PACKET_GENERATED_WITH_FIXED_PERIOD_"
568 <<
"::UWAPPLICATION::PACKET_GENERATED_WITH_FIXED_PERIOD_"
TclObject * create(int, const char *const *)
Creates the TCL object needed for the TCL language interpretation.
uwApplicationModuleClass()
Constructor of uwApplicationModuleClass class.
virtual void expire(Event *e)
virtual bool withoutSocket()
Verify if the communication take place with socket or the data payload is generated in a randomly way...
virtual void stop()
Close the socket connection in the case the communication take place with socket, otherwise stop the ...
int rttsamples
Number of RTT samples.
double sumftt2
Sum of (FTT^2).
int hrsn
Highest received sequence number.
virtual void incrPktOoseq()
Increase the number of DATA packets received out of order by the server.
virtual void init_Packet()
Set all the field of the DATA packet that must be send down after the creation to the below level.
virtual void updateRTT(const double &rtt)
Update the RTT after the reception of a new packet.
virtual double getTimeBeforeNextPkt()
Compute the DATA generation rate, that can be constant and equal to the PERIOD established by the use...
virtual void recv(Packet *)
Handle the transmission of DATA packets between CBR layer and the below level.
double sumftt
Sum of FTT samples.
uwSendTimerAppl chkTimerPeriod
Timer that schedule the period between two successive generation of DATA packets.
uint32_t esn
Expected serial number.
int pkts_recv
Counter of the packets correctly received by the server.
int drop_out_of_order
Enable or not the ordering of data packet received 1 enabled 0 not enabled.
int servSockDescr
socket descriptor for server
double sumrtt
Sum of RTT samples.
virtual void start_generation()
Start the process to generate DATA packets without sockets.
int rftt
Forward trip time.
int debug_
Used for debug purposes 1 debug activated 0 debug not activated.
virtual void incrPktSent()
Increase the sequence number and so the number of packets sent by the server.
virtual ~uwApplicationModule()
Destructor of uwApplicationModule class.
virtual double GetRTT() const
Returns the average Round Trip Time.
double sumdt
Sum of the delays.
virtual double GetPER() const
Rerturn the Packet Error Rate calculated.
int fttsamples
Number of FTT samples.
virtual bool useDropOutOfOrder()
If the communication take place without sockets verify if the data packets received by the server is ...
virtual int getPktsOOSequence()
return the number of DATA packets received out of order by the server
virtual int openConnectionUDP()
When socket communication is used, this method establish a connection between client and server.
virtual int getPktRecv()
return the number of DATA packet correctly received by the server
virtual void updateFTT(const double &ftt)
Update the FTT after the reception of a new packet.
virtual void init_Packet_UDP()
Set all the field of DATA packet and take from the specific queue the payload of DATA packet that wil...
virtual double GetFTT() const
Returns the average Forward Trip Time.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
double PERIOD
Interval time between two successive generation data packets.
virtual double GetTHR() const
Return the Throughput calculated [bps].
int uidcnt
Identifier counter that identify uniquely the DATA packet generated.
double sumbytes
Sum of bytes received.
virtual int openConnectionTCP()
When socket communication is used, this method establish a connection between client and server.
double sumrtt2
Sum of (RTT^2).
virtual bool usePoissonTraffic()
If the communication take place without sockets verify if the data generation period is constant or i...
int pkts_lost
Counter of the packet lost during the transmission.
virtual int getPktSent()
return the number of packets sent by the server
int clnSockDescr
*socket descriptor for client
unsigned long int getEpoch()
Calculate the epoch of the event.
bool * sn_check
Used to keep track of the packets already received.
int payloadsize
Size of each data packet payaload generated.
virtual int getPktsPushQueue()
return the number of DATA packets sotred in the server queue
virtual int getPktLost()
return the number of DATA packets lost by the server
virtual void incrPktInvalid()
Increse the number of DATA packets received with error by the server.
virtual double GetRTTstd() const
Return the standard deviation of the Round Trip Time calculated.
uwApplicationModule()
Constructor of uwApplicationModule class.
virtual int getpayloadsize()
return the size of DATA packet payload
virtual void incrPktLost(const int &npkts)
Increase the number of DATA packets lost by the server.
std::ofstream out_log
Variable that handle the file in which the protocol write the statistics.
virtual void statistics(Packet *p)
Comupte some statistics as the number of packets sent and receive between two layer,...
static uint MAX_READ_LEN
Maximum size (bytes) of a single read of the socket.
int poisson_traffic
Enable or not the Poisson process for generation of data packets 1 enabled 0 not enabled.
int port_num
Number of the port in which the server provide the service.
uint8_t dst_addr
IP destination address.
virtual double getPeriod()
return period generation time
virtual bool useTCP()
If the communication take place using sockets verify if the protocol used is TCP or UDP.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
virtual void init_Packet_TCP()
Set all the field of DATA packet and take from the specific queue the payload of DATA packet that wil...
int txsn
Transmission sequence number of DATA packet.
virtual void incrPktRecv()
Increase the number of DATA packet correctly received by the server.
virtual double GetFTTstd() const
Return the standard deviation of the Forward Trip Time calculated.
virtual void updateThroughput(const int &bytes, const double &dt)
Update the Throughput after the reception of a new packet.
double lrtime
Time of last packet reception.
virtual int getPktsInvalidRx()
return the number of DATA packets received with error by the server
Content header of TRIGGER packet.
int rftt_
Forward Trip Time of the packet.
char payload_msg[MAX_LENGTH_PAYLOAD]
Message payload.
int & rftt()
Reference to the rftt_ variable.
uint16_t sn_
Serial number of the packet.
bool rftt_valid_
Flag used to set the validity of the fft field.
uint16_t & payload_size()
uint8_t priority_
Priority flag: 1 means high priority, 0 normal priority.
hdr_uwip describes UWIP packets.
uint8_t & daddr()
Reference to the daddr_ variable.
static hdr_uwip * access(const Packet *p)
hdr_uwudp describes UWUDP packets.
static struct hdr_uwudp * access(const Packet *p)
uint8_t & dport()
Reference to the dport_ variable.
uwApplicationModuleClass class_module_uwapplicationmodule
packet_t PT_DATA_APPLICATION
Trigger packet type for UFetch protocol.
#define UWAPPLICATION_DROP_REASON_OUT_OF_SEQUENCE
Drop the packet.
#define UWAPPLICATION_DROP_REASON_UNKNOWN_TYPE
Drop the packet.
#define UWAPPLICATION_DROP_REASON_DUPLICATED_PACKET
Drop the packet.