summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_engine.c
blob: b1207ebc3aa62db0c937495612b6cc41f89d9a0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* BGP Engine pThread -- functions
 * Copyright (C) 2009 Chris Hall (GMCH), Highwayman
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Zebra; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <zebra.h>

#include "bgpd/bgp_engine.h"

#include "lib/memory.h"
#include "lib/symtab.h"

/*==============================================================================
 * The BGP Engine pThread contains:
 *
 *   * the BGP Finite State Machine (FSM) for BGP Sessions
 *   * the encoding and decoding of BGP protocol messages
 *   * all related socket handling and I/O
 *   * all related timers
 *
 * The BGP Engine communicates with the BGP Routeing pthread(s) via two Message
 * Queues.
 *
 * There are also shared pools of data:
 *
 *   * the BGP session structures, which ...
 *   * the Attributes Store
 *   * the Prefixes Store
 *   ...
 *
 * Other pthread-safe facilities used:
 *
 *   * logging
 *   * privilege raising/lowering
 *   ...
 *
 * At the heart of the BGP Engine pthread is a select for the socket I/O, a
 * Message Queue reader and a timer handler.  The Message Queue uses SIGUSR2 to
 * kick the pthread into action if it is stopped on the select.
 *
 */

/*==============================================================================
 * The qpnexus for the BGP Engine.
 *
 *
 */

/*==============================================================================
 * Start the BGP Engine Thread.
 *
 * Initialise the Engine Thread qpnexus
 *
 */

/* BGP Engine side of bgp_engine_start() must call bgp_open_listeners()
 * for which it needs the port and address from command line.
 *
 * Implemented in bgp_main.c
 */

/*==============================================================================
 * Stop the BGP Engine Thread.
 *
 */

/* BGP Engine side of bgp_engine_stop() must call bgp_close_listeners()
 *
 * Implemented in bgp_main.c
 */

/*==============================================================================
 * The BGP Engine Thread main loop
 *
 * Processes:
 *
 *   1) connections with pending work -- local queue.
 *
 *      When a connection fills its output buffers, any further messages
 *      requiring output are placed on the connection's pending queue.
 *
 *      When the output buffers empty sufficiently, some of those messages
 *      can (finally) be processed.
 *
 *      So this is done first.
 *
 *      [This is also where stopped connections are finally reaped.]
 *
 *   2) messages coming from the Routeing Engine -- mqueue_queue.
 *
 *      These will mostly be BGP UPDATE messages, which will either be
 *      processed into the relevant connection's output buffers, or end up
 *      on its pending queue.
 *
 *      There is a flow control mechanism to prevent the Routeing Engine from
 *      flooding the BGP Engine with UPDATE messages.
 *
 *      Other messages start/stop sessions and so on.
 *
 *   3) I/O -- qpselect
 *
 *      This deals with all active sockets for read/write/connect/accept.
 *
 *      Each time a socket is readable, one message is read and dispatched to
 *      the Routeing Engine (or otherwise dealt with by the FSM).
 *
 *      Each time a socket is writable, as much as possible is written to it
 *      from the connection's write buffer.  When the write buffer is drained,
 *      the connection goes back onto the local queue.
 *
 *   4) Timers -- qtimers
 *
 *      Which generate FSM events.
 *
 * Implemented in qpnexus.c
 *
 */


/*==============================================================================
 * The write queue for the BGP Engine
 *
 * Each connection has a single message buffer.  When that has yet to be
 *
 *
 */