-
Notifications
You must be signed in to change notification settings - Fork 565
/
README
1188 lines (927 loc) · 35.3 KB
/
README
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
B2B_LOGIC
__________________________________________________________
Table of Contents
1. Admin Guide
1.1. Overview
1.2. Scenario Logic
1.3. Dependencies
1.3.1. OpenSIPS Modules
1.3.2. External Libraries or Applications
1.4. Exported Parameters
1.4.1. hash_size (int)
1.4.2. script_req_route (str)
1.4.3. script_reply_route (str)
1.4.4. cleanup_period (int)
1.4.5. custom_headers_regexp (str)
1.4.6. custom_headers (str)
1.4.7. use_init_sdp (int)
1.4.8. db_url (str)
1.4.9. cachedb_url (str)
1.4.10. cachedb_key_prefix (string)
1.4.11. update_period (int)
1.4.12. max_duration (int)
1.4.13. contact_user (int)
1.4.14. b2bl_from_spec_param (string)
1.4.15. server_address (str)
1.4.16. init_callid_hdr (str)
1.4.17. db_mode (int)
1.4.18. db_table (str)
1.4.19. b2bl_th_init_timeout (int)
1.5. Exported Functions
1.5.1. b2b_init_request(id, [flags], [req_route],
[reply_route], [init_sdp_body],
[init_sdp_ctype])
1.5.2. b2b_server_new(id, [adv_contact],
[extra_hdrs], [extra_hdr_bodies])
1.5.3. b2b_client_new(id, dest_uri, [proxy],
[from_dname], [adv_contact], [extra_hdrs],
[extra_hdr_bodies])
1.5.4. b2b_bridge(entity1, entity2, [provmedia_uri],
[flags])
1.5.5. b2b_pass_request()
1.5.6. b2b_handle_reply()
1.5.7. b2b_send_reply(code, reason)
1.5.8. b2b_delete_entity()
1.5.9. b2b_end_dlg_leg()
1.5.10. b2b_bridge_request(b2bl_key,entity_no)
1.6. Exported MI Functions
1.6.1. b2b_trigger_scenario
1.6.2. b2b_bridge
1.6.3. b2b_list
1.6.4. b2b_terminate_call
1.7. Exported Pseudo-Variables
1.7.1. $b2b_logic.key
1.7.2. $b2b_logic.entity(field)[idx]
1.7.3. $b2b_logic.ctx(key)
1.7.4. $b2b_logic.scenario(key)
2. Developer Guide
2.1. b2b_logic_bind(b2bl_api_t* api)
2.2. init
2.3. bridge
2.4. bridge_extern
2.5. bridge_2calls
2.6. terminate_call
2.7. set_state
2.8. bridge_msg
3. Contributors
3.1. By Commit Statistics
3.2. By Commit Activity
4. Documentation
4.1. Contributors
List of Tables
3.1. Top contributors by DevScore^(1), authored commits^(2) and
lines added/removed^(3)
3.2. Most recently active contributors^(1) to this module
List of Examples
1.1. Set server_hsize parameter
1.2. Set script_req_route parameter
1.3. Set script_repl_route parameter
1.4. Set cleanup_period parameter
1.5. Set parameter
1.6. Set parameter
1.7. Set parameter
1.8. Set db_url parameter
1.9. Set cachedb_url parameter
1.10. Set cachedb_key_prefix parameter
1.11. Set update_period parameter
1.12. Set max_duration parameter
1.13. Set contact_user parameter
1.14. Set b2bl_from_spec_param parameter
1.15. Set server_address parameter
1.16. Set init_callid_hdr parameter
1.17. Set db_mode parameter
1.18. Set db_table parameter
1.19. Set b2bl_th_init_timeout parameter
1.20. b2b_init_request usage
1.21. b2b_server_new usage
1.22. b2b_client_new usage
1.23. b2b_bridge usage
1.24. b2b_pass_request usage
1.25. b2b_handle_reply usage
1.26. b2b_send_reply usage
1.27. b2b_delete_entity usage
1.28. b2b_end_dlg_leg usage
1.29. b2b_bridge_request usage
1.30. $b2b_logic.key usage
1.31. $b2b_logic.entity usage
1.32. $b2b_logic.ctx usage
1.33. $b2b_logic.scenario usage
2.1. b2bl_api_t structure
Chapter 1. Admin Guide
1.1. Overview
The B2BUA implementation in OpenSIPS is separated in two
layers:
* a lower one (implemented in the b2b_entities module) - the
basic functions of a UAS and UAC
* an upper one (implemented in b2b_logic module) - which
represents the logic engine of B2BUA, responsible of
actually implementing the B2BUA services using the
functions offered by the low level.
This module is a B2BUA upper level implementation that can be
used along with the b2b_entities module in order to provide
various B2BUA services (eg. PBX features). The actual logic of
the B2BUA scenarios can be implemented in dedicated script
routes.
A B2B session can be triggered in two ways:
* from the script - at the receipt of an initial INVITE
message
* with an extern command (MI) command - the server will
connect two end points in a session(Third Party Call
Control).
High Availability for B2B sessions can be achieved by enabling
the clustering support offered by the the lower b2b_entities
module (by setting the cluster_id modparam from b2b_entities).
1.2. Scenario Logic
After initializing a B2B session, the call legs will be handled
by the b2b_logic module and the first step will be to put the
two initial entities in contact. Requests and replies belonging
to these dialogs will not enter the script through the standard
OpenSIPS routes but instead will be handled in b2b_logic
dedicated routes (defined through the script_req_route and
script_reply_route modparams or, the custom routes given as
parameters to b2b_init_request()). The further steps of the
scenario can be implemented in these routes, by calling
dedicated b2b_logic script functions in order to perform
various actions. Normal "proxy-like" OpenSIPS functions should
not be executed in the b2b_logic routes.
Some messages will be handled automatically by the module and
will not enter the b2b_logic routes at all (BYE requests
received while in the process of bridging two entities,
ACKs/BYEs/replies for disconnected entities). Also, if no
dedicated b2b_logic reply route is defined, replies will be
handled internally by the module, with the same effects as
calling b2b_handle_reply() from such a route if it were
defined.
1.3. Dependencies
1.3.1. OpenSIPS Modules
* b2b_entities, a db module
1.3.2. External Libraries or Applications
No libraries or applications required before running OpenSIPS
with this module.
1.4. Exported Parameters
1.4.1. hash_size (int)
The size of the hash table that stores the session entities.
Default value is “9” (512 records).
Example 1.1. Set server_hsize parameter
...
modparam("b2b_logic", "hash_size", 10)
...
1.4.2. script_req_route (str)
The name of the script route to be called when requests
belonging to an ongoing B2B session are received.
Example 1.2. Set script_req_route parameter
...
modparam("b2b_logic", "script_req_route", "b2b_request")
...
1.4.3. script_reply_route (str)
The name of the script route to be called when replies
belonging to an ongoing B2B session are received.
Example 1.3. Set script_repl_route parameter
...
modparam("b2b_logic", "script_reply_route", "b2b_reply")
...
1.4.4. cleanup_period (int)
The time interval at which to search for an hanged b2b context.
A session is considered expired if the duration of a session
exceeds its defined lifetime. At that moment, BYE is sent in
all the dialogs from that context and the context is deleted.
Default value is “100”.
Example 1.4. Set cleanup_period parameter
...
modparam("b2b_logic", "cleanup_period", 60)
...
1.4.5. custom_headers_regexp (str)
Regexp to search SIP header by names that should be passed from
the dialog of one side to the other side. There are a number of
headers that are passed by default. They are:
* Content-Type
* Supported
* Allow
* Proxy-Require
* Session-Expires
* Min-SE
* Require
* RSeq
If you wish some other headers to be passed also you should
define them by setting this parameter.
It can be in forms like "regexp", "/regexp/" and
"/regexp/flags".
Meaning of the flags is as follows:
* i - Case insensitive search.
* e - Use extended regexp.
Default value is “NULL”.
Example 1.5. Set parameter
...
modparam("b2b_logic", "custom_headers_regexp", "/^x-/i")
...
1.4.6. custom_headers (str)
A list of SIP header names delimited by ';' that should be
passed from the dialog of one side to the other side. There are
a number of headers that are passed by default. They are:
* Max-Forwards (it is decreased by 1)
* Content-Type
* Supported
* Allow
* Proxy-Require
* Session-Expires
* Min-SE
* Require
* RSeq
If you wish some other headers to be passed also you should
define them by setting this parameter.
Default value is “NULL”.
Example 1.6. Set parameter
...
modparam("b2b_logic", "custom_headers", "User-Agent;Date")
...
1.4.7. use_init_sdp (int)
This parameter modifies the behaviour of the B2BUA when
bridging and a provisional media uri is set. For playing media
while the callee answers (that is connecting the caller to a
media server), the bridging with the callee must start by
sending an Invite to it. The correct way is to send an Invite
without a body in this case, but it has been observed that not
many gateways support this. So, the solution is to use the sdp
received in the first Invite from the caller and put it as the
body for this invite. By setting this parameter, this behavior
is enabled. You can also set use_init_sdp per session and
overwrite this global value.
Default value is “0”.
Example 1.7. Set parameter
...
modparam("b2b_logic", "use_init_sdp", 1)
...
1.4.8. db_url (str)
Database URL.
Example 1.8. Set db_url parameter
...
modparam("b2b_logic", "db_url", "mysql://opensips:opensipsrw@127.0.0.1/o
pensips")
...
1.4.9. cachedb_url (str)
URL of a NoSQL database to be used. Only Redis is supported at
the moment.
Example 1.9. Set cachedb_url parameter
...
modparam("b2b_logic", "cachedb_url", "redis://localhost:6379/")
...
1.4.10. cachedb_key_prefix (string)
Prefix to use for every key set in the NoSQL database.
Default value is “b2bl$”.
Example 1.10. Set cachedb_key_prefix parameter
...
modparam("b2b_logic", "cachedb_key_prefix", "b2b")
...
1.4.11. update_period (int)
The time interval at which to update the info in database.
Default value is “100”.
Example 1.11. Set update_period parameter
...
modparam("b2b_logic", "update_period", 60)
...
1.4.12. max_duration (int)
The maximum duration of a call.
Default value is “12 * 3600 (12 hours)”.
If you set it to 0, there will be no limitation.
Example 1.12. Set max_duration parameter
...
modparam("b2b_logic", "max_duration", 7200)
...
1.4.13. contact_user (int)
If set to 1, adds user from From: header to generated Contact:
Default value is “0”.
Example 1.13. Set contact_user parameter
...
modparam("b2b_logic", "contact_user", 1)
...
1.4.14. b2bl_from_spec_param (string)
The name of the pseudo variable for storing the new “From”
header. The PV must be set before calling “b2b_init_request”.
Default value is “NULL” (disabled).
Example 1.14. Set b2bl_from_spec_param parameter
...
modparam("b2b_logic", "b2bl_from_spec_param", "$var(b2bl_from)")
...
route{
...
# setting the From header
$var(b2bl_from) = "\"Call ID\" <sip:user@opensips.org>";
...
b2b_init_request("top hiding");
...
}
1.4.15. server_address (str)
The IP address of the machine that will be used as Contact in
the generated messages. This is compulsory only when OpenSIPS
starts a call from the middle. For scenarios triggered by
received calls, if it is not set, it is constructed dynamically
from the socket where the initiating request was received. This
socket will be used to send all the requests, replies for that
session.
Example 1.15. Set server_address parameter
...
modparam("b2b_logic", "server_address", "sip:sa@10.10.10.10:5060")
...
1.4.16. init_callid_hdr (str)
The module offers the possibility to insert the original callid
in a header in the generated Invites. If you want this, set
this parameter to the name of the header in which to insert the
original callid.
Example 1.16. Set init_callid_hdr parameter
...
modparam("b2b_logic", "init_callid_hdr", "Init-CallID")
...
1.4.17. db_mode (int)
The B2B modules have support for the 3 type of database storage
* NO DB STORAGE - set this parameter to 0
* WRITE THROUGH (synchronous write in database) - set this
parameter to 1
* WRITE BACK (update in db from time to time) - set this
parameter to 2
Default value is “2” (WRITE BACK).
Example 1.17. Set db_mode parameter
...
modparam("b2b_logic", "db_mode", 1)
...
1.4.18. db_table (str)
Name of the database table to be used
Default value is “b2b_logic”
Example 1.18. Set db_table parameter
...
modparam("b2b_logic", "db_table", "some_table_name")
...
1.4.19. b2bl_th_init_timeout (int)
Call setup timeout for topology hiding scenario.
Default value is “60”
Example 1.19. Set b2bl_th_init_timeout parameter
...
modparam("b2b_logic", "b2bl_th_init_timeout", 60)
...
1.5. Exported Functions
1.5.1. b2b_init_request(id, [flags], [req_route], [reply_route],
[init_sdp_body], [init_sdp_ctype])
This function initializes a new B2B session based on an initial
INVITE. A new server entity and a new client entity must be
created before running this function, with b2b_server_new() and
b2b_client_new(), respectively. These are the initial entities
to be connected and further scenario logic can be implemented
in the b2b_logic dedicated routes.
Parameters:
* scenario_id (string) - identifier for the scenario of this
B2B session. The special value top hiding initializes an
internal topology hiding scenario. This scenario will do a
simple pass-through of messages from one side to another,
and no additional scripting or dedicated routes are
required.
* flags (string, optional) - meanings of the flags is as
follows:
+ t[nn] - Call setup timeout. 0 sets timeout to
max_duration value. Example: t300.
+ a - Transparent authentication. In this mode b2b
passes your 401 or 407 authentication request to
destination server.
+ p - Preserve To: header.
+ s - Use init SDP (as described in the use_init_sdp
modparam) for this session.
* req_route (string, optional) - name of the script route to
be called when requests belonging to this B2B session are
received. This parameter will override the global
script_req_route modparam for this particular B2B session.
* reply_route (string, optional) - name of the script route
to be called when replies belonging to this B2B session are
received. This parameter will override the global
script_reply_route modparam for this particular B2B
session.
* init_sdp_body (string, optional) - SDP body to use as init
SDP (see the use_init_sdp modparam).
* init_sdp_ctype (string, optional) - Content type to use for
the init SDP (see the use_init_sdp modparam).
This function can be used from REQUEST_ROUTE.
Note
If you have a multi interface setup and want to chance the
outbound interface, it is mandatory to use the
"force_send_socket()" core function before passing control to
b2b function. If you do not do it, the requests may be
correctly routed, but the SIP pacakge may be invalid (as
Contact, Via, etc).
Example 1.20. b2b_init_request usage
...
if(is_method("INVITE") && !has_totag() && prepaid_user()) {
...
# create initial entities
b2b_server_new("server1");
b2b_client_new("client1", $var(media_uri));
# initialize B2B session
b2b_init_request("prepaid");
exit;
}
...
1.5.2. b2b_server_new(id, [adv_contact], [extra_hdrs],
[extra_hdr_bodies])
This function creates a new server entity (dialog where
OpenSIPS acts as a UAS) to be used for initializing a new B2B
session. It should only be used for initial INVITES, before
calling b2b_init_request().
Parameters:
* id (string) - ID used to reference this entity in further
B2B actions.
* adv_contact (string, optional) - Contact header to
advertise in generated messages.
* extra_hdrs (var, optioanl) - AVP variable holding a list of
extra headers (the header names) to be added for any
request sent to this entity.
* extra_hdr_bodies (var, optional) - AVP variable holding a
list of extra header bodies (corresponding to the headers
given in the extra_hdrs parameter) to be added for any
request sent to this entity.
This function can be used from REQUEST_ROUTE.
Example 1.21. b2b_server_new usage
...
if(is_method("INVITE") && !has_totag()) {
b2b_server_new("server1", $avp(b2b_hdrs), $avp(b2b_hdr_bodies));
...
}
...
1.5.3. b2b_client_new(id, dest_uri, [proxy], [from_dname],
[adv_contact], [extra_hdrs], [extra_hdr_bodies])
This function creates a new client entity (dialog where
OpenSIPS acts as a UAC) to be used for initializing a new B2B
session or for a bridge action. The function can be used before
calling b2b_init_request() or b2b_bridge().
Parameters:
* id (string) - ID used to reference this entity in further
B2B actions.
* dest_uri (string) - URI of the new destination.
* proxy (string, optional) - URI of the outbound proxy to
send the INVITE to.
* from_dname (string, optional) - Display name to use in the
From header.
* adv_contact (string, optional) - Contact header to
advertise in generated messages.
* extra_hdrs (var, optional) - AVP variable holding a list of
extra headers (the header names) to be added for any
request sent to this entity.
* extra_hdr_bodies (var, optional) - AVP variable holding a
list of extra header bodies (corresponding to the headers
given in the extra_hdrs parameter) to be added for any
request sent to this entity.
This function can be used from REQUEST_ROUTE and the b2b_logic
request routes.
Example 1.22. b2b_client_new usage
...
b2b_client_new("client1", "sip:alice@opensips.org");
...
1.5.4. b2b_bridge(entity1, entity2, [provmedia_uri], [flags])
This function bridges two entities, in the context of an
existing B2B session (the initial entities are already
connected). At least one of the two entities has to be a new
client entity. If an existing entity is provided, the first
step will be to send it a reINVITE.
Parameters:
* entity1 (string) - ID of the first entity to bridge; the
special values: peer and this can also be used to refer to
existing entities.
* entity2 (string) - ID of the second entity to bridge; the
special values: peer and this can also be used to refer to
existing entities.
* provmedia_uri (string, optional) - URI of the provisional
media server to be connected with the caller while the
callee answers.
* flags (string, optional) - meanings of the flags is as
follows:
+ t[nn] - Maximum duration of the B2B session. If the
lifetime expires, the B2BUA will send BYE messages to
both ends and delete the record. Example: t300.
+ n - Enable rfc3515 NOTIFY to inform the agent sending
the REFER of the status of the reference.
+ f - Rollback call to state before bridging in case of
transfer failed, don't hangup the call (default
behaviour).
This function can be used from the b2b_logic request routes.
Example 1.23. b2b_bridge usage
...
route[b2b_logic_request] {
...
b2b_client_new("client2", $hdr(Refer-To));
b2b_bridge("peer", "client2");
}
...
1.5.5. b2b_pass_request()
This function passes a request belonging to an existing B2B
session to the peer entity. The function should be called for
all requests unless a different action is required to implement
the scenario logic (eg. a bridge action).
This function can be used from the b2b_logic request routes.
Example 1.24. b2b_pass_request usage
...
route[b2b_logic_request] {
if ($rm != "BYE") {
b2b_pass_request();
exit;
} else {
# delete the current entity and bridge the peer to a new one
}
...
1.5.6. b2b_handle_reply()
This function processes the received reply by taking the
appropriate actions for the current state of the ongoing B2B
session (pass reply to peer, send INVITE or ACK to comeplete an
ongoing bridge action etc.). The function should be called for
all replies, if a b2b_logic reply route is defined.
This function can be used from the b2b_logic reply routes.
Example 1.25. b2b_handle_reply usage
...
route[b2b_logic_reply] {
xlog("B2B REPLY: [$rs $rm] from entity: $b2b_logic.entity(id)\n");
b2b_handle_reply();
}
...
1.5.7. b2b_send_reply(code, reason)
This function sends a reply to the entity that sent the current
request.
Parameters:
* code (int) - reply code
* reason (string) - reply reason string
This function can be used from the b2b_logic request routes.
Example 1.26. b2b_send_reply usage
...
route[b2b_logic_request] {
if ($rm == "REFER") {
b2b_send_reply(202, "Accepted");
...
}
}
...
1.5.8. b2b_delete_entity()
This function deletes the entity that sent the current request.
This function can be used from the b2b_logic request routes.
Example 1.27. b2b_delete_entity usage
...
route[b2b_logic_request] {
if ($rm == "BYE") {
b2b_send_reply(200, "OK");
b2b_delete_entity();
...
}
}
...
1.5.9. b2b_end_dlg_leg()
This function sends a BYE request to the entity that sent the
current request. It is not required to also call
b2b_delete_entity() in order to delete the current entity.
This function can be used from the b2b_logic request or reply
routes.
Example 1.28. b2b_end_dlg_leg usage
...
route[b2b_logic_request] {
if ($rm == "REFER") {
b2b_send_reply(202, "Accepted");
b2b_end_dlg_leg();
}
}
...
1.5.10. b2b_bridge_request(b2bl_key,entity_no)
This function will bridge an initial INVITE with one of the
particapnts from an existing b2b session.
Parameters:
* b2bl_key (string) - a string that contains the b2b_logic
key. The key can also be in the form of
callid;from-tag;to-tag.
* entity_no (int) - an integer that holds the entity of the
entity/participant to bridge.
Example 1.29. b2b_bridge_request usage
...
modparam("b2b_entities", "script_req_route", "b2b_request")
...
route[b2b_request]
{
# incoming requests from the B2B entities
...
if ($ci~="^B2B") { #keep this aligned with b2b_key_prefix
# request coming from the UAC side;
# the Call-ID carries the B2B key ID
if (is_method("BYE") {
$var(entity) = 1;
b2b_bridge_request($ci,$var(entity));
}
}
...
}
...
1.6. Exported MI Functions
1.6.1. b2b_trigger_scenario
This command initializes a new B2B session where OpenSIPS will
start a call from the middle. The initial entities to be
connected are specified through the command's parameters and
further scenario logic can be implemented in the b2b_logic
dedicated routes.
Name: b2b_trigger_scenario
Parameters:
* senario_id : ID for the scenario of this B2B session.
* entity1 - first entity to be connected; specified in the
following format: id,dest_uri[,from_dname] where:
+ id - ID used to reference this entity in further B2B
actions
+ dest_uri - URI of the new destination
+ from_dname (optional) - Display name to use in the
From header.
* entity2 - second entity to be connected; specified in the
same format as entity1
* context (array, optional) - array of B2B context values, in
the format: key=value
MI FIFO Command Format:
opensips-cli -x mi b2b_trigger_scenario marketing client1,sip:bo
b@opensips.org client2,sip:322@opensips.org:5070 agent_uri=sip:alice@ope
nsips.org
1.6.2. b2b_bridge
This command can be used by an external application to tell
B2BUA to bridge a call party from an on going dialog to another
destination. By default the caller is bridged to the new uri
and BYE is set to the callee. You can instead bridge the callee
if you send 1 as the third parameter.
Name: b2b_bridge
Parameters:
* dialog_id : the b2b_logic key, or the
callid;from-tag;to-tag of the ongoing dialog.
* new_uri - the uri of the new destination
* flag (optional) - used to specify that the callee must be
bridged to the new destination. If not present the caller
will be bridged. Possible values are '0' or '1'.
* prov_media_uri (optional) - the uri of a media server able
to play provisional media starting from the beginning of
the bridging scenario to the end of it. It is optional. If
not present, no other entity will be envolved in the
bridging scenario
MI FIFO Command Format:
opensips-cli -x mi b2b_bridge 1020.30 sip:alice@opensips.org
opensips-cli Command Format:
opensips-cli -x mi b2b_bridge 1020.30 sip:alice@opensips.org
1.6.3. b2b_list
This command can be used to list the internals of b2b_logic
entities.
Name: b2b_list
Parameters: none
MI FIFO Command Format:
opensips-cli -x mi b2b_list
1.6.4. b2b_terminate_call
Terminates an ongoing B2B session.
Name: b2b_terminate_call
Parameters:
* key : the b2b_logic key or the callid;from-tag;to-tag of
one of call legs of the ongoing session.
MI FIFO Command Format:
opensips-cli -x mi b2b_terminate_call 159.0
1.7. Exported Pseudo-Variables
1.7.1. $b2b_logic.key
This is a read-only variable that returns the b2b_logic key of
the ongoing B2B session.
The variable can be used in request route, local_route and the
dedicated routes defined through the b2b_entities and b2b_logic
modules.
Example 1.30. $b2b_logic.key usage
...
local_route {
...
if ($b2b_logic.key) {
xlog("request belongs to B2B session: $b2b_logic.key\n");
...
}
...
}
...
1.7.2. $b2b_logic.entity(field)[idx]
This is a read-only variable that returns information about the
entities(dialogs) involved in the ongoing B2B session.
The available entity information is:
* the Call-ID of the dialog, accessible by using the callid
subname;
* the entity key, accessible by using the key subname or no
subname at all.
* the entity ID, accessible by using the id subname.
The index is used to select which entity from the B2B session
to refer to. The only possible values are 0 or 1 and correspond
to the positions of the entities in the scenario. Initially,
this depends on the order in which the entities are created. In
the case of the internal topology hiding scenario, 0 is the
caller and 1 is the callee. When a further bridge action
happens, the bridged entity is always placed on the 0 index and
the new entity on 1.
If no index is provided, the variable will refer to the
entity(dialog) which the current SIP message belongs to.
The variable can be used in request route, local_route and the
dedicated routes defined through the b2b_entities and b2b_logic
modules.
Example 1.31. $b2b_logic.entity usage
...
modparam("b2b_entities", "script_request_route", "b2b_request")
...
route[b2b_request] {
...
xlog("received request for entity: $b2b_logic.entity\n");
...
if ($rm == "BYE" && $b2b_logic.entity == $(b2b_logic.entity[1]))
xlog("Disconnecting callee\n")
...
}
...
1.7.3. $b2b_logic.ctx(key)
This is a read-write variable that provides access to a custom
Key-Value storage(of string values) in the context of the
ongoing B2B session.
The variable can be used in request route, local_route and the
dedicated routes defined through the b2b_entities and b2b_logic
modules. In the main request route the variable can be used for
storing a new context value even before instantiating the
scenario with b2b_init_request().
Setting the variable to NULL will delete the value at the given
key.
Example 1.32. $b2b_logic.ctx usage
...
modparam("b2b_entities", "script_reply_route", "b2b_reply")
...
route {
...
b2b_init_request("prepaid", "sip:alice@127.0.0.1");
$b2b_logic.ctx(my_extra_info) = "my_value";
...
}
...
route[b2b_reply] {
...
xlog("my info: $b2b_logic.ctx(my_extra_info)\n");
...
}
...
1.7.4. $b2b_logic.scenario(key)
This is a read-only variable that returns the scenario ID of
the ongoing B2B session
The variable can be used in request route, local_route and the
dedicated routes defined through the b2b_entities and b2b_logic
modules.
Example 1.33. $b2b_logic.scenario usage
...
route[b2b_logic_request] {
if ($b2b_logic.scenario == "prepaid") {
route(prepaid);
} else {
route(marketing);
}
}
...
Chapter 2. Developer Guide
The module provides an API that can be used from other OpenSIPS
modules. The API offers the functions for instantiating b2b
scenarios from other modules (this comes as an addition to the
other two means of instantiating b2b scenarios - from script
and with an MI command). Also the instantiations can be
dynamically controlled, by commanding the bridging of an entity
involved in a call to another entity or the termination of the
call or even bridging two existing calls.
2.1. b2b_logic_bind(b2bl_api_t* api)
This function binds the b2b_entities modules and fills the
structure the exported functions that will be described in
detail.