How SIP message manipulation is done on AudioCodes

    In the SIP protocol, it is often required to change the fields for compatibility and for solving some particular tasks when connecting between telephone exchanges. It can be either deleting a simple SIP field, or transferring a value from one SIP field to another, or some more complicated manipulation.

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

    INVITE sip: 84951234567@10.11.12.13: 5060; transport = udp SIP / 2.0
    Via: SIP / 2.0 / UDP 11/10/12/13 :5060;branch= z9hG4bK-2342-1C21439
    To:
    From: "Ivanov" ; tag = 26814-XM-09a664f9-77e583465
    Allow: UPDATE, REFER, INFO
    Call-ID: 26814-TO-09a664f8-0a52daf11@sip.sp.com
    Contact:
    Content-Type: application /
    sdp CSeq: 157771616 INVITE
    History-Info:
    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:
    From: “Ivanov” field; tag = 26814-XM-09a664f9-77e583465
    Here:
    From - Header
    “Ivanov” - header parameter display name
    sip: 4957654321@sip.sp.com - SIP URL, where
    4957654321 - user part of the SIP URL
    Sip.sp.com - url SIP URL
    Tag part: header parameter
    AudioCodes knows a lot of fields and can parse them into parameters and SIP URLs. But, understood business, not all, since according to the SIP standard, it is possible to add any header that is not described anywhere. In this case, only regular expressions can help to parse this header. A more detailed description of which headers AudioCodes knows and which he does not know is described in the documentation: “SIP Message Manipulations Quick Reference Guide”. I don’t publish the link here, since the link to our site requires a certain level of access, and I won’t post it to the public, because at any time this link can stop living. If suddenly someone needs this documentation, then write, I will definitely share it.

    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 plan to manipulate. It can be just invite, or the answer to invite is invite.response.200, or the 2xx response to register = register.response.2xx. And so on by analogy. Separately, you can highlight the message reINVIE - reinvite.request
    Condition - under which condition this rule is fulfilled, and under which it is not fulfilled. 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 signs ==,! =,> =, <=,>, <, Contains,! Contains, exists,! Exists, suffix, prefix, len> , len <, len ==, regex. All characters can be listed using or or and, except for Regex.
    Action Subject - the title that you plan to change (Or the title parameter). For example: header.history-info
    Action value is what you plan to do 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 the 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 a header. For example: header.from.url.user
    b. If you plan to use an internal variable, then the same is indicated, only the internal variable. For example: param.message.address.dst.address (IP address where the message is sent)
    c. If you plan to use the part selected using the regular expression, then the $ sign indicates the part number of the regular expression. For example: $ 2
    d. If you plan to simply insert a specific value, then it is indicated in single quotes. For example, 'Vsem Privet!'
    e. If you plan to combine these values, then 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 fairly common task that confronts me is that in the case of a redirected number (as in the above example), you need to transfer the number from the history-info field to the From field. That is, the task is as follows:
    1. Transfer to the From field
    2. Delete the History-info field.
    How this is done
    Since AudioCodes does not parse the History-info field, you can only select a number using a regular expression. We build a regular expression in order to select a number from the header:
    History-Info:

    Allocation is required without regard to the name of the header. An example of such a regular expression would be
    ^ ( 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 ^ ( Action Subject: header.from.url.user
    Action Type: Modify
    Action Value: $ 2

    Since further we need to remove the Histroty-info field, we need to create another rule within 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

    Next, you just need to apply this Set ID as an outgoing rule for the corresponding IP Group. After which, 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:
    From: "Ivanov" ; tag = 26814-XM-09a664f9-77e583465
    Allow: UPDATE, REFER, INFO
    Call-ID: 26814-TO-09a664f8-0a52daf11@sip.sp.com
    Contact:
    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
    s = SIP Call
    c = IN IP4 12/13/10/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 the question is to use some variables that are not in the SIP message, for example, the remote IP address. In this case, you need to use internal variables such as
    Param.message.address.dst.address - The remote IP address to which the SIP message is sent.

    All internal variables are described in the documentation that I referenced before.

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

    Separately, it is worth noting that this rule can be applied not only to the SBC option, but also for the AudioCodes voice gateway, although with the restriction that the rule will work only for invite messages. To do this, you also need to create the necessary Manipulation SetID and apply it as an incoming or outgoing rule using the GWOutboundManipulationSet and GWInboundManipulationSet parameters, respectively.

    Also popular now: