> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.14/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/6.14/api-reference/session_api.md).

# Session API

The Session API provides basic capabilities to read and control PCS sessions.

The Session API exposes different models depends on a type of a requested
session. Current version of the Session API supports following session types:

- `ggsn`
- `scg`
- `combinedGGSNandSCG`

## Data model for `ggsn` session

```
   object Session {
       Id : string
       AcctSessionId : string
       ChargingAccountName : string
       Class : string
       FramedIp : inet:ip-address
       IMEISV : string
       IMEI : string
       MccMnc : string
       Module : string
       NasIp  : inet:ip-address
       PrivateUserName : string
       PublicUserName : string
       RatType : uint32
       ServiceProfileId : uint32
       ServiceProfileName : string
       ServiceProfileNatPoolId : uint32
       ServiceProfilePrimaryDns : string
       ServiceProfileSecondaryDns : string
       ServiceProfileWanIpRange : string
       ServiceProfileZoneId : string
       SessionStartTime : string
       SubscriberName : string
       Timeout : uint32
       Type : string
       Whitelist : string
   }
```

Where:

| Attribute | Description
|---|---
| Id | Id identifies the GGSN session object.
| ChargingAccountName | Unique identifier for the charging account.
| Class | Identifier of a session during authorization.
| IMEI | Unique identifier of a user device (15 digits).
| Module | A module which provides session handlers.
| NasIp | IP Address of the NAS which is requesting authentication of the user.
| PrivateUserName | Unique user identifier.
| PublicUserName | Unique username.
| ServiceProfileId | Identifier of a private user which is associated with a device.
| ServiceProfileName | Identifier of a profile which is associated with a device.
| ServiceProfileNatPoolId | Identifier of a NAT Pool used by a device.
| ServiceProfilePrimaryDns | Primary DNS used by a device.
| ServiceProfileSecondaryDns| Secondary DNS used by a device.
| ServiceProfileWanIpRange | Range of IP addresses used by a device.
| ServiceProfileZoneId | Identifier of a zone used by a device.
| Timeout | Time of session's life in seconds.
| Type | Type of a session.
| Whitelist | Flag that describes was session created in whitelist mode or not.
| RatType | Describes radio technology used by the mobile device.
| AcctSessionId | Unique identifier of a Accounting Id.
| FramedIp | An address which is configured for authenticated user.
| IMSI | Unique identifier of a SIM card.
| MccMnc | MCCMNC combination as defined in RADIUS Requests.
| SubscriberName | A subscriber is used to group a set of users. It represents the relationship with a customer. As an analogy, you can think of subscribers as representing the contract with the customer.|
| SessionStartTime | Duration of the service usage in seconds.
| IMEISV | Unique identifier of a user device with Software Version Number (16 digits).

## Data model for `scg` session

```
   object Session {
       Id : string
       AccessClass : string
       AcctSessionId : string
       BalanceId : string
       FramedIp : inet:ip-address
       NatPortEnd : inet:port-number (uint16)
       NatPortStart : inet:port-number (uint16)
       OutputOctets : uint64
       OutputPackets : uint64
       MultiSessionId : string
       InputOctets : uint64
       InputPackets : uint64
       Module : string
       Nas : string
       NatIp : inet:ip-address
       SessionStartTime: string
       SessionTime : uint32
       TimeStamp : string
       Timeout : uint32
       Type : string
       TotalOctets : uint64
   }
```

|Attribute | Description
|---|---
| Id | SCG session object.
| AccessClass | Describes state of a current session.
| AcctSessionId | Unique identifier of a Accounting Id.
| BalanceId | Unique identifier for the balance object.
| FramedIp | An address which is configured for authenticated user.
| NatPortStart | Start of port range when using port-based NAT.
| NatPortEnd | End of port range when using port-based NAT.
| OutputOctets | Amout of octets that have been sent.
| OutputPackets | Amount of packets that have been sent.
| InputOctets | Amount of octets that have been received.
| InputPackets | Amount of packets that have been received.
| MultiSessionId | Unique Accounting ID to make it easy to link together multiple related sessions.
| Module | A module which provides session handlers.
| Nas | NAS identifier.
| NatIp | NAT IP address of the device associated with the session when using port-based NAT.
| SessionStartTime | Duration of the service usage in seconds.
| SessionTime | Identifier of how many seconds an user has received for service.
| TimeStamp | Holds UTC time when last charging event arrived to TPOSS
| Timeout | Time of session's life in seconds.
| Type | Type of a session.
| TotalOctets | Total amount of octets.

### Data model for `combinedGGSNandSCG` session

```
   object Session {
       IdGGSN : string
       AcctSessionIdGGSN : string
       ChargingAccountName : string
       Class : string
       FramedIpGGSN : inet:ip-address
       IMEISV : string
       IMEI : string
       MccMnc : string
       ModuleGGSN : string
       NasIp  : inet:ip-address
       PrivateUserName : string
       PublicUserName : string
       RatType : uint32
       ServiceProfileId : uint32
       ServiceProfileName : string
       ServiceProfileNatPoolId : uint32
       ServiceProfilePrimaryDns : string
       ServiceProfileSecondaryDns : string
       ServiceProfileWanIpRange : string
       ServiceProfileZoneId : string
       SessionStartTimeGGSN : string
       SubscriberName : string
       TimeoutGGSN : uint32
       TypeGGSN : string
       Whitelist : string
       CallingStationId: string
       CalledStationId: string
       IdSCG : string
       AccessClass : string
       AcctSessionIdSCG : string
       BalanceId : string
       FramedIpSCG : inet:ip-address
       NatPortEnd : inet:port-number (uint16)
       NatPortStart : inet:port-number (uint16)
       OutputOctets : uint64
       OutputPackets : uint64
       MultiSessionId : string
       InputOctets : uint64
       InputPackets : uint64
       ModuleSCG : string
       Nas : string
       NatIp : inet:ip-address
       SessionStartTimeSCG: string
       SessionTime : uint32
       TimeStamp : string
       TimeoutSCG : uint32
       TypeSCG : string
       TotalOctets : uint64
   }
```

| Attribute | Description
|---|---
| IdSCG | SCG session object.
| AccessClass | Describes state of a current session.
| AcctSessionIdSCG | Unique identifier of a Accounting Id from an SCG session.
| BalanceId | Unique identifier for the balance object.
| FramedIpSCG | An address which is configured for authenticated user from an SCG session.
| NatPortStart | Start of port range when using port-based NAT.
| NatPortEnd | End of port range when using port-based NAT.
| OutputOctets | Amout of octets that have been sent.
| OutputPackets | Amount of packets that have been sent.
| InputOctets | Amount of octets that have been received.
| InputPackets | Amount of packets that have been received.
| MultiSessionId | Unique Accounting ID to make it easy to link together multiple related sessions.
| ModuleSCG | A module which provides session handlers for service sessions.
| Nas | NAS identifier.
| NatIp | NAT IP address of the device associated with the session when using port-based NAT.
| SessionStartTimeSCG | Duration of the service usage in seconds of an SCG session.
| SessionTime | Identifier of how many seconds an user has received for service.
| TimeStamp | Holds UTC time when last charging event arrived to TPOSS
| TimeoutSCG | Time of service session's life in seconds.
| TypeSCG | Type of a session.
| TotalOctets | Total amount of octets.
| IdGGSN | Id identifies the GGSN session object.
| ChargingAccountName | Unique identifier for the charging account.
| Class | Identifier of a session during authorization.
| IMEI | Unique identifier of a user device (15 digits).
| ModuleGGSN | A module which provides session handlers for a network session.
| NasIp | IP Address of the NAS which is requesting authentication of the user.
| PrivateUserName | Unique user identifier.
| PublicUserName | Unique username.
| ServiceProfileId | Identifier of a private user which is associated with a device.
| ServiceProfileName | Identifier of a profile which is associated with a device.
| ServiceProfileNatPoolId | Identifier of a NAT Pool used by a device.
| ServiceProfilePrimaryDns | Primary DNS used by a device.
| ServiceProfileSecondaryDns | Secondary DNS used by a device.
| ServiceProfileWanIpRange | Range of IP addresses used by a device.
| ServiceProfileZoneId | Identifier of a zone used by a device.
| TimeoutGGSN | Time of network session's life in seconds.
| TypeGGSN | Type of a session.
| Whitelist | Flag that describes was session created in whitelist mode or not.
| RatType | Describes radio technology used by the mobile device.
| AcctSessionIdGGSN | Unique identifier of a Accounting Id from a network session.
| FramedIpGGSN | An address which is configured for authenticated user.
| IMSI | Unique identifier of a SIM card from a network session.
| MccMnc | MCCMNC combination as defined in RADIUS Requests.
| SubscriberName | A subscriber is used to group a set of users. It represents the relationship with a customer. As an analogy, you can think of subscribers as representing the contract with the customer.
| SessionStartTimeGGSN | Duration of the service usage in seconds.
| IMEISV | Unique identifier of a user device with Software Version Number (16 digits).

