RTPSession Class Reference

#include <rtp.h>

List of all members.

Public Member Functions

 RTPSession ()
 ~RTPSession ()
virtual void timeout (int)
virtual void recv (Packet *p, Handler *)
virtual void recv_ctrl (Packet *p)
int command (int argc, const char *const *argv)
u_int32_t srcid ()
int build_report (int bye)
void localsrc_update (int)
void update_rate ()
void localsrc_update_nbytes (int n)
void smooth_rate (double rate)
int build_sdes ()
int build_bye ()
hdr_rtpaccess_hdr_rtp ()
void print_rcvs ()
void print_srcs ()
void start_timer ()
void stop_timer ()

Public Attributes

RTPSessionnext
RTPSourceallsrcs_
RTPSourcelocalsrc_
RTPReceiverreceivers_
SimStreamstream_
int last_np_
int enableFlowControl_
double rx_recv_
double jitter_
double smooth_rate_
SenderTimer sender_timer_

Protected Member Functions

RTPSourcelookup (u_int32_t)
RTPReceiverlookup_rcv (u_int32_t)
void enter (RTPSource *)
void enter_rcv (RTPReceiver *)
void calculate_RTT ()
void increase_rate (int a)
void measure_smooth_loss (double n)
void calculateR_tcp (int a)
void initial_rate (double a)
void remove_receiver (RTPReceiver *)
void calculate_alpha (double value)
void evaluate_jitter (double value)
void remove_sender (RTPSource *)
void setInst_tx (double newValue)
void average_tx ()
void slow_start ()

Protected Attributes

list< double > lst
double T_one_way_
hdr_rtprh_
int we_sent
double RTT_
double weight [8]
double pkt_loss_history [8]
double smooth_loss_
int last_pkts_lost_
int last_ehsr_
double tx_rate_
double time_elapsed_
double last_time_report_
double alpha
double smooth_factor
list< double > jitter_lst
double z_score
double low_
double high_
int level_
double avg_tx_
list< double > tx_lst
int running_


Detailed Description

the session class is the heart of the RTP protocol. all main functions can be found here. Any extension to the RTP code should reference this class

Definition at line 300 of file rtp.h.


Constructor & Destructor Documentation

RTPSession::RTPSession (  ) 

zero argument constructor

Definition at line 83 of file session-rtp.cc.

References alpha, avg_tx_, enableFlowControl_, high_, jitter_, last_time_report_, level_, low_, NOW, RTT_, rx_recv_, smooth_factor, smooth_loss_, smooth_rate_, weight, and z_score.

00084         : allsrcs_(0), localsrc_(0), receivers_(0),stream_(0),last_np_(0),sender_timer_(this), T_one_way_(0),rh_(0),
00085         we_sent(0),last_pkts_lost_(0),last_ehsr_(-1),tx_rate_(0), time_elapsed_(0),running_(0)
00086 {
00087         bind("enableFlowControl_", &enableFlowControl_);
00088         bind("rx_recv_",&rx_recv_);
00089         bind("jitter_",&jitter_);
00090         bind("RTT_",&RTT_);
00091         bind("z_score",&z_score);
00092         bind("smooth_loss_",&smooth_loss_);
00093         bind("level_",&level_);
00094         smooth_rate_ = 0;
00095         alpha = 1;
00096         smooth_factor = 0.9;
00097         last_time_report_ = NOW;
00098         low_ = 0;
00099         high_= 0;
00100         avg_tx_ = 0;
00101         
00102         weight[0] = 1;
00103         weight[1] = 1;
00104         weight[2] = 1;
00105         weight[3] = 1;
00106         weight[4] = 0.8;
00107         weight[5] = 0.6;
00108         weight[6] = 0.4;
00109         weight[7] = 0.2;
00110 }

RTPSession::~RTPSession (  ) 

destructor

Definition at line 115 of file session-rtp.cc.

References allsrcs_, localsrc_, lst, RTPReceiver::next, RTPSource::next, receivers_, and tx_lst.

00116 {
00117         while (allsrcs_ != 0) {
00118                 RTPSource* p = allsrcs_;
00119                 allsrcs_ = allsrcs_->next;
00120                 delete p;
00121         }
00122         delete localsrc_;
00123         while (receivers_ != 0) {
00124                 RTPReceiver* p = receivers_;
00125                 receivers_ = receivers_->next;
00126                 delete p;
00127         }
00128         lst.~list<double>();
00129         tx_lst.~list<double>();
00130         
00131 }


Member Function Documentation

void RTPSession::timeout ( int   )  [virtual]

Definition at line 904 of file session-rtp.cc.

References average_tx(), avg_tx_, level_, running_, sender_timer_, SimStream::setAvg_tx(), stream_, and TIMER_TIMEOUT.

Referenced by SenderTimer::expire().

00905 {
00906         if(running_) { 
00907                 average_tx();
00908                 stream_->setAvg_tx(avg_tx_,level_);
00909                 sender_timer_.resched(TIMER_TIMEOUT);
00910         } 
00911 }

void RTPSession::recv ( Packet *  p,
Handler *   
) [virtual]

this method accesses the RTP packets it adds a newly heard source, which is the originator of the RTP packet, calculates the one way trip time and calls the calculate_RTT(T_one_way_ , eff_rtt) method for the RTT calculation. It measures also the delay jitter time of the RTP packets. Use this method to update any wished field of the Source class instances

