2017-01-23 11 views
0

と私のアスタリスクサーバーからの応答を取得していないですが、ここでhttps://github.com/twisted/twisted/blob/trunk/src/twisted/test/test_sip.pyなぜ私は、コードを使用して、次のねじれたSIPのPythonコード

を見つけた私は、単純なSIPオプションがチェック私のローカル(127.0.0.1)アスタリスクサーバーを送信しようとしています。

From twisted.protocols import sip 
From twisted.internet import defer, reactor 

class Client(sip.Base): 

    def __init__(self): 
     sip.Base.__init__(self) 
     self.received = [] 
     self.deferred = defer.Deferred() 

    def handle_response(self, response, addr): 
     self.received.append(response) 
     self.deferred.callback(self.received) 

class OptionsC(): 

    def setup(self): 
     self.client = Client() 
     self.clientPort = reactor.listenUDP(
      5062, self.client, interface="127.0.1.1") 

    def testRegisterOPT(self): 
     p = self.clientPort.getHost().port 
     r = sip.Request("OPTIONS", "sip:127.0.0.1") 
     r.addHeader("via", sip.Via("127.0.1.1", port=5062, rport=5062, branch="test123").toString()) 
     r.addHeader("to", "<sip:[email protected]>") 
     r.addHeader("From", "<sip:[email protected]>") 
     r.addHeader("Call-ID", "<[email protected]>") 
     r.addHeader("CSeq", "1 OPTIONS") 
     r.addHeader("contact", "<sip:[email protected]:5062;transport=UDP>") 
     r.addHeader("Accept", "application/sdp") 
     r.addHeader("Content-Length", "0") 
     print(r.toString()) 
     self.client.sendMessage(
      sip.URL(host="127.0.0.1", port=5060), r) 
     d = self.client.deferred 

     def check(received): 
      self.assertEqual(len(received), 1) 
      r = received[0] 
      print(r) 
      print(r.code) 
      print(dir(r)) 
      self.assertEqual(r.code, 200) 
     d.addCallback(check) 
     return d 

opc = OptionsC() 
opc.setup() 
res = opc.testRegisterOPT() 
print("test") 

これは私の環境では、アスタリスクで

$ pip freeze 
constantly==15.1.0 
incremental==16.10.1 
Twisted==16.6.0 
zope.interface==4.3.3 

$ python -V 
Python 2.7.5 

どのように見えるか、私はメッセージが到着することを確認することができています。
アスタリスクは、私のコードに何が間違っているかを理解するのに便利な、何か他のもの、あるいは200何かのエラーを返すことはありません。

*CLI> sip set debug on 
SIP Debugging enabled 

<--- SIP read from UDP:127.0.1.1:5062 ---> 
OPTIONS sip:127.0.0.1 SIP/2.0 
Via: SIP/2.0/UDP 127.0.1.1:5062;branch=test123;rport=5062 
To: <sip:[email protected]> 
From: <sip:[email protected]> 
Call-ID: <[email protected]> 
CSeq: 1 OPTIONS 
Contact: <sip:[email protected]:5062;transport=UDP> 
Accept: application/sdp 
Content-Length: 0 

<-------------> 
--- (9 headers 0 lines) --- 

これを以下のsippとよく似たコマンドと比較してください。正しく私が見ることができる何

<--- SIP read from UDP:127.0.0.1:5061 ---> 
OPTIONS sip:127.0.0.1 SIP/2.0 
Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-19903-1-0 
Max-Forwards: 70 
To: <sip:[email protected]> 
From: <sip:[email protected]>;tag=1 
Call-ID: [email protected] 
CSeq: 1 OPTIONS 
Contact: <sip:[email protected]:5061;transport=UDP> 
Accept: application/sdp 
Content-Length: 0 

<-------------> 
--- (10 headers 0 lines) --- 
Sending to 127.0.0.1:5061 (NAT) 
Looking for s in public (domain 127.0.0.1) 

<--- Transmitting (NAT) to 127.0.0.1:5061 ---> 
SIP/2.0 200 OK 
Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-19903-1-0;received=127.0.0.1;rport=5061 
From: <sip:[email protected]>;tag=1 
To: <sip:[email protected]>;tag=as6e9328e8 
Call-ID: [email protected] 
CSeq: 1 OPTIONS 
Server: Asterisk PBX 13.10.0~dfsg-1ubuntu2 
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE 
Supported: replaces, timer 
Contact: <sip:127.0.0.1:5060> 
Accept: application/sdp 
Content-Length: 0 


