Skip to content

Commit ef37587

Browse files
committed
sockets_mgm: add proper README
1 parent 2c43076 commit ef37587

2 files changed

Lines changed: 347 additions & 178 deletions

File tree

modules/sockets_mgm/README

Lines changed: 200 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
Example Module
1+
Dynamic Sockets Management Module
22
__________________________________________________________
33

44
Table of Contents
55

66
1. Admin Guide
77

88
1.1. Overview
9-
1.2. Dependencies
9+
1.2. Sockets
1010

11-
1.2.1. OpenSIPS Modules
12-
1.2.2. External Libraries or Applications
11+
1.2.1. UDP handling
12+
1.2.2. TCP handling
1313

14-
1.3. Exported Parameters
14+
1.3. Limitations
15+
1.4. Dependencies
1516

16-
1.3.1. default_str (string)
17-
1.3.2. default_int (integer)
17+
1.4.1. OpenSIPS Modules
18+
1.4.2. External Libraries or Applications
1819

19-
1.4. Exported Functions
20+
1.5. Exported Parameters
2021

21-
1.4.1. example()
22-
1.4.2. example_str([string])
23-
1.4.3. example_int([int])
22+
1.5.1. db_url (string)
23+
1.5.2. table_name (string)
24+
1.5.3. socket_column (string)
25+
1.5.4. advertised_column (string)
26+
1.5.5. tag_column (string)
27+
1.5.6. flags_column (string)
28+
1.5.7. tos_column (string)
29+
1.5.8. processes (integer)
30+
1.5.9. max_sockets (integer)
31+
32+
1.6. Exported MI Functions
33+
34+
1.6.1. sockets_reload
35+
1.6.2. sockets_list
2436

2537
2. Contributors
2638

@@ -40,106 +52,229 @@ Example Module
4052

4153
List of Examples
4254

43-
1.1. Set “default_str” parameter
44-
1.2. Set “default_int” parameter
45-
1.3. example usage
46-
1.4. example_str() usage
47-
1.5. example_int() usage
55+
1.1. Set "db_url" parameter
56+
1.2. Set "table_name" parameter
57+
1.3. Set "socket_column" parameter
58+
1.4. Set "advertised_column" parameter
59+
1.5. Set "tag_column" parameter
60+
1.6. Set "flags_column" parameter
61+
1.7. Set "tos_column" parameter
62+
1.8. Set "processes" parameter
63+
1.9. Set "max_sockets" parameter
4864

4965
Chapter 1. Admin Guide
5066

5167
1.1. Overview
5268