Parameters:
p the RTP packet that just received by the RTP Agent
 

Definition at line 308 of file session-rtp.cc.

References hdr_rtp::access(), SimStream::compare(), RTPSource::cum_pkts_lost(), RTPSource::ehsr(), evaluate_jitter(), RTPSource::jitter(), jitter_, last_ehsr_, localsrc_, lookup(), RTPSource::nbytes(), NOW, RTPSource::np(), RTPSource::ps(), hdr_rtp::seqno(), RTPSource::srcid(), hdr_rtp::srcid(), stream_, hdr_rtp::T_epoch(), T_one_way_, hdr_rtp::timestamp(), and RTPSource::transit().

Referenced by RTPAgent::recv().

00309 {
00310 
00311         hdr_cmn* mh = hdr_cmn::access(p);
00312         hdr_rtp* rh = hdr_rtp::access(p);
00313         RTPSource* s = lookup(rh->srcid());
00314 
00315         if (s == 0) {
00316                 if(rh->srcid()!=localsrc_->srcid()){
00317                         Tcl& tcl = Tcl::instance();
00318                         tcl.evalf("%s new-source %d", name(),rh->srcid());
00319                         s = (RTPSource*)TclObject::lookup(tcl.result());
00320                         last_ehsr_ = rh->seqno();
00321                 }
00322         }
00323         if(rh->srcid()!=localsrc_->srcid())
00324         {
00325                 // calculate one way trip time
00326                 T_one_way_ = NOW - rh->timestamp();
00327                 // count packet losses
00328                 int pkts_lost = 0;
00329                 int difference =  rh->seqno() - s->ehsr();  
00330                 if (difference <= 1) { // to deal with the first RTP packet in which s->ehrs() = -1
00331                         pkts_lost = 0;
00332                         
00333                 }
00334                 
00335                 if (difference > 1) {
00336                         pkts_lost = difference -1;
00337                         
00338                 }
00339                 // calculate delay jitter, see RFC 3550 Appendix A8
00340                 double transit = NOW - rh->timestamp();
00341                 double d = transit - s->transit();
00342                 s->transit(transit);
00343                 if (d < 0) d = -d;
00344                 s->jitter( s->jitter() + (1./16.) * (d - s->jitter()));
00345                 evaluate_jitter(s->jitter());
00346                 jitter_ = s->jitter();
00347 //              printf("jitter %f \n",s->jitter());
00348                 s->np(1); // counts the packets that I have received from sender s
00349                 s->cum_pkts_lost(pkts_lost);// counts the packets that I have lost from sender s
00350                 s->ehsr(rh->seqno());// the first ehsr = -1
00351                 s->nbytes(mh->size()); // counts the number of bytes that I have lost from sender s
00352                 s->ps(mh->size());// the packet size in bytes
00353                 if(rh->T_epoch() == 1) {
00354                         stream_->compare();
00355                 }
00356         }
00357         Packet::free(p);
00358 }

void RTPSession::recv_ctrl ( Packet *  p  )  [virtual]

the function that accesses and exploits the SR and RR here is where the sender calculates the effective RTT time based on the receiver's RR. The sender also updates its transmission rate based on the receivers' RR. We don't exploit the SR in this implementation but a third party eg a network controller can exploit both SR and RR, witout in fact joining the session

Parameters:
p the RTCP packet

Definition at line 526 of file session-rtp.cc.

References hdr_rtp::access(), receiver_report::bye(), calculate_alpha(), receiver_report::DLSR(), RTPReceiver::eff_rtt(), sr_extensions::eff_rtt(), enableFlowControl_, enter_rcv(), sender_report::high_tx(), RTPSource::is_sender(), localsrc_, lookup(), lookup_rcv(), sender_report::low_tx(), receiver_report::LSR(), RTPSource::LSR(), sender_report::medium_tx(), RTPReceiver::next, sr_extensions::next, NOW, receiver_report::R_tcp(), RTPReceiver::rate(), receivers_, remove_receiver(), hdr_rtp::rr_, sender_report::s_ext_, sender_report::sender_srcid(), SimStream::setHigh_tx(), SimStream::setLow_tx(), SimStream::setMedium_tx(), slow_start(), hdr_rtp::sr_, RTPReceiver::srcid(), sr_extensions::srcid(), hdr_rtp::srcid(), RTPSource::srcid(), RTPSource::SRT(), stream_, hdr_rtp::timestamp(), and update_rate().

Referenced by RTCPAgent::recv().

