[asterisk-dev] new priority of pattern matching in 1.4. Does it makes sense?

Jared Smith jsmith at digium.com
Fri Feb 22 09:09:44 CST 2008


On Fri, 2008-02-22 at 08:13 -0600, John Lange wrote:
> Shouldn't Asterisk treat all the patterns with equal weight and select
> the best match?

Not if they're in different levels of contexts, because you may want to
have the *exact same* pattern in different contexts, and give priority
to one over the other.  Let me explain why with a simple example.

Let's say you're using contexts to enforce some class-of-service rules.
You have three different levels of service -- some people can only dial
local calls, some people can dial long-distance calls, and some people
can dial international calls.  (And I'll apologize right now to my
international friends -- this example is very North America centric,
although the concepts should work anywhere.)  So, we have a dialplan
like this:

[local]
exten => _NXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; seven-digit local
exten => _NXXNXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; ten-digit local
exten => _1800NXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; 800 toll free
exten => _1888NXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; 888 toll free
exten => _1877NXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; 877 toll free
exten => _1866NXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; 866 toll free

exten => _1NXXNXXXXXX,1,Playback(this-call-is-not-allowed,n) ; block ld 
exten => _1NXXNXXXXXX,n,Congestion(5)
exten => _1NXXNXXXXXX,n,Hangup()

exten => _011.,1,Playback(this-call-is-not-allowed,n) ; block int'l
exten => _011.,n,Congestion(5)
exten => _011.,n,Hangup()

[long-distance]
include => local
exten => _1NXXNXXXXXX,1,Dial(IAX2/some_itsp/${EXTEN}) ; allow ld calls

exten => _1900NXXXXXX,1,Playback(this-call-is-not-allowed,n) ; block 900
exten => _1900NXXXXXX,n,Congestion(5)
exten => _1900NXXXXXX,n,Hangup()

[international]
include => long-distance

exten => _011.,1,Dial(IAX2/some_itsp/${EXTEN})

Now let's say you have three phones... one in the lobby, one on the
secretary's desk, and one in the CEO's office.  The lobby phone is
pointed at the [local] context, the secretary's phone is pointed at the
[long-distance] context, and the CEO's phone is pointed at the
[international] context.  Can you see how if the secretary were to dial
a long-distance number, you'd want the pattern in the [long-distance]
context to match before the one in the [local] context.  

To see which pattern would actually match, you can type 'dialplan show
1256428600 at long-distance", for example, and see the following output:

localhost*CLI> dialplan show 12564286000 at long-distance
[ Context 'long-distance' created by 'pbx_config' ]
  '_1NXXNXXXXXX' => 1. Dial(IAX2/some_itsp/${EXTEN})              [pbx_config]
[ Included context 'local' created by 'pbx_config' ]
  '_1NXXNXXXXXX' => 1. Playback(this-call-is-not-allowed|n)       [pbx_config]
                    2. Congestion(5)                              [pbx_config]
                    3. Hangup()                                   [pbx_config]

See how it shows that the pattern in the long-distance context matches
before the local context?  I should also point out that if the Dial
application in priority 1 fails, Asterisk will happily continue in
priority 2, even if it's in another context, as in the example above.
If this *isn't* what you'd want, you'd want to add the following line to
to the long-distance context:

exten => _1NXXNXXXXXX,n,Hangup()

Hopefully this little example has shown you why it's important not to
just lump all the contexts together with equal weight.

-- 
Jared Smith
Community Relations Manager
Digium, Inc.




More information about the asterisk-dev mailing list