What will happen in SIP if both parties send INVITE to each other at same time - sip

"What will happen in SIP if both parties send INVITE to each other at same time"
What will be the behavior in the above case?
Which call will Process?

The received first INV may be proceed to establish the call by the SIP Proxy, whereas the received second INV maybe rejected by a 4xx response. But since SIP is session based it is also possible that the Proxy can establish both calls. But one call should be in hold state. Only one call will ve active.

The most likely behaviour is that the SIP user agents would display a new incoming call.
Since they would also both have an outgoing call in progress it would be up to the user as to whether they would answer the incoming call or ignore it and persist with their original outgoing call.
The crucial point is that the two INVITE requests are independent. It would be the same as if two people called each other on their mobile phones simultaneously.

RFC 3261 section 14.2 says
A UAS that receives an INVITE on a dialog while an INVITE it had sent
on that dialog is in progress MUST return a 491 (Request Pending)
response to the received INVITE.
So, I think both the parties will generate 491 response to each other. But I am still not sure as both of these INVITE will be part of different dialogs and standard mentions on the same dialog.

Related

What is the difference between the normal INVITE and the INVITE on hold in a session using SIP protocol?

hi all am new to software field and stack overflow too. I am analyzed the back end flow of a session between the caller and the callee using SIP protocol. I am little bit confusing on the normal INVITE and INVITE on hold. can anyone explain the difference between them?
Thanks in advance.
A normal SIP INVITE will mostly have CSeq 1. But the Re-INVITEs will have greater CSeq value. A difference between the INVITE and Re-INVITE is that their CSeq will be incremented else UAS will reject the message. An existing dialog can be modified in the form of Hold/Retrieve/Codec level changes using a Re-INVITE.
Please keep in mind that a Re-INVITE is different from a Re-Transmitted INVITE
Please check following link:
https://andrewjprokop.wordpress.com/2015/02/10/understanding-sip-re-invite/
The most common use for re-INVITE is call hold. The party putting the call on hold sends a re-INVITE with SDP indicating that media will no longer be sent. That same party will take the call off hold by sending another re-INVITE with SDP indicating that media transmission will resume.
I'm too late to answer! But adding one more difference.
One difference between invite and re-invite is obviously the re-invite has incremental cseq number than the initial invite.
The other difference is re-invite will have the totag value where in the initial invite doesn't.
This is an example of an initial invite because there is no totag on the To: header
Difference between Re-Invite & Re transmission of Invite is identified by C-Seq Number.
i.e Re transmission of Invite contain the same C-seq No that was previously used by the corresponding Invite.But in Re-Invite which is used to change the session parameter the c-seq is Increment by 1.
Re-Invite is commonly use for Call hold , that is set the a(attribute-Line) in SDP as send only or it can change the c(Connection Address) to 0.0.0.0.

Jain sip return 481 for a received bye request

I am trying to use Jain Sip to create a sip user agent, which can receive INVITE/ ACK/ BYE, and send back the response with SDP if necessary.
It can receive INVITE, send OK response, receive ACK and then do RTP packet transport. But when it receives BYE from the other side, a 481 will be thrown by Jain Sip itself.
I was sending response statelessly by using SipProvider.sendResponse(response). And it turns out if I switch to stateful (getNewServerTransaction from incoming request, then use SipServerTransaction.sendResponse), everything works. So I am wondering what is the difference between them? Is there anyway I can do this statelessly?
Basically when stateful the JAIN-SIP stack allocates its own resources to run the SIP state machines for transactions and dialogs. As you can imagine if you do it only partially for a call it will get out of hand. My guess is you have automatic dialog support turned on and you are mixing stateful and stateless mode in some way. If you want to go stateless make sure there is no auto dialog. Best way to debug is to see DEBUG logs and code.

The necessity of ACK in INVITE SIP transactions