## API methods

### Session.List

Returns the list of sessions based on the given query parameters. If the number
of sessions exceeds the internal query limit, only an initial subset will be
returned. Returns an error if no valid query parameter is passed.

Following parameters could be passed:

| Name | Type | Requirement | Description |
---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key.
| FeId | String | required | Static frontend identifier which should be unique  to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| SessionType | String | required | Describes type of a session
| Limit | uint16 | optional | Limit for the result set size.
| Offset | uint16 | optional | Number of results to be skipped in the result set.
| Filter | string | optional | Defines a filter.
| Sort | string | optional | Defines sorting.
| Fields | string | optional | Defines list of fields which should be returned

Available session types:

- `ggsn`
- `scg`
- `combinedGGSNandSCG`

For `ggsn` and `scg` sessions types following `Filter` values are supported:

- `is` - equal to.
- `neq` - not-equal to.
- `lte` - lower than or equal to.
- `gt` - greater than.
- `lt` - lower than.
- `gte` - great or equal.
- `starts_with` - match objects which starts with the given pattern.
- `ends_with` - match objects which ends with the given pattern.
- `contains` - match objects which contains the given pattern.

For example:

```
   {"Filter": "IMSI:ends_with:5"}
```

will request objects with `IMSI` which ends with `5`. Or:

```
   {"Filter": "BalanceId:is:test_balance"}
```

will request object where `BalanceId` is equal to `test_balance`.

In a case of `combinedGGSNandSCG` session type only following filter operations are supported:

- `is` - equal to.
- `in` - value is located in a set of values. Limit is - 30 values.

For example:

```
   {"Filter": "IMSI:in:[imsi1,imsi2,imsi3]"}
```

Note that `Limit`, `Offset`, `Sort` and `Fields` parameters supported only
for `ggsn` and `scg` session types. The `combinedGGSNandSCG` session type
supports only one - `Filter` parameter which is mandatory.

Example of `SessionType="ggsn"` request:

```
   $ curl -H 'Accept: application/json' -H "Content-Type: application/json" -X POST -d \
     '{
        "id": 1, "jsonrpc": "2.0",
        "method": "Session.List",
        "params": {
           "Filter" : "IMSI:is:100000000000001",
           "Limit": 3,
           "Sort": "desc",
           "AuthKey": "secret",
           "FeId": "TPUIBrowser",
           "SessionType": "ggsn",
           "FeSId": "TPUIBrowser"
        }
     }' http://127.0.0.1:12004
```

