FreeSwitch SIP and Media Server

FreeSWITCH is free and open source communications software licensed under Mozilla Public License. It if often the core of voice core to provider call routing and media control . Its core library, libfreeswitch, is capable of being embedded into other projects, as well as being used as a stand-alone application.

 FreeSWITCH is designed to route and interconnect popular communication protocols using audio, video, text, or any other form

of media. First released in January 2006, FreeSWITCH has grown to become the world’s premier open source soft-switch

platform. This versatile platform is used to power voice, video, and chat communications on devices ranging from single calls on

a Raspberry Pi to large server clusters handling millions of calls. FreeSWITCH powers a number of commercial products

from start-ups to Carriers.

– freeswitch.com

It can perform the functions of  ( but not limited to )

  • PBX Server (Transcoding B2BUA)
  • IVR & Announcement Server
  • Conference host
  • Voicemail
  • Session Border Controller
  • Text to Speech (TTS)
  • VOIP endpoint
  • Class 5 softswitch

Freeswitch has a modular architecture which is both scalable and customisable. The most important modules are , Endpoint , dialplan and Application .

Application is the instruction added for a particular dial plan with an extension object. Data Arguments are also passed to an application. Examples ,

  • Set: configure extension parameter
  • Bridge: bridge a new channel to the existing one
  • Answer: answer the call for a channel
  • Hangup: hangup a current channel
  • Run an IVR menu

Protocols set up call legs/ channels , negotiate codecs and stream media.The endpoint module helps to bridge channels between different protocol supported endpoints . SIP being the most popular protocol for voip session is implemented by mod_sofia module while RTP is inbuild into freeswitch core . SRTP ( media protocol for webrtc ) is provided by mod_verto.

Architecture and Design of Freeswitch

Freeswitch can form the basis of complicated and sophisticated communications backend framework with thousand CPS(Call per second ) . It can connect to VOIP ( voice over IP ) as well as PSTN ( Public Switched Telephone network ) and PRI ( Primary Rate Interfaces – used in enterprises communication)

 

Core

Data strutters are opaque and operations can be invoke by APIs with routines getting maximum reuse .

 

Threaded Model 

Enables parallel operation as every connection has its own thread. Event handlers push incoming events into threads .  Sub system run in background threads .

Modules

Loggers
mod_console
mod_graylog2
mod_logfile
mod_syslog

mod_yaml

Multi-Faceted
mod_enum is a dialplan interface, an application interface and an api command interface
mod_enum

XML Interfaces
mod_xml_rpc
mod_xml_curl
mod_xml_cdr
mod_xml_radius
mod_xml_scgi

Event Handlers
mod_amqp

mod_cdr_csv

log call detail records (CDRs) to a text file using text generation templates as in /conf/autoload_configs/cdr_csv.conf.xml

<configuration name=”cdr_csv.conf” description=”CDR CSV Format”>
<settings>
<param name=”default-template” value=”example”/>
<param name=”rotate-on-hup” value=”true”/>
<!– may be a b or ab –>
<param name=”legs” value=”a”/>
</settings>
<templates>
<template name=”sql”>INSERT INTO cdr VALUES (“${caller_id_name}”,”${caller_id_number}”,”${destination_number}”,”${context}”,”${start_stamp}”,”${answer_stamp}”,”${end_stamp}”,”${duration}”,”${billsec}”,”${hangup_cause}”,”${uuid}”,”${bleg_uuid}”, “${accountcode}”);</template>
</templates>
</configuration>
mod_cdr_sqlite
mod_event_multicast
mod_event_socket
mod_event_zmq
mod_zeroconf
mod_erlang_event
mod_smpp
mod_snmp

Directory Interfaces
mod_ldap

Endpoints

When any of the endpoints are loaded , they start listening for connection using configuration file . Dialstring identifies the recipient of the channel such as sofia/external/098099999 where sofia is the dialstring prefix for SIP.
mod_portaudio
mod_alsa
mod_sofia – SIP protocol support

mod_gsmopen –  Supports voice & SMS over a GSM network

mod_h323 – H.323 , ITU rich media communication protocol.

mod_opal – IAX2

mod_skypopen – Skype (discontinued )

mod_dingaling – Jingle , Google Talk, XMPP integration ( discontinued )

mod_verto

mod_rtc

