Transaction layer The SIP RFC divides the architectureinto layers. We actually went through two of the layers in thediscussion above: the first was the syntax and encoding layer thatdefines the message structure, and the second was the transport layer.Now it’s time to inspect the contents of the SIP message by taking alook at the transaction layer.
The SIP layers

Every SIP message is associated with a singletransaction. Similar to HTTP, messages are either requests orresponses, but unlike HTTP, matching responses to requests is notsimple. HTTP uses TCP as its transport, so you can match a responsebased on the order of the requests. But a SIP transaction can have morethan a single response, and, in some cases, more than one request. Whena SIP device sends a request, it acts as a user agent client (UAC). Therecipient of the request, the one that sends the response, acts as auser agent server (UAS). The layer above the transaction layer is named”transaction user” or TU. Let’s look at a SIP request that a UAC caninitiate:
Via: SIP/2.0/UDP;branch=z9hG4bKmq0Tgb
Call-ID: [email][/email]
Max-Forwards: 70

We have already seen that [i]REGISTER[/i] is the method (type of request), [i][/i] is the request-URI, and [i]SIP/2.0[/i]is the version. All the headers above are the mandatory. At this point,we’ll cover the headers that are important to the transaction layer,and we’ll cover the rest of them when we get to the way proxies andregistrars work. First, let’s examine the Via header.
TheVia header has a parameter called “branch” with an odd value. The first7 letters (z9hG4bK) are fixed, and they help identify this as a SIPtransaction based on RFC 3261. These letters, often referred to as the”magic cookie”, would not appear with a request that is using theprevious SIP RFC, which has different transaction matching rules. We’llonly look the cases that have the magic cookie because it’s very raretoday to encounter an implementation that has not caught up with thelatest spec.
After the seven letters, the rest is just arandom string. Every time you see a different branch value it’s adifferent transaction; conversely, if both messages have the samebranch value, then they should be the same transaction. One exceptionto this rule is if the method of the CSeq header is different. This isbecause the CANCEL method uses the same branch value to identify whichtransaction you should cancel. So, to fully match two messages to thesame transaction, both the branch and CSeq method have to match.Naturally, this means that responses to a request will have matchingvalues.
Before moving on, one final note on the Via header.When we refer to this header, we actually refer to the first, ortopmost, Via header. Via is one of those headers that can appearmultiple times within a message. The reason for this will become clearin the proxy section, but it’s important to note that you always matchthe transaction based on the first Via header and ignore the rest.
TheUAS sends a response to an incoming request. SIP responses are dividedinto 6 different classes, and the first digit of the 3-digit responsecode identifies each class. A 1xx response means any response in therange of 100 to 199. The response types are:
[list][*]1xx – [b]Provisional response[/b], whichindicates that the request is handled, but without a final responseyet. For example, 180 Ringing is a common provisional response.[*]2xx – [b]Successful response[/b]. The most common one is 200 OK.[*]3xx – [b]Redirect response[/b].A client receiving this response would know the user moved to adifferent location. For example, a phone may redirect all its calls toa different address by responding back with a 302 Moved Temporarily.[*]4xx – [b]Client error[/b],which means that the request cannot be fulfilled and the sender shouldmodify its request. For example, you can send 401 Unauthorized if therequest does not contain the correct user credentials.[*]5xx – [b]Server error[/b],which usually indicates that the error is not related to the request,but to the state of the server or the server capabilities. For example,you would send 501 Not Implemented when receiving an unknown method.[*]6xx – [b]Global error[/b],which indicates the request cannot be fulfilled by any server. It wouldbe rare to receive such responses, as it requires having globalknowledge of the network.[/list] SIP dedicates special attention to making sure theresponse is sent back to the same source IP that sent the request. Thisis, in fact, one of the roles of the transport layer, not thetransaction layer. The transport layer does this by adding a “received”parameter to the top Via header of the request. Later, [url=]RFC 3581[/url]defined a new parameter called “rport” to ensure that the response issent back to the same originating port. Both of these additions wereaimed at making SIP work over NAT. SIP’s default behavior is to sendthe response back on the same connection of the request, but in case itfails to do so, it will attempt to open a new connection. Therefore,none of the layers can assume a single transaction uses a singleconnection. A possible SIP response to the request above is:
SIP/2.0 200 OK
Via: SIP/2.0/UDP;branch=z9hG4bKmq0Tgb;received=
Call-ID: [email][/email]

