> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.15/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.15/api-reference/session_api.md).

# Session API

TPOSS Session API exposes different models depending on the requested session type. The current version of the Session API supports the following session types:

- `ggsn` - network session
- `scg` - service session 
- `combinedGGSNandSCG` - combined network and service session

TPOSS HTTP Session API allows you to read and manage PCS sessions using the following RPC methods:

- [Session.List](#sessionlist) - to fetch the list of PCS sessions filtered by the given criteria
- [Session.Stop](#sessionstop) - to stop a network session by the given identifier

## Data model

### Network session

A network session is represented by an object with the following properties:

| Attribute | Type | Description
|---|---|---
| Id | string | Network session identifier.
| ChargingAccountName | string | Unique identifier for a charging account.
| Class | string | Unique identifier of a session attached after authorization.
| IMEI | string | Unique identifier of a user device (15 digits).
| Module | string | Module name which provides session handlers.
| NasIp | string | [NAS](https://docs.cennso.com/components/tposs/6.15/glossary.md) IP address.
| PrivateUserName | string | Unique user identifier.
| PublicUserName | string | Unique username.
| ServiceProfileId | uint64 | Unique identifier of a service profile.
| ServiceProfileName | string | Name of a profile which is associated with a session.
| ServiceProfileNatPoolId | string | Identifier of a NAT pool used by a device.
| ServiceProfilePrimaryDns | string | Primary DNS used by a device.
| ServiceProfileSecondaryDns| string | Secondary DNS used by a device.
| ServiceProfileWanIpRange | string | Range of IP addresses used by a device.
| ServiceProfileZoneId | string | Identifier of a zone used by a device.
| Timeout | uint32 | Session's lifespan in seconds.
| Type | string | Type of a session.
| Whitelist | string | Flag that specifies if a session was created in the whitelist mode or not.
| RatType | string | Radio technology used by a mobile device.
| AcctSessionId | string | Unique accounting identifier of a network session.
| FramedIp | string | IP address configured for an authenticated user.
| IMSI | string | Unique identifier of a SIM card.
| MccMnc | string | MCC/MNC combination as defined in RADIUS Requests.
| SubscriberName | string | Subscriber used to group a set of users.
| SessionStartTime | string | Timestamp when a network session was started.
| IMEISV | string | Unique identifier of a user device with Software Version Number (16 digits).
| CalledStationId | string | APN name.
| CallingStationId | string | A Layer 2 address from which the subscriber is connected. Can be a MAC address or a phone number.

### Service session

A service session is represented by an object with the following properties:

| Attribute | Type | Description
|---|---|---
| Id | string | Service session object identifier.
| AccessClass | string | Set of rules allocated for a service session.
| AcctSessionId | string | Unique accounting identifier of a service session.
| BalanceId | string | Unique identifier for the balance object.
| FramedIp | string | IP address configured for an authenticated user.
| NatPortStart | uint16 | Start of port range when using port-based NAT.
| NatPortEnd | uint16 | End of port range when using port-based NAT.
| OutputOctets | uint64 | Number of sent octets.
| OutputPackets | uint64 | Number of sent packets.
| InputOctets | uint64 | Number of received octets.
| InputPackets | uint64 | Number of received packets.
| MultiSessionId | string | Unique accounting ID used to easily link together related service sessions.
| Module | string | Module name which provides session handlers.
| Nas | string | [NAS](https://docs.cennso.com/components/tposs/6.15/glossary.md) identifier.
| NatIp | string | NAT IP address of a device associated with a session when using port-based NAT.
| SessionStartTime | string | Timestamp when a service session was started.
| SessionTime | uint64 | Number of seconds passed since a service session creation time.
| TimeStamp | string | Time when the last charging event arrived to TPOSS. The time is provided in the UTC timezone.
| Timeout | uint32 | Session's lifespan in seconds.
| Type | string | Type of a session.
| TotalOctets | uint64 | Total number of octets available in a service session.

### Combined network and service session

The combined network and service sessions object has the following properties:

| Attribute | Type | Description
|---|---|---
| IdSCG | string | Service session object identifier.
| AccessClass | string | Set of rules allocated for a service session.
| AcctSessionIdSCG | string | Unique accounting identifier of a service session.
| BalanceId | string | Unique identifier for the balance object.
| FramedIpSCG | string | Address configured for an authenticated user from a service session.
| NatPortStart | uint16 | Start of port range when using port-based NAT.
| NatPortEnd | uint16 | End of port range when using port-based NAT.
| OutputOctets | uint64 | Number of sent octets.
| OutputPackets | uint64 | Number of sent packets.
| InputOctets | uint64 | Number of received octets.
| InputPackets | uint64 | Number of received packets.
| MultiSessionId | string | Unique Accounting ID to make it easy to link together multiple related sessions.
| ModuleSCG | string | Module name which provides session handlers for service sessions.
| Nas | string | [NAS](https://docs.cennso.com/components/tposs/6.15/glossary.md) identifier.
| NatIp | string | NAT IP address of the device associated with the session when using port-based NAT.
| SessionStartTimeSCG | string | Timestamp when a service session was started.
| SessionTime | uint32 | Number of seconds passed since a service session creation time.
| TimeStamp | string | Time when the last charging event arrived to TPOSS. The time is provided in the UTC timezone.
| TimeoutSCG | uint32 | Service session's lifespan in seconds.
| TypeSCG | string | Type of a service session.
| TotalOctets | uint64 | Total number of octets available in a service session.
| IdGGSN | string | A network session object identifier.
| ChargingAccountName | string | Unique identifier for a charging account.
| Class | string | Unique identifier of a session attached after authorization.
| IMEI | string | Unique identifier of a user device (15 digits).
| ModuleGGSN | string | Module name which provides session handlers for a network session.
| NasIp | string | [NAS](https://docs.cennso.com/components/tposs/6.15/glossary.md) IP address.
| PrivateUserName | string | Unique user identifier.
| PublicUserName | string | Unique username.
| ServiceProfileId | uint32 | Unique identifier of a service profile.
| ServiceProfileName | string | Identifier of a profile which is associated with a device.
| ServiceProfileNatPoolId | string | Identifier of a NAT pool used by a device.
| ServiceProfilePrimaryDns | string | Primary DNS used by a device.
| ServiceProfileSecondaryDns | string | Secondary DNS used by a device.
| ServiceProfileWanIpRange | string | Range of IP addresses used by a device.
| ServiceProfileZoneId | string | Identifier of a zone used by a device.
| TimeoutGGSN | uint32 | Network session's lifespan in seconds.
| TypeGGSN | string | Type of a network session.
| Whitelist | string | Flag that specifies if a session was created in the whitelist mode or not.
| RatType | string | Radio technology used by a mobile device.
| AcctSessionIdGGSN | string | Unique accounting identifier of a network session.
| FramedIpGGSN | string | Address configured for an authenticated user from a network session.
| IMSI | string | Unique identifier of a SIM card from a network session.
| MccMnc | string | MCC/MNC combination as defined in RADIUS Requests.
| SubscriberName | string | Subscriber name that is used to group a set of users.
| SessionStartTimeGGSN | string | Timestamp when a network session was started.
| IMEISV | string | Unique identifier of a user device with Software Version Number (16 digits).
| CalledStationId | string | APN name.
| CallingStationId | string | Layer 2 address from which the subscriber is connected. It can be a MAC address or a phone number.

## API methods

### Session.List

The method allows you to fetch the list of sessions based on the given query parameters. If the number of sessions exceeds the internal query limit, only the initial subset is returned. In the case when query parameters are invalid, TPOSS returns an error.

You can pass the following parameters in the request:

| Name | Type | Required / Optional | Description |
---|---|---|---|
| AuthKey | string | required | Pre-shared authentication key. |
| FeId | string | required | Static frontend identifier which must be unique to the system. |
| FeSId | string | optional | Dynamic frontend session identifier which must be reset upon system startup. |
| SessionType | string | required | Type of a session. Possible values are `ggsn`, `scg`, and `combinedGGSNandSCG`. |
| Limit | uint16 | optional | Limits the size of the result. |
| Offset | uint16 | optional | Number of results skipped in the response. |
| Sort | string | optional | Defines the ascending or descending sorting order by the session ID. The possible values are `"Sort":asc` and `"Sort":desc`. |
| Filter | string | optional | Defines a filter applied to the query results. |
| Fields | string | optional | Defines a list of fields which should be returned. |

>**NOTE:** The `Limit`, `Offset`, `Sort`, and `Fields` parameters are supported only for the `ggsn` and `scg` session types. The `combinedGGSNandSCG` session type supports only the`Filter` parameter which is mandatory.

The `Filter` field allows you to filter sessions. The filter format is: `FilterKey:FilterOperator:FilterValue`. The `FilterKey` parameter represents the session field name. The possible fields are listed in the [data model](#data-model) section. The `FilterOperator` values can be one of the following:

- `is` - equal to
- `neq` - not equal to
- `lte` - lower than or equal to
- `gt` - greater than
- `lt` - lower than
- `gte` - greater than or equal to
- `starts_with` - match objects which start with the given pattern
- `ends_with` - match objects which end with the given pattern
- `contains` - match objects which contain the given pattern

For example, this query requests sessions with IMSI that ends with 5:

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

This query requests sessions with the `BalanceId` equal to `test_balance`:

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

In the case of the `combinedGGSNandSCG` session type, only these filter operations are supported:

- `is` - equal to
- `in` - match objects contained in the given set of values. The limit is 30 values.

For example:

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

Example of the `SessionType="ggsn"` request:

```bash
curl -H 'Accept: application/json' -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "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"
  }
}
EOF
```

Example of the successful response:

```json
{
  "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 the `SessionType="combinedGGSNandSCG"` request:

```bash
curl -H 'Accept: application/json' -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "Session.List",
  "params": {
    "Filter" : "IMSI:in:[562019876543210, 562019876543211]",
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "SessionType": "combinedGGSNandSCG",
    "FeSId": "TPUIBrowser"
  }
}
EOF
```

Example of the successful response:

```json
{
  "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
    }]
  }
}
```

In the case of an error, the response contains the `error` object with an error code and message:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": "-33333",
    "message": "Not authenticated"
  }
}
```

The following error codes may be returned:

- `-30000` - Required field is missing.
- `-31411` - Invalid list parameter. This error may occur under different circumstances, such as the wrong format of the `Filter` parameter or the missing `Filter` parameter.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.

### Session.Stop

The method allows you to stop a running session with the given IMSI. The method works only for network sessions and only if the **radius.ggsn_creation_on_accounting** configuration parameter is set to `false`.

You can pass the following parameters in the request:

| Name | Type | Required / Optional | Description |
|---|---|---|---|
| AuthKey | string | required | Pre-shared authentication key. |
| FeId | string | required | Static frontend identifier which must be unique to the system. |
| FeSId | string | optional | Dynamic frontend session identifier which must be reset upon system startup. |
| IMSI | string | required | International Mobile Subscriber Identity. |
| SessionType | string | required | Type of a session. |

Example of the request:

```bash
curl -H 'Accept: application/json' -H "Content-Type: application/json" -X POST http://127.0.0.1:12000 --data-binary @- <<EOF
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "Session.Stop",
  "params": {
    "IMSI": "100000000000001",
    "AuthKey": "secret",
    "FeId": "TPUIBrowser",
    "FeSId": "TPUIBrowser",
    "SessionType": "ggsn"
  }
}
EOF
```

Example of the successful response:

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

In the case of an error, the response contains the `error` object with an error code and message:

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": "-33333",
    "message": "Not authenticated"
  }
}
```

The following error codes may be returned:

- `-30000` - Required field is missing.
- `-31808` - Session for the given IMSI was not found.
- `-32700` - Can't decode JSON request body.
- `-33333` - Not authenticated.