mod_loopback

mod_woomera

mod_freetdm – Provides support for telephony cards from manufacturers such as Digium, Sangoma and Zaptel. Can communicate in most legacy telephony protocols such as ISDN, SS7 & analog

mod_unicall

mod_skinny

mod_khomp

mod_rtmp

Applications

mod_commands

mod_conference

inbound and outbound conference bridge, loaded from file  conf/autoload_configs/conference.conf.xml
mod_curl

mod_db

 

mod_dptools

Dialplan tools provide the apps (commands) to process call sessions in XML dialplans.

answer

Answer the call for a channel.

<!– a sample IVR( Interactive Voice Response ) –>
<extension name=”ivr”>
<condition field=”destination_number” expression=”^9000$”>
<action application=”answer”/>
<action application=”sleep” data=”1000″/>
<action application=”ivr” data=”demo_ivr”/>
</condition>
</extension>
att_xfer

Attended Transfer.

bgsystem

Execute an operating system command in the background.

bind_digit_action – Bind a key sequence or regex to an action.

bind_meta_app

Respond to certain DTMF sequences on specified call leg(s) during a bridge and execute another dialplan application.

block_dtmf

Block DTMFs from being sent or received on the channel.

break

Cancel an application currently running on the channel.

bridge

Bridge a new channel to the existing one.

bridge_export

Export a channel variable across any bridge.

capture

Capture data into a channel variable.

chat

Send a text message to an IM client

check_acl

Block originating address unless it matches an ACL.Test the i.p. address that originates the call against an Access Control List or CIDR mask
clear_digit_action – Clear all digit bindings
clear_speech_cache – Clear speech handle cache.
cluechoo – Console-only “ConCon” choo-choo train
cng_plc – Packet Loss Concealment on lost packets + comfort noise generation
conference – Establish an inbound or outbound conference call
db – insert information into the database.
deflect – Send a call deflect/refer.
delay_echo – Echo audio at a specified delay.
detect_speech – Implements speech recognition.
digit_action_set_realm – Change binding realm.
displace_session – Displace audio on a channel.
early_hangup – Enable early hangup on a channel.

eavesdrop

Spy on a channel.

<extension name=”eavesdrop”>
<condition field=”destination_number” expression=”^88(\d{4})$|^*0(.*)$”>
<action application=”answer”/>
<action application=”eavesdrop” data=”${hash(select/${domain_name}-spymap/$1$2)}”/>
</condition>
</extension>

echo

Echo audio and video back to the originator.

enable_heartbeat

Enable Media Heartbeat.

endless_playback

Continuously play file to caller.

enum – Perform E.164 lookup.
erlang – Handle a call using Erlang.
eval – Evaluates a string.
event – Fire an event.

execute_extension

Execute an extension from within another extension and return.

export

Export a channel variable across a bridge <varname>=<value>

fax_detect – Detect FAX CNG – may be deprecated.
fifo – Send caller to a FIFO queue.
fifo_track_call – Count a call as a FIFO call in the manual_calls queue.
flush_dtmf – Flush any queued DTMF.
gentones – Generate TGML tones.
group – Insert or delete members in a group.

hangup

Hang up the current channel.

<extension name="show_info">
<condition field="destination_number" expression="^9192$">
<action application="answer"/>
<action application="info"/>
<action application="sleep" data="250"/>
<action application="hangup"/>
</condition>
</extension>

hash – Add a hash to the db.
hold – Send a hold message.

httapi

Send call control to a Web server with the HTTAPI infrastructure

info – Display Call Info.
intercept – Lets you pickup a call and take it over if you know the uuid.

ivr

Run an IVR menu.

