ATI Lua Service

Introduction

The AnyTimeInterrogationLuaService is a service for initiating Lua scripts running within the LogicApp.

The AnyTimeInterrogationLuaService receives a AnyTimeInterrogationRequest operation contained in a TCAP-RECV message from an instance of the SigtranApp which is configured to receive TCAP messages from an external client.

During the transaction, the AnyTimeInterrogationLuaService communicates with the SigtranApp using the TCAP-SEND and TCAP-RECV messages. See the definition of the TCAP-… messages.

Configuring AnyTimeInterrogationLuaService

The AnyTimeInterrogationLuaService is configured within a LogicApp.

    <?xml version="1.0" encoding="utf-8"?>
    <n2svcd>
      ...
      <applications>
        ...
        <application name="Logic" module="LogicApp">
          <include>
            <lib>../apps/logic/lib</lib>
          </include>
          <parameters>
            ...
          </parameters>
          <config>
            <services>
              <service module="SigtranApp::AnyTimeInterrogationLuaService" libs="../../n2sns/apps/sigtran/lib" script_dir="../../n2sns/test/regression/set6-MAP/logic_app">
                <triggers>
                  <trigger script_key="ati_success"/>
                </triggers>
              </service>
            </services>
            <agents>
              ...
            </agents>
          </config>
        </application>
        ...
      </application>
      ...
    </n2svcd>

In addition to the Common LogicApp Service Configuration, note the following specific attribute notes, and service-specific attributes.

Under normal installation, the following service attributes apply:

Parameter Name Type XML Type Description
module String Attribute [Required] The module name containing the Lua Service code: SigtranApp::AnyTimeInterrogationLuaService
libs String Element Location of the module for AnyTimeInterrogationLuaService.
(Default: ../apps/sigtran/lib)
script_dir String Attribute [Required] The directory containing scripts used by this service.
.triggers Array Element Array of trigger elements specifying Lua scripts to run for ATI Inbound Transactions.
.trigger Object Element Provisions a Lua script to run for a ATI Inbound Transaction for received AnyTimeInterrogationRequest operations.

Script Trigger Rules

Each ATI trigger rule defines the name of a script which is ready to handle an inbound AnyTimeInterrogationRequest Transaction.

Note that destination and origination addresses may contain hex digits A-F, and the matching is for destination_prefix and origination_prefix is case-insensitive.

Each trigger Object in the config.triggers Array is configured as follows.

Parameter Name Type XML Type Description
ssn 1-255 Attribute This trigger applies for only AnyTimeInterrogationRequest to this exact SCCP subsystem number.
(Default = Trigger applies to all SCCP subsystem numbers).
destination Hex Digits Attribute This trigger applies for only AnyTimeInterrogationRequest to this exact destination reference digits (in MAP Open).
(Default = Trigger applies to all AnyTimeInterrogationRequest).
destination_prefix Hex Digits Attribute This trigger applies for only AnyTimeInterrogationRequest to destination reference digits (in MAP Open) with this prefix.
(Default = Trigger applies to all AnyTimeInterrogationRequest).
origination Hex Digits Attribute This trigger applies for only AnyTimeInterrogationRequest from this exact origination reference digits (in MAP Open).
(Default = Trigger applies to all AnyTimeInterrogationRequest).
origination_prefix Integer Attribute This trigger applies for only AnyTimeInterrogationRequest from origination reference digits (in MAP Open) with this prefix.
(Default = Trigger applies to all AnyTimeInterrogationRequest).
script_key String Attribute The name for the Lua script to load (excluding the ".lua" or ".lc" suffix).
The script should reside in the configured script_dir directory.

Script Selection (ATI Transaction Request)

The Lua script selection to execute for a AnyTimeInterrogationRequest takes into consideration the received content of the inbound TCAP_BEGIN transaction and/or the MAP content and/or the SCCP addressing information.

The destination address for matching is:

The origination address for matching is:

The operation fields e.g. subscriberIdentity.msisdn_digits, subscriberIdentity.imsi_digits, gsmSCF-Address_digits are not currently available for use in script selection.