The example shows a successful response, but a UASmay choose to send an error response, such as the well-known “404 notfound,” in an instance where the user is not known. Both the UAC andUAS maintain a state machine for each transaction, and each statemachine has timers. Timers are necessary in case the other side doesnot respond in time, and they’re also required in case the layer abovethe transaction layer does not send a proper event and leaves thetransaction open.
Ultimately, SIP has built each of itslayers to be as decoupled as possible from the other layers, and anerror in any one layer has minimal impact on the rest. This separationmakes it easy for programmers to separate their software into smallercomponents.
The protocol distinguishes between 4 types oftransactions, so it has 4 different types of state machines: clientINVITE, client non-INVITE, server INVITE and server non-INVITE. Wehaven’t mentioned the INVITE method yet, and for a good reason. INVITEis a method used to generate a call, and these lower layers do notmaintain the call state. However, this transaction is different becausecalls have a 3-way handshake that affects the state-machine. Let’sstart with a diagram of the client non-INVITE transaction state-machine:
The Non-INVITE client transaction

Most of the timers are for retransmissions in UDP, andthey are disabled in TCP. An additional timeout timer exists in case noresponse is received. Transactions normally exist for 32 seconds untilthey time out. The equivalent server state-machine is quite similar; itreceives a request, sends it to the TU, sends the response back, andhandles retransmissions if required. It should be noted that some ofthe non-INVITE transaction definitions were updated by [url=]RFC 4320[/url].
Let’scover the 3-way handshake. The UAC sending the INVITE waits for aresponse, but this time to complete the handshake it sends an ACKrequest back to the server. ACK has no response, as it’s the 3rdmessage in the handshake. This fact forces ACK to be an exception tomany of the rules.
When a client receives a successful(2xx) response type, it means a call was created and it will send theACK in a new transaction. A failure response (300-699) means the ACKwill be on the same transaction. The reason for this lies in thebehavior of the upper layers. We will see that proxies are not aware ofa call state, and those that are stateful maintain just the transactionstate. There are scenarios in which a proxy would need to ACK a failedresponse, but it cannot ACK a successful response because that wouldrequire understanding call-related information. The INIVITE clientstate machine is as follows:
The INVITE client transaction


打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022年 8月 26日 下午3:26
下一篇 2022年 8月 26日 下午3:27


  • did,cid是什么意思


    文档 2022年 8月 26日
  • 问个硬件问题

    软件环境完全相同(linux elastix及其它相关的软件) 内存相同:4G 硬件: DELL1900 (CPU:Intel(R) Xeon(R) CPU E5320 @ [b]1.86GHz[/b] [b][color=red]二个[/color][/b]4核的)硬件:组装机(CPU:Intel(R) Core(TM)2 Duo CPU E8400 @ …

    文档 2022年 8月 26日
  • 移动比联通牛的原因

    [table=98%][tr=#f5f8fa][td][color=#000000][size=10pt]移动比联通牛的原因 如果你的电脑操作系统是win2000或winxp的话,那么: 在桌面上点右键,选择新建-文本文档;2、打开”新建文本文档”,录入”移动”两字后存盘退出;3、重新打开”新建文本…

    文档 2022年 8月 26日
  • 高手请进,传真接收故障

    我在trixbox上安装了 iaxmodem与hylafax软件来收发传真,安装比较顺利,现在我可以用hylafax来发送传真,一切正常。但无法收传真,hylafax错误如下:Aug 31 16:41:05.62: [26974]: –> [2:OK]Aug 31 16:41:05.62: [26974]: [10:NO CARRIER]Aug …

    文档 2022年 8月 26日
  • FreePBX或Elastix二次IVR转接问题,请高手急救

    先说说我的应用环境 我用的是亚讯语音系统,亚讯拨通对方号码(假设为:0103456789),对方接听后,听到亚讯语音系统播放的语音导航后,提示按0转人工服务,对方按0后,触发亚讯系统预设的号码:8888,由于亚讯语音系统已设置好对接到FreePBX,亚讯语音系统收到触发指令后,将8888送到FreePBX上,对方的号码会作为主叫送到FreePBX上要求Fre…

    文档 2022年 8月 26日


您的电子邮箱地址不会被公开。 必填项已用*标注



在线咨询: QQ交谈