root/vic/branches/cc/cc/tfrc_sndr.h @ 4804

Revision 4804, 5.3 KB (checked in by soohyunc, 4 years ago)

added TFRC sending and receiving mechanisms
(currently, TFRC's send rate calculation is omitted)

  • Property svn:keywords set to Id Revision
Line 
1/*
2 * Copyright (c) 2010 University College London
3 * All rights reserved.
4 *
5 * AUTHOR: Soo-Hyun Choi <s.choi@cs.ucl.ac.uk>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor of the Laboratory may be used
16 *    to endorse or promote products derived from this software without
17 *    specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * $Id$
32 */
33
34#ifndef vic_tfrc_sndr_h
35#define vic_tfrc_sndr_h
36
37#include "config.h"
38#include "bitmap.h"
39#include "cc_common.h"
40#include "cc_timer.h"
41
42class TfrcSndr;
43
44// TFRC sender class
45class TfrcSndr {
46public:
47        // constructor
48        TfrcSndr();
49        virtual ~TfrcSndr() {};
50
51        // virtual functions
52        virtual void tfrc_output(bool recv_by_ch=0) {UNUSED(recv_by_ch);};
53        virtual void tfrc_output(pktbuf*) {};
54        virtual double tx_ts_offset() {};
55        virtual int tx_buf_size() {};
56
57        // parse seqno and timestamp
58        void send(pktbuf*, double);
59
60        // main reception path
61        void recv(u_int16_t, u_int16_t, u_int16_t,
62                u_int16_t*, double, bool, pktbuf*);
63
64        // return ackofack
65        inline u_int16_t get_aoa() { return aoa_; }
66
67        u_int16_t seqno_;       // packet sequence number
68        double x_rate_;         // send rate
69
70        // TfrcSndr instance
71        static inline TfrcSndr& instance() { return instance_; }
72
73protected:
74
75        static TfrcSndr instance_;
76
77        // generate sequence numbers
78        void gen_seqvec(u_int16_t *v, int n);
79        // generate reference seqno
80        void gen_refvec(int end, int begin);
81        // reset variables
82        void reset_var(bool reverted);
83
84        u_int16_t *ackv_;       // received AckVec
85        u_int16_t aoa_; // ack of ack
86        double ts_;                     // timestamp
87        double now_;            // real-time now
88        double so_recv_;        // SO_TIMESTAMP
89        double tao_;            // sampled RTT
90
91        // packet size
92        int asize_;             // average packet size per frame
93        int pcnt_;              // packet counter per frame
94        int psize_;             // EWMA packet size
95        double lambda1_;        // EWMA coeff
96        double lambda2_;        // EWMA coeff
97
98private:
99        // update RTT
100        void update_rtt(double tao);
101
102        // TFRC congestion control
103        void calc_rate();
104        // average loss interval
105        void avg_loss_interval();
106        // loss history
107        void loss_history();
108
109        // AckVec clone from Vic
110        inline void clone_ackv(u_int16_t *c, int n) {
111                for (int i = 0; i < n; i++)
112                ackv_[i] = ntohs(c[i]);
113        }
114        // number of ackvec elements
115        inline int get_numvec(int n) {
116        return (n/BITLEN + (n%BITLEN > 0));
117        }
118        // number of ackvec elements
119        inline int get_numelm (int begin, int end) {
120        return (end - begin + 1);
121        }
122        // clear timestamp vector
123        inline void clear_tsv (int n) {
124                for (int i = 0; i < n; i++)
125                tsvec_[i] = 0;
126        }
127        // clear seqvec
128        inline void clear_sqv (int n) {
129                for (int i = 0; i < n; i++)
130                seqvec_[i] = 0;
131        }
132        // clear ackvec
133        inline void clear_ackv (int n) {
134                for (int i = 0; i < n; i++)
135                ackv_[i] = 0;
136        }
137        // clear refvec
138        inline void clear_refv(int n) {
139                for (int i = 0; i < n; i++)
140                refvec_[i] = 0;
141        }
142
143        int ndtp_;      // number of data packet sent
144        int nakp_;      // number of ackvec packet received
145        int ntep_;      // number of ts_echo packet received
146        int nsve_;      // number of seqvec element
147
148        double ts_off_; // timestamp offset for gettimeofday
149
150        u_int32_t *seqvec_;     // generated seqno vec
151        int num_seqvec_;        // number of seqvec elements
152        u_int32_t *refvec_;     // reference seqno vec
153        int num_refvec_;        // number of refvec elements
154        double *tsvec_;         // timestamp vector
155        u_int16_t jacked_;      // just acked seqno (head of ackvec)
156        int num_missing_;       // number of missing seqno
157
158        // XR chunk begin/end
159        u_int16_t begins_;      // start seqno that this XR chunk reports
160        u_int16_t ends_;        // end seqno + 1 that this XR chunk reports
161        int num_elm_;           // number of ackvec elements
162        int num_vec_;           // number of ackvec chunks
163
164        // print vec
165        inline void print_vec(const char* str, u_int32_t *vec, int c) {
166        fprintf(stderr, "\t%s: (", str);
167                for (int i = 0; i < c; i++)
168                fprintf(stderr, " %d", vec[i]);
169        fprintf(stderr, " )\n");
170        }
171        inline void print_vec(const char* str, u_int16_t *vec, int c) {
172        fprintf(stderr, "\t%s: (", str);
173                for (int i = 0; i < c; i++)
174                fprintf(stderr, " %d", vec[i]);
175        fprintf(stderr, " )\n");
176        }
177
178        // print the actual packet size and EWMA estimated one
179        inline void print_psize(double now, int size, int len) {
180        fprintf(stderr, "\tnow: %f psize: %d actual: %d\n", now, size, len);
181        }
182};
183
184#endif
Note: See TracBrowser for help on using the browser.