Collection of examples demonstrating various aspects of the Diameter Gateway client.
Complexity: ⭐ Beginner
Minimal example showing:
- Connection pool creation
- State monitoring
- Basic statistics
Best for: Understanding the basics
cd simple_pool
go run main.goComplexity: ⭐⭐⭐ Production
Complete S13 gateway implementation with:
- Full connection pool setup
- S13 message handling (ECR/ECA)
- Statistics reporting
- Graceful shutdown
- Signal handling
Best for: Production deployment reference
cd s13_client
go build -o s13-gateway main.go
./s13-gatewayComplexity: ⭐ Legacy
Legacy examples predating the client package:
- Simple CER/CEA handshake
- Low-level protocol operations
Best for: Understanding protocol fundamentals
cd basic
go run simple_cer_cea.goAll examples can run without a real DRA server to demonstrate:
- Connection retry behavior
- Reconnection logic
- Error handling
- State management
-
Update the configuration in each example:
config.Host = "your-dra-host.example.com" config.Port = 3868 config.OriginHost = "your-gateway.example.com" config.OriginRealm = "your-realm.com"
-
Run the example:
go run main.go
Recommended learning path:
simple_pool → s13_client → Production
(Learn basics) (Learn features) (Deploy)
| Feature | simple_pool | s13_client | basic |
|---|---|---|---|
| Connection Pool | ✓ | ✓ | ✗ |
| CER/CEA | ✓ | ✓ | ✓ |
| DWR/DWA | ✓ | ✓ | ✗ |
| Auto-reconnect | ✓ | ✓ | ✗ |
| Load Balancing | ✓ | ✓ | ✗ |
| S13 Messages | ✗ | ✓ | ✗ |
| Statistics | ✓ | ✓ | ✗ |
| Graceful Shutdown | ✓ | ✓ | ✗ |
| Signal Handling | ✗ | ✓ | ✗ |
All examples use similar configuration:
config := client.DefaultConfig()
config.Host = "127.0.0.1" // DRA address
config.Port = 3868 // Diameter port
config.OriginHost = "gateway.example.com"
config.OriginRealm = "example.com"
config.ConnectionCount = 5 // Connection pool size
config.DWRInterval = 30 * time.Second // Heartbeat interval# Start example
go run simple_pool/main.go
# While running, stop/start your DRA to see reconnection# Send multiple messages and watch them distribute
# across connections (see s13_client example)# Press Ctrl+C and observe clean shutdown
go run s13_client/main.go
^C# From examples directory
go build -o bin/simple-pool simple_pool/main.go
go build -o bin/s13-gateway s13_client/main.gogo build -ldflags="-s -w" -o s13-gateway s13_client/main.go- DRA server not running
- Wrong host/port
- Firewall blocking
Solution: Examples work without DRA to show retry behavior
- All connections failed to establish
- DRA rejecting connections
- Network issues
Solution: Check DRA logs and network connectivity
- Too many reconnection attempts
- Increase
ReconnectInterval
Solution: Adjust backoff settings in config
- Client Package Documentation
- Design Document
- Implementation Summary
- RFC 6733: Diameter Base Protocol
- 3GPP TS 29.272: S13 Interface
To add a new example:
- Create a new directory:
examples/my_example/ - Add
main.goandREADME.md - Update this main README
- Ensure it builds and runs
- Document what it demonstrates
Part of the Diameter Gateway project.