53-
This module serves as an example of how to write a module in
54-
OpenSIPS. Its primary goal is to simplify the development of
55-
new modules for newcomers, providing a clear and accessible
56-
starting point.
57-
58-
1.2. Dependencies
59-
60-
1.2.1. OpenSIPS Modules
69+
This module provides the means to provision and manage dynamic
70+
sockets for OpenSIPS at runtime. The definition of the sockets
71+
is stored in an SQL database and can be dynamically changed at
72+
runtime.
73+
74+
The module caches the entire table sockets and only adjusts the
75+
dynamic socket list after a reload using the sockets_reload MI
76+
command.
77+
78+
The sockets_list MI command. can be used to show all the
79+
dynamic sockets OpenSIPS is listening on.
80+
81+
1.2. Sockets
82+
83+
The module exclusively handles sockets used for SIP traffic
84+
(e.g., UDP, TCP, TLS, WSS). It does not support BIN or HEP
85+
listeners, as these cannot be dynamically utilized or enforced
86+
in the script.
87+
88+
The management of dynamic sockets is divided into two
89+
behaviors, depending on whether the traffic is UDP-based or
90+
TCP-based. Based on the nature of your traffic, ensure that
91+
your settings are properly tuned to accommodate any sockets you
92+
may provision dynamically.
93+
94+
1.2.1. UDP handling
95+
96+
All dynamically added UDP sockets are assigned to a group of
97+
dedicated extra processes. The number of these processes can be
98+
adjusted using the processes parameter. These processes handle
99+
UDP-based socket traffic evenly by balancing requests across
100+
the less loaded processes. The difference, however, is that
101+
static sockets are bound to designated processes, while dynamic
102+
sockets share the pool of extra processes.
103+
104+
1.2.2. TCP handling
105+
106+
In contrast to UDP traffic handling, TCP traffic is processed
107+
in the same way as all other TCP traffic: requests are
108+
dispatched to one of the existing static TCP processes.
109+
110+
1.3. Limitations
111+
112+
Although traffic processing by dynamic workers closely
113+
resembles that of static ones, there are certain limitations
114+
associated with using dynamic sockets:
115+
116+
* UDP socket handling does not currently benefit from the
117+
autoscaling feature for the designated extra processes.
118+
This means that the number of processes defined at startup
119+
will always be forked, and only these processes will handle
120+
all traffic associated with dynamically added UDP sockets.
121+
* As stated earlier, the module only supports SIP based
122+
dynamic listener, no HEP or BIN.
123+
* Sockets defined in the database cannot be expanded to more
124+
than one listener. This means you cannot use an interface
125+
name or an alias that resolves to multiple IPs as a host.
126+
Only a single IP:port socket will be created, so
127+
provisioning should ideally be done with an explicit IP.
128+
* Due to some internal limitations, the dynamic sockets need
129+
to be pre-allocated at startup. This means that the number
130+
of dynamic sockets used at runtime have to be limited by a
131+
static value, defined at startup. This is why it is
132+
recommended to use a fairly high value for the sockets in
133+
the max_sockets parameter - we're defaulting a confortable
134+
100 sockets.
135+
* The sockets defined in the max_sockets are being rotated in
136+
a FIFO manner - this way we are trying to avoid overlapping
137+
sockets in a short period of time.
138+
139+
1.4. Dependencies
140+
141+
1.4.1. OpenSIPS Modules
61142

62143
The following modules must be loaded before this module:
63-
* No dependencies on other OpenSIPS modules.
144+
* A database module is needed for fetching the sockets.
64145

65-
1.2.2. External Libraries or Applications
146+
1.4.2. External Libraries or Applications
66147

67148
The following libraries or applications must be installed
68149
before running OpenSIPS with this module loaded:
69150
* None.
70151

