|
| 1 | +# Phase 47 M3UA Runtime |
| 2 | + |
| 3 | +## Objective |
| 4 | + |
| 5 | +Provide a long-running M3UA ASP service that upper layers can consume through |
| 6 | +`IMtp3Network` without coordinating transport reads, ASP handshakes, heartbeat |
| 7 | +responses, reconnects, or queue pressure themselves. |
| 8 | + |
| 9 | +## Runtime API |
| 10 | + |
| 11 | +`M3uaRuntime` implements `IMtp3Network` and owns: |
| 12 | + |
| 13 | +- ASP Up and ASP Active startup. |
| 14 | +- ASP Inactive and ASP Down graceful shutdown sends. |
| 15 | +- A single inbound M3UA receive loop. |
| 16 | +- Bounded inbound and outbound MTP3 transfer channels. |
| 17 | +- Automatic response to peer heartbeats. |
| 18 | +- Correlated heartbeat supervision with timeout handling. |
| 19 | +- Session replacement and failover through `IM3uaRuntimeSessionFactory`. |
| 20 | +- Reconnect backoff through `SctpReconnectPolicy`. |
| 21 | +- Runtime lifecycle, traffic, heartbeat, reconnect, shutdown, and fault events. |
| 22 | +- Queue, transfer, heartbeat, reconnect, and fault metrics. |
| 23 | +- Cancellation for startup, traffic waits, reconnect delays, and shutdown. |
| 24 | + |
| 25 | +## Session Factory |
| 26 | + |
| 27 | +`IM3uaRuntimeSessionFactory.OpenAsync` returns an |
| 28 | +`M3uaRuntimeSessionLease`. The factory owns endpoint selection and can rotate |
| 29 | +between primary and secondary associations after a fault. |
| 30 | + |
| 31 | +The returned `M3uaTransportSession` should share one `M3uaAspSession` between its |
| 32 | +inbound and outbound processors. Production payload policy should require an |
| 33 | +active ASP. |
| 34 | + |
| 35 | +```csharp |
| 36 | +M3uaAspSession aspSession = new(); |
| 37 | +M3uaInboundProcessor inbound = new( |
| 38 | + aspSession, |
| 39 | + requireActiveAspForPayload: true); |
| 40 | +M3uaOutboundProcessor outbound = new( |
| 41 | + aspSession, |
| 42 | + networkAppearance: 7, |
| 43 | + routingContext: 100, |
| 44 | + requireActiveAspForPayload: true); |
| 45 | + |
| 46 | +IM3uaRuntimeSessionFactory factory = new M3uaDelegateRuntimeSessionFactory( |
| 47 | + async ct => |
| 48 | + { |
| 49 | + ISctpTransport transport = await OpenSctpTransportAsync(ct); |
| 50 | + M3uaTransportSession session = new( |
| 51 | + transport, |
| 52 | + inbound, |
| 53 | + outbound); |
| 54 | + return new M3uaRuntimeSessionLease("primary-sg", session); |
| 55 | + }); |
| 56 | + |
| 57 | +await using M3uaRuntime runtime = new( |
| 58 | + factory, |
| 59 | + new M3uaRuntimeOptions( |
| 60 | + startupOptions: new M3uaAspStartupOptions( |
| 61 | + aspIdentifier: 42, |
| 62 | + trafficModeType: M3uaTrafficModeType.Loadshare))); |
| 63 | + |
| 64 | +await runtime.StartAsync(); |
| 65 | +IMtp3Network network = runtime; |
| 66 | +``` |
| 67 | + |
| 68 | +The session factory delegate should create new processor instances for each |
| 69 | +replacement session when reconnect and failover are enabled. |
| 70 | + |
| 71 | +## Backpressure |
| 72 | + |
| 73 | +Both runtime channels use `BoundedChannelFullMode.Wait`. Producers are suspended |
| 74 | +when the outbound queue is full and the receiver loop is suspended when an upper |
| 75 | +layer does not drain the inbound queue. Both waits honor caller cancellation. |
| 76 | + |
| 77 | +`M3uaRuntimeMetrics` reports both queue depths so operators can alert before |
| 78 | +traffic latency becomes unacceptable. |
| 79 | + |
| 80 | +## Heartbeats |
| 81 | + |
| 82 | +Only the runtime receive loop reads M3UA messages. Heartbeat requests carry a |
| 83 | +monotonic 64-bit token, and the receive loop correlates the echoed |
| 84 | +`Heartbeat Ack`. A timeout faults the active session and activates the reconnect |
| 85 | +policy. |
| 86 | + |
| 87 | +Inbound peer heartbeats are acknowledged automatically. |
| 88 | + |
| 89 | +## Completion Criteria |
| 90 | + |
| 91 | +Phase 47 is complete because: |
| 92 | + |
| 93 | +- The runtime implements `IMtp3Network`. |
| 94 | +- ASP activation, heartbeat supervision, traffic, and shutdown are covered by an |
| 95 | + executable loopback test. |
| 96 | +- Queue pressure, events, and metrics are public and documented. |
| 97 | +- Reconnect/failover is delegated through a replaceable session factory. |
| 98 | +- Product readiness no longer reports the M3UA runtime implementation blocker. |
| 99 | +- Build, tests, and package validation pass. |
| 100 | + |
0 commit comments