2020. 2. 29. 12:23ㆍ카테고리 없음
NoteAsterisk allows devices using manydifferent protocols to speak to it (and therefore to each other).However, the SIP and IAX2 protocols are the most popular and mature VoIPmodules, so we will focus our attention on them. For your first Asteriskbuild, you might be best off not bothering with the other protocols(such as Skinny/SCCP, Unistim, H.323, and MGCP), and getting comfortableworking with SIP and IAX2 first. The configuration for the otherprotocols is similar, and the sample configuration files are full ofinformation and examples, so once you have the basics down, otherprotocols should be fairly easy to workwith.The channel configurationfiles, such as sip.conf andiax.conf, contain the configuration for the channeldriver, such as chaniax2.so orchansip.so, along with the information andcredentials required for a telephony device to contact and interact withAsterisk.Common information about the channeldriver is contained at the top of the configuration file, in thegeneral section. All section names are encased insquare brackets, including device names. Anything that follows a sectionname (or device definition, which for our purposes is essentially the samething) is applied to that section. The generalsection can also contain information to define defaults for deviceconfigurations, which are overridden in the section for each device, or ina template. Asterisk also comes with defaults that are hardcoded, so whilesome settings are mandatory, many other settings can be ignored as long asyou are happy with the defaults.Check the specific section forthe relevant channel.Check the template for thesection.Check thegeneral section.Use the hardcodeddefaults.This means that just because youdidn’t specify a setting for a particular parameter doesn’t mean yourdevice isn’t going to have a setting for that parameter.
If you arenot sure, set the parameter explicitly in the section of theconfiguration file that deals with that specific channel, or in therelevant template.This concept should make more senseas you read on. How Channel Configuration Files Work with the DialplanWhile we haven’t discussed Asterisk dialplans yet, it isuseful to be able to visualize the relationship between the channelconfiguration files ( sip.conf,iax.conf) and the dialplan( extensions.conf). The dialplan is the heart of anAsterisk system: it controls how call logic is applied to any connectionfrom any channel, such as what happens when a device dials extension101 or an incoming call from an external provider isrouted. Both the relevant channel configuration file and theextensions.conf file play a role in most calls routed through the system.provides a graphicalrepresentation of the relationship between thesip.conf and extensions.conffiles.When a call comes into Asterisk, theidentity of the incoming call is matched in the channel configurationfile for the protocol in use (e.g., sip.conf). Thechannel configuration file also handles authentication and defines wherethat channel will enter the dialplan.Once Asterisk has determined how tohandle the channel, it will pass call control to the correct context inthe dialplan.
The context parameter in the channelconfiguration file tells the channel where it will enter the dialplan(which contains all the information about how to handle and route thecall). Conversely, if the dialplan has beenprogrammed to dial another device when the request for extension number101 is being processed, a request to dial telephonydevice 0000FFFF0002 will use the channelconfiguration file to determine how to pass the call back out of thedialplan to the telephone on the network (including such details asauthentication, codec, and so forth).A key point to remember is that thechannel configuration files control not only how calls enter the system,but also how they leave the system. So, for example, if one set callsanother set, the channel configuration file is used not only to pass thecall through to the dialplan, but also to direct the call from thedialplan to the destination. Sip.confThe SIP channel module is arguably the most mature andfeature-rich of all the channel modules in Asterisk. This is due to theenormous popularity of the SIP protocol, which has taken over theVoIP/telecom industry and been implemented in thousands of devices andPBXs.
If you look through the sip.conf.sample filein the./configs subdirectory of your Asterisksource you will notice a wealth of options available. NoteYou may be wondering why you mightever want to allow unauthenticated calls.
The reason is that if you publish your SIP URI on yourbusiness cards (e.g., sip:leif.madsen@shifteight.org),calls to that URI will fail if your unauthenticated context simplyhangs up. What you want instead is for your unauthenticated context toput incoming calls into a controlled environment. You may wish toallow the calls, but you won’t necessarily trust them. Thesrvlookup option is used to enable Asterisk to perform a lookup viaa DNS SRV record, which is typically used for outbound connections toservice providers. We’ll talk more about Asterisk and DNS in.Theudpbindaddr option takes the value of an IP address or0.0.0.0 to tell Asterisk which network interface itshould listen to for requests carried by the UDP network transportprotocol (which is the protocol that actually carries the voicechannels). By defining 0.0.0.0, we’re instructing thechannel driver to listen on all available interfaces.
Alternatively, wecould limit VoIP connections for this protocol to a single interface bydefining the IP address of a specific network interface on oursystem. Udpbindaddr valueDescription192.168.100.50Bind to a specific IPv4 address.2001:db8::1Bind to a specific IPv6 address0.0.0.0Bind to all IPv4 addresses on the system.::Bind to all IPv4 and IPv6addresses.Thetcpenable option allows us to accept requests via the TCP networktransport protocol. For now we’ve disabled it, as the UDP method iscurrently more mature (and more popular) and we’re attempting toeliminate as many barriers as possible.
Having said that, feel free totest TCP support once you’re comfortable configuring your devices. TipFollowing the section name with(!) tells Asterisk to treat this section as a template. Bydoing this we eliminate the need to repetitively add and changeconfiguration options for every device we choose to define. Templatesare extremely useful and are available in all of Asterisk’sconfiguration files. If you want to change something for an individualdevice that was previously defined in the template for that device,you can do that under the section header, and it will override whatwas defined by the template. It is not necessary to use templates, butthey are extremely handy, and we use them extensively.In theoffice-phone template we’ve defined several options requiredfor authentication and control of calls to and from devices that usethat template.
The first option we’ve configured is thetype, which we’ve set to friend.This tells the channel driver to attempt to match on name first, andthen IP address. Type =DescriptionpeerMatch incoming requests to a configuration entry usingthe source IP address and port number.userMatch incoming requests to a configuration entry usingthe username in the From header of the SIPrequest. This name is matched to a section insip.conf with the same name in squarebrackets.friendThis enables matching rules for bothpeer and user. This isthe setting most commonly used for SIP phones.When a request from a telephone isreceived and authenticated by Asterisk, the requested extension numberis handled by the dialplan in the context defined inthe device configuration; in our case, the context namedLocalSets.The host option is used when we need to send a request to thetelephone (such as when we want to call someone).
Asterisk needs to knowwhere the device is on the network. By defining the value asdynamic, we let Asterisk know that the telephone willtell us where it is on the network instead of having its locationdefined statically. If we wanted to define the address statically, wecould replace dynamic with an IP address such as192.168.128.30.The nat option is used to tell Asterisk to enable some tricks tomake phone calls work when a SIP phone may be located behind a NAT. Thisis important because the SIP protocol includes IP addresses in messages.If a phone is on a private network, it may end up placing privateaddresses in SIP messages, which are often not useful.The password for the device is definedby the secret parameter.
While this is not strictly required, youshould note that it is quite common for unsavory folks to run phishingscripts that look for exposed VoIP accounts with insecure passwords andsimple device names (such as a device name of 100with a password of 1234). By utilizing an uncommondevice name such as a MAC address, and a password that is a littleharder to guess, we can significantly lower the risk to our systemshould we need to expose it to the outside world. WarningDo not use the password we havedefined in the example. This book will be available online and can bedownloaded by anyone, and that particular password is almost certainto become one of the first passwords added to the list employed byVoIP phishing scripts in brute-force password attacks. If your SIPports are exposed to the Internet and you use simple passwords, restassured that you will eventually be defrauded.Thedtmfmode option is used to define which DTMF (touch-tone) formatAsterisk should expect to be sent by the telephone.
The four optionsare: info, inband,rfc2833, and auto. Theinfo value means to use the SIP INFO method,inband is for inband audio tones, andrfc2833 is for the out-of-band method defined by thatRFC. Using auto allows Asterisk to automaticallydetermine which DTMF mode to use (it prefers rfc2833if available).The last two options,disallow and allow (sip.conf), are used tocontrol which audio codecs are accepted from and offered to thetelephone. By defining disallow=all first, we’retelling Asterisk to reset any previously defined codec definitions inthe general section (or the internal defaults);then we explicitly declare which codecs we’ll accept (and the order weprefer). In our example we’ve enabled both ulaw andalaw, with ulaw most preferred (ifyou are outside of Canada or the US, you’ll likely want to declarealaw first).Now that we’re finished with ourtemplate, we can define our device names and, utilizing theoffice-phone template, greatly simplify the amount ofdetails required under each device section. The device name is definedin the square brackets, and the template to be applied is defined in theparentheses following the device name.
Iax.confIAX2 stands for the Inter-Asterisk eXchange protocol,version 2. It was originally developed to connect Asterisk systemstogether across different physical networks, and especially those behindfirewalls and NAT devices. IAX2 was designed to limit the number ofports required to carry VoIP calls across a firewall, and to easilytraverse networks that employed NAT devices (which historically havebeen problematic for the SIP protocol).
As Asterisk has developed overthe years, the IAX2 protocol has matured. It was standardized in an IETFRFC in 2009but IAX2 has not become popular with hardware vendors,possibly due to the relative recency of the RFC, and certainly due tothe fact that SIP is far and away the most recognized VoIP protocol interms of mind-share (i.e., nontechnical folks have probably heard ofSIP). IAX2, however, has advantages that make it a protocol worthdiscussing.One of the primary advantages of IAX issingle-port firewall penetration.
All traffic, including signaling and audio data, istransferred over a single UDP port (4569), which can greatly simplifysecuring the VoIP network. Another advantage is IAX2 trunking,which encapsulates packets for several voice frames into the samedatagram using a single IAX2 header.
The benefit of this is a reductionin the amount of overhead required to send many simultaneous callsbetween two endpoints. NoteThe other two types areuser and peer. In IAX2, afriend is a combination of both auser and a peer, which is commonfor telephones because we expect to send calls to them, and to receiverequests for placing calls from them. We could alternatively definetwo separate sections with the same name with types ofuser and peer, and then defineonly the required information for each of those types; or if we onlyever expected to send calls to or place calls using a section (such asin the case of an inbound- or outbound-only service provider), wewould define it as only either a user or apeer. However, in the vast majority of cases, justutilizing the type of friend isthe most logical choice.Note the difference between themeaning of the type option iniax.conf versus sip.conf(see the sidebar ). Iniax.conf, the meaning is much simpler: it onlyhas to do with the direction of the phone calls.Following the typeoption, we’ve set host to dynamic,which means the phone will register with us to identify where it existson the network (so that we know where to send its calls).
Alternatively,we could statically define an IP address such as192.168.128.50 where all calls will be sent to andaccepted from. This will only work if the device will always have thesame IP address.The next option issecret, which defines the password. WarningYou should make sure you areimplementing a secure password here, especially if you plan on openingyour system up to the outside world at all. Do not use somethingstupid such as 1234, or you’ll regret it. We’re not kidding. Not even in the lab.The number of successful attacks onVoIP-enabled telephone systems (not just Asterisk) is on the rise, andwill continue to get worse. Commonly, successful intrusions are due toweak passwords.
If you get in the habit of using strong passwords now,you’ll have that much more protection in the future. WarningDo not use the password we havedefined in the example.
Amr Codec Media Player
You can be sure that shortly after this bookis published, that will be one of the first passwords a brute-forcebot will try to use on your system.Thecontext option defines the context at which this channel willenter the dialplan. When a call is placed by a telephone and the requestis received by Asterisk, it is handled by the logic defined in thecontext configured here within the dialplan( extensions.conf).Following that are thedisallow and allow options. These define the codecs that will be allowed forthis channel (in order of preference). The directivedisallow=all resets any default codecs that may havebeen permitted in the general section (or as partof the channel defaults). Then, we define the specific codecs we wish topermit with allow. Modifying Your Channel Configuration Files for YourEnvironmentOur examples so far have been based on hypothetical devicenames.
To create actual channels based on whatever you have in yourenvironment, you will want to change the device names in yoursip.conf and iax.conf files tosomething that makes more sense.For example, if you have a Polycom IP430 set with a MAC address of 00, you’llwant to define a device identifier in sip.conf forthat device: 00(office-phone)If you have an IAX softphone on your PC that you wish to use, youriax.conf file may want something like this: 001b63a28ccc(office-phone); you could have a comment like Leif's LaptopRemember that you can name your devicesanything you want. Asterisk doesn’t care, but for ease of management,make sure you choose a naming convention that is logical, scalable, andsustainable.
CodecsCodecs aregenerally understood to be various mathematical models used todigitally encode (and compress) analog audio information. Many ofthese models take into account the human brain's ability to form animpression from incomplete information.
We've all seen opticalillusions; likewise, voice-compression algorithms take advantage of our tendency to interpretwhat we believe we should hear,rather than what we actuallyhear. The purpose of the variousencoding algorithms is to strike a balance between efficiency andquality.'
Aoccdrnig to rsereach at anElingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers ina wrod are, the olny iprmoetnt tihng is taht frist and lsat ltteresare in the rghit pclae. The rset can be a toatl mses and you cansitll raed it wouthit a porbelm. Tihs is bcuseae we do not raedervey lteter by istlef, but the wrod as a wlohe.' (The source ofthis quote is unknownsee.)Tihs is ture with snoud, too.On an audio CD, quality is far more importantthan bandwidth, so the audio is quantized at 16 bits (times 2, asit's stereo), with a sampling rate of 44,100 Hz. Considering thatthe CD was invented in the late 1970s, this was quite impressivestuff. The telephone network does not require this level of quality(and needs to optimize bandwidth), so telephone signals are encodedusing 8 bits, at a sampling frequency of 8,000 Hz.Originally, the term CODEC referred to aCOder/DECoder: a device that converts between analog and digital.Now, the term seems to relate more toCOmpression/DECompression.Before we dig into the individual codecs, take alook at it's a quick reference that youmay want to refer back to. Codec quick referenceCodecData bitrate (kbps)Licence required?G.71164 kbpsNoG.72616, 24, or 32 kbpsNoG.723.15.3 or 6.3 kbpsYes (no for passthrough)G.729A8 kbpsYes (no for passthrough)GSM13 kbpsNoiLBC13.3 kbps (30-ms frames) or 15.2 kbps (20-msframes)NoSpeexVariable (between 2.15 and 22.4 kbps)No8.3.1.
G.711G.711 is the fundamental codec of the PSTN. Infact, if someone refers to PCM (discussed in the previous chapter)with respect to a telephone network, you are allowed to think ofG.711. Two companding methods are used: m-law in North America and A-law in the rest of theworld. Either one delivers an 8-bit word transmitted 8,000 timesper second. If you do the math, you will see that this requires64,000 bits to be transmitted per second.Many people will tell you that G.711 is anuncompressed codec. This is not exactly true, as companding isconsidered a form of compression. What is true is that G.711 is thebase codec from which all of the others are derived.
G.726This codec has been around for some time (itused to be G.721, which is now obsolete), and it is one of theoriginal compressed codecs. It is also known as AdaptiveDifferential Pulse-Code Modulation (ADPCM), and it can run at several bitrates. Themost common rates are 16 kbps, 24 kbps, and 32 kbps. As of thiswriting, Asterisk currently supports only the ADPCM-32 rate, whichis far and away the most popular rate for this codec.G.726 offersquality nearly identical to G.711, but it uses only half thebandwidth. This is possible because rather than sending the resultof the quantization measurement, it sends only enough informationto describe the difference between the current sample and theprevious one.
G.726 fell from favor in the 1990s due to itsinability to carry modem and fax signals, but because of itsbandwidth/CPU performance ratio it is now making a comeback. G.726is especially attractive because it does not require a lot ofcomputational work from the system. G.723.1Not to be confused with G.723 (which is anotherobsolete version of ADPCM), this codec is designed for low-bitratespeech. It has two data bitrate settings: 5.3 kbps and 6.3 kbps.G.723.1 is one of the codecs required for compliance with the H.323protocol (although other codecs may be employed by H.323). It iscurrently encumbered by patents and thus requires licensing if usedin commercial applications. What this means is that while you canswitch two G.723.1 calls through your Asterisk system, you are notallowed to decode them without a license. G.729AConsidering how little bandwidth it uses, G.729Adelivers impressive sound quality.
It does this through the use ofConjugate-Structure Algebraic-Code-Excited Linear Prediction(CS-ACELP). Because of patents, you can'tuse G729A without paying a licensing fee; however, it is extremelypopular and is thus well supported on many different phones andsystems.CELP is a popular method ofcompressing speech. By mathematically modeling the various wayshumans make sounds, a codebook of sounds can be built. Rather thansending an actual sampled sound, a code corresponding to the soundis then sent.
(Of course, there is much more to it than that.)Jason Woodward's Speech Coding page is a source of helpful information for the non-mathematicallyinclined. This is fairly heavy stuff, though, so wear your thinkingcap.To achieve its impressive compression ratio,this codec requires an equally impressive amount of effort from theCPU. In an Asterisk system, the use of heavily compressed codecswill quickly bog down the CPU.G.729A uses 8 kbps of bandwidth.
Amr Codec Rate
GSMGSM is the darlingcodec of Asterisk. This codec does not come encumbered with alicensing requirement the way that G.723.1 and G.729A do, and itoffers outstanding performance with respect to the demand it placeson the CPU.
The sound quality is generally considered to be of alesser grade than that produced by G.729A, but as much of thiscomes down to personal opinion, be sure to try it out.GSM operates at 13 kbps. ILBCThe Internet Low Bitrate Codec (iLBC) provides an attractive mix of low bandwidthusage and quality, and it is especially well suited to sustainingreasonable quality on lossy network links.Naturally, Asterisk supports it (and supportelsewhere is growing), but it is not as popular as the ITU codecsand thus may not be compatible with common IP telephones andcommercial VoIP systems. IETF RFCs 3951 and 3952 have beenpublished in support of iLBC, and iLBC is on the IETF standardstrack.Because iLBC uses complex algorithms to achieveits high levels of compression, it has a fairly high CPU cost inAsterisk.While you are allowed to use iLBC without payingroyalty fees, the holder of the iLBC patent, Global IP Sound(GIPS), wants to know whenever you use it in a commercialapplication. The way you do that is by downloading and printing acopy of the iLBC license, signing it, and returning it to them. Ifyou want to read about iLBC and its license, you can do so at.iLBC operates at 13.3 kbps (30-ms frames) and15.2 kbps (20-ms frames). SpeexSpeex is a Variable Bitrate (VBR) codec, whichmeans that it is able to dynamically modify its bitrate to respondto changing network conditions.
It is offered in both narrowbandand wideband versions, depending on whether you want telephonequality or better.Speex is a totally free codec, licensed underthe variant of the BSD license.An Internet draft for Speex is available, andmore information about Speex can be found at its home page.Speex can operate at anywhere from 2.15 to 22.4kbps, due to its variable bitrate 8.3.1.8. MP3Sure thing, MP3 isa codec. Specifically, it's the Moving Picture Experts Group AudioLayer 3 Encoding Standard. With a namelike that, it's no wonder we call it MP3! In Asterisk, the MP3codec is typically used for Music on Hold (MoH).
MP3 is not atelephony codec, as it is optimized for music, not voice;nevertheless, it's very popular with VoIP telephony systems as amethod of delivering Music on Hold.If you want to learn all aboutMPEG audio, do a web search for Davis Pan's paper entitled 'ATutorial on MPEG/Audio Compression.' Be aware that music cannot usually be broadcastwithout a license. Many people assume that there is no legalproblem with connecting a radio station or CD as a Music on Holdsource, but this is very rarely true.