00527 {
00528         hdr_cmn* mh = hdr_cmn::access(p);
00529         hdr_rtp* rh = hdr_rtp::access(p);
00530         u_int32_t local_src = localsrc_->srcid();
00531         
00532         if(rh->srcid() != local_src) {
00533         
00534                 if (rh->sr_ != 0) { // get the Sender report
00535                         RTPSource* source = lookup(rh->sr_->sender_srcid());
00536                         if (source != 0 && source->srcid()!= local_src) {
00537                                 source->LSR(rh->timestamp());
00538                                 source->SRT(NOW);
00539                                 stream_->setLow_tx(rh->sr_->low_tx());
00540                                 stream_->setMedium_tx(rh->sr_->medium_tx());
00541                                 stream_->setHigh_tx(rh->sr_->high_tx());
00542                                 if(rh->sr_->s_ext_ != 0) {
00543                                 sr_extensions* se = new sr_extensions;
00544                                 for (se = rh->sr_->s_ext_; se != 0; se = se->next) {
00545 
00546                                         if(se->srcid()==localsrc_->srcid()) {
00547                                         
00548                                                 if(se->eff_rtt() == 0) {
00549                                                         calculate_alpha(0);
00550                                                 } else calculate_alpha(se->eff_rtt());
00551                                         }
00552                                                 
00553                                 }// end for
00554                                 }
00555                                 
00556                         }
00557                 }
00558 
00559                 if(localsrc_->is_sender()){ // get the Receiver report
00560 
00561                                 if(rh->rr_ != 0){
00562                                         RTPReceiver* s = lookup_rcv(rh->srcid());
00563                                                 
00564                                                 if (s != 0) {
00565                                                         for (s = receivers_; s!= 0; s = s->next) {
00566                 
00567                                                                 if(rh->srcid() == s->srcid()) {
00568                                                                         
00569                                                                         double eff_rtt = 0.0;
00570                                                                 
00571                                                                         if(rh->rr_->LSR()!=0) {
00572                                                                         eff_rtt = NOW - rh->rr_->LSR() - rh->rr_->DLSR();
00573                                                                         }
00574                                                                         s->eff_rtt(eff_rtt);
00575                                                                         s->rate(rh->rr_->R_tcp());
00576                                                                         if(rh->rr_->bye() == 1) {
00577                                                                                 remove_receiver(s);
00578                                                                         }
00579                                                                         
00580                                                                 }       
00581 
00582                                                         } // end for loop
00583                                                         if(enableFlowControl_ == 1 && receivers_) {
00584                                                                 update_rate();
00585                                                                 } else {
00586                                                                         printf("TIME: %f Sender %d NOT HAVING RECEIVERS \n", NOW,localsrc_->srcid());
00587                                                                         slow_start();
00588                                                                         
00589                                                                         }
00590                                                 } //end if
00591                                                 else {
00592                                                         s = new RTPReceiver(rh->srcid());
00593                                                         enter_rcv(s);
00594                                                 }
00595                                                 
00596                                         }
00597                                 }
00598         }
00599 
00600         Tcl::instance().evalf("%s sample-size %d", name(), mh->size());
00601         Packet::free(p);
00602 }

int RTPSession::command ( int  argc,
const char *const *  argv 
)

the command function that handles TCL commands

Definition at line 826 of file session-rtp.cc.

References enter(), high_, initial_rate(), localsrc_, low_, and stream_.

00827 {
00828         if (argc == 3) {
00829                 if (strcmp(argv[1], "enter") == 0) {
00830                         RTPSource* s = (RTPSource*)TclObject::lookup(argv[2]);
00831                         enter(s);
00832                         return (TCL_OK);
00833                 }
00834                 if (strcmp(argv[1], "localsrc") == 0) {
00835                         localsrc_ = (RTPSource*)TclObject::lookup(argv[2]);
00836                         enter(localsrc_);
00837                         return (TCL_OK);
00838                 }
00839                 if (strcmp(argv[1], "rate") == 0) {
00840                         initial_rate(atoi(argv[2]));
00841                         return(TCL_OK);
00842                 }
00843                 if (strcmp(argv[1], "stream") == 0) {
00844                         stream_ = (SimStream*)TclObject::lookup(argv[2]);
00845                         return (TCL_OK);
00846                 }
00847         }
00848         if (argc == 4) {
00849                 if (strcmp(argv[1], "bw-limits") == 0) {
00850                         low_ = atoi(argv[2])/8;
00851                         high_ = atoi(argv[3])/8;
00852                         return(TCL_OK);
00853                 }
00854         }
00855 
00856         return (TclObject::command(argc, argv));
00857 }

u_int32_t RTPSession::srcid (  )  [inline]

Definition at line 313 of file rtp.h.

References localsrc_, and RTPSource::srcid().

Referenced by SimStream::enter(), RTPAgent::makepkt(), and RTCPAgent::sendpkt().

00313 { return (localsrc_->srcid()); }

int RTPSession::build_report ( int  bye  ) 

the method for creating the SR and RR reports the "heart" of the RTCP protocol

Parameters:
bye if there is a bye event
Returns:
the length of this report in bytes

Definition at line 167 of file session-rtp.cc.

References allsrcs_, build_bye(), build_sdes(), receiver_report::bye(), calculate_RTT(), calculateR_tcp(), receiver_report::cum_pkts_lost(), receiver_report::DLSR(), RTPReceiver::eff_rtt(), sr_extensions::eff_rtt(), SimStream::getAvg_rx(), SimStream::getHigh_tx(), SimStream::getLow_tx(), SimStream::getMedium_tx(), sender_report::high_tx(), increase_rate(), receiver_report::jitter(), last_ehsr_, last_np_, last_time_report_, localsrc_, sender_report::low_tx(), receiver_report::LSR(), measure_smooth_loss(), sender_report::medium_tx(), RTPSource::nbytes(), RTPSource::next, sr_extensions::next, RTPReceiver::next, NOW, RTPSource::np(), sender_report::octets_sent(), sender_report::pkts_sent(), receiver_report::R_tcp(), receivers_, remove_sender(), rh_, hdr_rtp::rr_, RTCP_HDRSIZE, RTCP_RR_SIZE, RTCP_SR_SIZE, receiver_report::rx(), rx_recv_, sender_report::s_ext_, sender_report::sender_srcid(), SimStream::setRcv_rate(), smooth_rate_, hdr_rtp::sr_, RTPReceiver::srcid(), sr_extensions::srcid(), RTPSource::srcid(), stream_, time_elapsed_, and we_sent.