I am just curious, what is the fundamental reason to have 200 OK responses from a remote end point to be ACKed by the local end point? RFC 3261 states that it is needed for stability purposes but does not go into details. The only reason that comes to my head is the case with call forking. So, if an AOR is registered at multiple end points and these end points respond simultaneously with a 200 OK message, then an ACK will actually indicate which of the remote parties will participate in a peer-to-peer connection. Is there any other reason to end and INVITE hand shake with an ACK?
It's because SIP needs some responses (only INVITE responses in practise) to be reliably transmitted in situations where the underlying transport is unreliable, such as with UDP.
The ACK request is the way for the (UAC User Agent Client) to let the UAS (User Agent Server) know that it received the final response to an INVITE request. Without employing something like the ACK request there would always be the risk that the UAS response would not get through to the UAC and the call would be left sitting in an incorrect state.
The ACK request doesn't have any specific role in call forking. In the case you've described in a call with multiple end points BYE requests will be sent to any call legs that are not required. ACK requests still need to be sent to any UAS that responds irrespective of whether the UAC wants that call leg to proceed or not.

How to Detect sip call forward to server's Voice mail?

Am Using Pjsip libraries for SIP implementation . Using Pjsip lib i can able to make IP calls perfectly . My problem is While I Make call if other End User Decline/not Reachable or No answer ,My call will connect with Voice mail and get 200k(call connected state) from sip server as same like other end user Answering call.
Not Reachable Case i can differentiate 200 ok By missing 183 Session Progress Message. But noanswer and decline case I couldn't get the actual State of call .
is any way to find call connected state and Voice mail connected state ?
There isn't any one way of a user agent knowing it has reached a voicemail server versus a person answering.
Usually what will happen is that your user agent will send an INVITE to a From URI, and some proxy responsible for that URI will fork the INVITE to the various user agents the remote party uses: her phone, her voicemail service, and so on. The first user agent to return a 2xx response sets up the call.
You will however always know to which user agent you have connected, in the Contact header of the 200 OK.
Presumably a voicemail server will indicate in its SDP offer/answer that while it accepts certain incoming media streams, it will not send anything, by marking the stream with an a=recvonly attribute (See RFC 3264).

Is there a SIP/VOIP-agnostic way to know when a phone goes offline?

Working on a SIP application that requires monitoring call activity/state on a phone. My app (UA) is registered with a proxy server, as is the phone being monitored. I am making use of SUBSCRIBE/NOTIFY messages to tell the phone that I want to know about its "dialog" events, and once subscribed, this works fine. I am running into two problems:
I am requesting a subscription length of 900 seconds and consistently getting some absurd amount of 4000+ seconds returned from the phone.
There is the possibility that the phone may be unplugged while the subscription is active (don't ask, but, yes, this is a possibility). When this happens, I am not getting any type of notification as to the phone no longer being available. Consequently, I have to wait for my subscription to time out, try and renew it, handle the failure, and create a new subscription.
I realize that I can renew my subscription sooner than its expiration time, but is there a better way to go about it? For example, would I be able to get "presence" events and use them to know when the phone is there or not? Are those events always guaranteed to happen on phone start-up, and even so, since there is a proxy in the middle, would I even get the notifications, or would I still not know that the phone restarted and no longer recognizes my subscription(s)? Are these "presence" updates something that I can request from the proxy?
Any insight would be great; for the moment, I'm going to simply try and refresh my subscription on a much smaller interval, but I would love to know if there is a better way to go about it. Thanks in advance.
I don't know about a SIP agnostic way other than perhaps somehow pinging the phone but there is definitely a SIP way to do presence and that's using the same subscribe/notify model you are using for dialogs but in this case for presence. The relevant standard is RFC 3856 A Presence Event Package for the Session Initiation Protocol (SIP).
Typically the presence notifications would be generated by a SIP registrar, and since you say your phone is registering with your proxy it must also have a registrar built in. The registrar would notify your UA when the other phone's registration status changes such as when it first came online or when it failed to re-register. As far as the delay between a phone "disappearing" and the registrar server detecting it there's no prescribed way to do it. You can either wait for the registration period to expire and mark the phone as offline when it fails to register or alternatively the server could actively send a packet or even a SIP request such as an OPTIONS request to the phone and mark it as offline if it got a failure response, Asterisk uses te latter approach.
When a SIP UAC client registers with a SIP UAS Registrar, the SIP client provides a Expiry Header, which indicates that maximum amount of time after which a SIP client needs to re-register itself. If the SIP client does not re-register itself in this time period, then Sip UAS proxy/registrar server will mark the client as disconnected.
Proprietary SIP packages like FreePBX and Asterisk, proactively, send SIP OPTIONS to the client, continuously, at some interval, wherein the client responds with OK. This is a more proactive way of validating if SIP clients are online; however, this technique is proprietary and not part of the actual SIP specification.