cleanup
[linux-2.4.21-pre4.git] / include / net1 / kernel_qtype.h
1 /* FILE : /usr/src/linux/include/net/kernel_qtype.h * 
2  * This file define data structures used in kernel to run WF2Q scheduler. 
3  */
4
5 #include <net/qtype.h>
6 #include <net/qmgt_red.h>
7 #include <linux/time.h> //for "struct timeval"
8 #include <asm/semaphore.h> //for "struct semaphore"
9
10 /*Please reference the include/linux/types.h for more info of u_intxx_t type*/
11
12 #define MAX_UINT64 0xfffffffffffff800 //used to detect when to wrap around
13                                       //an 64-bit integer which is going to
14                                       //overflow
15 /* Statistical information of a queue. */
16
17 struct t_qstat{ 
18 //"Static" property of the queue
19         u_int8_t policy_type;
20         //the drop mechanism(RED or TD) 
21         u_int8_t if_dir;
22         //the direction of the queue
23         u_int32_t qid;
24         //the id of the queue
25         u_int32_t weight;
26         //the weight of the queue (unit: 1/10000)
27         u_int32_t max_weight;
28         //the max weight of the queue(for max rate control)
29         u_int32_t buf_len;
30         //the required buffer length (bytes)
31         u_int32_t delay;
32         //the required delay(in ms)
33         u_int32_t max_delay;
34         //the max delay bound
35         u_int32_t sample_counter;
36         //to determine the sample rate
37         struct timeval last_VFT;//the latest Virtual Finish Time
38
39         //"Statistical" property of the queue
40         u_int64_t send_pkt;     //the # of sent packets.
41         u_int64_t send_byte;    //the # of sent bytes.
42         u_int64_t recv_pkt;     //the # of received packets.
43         u_int64_t recv_byte;    //the # of received bytes.
44         u_int64_t drop_pkt;     //the # of dropped packets.
45         u_int64_t drop_byte;    //the # of dropped bytes.
46         u_int32_t current_q_len;        //the current length of queue (bytes)
47         u_int32_t current_q_pkt;        //the current length of queue (pkts)
48         u_int32_t avg_q_len;    //the average length of queue
49         u_int32_t avg_delay;    //the average delay
50         u_int64_t second_moment_delay;  //the second moment of delay
51         u_int64_t var_delay;    //the delay variance
52         u_int32_t max_delay_until_now;  //the max delay so far
53         u_int8_t policing_enable;       //the flag the determine whether to
54                                         //perform policing
55         Qmgt_RED red_info;
56 };
57
58 typedef struct t_qstat Q_Stat;
59
60 /* Imformation of the policer of a bandwidth pipe (Bpipe) * */
61
62 struct t_policer{
63         u_int8_t        policer_type;
64         //to Best Effort or Drop it
65         u_int32_t       TB_left_token;  //the left credit of the class/flow,
66                                         //measured in BYTE
67
68         //"Statistical information"
69         u_int64_t recv_pkt;             //the # of received packets
70         u_int64_t recv_byte;    //the # of received bytes
71         u_int64_t conform_pkt;  //the # of comfom packets
72         u_int64_t conform_byte; //the # of comfom bytes
73                                 //NOTE that "conform_pkt" and "conform_byte"
74                                 //will be the same as "recv_pkt" and
75                                 //"recv_byte" respectively.
76         T_Spec          t_spec; //the traffic spec
77         struct timeval last_policing_time; //to count the remaining tokens
78                                            //of this Bpipe
79 };
80
81 typedef struct t_policer Policer_Spec;
82 /* Information identifying which queue a packet belongs to. *
83  * Information here is usually reffered to when doing packet classification. */
84
85 struct t_filter{
86         C_Spec          c_spec; //the filter rule
87         Class_Name      class_name; //the name of the class/flow
88         struct t_qspec *theQueue; //the queue to which the traffic belongs
89 };
90
91 typedef struct t_filter Filter_Spec;
92
93 /* Information of a queue *
94  * A queue could represent a service class or bandwidth pipe(Bpipe). */
95
96 struct t_qspec{
97         Q_Stat          q_stat; //the information of the queue
98         Policer_Spec    p_spec; //the policer info of the queue
99         Filter_Spec     *f_spec;//the filter bound to the queue
100
101         //We use doubly linked list to manage the ACTIVE queues.
102         struct t_qspec *prev_active;//the previous active queue
103         struct t_qspec *next_active;//the next active queue
104
105         //We also use doubly linked list to manage ALL queues
106         struct t_qspec  *prev;//the previous queue
107         struct t_qspec  *next;//the next queue
108         struct sk_buff_head pkt_list;   //the packet list of the queue  
109
110         u_int16_t       po;             //Precedence Order
111                                         //20020716 by ARGAY
112
113         u_int8_t        enabled;        //Is this Bpipe enabled? (DISABLE_BPIPE v.s. ENABLE_BPIPE)
114                                         //20020716 by ARGAY
115
116         void *ext;                      // for future extension
117 };
118
119 typedef struct t_qspec Q_Spec;
120
121 /* Information of a WF2Q scheduler *
122  */
123
124 struct wfq_sch_data{
125         Q_Spec *head;           //head of queue list which contains ALL queues
126                                 //created in a NIC (Let say "ALL-queue list")
127         Q_Spec *active_head;    //head of active queue list which contains ONLY
128                                 //active queues in a NIC (Let say "ACTIVE-queue
129                                 //list")
130         Q_Spec *default_q;      //for Best Effort traffic
131         u_int32_t usedWeight;   //sum of weights of active queues
132         u_int32_t totalWeight;  //sum of weights of all queues
133         u_int32_t BW;           //bandwidth of link
134                                 //NOTE that "bandwidth" may be less than
135                                 //NIC's maximum capacity. If it is set
136                                 //this way, mechanism of "Maximum output
137                                 //rate control" will enforce the NIC to run
138                                 //at speed no more faster than "bandwidth".
139         u_int32_t BW_token;     //for bandwidth control (maximum output rate
140                                 //control), measured in BYTES
141         struct timeval last_ctl_time; //to count residual tokens of a NIC
142         struct semaphore *active_queue_lock; //to avoid infinite loop caused by
143                                             //erroneously reffering to ACTIVE
144                                             //queue list
145         struct semaphore *all_queue_lock; //to avoid infinite loop caused by
146                                             //erroneously reffering to ALL
147                                             //queue list
148         struct timer_list deq_timer; //to regularly wake up scheduler to send
149                                      //packets out
150 };