Referenced by RTCPAgent::command(), and RTCPAgent::timeout().

00168 {
00169 //printf("INSIDE BUILD REPORT TIME: %f Local %d  \n", NOW,localsrc_->srcid());
00170 
00171         rh_ = new hdr_rtp;
00172         rh_->rr_ = 0;
00173         rh_->sr_ = 0;
00174         
00175         int nsrc = 0;
00176         int nrr = 0;
00177         int len = RTCP_HDRSIZE;
00178         we_sent = 0;
00179         double fraction = 0.0;
00180         time_elapsed_ = NOW - last_time_report_;
00181         last_time_report_ = NOW;
00182         if (localsrc_->np() != last_np_) {
00183                 last_np_ = localsrc_->np();
00184                 we_sent = 1;
00185                 len += RTCP_SR_SIZE;
00186                 //add sender report
00187                 sender_report* sr;
00188                 //fill the report
00189                 sr = new sender_report;
00190                 sr->s_ext_ = 0;
00191                 sr->sender_srcid()= localsrc_->srcid();
00192                 sr->pkts_sent() = localsrc_->np();
00193                 sr->octets_sent() = localsrc_->nbytes();
00194                 sr->low_tx()=stream_->getLow_tx();
00195                 sr->medium_tx()=stream_->getMedium_tx();
00196                 sr->high_tx()=stream_->getHigh_tx();
00197                 RTPReceiver *p;
00198                 for (p = receivers_; p != 0; p = p->next) {
00199                         sr_extensions* se = new sr_extensions;
00200                         se->srcid()=p->srcid();
00201                         se->eff_rtt()=p->eff_rtt();
00202                         se->next = sr->s_ext_;
00203                         sr->s_ext_ = se;
00204                 }
00205                 //store the report
00206                 rh_->sr_ = sr;
00207         }
00208         for (RTPSource* sp = allsrcs_; sp != 0; sp = sp->next) {
00209                 ++nsrc;
00210                 int received = sp->np() - sp->snp();
00211 
00212                 if (received == 0) {
00213 
00214                         continue;
00215                 }
00216                 if(localsrc_->srcid() != sp->srcid()) {
00217 
00218                 int bytes = received * (sp->ps());
00219                 rx_recv_ = ( 8 * (double)bytes)/time_elapsed_;
00220                 stream_->setRcv_rate(rx_recv_);
00221                 sp->snp(sp->np());
00222                 len += RTCP_RR_SIZE;
00223                 // calculate loss fraction since previous report
00224                 int expected_interval  = sp->ehsr() - last_ehsr_;
00225                 last_ehsr_ = sp->ehsr();
00226                 int lost_interval = expected_interval -  received;
00227 
00228 
00229                 if (lost_interval <= 0 || expected_interval == 0 ) {
00230                          fraction = 0;
00231 
00232                 } else fraction = ((double)lost_interval  / (double)expected_interval);
00233                 calculate_RTT();
00234                 // Update the R_tcp according to fraction value
00235                 if( sp->np() >= 1) {// I have already received RTP packets from the source
00236                         if(fraction == 0) {
00237                                 increase_rate(sp->ps());
00238 
00239                         }       else /*if(fraction != 0)*/ {
00240                                         measure_smooth_loss(fraction);
00241                                         calculateR_tcp(sp->ps());
00242                                 }
00243                 }
00244                 //add receiver report
00245                 receiver_report* rr;
00246                 rr = new receiver_report;
00247                 //fill the report
00248                 rr->cum_pkts_lost() = sp->cum_pkts_lost();
00249                 rr->LSR() = sp->LSR();
00250                 rr->DLSR()= Scheduler::instance().clock() - sp->SRT();
00251                 rr->R_tcp() = smooth_rate_;
00252                 rr->jitter() = sp->jitter();
00253                 rr->rx()=stream_->getAvg_rx();
00254                 if(bye) {
00255                 rr->bye()= 1;
00256                 remove_sender(sp);
00257                 } else rr->bye() = 0;
00258                 
00259                 rh_->rr_ = rr;
00260 
00261                 if (++nrr >= 31)
00262                         break;
00263                 } // end if
00264 
00265         }// end for loop
00266 
00267 
00268         if (bye) {
00269                 len += build_bye();
00270                 }
00271         else
00272                 len += build_sdes();
00273 
00274         Tcl::instance().evalf("%s adapt-timer %d %d %d", name(),
00275                               nsrc, nrr, we_sent);
00276         Tcl::instance().evalf("%s sample-size %d", name(), len);
00277 
00278         return (len);
00279 }

void RTPSession::localsrc_update ( int   ) 

it is called when the RTPAgent sends a RTP packet and updates the number of packets (np) field of the originator of the RTP packet

Parameters:
int the packet to be added

Definition at line 139 of file session-rtp.cc.

References RTPSource::is_sender(), localsrc_, and RTPSource::np().

Referenced by RTPAgent::timeout().

00140 {
00141         localsrc_->np(1);
00142         localsrc_->is_sender(true);
00143 }

void RTPSession::update_rate (  ) 

this method compares the reported TCP friendly bandwidth by the receivers and calls the session_bw and transmit methods in session-rtp.tcl class to adjust the sender's transmission rate The adjustment in the transmission rate occures after the sender receives reports from all the receivers. r_tcp, is the receiver estimation of the TCP friendly bandwidth

