|
| 1 | +namespace sigtran.net.Layers.SCTP; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes an opt-in native SCTP lab profile. |
| 5 | +/// </summary> |
| 6 | +public sealed class NativeSctpLabProfile |
| 7 | +{ |
| 8 | + /// <summary>The environment variable that enables native SCTP lab tests.</summary> |
| 9 | + public const string EnableEnvironmentVariable = "SIGTRAN_NATIVE_SCTP_LAB"; |
| 10 | + |
| 11 | + /// <summary>Creates a native SCTP lab profile.</summary> |
| 12 | + /// <param name="enabled">Whether the profile is enabled.</param> |
| 13 | + /// <param name="loopbackEndpoint">The loopback SCTP endpoint.</param> |
| 14 | + /// <param name="requiresExternalPeer">Whether an external peer is required.</param> |
| 15 | + public NativeSctpLabProfile(bool enabled, SctpEndpoint loopbackEndpoint, bool requiresExternalPeer) |
| 16 | + { |
| 17 | + Enabled = enabled; |
| 18 | + LoopbackEndpoint = loopbackEndpoint ?? throw new ArgumentNullException(nameof(loopbackEndpoint)); |
| 19 | + RequiresExternalPeer = requiresExternalPeer; |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary>Whether the profile is enabled.</summary> |
| 23 | + public bool Enabled { get; } |
| 24 | + |
| 25 | + /// <summary>The loopback SCTP endpoint.</summary> |
| 26 | + public SctpEndpoint LoopbackEndpoint { get; } |
| 27 | + |
| 28 | + /// <summary>Whether an external peer is required.</summary> |
| 29 | + public bool RequiresExternalPeer { get; } |
| 30 | + |
| 31 | + /// <summary>Formats a compact lab profile summary.</summary> |
| 32 | + /// <returns>The lab profile summary.</returns> |
| 33 | + public string Describe() |
| 34 | + { |
| 35 | + return $"enabled={Enabled} loopback={LoopbackEndpoint} externalPeer={RequiresExternalPeer}"; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +/// <summary> |
| 40 | +/// Provides native SCTP lab profile helpers. |
| 41 | +/// </summary> |
| 42 | +public static class NativeSctpLab |
| 43 | +{ |
| 44 | + /// <summary>Creates the current native SCTP lab profile from environment variables.</summary> |
| 45 | + /// <returns>The native SCTP lab profile.</returns> |
| 46 | + public static NativeSctpLabProfile CreateFromEnvironment() |
| 47 | + { |
| 48 | + bool enabled = string.Equals( |
| 49 | + Environment.GetEnvironmentVariable(NativeSctpLabProfile.EnableEnvironmentVariable), |
| 50 | + "1", |
| 51 | + StringComparison.Ordinal); |
| 52 | + |
| 53 | + return new( |
| 54 | + enabled, |
| 55 | + new SctpEndpoint("127.0.0.1", 2905), |
| 56 | + requiresExternalPeer: false); |
| 57 | + } |
| 58 | +} |
0 commit comments