asterisk -vvvc
It will execute the server. These options tell the server not to run in the background and to run at a verbosity level of three, which means all the important messages will be displayed and enough less important ones and that the user will see all diagnostic messages. While many messages will quickly scroll by on the screen, most of these are simple initialization messages that can be ignored. If any fatal errors occur, Asterisk will stop and exit so the message remains on the screen. Asterisk will display “Asterisk Ready” when it has successfully run.
asterisk
The other way to run Asterisk is to start the daemon by running the command without any arguments at the command prompt.This will start the server in the background. Starting in the background as opposed to the foreground has advantages and disadvantages. While the server won’t tie up a terminal or exit when the terminal is closed, it will not display any diagnostic messages to the terminal during startup either. Running Asterisk in the background is the most common way to run Asterisk since normally an Asterisk process would be running at all times. One would want to run Asterisk in the foreground if diagnosis information is needed. To connect to an already running Asterisk process, run the command.
asterisk -vvvr
This will duplicate the verbosity settings to the above command.
You can issue the stop or restart command to Asterisk in three ways. When issuing the restart or stop command, you can tell Asterisk to do it now, gracefully, or when convenient.These control how the server will go about shutting down.
now : The server process is shut down immediately, without any concerns for activity.Any active calls are terminated and all active threads are killed.This is not normally the way to shut down the server in a production environment.
gracefully: it is a much cleaner way to shut down or restart. After the command is issued, Asterisk stops answering all new calls.
convenient: continues functioning normally, the server restarts or stops when there are no active calls within the system. While this is the best when talking in terms of lost productivity, if the system constantly has active calls on it, the system will never stop or restart.
reload : reloads all the configuration files on-the-fly without interrupting system activity.
Configuring Asterisk:
If you enter into your Asterisk configuration directory, /etc/asterisk, you’ll see 65 files.
Asterisk Configuration Files:
adsi.conf Controls Asterisk Analog Display Services Interface settings.
adtranvofr.conf Contains settings related to Voice over Frame Relay and AdTran equipment.
agents.conf Contains settings for call agents that work call queues.
alarmreceiver.conf Contains settings for the Alarm Receiver application.
alsa.conf Contains settings for the CLI sound system if using ALSA sound drivers.
amd.conf Contains settings for answering machine detection on outbound calls.
asterisk.adsi Asterisk Analog Display Services Interface script.
cdr.conf Contains settings for Call Detail Records (CDRs).
cdr_custom.conf Contains settings for custom Call Detail Record mappings.
cdr_manager.conf Contains settings for sending CDRs to the Asterisk Management Interface.
cdr_odbc.conf Contains settings for storing your CDRs into a database connected via ODBC.
cdr_pgsql.conf Contains settings for storing your CDRs into a PostgreSQL SQL database.
cdr_tds.conf Contains settings for storing your CDRs into a FreeTDS database.
CODECs.conf Contains CODEC settings.
dnsmgr.conf Contains settings about Domain Name System (DNS) lookups done by Asterisk.
dundi.conf Controls Distributed Universal Number Discovery connections and settings.
enum.conf Controls Telephone Number Mapping/E164 connections and settings.
extconfig.conf Contains mappings for external database connections for configuration settings.
extensions.ael Contains the dial plan settings, written in Asterisk Extension Language.
extensions.conf Contains the dial plan settings.
Features.conf Contains settings for call parking.
festival.conf Contains settings for the connection between Asterisk and the Festival TTS Engine.
followme.conf Contains settings for the FollowMe application.
func_odbc.conf Contains settings for template-based SQL functions accessed via ODBC.
gtalk.conf Controls Google Talk connections and settings.
h323.conf Controls H323 Protocol connections and settings.
http.conf Contains settings for Asterisk’s integrated HTTP server.
iax.conf Controls Inter Asterisk eXchange Protocol Connections and Settings.
iaxprov.conf Contains settings for IAXy provisioning.
indications.conf Contains settings for the system’s Ring, Busy, Reorder, and Special Information tones.
jabber.conf Controls Jabber Protocol connections and settings.
logger.conf Contains settings about where and what to log.
manager.conf Contains settings for the Asterisk Management Interface.
meetme.conf Contains settings for the MeetMe conferencing system.
mgcp.conf Controls Media Gateway Control Protocol connections and settings.
misdn.conf Controls Integrated Serial Digital Networks (ISDNs) connections and settings.
modem.conf Controls ISDN modem settings.
modules.conf Controls which applications and modules are loaded when the server is started.
musiconhold.conf Contains Music on Hold settings.
muted.conf Contains settings for the Mute Daemon.
osp.conf Controls settings and connections for the Open Settlement Protocol.
oss.conf Contains settings for the CLI sound system if using OSS sound drivers.
phone.conf Contains settings for Linux Telephony devices.
privacy.conf Contains settings for the PrivacyManager application.
queues.conf Contains settings for call queues.
res_odbc.conf Contains settings for external database connections for configuration settings.
res_snmp.conf Contains Simple Network Management Protocol settings for the SNMP application.
rpt.conf Controls settings of the app_rpt application, which enables radio systems to be linked via VoIP.
rtp.conf Contains Real-time Transport Protocol settings.
say.conf Contains string settings for the various say_* applications.
sip.conf Controls Session Initiation Protocol (SIP) connections and settings.
sip_notify.conf Contains settings for SIP’s NOTIFY command.
skinny.conf Controls Skinny Client Control Protocol connections and settings.
sla.conf Controls Shared Line Appearance connections and settings.
smdi.conf Contains settings for the Simplified Message Desk Interface.
telcordia-1.adsi Default Telcordia Analog Display Services Interface script.
udptl.conf Contains settings for UDPTL, one of the transports for Faxing over IP Networks.
users.conf A file that controls a combination of settings, allowing for easier user maintenance.
voicemail.conf Contains voice mail settings and mailbox details.
vpb.conf Contains settings for VoiceTronix hardware.
zapata.conf Controls settings for Zapata hardware.
Step 10: Configuring Dial Plan
The dial plan is the logic behind how phone calls are routed through your Asterisk installation. Asterisk runs every incoming call, every outgoing call, and every call in between extensions through the dial plan logic in order to determine where it should go and whether or not it should be completed. The dial plan is contained in extensions.conf, and therefore it can be said that extensions.conf is easily the most important configuration file in Asterisk. Removing extensions.conf is similar to removing a traffic light at a complicated intersection; cars will want to enter and cars will want to leave, but there will be no way to direct them. extensions.conf can be broken down into three major parts: 1. Contexts, 2. Extensions, and 3. Variables. Each has their own unique and important function and needs to work together for a good dial plan to function.
1. Contexts : A context is a simple way for grouping extension commands based on what the user has dialed.To begin a context, put the name of a context by itself in square brackets. Each context then contains a list of commands. In extensions.conf there are two special contexts called [general] and [globals] in which certain settings can be set. general has a few special settings that define how extensions.conf behaves. First off is the static setting.This, can be set to either yes or no, but for some reason, only yes has been implemented.This will eventually control Asterisk from rewriting the extensions.conf every time an extension is added or deleted.The next setting is writeprotect. This can also be set to either yes or no, and this controls the ability of someone at the CLI to rewrite your dial plan via the save dialplan command.This may seem handy, but doing so will delete all comments in the file. Each extension follows a similar syntax. exten => EXTENSION,PRIORITY,COMMAND(ARGS). exten => precedes every extension.This is a directive that tells Asterisk to define an extension, as opposed to a context.The next three parts of an extension are 1) EXTENSION, 2) PRIORITY, and 3) COMMAND(). Let’s cover these three portions.
1) EXTENSION--- Extensions can be broken down into three types: a constant extension, a wildcard extension, and a special extension. A constant extension is an extension that when coded to a literal constant is the dial plan. A wildcard extension is a context that uses wildcards to match multiple possibilities for the extension.Wildcards can be either internal Asterisk wildcards or RegEx-like patterns given below:
[0126-9]--- Any digit within the pattern. (In this case: 0,1,2,6,7,8, and 9).
X ---Any number 0 through 9. The equivalent of [0-9].
Z --- Numbers between 1 through 9. The equivalent of [1-9].
N -- Numbers between 2 through 9. The equivalent of [2-9]. This scheme is used most commonly in Area Code and Prefix assignments.
.(dot)--- Any number, one or more times.
Example: Let’s say a department in your building, the ever-important Chemical department, have moved to another division and wanted to leave a message at their old extensions informing callers that they had moved.They previously occupied Extensions 300 through 329 on your PBX. Rather than rewrite 30 lines; you can add a single extension of
exten => 3[0-2]X,1,Playback(ChemicalDeptHasMoved)
This will have any caller dialing the department’s former extensions greeted by a message informing them of the move.
N.B. - Playback is a command that plays back a sound file stored on the system.
In addition to wildcard and literal extensions, there are also special extensions that correspond to special events in the dial plan:
S --> Start --> Used when a caller is put in a context before dialing a number.
I --> Invalid --> Used when a caller dials an extension not defined in the current context.
H --> Hangup --> Used when a caller hangs up.
T --> Time Out --> Used when a caller does not respond within the response timeout period.
T --> Absolute Time Out --> Used when a caller does not respond within the about timeout period.
O --> Operator.
2) PRIORITY--- it controls the flow in which commands are executed. For each extension, this is either controlled by an increasing number or a special n syntax.The n syntax tells Asterisk to execute the extension one line after the other:
[incomingcall]
exten => s,1,Answer()
exten => s,n,Playback(mainmenu)
exten => s,n,Hangup()
In this example, any call being routed to the “incomingcall” extension in Asterisk would have its call answered, a menu would then play, and then the call would be terminated. After Asterisk finishes executing one line, the next line would be executed. Numbering the steps provides greater flexibility with the dial plan since it is possible to control the flow logically rather than line by line. For example, the extension shown earlier could be rewritten with a numbered sequence
[incomingcall]
exten => s,2,Playback(mainmenu)
exten => s,1,Answer()
exten => s,3,Hangup()
Asterisk still answers, plays the menu, and hangs up because it executes by line number rather than by the order in which the lines appear. It executes step 1, followed by steps 2, and then 3.These steps could be scattered throughout the context and intertwined with hundreds of extensions. As long as they are numbered correctly, Asterisk will execute them in order for that context.
3) COMMAND()----The commands are the heart of any dial plan.They are what actually cause Asterisk to answer the call, ring the phone, transfer the call, play the menu, and do numerous other things.
Dial(CHANNEL) ---> Dials a channel
Answer() ---> Answers a ringing channel
Playback(FILE) ---> Plays a sound file in the foreground
Background(FILE) ---> Plays a sound file in the background, while waiting for the user to input an extension
Hangup() ---> Hangs up the call
SayDigits(NUMBER) ---> Says a number, digit by digit
N.B: Extensions are the physical numbers assigned to a device, while channels, on the other hand, are the connections to the devices themselves.
For example, you can have a phone at your desk set up to ring on three separate extensions; however, each of these extensions will ring the same
channel—namely, your phone.
2. Extensions: Variables in extensions.conf are nothing special.They act like variables in any other language.Variables are set via the Set() command and are read via the variable name encased in ${}:
[example]
exten => s,1,Set(TEST=1)
exten => s,2,NoOp(${TEST})
Variables are common in simple dial-plan applications and Asterisk uses certain variables for internal functions, but their use is somewhat uncommon in regular dial plan usage.
Now a very extensions.conf looks like:
[default]
exten => s,1,Answer()
exten => s,2,Background(thank-you-for-calling-
exten => s,3,Background(
exten => s,4,Hangup()
exten => 100,1,Dial(SIP/10)
exten => 200,1,Dial(SIP/20)
Now what it mean is : When a call enters the [default] context, it is answered by Asterisk. Asterisk then starts playing the mainmenu sound file while waiting for the caller to enter digits. At this point, the caller can either enter 100 and be connected to the channel SIP/10 or 20 and be connected to the channel SIP/20. If the menu finishes playing and the user has not entered any digits, the call will be hung up on.
Now we try to take the file we had before and use some special extensions to have the menu replay if the user hasn’t entered an extension and inform them if the extension they entered is invalid.
[default]
exten => s,1,Answer()
exten => s,2,Background(thank-you-for-calling-
exten => s,3,Background(
exten => t,1,Goto(s,2)
exten => i,1,Playback(sorry-thats-not-valid)
exten => i,2,Goto(s,2)
exten => 100,1,Dial(SIP/10)
exten => 200,1,Dial(SIP/20)
Creating submenu: Now to have a support menu that allows customers to direct their questions to the appropriate support group. We can accomplish this by creating a second context that contains the appropriate menu and extensions. Let’s build on the previous example again and add a second menu that allows callers to be connected to the Technical, Widget, or Chemical support lines.
[default]
exten => s,1,Answer()
exten => s,2,Background(thank-you-for-calling-socal)
exten => s,3,Background(socal-mainmenu)
exten => t,1,Goto(s,2)
exten => i,1,Playback(sorry-thats-not-valid)
exten => i,2,Goto(s,2)
exten => 3,1,Goto(s,1,supportmenu)
exten => 100,1,Dial(SIP/10)
exten => 200,1,Dial(SIP/20)
[supportmenu]
exten => s,1,Background(socal-supportmenu)
exten => 1,1,Dial(SIP/technicalsupportline)
exten => 2,1,Dial(SIP/widgetsupportline)
exten => 3,1,Dial(SIP/chemicalsupportline)
exten => #,1, Goto(s,2,default)
exten => t,1,Goto(s,1)
exten => i,1,Playback(sorry-thats-not-valid)
exten => i,2,Goto(s,1)
Now here If a caller dials 3, they are connected to the [supportmenu] context with a Goto() statement. Goto() can be called many different ways.You can jump between priorities in the same extension by just specifying Goto(priority) or you can jump between extensions in the same context by specifying Goto(priority,extension). Lastly, you can switch contexts by specifying Goto(context, extension, priority).
N.B: For example: Goto(supportmenu,s,1) will behave differently than Goto(supportmenu, s, 1). In the first example, Goto will behave as expected and jump to the “s” extension, priority 1. However, in the second example, Goto will jump to the “s” extension, priority 1. Note how there is a space that precedes the “s”. This can be a source of frustration if you don’t know to look for it.
Asterisk permits other contexts to be joined together via the include => directive.This allows other contexts to be include-ed into the current context and act as one giant context.
Creating Voice Mail Support for Existing Extensions:
[default]
include => specialextensions
exten => s,1,Answer()
exten => s,2,Background(thank-you-for-calling-socalLabs)
exten => s,3,Background(socalLabs-mainmenu)
exten => 3,1,Goto(supportmenu,s,1)
exten => 100,1,Dial(SIP/10,20)
exten => 100,2,Goto(s-100-${DIALSTATUS},1)
exten => s-100-NOANSWER,1,Voicemail(u100)
exten => s-100-NOANSWER,2,Hangup()
exten => s-100-BUSY,1,Voicemail(b100)
exten => s-100-BUSY,2,Hangup()
exten => _s-.,1,Goto(s-100-NOANSWER,1)
exten => 200,1,Dial(SIP/20)
exten => 200,2,Goto(s-200-${DIALSTATUS},1)
exten => s-200-NOANSWER,1,Voicemail(u200)
exten => s-200-NOANSWER,2,Hangup()
exten => s-200-BUSY,1,Voicemail(b200)
exten => s-200-BUSY,2,Hangup()
exten => _s-.,1,Goto(s-200-NOANSWER,1)
[supportmenu]
include => specialextensions
exten => s,1,Background(socalLabs-supportmenu)
exten => 1,1,Dial(SIP/blivetsupportline)
exten => 2,1,Dial(SIP/widgetsupportline)
exten => 3,1,Dial(SIP/frobsupportline)
exten => #,1,Goto(s,2)
[specialextensions]
exten => t,1,Goto(s,1)
exten => i,1,Playback(sorry-thats-not-valid)
exten => i,2,Goto(s,1)
Step 11: Configuring extensions.ael :
The alternative to extensions.conf is extensions.ael. extensions.ael is extensions.conf written in a scripting language called Asterisk Extensions Language (AEL). AEL is language maintained by Digium solely for writing dial plans in Asterisk. While it is functionally equivalent to extensions.conf, AEL is syntactically much more powerful and allows for greater flexibility in simple scripting and logical operations.
[default]
exten => s,1,Answer()
exten => s,2,Background(thank-you-for-calling-
exten => s,3,Background(
exten => s,4,Hangup()
exten => 100,1,Dial(SIP/10)
exten => 200,1,Dial(SIP/20)
is written in extensions.conf the same thing we can write in extensions.ael like this,
context default {
s => {
Answer();
Background(thank-you-for-calling-conglomocorp);
Background(conglomocorp-mainmenu);
Hangup();
};
100 => Dial(SIP/10);
200 => Dial(SIP/20);
};
And this
[default]
exten => s,1,Answer()
exten => s,2,Background(thank-you-for-calling-conglomocorp)
exten => s,3,Background(conglomocorp-mainmenu)
exten => t,1,Goto(s,2)
exten => i,1,Playback(sorry-thats-not-valid)
exten => i,2,Goto(s,2)
exten => 100,1,Dial(SIP/10)
exten => 200,1,Dial(SIP/20)
can be this
context default {
s => {
Answer();
restart:
Background(thank-you-for-calling-conglomocorp);
Background(conglomocorp-mainmenu);
Hangup();
};
100 => Dial(SIP/10);
200 => Dial(SIP/20);
t => { goto s|restart;}
i => {
Playback(sorry-thats-not-valid);
goto s|restart;
}
};
Step 12: Protocols Support :
SIP --> Session Initiation Protocol --> Most common VoIP protocol. Used in numerous devices.
IAX --> Inter Asterisk eXchange Protocol --> Used primarily in connections between Asterisk servers.
SCCP --> Skinny Client Control Protocol --> Used in Cisco devices.
MGCP --> Media Gateway Control Protocol --> Used in some VoIP devices, notably D-Link.
H323 --> H.323 Protocol --> Used in some older VoIP devices.
Each protocol is controlled by a different file. Multiple connections can be set up in a single file, or the files can be broken down and linked via include statements. Each file has certain specific configuration options that are used only for the protocol the file governs, and they also have options that are common across all files. Let’s go over some of the conventions:
Have a look at iax.conf
[my_iax_server]
type=peer
auth=md5
notransfer=yes
host=10.0.23.232
disallow=all
allow=ulaw
Asterisk uses some peculiar classifications for its VoIP connections.They are classified by the type= setting, which is either set to user, friend, or peer.
A user is a connection that will be used to make telephone calls to the local server; a peer is a connection that will be used to make telephone calls from the local server; and a friend is a connection that will be used to make telephone calls both to, and from, the local server.
Step 13: Allowing and Disallowing Codecs
Asterisk supports numerous codecs for audio. Codecs can save bandwidth and allow for more simultaneous phone calls on a data link.
Codecs Speed Simultaneous Calls
ยต-Law---> 64 Kbps -------> 24
G.723.1 --->5.3/6.3 Kbps -->289/243
G.726 --->16/24/32/40 Kbps --->96/64/48/38
G.729 ----->8 Kbps ------------> 192----------> Requires license
GSM ------->13 Kbps ----------->118
iLBC -------->15 Kbps ----------->102
LPC-10 ------>2.5 Kbps ---------->614
Speex ------->2.15 to 44.2 Kbps -->714 to 34----> “Open” codec
Say your shiny new Asterisk server has a connection to your telephone provider via the IAX2 protocol. However, whenever a phone call is made through the provider, the GSM codec is used, rather than the ulaw codec that is used when you call between extensions in the office.This needs to be fixed. So opening up the iax.conf configuration file you add the following line to the section controlling the connection:
disallow=gsm
Then issue a reload command to Asterisk.
The correct way to ensure ulaw is used as the codec would be to add the following lines to iax.conf.
disallow=all
allow=ulaw
Step 14: Configuring SIP Connections
SIP is the most common VoIP protocol in use today. It is an official Internet standard and is supported by almost every VoIP device and service on the market. SIP connections are configured in the sip.conf file in the system’s configuration directory, usually /etc/asterisk.
To address the firewall issue, you need to open up the firewall to allow connections from external sources to the Asterisk server on a massive amount of ports.This is a bit of an issue if the server is accepting connections from all over the Internet since there is no way to lock the access down to specific address blocks.A way to limit the amount of ports you need to open up is to edit rtp.conf in the Asterisk configuration directory:
;
; RTP Configuration
;
[general]
;
; RTP start and RTP end configure start and end addresses
;
rtpstart=10000
rtpend=20000
In sip.conf, there are three settings: the externip setting, the localnet setting, and the nat setting.The nat setting determines whether or not the server is behind a NAT.This can be set to four different settings: yes, no, never, and route.The yes setting is the straightforward setting. It informs Asterisk that we are behind a NAT and it should assume so whenever it sends SIP messages.The no setting is a bit more complicated than “No, the server is not behind a NAT.”The no setting tells Asterisk it should use RFC3581 to determine whether or not there is a NAT between the local server and the remote server.The next setting, route, is a bit of a kludge to help NAT work with certain phones that do not completely support RFC3581; you likely will never use this, and hopefully this behavior will be moved to another setting in future versions. Finally, there is never, which informs Asterisk to never think the server is behind a NAT.
For example, let’s say we have a server at our office on a 196.168.42.0/24 network that is NATed behind a gateway with an external IP address of 118.23.45.76.This is how we would make our NAT settings:
[general]
nat=yes
externip=118.23.45.76
localnet=192.168.42.0/24
Step 15: Connecting to an SIP Server
1) Registering Your Connection: Most providers do not have your account tied to a specific IP address since it’s becoming less and less common to have static IP addresses in most situations and it’s less of a hassle for you to come to them. So how do we let the provider know where to route the incoming calls? We register with them. Registering is a way of checking in with a remote server, letting them know where to route calls and that the local server is still alive.A typical register line in sip.conf would look like this:
register => auro:mondal@voip.globaltelephone.com/3115552368
In which, after a reload, we would be registering the phone number “311-555-2368” with the server voip.globaltelephone.com using the username karthik and the password reddy.
N.B: Asterisk doesn’t have any security on its configuration files by default, so before you add any sensitive information, you may want to make sure the file permissions are locked down enough that the only nonprivileged user that can read them is the user Asterisk is running under.
No comments:
Post a Comment