Definition at line 612 of file session-rtp.cc.

References high_, low_, lst, RTPReceiver::next, RTPReceiver::rate(), receivers_, setInst_tx(), and tx_rate_.

Referenced by recv_ctrl().

00613 {
00614         RTPReceiver* s;
00615         for (s = receivers_; s!= 0; s = s->next) {
00616                 if(s->rate() > 0) {
00617                         lst.push_front(s->rate());
00618                 }
00619         }
00620         lst.sort();
00621         double inst_tx =lst.front();
00622         lst.clear();
00623         if(inst_tx != tx_rate_) {
00624                 tx_rate_ = inst_tx;
00625                 if(tx_rate_ <=  low_) {
00626                         tx_rate_ = low_;
00627                 }
00628                 if(tx_rate_ > high_) {
00629                         tx_rate_ =  high_;
00630                 }
00631         setInst_tx(tx_rate_);   
00632         Tcl::instance().evalf("%s session_bw %fb/s",name(),8*tx_rate_);
00633         Tcl::instance().evalf("%s transmit %fb/s",name(),8*tx_rate_);
00634         }
00635 }

void RTPSession::localsrc_update_nbytes ( int  n  ) 

it is called when the RTPAgent sends a RTP packet and updates the number of number of bytes (nbytes) field of the originator of the RTP packet

Parameters:
n the bytes to be added

Definition at line 151 of file session-rtp.cc.

References localsrc_, and RTPSource::nbytes().

Referenced by RTPAgent::timeout().

00152 {
00153         localsrc_->nbytes(n);
00154         
00155 }

void RTPSession::smooth_rate ( double  inst_tx  ) 

this is the filter function for the smooth transmission rate measurement

Parameters:
inst_tx the current transmission rate estimation by the RTP receiver

Definition at line 509 of file session-rtp.cc.

References SimStream::setInst_rx_rate(), smooth_factor, smooth_rate_, and stream_.

Referenced by calculateR_tcp(), and increase_rate().

00510 {
00511         smooth_rate_ = smooth_factor * inst_tx + smooth_rate_ * (1 - smooth_factor);
00512         stream_->setInst_rx_rate(smooth_rate_);
00513 }

int RTPSession::build_sdes (  ) 

not implemented yet. It only returns 20 bytes that are to be added to the RTCP report

Definition at line 292 of file session-rtp.cc.

Referenced by build_report().

00293 {
00294 
00295         /* XXX We'll get to this later... */
00296         return (20);
00297 }

int RTPSession::build_bye (  ) 

it is called upon a bye event returns 8 bytes length

Definition at line 284 of file session-rtp.cc.

Referenced by build_report().

00285 {
00286         
00287         return (8);
00288 }

hdr_rtp * RTPSession::access_hdr_rtp (  ) 

accesses the RTP packet header

Returns:
, the

Definition at line 655 of file session-rtp.cc.

References rh_.

Referenced by RTCPAgent::sendpkt().

00656 {
00657         return rh_;
00658 }

void RTPSession::print_rcvs (  ) 

for debugging, prints all the receivers that a source serves

Definition at line 698 of file session-rtp.cc.

References RTPReceiver::next, receivers_, and RTPReceiver::srcid().

00699 {
00700 
00701         RTPReceiver *p;
00702         for (p = receivers_; p != 0; p = p->next)
00703         {
00704             printf("Receiver:%d\n", p->srcid());
00705         }
00706 }

void RTPSession::print_srcs (  ) 

for debugging, prints all the sources that a receiver listens

Definition at line 711 of file session-rtp.cc.

References allsrcs_, RTPSource::next, and RTPSource::srcid().

00712 {
00713 
00714         RTPSource* s;
00715         for (s = allsrcs_; s != 0; s = s->next)
00716         {
00717             printf("Source:%d\n", s->srcid());
00718         }
00719 }

void RTPSession::start_timer (  ) 

Definition at line 888 of file session-rtp.cc.

References INITIAL_TIMEOUT, running_, and sender_timer_.

Referenced by RTPAgent::start().

00889 {
00890         running_ = 1;
00891         sender_timer_.resched(INITIAL_TIMEOUT);
00892 
00893 }

void RTPSession::stop_timer (  ) 

Definition at line 895 of file session-rtp.cc.

References running_, and sender_timer_.

Referenced by RTPAgent::stop().

00896 {
00897         running_ = 0;
00898         sender_timer_.force_cancel();
00899         
00900 }

RTPSource * RTPSession::lookup ( u_int32_t  srcid  )  [protected]

it checks if the source has heard

Parameters:
srcid the source id of this source
Returns:
the source of the RTP packet if it exists, zero otherwise

Definition at line 666 of file session-rtp.cc.

References allsrcs_, RTPSource::next, and RTPSource::srcid().

Referenced by recv(), and recv_ctrl().

00667 {
00668         RTPSource *p;
00669         for (p = allsrcs_; p != 0; p = p->next)
00670         {       
00671                 if (p->srcid() == srcid)
00672                         return (p);
00673         }
00674         return (0);
00675 }

RTPReceiver * RTPSession::lookup_rcv ( u_int32_t  srcid  )  [protected]

Check if the receiver exists in the sender's list

Parameters:
srcid the source id of this receiver
Returns:
the receiver if it exists, zero otherwise

Definition at line 683 of file session-rtp.cc.

References RTPReceiver::next, receivers_, and RTPReceiver::srcid().

Referenced by recv_ctrl().

00684 {
00685 
00686         RTPReceiver *p;
00687         for (p = receivers_; p != 0; p = p->next)
00688         {
00689                 if (p->srcid() == srcid)
00690                         return (p);
00691         }
00692         return (0);
00693 }

void RTPSession::enter ( RTPSource s  )  [protected]

enter a new source

Parameters:
s the new RTPSource

Definition at line 726 of file session-rtp.cc.

References allsrcs_, and RTPSource::next.

Referenced by command().

00727 {
00728         
00729         s->next = allsrcs_;
00730         allsrcs_ = s;
00731 }

void RTPSession::enter_rcv ( RTPReceiver s  )  [protected]

enter a new receiver

Parameters:
s the new RTPReceiver

Definition at line 737 of file session-rtp.cc.

References localsrc_, RTPReceiver::next, NOW, receivers_, RTPReceiver::srcid(), and RTPSource::srcid().

Referenced by recv_ctrl().

00738 {
00739         printf("Time:%f Sender:%d ...I add receiver %d \n", NOW,localsrc_->srcid(), s->srcid());
00740         s->next = receivers_;
00741         receivers_ = s;
00742         
00743 }

void RTPSession::calculate_RTT (  )  [protected]

calculates the RTT time one_way is the one way trip time eff is the effective RTT time measured and reported by the sender of the RTP packets

Parameters:
eff,the effective RTT time measured by the sender

Definition at line 427 of file session-rtp.cc.

References alpha, RTT_, and T_one_way_.

Referenced by build_report().

00428 {
00429         double temp = (1+alpha) * T_one_way_;
00430  //     RTT_ = temp * 0.5 + 0.5 * RTT_;
00431         RTT_ = temp * 0.1 + 0.9 * RTT_;   //taken from RFC 3448
00432 }

void RTPSession::increase_rate ( int  ps  )  [protected]

the estimation made by the receiver of the transmission rate when fraction loss is zero. The increase is not higher than 1 RTP packet/current rate in bytes/sec sample_tx is the current estimation of the RTP receiver. We pass this value from the filter

Parameters:
ps,the packet size of the RTP packet

Definition at line 442 of file session-rtp.cc.

References RTT_, smooth_rate(), and smooth_rate_.

Referenced by build_report().

00443 {
00444         double sample_tx = smooth_rate_ +  (double)ps/RTT_;
00445         // pass sample_tx from the filter
00446         smooth_rate(sample_tx);
00447 }

void RTPSession::measure_smooth_loss ( double  fraction  )  [protected]

measure_smooth_loss is called when the last measured by the receiver loss fraction is not zero.

Parameters:
fraction the fraction of lost RTP packets/expected RTP packets since last RR

Definition at line 455 of file session-rtp.cc.

References pkt_loss_history, smooth_loss_, and weight.

Referenced by build_report().

00456 {
00457         
00458         double I_tot0 = 0;
00459         double I_tot1 = 0;
00460         double W_tot = 0;
00461         for (int i=0; i<7; i++) {
00462         pkt_loss_history[i+1]= pkt_loss_history[i];
00463         }
00464         pkt_loss_history[0] = fraction;
00465 
00466         for (int i=0; i<7; i++) {
00467         I_tot0 = I_tot0+ (pkt_loss_history[i] * weight[i]);
00468         W_tot = W_tot +  weight[i];
00469         }
00470 
00471         for (int i=1; i<8; i++) {
00472         I_tot1 = I_tot1 + (pkt_loss_history[i] * weight[i-1]);
00473         }
00474         double I_tot =0;
00475         if( I_tot0 > I_tot1) {
00476         I_tot = I_tot0;
00477         } else {
00478         I_tot = I_tot1;
00479         }
00480         double  I_mean = I_tot/W_tot;
00481 
00482         smooth_loss_= I_mean;
00483 }

void RTPSession::calculateR_tcp ( int  ps  )  [protected]

calculates the TCP friendly bandwidth share

Parameters:
ps is the size of the RTP packet

Definition at line 489 of file session-rtp.cc.

References RTT_, smooth_loss_, and smooth_rate().

Referenced by build_report().

00490 {
00491 
00492         double min =0;
00493         double fraction = 3 * sqrt((3 * smooth_loss_) / 8);
00494         if(fraction <  1 ){
00495                 min = fraction;
00496         }       else min =1;
00497         // TCP friendly BW share equation
00498         double sample_tx = (double)ps / (RTT_ *  (sqrt(2 * smooth_loss_ /3)) + 4 * (RTT_ * min * smooth_loss_) * (1 + (32 * pow(smooth_loss_,2))));
00499         // pass sample_tx from the filter
00500         smooth_rate(sample_tx);
00501 }

void RTPSession::initial_rate ( double  a  )  [protected]

it's good for the receiver to have a rough knowledge of the session rate

Parameters:
a the initial session rate

Definition at line 814 of file session-rtp.cc.

References smooth_rate_, and tx_rate_.

Referenced by command().

00815 {
00816         tx_rate_ =(double)a/8;
00817         smooth_rate_ = tx_rate_;
00818         
00819         
00820 }

void RTPSession::remove_receiver ( RTPReceiver p  )  [protected]

remove a receiver from a sender's list

Parameters:
p the RTPReceiver to be removed

Definition at line 749 of file session-rtp.cc.

References localsrc_, RTPReceiver::next, NOW, receivers_, RTPReceiver::srcid(), and RTPSource::srcid().

Referenced by recv_ctrl().

00750 {
00751 
00752         printf("Time:%f Sender:%d ...I remove receiver %d \n", NOW,localsrc_->srcid(),p->srcid());
00753         
00754         RTPReceiver* s;
00755         RTPReceiver* q;
00756         if (receivers_== p)
00757         {
00758                 q = receivers_;
00759                 receivers_= receivers_->next;
00760                 delete q;
00761         }
00762         else
00763         {
00764                 for (s = receivers_; s!=0; s=s->next)
00765                 {
00766                         if (s->next==p)
00767                         {
00768                                 q = s->next;
00769                                 s->next=q->next;
00770                                 delete q; 
00771                         }       
00772                 }
00773         }
00774 
00775 }

void RTPSession::calculate_alpha ( double  value  )  [protected]

the function that calculate the A value

Parameters:
value the effective RTT that is measured by the RTP sender

Definition at line 410 of file session-rtp.cc.

References alpha, and T_one_way_.

Referenced by recv_ctrl().

00411 {
00412 
00413         if( value == 0) {
00414                 alpha = 1;
00415         } else
00416         alpha = (value/T_one_way_) -1;
00417 }

void RTPSession::evaluate_jitter ( double  value  )  [protected]

This is a core function. It tunes our congestion controller based on network statistical information. We evaluate upcoming congestion by checking how far the new jitter value falls from the jitter stab=ndard deviation

Parameters:
value the newly measured jitter value

Definition at line 366 of file session-rtp.cc.

References CONGESTED, DELTA, jitter_, jitter_lst, LOADED, smooth_factor, UNLOADED, and z_score.

Referenced by recv().

00367 {
00368         jitter_ = 0.8 * value - 0.2 * jitter_;
00369         jitter_lst.push_front(jitter_);
00370         list<double> temp_lst;
00371         temp_lst = jitter_lst;
00372         int size = jitter_lst.size();
00373         double temp_array[size];
00374         double dev_array[size];
00375         double mean =0;
00376         double count =0;
00377         double std_dev =0;
00378         
00379         if (size >1) {
00380                 for (int i=0; i<size; i++) {
00381                         temp_array[i]=jitter_lst.front();
00382                         count += temp_array[i];
00383                         jitter_lst.pop_front();
00384                 }
00385                 mean = count/size;
00386                 count =0;
00387                 for (int j =0; j<size; j++) {
00388                         dev_array[j]=temp_array[j]-mean;
00389                         count+=pow(dev_array[j],2);
00390                 }
00391                 std_dev = sqrt(count/(size-1));
00392                 double temp = temp_lst.front();
00393                 z_score = (temp - mean)/std_dev;
00394                 
00395                 jitter_lst = temp_lst;
00396                 if(-DELTA < z_score < DELTA) {
00397                          smooth_factor = LOADED;
00398                 } else if ( z_score <= -DELTA) {
00399                          smooth_factor = UNLOADED;
00400                 } else smooth_factor = CONGESTED;
00401         }
00402 }

void RTPSession::remove_sender ( RTPSource p  )  [protected]

we remove this sender from the list upon a bye event

Parameters:
p the sender that has to be removed from our sources' list

Definition at line 781 of file session-rtp.cc.

References allsrcs_, localsrc_, RTPSource::next, and RTPSource::srcid().

Referenced by build_report().

00782 {
00783         
00784         if(p->srcid() != localsrc_->srcid()) {
00785         RTPSource* s;
00786         RTPSource* q;
00787         if (allsrcs_==p)
00788         {
00789                 q = allsrcs_;
00790                 allsrcs_= allsrcs_->next;
00791                 delete q;
00792         }
00793         else
00794         {
00795                 for (s = allsrcs_; s!=0; s=s->next)
00796                 {
00797                         if (s->next==p)
00798                         {
00799                                 q = s->next;
00800                                 s->next=q->next;
00801                                 delete q; 
00802                         }       
00803                 }
00804         }       
00805         
00806         }
00807 }

void RTPSession::setInst_tx ( double  newValue  )  [protected]

add the current transmission rate in the list

Parameters:
newValue the new instantaneous transmission rate

Definition at line 917 of file session-rtp.cc.

References tx_lst.

Referenced by slow_start(), and update_rate().

00918 {
00919         tx_lst.push_front(newValue);
00920 }

void RTPSession::average_tx (  )  [protected]

it averages the transmission rate over a period Δt (TIMER_TIMEOUT)

Definition at line 927 of file session-rtp.cc.

References avg_tx_, and tx_lst.

Referenced by timeout().

00928 {
00929         int size = tx_lst.size();
00930         double sum = 0;
00931         if(size > 1) {
00932         for(int i = 0; i<size; i++) {
00933                 sum += tx_lst.front();
00934                 tx_lst.pop_front();
00935         }
00936         avg_tx_ = sum/size;
00937         }       
00938 }

void RTPSession::slow_start (  )  [protected]

we start a slow start when all receivers have left the session

Definition at line 641 of file session-rtp.cc.

References low_, setInst_tx(), and tx_rate_.

Referenced by recv_ctrl().

