A production-grade Equipment Identity Register (EIR) system implemented in Go following hexagonal (clean) architecture principles.
This EIR system provides:
- Diameter S13 Interface (4G LTE) - ME-Identity-Check operations
- HTTP N5g-eir Interface (5G) - Equipment status query API (3GPP TS 29.511)
- PostgreSQL Storage - Persistent equipment database with audit logging
- Hexagonal Architecture - Clean separation of domain, ports, and adapters
- Production-Ready - Observability, metrics, health checks, and graceful shutdown
┌─────────────────────────────────────────────────────────────┐
│ Adapters (Infrastructure) │
├──────────────────┬──────────────────┬───────────────────────┤
│ Diameter S13 │ HTTP (5G) │ PostgreSQL │
│ Gateway │ Gateway │ Repository │
└────────┬─────────┴─────────┬────────┴───────────┬───────────┘
│ │ │
└───────────────────┼────────────────────┘
│
┌───────────────────▼────────────────────┐
│ Ports (Interfaces) │
│ - EIRService │
│ - IMEIRepository │
│ - AuditRepository │
└───────────────────┬────────────────────┘
│
┌───────────────────▼────────────────────┐
│ Domain Layer (Business Logic) │
│ - IMEI Validation (Luhn algorithm) │
│ - Policy Evaluation │
│ - Equipment Status Mapping │
│ - Audit Event Generation │
└────────────────────────────────────────┘
- Business logic is isolated - Domain layer has NO dependencies on infrastructure
- Dependency Inversion - Interfaces (ports) are owned by the domain
- Testability - Each layer can be tested independently
- Flexibility - Easy to swap implementations (e.g., different databases)
eir/
├── cmd/
│ └── eir/
│ └── main.go # Application entry point
├── internal/
│ ├── domain/ # Domain layer (business logic)
│ │ ├── models/ # Domain models
│ │ │ └── equipment.go # Equipment entity, IMEI validation
│ │ ├── ports/ # Interfaces (owned by domain)
│ │ │ ├── repository.go # Repository interfaces
│ │ │ └── service.go # Service interfaces
│ │ └── service/ # Business logic implementation
│ │ └── eir_service.go # Core EIR service
│ ├── adapters/ # Infrastructure adapters
│ │ ├── diameter/ # Diameter S13 adapter
│ │ │ ├── s13_handler.go # S13 message handler
│ │ │ └── server.go # Diameter server
│ │ ├── http/ # HTTP adapter (5G N5g-eir)
│ │ │ ├── handler.go # HTTP handlers
│ │ │ ├── models.go # HTTP DTOs
│ │ │ └── router.go # HTTP routes
│ │ └── postgres/ # PostgreSQL adapter
│ │ ├── db.go # Database connection
│ │ ├── imei_repository.go
│ │ ├── audit_repository.go
│ │ └── schema.sql # Database schema
│ ├── config/ # Configuration management
│ │ └── config.go
│ └── observability/ # Logging & metrics
│ ├── logger.go
│ └── metrics.go
├── config/
│ └── config.yaml # Configuration file
├── deploy/
│ └── prometheus.yml # Prometheus configuration
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yaml # Docker Compose setup
├── Makefile # Build automation
└── README.md
- Go 1.21+
- PostgreSQL 15+
- Docker & Docker Compose (optional)
# Start all services (PostgreSQL, Redis, EIR, Prometheus, Grafana) docker-compose up -d # Check logs docker-compose logs -f eir # Stop services docker-compose down
The services will be available at:
- EIR HTTP API: http://localhost:8080
- Diameter S13: localhost:3868
- Prometheus Metrics: http://localhost:9090
- Grafana Dashboard: http://localhost:3000 (admin/admin)
- Start PostgreSQL:
docker run -d \ --name eir-postgres \ -e POSTGRES_USER=eir \ -e POSTGRES_PASSWORD=eir_password \ -e POSTGRES_DB=eir \ -p 5432:5432 \ postgres:15-alpine
- Apply database schema:
make db-migrate
# Or manually:
psql -h localhost -U eir -d eir -f internal/adapters/postgres/schema.sql- Run the application:
make run
# Or:
go run cmd/eir/main.go# Build binary make build # Run tests make test # Run tests with coverage make test-coverage # Format code make fmt # Download dependencies make deps
Check Equipment Status:
curl "http://localhost:8080/n5g-eir-eic/v1/equipment-status?pei=123456789012345"Response:
{
"status": "WHITELISTED"
}Provision Equipment:
curl -X POST http://localhost:8080/api/v1/equipment \ -H "Content-Type: application/json" \ -d '{ "imei": "123456789012345", "status": "BLACKLISTED", "reason": "Reported stolen" }'
Get Equipment:
curl http://localhost:8080/api/v1/equipment/123456789012345
List Equipment:
curl "http://localhost:8080/api/v1/equipment?offset=0&limit=100"Delete Equipment:
curl -X DELETE http://localhost:8080/api/v1/equipment/123456789012345
The Diameter S13 interface listens on port 3868 and supports:
- ME-Identity-Check-Request (MICR) - Command Code 324
- ME-Identity-Check-Answer (MICA) - Returns equipment status
Example flow:
- MME sends MICR with IMEI in Terminal-Information AVP
- EIR validates IMEI and checks database
- EIR returns MICA with Equipment-Status AVP (0=WHITELISTED, 1=BLACKLISTED, 2=GREYLISTED)
- Primary storage for IMEI records
- Indexed by IMEI, status, manufacturer TAC
- Atomic check count increment via stored procedure
- Partitioned by time (quarterly partitions)
- Records all equipment check operations
- Indexed by IMEI, check_time, status
Configuration can be provided via:
- YAML file (
config/config.yaml) - Environment variables (prefixed with
EIR_)
Example environment variables:
export EIR_DATABASE_HOST=localhost export EIR_DATABASE_PORT=5432 export EIR_DATABASE_USER=eir export EIR_DATABASE_PASSWORD=eir_password export EIR_DIAMETER_ORIGINHOST=eir.example.com export EIR_LOGGING_LEVEL=debug
Prometheus metrics exposed at /metrics:
eir_equipment_check_total- Total check requests by source and statuseir_equipment_check_duration_seconds- Check latency histogrameir_database_query_duration_seconds- Database query latencyeir_cache_hit_total- Cache hit/miss countseir_active_diameter_connections- Active Diameter connections
Structured JSON logging with configurable levels:
debug,info,warn,error
curl http://localhost:8080/health
The system performs strict IMEI validation:
- Length check: 14-16 digits
- Format check: Numeric only
- Luhn algorithm: Validates check digit for 15-digit IMEIs
- TAC extraction: Extracts Type Allocation Code (first 8 digits)
Unknown equipment (not in database) is WHITELISTED by default.
This is a permissive policy. For restrictive policy, modify applyDefaultPolicy() in eir_service.go to return BLACKLISTED or GREYLISTED.
- Database credentials should be stored in secrets management (e.g., Vault, AWS Secrets Manager)
- Enable TLS for Diameter connections in production
- Enable PostgreSQL SSL mode in production
- Use authentication middleware for HTTP provisioning API
- Implement rate limiting for public APIs
Production optimizations:
- Connection pooling (PostgreSQL, Redis)
- Database indexing strategy
- Optional caching layer (Redis)
- Asynchronous audit logging
- Partitioned audit tables for scalability
# Run all tests make test # Run with coverage make test-coverage # Run specific package go test -v ./internal/domain/service/
Database connection fails:
- Check PostgreSQL is running
- Verify credentials in config
- Check network connectivity
Diameter connection fails:
- Verify port 3868 is not in use
- Check firewall rules
- Verify origin-host/realm configuration
High latency:
- Enable Redis caching
- Review database query performance
- Check connection pool settings
Copyright © 2024. All rights reserved.
This is a production system. All changes require:
- Unit tests with >80% coverage
- Integration tests for adapters
- Documentation updates
- Security review for sensitive changes
For issues and questions, contact the Telecom Core Network team.