The ATI Lua Service will iterate the configured trigger entries in the sequence in which they are configured and find the first trigger which matches the parameters of the received message.

Refer to the LogicApp configuration for more information on directories, library paths, and script caching parameters.

Script Global Variables

Scripts run with this service have access to the Common LUA Service Global Variables.

There are no service-specific global variables.

Script Entry Parameters (ATI Request)

The Lua script defines the service processing steps, such as the following:

local n2svcd = require "n2.n2svcd"
local ati_service = require "n2.n2svcd.ati_service"

local mnp_db = {
    ['61426300203'] = '1427'
}

local args = ... 

-- Get the MSISDN, error if it is not present.
n2svcd.debug_var (args)

local request = args.ati
if (request.subscriberIdentity == nil) then
    return ati_service.ERROR_DATA_MISSING
end

local msisdn_digits = request.subscriberIdentity.msisdn_digits
if (msisdn_digits == nil) then
    return ati_service.ERROR_DATA_MISSING
end

-- Find the carrier for this MSISDN, error if we don't have a matching record.
local carrier_hoc = mnp_db[msisdn_digits]
if (carrier_hoc == nil) then
    return ati_service.ERROR_UNKNOWN_SUBSCRIBER
end

local nps = ati_service.NPS_OWN_PORTED_OUT

-- Return the matched prefix.
return {
    subscriberInfo = {
        mnpInfoRes = {
            routeingNumber_digits = carrier_hoc,
            numberPortabilityStatus = nps
        }
    }
}

The service script will be executed with an args entry parameter which is an object with the following attributes:

Attribute Type Description
.remote_sccp SCCP Address Object The far-end SCCP address, as per the TCAP-RECV Message.
.local_sccp SCCP Address Object The near-end SCCP address, as per the TCAP-RECV Message.
.ati Object The decoded attributes of the AnyTimeInterrogationRequest operation. Some of these attributes may be optional. Site-specific protocol variants may add additional parameters not documented here.
.subscriberIdentity Object Container for subscriber identity informatiuon.
.msisdn Binary The MSISDN (raw bytes) encoded as MAP Address String.
.msisdn_digits HEX String The decoded digits of the MSISDN address.
.msisdn_noa Integer The decoded Nature Of Address of the MSISDN address.
.msisdn_npi Integer The decoded Numbering Plan Indicator of the MSISDN address.
.imsi Binary The IMSI (raw bytes) encoded as TBCD String.
.imsi_digit HEX String The decoded digits of the IMSI.
.gsmSCF-Address Binary The GSM SCF address (raw bytes) encoded as MAP Address String.
.gsmSCF-Address_digits HEX String The decoded digits of the GSM SCF address.
.gsmSCF-Address_noa Integer The decoded Nature Of Address of the GSM SCF address.
.gsmSCF-Address_npi Integer The decoded Numbering Plan Indicator of the GSM SCF address.
.map_open Table The decoded attributes of the MAP-Open element within the TCAP's MAP Dialogue PDU. Some of these attributes may be optional. Site-specific protocol variants may add additional parameters not documented here.
.destination_reference Binary The Destination Reference (raw bytes) encoded as MAP Address String.
.destination_reference_digits HEX String The decoded digits of the Destination Reference address.
.destination_reference_noa Integer The decoded Nature Of Address of the Destination Reference address.
.destination_reference_npi Integer The decoded Numbering Plan Indicator of the Origination Reference address.
.origination_reference Binary The Origination Reference (raw bytes) encoded as MAP Address String.
.origination_reference_digits HEX String The decoded digits of the Origination Reference address.
.origination_reference_noa Integer The decoded Nature Of Address of the Origination Reference address.
.origination_reference_npi Integer The decoded Numbering Plan Indicator of the Origination Reference address.

Script Return Parameters (ATI Response)

The Lua script is responsible for determing the contents of the ReturnResult for the AnyTimeInterrogationRequest operation, which will be sent back to the HLR and conclude the transaction.

