Copyright © 2009
Anca-Maria
Vamanu
Copyright © 2010 VoIP Embedded, Inc.
Revision History | |
---|---|
Revision $Revision: 8137 $ | $Date: 2011-07-07 14:02:20 +0200 (Thu, 07 Jul 2011) $ |
Table of Contents
hash_size
(int)script_scenario
(str)extern_scenario
(str)cleanup_period
(int)custom_headers
(str)use_init_sdp
(int)db_url
(str)update_period
(int)max_duration
(int)b2bl_key_avp
(string)b2bl_from_spec_param
(string)server_address
(str)init_callid_hdr
(str)db_mode
(int)List of Examples
server_hsize
parameterscript_scenario
parameterscript_scenario
parametercleanup_period
parameter
parameter
parameterdb_url
parameterupdate_period
parametermax_duration
parameterb2bl_key_avp
parameterb2bl_from_spec_param
parameterserver_address
parameterinit_callid_hdr
parameterdb_mode
parameterb2b_init_request
usageb2b_bridge_request
usageb2bl_api_t
structureThe B2BUA implementation in OpenSIPS is separated in two layers:
This module is a B2BUA upper level implementation that can be used with b2b_entities module to have B2BUA that can be configured to provide some PBX services. The B2B services are coded in an XML scenario document. The b2b_logic module examines this document and uses the functions provided by the b2b_entities module to achieve the actions specified in the document and enable the service.
A scenario can be instantiated in two ways:
The size of the hash table that stores the scenario instatiation entities.
Default value is “9” (512 records).
This parameter should be set with the path of a document that contains a scenario that can be instantiated from the script at the receipt of an initial message.
This parameter can be set more than once.
Example 1.2. Set script_scenario
parameter
... modparam("b2b_logic", "script_scenario", "/usr/local/opensips/scripts/b2b_prepaid.xml") ...
This parameter should be set with the path of a document that contains a scenario that can be instantiated with an MI command.
This parameter can be set more than once.
Example 1.3. Set script_scenario
parameter
... modparam("b2b_logic", "extern_scenario", "/usr/local/opensips/scripts/b2b_marketing.xml") ...
The time interval at which to search for an hanged b2b context. A scenario is considered expired if the duration of a session exceeds the lifetime specified in the scenario. At that moment, BYE is sent in all the dialogs from that context and the context is deleted.
Default value is “100”.
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:
If you wish some other headers to be passed also you should define them by setting this parameter.
Default value is “NULL”.
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 scenario and overwrite this global value.
Default value is “0”.
Database URL.
Example 1.7. Set db_url
parameter
... modparam("b2b_logic", "db_url", "mysql://opensips:opensipsrw@127.0.0.1/opensips") ...
The time interval at which to update the info in database.
Default value is “100”.
The maximum duration of a call.
Default value is “12 * 3600 (12 hours)”.
If you set it to 0, there will be no limitation.
The name of the Attribute-Value-Pair (AVP) used to store the b2b_logic entity key. The avp will be set after calling “b2b_init_request”. The avp will be visible in b2b_entities request/reply routes
The avp is not visible in local_route.
Default value is “NULL” (disabled).
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.11. 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"); ... }
The IP address of the machine that will be used as Contact in the generated messages. This is compulsory only when using external scenarios. For the script scenarios, 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 scenario instantiation.
Example 1.12. Set server_address
parameter
... modparam("b2b_logic", "server_address", "sip:sa@10.10.10.10:5060") ...
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.13. Set init_callid_hdr
parameter
... modparam("b2b_logic", "init_callid_hdr", "Init-CallID") ...
The B2B modules have support for the 3 type of database storage
Default value is “2” (WRITE BACK).
This is the function that must be called by the script writer on an initial INVITE for which a B2B scenario must be instantiated. It is up to the script writer to decide which are the criteria to decide for which messages certain scenarios must be instantiated.
The first parameter is the identifier for the scenario. This is defined in the XML document as an attribute of the root node.
Then it can take at most 4 other parameters that represent the parameters for the xml scenario. The expected number of parameters is also specified as an attribute in the root node of the XML scenario.
Do not call t_newtran() from the script on this request. It will be called internally by the function. Calling t_newtran() from the script will result in the transaction remaining in memory for ever.
Example 1.15. b2b_init_request
usage
... if(is_method("INVITE") && !has_totag() && prepaid_user()) b2b_init_request("prepaid", "sip:320@opensips.org:5070", "sip:321@opensips.org:5070")); ...
This function will bridge an initial INVITE with one of the particapnts from an existing b2b dialog.
Parameters:
b2bl_key - a pseudo-variable that contains the b2b_logic key
entity_no - a pseudo-variable that holds the entity of the particapnt to bridge.
Example 1.16. b2b_bridge_request
usage
... modparam("b2b_logic", "b2bl_key_avp", "$avp(99)") ... route(X) { # handling b2b calls here ... b2b_init_request("top hiding"); xlog("L_INFO","[$mi] got b2bl_key='$avp(99)'\n"); # saving the b2b key into the local cache cache_store("local","some_b2bl_key_identifier","$avp(99)"); ... } route(Y) { # handling calls to bridge to existing b2b calls ... # retrieving the key of a b2b call cache_fetch("local","some_b2bl_key_identifier", $avp(98) ); $var(entity) = 1; b2b_bridge_request("$avp(98)","$var(entity)"); ... } ...
This command instantiated a B2B scenario.
Name: b2b_trigger_scenario
Parameters:
senario_id : the id of the scenario to be instantiated.
scenario parameters - it can take 4 more parameters that are scenario parameters
MI FIFO Command Format:
:b2b_trigger_scenario:fifo_reply marketing sip:bob@opensips.org sip:322@opensips.org:5070 sip:alice@opensips.org _empty_line_
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 id of the dialog. If you set the module parameter dialog-id the server will include the dialogid in the generated Invites as the content of a header with name 'Dialog-ID'.
new uri - the uri of the new destination
flag to specify that the callee must be bridged to the new destination. It is optional. If not present the caller will be bridged.
MI FIFO Command Format:
:b2b_bridge:fifo_reply 1020.30 sip:alice@opensips.org _empty_line_
opensipsctl Command Format:
opensipsctl b2b_bridge 1020.30 sip:alice@opensips.org
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.
This function binds the b2b_entities modules and fills the structure the exported functions that will be described in detail.
Example 2.1. b2bl_api_t
structure
... typedef struct b2bl_api { b2bl_init_f init; b2bl_bridge_f bridge; b2bl_bridge_extern_f bridge_extern; b2bl_bridge_2calls_t bridge_2calls; b2bl_terminate_call_t terminate_call; b2bl_set_state_f set_state; b2bl_bridge_msg_t bridge_msg; }b2bl_api_t; ...
Field type:
... typedef str* (*b2bl_init_f)(struct sip_msg* msg, str* name, str* args[5], b2bl_cback_f, void* param); ...
Initializing a b2b scenario. The last two parameters are the callback function and the parameter to be called in 3 situations that will be listed below. The callback function has the following definition:
... typedef int (*b2b_notify_t)(struct sip_msg* msg, str* id, int type, void* param); ...
The first argument is the callback given in the init function.
The second argument is a structure with some statistics about the call -start time, setup time, call time.
The third argument is the current state of the scenario instantiation.
The last argument is the event that triggered the callback. There are 3 events when the callback is called:
when a BYE is received from either side- event parameter will also show from which side the BYE is received, so it can be B2B_BYE_E1 or B2B_BYE_E2
If while bridging, a negative reply is received from the second entity - the event is B2B_REJECT_E2.
When the b2b logic entity is deleted- the evnet is B2B_DESTROY
The return code controls what will happen with the request/reply that caused the event (except for the last event, when the return code does not matter)
-1 - error
0 - drop the BYE or reply
1 - send the BYE or reply on the other side
2 - do what the scenario tells, if no rule defined send the BYE or reply on the other side
Field type:
... typedef int (*b2bl_bridge_f)(str* key, str* new_uri, str* new_from_dname,int entity_type); ...
This function allows bridging an entity that is in a call handled by b2b_logic to another entity.
Field type:
... typedef str* (*b2bl_bridge_extern_f)(str* scenario_name, str* args[5], b2bl_cback_f cbf, void* cb_param); ...
This function allows initiating an extern scenario, when the B2BUA starts a call from the middle.
Field type:
... typedef int (*b2bl_bridge_2calls_t)(str* key1, str* key2); ...
With this function it is possible to bridge two existing calls. The first entity from the two calls will be connected and BYE will be sent to their peers.
Field type:
... typedef int (*b2bl_terminate_call_t)(str* key); ...
Terminate a call.
Field type:
... typedef int (*b2bl_set_state_f)(str* key, int state); ...
Set the scenario state.
Field type:
... typedef int (*b2bl_bridge_msg_t)(struct sip_msg* msg, str* key, int entity_no); ...
This function allows bridging an incoming call to an entity from an existing call.
The first argument is the INVITE message of the current incoming call.
The second argument is the b2bl_key of an existing call.
The third argument is the entity identifier.