# Operation principles

## 1. Call processing

### Reachable endpoints

Before gatekeeper starts alias matching it sorts out all endpoints which not reachable by some reasons. These reasons are:

- Call to endpoint prohibited by 'dial' expression.
- No sufficient bandwidth available to make connection.
- Endpoint exhausted its connections limit.

All other endpoints presumed reachable and all other operations will be made over them only.

### Resolving called endpoint by dialed alias

Dialed alias processing order:

- Outgoing dialed alias translation 'translate outgoing callee alias'.
- Dialed alias matching with declared aliases 'alias', 'login creates alias'.
- Matched alias translation 'translate incoming callee alias', 'alias ... translate to'.

1. First dialed alias goes thru outgoing dial translation ('translate outgoing callee alias' expression) declared for user who dials the given alias. For all translations only first matched translation will take the place. Originally this translation used to bring simple user dialed alias to complex system defined complete form. Result of this translation can be null string to prevent dialed alias to match. I.e. you can inhibit user to dial some strings. Once alias translated by this expression, gatekeeper will look through other endpoints to make dialed alias matching.

2. At this stage gatekeeper will simply match dialed alias with defined endpoint aliases.

3. After aliases were successfully matched and endpoint was chosen as terminating for the call, gatekeeper will translate matched alias using given rule. Originally this translation used to represent matched alias to endpoint in different form. F.e, in case endpoint is a gateway to some other telephony network with different numbering plan. Result of this translation cannot be null !

In case there is more than one dialed alias present in a call each of them will go through that process in parallel. I.e. only when all aliases passed one procedure gatekeeper will move to the other. And every dialed alias must match at stage 3 to proceed to the next level.

### Load balancing

There can be more than one endpoint with matched aliases. In this case all these endpoints going to load balancing procedure to determine one actual terminating endpoint. Endpoints balanced in following scheme:

- Endpoint with less cost wins.
- If costs equal, endpoint with greater available bandwidth wins.
- If available bandwidth same for both endpoints, one with less load wins.
- If endpoints have equal load, first random will win balancing.

Endpoint's load calculating formula

Load = CurrentConnectionCount+1/MaxConnectionCount

## 2. RADIUS

### Packet format

Packets formatted to conform RFC-2865 and RFC-2866 specifications. Refer to these standards for base packet formatting rules and fields meaning. Any variance from standards detected in gatekeeper RADIUS packets should be considered as implementation error. Common fields for all packets are:

NAS-IP-Address

Gatekeeper IP address specified in 'system address' configuration expression.

NAS-Identifier

Gatekeeper identifier specified in 'system identifier' configuration expression. Entire attribute omitted in case there is no defined value.

User-Name

User name specified in 'user' configuration expression.

User-Password

User password specified in 'user aaa password' configuration expression. Entire attribute omitted in case there is no defined value.

#### Registration authentication packet

Packet code is Access-Request. Included attributes are:

- NAS-IP-Address
- NAS-Identifier
- User-Name
- User-Password
- Service-Type

Service-Type

Always set to "login" value for this type of packet. Use this field to determine packet type.

#### Connection authentication packet

Packet code is Access-Request. Included attributes are:

- NAS-IP-Address
- NAS-Identifier
- User-Name
- User-Password
- Service-Type
- Calling-Station-Id
- Called-Station-Id

Service-Type

Always set to "call check" value for this type of packet. Use this field to determine packet type.

Calling-Station-Id

Calling endpoint aliases presented by endpoint. Entire attribute omitted in case there is no any alias defined. There can be more than one attribute of this type in case endpoint presented more than one alias.

Called-Station-Id

Called endpoint aliases presented by endpoint. Entire attribute omitted in case there is no any alias defined. There can be more than one attribute of this type in case endpoint presented more than one alias.

#### Registration accounting start packet

Packet code is Accounting-Request. Included attributes are:

- NAS-IP-Address
- NAS-Identifier
- User-Name
- Service-Type
- Acct-Authentic
- Acct-Session-Id
- Acct-Status-Type

Service-Type

Always set to "login" value for this type of packet. Use this field to determine packet type.

Acct-Authentic

Has RADIUS or Local value depending on how user was authenticated, by RADIUS server or by gatekeeper only.