javascript – Run a JavaScript script from the dialplan
jitterbuffer – Send a jitter buffer message to a session
limit – Set a limit on number of calls to/from a resource
limit_execute – Set the limit on a specific application
limit_hash – Set a limit on number of calls to/from a resource
limit_hash_execute – Set the limit on a specific application
log – Logs a channel variable for the channel calling the application
loop_playback – Playback a file to the channel looply for limted times
lua – Run a Lua script from the dialplan
media_reset – Reset all bypass/proxy media flags.
mkdir – Create a directory.
multiset – Set multiple channel variables with a single action.
mutex – Block on a call flow, allowing only one at a time
page – Play an audio file as a page.
park – Park a call.
park_state – Park State.
phrase – Say a Phrase.
pickup – Pickup a call.
play_and_detect_speech – Play while doing speech recognition.
play_and_get_digits – Play and get Digits.
play_fsv – Play an FSV file. FSV – (FS Video File Format) additional description needed
playback – Play a sound file to the originator.
pre_answer – Answer a channel in early media mode.[old wiki]
preprocess – description needed
presence – Send Presence
privacy – Set caller privacy on calls.
queue_dtmf – Send DTMF digits after a successful bridge.
read – Read Digits.
record – Record a file from the channel’s input.
record_fsv – Record a FSV file. FSV – (FS Video File Format) additional description needed
record_session – Record Session.
recovery_refresh – Send a recovery refresh.
redirect – Send a redirect message to a session.
regex – Perform a regex.
remove_bugs – Remove media bugs.
rename – Rename file.
respond – Send a respond message to a session.
ring_ready – Indicate Ring_Ready on a channel.
rxfax – Receive a fax as a tif file.

say

Say time/date/ip_address/digits/etc. With pre-recorded prompts.
sched_broadcast – Enable Scheduled Broadcast.
sched_cancel – Cancel a scheduled future broadcast/transfer.
sched_hangup – Enable Scheduled Hangup.
sched_heartbeat – Enable Scheduled Heartbeat.
sched_transfer – Enable Scheduled Transfer.
send_display – Sends an info packet with a sipfrag.
send_dtmf – Send inband DTMF, 2833, or SIP Info digits from a session.
send_info – Send info to the endpoint.
session_loglevel – Override the system’s loglevel for this channel.
set – Set a channel variable for the channel calling the application.
set_audio_level – Adjust the read or write audio levels for a channel.
set_global – Set a global variable.
set_name – Name the channel.
set_profile_var – Set a caller profile variable.
set_user – Set a user.
set_zombie_exec – Sets the zombie execution flag on the current channel.
sleep – Pause a channel.
socket – Establish an outbound socket connection.
sound_test – Analyze Audio.
speak – Speaks a string or file of text to the channel using the defined TTS engine.[old wiki]
soft_hold – Put a bridged channel on hold.
start_dtmf – Start inband DTMF detection.
stop_dtmf – Stop inband DTMF detection.
start_dtmf_generate – Start inband DTMF generation.
stop_displace_session – Stop displacement audio on a channel.
stop_dtmf_generate – Stop inband DTMF generation.
stop_record_session – Stop Record Session.
stop_tone_detect – Stop detecting tones.
strftime – Returns formatted date and time.
system – Execute an operating system command.
three_way – Three way call with a UUID.
tone_detect – Detect the presence of a tone and execute a command if found.
transfer – Immediately transfer the calling channel to a new extension.[old wiki]
translate – Number translation.
unbind_meta_app – Unbind a key from an application.
unset – Unset a variable.
unhold – Send a un-hold message.
verbose_events – Make ALL Events verbose (Make all variables appear in every single event for this channel).
wait_for_silence – Pause processing while waiting for silence on the channel.
wait_for_answer – Pause processing while waiting for the call to be answered.

API
chat – Send a text message to a IM client.
presence – Send Presence.
strepoch – Returns the date/time as a UNIX epoch (seconds elapsed since midnight UTC, January 1, 1970).
strftime – Returns formatted date and time.
strftime_tz – Returns formatted date and time in the timezone specified.
mod_expr
mod_fifo
mod_hash
mod_mongo
mod_voicemail
mod_directory
mod_distributor
mod_lcr
mod_easyroute
mod_esf
mod_fsv
mod_cluechoo
mod_valet_parking
mod_fsk
mod_spy
mod_sms
mod_smpp
mod_random
mod_httapi
mod_translate

SNOM Module
mod_snom

This one only works on Linux for now
mod_ladspa

Dialplan Interfaces
mod_dialplan_directory
mod_dialplan_xml
mod_dialplan_asterisk

Codec Interfaces
mod_spandsp
mod_g723_1
mod_g729
mod_amr
mod_ilbc
mod_h26x
mod_vpx
mod_b64
mod_siren
mod_isac
mod_opus

