Skip to content

alexeymx/gtpc-sgw-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GTP-C Simulator (SGW Simulator)

A Python tool to simulate an SGW (Serving Gateway) connecting to a PGW (PDN Gateway) via GTP-C version 2 protocol.

Purpose

This tool helps test PGW-C implementations by simulating realistic session creation requests from an SGW, including:

  • Internet APN sessions
  • IMS APN sessions
  • Proper GTP-C v2 message encoding/decoding

Installation

pip install -r requirements.txt

Usage

python gtpc_simulator.py --pgw-host <PGW_IP> --pgw-port <PGW_PORT> \
                         --local-host <LOCAL_IP> --local-port <LOCAL_PORT> \
                         --imsi <IMSI> \
                         [--test-modify] [--test-delete]

Examples

Basic - Create Sessions Only:

python gtpc_simulator.py --pgw-host 192.168.1.100 --pgw-port 2123 \
                         --local-host 0.0.0.0 --local-port 2123 \
                         --imsi 001010123456789 \
                         --no-delete

Full Test - Create, Modify, and Delete:

python gtpc_simulator.py --pgw-host 192.168.1.100 --pgw-port 2123 \
                         --local-host 0.0.0.0 --local-port 2123 \
                         --imsi 001010123456789 \
                         --test-modify --test-delete

Multiple APNs with Lifecycle Testing:

python gtpc_simulator.py --pgw-host 192.168.1.100 --pgw-port 2123 \
                         --local-host 0.0.0.0 --local-port 2123 \
                         --imsi 001010123456789 \
                         --apns internet,ims,mms,xcap \
                         --test-modify --test-delete

Custom MCC/MNC (e.g., AT&T USA: MCC=310, MNC=410):

python gtpc_simulator.py --pgw-host 192.168.1.100 --pgw-port 2123 \
                         --local-host 0.0.0.0 --local-port 2123 \
                         --imsi 310410123456789 \
                         --mcc 310 --mnc 410 \
                         --apns internet

With Time Zone (e.g., India: UTC+5:30):

python gtpc_simulator.py --pgw-host 192.168.1.100 --pgw-port 2123 \
                         --local-host 0.0.0.0 --local-port 2123 \
                         --imsi 404451234567890 \
                         --mcc 404 --mnc 45 \
                         --timezone 5.5 \
                         --apns internet

Parameters

  • --pgw-host: PGW IP address (required)
  • --pgw-port: PGW GTP-C port (default: 2123)
  • --local-host: Local IP to bind socket (default: 0.0.0.0)
  • --local-port: Local port to bind socket (default: 2123)
  • --imsi: IMSI to use for session creation (required, 14-15 digits)
  • --imei: IMEI - Mobile Equipment Identity (default: 123456789012345, 15 digits)
  • --mcc: Mobile Country Code - 3 digits (default: 001)
  • --mnc: Mobile Network Code - 2 or 3 digits (default: 01)
  • --timezone: UE Time Zone in hours, supports half-hours (default: 0 for UTC)
    • Examples: 0 (UTC), 1 (UTC+1), -5 (UTC-5), 5.5 (UTC+5:30 India)
  • --apns: Comma-separated list of APNs (default: internet,ims)
  • --test-modify: Test Modify Bearer Request after creating sessions
  • --test-delete: Test Delete Session Request (clean up sessions)
  • --no-delete: Keep sessions active (don't delete)

Features

Supported GTP-C v2 Messages

Create Session Request/Response (Message Type 32/33)

  • Full session establishment
  • Bearer context creation
  • IP address allocation
  • F-TEID exchange

Modify Bearer Request/Response (Message Type 34/35)

  • Bearer modification
  • F-TEID updates
  • QoS changes simulation

Delete Session Request/Response (Message Type 36/37)

  • Session teardown
  • Bearer deletion
  • Clean resource cleanup

Additional Features

  • Creates GTP-C v2 sessions for multiple APNs
  • Simulates realistic SGW behavior
  • Complete session lifecycle testing
  • Configurable network parameters
  • Proper sequence number handling
  • Session state tracking

Information Elements (IEs) Included

The simulator sends comprehensive IEs to ensure compatibility:

UE Identity & Location:

  • IMSI (Type 1): International Mobile Subscriber Identity
  • MSISDN (Type 76): Phone number
  • MEI (Type 75): Mobile Equipment Identity (IMEI)
  • ULI (Type 86): User Location Information (TAI + ECGI)
  • UE Time Zone (Type 114): Time zone and DST adjustment

Network Information:

  • Serving Network (Type 83): MCC/MNC (PLMN)
  • RAT Type (Type 82): Radio Access Technology (E-UTRAN)

Session Configuration:

  • APN (Type 71): Access Point Name
  • PDN Type (Type 99): IPv4/IPv6/IPv4v6
  • PAA (Type 79): PDN Address Allocation request
  • PCO (Type 78): Protocol Configuration Options
    • DNS Server IPv4 Address Request
    • IP address allocation via NAS signaling
    • P-CSCF IPv4 Address Request (for IMS)
  • Selection Mode (Type 128): APN selection method
  • APN Restriction (Type 127): APN usage restrictions
  • AMBR (Type 72): Aggregate Maximum Bit Rate

Bearer Context:

  • EPS Bearer ID (Type 73): Bearer identifier
  • Bearer QoS (Type 80): QoS parameters (QCI, bit rates)
  • F-TEID (Type 87): Fully Qualified TEIDs for control and user plane

What is PCO (Protocol Configuration Options)?

PCO (IE Type 78) is used by the UE to request network configuration from the PGW:

Purpose:

  • Request DNS server addresses (Primary and Secondary)
  • Request P-CSCF (Proxy Call Session Control Function) addresses for IMS/VoLTE
  • Negotiate IP address allocation methods
  • Request other protocol-specific configurations

What the simulator requests:

Configuration Protocol: 0x80 (PPP for 3GPP)
├─ 0x000D: DNS Server IPv4 Address Request (Primary)
├─ 0x000D: DNS Server IPv4 Address Request (Secondary)
├─ 0x000A: IP address allocation via NAS signaling
├─ 0x0005: IP address allocation via NAS (alternative)
└─ 0x0001: P-CSCF IPv4 Address Request (for IMS)

PGW Response: The PGW should respond with PCO containing:

  • Assigned DNS server IP addresses
  • P-CSCF server addresses (if IMS APN)
  • Other requested configuration parameters

Disclaimer

I created this script because I couldn’t find a simple out-of-the-box solution. It works perfectly for testing the Open5GS SMF.

License

This project is licensed under the MIT License (free to use by anyone, including commercial and private use).

About

A lightweight Python-based SGW (Serving Gateway) simulator that connects to a PGW (PDN Gateway) using the GTP-C v2 protocol.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors