root/vic/branches/cc/rtp/session.h @ 4831

Revision 4831, 9.7 KB (checked in by soohyunc, 4 years ago)

It is critically important for TFWC (or any kind of ack-clock based CC
mechanisms) to receive Ack as soon as it arrives to the data sender, so that the
data sender can update CC information (cwnd or send rate) in a timely fashion.

We have discovered that Ack can be arrived to the sender in a bulky manner -
i.e., multimple Acks arrived in a very short time scale.

Although TFWC had a mechanism to pull out the arrived-ack before sending every
data packet, it wasn't sufficient when MANY Acks are arrived already.

Therefore, we have created a while loop to pull out the arrived XR as soon as
possible as long as it is there. So, these Acks are not the normal Ack clock,
hence we have changed some variable names accordingly (recv_by_ch => ack_clock).

Also, there was a typo in tfwc_sndr.h when returning the number of bytes that
this Ack is giving.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[900]1/*
2 * Copyright (c) 1995 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the Network Research
16 *      Group at Lawrence Berkeley National Laboratory.
17 * 4. Neither the name of the University nor of the Laboratory may be used
18 *    to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#) $Header$ (LBL)
[4233]34 * $Id$
[900]35 */
36
37#ifndef vic_session_h
38#define vic_session_h
39
40#include "net.h"
41#include "transmitter.h"
42#include "timer.h"
43#include "iohandler.h"
44#include "source.h"
45#include "mbus_handler.h"
46
47class Source;
48class SessionManager;
[4353]49/*
50 * global variable representing data sender or receiver
51 * (by default, it is set to a data receiver.)
52 *
53 * e.g., for data sender, it must change this variable
54 *              using i_am_sender() method.
55*/
56bool is_sender_ = false;
[900]57
58class DataHandler : public IOHandler {
59    public:
[956]60        DataHandler* next;
61        inline DataHandler() : next(0), sm_(0), net_(0), addrp_(0) {}
62//      inline DataHandler(SessionManager& sm) : sm_(sm), net_(0), addrp_(0) {}
[900]63        virtual void dispatch(int mask);
64        inline Network* net() const { return (net_); }
[956]65        virtual void net(Network* net) {
[900]66                unlink();
67                link(net->rchannel(), TK_READABLE);
68                net_ = net;
69                if (addrp_) delete addrp_;
70                addrp_ = net->addr().copy(); // get right type of address
71        }
72        inline int recv(u_char* bp, int len, Address*& addrp) {
73                return (net_->recv(bp, len, *(addrp = addrp_)));
74        }
75        inline void send(u_char* bp, int len) {
76                net_->send(bp, len);
77        }
[956]78        inline void manager(SessionManager* sm) { sm_ = sm; }
[900]79    protected:
[956]80        SessionManager *sm_;
[900]81        Network* net_;
82        Address *addrp_;
83};
[956]84/*
85 * Parameters controling the RTCP report rate timer.
86 */
87#define CTRL_SESSION_BW_FRACTION (0.05)
88#define CTRL_MIN_RPT_TIME (5.)
89#define CTRL_SENDER_BW_FRACTION (0.25)
90#define CTRL_RECEIVER_BW_FRACTION (1. - CTRL_SENDER_BW_FRACTION)
91#define CTRL_SIZE_GAIN (1./8.)
[900]92
[956]93class CtrlHandler : public DataHandler, public Timer {
[900]94    public:
[956]95        CtrlHandler();
96//      inline CtrlHandler(SessionManager& sm) : DataHandler(sm) {}
[900]97        virtual void dispatch(int mask);
[956]98        inline Network* net() const { return (net_); }
99// new for layering - individual report timers for each layer
100        virtual void timeout();
101        virtual void net(Network* net);
102        void adapt(int nsrc, int nrr, int we_sent);
103        void sample_size(int cc);
104        inline double rint() const { return (rint_); }
[4259]105        void send_aoa();        // send ackofack (TfwcSndr side)
106        void send_ts();         // send timestamp (TfwcSndr side)
[4665]107        void send_ackv();       // send ackvec (TfwcRcvr side)
[4587]108        void send_p();
[4290]109        void send_ts_echo();
[4254]110
[4354]111        // i am an RTP data sender/receiver
[4353]112        inline void i_am_sender() { is_sender_ = true; }
[4354]113        inline void i_am_receiver() { is_sender_ = false; }
[4353]114
[956]115 protected:
116        void schedule_timer();
117        double ctrl_inv_bw_;
118        double ctrl_avg_size_;  /* (estimated) average size of ctrl packets */
119        double rint_;           /* current session report rate (in ms) */
[4831]120
121        // control channel dispatch debug info
122        inline void dispatch_info(double now, int nbytes, int i) {
123        fprintf(stderr, "  \tnow: %f\tdispatched[%d]: %d\n",now,i,nbytes);
124        }
[900]125};
126
127class ReportTimer : public Timer {
128    public:
129        inline ReportTimer(SessionManager& sm) : sm_(sm) {}
130        void timeout();
131    protected:
132        SessionManager& sm_;
133};
134
135class SessionManager : public Transmitter, public MtuAlloc {
[956]136public:
[900]137        SessionManager();
138        virtual ~SessionManager();
139        virtual int command(int argc, const char*const* argv);
[4825]140        virtual int recv(CtrlHandler*);
[900]141        virtual void recv(DataHandler*);
[956]142        virtual void announce(CtrlHandler*); //LLL
143//      virtual void send_bye();
144        virtual inline void send_bye() { send_report(&ch_[0], 1); }
145//      virtual void send_report();
146        virtual void send_report(CtrlHandler*, int bye, int app = 0);
[4487]147        virtual void build_xreport(CtrlHandler*, int bt);
[4667]148        virtual void send_xreport(CtrlHandler* ch,
[4487]149                u_int8_t bt, u_int8_t rsvd, u_int8_t thin,
150                u_int16_t begin_seq, u_int16_t end_seq,
151                u_int16_t *chunks, u_int16_t num_chunks,
152                u_int32_t xrssrc);
[4468]153
[4665]154        // receive XR
[4825]155        int recv_xreport(CtrlHandler*, pktbuf*, bool);
[4665]156
[4255]157        void build_aoa_pkt(CtrlHandler* ch);
158        void build_ts_pkt(CtrlHandler* ch);
[4290]159        void build_ackv_pkt(CtrlHandler* ch);
[4587]160        void build_p_pkt(CtrlHandler* ch);
[4290]161        void build_ts_echo_pkt(CtrlHandler* ch);
[956]162
[4353]163        // am i a data sender?
164        inline bool am_i_sender() { return is_sender_; }
[4831]165        // see if any XR has arrived
166        virtual int check_xr_arrival(pktbuf*, bool);
[4353]167
[956]168protected:
169//      void demux(rtphdr* rh, u_char* bp, int cc, Address & addr, int layer);
170        void demux(pktbuf* pb, Address & addr);
[900]171        virtual int check_format(int fmt) const = 0;
[4831]172        virtual void transmit(pktbuf* pb, bool ack_clock=0);
173        virtual void tx_data_only(pktbuf* pb, bool ack_clock);
[900]174        void send_report(int bye);
[4487]175        void send_ECNXreport(CtrlHandler* ch, u_int8_t tos, u_int16_t begin_seq);
[900]176        int build_bye(rtcphdr* rh, Source& local);
[3995]177        u_char* build_sdes_item(u_char* p, int code, Source&);
[900]178        int build_sdes(rtcphdr* rh, Source& s);
[4184]179        int build_app(rtcphdr* rh, Source& ls, const char *name,
180                        void *data, int datalen);
[900]181
182        void parse_sr(rtcphdr* rh, int flags, u_char* ep,
[956]183                      Source* ps, Address & addr, int layer);
[900]184        void parse_rr(rtcphdr* rh, int flags, u_char* ep,
[956]185                      Source* ps, Address & addr, int layer);
[4234]186        void parse_xr(rtcphdr* rh, int flags, u_char* ep,
[4831]187                      Source* ps, Address & addr, int layer, bool ack_clock, pktbuf* pb=0);
[900]188        void parse_rr_records(u_int32_t ssrc, rtcp_rr* r, int cnt,
189                              const u_char* ep, Address & addr);
[4260]190        void parse_xr_records(u_int32_t ssrc, rtcp_xr* xr, int cnt,
[4831]191                              const u_char* ep, Address & addr, bool ack_clock, pktbuf* pb);
[900]192        int sdesbody(u_int32_t* p, u_char* ep, Source* ps,
[956]193                     Address & addr, u_int32_t ssrc, int layer);
[900]194        void parse_sdes(rtcphdr* rh, int flags, u_char* ep, Source* ps,
[956]195                        Address & addr, u_int32_t ssrc, int layer);
[900]196        void parse_bye(rtcphdr* rh, int flags, u_char* ep, Source* ps);
197
198        int parseopts(const u_char* bp, int cc, Address & addr) const;
199        int ckid(const char*, int len);
200
201        u_int32_t alloc_srcid(Address & addr) const;
202
203        int lipSyncEnabled() { return (lipSyncEnabled_);}
204        void lipSyncEnabled(int v) { lipSyncEnabled_=v;}
205
206        char* stats(char* cp) const;
207
[956]208        DataHandler dh_[NLAYER];
209        CtrlHandler ch_[NLAYER];
[900]210
211        // MBus stuff
212        MBusHandler mb_; // Handles mbus and interfaces to mbus
213                                         // code in common libraries
214        int lipSyncEnabled_;
215
216        /*XXX cleanup*/
217        u_int badversion_;
218        u_int badoptions_;
219        u_int badfmt_;
220        u_int badext_;
221        u_int nrunt_;
222
223        u_int32_t last_np_;
224        u_int32_t sdes_seq_;
225
226        double rtcp_inv_bw_;
227        double rtcp_avg_size_;  /* (estimated) average size of rtcp packets */
228        double rint_;           /* current session report rate (in ms) */
229
230        int confid_;
231
[956]232        BufferPool* pool_;
[900]233        u_char* pktbuf_;
[956]234
235        SourceManager *sm_;
[4233]236
237        // RTP packet sequence number (for the use of AckVec)
238        u_int16_t seqno_;               // RTP packet sequence number
239        u_int16_t lastseq_;             // last packet's seqno
[4246]240        u_int16_t ackofack_;    // Ack of ack
[4233]241
242        // AckVector
[4347]243        u_int16_t ackvec_;      // this is a bit vector
[4654]244        // timestamp
245        double recv_ts_;        // receive timestamp
[4730]246
247private:
248        // print RTP data packet's seqno
249        inline void print_rtp_seqno(u_int16_t seqno) {
250        fprintf(stderr, "\n\tnow: %f\tseqno: %d\n\n",tx_get_now(),seqno);
251        }
252        inline void print_rtp_seqno(pktbuf* pb) {
253        rtphdr* rh = (rtphdr *) pb->data;
[4831]254        fprintf(stderr, "\n\tnow: %f\tseqno: %d\n\n",
255            tx_get_now(),ntohs(rh->rh_seqno));
[4730]256        }
257        // print sender's XR info
[4804]258        inline void sender_xr_info(const char* str, const int i,
[4831]259        u_int16_t b, u_int16_t e, rtcp_xr_BT_1_hdr* xrh, u_int16_t l) {
[4804]260        fprintf(stderr, "  [%s +%d] beg:%d, end:%d, xr1len:%d (xrlen:%d)\n",
261                str, i, b, e, ntohs(xrh->xr_len),l);
[4730]262        }
263        // print sender's XR info
264        inline void sender_xr_ts_info(double ts) {
265        fprintf(stderr, "*** recv_ts: %f so_rtime: %f diff: %f\n",
266                recv_ts_, ts, recv_ts_-ts);
267        }
268        // print receiver's XR info
[4804]269        inline void receiver_xr_info(const char* str, const int i, u_int16_t *c) {
270        fprintf(stderr, "  [%s +%d] chunk[0]:%d\n",str, i, ntohs(c[0]));
[4730]271        }
272        // print parse XR banner
273        inline void parse_xr_banner_top() {
274        fprintf(stderr,
275        "~~~~~~~~~~~~~~~~~~entering parse_xr_records()~~~~~~~~~~~~~~~~~~\n");
276        }
277        inline void parse_xr_banner_bottom() {
278        fprintf(stderr,
279        "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
280        }
[4831]281        inline void xr_arrival_info(int nbytes, int i) {
282        fprintf(stderr, "  \tnow: %f\tnbytes[%d]: %d\n",tx_get_now(),i,nbytes);
283        }
[900]284};
285
286class AudioSessionManager : public SessionManager {
287    protected:
288        int check_format(int fmt) const;
289};
290
291class VideoSessionManager : public SessionManager {
292    protected:
293        int check_format(int fmt) const;
294};
295
296
297#endif
Note: See TracBrowser for help on using the browser.