blob: 7e5b3420d73b16e9c5aab6c4ba1e7ca064ec3145 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau5b4c2b52009-10-03 11:21:53 +02002 * include/types/backend.h
3 * This file assembles definitions for backends
4 *
5 * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020021
22#ifndef _TYPES_BACKEND_H
23#define _TYPES_BACKEND_H
24
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreau5b4c2b52009-10-03 11:21:53 +020026#include <types/lb_fwlc.h>
27#include <types/lb_fwrr.h>
28#include <types/lb_map.h>
29#include <types/server.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020030
Willy Tarreau5b4c2b52009-10-03 11:21:53 +020031/* Parameters for lbprm.algo.
Willy Tarreaudf366142007-11-30 16:23:20 +010032 * The low part of the value is unique for each algo so that applying the mask
33 * BE_LB_ALGO returns a unique algorithm.
34 * The high part indicates specific properties.
35 */
36
37/* Masks to extract algorithm properties */
38#define BE_LB_ALGO 0x000007FF /* mask to extract all algorithm flags */
39#define BE_LB_PROP_DYN 0x00000100 /* mask to match dynamic algorithms */
40#define BE_LB_PROP_L4 0x00000200 /* mask to match layer4-based algorithms */
41#define BE_LB_PROP_L7 0x00000400 /* mask to match layer7-based algorithms */
42
43/* the algorithms themselves */
44#define BE_LB_ALGO_NONE 0x00000000 /* dispatch or transparent mode */
45#define BE_LB_ALGO_RR (BE_LB_PROP_DYN | 0x01) /* fast weighted round-robin mode (dynamic) */
46#define BE_LB_ALGO_SH (BE_LB_PROP_L4 | 0x02) /* balance on source IP hash */
47#define BE_LB_ALGO_UH (BE_LB_PROP_L7 | 0x03) /* balance on URI hash */
48#define BE_LB_ALGO_PH (BE_LB_PROP_L7 | 0x04) /* balance on URL parameter hash */
Benoitaffb4812009-03-25 13:02:10 +010049#define BE_LB_ALGO_LC (BE_LB_PROP_DYN | 0x05) /* fast weighted leastconn mode (dynamic) */
50#define BE_LB_ALGO_HH (BE_LB_PROP_L7 | 0x06) /* balance on Http Header value */
Emeric Brun736aa232009-06-30 17:56:00 +020051#define BE_LB_ALGO_RCH (BE_LB_PROP_L4 | 0x07) /* balance on RDP Cookie value */
Willy Tarreaub625a082007-11-26 01:15:43 +010052
53/* various constants */
Willy Tarreaub698f0f2007-12-02 11:01:23 +010054
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +020055/* The scale factor between user weight and effective weight allows smooth
Willy Tarreaub698f0f2007-12-02 11:01:23 +010056 * weight modulation even with small weights (eg: 1). It should not be too high
57 * though because it limits the number of servers in FWRR mode in order to
58 * prevent any integer overflow. The max number of servers per backend is
59 * limited to about 2^32/255^2/scale ~= 66051/scale. A scale of 16 looks like
60 * a good value, as it allows more than 4000 servers per backend while leaving
61 * modulation steps of about 6% for servers with the lowest weight (1).
62 */
63#define BE_WEIGHT_SCALE 16
Willy Tarreaub625a082007-11-26 01:15:43 +010064
Willy Tarreau5b4c2b52009-10-03 11:21:53 +020065/* LB parameters for all algorithms */
66struct lbprm {
67 int algo; /* load balancing algorithm and variants: BE_LB_ALGO_* */
68 int tot_wact, tot_wbck; /* total effective weights of active and backup servers */
69 int tot_weight; /* total effective weight of servers participating to LB */
70 int tot_used; /* total number of servers used for LB */
71 int wmult; /* ratio between user weight and effective weight */
72 int wdiv; /* ratio between effective weight and user weight */
73 struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */
74 struct lb_map map; /* LB parameters for map-based algorithms */
75 struct lb_fwrr fwrr;
76 struct lb_fwlc fwlc;
77 /* Call backs for some actions. Some may be NULL (thus should be ignored). */
78 void (*update_server_eweight)(struct server *); /* to be called after eweight change */
79 void (*set_server_status_up)(struct server *); /* to be called after status changes to UP */
80 void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN */
81 void (*server_take_conn)(struct server *); /* to be called when connection is assigned */
82 void (*server_drop_conn)(struct server *); /* to be called when connection is dropped */
83};
84
Willy Tarreaubaaee002006-06-26 02:48:02 +020085#endif /* _TYPES_BACKEND_H */
86
87/*
88 * Local variables:
89 * c-indent-level: 8
90 * c-basic-offset: 8
91 * End:
92 */