2

Using jain sip to create sip proxy app.
client A -> proxy app -> client B
In case A call B: A can hangup, but when B send BYE sometime Jain Sip return 481 call leg to B.
When the call end in seconds, it can BYE success.
But if the call end in minutes, when B send BYE, Jain sip return 481 call leg.
And the caller client A always BYE success.

already check the call-id, request uri, from, to tag. Still no idea.

Here is the LOG

<message
from="192.168.101.217:5217" 
to="192.168.100.45:5062" 
time="1593501306804"
isSender="false" 
transactionId="z9hg4bk474906270" 
callId="1024711825" 
firstLine="INVITE sip:14@192.168.100.45:5062 SIP/2.0" 
>
<![CDATA[INVITE sip:14@192.168.100.45:5062 SIP/2.0
Via: SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK474906270;received=192.168.101.217
From: <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>
Call-ID: 1024711825
CSeq: 20 INVITE
Contact: <sip:217@192.168.101.217:5217>
Content-Type: application/sdp
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Subject: Call conversation
Expires: 120
Content-Length: 405

]]>
</message>

<message
from="192.168.100.45:5062" 
to="192.168.101.14:5014" 
time="1593501306864"
isSender="true" 
transactionId="z9hg4bk-3137-6aaa9fa3786b6b7fb08d9bdbbf9256c5" 
callId="1024711825" 
firstLine="INVITE sip:14@192.168.100.45:5062 SIP/2.0" 
>
<![CDATA[INVITE sip:14@192.168.100.45:5062 SIP/2.0
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=z9hG4bK-3137-6aaa9fa3786b6b7fb08d9bdbbf9256c5,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK474906270;received=192.168.101.217
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>
Call-ID: 1024711825
CSeq: 20 INVITE
Contact: <sip:217@192.168.101.217:5217>
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Subject: Call conversation
Expires: 120
Content-Type: application/sdp
Route: "14" <sip:14@192.168.101.14:5014;lr>
Record-Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
Content-Length: 403

]]>
</message>


<message
from="192.168.101.14:5014" 
to="192.168.100.45:5062" 
time="1593501307050"
isSender="false" 
transactionId="z9hg4bk-3137-6aaa9fa3786b6b7fb08d9bdbbf9256c5" 
callId="1024711825" 
firstLine="SIP/2.0 200 OK" 
>
<![CDATA[SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=z9hG4bK-3137-6aaa9fa3786b6b7fb08d9bdbbf9256c5,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK474906270;received=192.168.101.217
Record-Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 20 INVITE
Contact: <sip:14@192.168.101.14:5014>
Content-Type: application/sdp
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
User-Agent: eXosip/3.1.0
Content-Length: 200

]]>
</message>

<message
from="192.168.101.14:5014" 
to="192.168.100.45:5062" 
time="1593501307051"
isSender="false" 
transactionId="z9hg4bk-3137-6aaa9fa3786b6b7fb08d9bdbbf9256c5" 
callId="1024711825" 
firstLine="SIP/2.0 200 OK" 
>
<![CDATA[SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=z9hG4bK-3137-6aaa9fa3786b6b7fb08d9bdbbf9256c5,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK474906270;received=192.168.101.217
Record-Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 20 INVITE
Contact: <sip:14@192.168.101.14:5014>
Content-Type: application/sdp
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
User-Agent: eXosip/3.1.0
Content-Length: 200

]]>
</message>

<message
from="192.168.100.45:5062" 
to="192.168.101.217:5217" 
time="1593501307054"
isSender="true" 
transactionId="z9hg4bk474906270" 
callId="1024711825" 
firstLine="SIP/2.0 200 OK" 
>
<![CDATA[SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK474906270;received=192.168.101.217
Record-Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 20 INVITE
Contact: <sip:14@192.168.101.14:5014>
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,NOTIFY,MESSAGE,SUBSCRIBE,INFO
User-Agent: eXosip/3.1.0
Content-Type: application/sdp
Content-Length: 200

]]>
</message>