Acct-Session-Id

Unique session identification to match start-stop requests.

Acct-Status-Type

Always set to "start" value for this type of packet.

#### Registration accounting stop packet

Packet code is Accounting-Request. All attribute values not described here has same values as in accounting start packet. Included attributes are:

- NAS-IP-Address
- NAS-Identifier
- User-Name
- Service-Type
- Acct-Authentic
- Acct-Session-Id
- Acct-Status-Type
- Acct-Session-Time

Acct-Status-Type

Always set to "stop" value for this type of packet.

Acct-Session-Time

Session time in seconds.

#### Connection accounting start packet

Packet code is Accounting-Request. Included attributes are:

- NAS-IP-Address
- NAS-Identifier
- User-Name
- Calling-Station-Id
- Called-Station-Id
- Acct-Authentic
- Acct-Session-Id
- Acct-Status-Type

Calling-Station-Id

Calling endpoint aliases presented by endpoint. Entire attribute omitted in case there is no any alias defined. There can be more than one attribute of this type in case endpoint presented more than one alias.

Called-Station-Id

Called endpoint aliases presented by endpoint. Entire attribute omitted in case there is no any alias defined. There can be more than one attribute of this type in case endpoint presented more than one alias.

Acct-Authentic

Has RADIUS or Local value depending on how user was authenticated, by RADIUS server or by gatekeeper only.

Acct-Session-Id

Unique session identification to match start-stop requests.

Acct-Status-Type

Always set to "start" value for this type of packet.

#### Connection accounting stop packet

Packet code is Accounting-Request. All attribute values not described here has same values as in accounting start packet. Included attributes are:

- NAS-IP-Address
- NAS-Identifier
- User-Name
- Calling-Station-Id
- Called-Station-Id
- Acct-Authentic
- Acct-Session-Id
- Acct-Status-Type
- Acct-Session-Time
- Acct-Input-Octets
- Acct-Output-Octets

Acct-Status-Type

Always set to "stop" value for this type of packet.

Acct-Session-Time

Session time in seconds.

Acct-Input-Octets

Octets count caller sent during session. Present only in case "proxy level" was "full" for given connection.

Acct-Output-Octets

Octets count callee sent during session. Present only in case "proxy level" was "full" for given connection.

## 3. Posix basic regular expressions

The Posix Basic Regular Expression language is a notation for describing textual patterns. Regexps are typically used by comparing them to a string to see if that string matches the pattern, or by searching within a string for a substring that matches.

This chapter introduces the Posix regexp notation. This is not a formal or precise definition of Posix regexps -- it is an intuitive and hopefully expository description of them.

### An introduction to regexps

In the simplest cases, a regexp is just a literal string that must match exactly. For example, the pattern:

regexp

matches the string "regexp" and no others.

Some characters have a special meaning when they occur in a regexp. They aren't matched literally as in the previous example, but instead denote a more general pattern. For example, the character * is used to indicate that the preceding element of a regexp may be repeated 0, 1, or more times. In the pattern:

smooo*th

the * indicates that the preceding o can be repeated 0 or more times. So the pattern matches:

smooth
smoooth
smooooth
smoooooth
...

Suppose you want to write a pattern that literally matches a special character like * -- in other words, you don't want to * to indicate a permissible repetition, but to match * literally. This is accomplished by quoting the special character with a backslash. The pattern:

smoo\*th

matches the string:

smoo*th

and no other strings.

The remaining sections of this chapter introduce and explain the various special characters that can occur in regexps.

### Literal regexps

A literal regexp is a string which contains no special characters. A literal regexp matches an identical string, but no other characters. For example:

literally

matches

literally

and nothing else.