71-
1.3. Exported Parameters
152+
1.5. Exported Parameters
153+
154+
1.5.1. db_url (string)
155+
156+
The database URL where the sockets are fetched from.
157+
158+
Default value is
159+
"mysql://opensips:opensipsrw@localhost/opensips".
160+
161+
Example 1.1. Set "db_url" parameter
162+
...
163+
modparam("sockets_mgm", "db_url", "dbdriver://username:password@dbhost/d
164+
bname")
165+
...
72166

73-
1.3.1. default_str (string)
167+
1.5.2. table_name (string)
74168

75-
The default parameter used when the example_str() function is
76-
called without any parameter.
169+
The database table name where the sockets are stored.
77170

78-
Default value is “” (empty sring).
171+
Default value is "sockets".
79172

80-
Example 1.1. Set “default_str” parameter
173+
Example 1.2. Set "table_name" parameter
81174
...
82-
modparam("example", "default_str", "TEST")
175+
modparam("sockets_mgm", "table_name", "sockets_def")
83176
...
84177

85-
1.3.2. default_int (integer)
178+
1.5.3. socket_column (string)
86179

87-
The default parameter used when the example_int() function is
88-
called without any parameter.
180+
The database table column where the socket definition is
181+
stored.
89182

90-
Default value is “0”.
183+
Default value is "socket".
91184

92-
Example 1.2. Set “default_int” parameter
185+
Example 1.3. Set "socket_column" parameter
93186
...
94-
modparam("example", "default_int", -1)
187+
modparam("sockets_mgm", "socket_column", "sock")
95188
...
96189

97-
1.4. Exported Functions
190+
1.5.4. advertised_column (string)
191+
192+
The database table column where the advertised definition is
193+
stored.
194+
195+
Default value is "advertised".
98196

99-
1.4.1. example()
197+
Example 1.4. Set "advertised_column" parameter
198+
...
199+
modparam("advertiseds_mgm", "advertised_column", "adv")
200+
...
100201

101-
Function that simply prints a message to log, saying that it
102-
has been called.
202+
1.5.5. tag_column (string)
103203

104-
This function can be used from any route.
204+
The database table column where the tag definition is stored.
105205

106-
Example 1.3. example usage
206+
Default value is "tag".
207+
208+
Example 1.5. Set "tag_column" parameter
107209
...
108-
example();
210+
modparam("tags_mgm", "tag_column", "sock")
109211
...
110212

111-
1.4.2. example_str([string])
213+
1.5.6. flags_column (string)
214+
215+
The database table column where the flags definition is stored.
112216

113-
Function that simply prints a message to log, saying that it
114-
has been called. If a parameter is passed, it is printed in the
115-
log, otherwise the value of default_str parameter is used.
217+
Default value is "flags".
116218

117-
Meaning of the parameters is as follows:
118-
* string (string, optional) - parameter to be logged
219+
Example 1.6. Set "flags_column" parameter
220+
...
221+
modparam("flagss_mgm", "flags_column", "sock")
222+
...
223+
224+
1.5.7. tos_column (string)
225+
226+
The database table column where the tos definition is stored.
119227

120-
This function can be used from any route.
228+
Default value is "tos".
121229

122-
Example 1.4. example_str() usage
230+
Example 1.7. Set "tos_column" parameter
123231
...
124-
example_str("test");
232+
modparam("toss_mgm", "tos_column", "sock")
125233
...
126234

127-
1.4.3. example_int([int])
235+
1.5.8. processes (integer)
236+
237+
The number of processes designated to handle UDP sockets.
238+
239+
Default value is "8".
240+
241+
Example 1.8. Set "processes" parameter
242+
...
243+
modparam("sockets_mgm", "processes", 32)
244+
...
128245

129-
Function that simply prints a message to log, saying that it
130-
has been called. If a parameter is passed, it is printed in the
131-
log, otherwise the value of default_int parameter is used.
246+
1.5.9. max_sockets (integer)
132247

133-
Meaning of the parameters is as follows:
134-
* int (integer, optional) - parameter to be logged
248+
The maximum number of sockets that can be defined dinamically.
249+
See the Limitations section for more information.
135250

136-
This function can be used from any route.
251+
Default value is "100".
137252

138-
Example 1.5. example_int() usage
253+
Example 1.9. Set "max_sockets" parameter
139254
...
140-
example_int(10);
255+
modparam("sockets_mgm", "max_sockets", 2000)
141256
...
142257

258+
1.6. Exported MI Functions
259+
260+
1.6.1. sockets_reload
261+
262+
MI command used to reload the sockets from the database.
263+
264+
MI FIFO Command Format:
265+
## reload sockets from the database
266+
opensips-mi sockets_reload
267+
opensips-cli -x mi sockets_reload
268+
269+
1.6.2. sockets_list
270+
271+
MI command to list all the currently used dynamic sockets.
272+
273+
MI FIFO Command Format:
274+
## reload sockets from the database
275+
opensips-mi sockets_list
276+
opensips-cli -x mi sockets_list
277+
143278
Chapter 2. Contributors
144279

145280
2.1. By Commit Statistics
@@ -182,4 +317,4 @@ Chapter 3. Documentation
182317

183318
Documentation Copyrights:
184319

185-
Copyright © 2024 OpenSIPS Solutions;
320+
Copyright � 2025 OpenSIPS Solutions;

0 commit comments

Comments
 (0)