The simplest way to do this is by the return value given back to the service at the end of script execution.

For full control over the ATI response, the script return value may be a response object with the following attributes:

Field Type Description
response Table Container for the ATI response parameters we are to send.
subscriberInfo Table Container for the returned Subscriber Info.
locationInformation Table Container for the returned Subscriber Info Location Information.
.ageOfLocationInformation Integer The age of location information for the Subscriber Info Location Information.
.geographicalInformation Binary Opaque binary field for setting returned Subscriber Info Location Information Geographical Information.
.vlr-number Binary The encoded bytes for the VLR Number as a MAP Address String.
In general, you will set the vlr-number_digits field, and the binary MAP address string will be constructed for you.
(Default = None)
.vlr-number_digits HEX String The digits for the returned VLR Number address.
(Default = None)
.vlr-number_noa Integer The Nature Of Address to encode into the returned VLR Number address.
(Default = 0)
.vlr-number_npi Integer The Numbering Plan Indicator to encode into the returned VLR Number address.
(Default = 1)
.locationNumber Binary The encoded bytes for the Location Number.
In general, you will set the locationNumber_digits field, and the binary MAP address string will be constructed for you. (Default = None)
.locationNumber_digits HEX String The digits for the returned Location Number address.
(Default = None)
.locationNumber_noa Integer The Nature Of Address to encode into the returned Location Number address.
(Default = 2)
.locationNumber_inn Integer The Internal Network Indicator to encode into the returned Location Number address.
(Default = 1)
.locationNumber_npi Integer The Numbering Plan Indicator to encode into the returned Location Number address.
(Default = 1)
.locationNumber_pri Integer The Presentation Restricted Indicator to encode into the returned Location Number address.
(Default = 1)
.locationNumber_si Integer The Screening Indicator to encode into the returned Location Number address.
(Default = 3)
.cellGlobalIdOrServiceAreaIdOrLAI Table Container for the returned Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI choice.
If present, should contain either cellGlobalIdOrServiceAreaIdFixedLength or laiFixedLength.
.cellGlobalIdOrServiceAreaIdFixedLength Binary Opaque binary field for setting returned Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (cellGlobalIdOrServiceAreaIdFixedLength).
In general, you will set the vlr-cellGlobalIdOrServiceAreaIdFixedLength_ci and other fragment fields, and the binary field will be constructed for you.
.cellGlobalIdOrServiceAreaIdFixedLength_ci HEX String (1-4) Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (cellGlobalIdOrServiceAreaIdFixedLength) by parts.
This field contains the Cell Identity or Service Area Code as a one-to-four character hex string (not an integer).
.cellGlobalIdOrServiceAreaIdFixedLength_lac HEX String (1-4) Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (cellGlobalIdOrServiceAreaIdFixedLength) by parts.
This field contains the Local Area Code as a one-to-four character hex string (not an integer).
.cellGlobalIdOrServiceAreaIdFixedLength_mcc HEX String (3) Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (cellGlobalIdOrServiceAreaIdFixedLength) by parts.
This field contains the Mobile Country Code as a three-character hex string (not an integer).
.cellGlobalIdOrServiceAreaIdFixedLength_mnc HEX String (2-3) Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (cellGlobalIdOrServiceAreaIdFixedLength) by parts.
This field contains the Mobile Network Code as a two or three character hex string (not an integer).
.laiFixedLength Binary Opaque binary field for setting returned Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (laiFixedLength).
In general, you will set the vlr-laiFixedLength_lac and other fragment fields, and the binary field will be constructed for you.
.laiFixedLength_lac HEX String Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (laiFixedLength) by parts.
This field contains the Local Area Code as a one-to-four character hex string (not an integer).
.laiFixedLength_mcc HEX String (3) Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (laiFixedLength) by parts.
This field contains the Mobile Country Code as a three-character hex string (not an integer).
.laiFixedLength_mnc HEX String (2-3) Mechanism for returning Subscriber Info Location Information cellGlobalIdOrServiceAreaIdOrLAI (laiFixedLength) by parts.
This field contains the Mobile Network Code as a two or three character hex string (not an integer).
.selectedLSA-Id Binary Opaque binary field for setting returned Subscriber Info Location Information Selected LSA ID.
.msc-number Binary The encoded bytes for the MSC Number.
In general, you will set the msc-number_digits field, and the binary MAP address string will be constructed for you.
(Default = None)
.msc-number_digits HEX String The digits for the returned MSC Number address.
(Default = None)
.msc-number_noa Integer The Nature Of Address to encode into the return MSC Number address.
(Default = 0)
.msc-number_npi Integer The Numbering Plan Indicator to encode into the MSC Number address.
(Default = 1)
.geodeticInformation Binary Opaque binary field for setting returned Subscriber Info Location Information.
.currentLocationRetrieved 1 Set this field to 1 to include the currentLocationRetrieved attribute in the response.
.sai-Present 1 Set this field to 1 to include the sai-Present attribute in the response.
subscriberState Table Container for the returned Subscriber State fields.
.assumedIdle 1 Set this field to 1 to include the assumedIdle attribute in the response.
.camelBusy 1 Set this field to 1 to include the camelBusy attribute in the response.
.netDetNotReachable Integer Contains the netDetNotReachable value to return back for the Subscriber State.
.notProvidedFromVLR 1 Set this field to 1 to include the notProvidedFromVLR attribute in the response.
mnpInfoRes Table Container for the returned Mobile Number Portability Information Response fields.
.routeingNumber Binary The encoded bytes for the Routeing Number as TBCD-Encoded bytes.
In general, you will set the routeingNumber_digits field, and the binary TBCD value will be constructed for you.
(Default = None)
.routeingNumber_digits HEX String The digits for the returned Routing Number.
(Default = None)
.imsi Binary The encoded bytes for the returned MNP IMSI as TBCD-Encoded bytes.
In general, you will set the imsi_digits field, and the binary TBCD value will be constructed for you.
(Default = None)
.imsi_digits HEX String The digits for the returned MNP IMSI.
(Default = None)
.msisdn Binary The encoded bytes for the returned MNP MSISDN as a MAP Address String.
In general, you will set the msisdn_digits field, and the binary MAP address string will be constructed for you.
(Default = None)
.msisdn_digits HEX String The digits for the returned MNP MSISDN address.
(Default = None)
.msisdn_noa Integer The Nature Of Address to encode into the returned MNP MSISDN address.
(Default = 0)
.msisdn_npi Integer The Numbering Plan Indicator to encode into the returned MNP MSISDN address.
(Default = 1)
.numberPortabilityStatus Integer Contains the numberPortabilityStatus value to return back for the MNP information.
There are constants defined in the Lua API for this purpose.