<------------> 
Scheduling destruction of SIP dialog '[email protected]' in 32000 ms (Method: OPTIONS) 
Really destroying SIP dialog '[email protected]' Method: OPTIONS 

への応答を生成し、アスタリスク

$ sipp -sf ./options.xml -m 1 -max_non_invite_retrans 1 127.0.0.1:5060 
Resolving remote host '127.0.0.1'... Done. 
$ cat ./options.xml 
<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!DOCTYPE scenario SYSTEM "sipp.dtd"> 

<scenario name="Options"> 

    <send retrans="500" start_rtd="opt-timer"> 
    <![CDATA[ 

     OPTIONS sip:[remote_ip] SIP/2.0 
     Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] 
     Max-Forwards: 70 
     To: <sip:[service]@[remote_ip]> 
     From: <sip:[service]@[remote_ip]>;tag=[call_number] 
     Call-ID: [call_id] 
     CSeq: [cseq] OPTIONS 
     Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]> 
     Accept: application/sdp 
     Content-Length: 0 

    ]]> 
    </send> 

    <recv response="200" rrs="true" rtd="opt-timer"></recv> 


    <!-- definition of the response time repartition table (unit is ms) --> 
    <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/> 

    <!-- definition of the call length repartition table (unit is ms)  --> 
    <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/> 

</scenario> 

は、SIPは、SIPダイアログを初期化するために、バックグラウンドで他のいくつかの仕事をしているということです。 私はそれが上記の例のコードでは見当たらないと思います。 アスタリスクが正しく開始されるクライアントへの応答への送信sippが作成中です。

答えて

0

r.addHeader("CSeq", "1 OPTIONS")を削除します。
私は今、私の地元のアスタリスクはだから私は、私は適切か、単にそれを無視呼び出しシーケンスで動作する方法を構築する必要があると思います

def testRegisterOPT(self): 
    p = self.clientPort.getHost().port 
    r = sip.Request("OPTIONS", "sip:127.0.0.1") 
    r.addHeader("via", sip.Via("127.0.1.1", port=5062, rport=5062, branch="test123").toString()) 
    r.addHeader("to", "<sip:[email protected]>") 
    r.addHeader("From", "<sip:[email protected]>") 
    r.addHeader("Call-ID", "<[email protected]>") 
    # r.addHeader("CSeq", "1 OPTIONS") 
    r.addHeader("contact", "<sip:[email protected]:5062;transport=UDP>") 
    r.addHeader("Accept", "application/sdp") 
    r.addHeader("Content-Length", "0") 
    print(r.toString()) 
    self.client.sendMessage(
     sip.URL(host="127.0.0.1", port=5060), r) 
    d = self.client.deferred 

を応答するために取得しています。

アスタリスクが投稿するという警告があります。
chan_sip.c:11681 copy_header: No field 'CSeq' present to copy
しかし、少なくとも私のテストは今働いている

<--- SIP read from UDP:127.0.0.1:46947 ---> 
    OPTIONS sip:127.0.0.1 SIP/2.0 
    Via: SIP/2.0/UDP 127.0.0.1:5062;rport=5062 
    Max-Forward: 3 
    To: <sip:[email protected]> 
    From: <sip:[email protected]> 
    Call-ID: <[email protected]> 
    Contact: <sip:[email protected];transport=UDP> 
    Accept: application/sdp 
    Content-Length: 0 

    <-------------> 
    --- (9 headers 0 lines) --- 
    Sending to 127.0.0.1:5062 (no NAT) 
    [Jan 24 12:52:54] NOTICE[12752]: chan_sip.c:11681 copy_header: No field 'CSeq' present to copy 

    <--- Transmitting (no NAT) to 127.0.0.1:5062 ---> 
    SIP/2.0 400 Bad Request 
    Via: SIP/2.0/UDP 127.0.0.1:5062;rport=5062;received=127.0.0.1 
    From: <sip:[email protected]> 
    To: <sip:[email protected]>;tag=as7d34b365 
    Call-ID: <[email protected]> 
    Server: Asterisk PBX 13.10.0~dfsg-1ubuntu2 
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE 
    Supported: replaces, timer 
    Content-Length: 0 
関連する問題