与云上的Asterisk服务器一起使用时,软电话无法连接

时间:2018-07-06 18:35:58

标签: asterisk

在GCP上设置星号

我在Google Cloud Platform实例上使用过Asterisk 13,我对Asterisk还是陌生的(几天前开始使用它)。我需要了解如何连接本地计算机上的设备(软件可以使用)的帮助。

sip.conf

    [general]
    context=public                  ; Default context for incoming calls. Defaults to 'default'
    allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
    udpbindaddr=0.0.0.0             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
    tcpenable=no                    ; Enable server for incoming TCP connections (default is no)
    tcpbindaddr=0.0.0.0             ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces)
    transport=udp                   ; Set the default transports.  The order determines the primary default transport.
    srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
    [authentication]
    [basic-options](!)                ; a template
            dtmfmode=rfc2833
            context=from-office
            type=friend
    [natted-phone](!,basic-options)   ; another template inheriting basic-options
            directmedia=no
            host=dynamic
    [public-phone](!,basic-options)   ; another template inheriting basic-options
            directmedia=yes
    [my-codecs](!)                    ; a template for my preferred codecs
            disallow=all
            allow=ilbc
            allow=g729
            allow=gsm
            allow=g723
            allow=ulaw
    [ulaw-phone](!)                   ; and another one for ulaw-only
            disallow=all
            allow=ulaw
    [peer-default]                    ; Added by me, above all is default
            disallow=all
            allow=alaw,ulaw
            type=friend
            host=dynamic
            context=softphone
            secret=<secret>
    [peer-xvhy]
            disallow=all
            allow=alaw,ulaw
            context=softphone
            type=friend
            host=dynamic
            secret=<secret>

地址

  • GCP实例具有公共IP = GCP_IP
  • 我的本地计算机(macOs)具有公共IP = LOCAL_IP
  • 我连接了两个软电话,其域= GCP_IP 一个用户名= peer-default 另一个用户名= peer-xvhy

这样,我就可以连接手机了。 在sip show peers上,我看到:

peer-default/peer-default LOCAL_IP                          D  No   No             52629    Unmonitored                                  
peer-xvhy/peer-xvhy       LOCAL_IP                          D  No   No             52629    Unmonitored                                  
2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 2 online, 0 offline]

我感到奇怪的是,它们具有相同的ip和端口。

当我尝试使用此extensions.conf拨打电话时:

[softphone]
exten => 100, 1, Dial(SIP/peer-default)
    same => n, Hangup()

我在sip set debug on控制台中看到了这一点:

<------------>
-- Executing [100@softphone:1] Dial("SIP/peer-default-00000021", "SIP/peer-default") in new stack
      == Using SIP RTP CoS mark 5
    Audio is at 16760
    Adding codec alaw to SDP
    Adding codec ulaw to SDP
    Adding non-codec 0x1 (telephone-event) to SDP
    Reliably Transmitting (no NAT) to <LOCAL_IP>:52629:
    INVITE sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK5664fbba
    Max-Forwards: 70
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@<LOCAL_IP>:52629;ob>
    Contact: <sip:peer-default@<LOCAL_IP>:5060>
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    To: <sip:100@<GCP_IP>>;tag=as78507fab
    CSeq: 102 INVITE
    User-Agent: Asterisk PBX certified/13.21-cert2
    Date: Fri, 06 Jul 2018 17:38:06 GMT
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    Content-Type: application/sdp
    Content-Length: 282

    v=0
    o=root 886654089 886654089 IN IP4 <LOCAL_IP>
    s=Asterisk PBX certified/13.21-cert2
    c=IN IP4 <LOCAL_IP>
    t=0 0
    m=audio 16760 RTP/AVP 8 0 101
    a=rtpmap:8 PCMA/8000
    a=rtpmap:0 PCMU/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    a=maxptime:150
    a=sendrecv

    ---
        -- Called SIP/peer-default

    <--- SIP read from UDP:<LOCAL_IP>:52629 --->
    SIP/2.0 100 Trying
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK5664fbba
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@192.168.3.227;ob>
    CSeq: 102 INVITE
    Content-Length: 0

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

    <--- SIP read from UDP:<LOCAL_IP>:52629 --->
    SIP/2.0 180 Ringing
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK5664fbba
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@192.168.3.227;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
    CSeq: 102 INVITE
    Contact: "jacken-hagar" <sip:peer-default@<LOCAL_IP>:52629;ob>
    Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
    Content-Length: 0

    <------------->
    --- (9 headers 0 lines) ---
    sip_route_dump: route/path hop: <sip:peer-default@<LOCAL_IP>:52629;ob>
        -- SIP/peer-default-00000022 is ringing

    <--- Transmitting (no NAT) to <LOCAL_IP>:52629 --->
    SIP/2.0 180 Ringing
    Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
    From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
    To: <sip:100@<GCP_IP>>;tag=as78507fab
    Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
    CSeq: 26560 INVITE
    Server: Asterisk PBX certified/13.21-cert2
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    Contact: <sip:100@<LOCAL_IP>:5060>
    Content-Length: 0


    <------------>

    <--- SIP read from UDP:<LOCAL_IP>:52629 --->
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK5664fbba
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@192.168.3.227;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
    CSeq: 102 INVITE
    Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
    Contact: "jacken-hagar" <sip:peer-default@<LOCAL_IP>:52629;ob>
    Supported: replaces, 100rel, norefersub
    Content-Type: application/sdp
    Content-Length: 282

    v=0
    o=- 3739887487 3739887488 IN IP4 <LOCAL_IP>
    s=pjmedia
    b=AS:117
    t=0 0
    a=X-nat:0
    m=audio 4010 RTP/AVP 8 101
    c=IN IP4 <LOCAL_IP>
    b=TIAS:96000
    a=rtcp:4011 IN IP4 192.168.3.227
    a=sendrecv
    a=rtpmap:8 PCMA/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    <------------->
    --- (11 headers 14 lines) ---
    Found RTP audio format 8
    Found RTP audio format 101
    Found audio description format PCMA for ID 8
    Found audio description format telephone-event for ID 101
    Capabilities: us - (alaw|ulaw), peer - audio=(alaw)/video=(nothing)/text=(nothing), combined - (alaw)
    Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
    Peer audio RTP is at port <LOCAL_IP>:4010
    sip_route_dump: route/path hop: <sip:peer-default@<LOCAL_IP>:52629;ob>
    set_destination: Parsing <sip:peer-default@<LOCAL_IP>:52629;ob> for address/port to send to
    set_destination: set destination to <LOCAL_IP>:52629
    Transmitting (no NAT) to <LOCAL_IP>:52629:
    ACK sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK7fa42c02
    Max-Forwards: 70
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@<LOCAL_IP>:52629;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
    Contact: <sip:peer-default@<LOCAL_IP>:5060>
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    CSeq: 102 ACK
    User-Agent: Asterisk PBX certified/13.21-cert2
    Content-Length: 0


    ---
        -- SIP/peer-default-00000022 answered SIP/peer-default-00000021
    Audio is at 19568
    Adding codec alaw to SDP
    Adding codec ulaw to SDP
    Adding non-codec 0x1 (telephone-event) to SDP

    <--- Reliably Transmitting (no NAT) to <LOCAL_IP>:52629 --->
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
    From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
    To: <sip:100@<GCP_IP>>;tag=as78507fab
    Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
    CSeq: 26560 INVITE
    Server: Asterisk PBX certified/13.21-cert2
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    Contact: <sip:100@<LOCAL_IP>:5060>
    Content-Type: application/sdp
    Content-Length: 282

    v=0
    o=root 401214028 401214028 IN IP4 <LOCAL_IP>
    s=Asterisk PBX certified/13.21-cert2
    c=IN IP4 <LOCAL_IP>
    t=0 0
    m=audio 19568 RTP/AVP 8 0 101
    a=rtpmap:8 PCMA/8000
    a=rtpmap:0 PCMU/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    a=maxptime:150
    a=sendrecv

    <------------>
        -- Channel SIP/peer-default-00000022 joined 'simple_bridge' basic-bridge <f1c38edc-c2d7-4681-ad97-7bcb7f7b19b1>
        -- Channel SIP/peer-default-00000021 joined 'simple_bridge' basic-bridge <f1c38edc-c2d7-4681-ad97-7bcb7f7b19b1>
    set_destination: Parsing <sip:peer-default@<LOCAL_IP>:52629;ob> for address/port to send to
    set_destination: set destination to <LOCAL_IP>:52629
    Audio is at 16760
    Adding codec alaw to SDP
    Adding codec ulaw to SDP
    Adding non-codec 0x1 (telephone-event) to SDP
    Reliably Transmitting (no NAT) to <LOCAL_IP>:52629:
    INVITE sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK71beb7ff
    Max-Forwards: 70
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@<LOCAL_IP>:52629;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
    Contact: <sip:peer-default@<LOCAL_IP>:5060>
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    CSeq: 103 INVITE
    User-Agent: Asterisk PBX certified/13.21-cert2
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    X-asterisk-Info: SIP re-invite (External RTP bridge)
    Content-Type: application/sdp
    Content-Length: 281

    v=0
    o=root 886654089 886654090 IN IP4 <LOCAL_IP>
    s=Asterisk PBX certified/13.21-cert2
    c=IN IP4 <LOCAL_IP>
    t=0 0
    m=audio 4008 RTP/AVP 8 0 101
    a=rtpmap:8 PCMA/8000
    a=rtpmap:0 PCMU/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    a=maxptime:150
    a=sendrecv

    ---

    <--- SIP read from UDP:<LOCAL_IP>:52629 --->
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;received=<GCP_IP>;branch=z9hG4bK71beb7ff
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@192.168.3.227;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
    CSeq: 103 INVITE
    Contact: "jacken-hagar" <sip:peer-default@<LOCAL_IP>:52629;ob>
    Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
    Supported: replaces, 100rel, timer, norefersub
    Content-Type: application/sdp
    Content-Length: 282

    v=0
    o=- 3739887487 3739887489 IN IP4 <LOCAL_IP>
    s=pjmedia
    b=AS:117
    t=0 0
    a=X-nat:0
    m=audio 4010 RTP/AVP 8 101
    c=IN IP4 <LOCAL_IP>
    b=TIAS:96000
    a=rtcp:4011 IN IP4 192.168.3.227
    a=sendrecv
    a=rtpmap:8 PCMA/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    <------------->
    --- (11 headers 14 lines) ---
    Found RTP audio format 8
    Found RTP audio format 101
    Found audio description format PCMA for ID 8
    Found audio description format telephone-event for ID 101
    Capabilities: us - (alaw|ulaw), peer - audio=(alaw)/video=(nothing)/text=(nothing), combined - (alaw)
    Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
    Peer audio RTP is at port <LOCAL_IP>:4010
    set_destination: Parsing <sip:peer-default@<LOCAL_IP>:52629;ob> for address/port to send to
    set_destination: set destination to <LOCAL_IP>:52629
    Transmitting (no NAT) to <LOCAL_IP>:52629:
    ACK sip:peer-default@<LOCAL_IP>:52629;ob SIP/2.0
    Via: SIP/2.0/UDP <LOCAL_IP>:5060;branch=z9hG4bK3f0206ce
    Max-Forwards: 70
    From: "jacken-hagar" <sip:peer-default@<LOCAL_IP>>;tag=as3175e9a7
    To: <sip:peer-default@<LOCAL_IP>:52629;ob>;tag=ERo8E-rMSwEcwRC31GLgFSGyuafT0zMp
    Contact: <sip:peer-default@<LOCAL_IP>:5060>
    Call-ID: 0e6f6ecb04a151372a04d3e12eea8eae@<LOCAL_IP>:5060
    CSeq: 103 ACK
    User-Agent: Asterisk PBX certified/13.21-cert2
    Content-Length: 0


    ---
    Retransmitting #1 (no NAT) to <LOCAL_IP>:52629:
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
    From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
    To: <sip:100@<GCP_IP>>;tag=as78507fab
    Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
    CSeq: 26560 INVITE
    Server: Asterisk PBX certified/13.21-cert2
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    Contact: <sip:100@<LOCAL_IP>:5060>
    Content-Type: application/sdp
    Content-Length: 282

    v=0
    o=root 401214028 401214028 IN IP4 <LOCAL_IP>
    s=Asterisk PBX certified/13.21-cert2
    c=IN IP4 <LOCAL_IP>
    t=0 0
    m=audio 19568 RTP/AVP 8 0 101
    a=rtpmap:8 PCMA/8000
    a=rtpmap:0 PCMU/8000
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-16
    a=maxptime:150
    a=sendrecv
    ```
    The retransmit log appears 10 times and then the call disconnects
    this happens within 32 seconds every time.

    with this error:
    ```
    WARNING[25825]: chan_sip.c:4069 retrans_pkt: Retransmission timeout reached on transmission f60f2b6a32c0d48cc30f2e0f9c5174c8 for seqno 1 (Critical Response) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions
    Packet timed out after 32000ms with no response