File Format Interfaces
mod_sndfile
mod_native_file
mod_png
mod_shell_stream
For icecast/mp3 streams/files
mod_shout
For local streams (play all the files in a directory)
mod_local_stream
mod_tone_stream

Timers
mod_timerfd
mod_posix_timer

Languages
mod_v8
mod_perl
mod_python
mod_java
mod_lua

ASR /TTS
mod_flite
mod_pocketsphinx
mod_cepstral
mod_tts_commandline
mod_rss

Say
mod_say_en
mod_say_ru
mod_say_zh
mod_say_sv

Third party modules
mod_nibblebill
mod_callcenter

 

Channel Variables

Channel variables are used to manipulate dialplan execution, to control call progress, and to provide options to applications. They play a pervasive role, as FreeSWITCH™ frequently consults channel variables as a way to customize processing prior to a channel’s creation, during call progress, and after the channel hangs up.

Expansion

  • $${variable} is expanded once when FreeSWITCH™ first parses the configuration on startup or after invoking reloadxml. It is suitable for variables that do not change, such as the domain of a single-tenant FreeSWITCH™ server.

<param name=”domain” value=”$${domain}”/>

  • ${variable} is expanded during each pass through the dialplan, so it is used for variables that are expected to change, such as the ${destination_number} or ${sip_to_user} fields.

Setting a channel variable :

<application=”set” data=”rtp_secure_media=true”/>

Reading a channel variable:

<route service=”E2U+SIP” regex=”sip:(.*)” replace=”sofia/${use_profile}/$1;transport=udp”/>

Exporting channel variables in bridge operations

  • from one to another call leg using export_var
  • exporting to a list using export application

<action application=”export” data=”dialed_extension=$1″/>

Custom channel variables can be defined anytime too such as

<action application=”set” data=”conference_auto_outcall_caller_id_name=Mad Boss”/>

Also channel variables can be limited to scope on an extension . An example of passing some channel variable to log application .

<action application=”log” data=”INFO Inbound call CallUUID ${call_uuid} SIPCallID ${sip_call_id}- from ${caller_id_number} to ${destination_number}”/>

If the conditions are not met, optional anti-actions are executed.

<name="is_secure" continue="true">
<-- Only Truly consider it secure if its TLS and SRTP -->

<condition field="${sip_via_protocol}" expression="tls"/>

<condition field="${rtp_secure_media_confirmed}" expression="^true$">

<action application="sleep" data="2000"/>

<action application="playback" data="misc/call_secured.wav"/>

<anti-action application="eval" data="not_secure"/>

<condition>

<extension>

Inline actions are executed during the hunting phase of dialplan

Dialplan

A Dialplan is designed to lookup list of instructions from the central XML registry within FreeSWITCH. In general dialplans are used to route a dialed call to an endpoint based on the extension and its  condition. When a matching extension is found , it executes its actions . The combination of the above can create detailed control and call flow plans .

Example 1 : Call Routing based on destination number

Example 2 : Call Routing based on destination address format ( sip uri in this case )

Example 3 :  Talking Clock

&amp;amp;lt;include&amp;amp;gt; &amp;amp;lt;context name=”default”&amp;amp;gt; &amp;amp;lt;extension name=”Talking Clock Date and Time” &amp;amp;gt;&amp;amp;lt;!–e.g. March 8, 2011 10:56pm–&amp;amp;gt; &amp;amp;lt;condition field=”destination_number” expression=”^9172$”&amp;amp;gt; &amp;amp;lt;action application=”answer”/&amp;amp;gt; &amp;amp;lt;action application=”sleep” data=”1000″/&amp;amp;gt; &amp;amp;lt;action application=”say” data=”en CURRENT_DATE_TIME pronounced ${strepoch()}”/&amp;amp;gt; &amp;amp;lt;action application=”hangup”/&amp;amp;gt; &amp;amp;lt;/condition&amp;amp;gt; &amp;amp;lt;/extension&amp;amp;gt; &amp;amp;lt;/context&amp;amp;gt; &amp;amp;lt;/include&amp;amp;gt;

Dialplan.xml is the primary and default dialplan used by freeswitch. other dialplans can also be found under conf/dialplan directory

 

 

 


Ref:

My freeswitch contributor profile  https://freeswitch.org/confluence/users/viewuserprofile.action?username=altanai

Freeswitch Wiki

Freeswitch bitbucket Codebase 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s