<message
from="192.168.101.217:5217" 
to="192.168.100.45:5062" 
time="1593501307348"
isSender="false" 
transactionId="z9hg4bk1089380003" 
callId="1024711825" 
firstLine="ACK sip:14@192.168.100.45:5062 SIP/2.0" 
>
<![CDATA[ACK sip:14@192.168.100.45:5062 SIP/2.0
Via: SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK1089380003;received=192.168.101.217
Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 20 ACK
Contact: <sip:217@192.168.101.217:5217>
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>

<message
from="192.168.100.45:5062" 
to="192.168.101.14:5014" 
time="1593501307353"
isSender="true" 
transactionId="966553558-1024711825-20-ack-192.168.100.45-50623137" 
callId="1024711825" 
firstLine="ACK sip:14@192.168.100.45:5062 SIP/2.0" 
>
<![CDATA[ACK sip:14@192.168.100.45:5062 SIP/2.0
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=966553558-1024711825-20-ack-192.168.100.45-50623137,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK1089380003;received=192.168.101.217
Route: "14" <sip:14@192.168.101.14:5014;lr>,"TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 20 ACK
Contact: <sip:217@192.168.101.217:5217>
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>


<message
from="192.168.101.14:5014" 
to="192.168.100.45:5062" 
time="1593501381766"
isSender="false" 
transactionId="z9hg4bk106975397" 
callId="1024711825" 
firstLine="BYE sip:217@192.168.100.45:5062 SIP/2.0" 
>
<![CDATA[BYE sip:217@192.168.100.45:5062 SIP/2.0
Via: SIP/2.0/UDP 192.168.101.14:5014;rport=5014;branch=z9hG4bK106975397;received=192.168.101.14
Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: <sip:14@192.168.100.45:5062>;tag=113355942
To: "217" <sip:217@192.168.100.45:5062>;tag=966553558
Call-ID: 1024711825
CSeq: 2 BYE
Contact: <sip:14@192.168.101.14:5014>
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>

<message
from="192.168.100.45:5062" 
to="192.168.101.14:5014" 
time="1593501381771"
isSender="true" 
transactionId="z9hg4bk106975397" 
callId="1024711825" 
firstLine="SIP/2.0 481 Call leg/Transaction does not exist" 
>
<![CDATA[SIP/2.0 481 Call leg/Transaction does not exist
CSeq: 2 BYE
Call-ID: 1024711825
From: <sip:14@192.168.100.45:5062>;tag=113355942
To: "217" <sip:217@192.168.100.45:5062>;tag=966553558
Via: SIP/2.0/UDP 192.168.101.14:5014;rport=5014;branch=z9hG4bK106975397;received=192.168.101.14
Content-Length: 0

]]>
</message>


<message
from="192.168.101.217:5217" 
to="192.168.100.45:5062" 
time="1593501389132"
isSender="false" 
transactionId="z9hg4bk550352336" 
callId="1024711825" 
firstLine="BYE sip:14@192.168.100.45:5062 SIP/2.0" 
>
<![CDATA[BYE sip:14@192.168.100.45:5062 SIP/2.0
Via: SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK550352336;received=192.168.101.217
Route: "TERRA_PROXY_SERVER" <sip:TERRA_PROXY_SERVER@192.168.100.45:5062;lr>
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 21 BYE
Contact: <sip:217@192.168.101.217:5217>
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>

<message
from="192.168.100.45:5062" 
to="192.168.101.217:5217" 
time="1593501389136"
isSender="true" 
transactionId="z9hg4bk550352336" 
callId="1024711825" 
firstLine="SIP/2.0 200 OK" 
>
<![CDATA[SIP/2.0 200 OK
CSeq: 21 BYE
Call-ID: 1024711825
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Via: SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK550352336;received=192.168.101.217
Contact: "217" <sip:217@192.168.101.217>;expires=60
Expires: 60
Content-Length: 0

]]>
</message>

<message
from="192.168.100.45:5062" 
to="192.168.101.14:5014" 
time="1593501389137"
isSender="true" 
transactionId="966553558-1024711825-21-bye-192.168.100.45-50623137" 
callId="1024711825" 
firstLine="BYE sip:14@192.168.101.14:5014 SIP/2.0" 
>
<![CDATA[BYE sip:14@192.168.101.14:5014 SIP/2.0
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=966553558-1024711825-21-bye-192.168.100.45-50623137,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK550352336;received=192.168.101.217
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 21 BYE
Contact: <sip:217@192.168.101.217:5217>
Max-Forwards: 70
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>

<message
from="192.168.101.14:5014" 
to="192.168.100.45:5062" 
time="1593501389154"
isSender="false" 
transactionId="966553558-1024711825-21-bye-192.168.100.45-50623137" 
callId="1024711825" 
firstLine="SIP/2.0 481 Call Leg/Transaction Does Not Exist" 
>
<![CDATA[SIP/2.0 481 Call Leg/Transaction Does Not Exist
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=966553558-1024711825-21-bye-192.168.100.45-50623137,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK550352336;received=192.168.101.217
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 21 BYE
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>

<message
from="192.168.101.14:5014" 
to="192.168.100.45:5062" 
time="1593501389155"
isSender="false" 
transactionId="966553558-1024711825-21-bye-192.168.100.45-50623137" 
callId="1024711825" 
firstLine="SIP/2.0 481 Call Leg/Transaction Does Not Exist" 
>
<![CDATA[SIP/2.0 481 Call Leg/Transaction Does Not Exist
Via: SIP/2.0/UDP 192.168.100.45:5062;branch=966553558-1024711825-21-bye-192.168.100.45-50623137,SIP/2.0/UDP 192.168.101.217:5217;rport=5217;branch=z9hG4bK550352336;received=192.168.101.217
From: "217" <sip:217@192.168.100.45:5062>;tag=966553558
To: <sip:14@192.168.100.45:5062>;tag=113355942
Call-ID: 1024711825
CSeq: 21 BYE
User-Agent: eXosip/3.1.0
Content-Length: 0

]]>
</message>

getServerTransaction code when auto-dialogs are off. st is null, but still exception when getNewServerTransaction.

  public static ServerTransaction getServerTransaction(RequestEvent eventObject) {
    ServerTransaction st = eventObject.getServerTransaction();
    if (st != null) {
      return st;
    }
    SipProvider sipProvider = (SipProvider) eventObject.getSource();
    if (sipProvider == null) {
      log.debug("getServerTransaction fail. SipProvider is null.");
      return null;
    }
    try {
      st = sipProvider.getNewServerTransaction(eventObject.getRequest());
    } catch (SipException se) {
      log.debug("getServerTransaction fail.", se);
    }
    return st;
  }
chunpo
  • 23
  • 1
  • 4

2 Answers2

0

If you are receiving 481 from jsip that suggests you are trying to look up a dialog when you receive the BYE and it probably doesn't exist at this point. When jsip is a proxy you should not have any jsip dialogs.

Proxy applications in jsip shouldn't rely on jsip dialogs and must maintain their own dialog state (or not for stateless proxies). Proxies should always be implemented in a dialog-stateless mode which basically means to avoid creating any dialogs. You can see a general example here https://github.com/usnistgov/jsip/blob/master/src/examples/forked/invite/Proxy.java

If you have already done this please post some code and debug level logs.

Vladimir Ralev
  • 1,371
  • 9
  • 18
  • Thank you. I did not have any jain sip dialogs. And I find the jain sip trigger processDialogTerminated(DialogTerminatedEvent dte). This may be the problem. I have no idea why it trigger DialogTerminatedEvent, the event source is gov.nist.javax.sip.SipProviderImpl . I did not find any BYE/CANCEL request there. But after that, the client A still can BYE success. – chunpo Jul 01 '20 at 02:25
  • May be you have automatic dialog mode enabled, make sure auto-dialogs are off properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT", "off"); – Vladimir Ralev Jul 01 '20 at 13:51
  • yes. Auto-dialog is on. But when I change it to off, it cannot use SipProvider.getNewServerTransaction(Request req) . – chunpo Jul 03 '20 at 00:51
  • It can use it just be aware of retransmissions, check out the proxy example here https://github.com/usnistgov/jsip/blob/master/src/examples/forked/invite/Proxy.java – Vladimir Ralev Jul 03 '20 at 10:07
  • Do you means check ServerTransaction? I add my getServerTransaction code. When auto-dialogs are off. it still throw exception when ServerTransaction is null. I use it to send ACK to another client. – chunpo Jul 07 '20 at 03:45
  • Yep, this is expected. For ACK in a proxy you should relay the ACK using sipProvider.sendRequest(request); and not use anything dialog stateful. I think ACK is the only exception and everything else should work just fine with server transaction and relaying. – Vladimir Ralev Jul 08 '20 at 06:45
0

You need to take a closer look at Route, Record-Route, and Contact headers.

The initial error appears in first ACK received by User-Agent on proxy.

ACK sip:14@192.168.100.45:5062 SIP/2.0

The above request-uri should be the Contact of the 200 Ok.

ACK sip:14@192.168.101.14:5014 SIP/2.0

I would advise you to fix all Contact, Record-Route, Route and then make sure you handle ACK and BYE in proxy mode: ie, you need to forward them using request-uri and Route instead of answering them.

AymericM
  • 1,645
  • 13
  • 13