Generally, whitespace characters, numbers, and letters are not special. Some punctuation characters are special and some are not (the syntax summary at the end of this chapter makes a convenient reference for which characters are special and which aren't).

### Character sets

This section introduces the special characters . and [.

. matches any character except the NULL character. For example:

p.ck

matches

pick
pack
puck
pbck
pcck
p.ck
...

[ begins a character set. A character set is similar to . in that it matches not a single, literal character, but any of a set of characters. [ is different from . in that with [, you define the set of characters explicitly.

There are three basic forms a character set can take.

In the first form, the character set is spelled out:

[<cset-spec>] -- every character in <cset-spec> is in the set.

In the second form, the character set indicated is the negation of a character set is explicitly spelled out:

[^<cset-spec>] -- every character *not* in <cset-spec> is in the set.

A <cset-spec> is more or less an explicit enumeration of a set of characters. It can be written as a string of individual characters:

[aeiou]

or as a range of characters:

[0-9]

These two forms can be mixed:

[A-za-z0-9_$]

Note that special regexp characters (such as *) are not special within a character set. -, as illustrated above, is special, except, as illustrated below, when it is the first character mentioned.

This is a four-character set:

[-+*/]

The third form of a character set makes use of a pre-defined "character class":

\class-letter -- every character described by class-name is in the set.

The supported character classes are:

\w - the set of alpha-numeric characters
\d - decimal digits
\l - lower case letters
\s - whitespace characters
\u - upper case letters
Finally, character class sets can also inverted by uppercasing class letter.

Character sets can be used in a regular expression anywhere a literal character can.

### Subexpressions

A subexpression is a regular expression enclosed in ( and ). A subexpression can be used anywhere a single character or character set can be used.

Subexpressions are useful for grouping regexp constructs. For example, the repeat operator, *, usually applies to just the preceding character. Recall that:

smooo*th

matches

smooth
smoooth
...

Using a subexpression, we can apply * to a longer string:

banan(an)*a

matches

banana
bananana
banananana
...

Subexpressions also have a special meaning with regard to backreferences and substitutions.

### Repeated subexpressions

* is the repeat operator. It applies to the preceding character, character set, subexpression or backreference. It indicates that the preceding element can be matched 0 or more times:

bana(na)*

matches

bana
banana
bananana
banananana
...

+ is similar to * except that + requires the preceding element to be matched at least once. So while:

bana(na)*

matches

bana

bana(na)+

does not. Both match

banana
bananana
banananana
...

Thus, bana(na)+ is short-hand for banana(na)*.

### Optional subexpressions

? indicates that the preceding character, character set, or subexpression is optional. It is permitted to match, or to be skipped:

CSNY?

matches both

CSN
CSNY

### Counted subexpressions

An interval expression, {m,n} where m and n are non-negative integers with n >= m, applies to the preceding character, character set, subexpression or backreference. It indicates that the preceding element must match at least m times and may match as many as n times.

For example:

c([ad]){1,4}r

matches

car
cdr
caar
cdar
...
caaar
cdaar
...
cadddr
cddddr

### Alternative subexpressions

An alternative is written:

regexp-1|regexp-2|regexp-3|...

It matches anything matched by some regexp-n. For example:

Crosby, Stills, (and Nash|Nash, and Young)

matches

Crosby, Stills, and Nash
Crosby, Stills, Nash, and Young

### Backreferences, extractions and substitutions

A backreference is written \n where n is some single digit other than 0. To be a valid backreference, there must be at least n parenthesized subexpressions in the pattern prior to the backreference.

A backreference matches a literal copy of whatever was matched by the corresponding subexpression. For example,

(.*)-\1

matches

go-go
ha-ha
wakka-wakka
...

In some applications, subexpressions are used in string substitution. This again uses the backreference numbering scheme. For example, this command:

translate alias '90244(\d{,5})' to '90248\1'

first matches the line:

9024412345

when it does, subexpression 1 matches "12345". The command replaces the matched line with "90248\1" after doing subexpression substitution on it to get:

9024812345

### A summary of regexp syntax

In summary, regexps can be:

abcd -- matching a string literally.

. -- matching everything except NULL.

[a-z_?], ^[a-z_?], \d and \D -- matching character sets.

(subexp) -- grouping an expression into a subexpression.

The following special characters and sequences can be applied to a character, character set, subexpression, or backreference:

* -- repeat the preceding element 0 or more times.

+ -- repeat the preceding element 1 or more times.

? -- match the preceding element 0 or 1 time.

{m,n} -- match the preceding element at least m, and as many as n times.

regexp-1|regexp-2|.. -- match any regexp-n.

A special character, like . or * or ? or + can be made into a literal character by prefixing it with \.