• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tcp/linux/ns-linux-c.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-c.h
00012  *      This is the header file of shortcuts for Linux source codes (in C)
00013  *      We shortcut most of the Linux system calls which are not related to congestion control.
00014  *
00015  * See a mini-tutorial about TCP-Linux at: http://netlab.caltech.edu/projects/ns2tcplinux/
00016  *
00017  */
00018 
00019 #ifndef NS_LINUX_C_H
00020 #define NS_LINUX_C_H
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include "ns-linux-util.h"
00025 //For sharing Reno
00026 
00027 extern u32 tcp_reno_ssthresh(struct sock *sk);
00028 extern void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 rtt, u32 in_flight, int flag);
00029 extern u32 tcp_reno_min_cwnd(const struct sock *sk);
00030 
00031 #define tcp_is_cwnd_limited(sk, in_flight)  ((in_flight) >= (sk)->snd_cwnd)
00032 //from kernel.h
00033 
00034 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
00035 #define min(x,y) (((x)<(y))?(x):(y))
00036 #define max(x,y) (((x)>(y))?(x):(y))
00037 #define after(seq1,seq2) ((seq2)<(seq1))
00038 
00039 
00040 #define HZ 1000
00041 
00042 // Shortcuts
00043 #define THIS_MODULE 0
00044 #define EXPORT_SYMBOL_GPL(symbol)
00045 #define __init
00046 #define __exit
00047 
00048 typedef int (*registerFunctionPointer)(void);
00049 
00050 #ifdef NS_PROTOCOL
00051 // for new source codes that defines NS_PROTOCOL, we support module parameters
00052 // set the file name of last_added file
00053 extern void set_linux_file_name(const char*);
00054 extern void record_linux_param(const char*, const char*, const char*, void*);
00055 extern void record_linux_param_description(const char*, const char*, const char*);
00056 #define module_init(x) \
00057         static void module_register(void) __attribute__((constructor));\
00058         static void module_register(void) { \
00059                 x(); \
00060                 set_linux_file_name(NS_PROTOCOL);\
00061         };
00062 
00063 #define module_exit(x) \
00064         static void module_unregister_fake(void) __attribute__((constructor));\
00065         static void module_unregister_fake(void) {\
00066                 if (0) x();\
00067         };
00068 
00069 #define module_param(name, type, mode) \
00070         static void module_param_##name(void) __attribute__((constructor));\
00071         static void module_param_##name(void) { record_linux_param(NS_PROTOCOL, #name, #type, &name); };
00072 
00073 #define MODULE_PARM_DESC(name, exp) \
00074         static void module_param_desc_##name(void) __attribute__((constructor));\
00075         static void module_param_desc_##name(void) { record_linux_param_description(NS_PROTOCOL, #name, exp); };
00076 
00077 #else
00078 // for old source codes that do not define NS_PROTOCOL, we do not support module parameters
00079 #define module_init(x) \
00080         static void module_register(void) __attribute__((constructor));\
00081         static void module_register(void) { \
00082                 x(); \
00083          };
00084 #define module_param(a,b,c)
00085 #define MODULE_PARM_DESC(a,b)
00086 #endif
00087 
00088 
00089 #define module_put(x)
00090 #define try_module_get(x) 0
00091 #define MODULE_AUTHOR(x)
00092 #define MODULE_LICENSE(x)
00093 #define MODULE_DESCRIPTION(x)
00094 #define MODULE_VERSION(a)
00095 
00096 #define KERN_ERR "<2> "
00097 #define KERN_NOTICE "<1> "
00098 #define KERN_INFO "<0> "
00099 #define printk(fmt, args...) { \
00100         if (strlen(fmt)<4 || fmt[0]!='<' || fmt[2]!='>' || fmt[3]!=' ') \
00101                 fprintf(stderr, "<Unspecified>" fmt, args);\
00102         else if (fmt[1]>=debug_level+'0')\
00103                 printf(fmt, args);\
00104 }
00105 
00106 #define EINVAL 1
00107 #define EEXIST 2
00108 #define ENOENT 3
00109 #define EBUSY 4
00110 #define ENOMEM 5
00111 #define EPERM 6
00112 #define BUG_ON(x) 
00113 #define BUILD_BUG_ON(x)
00114 #define WARN_ON(x)
00115 //please make sure the system can run
00116 
00117 #define spin_lock(x)
00118 #define spin_unlock(x)
00119 #define rcu_read_lock()
00120 #define rcu_read_unlock()
00121 
00122 #define late_initcall(x)
00123 
00124 #define capable(x) 1
00125 #define between(seq1, seq2, seq3) ((seq3) - (seq2) >= (seq1) - (seq2))
00126 
00127 #define kstrdup(str, mode) strdup(str)
00128 
00130 struct tcpvegas_info {
00131         __u32   tcpv_enabled;
00132         __u32   tcpv_rttcnt;
00133         __u32   tcpv_rtt;
00134         __u32   tcpv_minrtt;
00135 };
00136 #define INET_DIAG_VEGASINFO 1
00137 struct rtattr {};
00138 #define __RTA_PUT(skb, INFO_FLAG, size) NULL
00139 #define RTA_DATA(rta) NULL
00140 
00141 //#define DEFINE_SPINLOCK(x)
00142 //#define LIST_HEAD(name)
00143 #define DEFINE_SPINLOCK(x) int FAKED_LOCK_X
00144 #define LIST_HEAD(name) int FAKED_LIST_HEAD
00145 //The true list head is declared in ns-linux-util.h since it has to be accessible by TCP-Linux's cpp codes.
00146 
00147 
00149 /*
00150  * fls: find last bit set.
00151  */
00152 
00153 extern int fls(int x);
00154 extern int fls64(__u64 x);
00155 
00157 #define do_div(n,base) ({                                      \
00158         uint32_t __base = (base);                               \
00159         uint32_t __rem;                                         \
00160         __rem = ((uint64_t)(n)) % __base;                       \
00161         (n) = ((uint64_t)(n)) / __base;                         \
00162         __rem;                                                  \
00163  })
00164 
00165 #define CONG_NUM 0
00166 
00167 #define jiffies tcp_time_stamp
00168 
00169 #define pr_debug(args...) {if ((debug_level+'0') <= KERN_NOTICE[1]) printf(args);}
00170 
00171 #define __read_mostly 
00172 
00173 /* 64bit divisor, dividend and result. dynamic precision */
00174 extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
00175 
00176 #define nla_put(skb, type, len, data)
00177 
00178 extern int tcp_register_congestion_control(struct tcp_congestion_ops *ca);
00179 extern void tcp_slow_start(struct tcp_sock *tp);
00180 extern void tcp_unregister_congestion_control(struct tcp_congestion_ops *ca);
00181 #endif

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