blob: c75f2b26307d2d85b144ef527bc0eb1e6fad73a4 [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 *
Willy Tarreau3ebb1162012-02-13 16:57:44 +01005 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
Willy Tarreau5b4c2b52009-10-03 11:21:53 +02006 *
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 Tarreau6b2e11b2009-10-01 07:52:15 +020026#include <types/lb_chash.h>
Willy Tarreau5b4c2b52009-10-03 11:21:53 +020027#include <types/lb_fwlc.h>
28#include <types/lb_fwrr.h>
29#include <types/lb_map.h>
30#include <types/server.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020031
Willy Tarreauf3e49f92009-10-03 12:21:20 +020032/* Parameters for lbprm.algo */
33
34/* Lower bits define the kind of load balancing method, which means the type of
35 * algorithm, and which criterion it is based on. For this reason, those bits
36 * also include information about dependencies, so that the config parser can
37 * detect incompatibilities.
Willy Tarreaudf366142007-11-30 16:23:20 +010038 */
39
Willy Tarreau3ebb1162012-02-13 16:57:44 +010040/* LB parameters are on the lower 8 bits. Depends on the LB kind. */
41
42/* BE_LB_HASH_* is used with BE_LB_KIND_HI */
Willy Tarreauf3e49f92009-10-03 12:21:20 +020043#define BE_LB_HASH_SRC 0x00000 /* hash source IP */
44#define BE_LB_HASH_URI 0x00001 /* hash HTTP URI */
45#define BE_LB_HASH_PRM 0x00002 /* hash HTTP URL parameter */
46#define BE_LB_HASH_HDR 0x00003 /* hash HTTP header value */
47#define BE_LB_HASH_RDP 0x00004 /* hash RDP cookie value */
Willy Tarreau9757a382009-10-03 12:56:50 +020048
Willy Tarreau3ebb1162012-02-13 16:57:44 +010049/* BE_LB_RR_* is used with BE_LB_KIND_RR */
Willy Tarreau9757a382009-10-03 12:56:50 +020050#define BE_LB_RR_DYN 0x00000 /* dynamic round robin (default) */
51#define BE_LB_RR_STATIC 0x00001 /* static round robin */
Willy Tarreau3ebb1162012-02-13 16:57:44 +010052
53/* BE_LB_CB_* is used with BE_LB_KIND_CB */
54#define BE_LB_CB_LC 0x00000 /* least-connections */
55
Willy Tarreauf3e49f92009-10-03 12:21:20 +020056#define BE_LB_PARM 0x000FF /* mask to get/clear the LB param */
57
58/* Required input(s) */
59#define BE_LB_NEED_NONE 0x00000 /* no input needed */
60#define BE_LB_NEED_ADDR 0x00100 /* only source address needed */
61#define BE_LB_NEED_DATA 0x00200 /* some payload is needed */
62#define BE_LB_NEED_HTTP 0x00400 /* an HTTP request is needed */
63/* not used: 0x0800 */
64#define BE_LB_NEED 0x00F00 /* mask to get/clear dependencies */
65
66/* Algorithm */
67#define BE_LB_KIND_NONE 0x00000 /* algorithm not set */
68#define BE_LB_KIND_RR 0x01000 /* round-robin */
Willy Tarreau3ebb1162012-02-13 16:57:44 +010069#define BE_LB_KIND_CB 0x02000 /* connection-based */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020070#define BE_LB_KIND_HI 0x03000 /* hash of input (see hash inputs above) */
Willy Tarreauf3e49f92009-10-03 12:21:20 +020071#define BE_LB_KIND 0x07000 /* mask to get/clear LB algorithm */
72
73/* All known variants of load balancing algorithms. These can be cleared using
74 * the BE_LB_ALGO mask. For a check, using BE_LB_KIND is preferred.
75 */
76#define BE_LB_ALGO_NONE (BE_LB_KIND_NONE | BE_LB_NEED_NONE) /* not defined */
77#define BE_LB_ALGO_RR (BE_LB_KIND_RR | BE_LB_NEED_NONE) /* round robin */
Willy Tarreau3ebb1162012-02-13 16:57:44 +010078#define BE_LB_ALGO_LC (BE_LB_KIND_CB | BE_LB_NEED_NONE | BE_LB_CB_LC) /* least connections */
Willy Tarreau9757a382009-10-03 12:56:50 +020079#define BE_LB_ALGO_SRR (BE_LB_KIND_RR | BE_LB_NEED_NONE | BE_LB_RR_STATIC) /* static round robin */
Willy Tarreauf3e49f92009-10-03 12:21:20 +020080#define BE_LB_ALGO_SH (BE_LB_KIND_HI | BE_LB_NEED_ADDR | BE_LB_HASH_SRC) /* hash: source IP */
81#define BE_LB_ALGO_UH (BE_LB_KIND_HI | BE_LB_NEED_HTTP | BE_LB_HASH_URI) /* hash: HTTP URI */
82#define BE_LB_ALGO_PH (BE_LB_KIND_HI | BE_LB_NEED_HTTP | BE_LB_HASH_PRM) /* hash: HTTP URL parameter */
83#define BE_LB_ALGO_HH (BE_LB_KIND_HI | BE_LB_NEED_HTTP | BE_LB_HASH_HDR) /* hash: HTTP header value */
84#define BE_LB_ALGO_RCH (BE_LB_KIND_HI | BE_LB_NEED_DATA | BE_LB_HASH_RDP) /* hash: RDP cookie value */
85#define BE_LB_ALGO (BE_LB_KIND | BE_LB_NEED | BE_LB_PARM ) /* mask to clear algo */
86
87/* Higher bits define how a given criterion is mapped to a server. In fact it
88 * designates the LB function by itself. The dynamic algorithms will also have
89 * the DYN bit set. These flags are automatically set at the end of the parsing.
90 */
91#define BE_LB_LKUP_NONE 0x00000 /* not defined */
92#define BE_LB_LKUP_MAP 0x10000 /* static map based lookup */
93#define BE_LB_LKUP_RRTREE 0x20000 /* FWRR tree lookup */
94#define BE_LB_LKUP_LCTREE 0x30000 /* FWLC tree lookup */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020095#define BE_LB_LKUP_CHTREE 0x40000 /* consistent hash */
Willy Tarreauf3e49f92009-10-03 12:21:20 +020096#define BE_LB_LKUP 0x70000 /* mask to get just the LKUP value */
97
98/* additional properties */
99#define BE_LB_PROP_DYN 0x80000 /* bit to indicate a dynamic algorithm */
100
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200101/* hash types */
102#define BE_LB_HASH_MAP 0x000000 /* map-based hash (default) */
103#define BE_LB_HASH_CONS 0x100000 /* consistent hashbit to indicate a dynamic algorithm */
Willy Tarreau798a39c2010-11-24 15:04:29 +0100104#define BE_LB_HASH_AVAL 0x200000 /* run an avalanche hash before a map */
105#define BE_LB_HASH_TYPE 0x300000 /* get/clear hash types */
Willy Tarreaub625a082007-11-26 01:15:43 +0100106
107/* various constants */
Willy Tarreaub698f0f2007-12-02 11:01:23 +0100108
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200109/* The scale factor between user weight and effective weight allows smooth
Willy Tarreaub698f0f2007-12-02 11:01:23 +0100110 * weight modulation even with small weights (eg: 1). It should not be too high
111 * though because it limits the number of servers in FWRR mode in order to
112 * prevent any integer overflow. The max number of servers per backend is
113 * limited to about 2^32/255^2/scale ~= 66051/scale. A scale of 16 looks like
114 * a good value, as it allows more than 4000 servers per backend while leaving
115 * modulation steps of about 6% for servers with the lowest weight (1).
116 */
117#define BE_WEIGHT_SCALE 16
Willy Tarreaub625a082007-11-26 01:15:43 +0100118
Willy Tarreau5b4c2b52009-10-03 11:21:53 +0200119/* LB parameters for all algorithms */
120struct lbprm {
Willy Tarreauf3e49f92009-10-03 12:21:20 +0200121 int algo; /* load balancing algorithm and variants: BE_LB_* */
Willy Tarreau5b4c2b52009-10-03 11:21:53 +0200122 int tot_wact, tot_wbck; /* total effective weights of active and backup servers */
123 int tot_weight; /* total effective weight of servers participating to LB */
124 int tot_used; /* total number of servers used for LB */
125 int wmult; /* ratio between user weight and effective weight */
126 int wdiv; /* ratio between effective weight and user weight */
127 struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */
128 struct lb_map map; /* LB parameters for map-based algorithms */
129 struct lb_fwrr fwrr;
130 struct lb_fwlc fwlc;
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200131 struct lb_chash chash;
Willy Tarreau5b4c2b52009-10-03 11:21:53 +0200132 /* Call backs for some actions. Some may be NULL (thus should be ignored). */
133 void (*update_server_eweight)(struct server *); /* to be called after eweight change */
134 void (*set_server_status_up)(struct server *); /* to be called after status changes to UP */
135 void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN */
136 void (*server_take_conn)(struct server *); /* to be called when connection is assigned */
137 void (*server_drop_conn)(struct server *); /* to be called when connection is dropped */
138};
139
Willy Tarreaubaaee002006-06-26 02:48:02 +0200140#endif /* _TYPES_BACKEND_H */
141
142/*
143 * Local variables:
144 * c-indent-level: 8
145 * c-basic-offset: 8
146 * End:
147 */