Example of response:

```
   {
      "id":1, "jsonrpc":"2.0",
      "result": {
         "TotalResults": 1,
         "Records": [{
           "AcctSessionId": "test",
           "ChargingAccountName": "700032310@account.charging.test",
           "Class": "class",
           "FramedIp": "127.0.0.3",
           "IMEISV": "356938035643817",
           "IMEI": "356938035643809",
           "IMSI": "100000000000001",
           "Id": "262019876543210",
           "MccMnc": "12345",
           "Module": "Elixir.Tposs.Pcs.Ggsn",
           "NasIp": "10.10.0.1",
           "PrivateUserName": "some_user",
           "RatType": "0,0,0,1",
           "ServiceProfileId": 1,
           "ServiceProfileName": "AT",
           "ServiceProfileNatPoolId": "test",
           "ServiceProfilePrimaryDns": "8.8.8.4",
           "ServiceProfileSecondaryDns": "8.8.8.8",
           "ServiceProfileWanIpRange": "192.160.0.1-192.175.255.255",
           "ServiceProfileZoneId": "MOBILE",
           "SessionStartTime": "2017-03-22 18:50:34",
           "SubscriberName": "subscriber1",
           "Timeout": 5400,
           "Type": "ggsn",
           "Whitelist": true,
           "PublicUserName": "user1"}
         ]
      }
   }
```

Example of `SessionType="combinedGGSNandSCG"` request:

```
   $ curl -H 'Accept: application/json' -H "Content-Type: application/json" -X POST -d \
     '{
        "id": 1, "jsonrpc": "2.0",
        "method": "Session.List",
        "params": {
           "Filter" : "IMSI:in:[562019876543210, 562019876543211]",
           "AuthKey": "secret",
           "FeId": "TPUIBrowser",
           "SessionType": "combinedGGSNandSCG",
           "FeSId": "TPUIBrowser"
        }
     }' http://127.0.0.1:12004
```

Example of response:

```
   {
      "id":1, "jsonrpc":"2.0",
      "result": {
         "TotalResults": 2,
         "Records": [{
           "AcctSessionIdGGSN": "test",
           "ChargingAccountName": "700032310@account.charging.test",
           "Class": "class-1",
           "FramedIpGGSN": "127.0.0.1",
           "IMEISV": "356938035643817",
           "IMEI": "562019876543213",
           "IMSI": "562019876543211",
           "IdGGSN": "562019876543211",
           "MccMnc": "12345",
           "ModuleGGSN": "Elixir.Tposs.Pcs.Ggsn",
           "NasIp": "10.10.0.1",
           "PrivateUserName": "some_user-1",
           "RatType": "0,0,0,1",
           "ServiceProfileId": 1,
           "ServiceProfileName": "AT",
           "ServiceProfileNatPoolId": "test",
           "ServiceProfilePrimaryDns": "8.8.8.4",
           "ServiceProfileSecondaryDns": "8.8.8.8",
           "ServiceProfileWanIpRange": "192.160.0.1-192.175.255.255",
           "ServiceProfileZoneId": "MOBILE",
           "SessionStartTimeGGSN": "2017-03-22 18:50:34",
           "SubscriberName": "subscriber1",
           "TypeGGSN": "ggsn",
           "Whitelist": true,
           "PublicUserName": "user1",
           "IdSCG": "scg-1",
           "AccessClass": "Online",
           "AcctSessionIdSCG": "test-session-id-1"
           "BalanceId": "test-balance-id-1",
           "FramedIpSCG": "127.0.0.1",
           "NatPortEnd": 6100,
           "NatPortStart": 6000,
           "OutputOctets": 2000,
           "OutputPackets": 0,
           "MultiSessionId": "test_id",
           "InputOctets": 100,
           "InputPackets": 0,
           "ModuleSCG": "Elixir.Tposs.Pcs.Scg",
           "Nas": "SCG",
           "NatIp": "127.0.0.1",
           "SessionStartTimeSCG": "2017-03-22 18:50:34",
           "SessionTime": 10000,
           "TimeStamp": "2017-03-22 18:50:34",
           "TimeoutSCG": 5400,
           "TypeSCG": "scg",
           "TotalOctets": 100
         },
         {
           "AcctSessionIdGGSN": "test",
           "ChargingAccountName": "700032311@account.charging.test",
           "Class": "class-2",
           "FramedIpGGSN": "127.0.0.2",
           "IMEISV": "356938035643818",
           "IMEI": "562019876543212",
           "IMSI": "562019876543211",
           "IdGGSN": "562019876543211",
           "MccMnc": "12345",
           "ModuleGGSN": "Elixir.Tposs.Pcs.Ggsn",
           "NasIp": "10.10.0.1",
           "PrivateUserName": "some_user-2",
           "RatType": "0,0,0,1",
           "ServiceProfileId": 1,
           "ServiceProfileName": "AT",
           "ServiceProfileNatPoolId": "test",
           "ServiceProfilePrimaryDns": "8.8.8.4",
           "ServiceProfileSecondaryDns": "8.8.8.8",
           "ServiceProfileWanIpRange": "192.160.0.1-192.175.255.255",
           "ServiceProfileZoneId": "MOBILE",
           "SessionStartTimeGGSN": "2017-03-22 18:50:34",
           "SubscriberName": "subscriber2",
           "TypeGGSN": "ggsn",
           "Whitelist": true,
           "PublicUserName": "user2",
           "IdSCG": "scg-2",
           "AccessClass": "Online",
           "AcctSessionIdSCG": "test-session-id-2"
           "BalanceId": "test-balance-id-2",
           "FramedIpSCG": "127.0.0.2",
           "NatPortEnd": 6100,
           "NatPortStart": 6000,
           "OutputOctets": 2000,
           "OutputPackets": 0,
           "MultiSessionId": "test_id-2",
           "InputOctets": 100,
           "InputPackets": 0,
           "ModuleSCG": "Elixir.Tposs.Pcs.Scg",
           "Nas": "SCG",
           "NatIp": "127.0.0.1",
           "SessionStartTimeSCG": "2017-03-22 18:50:34",
           "SessionTime": 10000,
           "TimeStamp": "2017-03-22 18:50:34",
           "TimeoutSCG": 5400,
           "TypeSCG": "scg",
           "TotalOctets": 100
         }]
      }
   }
```

Following list of error codes may be returned:

- `-31411` - Invalid list Query. This error may occur under different
circumstances such a wrong format of a `Filter`, `Filter` parameter
is missed and so on.

### Session.Stop

The method can be used to stop a running session. The session with the given
`IMSI` will be stopped. Returns an error if no valid query parameter is
passed.

Following parameters could be passed:

| Name | Type | Requirement | Description |
|---|---|---|---|
| AuthKey | AuthKey | required | Pre-shared authentication key. |
| FeId | String | required | Static frontend identifier which should be unique to the system.
| FeSId | String | required | Dynamic frontend session identifier which should be reset upon system startup.
| IMSI | string | required | International Mobile Subscriber Identity. |
| SessionType | String | required | Describes type of a session |

Example of request:

```
   $ curl -H 'Accept: application/json' -H "Content-Type: application/json" -X POST -d \
     '{
        "id": 1, "jsonrpc": "2.0",
        "method": "Session.Stop",
        "params": {
           "IMSI": "100000000000001",
           "AuthKey": "secret",
           "FeId": "TPUIBrowser",
           "FeSId": "TPUIBrowser",
           "SessionType": "ggsn"
        }
     }' http://127.0.0.1:12004
```

Example of response:

```
   {"id": 1, "jsonrpc": "2.0", "result": "true"}
```

There is only single possible error code:

- `-31808` - Session not found.