Example (returning a Table ATI Response):

local n2svcd = require "n2.n2svcd"

local args = ...

return ({ subscriberInfo = { mnpInfoRes = { numberPortabilityStatus = ati_service.NPS_NOT_KNOWN_PORTED } } })

Alternatively, a script may return a numeric scalar value which is treated as an Error Code to be returned in ReturnError in the same way as a call to the service’s .decline method.

Example (returning an ATI Error Code):

local n2svcd = require "n2.n2svcd"

local args = ...

-- Check the Database is online.
if (n2svcd.agent_status ("DB") <= n2svcd.STATUS_OFFLINE) then
    ati_service.ERROR_SYSTEM_FAILURE
end

...

return

Alternatively, the script may return nil in which case the ATI transaction will be closed by sending Empty TCAP END.

Example (returning nothing):

local n2svcd = require "n2.n2svcd"

local args = ...

return nil

In this case, the transaction will be closed with an empty TCAP END to the HLR. This may or may not be something which the HLR is expected to support.

The AnyTimeInterrogationLuaService API

The ATI Service API can be loaded as follows.

    local ati_service = require "n2.n2svcd.ati_service"

It is not necessary to load the ATI Service API if you are only using the simple response mechanism described above. It is only required if you wish to use any of the extended features described below, or any of the constants.