从重传日志中我可以理解的是(无论什么):

From: "jacken-hagar" <sip:peer- 
default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab

这是应该发送到LOCAL_IP或从sip show peers发送的问题,因为private class ItemComparer : IComparer { public int Compare(object x, object y) { // Convert objects to ListViewItems ListViewItem i1 = x as ListViewItem; ListViewItem i2 = y as ListViewItem; // If converstion to ListViewItems failed, return -1 (less than) if (i1 == null) return -1; if (i2 == null) return -1; // If ListViewItems DO NOT have the correct number of subitems, return -1 (less than) if (i1.SubItems.Count < 2) return -1; if (i2.SubItems.Count < 2) return -1; // Convert subitem 2 (index 1) text to a numeric value double distance1, distance2; if (!Double.TryParse(i1.SubItems[1].Text, out distance1)) return -1; if (!Double.TryParse(i2.SubItems[1].Text, out distance2)) return -1; // Compare the distance1 to distance2 (-1 = less than, 0 = equal, 1 = greater than) return distance1.CompareTo(distance2); } } public Form1() { InitializeComponent(); listView1.Items.Add(new ListViewItem(new string[] { "Flick", "20", "1.4" })); listView1.Items.Add(new ListViewItem(new string[] { "John", "19", "1.0" })); listView1.Items.Add(new ListViewItem(new string[] { "Hamn", "19", "0.9" })); listView1.ListViewItemSorter = new ItemComparer(); listView1.Sort(); } 是关于我的软电话地址的。

1 个答案:

答案 0 :(得分:1)

最后必须解决此问题,希望这可以帮助其他人。

Retransmitting #1 (no NAT) to <LOCAL_IP>:52629:
SIP/2.0 200 OK
Via: SIP/2.0/UDP <LOCAL_IP>:52629;branch=z9hG4bKPjgVfIZ2GZvjLmd.liWqt5Kx4tzfqul90b;received=<LOCAL_IP>;rport=52629
From: "jacken-hagar" <sip:peer-default@<GCP_IP>>;tag=YdEWucbUlrPjEvqWtnSNwzAamrQraB2D
To: <sip:100@<GCP_IP>>;tag=as78507fab
Call-ID: VbDA043j0pr7mzU-WCYMOfp5PS0YGPUR
CSeq: 26560 INVITE
Server: Asterisk PBX certified/13.21-cert2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:100@<LOCAL_IP>:5060>
Content-Type: application/sdp
Content-Length: 282

每次在 sip set debug on 日志中看到以上内容时,您都应关注联系人标题。

Contact: <sip:100@<LOCAL_IP>:5060>

在我的情况下,<LOCAL_IP>是GCP实例的内部地址,而不是计算机的本地ip

从这里开始在 sip.conf

[general]
context=public                  ; Default context for incoming calls. Defaults to 'default'
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
udpbindaddr=0.0.0.0             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
tcpenable=no                    ; Enable server for incoming TCP connections (default is no)
tcpbindaddr=0.0.0.0             ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces)
transport=udp                   ; Set the default transports.  The order determines the primary default transport.
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
externip=<PUBLIC_IP_OF_YOUR_INSTANCE>
localnet=<INTERNAL_IP_OF_YOUR_INSTANCE>/<MASK (255.255.255.255)>