OSDN Git Service

trunk整理
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / module / schedule / schedule_module_wrr.h
1 /*
2  *    @file    schedule_module_wrr.h
3  *    @brief    shared object schedule module class
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24 #ifndef    SCHEDULE_MODULE_WRR_H
25 #define    SCHEDULE_MODULE_WRR_H
26
27 #include "schedule_module_base.h"
28
29 namespace l7vs
30 {
31
32 class schedule_module_weighted_round_robin : public schedule_module_base
33 {
34 protected:
35         boost::asio::ip::tcp::endpoint    tcp_endpoint ;
36         boost::asio::ip::udp::endpoint    udp_endpoint ;
37
38         struct wrr_weights {
39                 int currentWeight;  /*! Current Weight */
40                 int maxWeight;      /*! Max of Weight */
41                 int gcd;            /*! G.C.D. of RealServer list */
42                 wrr_weights() : currentWeight(0), maxWeight(0), gcd(0) {}
43         } vs_weights;
44 public:
45         //!    constructor
46         schedule_module_weighted_round_robin();
47         //! destructor
48         ~schedule_module_weighted_round_robin();
49
50         //!    initialize function
51         void    initialize();
52
53         //! tcp protocol support check
54         //! @return tcp support is true
55         //! @return tcp not-support is false
56         bool    is_tcp();
57         //! udp protocol support check
58         //! @return udp support is true
59         //! @return udp not-support is false
60         bool    is_udp();
61
62         //! handle schedule called then schedule function for TCP/IP endpoint
63         //! @param[in]    thread id
64         //! @param[in]    list iterator first function object
65         //!    @param[in]    list iterator last function object
66         //!    @param[in]    list iterator next function object
67         //! @param[out]    scheduled TCP/IP endpoint
68         void    handle_schedule(
69                 boost::thread::id                    thread_id,
70                 rslist_iterator_begin_func_type        inlist_begin,
71                 rslist_iterator_end_func_type        inlist_end,
72                 rslist_iterator_next_func_type        inlist_next,
73                 boost::asio::ip::tcp::endpoint        &outendpoint);
74
75         //! handle schedule calls then schedule function for UDP endpoint
76         //! @param[in]    thread id
77         //! @param[in]    list iterator first function object
78         //!    @param[in]    list iterator last function object
79         //!    @param[in]    list iterator next function object
80         //! @param[out]    scheduled UDP endpoint
81         void    handle_schedule(
82                 boost::thread::id                    thread_id,
83                 rslist_iterator_begin_func_type        inlist_begin,
84                 rslist_iterator_end_func_type        inlist_end,
85                 rslist_iterator_next_func_type        inlist_next,
86                 boost::asio::ip::udp::endpoint        &outendpoint);
87
88         //! replication interval interrupt
89         //! timer thread call this function. from virtualservice.
90         void    replication_interrupt();
91
92 protected:
93         int        sched_wrr_service_init(
94                 rslist_iterator_begin_func_type        inlist_begin,
95                 rslist_iterator_end_func_type        inlist_end,
96                 rslist_iterator_next_func_type        inlist_next);
97         int        sched_wrr_getMaxWeight(
98                 rslist_iterator_begin_func_type        inlist_begin,
99                 rslist_iterator_end_func_type        inlist_end,
100                 rslist_iterator_next_func_type        inlist_next);
101         int        sched_wrr_gcd(int a, int b);
102         int        sched_wrr_getGCD(
103                 rslist_iterator_begin_func_type        inlist_begin,
104                 rslist_iterator_end_func_type        inlist_end,
105                 rslist_iterator_next_func_type        inlist_next);
106 };
107
108 }    //namespace l7vs
109
110 #endif //SCHEDULE_MODULE_WRR_H