.response [Synchronous]

When a Lua script needs to perform extended processing, it may wish to send an early ATI response before the script completes.
This can be done with the response method on the ATI Service API.

This method will send a ReturnResult for the AnyTimeInterrogationRequest operation, within a TCAP_END.
The ATI transaction is over.
Subsequent calls to response or decline are not permitted, and will generate a runtime script error.

The response method takes a single response parameter.

Parameter Type Description
response Table or String A Lua table with the same structure as the returned object described under "Script Return Parameters".

After the response method, the ATI transaction is no longer in progress.

The response method returns the following object structure:

Parameter Type Description
controlled false This field is always false to indicate that the transaction is no longer under control.
reason Response / Abandon Response - The ReturnResult request was successfully sent to the SigtranApp.
Abandon - The user abandoned with TCAP ABORT or TCAP Empty END prior to the response attempt.

[Fragment] Example Early Response specifying Language:

    ...
    ati_service.response ({ subscriberInfo = { mnpInfoRes = { numberPortabilityStatus = ati_service.NPS_NOT_KNOWN_PORTED } } })

    [post-processing logic after ATI transaction is ended]
    ...

.decline [Synchronous]

If the Lua service logic script does not wish to handle the request, it can indicate error processing by sending a ReturnError for the AnyTimeInterrogationRequest operation, within a TCAP_END.

The ATI transaction is over. Subsequent calls to response or decline are not permitted, and will generate a runtime script error.

The decline method takes a single error_code parameter.

Parameter Type Description
error_code Integer An optional custom error code.
(Default = System Failure - Error Code 34)

After the decline method, the ATI transaction is no longer in progress.

The decline method returns the following object structure:

Parameter Type Description
controlled false This field is always false to indicate that the transaction is no longer under control.
reason Decline / Abandon Decline - The ReturnError was successfully sent to the SigtranApp.
Abandon - The user abandoned with TCAP ABORT or TCAP Empty END prior to the decline attempt.

[Fragment] Decline request using custom error code:

    ...
    ati_service.decline (ati_service.ERROR_UNKNOWN_SUBSCRIBER)

    return nil

.close [Synchronous]

The service logic may use this method to conclude the TCAP transaction without sending back a final response message. This has the same effect as returning nil from the service script.

The close method takes no parameters.

The close method returns nil.

[Fragment] Example close transaction using empty TCAP END:

    ...
    -- We wish to close the transaction immediately.
    ati_service.close ()
    ...

Again, note that this behavior may not necessarily be acceptible to the HLR.

Constants

The following ATI constants are defined on the returned ati object.

ATI Reason Constants

The following constants are used to indicate the reason that a ATI interaction succeed or failed.

-- ATI Reason Constants.
ati_service.REASON_RESPONSE = 'Response'
ati_service.REASON_DECLINE = 'Decline'
ati_service.REASON_ABANDON = 'Abandon'

ATI Error Constants

The following constants are error code values for ReturnError as passed into the decline method.

-- ATI Error Constants.
ati_service.ERROR_SYSTEM_FAILURE = 34
ati_service.ERROR_ATI_NOT_ALLOWED = 49
ati_service.ERROR_DATA_MISSING = 35
ati_service.ERROR_UNEXPECTED_DATA_VALUE = 36
ati_service.ERROR_UNKNOWN_SUBSCRIBER = 1

ATI Number Port Status Constants

The following constants are provided for convenience as standard values typically used for the subscriberInfo.mnpInfoRes.numberPortabilityStatus field value.

-- ATI Number Port Status Constants.
ati_service.NPS_NOT_KNOWN_PORTED = 0,
ati_service.NPS_OWN_PORTED_OUT = 1,
ati_service.NPS_FOREIGN_PORTED_FOREIGN = 2,
ati_service.NPS_OWN_NOT_PORTED_OUT = 3,
ati_service.NPS_FOREIGN_PORTED_IN = 4,