• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tcp/linux/ns-linux-util.h

00001 /* 
00002  * TCP-Linux module for NS2 
00003  *
00004  * May 2006
00005  *
00006  * Author: Xiaoliang (David) Wei  (DavidWei@acm.org)
00007  *
00008  * NetLab, the California Institute of Technology 
00009  * http://netlab.caltech.edu
00010  *
00011  * Module: linux/ns-linux-util.h
00012  *      This is the header file for linkages between NS-2 source codes (in C++) and Linux source codes (in C)
00013  *
00014  * See a mini-tutorial about TCP-Linux at: http://netlab.caltech.edu/projects/ns2tcplinux/
00015  *
00016  */
00017 
00018 #ifndef NS_LINUX_UTIL_H
00019 #define NS_LINUX_UTIL_H
00020 #include <stdlib.h>
00021 #include "ns-linux-param.h"
00022 
00023 extern struct tcp_congestion_ops tcp_reno;
00024 
00025 extern unsigned long tcp_time_stamp;
00026 extern long long ktime_get_real;
00027 
00028 #define JIFFY_RATIO 1000
00029 #define US_RATIO 1000000
00030 #define MS_RATIO 1000
00031 
00032 #define jiffies_to_usecs(x) ((US_RATIO/JIFFY_RATIO)*(x))
00033 #define msecs_to_jiffies(x) ((JIFFY_RATIO/MS_RATIO)*(x))
00034 
00035 extern void tcp_cong_avoid_register(void);
00036 
00037 #define __u64 unsigned long long
00038 #define __u32 unsigned long
00039 #define __u16 unsigned int
00040 #define __u8 unsigned char
00041 
00042 #define u64 __u64
00043 #define u32 __u32
00044 #define u16 __u16
00045 #define u8 __u8
00046 
00047 #define s32 long
00048 #define s64 long long
00049 
00050 #define uint64_t u64
00051 #define uint32_t u32
00052 
00053 #define ktime_t s64
00054 extern ktime_t net_invalid_timestamp();
00055 extern int ktime_equal(const ktime_t cmp1, const ktime_t cmp2);
00056 extern s64 ktime_to_us(const ktime_t kt);
00057 extern ktime_t net_timedelta(ktime_t t);
00058 
00059 #define inet_csk(sk) (sk)
00060 #define tcp_sk(sk) (sk)
00061 #define inet_csk_ca(sk) (void*)((sk)->icsk_ca_priv)
00062 
00063 
00064 //from kernel.h
00065 #define min_t(type,x,y) \
00066         (((type)(x)) < ((type)(y)) ? ((type)(x)): ((type)(y)))
00067 
00068 #define max_t(type,x,y) \
00069         (((type)(x)) > ((type)(y)) ? ((type)(x)): ((type)(y)))
00070 
00071 
00072 //#define max(x,y) ((x>y)? x:y)
00073 
00074 /* Events passed to congestion control interface */
00075 enum tcp_ca_event {
00076         CA_EVENT_TX_START,      /* first transmit when no packets in flight */
00077         CA_EVENT_CWND_RESTART,  /* congestion window restart */
00078         CA_EVENT_COMPLETE_CWR,  /* end of congestion recovery */
00079         CA_EVENT_FRTO,          /* fast recovery timeout */
00080         CA_EVENT_LOSS,          /* loss timeout */
00081         CA_EVENT_FAST_ACK,      /* in sequence ack */
00082         CA_EVENT_SLOW_ACK,      /* other ack */
00083 };
00084 
00085 #define sock tcp_sock
00086 #define inet_sock tcp_sock
00087 #define inet_connection_sock tcp_sock
00088 struct sk_buff;
00089 struct sock;
00090 
00091 
00092 /* A list of parameters for different cc */
00093 struct cc_param_list {
00094         const char* name;
00095         const char* type;
00096         const char* description;
00097         const void* ptr;
00098         struct cc_param_list* next;
00099 };
00100 
00101 struct cc_list {
00102         const char* proto;
00103         struct cc_param_list* param_head;
00104         struct cc_list* next;
00105 };
00106 extern struct cc_list* cc_list_head;
00107 
00108 /* List Type purely for tcp_cong_list*/
00109 struct list_head {
00110         struct list_head *prev;
00111         struct list_head *next;
00112         const char* file_name;
00113 };
00114 
00115 extern unsigned char cc_list_changed;
00116 extern struct list_head ns_tcp_cong_list;
00117 extern struct list_head *last_added;
00118 #define list_for_each_entry_rcu(pos, head, member) \
00119         for (pos=(struct tcp_congestion_ops*)ns_tcp_cong_list.next; pos!=(struct tcp_congestion_ops*)(&ns_tcp_cong_list); pos=(struct tcp_congestion_ops*)pos->member.next) 
00120 
00121 #define list_add_rcu(a,b) {\
00122         (a)->next=ns_tcp_cong_list.next;\
00123         (a)->prev=(&ns_tcp_cong_list);\
00124         ns_tcp_cong_list.next->prev=(a);\
00125         ns_tcp_cong_list.next=(a);\
00126         last_added = (a);\
00127         cc_list_changed = 1;\
00128 }
00129 
00130 #define list_del_rcu(a) {(a)->prev->next=(a)->next; (a)->next->prev=(a)->prev; cc_list_changed = 1; }
00131 #define list_move(a,b) {list_del_rcu(a); list_add_rcu(a,b);}
00132 #define list_entry(a,b,c) ((b*)ns_tcp_cong_list.next)
00133 #define list_add_tail_rcu(a,b) {\
00134         (a)->prev=ns_tcp_cong_list.prev;\
00135         (a)->next=(&ns_tcp_cong_list);\
00136         ns_tcp_cong_list.prev->next=(a);\
00137         ns_tcp_cong_list.prev=(a);\
00138         last_added = (a);\
00139         cc_list_changed = 1;\
00140 }
00141 
00142 /*
00143  * Interface for adding new TCP congestion control handlers
00144  */
00145 #define TCP_CA_NAME_MAX 16
00146 #define TCP_CONG_NON_RESTRICTED 0x1
00147 #define TCP_CONG_RTT_STAMP      0x2
00148 struct tcp_congestion_ops {
00149         struct list_head        list;
00150 
00151         unsigned long flags;
00152         int non_restricted;
00153 
00154         /* initialize private data (optional) */
00155         void (*init)(struct sock *sk);
00156         /* cleanup private data  (optional) */
00157         void (*release)(struct sock *sk);
00158 
00159         /* return slow start threshold (required) */
00160         u32 (*ssthresh)(struct sock *sk);
00161         /* lower bound for congestion window (optional) */
00162         u32 (*min_cwnd)(const struct sock *sk);
00163         /* do new cwnd calculation (required) */
00164         void (*cong_avoid)(struct sock *sk, u32 ack,
00165                            u32 rtt, u32 in_flight, int good_ack);
00166         /* round trip time sample per acked packet (optional) */
00167         void (*rtt_sample)(struct sock *sk, u32 usrtt);
00168         /* call before changing ca_state (optional) */
00169         void (*set_state)(struct sock *sk, u8 new_state);
00170         /* call when cwnd event occurs (optional) */
00171         void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev);
00172         /* new value of cwnd after loss (optional) */
00173         u32  (*undo_cwnd)(struct sock *sk);
00174         /* hook for packet ack accounting (optional) */
00175         void (*pkts_acked)(struct sock *sk, u32 num_acked, ktime_t last);
00176         /* get info for inet_diag (optional) */
00177         void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb);
00178 
00179         char            name[TCP_CA_NAME_MAX];
00180         struct module   *owner;
00181 };
00182 
00183 struct tcp_options_received {
00184 /*      PAWS/RTTM data  */
00185 //      long    ts_recent_stamp;/* Time we stored ts_recent (for aging) */
00186 //      __u32   ts_recent;      /* Time stamp to echo next              */
00187         __u32   rcv_tsval;      /* Time stamp value                     */
00188         __u32   rcv_tsecr;      /* Time stamp echo reply                */
00189         __u16   saw_tstamp : 1, /* Saw TIMESTAMP on last packet         */
00190                 dump_xxx: 15;
00191 //              tstamp_ok : 1,  /* TIMESTAMP seen on SYN packet         */
00192 //              dsack : 1,      /* D-SACK is scheduled                  */
00193 //              wscale_ok : 1,  /* Wscale seen on SYN packet            */
00194 //              sack_ok : 4,    /* SACK seen on SYN packet              */
00195 //              snd_wscale : 4, /* Window scaling received from sender  */
00196 //              rcv_wscale : 4; /* Window scaling to send to receiver   */
00197 /*      SACKs data      */
00198 //      __u8    eff_sacks;      /* Size of SACK array to send with next packet */
00199 //      __u8    num_sacks;      /* Number of SACK blocks                */
00201 //      __u16   mss_clamp;      /* Maximal mss, negotiated at connection setup */
00202 };
00203 
00204 struct tcp_sock {
00205 /* inet_connection_sock has to be the first member of tcp_sock */
00206 //      struct inet_connection_sock     inet_conn;
00207         int     sk_state;
00208 //      int     tcp_header_len; /* Bytes of tcp header to send          */
00209 
00210 /*
00211  *      Header prediction flags
00212  *      0x5?10 << 16 + snd_wnd in net byte order
00213  */
00214 //      __u32   pred_flags;
00215 
00216 /*
00217  *      RFC793 variables by their proper names. This means you can
00218  *      read the code and the spec side by side (and laugh ...)
00219  *      See RFC793 and RFC1122. The RFC writes these in capitals.
00220  */
00221 //      __u32   rcv_nxt;        /* What we want to receive next         */
00222         __u32   snd_nxt;        /* Next sequence we send                */
00223 
00224         __u32   snd_una;        /* First byte we want an ack for        */
00225 //      __u32   snd_sml;        /* Last byte of the most recently transmitted small packet */
00226 //      __u32   rcv_tstamp;     /* timestamp of last received ACK (for keepalives) */
00227 //      __u32   lsndtime;       /* timestamp of last sent data packet (for restart window) */
00228 
00229         /* Data for direct copy to user */
00230 //      struct {
00231 //              struct sk_buff_head     prequeue;
00232 //              struct task_struct      *task;
00233 //              struct iovec            *iov;
00234 //              int                     memory;
00235 //              int                     len;
00236 //      } ucopy;
00237 
00238 //      __u32   snd_wl1;        /* Sequence for window update           */
00239 //      __u32   snd_wnd;        /* The window we expect to receive      */
00240 //      __u32   max_window;     /* Maximal window ever seen from peer   */
00241 //      __u32   pmtu_cookie;    /* Last pmtu seen by socket             */
00242         __u32   mss_cache;      /* Cached effective mss, not including SACKS */
00243 //      __u16   xmit_size_goal; /* Goal for segmenting output packets   */
00244 //      __u16   ext_header_len; /* Network protocol overhead (IP/IPv6 options) */
00245 //
00246 //      __u32   window_clamp;   /* Maximal window to advertise          */
00247 //      __u32   rcv_ssthresh;   /* Current window clamp                 */
00248 //
00249 //      __u32   frto_highmark;  /* snd_nxt when RTO occurred */
00250 //      __u8    reordering;     /* Packet reordering metric.            */
00251 //      __u8    frto_counter;   /* Number of new acks after RTO */
00252 //      __u8    nonagle;        /* Disable Nagle algorithm?             */
00253 //      __u8    keepalive_probes; /* num of allowed keep alive probes   */
00254 
00255 /* RTT measurement */
00256         __u32   srtt;           /* smoothed round trip time << 3        */
00257 //      __u32   mdev;           /* medium deviation                     */
00258 //      __u32   mdev_max;       /* maximal mdev for the last rtt period */
00259 //      __u32   rttvar;         /* smoothed mdev_max                    */
00260 //      __u32   rtt_seq;        /* sequence number to update rttvar     */
00261 //
00262 //      __u32   packets_out;    /* Packets which are "in flight"        */
00263 //      __u32   left_out;       /* Packets which leaved network */
00264 //      __u32   retrans_out;    /* Retransmitted packets out            */
00265 /*
00266  *      Options received (usually on last packet, some only on SYN packets).
00267  */
00268         struct tcp_options_received rx_opt;
00269 
00270 /*
00271  *      Slow start and congestion control (see also Nagle, and Karn & Partridge)
00272  */
00273         __u32   snd_ssthresh;   /* Slow start size threshold            */
00274         __u32   snd_cwnd;       /* Sending congestion window            */
00275         __u16   snd_cwnd_cnt;   /* Linear increase counter              */
00276         __u16   snd_cwnd_clamp; /* Do not allow snd_cwnd to grow above this */
00277 //      __u32   snd_cwnd_used;
00278         __u32   snd_cwnd_stamp;
00279         __u32   bytes_acked;
00280 //
00281 //      struct sk_buff_head     out_of_order_queue; /* Out of order segments go here */
00282 //
00283 //      struct tcp_func         *af_specific;   /* Operations which are AF_INET{4,6} specific   */
00284 //
00285  //     __u32   rcv_wnd;        /* Current receiver window              */
00286 //      __u32   rcv_wup;        /* rcv_nxt on last window update sent   */
00287 //      __u32   write_seq;      /* Tail(+1) of data held in tcp send buffer */
00288 //      __u32   pushed_seq;     /* Last pushed seq, required to talk to windows */
00289 //      __u32   copied_seq;     /* Head of yet unread data              */
00290 //
00291 /*      SACKs data      */
00292 //      struct tcp_sack_block duplicate_sack[1]; /* D-SACK block */
00293 //      struct tcp_sack_block selective_acks[4]; /* The SACKS themselves*/
00294 
00295 //      __u16   advmss;         /* Advertised MSS                       */
00296 //      __u16   prior_ssthresh; /* ssthresh saved at recovery start     */
00297 //      __u32   lost_out;       /* Lost packets                 */
00298 //      __u32   sacked_out;     /* SACK'd packets                       */
00299 //      __u32   fackets_out;    /* FACK'd packets                       */
00300 //      __u32   high_seq;       /* snd_nxt at onset of congestion       */
00301 //
00302 //      __u32   retrans_stamp;  /* Timestamp of the last retransmit,
00303 //                               * also used in SYN-SENT to remember stamp of
00304 //                               * the first SYN. */
00305 //      __u32   undo_marker;    /* tracking retrans started here. */
00306 //      int     undo_retrans;   /* number of undoable retransmissions. */
00307 //      __u32   urg_seq;        /* Seq of received urgent pointer */
00308 //      __u16   urg_data;       /* Saved octet of OOB data and control flags */
00309 //      __u8    urg_mode;       /* In urgent mode               */
00310 //      __u8    ecn_flags;      /* ECN status bits.                     */
00311 //      __u32   snd_up;         /* Urgent pointer               */
00312 //
00313 //      __u32   total_retrans;  /* Total retransmits for entire connection */
00314 //
00315 //      unsigned int            keepalive_time;   /* time before keep alive takes place */
00316 //      unsigned int            keepalive_intvl;  /* time interval between keep alive probes */
00317 //      int                     linger2;
00318 //
00319 //      unsigned long last_synq_overflow; 
00320 //
00321 /* Receiver side RTT estimation */
00322 //      struct {
00323 //              __u32   rtt;
00324 //              __u32   seq;
00325 //              __u32   time;
00326 //      } rcv_rtt_est;
00327 
00328 /* Receiver queue space */
00329 //      struct {
00330 //              int     space;
00331 //              __u32   seq;
00332 //              __u32   time;
00333 //      } rcvq_space;
00334         struct tcp_congestion_ops *icsk_ca_ops;
00335         __u8                      icsk_ca_state;
00336         u32                       icsk_ca_priv[16];
00337 #define ICSK_CA_PRIV_SIZE       (16 * sizeof(u32))
00338 };
00339 
00340 struct sk_buff {
00341 
00342 };
00343 
00344 extern struct tcp_congestion_ops tcp_init_congestion_ops;
00345 
00346 
00347 enum tcp_ca_state
00348 {
00349         TCP_CA_Open = 0,
00350 #define TCPF_CA_Open    (1<<TCP_CA_Open)
00351         TCP_CA_Disorder = 1,
00352 #define TCPF_CA_Disorder (1<<TCP_CA_Disorder)
00353         TCP_CA_CWR = 2,
00354 #define TCPF_CA_CWR     (1<<TCP_CA_CWR)
00355         TCP_CA_Recovery = 3,
00356 #define TCPF_CA_Recovery (1<<TCP_CA_Recovery)
00357         TCP_CA_Loss = 4
00358 #define TCPF_CA_Loss    (1<<TCP_CA_Loss)
00359 };
00360 
00361 #define FLAG_ECE 1
00362 #define FLAG_DATA_SACKED 2
00363 #define FLAG_DATA_ACKED 4
00364 #define FLAG_DATA_LOST 8
00365 #define FLAG_CA_ALERT           (FLAG_DATA_SACKED|FLAG_ECE)
00366 #define FLAG_NOT_DUP            (FLAG_DATA_ACKED)
00367 
00368 #define FLAG_UNSURE_TSTAMP 16
00369 
00370 #define CONFIG_DEFAULT_TCP_CONG "reno"
00371 #define TCP_CLOSE 0
00372 
00373 #endif

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1