Skip to content

Session Management

Overview

Session management is a fundamental component of the TelcoAPI policy control system. This document outlines the session management architecture, implementation details, and best practices for handling subscriber sessions.

Session Types

Policy Sessions

  • Gx sessions for policy control
  • Rx sessions for application functions
  • Session correlation and binding

Charging Sessions

  • Online charging sessions (Ro)
  • Offline charging sessions (Rf)
  • Rating and charging control

Implementation

interface Session {
  id: string;
  subscriberId: string;
  type: 'GX' | 'RX' | 'RO' | 'RF';
  status: 'ACTIVE' | 'SUSPENDED' | 'TERMINATED';
  startTime: string;
  endTime?: string;
  ipCanType: 'THREE_GPP_GPRS' | 'THREE_GPP_EPS' | 'NON_THREE_GPP_WIFI';
  accessInfo: {
    ratType: string;
    anGwAddress: string;
    userLocationInfo?: string;
    userEquipmentInfo?: string;
  };
  qosInfo?: {
    profileId: string;
    rules: string[];
  };
  chargingInfo?: {
    ratingGroup: number;
    serviceIdentifier?: number;
    reportingLevel: 'RATING_GROUP' | 'SERVICE_IDENTIFIER';
  };
}

interface SessionBinding {
  id: string;
  gxSessionId: string;
  rxSessionIds: string[];
  ipAddress: string;
  bindingType: 'IP_CAN_SESSION' | 'GATEWAY';
  createdAt: string;
  updatedAt: string;
}

Session Lifecycle

Establishment

  1. Session request validation
  2. Resource allocation
  3. Policy installation
  4. Charging initialization

Modification

  1. Update triggers
  2. QoS modification
  3. Charging updates
  4. Event notification

Termination

  1. Resource release
  2. Policy removal
  3. Final charging report
  4. Session cleanup

Error Handling

enum SessionError {
  INITIALIZATION_FAILED = 'INITIALIZATION_FAILED',
  RESOURCE_EXHAUSTED = 'RESOURCE_EXHAUSTED',
  BINDING_FAILED = 'BINDING_FAILED',
  POLICY_INSTALLATION_FAILED = 'POLICY_INSTALLATION_FAILED',
  CHARGING_ERROR = 'CHARGING_ERROR'
}

interface SessionErrorResponse {
  error: SessionError;
  message: string;
  sessionId: string;
  subscriberId: string;
  timestamp: string;
  details?: {
    failedOperation: string;
    resourceState?: string;
    policyRules?: string[];
  };
}

Session Storage

interface SessionStore {
  async create(session: Session): Promise<void>;
  async get(sessionId: string): Promise<Session | null>;
  async update(sessionId: string, updates: Partial<Session>): Promise<void>;
  async delete(sessionId: string): Promise<void>;
  async listBySubscriber(subscriberId: string): Promise<Session[]>;
  async listActive(): Promise<Session[]>;
}

class CloudflareSessionStore implements SessionStore {
  constructor(private db: D1Database, private cache: KVNamespace) {}

  async create(session: Session): Promise<void> {
    // Store in database
    await this.db.prepare(
      'INSERT INTO sessions (id, subscriber_id, type, status, data) VALUES (?, ?, ?, ?, ?)'
    ).bind(session.id, session.subscriberId, session.type, session.status, JSON.stringify(session))
     .run();

    // Cache the session
    await this.cache.put(`session:${session.id}`, JSON.stringify(session), {
      expirationTtl: 3600 // 1 hour
    });
  }

  // ... other method implementations
}

Monitoring

Key Metrics

  • Active sessions count
  • Session establishment rate
  • Session duration distribution
  • Error rates by type
  • Resource utilization

Performance Indicators

  • Session setup latency
  • Policy installation time
  • Charging response time
  • Cache hit ratio

Best Practices

  1. Session Management
  2. Implement session timeouts
  3. Handle network failures gracefully
  4. Maintain session state consistency
  5. Use appropriate cache TTLs

  6. Resource Optimization

  7. Implement session cleanup
  8. Monitor resource usage
  9. Use efficient storage patterns
  10. Optimize cache usage

  11. Error Recovery

  12. Implement retry mechanisms
  13. Handle partial failures
  14. Maintain session logs
  15. Regular health checks

Implementation Example

class SessionManager {
  constructor(
    private store: SessionStore,
    private policyManager: PolicyManager,
    private chargingManager: ChargingManager
  ) {}

  async createSession(request: SessionRequest): Promise<Session> {
    try {
      // Validate request
      this.validateRequest(request);

      // Create session
      const session = await this.initializeSession(request);

      // Install policies
      await this.policyManager.installPolicies(session);

      // Initialize charging
      if (session.type === 'RO' || session.type === 'RF') {
        await this.chargingManager.initializeCharging(session);
      }

      // Store session
      await this.store.create(session);

      return session;
    } catch (error) {
      throw this.handleError(error);
    }
  }

  async updateSession(sessionId: string, updates: SessionUpdates): Promise<void> {
    const session = await this.store.get(sessionId);
    if (!session) {
      throw new Error('Session not found');
    }

    // Apply updates
    const updatedSession = { ...session, ...updates };

    // Update policies if needed
    if (updates.qosInfo) {
      await this.policyManager.updatePolicies(sessionId, updates.qosInfo);
    }

    // Update charging if needed
    if (updates.chargingInfo) {
      await this.chargingManager.updateCharging(sessionId, updates.chargingInfo);
    }

    // Store updates
    await this.store.update(sessionId, updatedSession);
  }

  async terminateSession(sessionId: string): Promise<void> {
    const session = await this.store.get(sessionId);
    if (!session) {
      throw new Error('Session not found');
    }

    // Remove policies
    await this.policyManager.removePolicies(sessionId);

    // Finalize charging
    if (session.type === 'RO' || session.type === 'RF') {
      await this.chargingManager.finalizeCharging(sessionId);
    }

    // Update session status
    await this.store.update(sessionId, {
      status: 'TERMINATED',
      endTime: new Date().toISOString()
    });

    // Cleanup after grace period
    setTimeout(() => this.store.delete(sessionId), 3600000); // 1 hour
  }
}

References

  1. 3GPP TS 23.203: Policy and charging control architecture
  2. 3GPP TS 29.212: Policy and Charging Control over Gx reference point
  3. 3GPP TS 29.214: Policy and Charging Control over Rx reference point
  4. 3GPP TS 32.240: Charging architecture and principles