Main Page | Class Hierarchy | Class List | File List | Class Members

LossyReceivingPort Class Reference

A receiving port simulating link loss and delay. More...

#include <common.h>

Inheritance diagram for LossyReceivingPort:

ReceivingPort Port List of all members.

Public Member Functions

 LossyReceivingPort (float lossyratio)
PacketreceivePacket ()

Protected Attributes

float loss_ratio_
 how probable a packet will get dropped in receiving
int secdelay_
 how large is the link propagation delay.

Detailed Description

A receiving port simulating link loss and delay.

A receiving port which would random drop packets and delay packet reception in 1 second.

Definition at line 390 of file common.h.

Constructor & Destructor Documentation

LossyReceivingPort::LossyReceivingPort float  lossyratio  ) 

Constructor with parameter (drop probability p) Using a fixed link delay: 1 second

Definition at line 507 of file common.cpp.

00507                                                       : ReceivingPort(), loss_ratio_(lossyratio),secdelay_(1)
00508 {
00509 }

Member Function Documentation

Packet * LossyReceivingPort::receivePacket  ) 

Simulate link delay of 1 seconds. Drop packets with a propabilty equal to loss_ratio

Reimplemented from ReceivingPort.

Definition at line 514 of file common.cpp.

References loss_ratio_, ReceivingPort::receivePacket(), and secdelay_.

00515 {   
00516   Packet *p = ReceivingPort::receivePacket();
00517   //simulate some delay
00518   sleep(secdelay_); //delay
00519   float  x;
00520   // Set evil seed (initial seed)
00521   srand( (unsigned)time( NULL ) );
00522   x = (double) rand()/RAND_MAX;
00523   //cout << x << endl;
00524   if ( x <= loss_ratio_) 
00525     return NULL;
00526   else
00527     return p;
00528 }

The documentation for this class was generated from the following files:
Generated on Fri Feb 17 17:55:49 2006 for Common_Classes_Projects_ECE544 by  doxygen 1.4.2