📜 ⬆️ ⬇️

How to manipulate SIP messages on AudioCodes hardware

In the SIP protocol, it is often necessary to change the fields for compatibility and solving some particular problems at the junction between telephone exchanges. This can be either the removal of a simple SIP field, or the transfer of a value from one SIP field to another, or some more complicated manipulation.

How this can be done on the equipment AudioCodes SBC (And absolutely on any SBC, even the youngest model). Before you begin to describe how the transformation is done, we first deal with the terminology.
As an example, take the INVITE message:

INVITE sip: 84951234567@10.11.12.13: 5060; transport = udp SIP / 2.0
Via: SIP / 2.0 / UDP 10.11.12.13:5060;branch=z9hG4bK-2342-1C21439
To: <sip: 84951234567@sip.sp.com; user = phone>
From: "Ivanov" <sip: 4957654321@sip.sp.com; user = phone>; tag = 26814-XM-09a664f9-77e583465
Allow: UPDATE, REFER, INFO
Call ID: 26814-TO-09a664f8-0a52daf11@sip.sp.com
Contact: <sip: 12/13/11/10: 5060>
Content-Type: application / sdp
CSeq: 157771616 INVITE
History-Info: <sip: 4952345678@20.21.22.23? Reason = Forward>
Max-Forwards: 29
User-Agent: GW_SIP
Content-Length: 258

v = 0
o = cp10 139660536057 139660536057 IN IP4 12/13/11/10
s = sip call
c = IN IP4 12/13/11/10
t = 0 0
m = audio 31854 RTP / AVP 8 0 18
b = AS: 80
a = rtpmap: 8 PCMA / 8000/1
a = rtpmap: 0 PCMU / 8000/1
a = rtpmap: 18 G729 / 8000/1
a = fmtp: 18
annexb = no
a = ptime: 20
a = sendrecv
')
For example, take the From field:
From: "Ivanov" <sip: 4957654321@sip.sp.com; user = phone>; tag = 26814-XM-09a664f9-77e583465
Here:
From - Title
“Ivanov” - display name header parameter
sip: 4957654321@sip.sp.com - SIP URL, where
4957654321 - user part of the SIP URL
Sip.sp.com - url part of the SIP URL
Tag: title parameter
AudioCodes knows quite a lot of fields and can parse them into parameters and SIP URLs. But, of course, not everything, because according to the SIP standard, it is possible to add any title that is not described anywhere and in any way. In this case, only regular expressions can help to parse this header. A more detailed description of what headers AudioCodes equipment knows and which ones does not know is described in the documentation: "SIP Message Manipulations Quick Reference Guide". I do not publish the link here, because the link to our site requires a certain level of access, but I will not post it in public access, because at any moment in time this link may stop living. If suddenly someone needs this documentation, then write, be sure to share.

When creating a manipulation rule, there are the following rule parameters:
Manipulation index - rule number. Rules are processed sequentially.
Manipulation Set ID - a set of rules that you apply for a particular direction.
Message Type - the type of message you are trying to manipulate. It can be simply invite, or the answer to invite - invite.response.200, or the answer 2xx to register = register.response.2xx. And so on by analogy. Separately, you can select the message reINVIE - reinvite.request
Condition - under what condition this rule is executed, and under what condition it is not. Here you can give a simple example header.from.url.user == '4957654321'. This means that the User part of the SIP URL of the From field is 4957654321. You can also use the ==,! =,> =, <=,>, <, Contains,! Contains, exists,! Exists, suffix, prefix, len> signs , len <, len ==, regex. All characters can be listed with or or and except Regex.
Action Subject - the title that you plan to change (Either the header parameter). For example: header.history-info
Action value is what you are doing to Add / Remove / Modify / Add Prefix / Add Sufix / Remove Suffix / Remove Prefix.
Action Subject is what you plan to insert if Remove is not specified in Action Subject. The syntax is very important here.
a. If you plan to insert a value from another header, then you just need to specify the title. For example: header.from.url.user
b. If you plan to use an internal variable, then only the internal variable is specified. For example: param.message.address.dst.address (IP address where the message is sent)
c. If you plan to use the part selected using a regular expression, then the sign of the $ indicates the part number of the regular expression. For example: $ 2
d. If you plan to just insert a specific value, then it is indicated in single quotes. For example 'Vsem Privet!'
e. If you plan to combine these values, this is done through the + sign. For example: header.from.url.user + $ 2 + 'vsem Privet!'.

Let's give an example of a regular expression. A rather common task that confronts me is that in the case of a redirected number (as in the example above), it is necessary to transfer the number from the history-info field to the From field. That is, the task is as follows:
1. Move to the From field
2. Delete the History-info field.
How it's done
Since AudioCodes does not parse the History-info field, the number can only be selected using a regular expression. We build a regular expression in order to select a number from the header:
History-Info: <sip: 4952345678@20.21.22.23? Reason = Forward>

Highlight is required without regard to the title name. An example of such a regular expression would be
^ (<sip:) (. *) (@) (. *)
The required number will be the second parameter in this regular expression. That is, we need to insert the value of $ 2.

An example of such an expression:
Manipulation Set ID: 1
Message Type: invite
Condition: header.history-info regex ^ (<sip:) (. *) (@) (. *)
Action Subject: header.from.url.user
Action Type: Modify
Action Value: $ 2

Since then we need to remove the field Histroty-info, we need to create another rule within the framework of the same Manipulation Set ID
Manipulation Set ID: 1
Message Type: invite
Condition: header.history-info exists
Action Subject: header.history-info
Action Type: Remove

Then you just need to apply this Set ID as an outgoing rule for the corresponding IP Group. Then at the output we will receive a message of the following form:
INVITE sip: 84951234567@10.11.12.13: 5060; transport = udp SIP / 2.0
Via: SIP / 2.0 / UDP 10.11.12.13:5060;branch=z9hG4bK-2342-1C21439
To: <sip: 84951234567@sip.sp.com; user = phone>
From: "Ivanov" <sip: 4952345678@sip.sp.com; user = phone>; tag = 26814-XM-09a664f9-77e583465
Allow: UPDATE, REFER, INFO
Call ID: 26814-TO-09a664f8-0a52daf11@sip.sp.com
Contact: <sip: 12/13/11/10: 5060>
Content-Type: application / sdp
CSeq: 157771616 INVITE
Max-Forwards: 29
User-Agent: GW_SIP
Content-Length: 258

v = 0
o = cp10 139660536057 139660536057 IN IP4 12/13/11/10
s = sip call
c = IN IP4 12/13/11/10
t = 0 0
m = audio 31854 RTP / AVP 8 0 18
b = AS: 80
a = rtpmap: 8 PCMA / 8000/1
a = rtpmap: 0 PCMU / 8000/1
a = rtpmap: 18 G729 / 8000/1
a = fmtp: 18
annexb = no
a = ptime: 20
a = sendrecv

Often there is a question in the manipulation to use some variables that are not in the SIP message, for example, the remote IP address. In this case, it is required to use internal variables, such as
Param.message.address.dst.address - Remote IP address to which the SIP message is sent.

All internal variables are described in the documentation I referred to before.

It is also possible to transfer parameters from one SIP message to another, after saving them in variables. These examples in this article will not be considered.

We should also note that this rule can be applied not only to the SBC variant, but also to the AudioCodes voice gateway, but with the restriction that the rule will only work for messages to invite. To do this, you also need to create the necessary Manipulation SetID and apply it as an inbound or outbound rule using the GWOutboundManipulationSet parameter and GWInboundManipulationSet, respectively.

Source: https://habr.com/ru/post/253015/


All Articles