00642 {       
00643         tx_rate_ = low_;
00644         setInst_tx(tx_rate_);   
00645         printf("Starting Slow start at ...%f\n", tx_rate_ * 8);
00646         Tcl::instance().evalf("%s session_bw %fb/s",name(),8*tx_rate_);
00647         Tcl::instance().evalf("%s transmit %fb/s",name(),8*tx_rate_);
00648 }


Member Data Documentation

Definition at line 304 of file rtp.h.

Referenced by SimStream::enter(), and SimStream::~SimStream().

Definition at line 324 of file rtp.h.

Referenced by build_report(), enter(), lookup(), print_srcs(), remove_sender(), and ~RTPSession().

Definition at line 327 of file rtp.h.

Referenced by build_report(), command(), recv(), recv_ctrl(), smooth_rate(), and timeout().

the last packet number

Definition at line 329 of file rtp.h.

Referenced by build_report().

zero by default

Definition at line 339 of file rtp.h.

Referenced by recv_ctrl(), and RTPSession().

the receiveing rate as it measured by the RTP receiver

Definition at line 341 of file rtp.h.

Referenced by build_report(), and RTPSession().

the jitter delay as is it measured by the RTP receiver

Definition at line 343 of file rtp.h.

Referenced by evaluate_jitter(), recv(), and RTPSession().

the smooth transmission rate

Definition at line 345 of file rtp.h.

Referenced by build_report(), increase_rate(), initial_rate(), RTPSession(), and smooth_rate().

Definition at line 347 of file rtp.h.

Referenced by start_timer(), stop_timer(), and timeout().

list<double> RTPSession::lst [protected]

a list to store values

Definition at line 359 of file rtp.h.

Referenced by update_rate(), and ~RTPSession().

double RTPSession::T_one_way_ [protected]

the one-way trip time

Definition at line 375 of file rtp.h.

Referenced by calculate_alpha(), calculate_RTT(), and recv().

hdr_rtp* RTPSession::rh_ [protected]

the rtp header

Definition at line 377 of file rtp.h.

Referenced by access_hdr_rtp(), and build_report().

int RTPSession::we_sent [protected]

true if the RTP sender sent packets since the last RTP SR

Definition at line 381 of file rtp.h.

Referenced by build_report().

double RTPSession::RTT_ [protected]

the RTT time

Definition at line 383 of file rtp.h.

Referenced by calculate_RTT(), calculateR_tcp(), increase_rate(), and RTPSession().

double RTPSession::weight[8] [protected]

weights for the smooth loss raton calculation

Definition at line 385 of file rtp.h.

Referenced by measure_smooth_loss(), and RTPSession().

double RTPSession::pkt_loss_history[8] [protected]

the array to keep the packet loss history

Definition at line 387 of file rtp.h.

Referenced by measure_smooth_loss().

double RTPSession::smooth_loss_ [protected]

the smooth loss ratio

Definition at line 389 of file rtp.h.

Referenced by calculateR_tcp(), measure_smooth_loss(), and RTPSession().

int RTPSession::last_pkts_lost_ [protected]

keeps the number of the last packets losts since the beginning of the session

Definition at line 391 of file rtp.h.

int RTPSession::last_ehsr_ [protected]

keeps the highest expected RTP sequence number

Definition at line 393 of file rtp.h.

Referenced by build_report(), and recv().

double RTPSession::tx_rate_ [protected]

the transmission rate that is measured by the receiver

Definition at line 395 of file rtp.h.

Referenced by initial_rate(), slow_start(), and update_rate().

double RTPSession::time_elapsed_ [protected]

time elapsed since the last RR (receiver report)

Definition at line 397 of file rtp.h.

Referenced by build_report().

double RTPSession::last_time_report_ [protected]

the time when the last RR was sent

Definition at line 399 of file rtp.h.

Referenced by build_report(), and RTPSession().

double RTPSession::alpha [protected]

the value A

Definition at line 401 of file rtp.h.

Referenced by calculate_alpha(), calculate_RTT(), and RTPSession().

double RTPSession::smooth_factor [protected]

defines the responsiveness of the protocol

Definition at line 407 of file rtp.h.

Referenced by evaluate_jitter(), RTPSession(), and smooth_rate().

list<double> RTPSession::jitter_lst [protected]

list to keep all jitter delay measurements

Definition at line 409 of file rtp.h.

Referenced by evaluate_jitter().

double RTPSession::z_score [protected]

z score for statistical measurements

Definition at line 411 of file rtp.h.

Referenced by evaluate_jitter(), and RTPSession().

double RTPSession::low_ [protected]

Definition at line 412 of file rtp.h.

Referenced by command(), RTPSession(), slow_start(), and update_rate().

double RTPSession::high_ [protected]

Definition at line 413 of file rtp.h.

Referenced by command(), RTPSession(), and update_rate().

int RTPSession::level_ [protected]

Definition at line 415 of file rtp.h.

Referenced by RTPSession(), and timeout().

double RTPSession::avg_tx_ [protected]

Definition at line 416 of file rtp.h.

Referenced by average_tx(), RTPSession(), and timeout().

list<double> RTPSession::tx_lst [protected]

Definition at line 418 of file rtp.h.

Referenced by average_tx(), setInst_tx(), and ~RTPSession().

int RTPSession::running_ [protected]

Definition at line 420 of file rtp.h.

Referenced by start_timer(), stop_timer(), and timeout().


The documentation for this class was generated from the following files:

Generated on Sun Jun 1 20:54:52 2008 for ASMP_S by  doxygen 1.5.5