1

I have 2 sip servers on different LANs. Freeswitch and another is Asterisk.

Asterisk sits on a VPN with a provider and who has provided DIDs. All users register on Freeswitch. How can I route calls to the provider through Asterisk and back,

I tried sofia/default/DIDNUMBER@ASTERISKSERVERIP:5060 but the call is not going through to the provider.

Ben Kabale
  • 13
  • 4
  • I don't know about freeswitch, but you would add a sip peer on freeswitch and another on asterisk. in asterisk would be like: Dial(SIP/peername/number); – cusco Jul 20 '18 at 17:50

1 Answers1

0

Asterisk ⟷ FreeSWITCH

Your needs of course might be different but this is a good start—I have a couple servers with a private connection and so you may need to adapt authentication measures but this should illustrate the basics of communication back and forth and dropping into correct context, etc.

Asterisk

pjsip.conf

[tel]
type=transport
protocol=udp
bind=10.8.0.2 # set asterisk's IP -- bind to this address

[acl]
type=acl
deny=0.0.0.0/0
permit=10.8.0.3/32 # allow only calls from freeswitch who is on 10.8.0.3 see above deny

[fs]
type=identify
endpoint=fs
match=10.8.0.3 # identify/auth traffic from freeswitch by its IP

[fs]
type=endpoint # set options for endpoint we identified just above
trust_id_inbound=yes
trust_id_outbound=yes
aors=fs
context=from-internal ## WHERE DO CALLS FROM FREESWITCH TO ASTERISK GO?
allow=!all,g722,ulaw
transport=tel

[fs]
type=aor
contact=sip:10.8.0.3 # address-of-record to find freeswitch so can dial to fs without it registering with us (this is fed up to [fs] type=endpoint via its aors above so calls to Dial(PJSIP/1234@fs) dials 1234 on FreeSWITCH 10.8.0.3)

extensions.conf

[from-internal]
include = toFreeSWITCH

[toFreeSWITCH]
exten = _N11!,1,Dial(PJSIP/${EXTEN}@fs)
exten = _0!,1,Dial(PJSIP/${EXTEN}@fs)
exten = _3XX,1,Dial(PJSIP/${EXTEN}@fs)
exten = _1NXXNXXXXXX,1,Dial(PJSIP/${EXTEN}@fs)
exten = _508NXXXXXX,1,Dial(PJSIP/${EXTEN}@fs)
exten = _774NXXXXXX,1,Dial(PJSIP/${EXTEN}@fs)

FreeSWITCH

conf/autoload_configs/acl.conf.xml

add this inside <network-lists>:

<list name="asterisk" default="deny">
  <node type="allow" cidr="10.8.0.2/32"/>
</list>

conf/sip_profiles/asterisk.xml

<profile name="asterisk">
    <gateways>
      <gateway name="asterisk">
        <param name="username" value="freeswitch"/>
        <param name="realm" value="your-asterisk-domain"/>
        <param name="password" value="unused-but-required-field"/>
        <param name="from-domain" value="your-asterisk-domain"/>
        <param name="proxy" value="10.8.0.2"/><!-- ASTERISK ADDRESS -->
        <param name="register" value="false"/><!-- INSTEAD WE SET AOR IN PJSIP.CONF -->
        <param name="cid-type" value="pid"/>
        <param name="rfc-5626" value="true"/>
       </gateway>
    </gateways>
    <settings>
        <param name="apply-inbound-acl" value="asterisk"/>
        <param name="auth-calls" value="false"/>
        <param name="context" value="public"/><!-- WHERE DO CALLS FROM ASTERISK COME INTO? -->
        <param name="rtp-ip" value="10.8.0.3"/><!-- this FreeSWITCH MEDIA IP -->
        <param name="sip-ip" value="10.8.0.3"/><!-- this FreeSWITCH SIP IP -->
    </settings>
</profile>

dialplan.xml

adapt and add inside a dialplan:

<extension name="to-asterisk">
  <condition field="destination_number" expression="^([2-9]11|1?[2-9]\d{2}[2-9]\d{6}|3\d{2})$">
    <action application="set" data="dialed_extension=$1"/>
    <action application="export" data="dialed_extension=$1"/>
    <action application="set" data="call_timeout=30"/>
    <action application="set" data="hangup_after_bridge=true"/>
    <action application="set" data="continue_on_fail=true"/>
    <action application="export" data="rtp_secure_media=false"/>
    <action application="bridge" data="sofia/gateway/asterisk/${destination_number}"/>
  </condition>
</extension>