|
@ -7,6 +7,8 @@ using LTEMvcApp.Models; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
using System.IO; |
|
|
|
|
|
using System.Text.Json; |
|
|
|
|
|
|
|
|
namespace LTEMvcApp.Services |
|
|
namespace LTEMvcApp.Services |
|
|
{ |
|
|
{ |
|
@ -25,6 +27,7 @@ namespace LTEMvcApp.Services |
|
|
private ClientConfig _testClientConfig; |
|
|
private ClientConfig _testClientConfig; |
|
|
private const int LogCacheSize = 10000; // 服务器最多缓存10000条最新日志
|
|
|
private const int LogCacheSize = 10000; // 服务器最多缓存10000条最新日志
|
|
|
private readonly ConcurrentQueue<LTELog> _logCache = new ConcurrentQueue<LTELog>(); |
|
|
private readonly ConcurrentQueue<LTELog> _logCache = new ConcurrentQueue<LTELog>(); |
|
|
|
|
|
private readonly string _configFilePath = "test_client_config.json"; |
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
@ -65,41 +68,87 @@ namespace LTEMvcApp.Services |
|
|
_logger = logger; |
|
|
_logger = logger; |
|
|
_serviceProvider = serviceProvider; |
|
|
_serviceProvider = serviceProvider; |
|
|
|
|
|
|
|
|
// 初始化测试客户端配置
|
|
|
LoadTestClientConfig(); |
|
|
_testClientConfig = new ClientConfig |
|
|
|
|
|
|
|
|
_logger.LogInformation("WebSocketManagerService 初始化"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载测试客户端配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void LoadTestClientConfig() |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
if (File.Exists(_configFilePath)) |
|
|
|
|
|
{ |
|
|
|
|
|
var json = File.ReadAllText(_configFilePath); |
|
|
|
|
|
_testClientConfig = JsonSerializer.Deserialize<ClientConfig>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })!; |
|
|
|
|
|
_logger.LogInformation("成功从 {FilePath} 加载测试客户端配置。", _configFilePath); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogWarning("配置文件 {FilePath} 未找到,将创建并使用默认配置。", _configFilePath); |
|
|
|
|
|
_testClientConfig = GetDefaultTestConfig(); |
|
|
|
|
|
SaveTestClientConfig(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogError(ex, "加载或创建测试客户端配置文件时出错。将使用默认配置。"); |
|
|
|
|
|
_testClientConfig = GetDefaultTestConfig(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 保存测试客户端配置到文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void SaveTestClientConfig() |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
var options = new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; |
|
|
|
|
|
var json = JsonSerializer.Serialize(_testClientConfig, options); |
|
|
|
|
|
File.WriteAllText(_configFilePath, json); |
|
|
|
|
|
_logger.LogInformation("测试客户端配置已成功保存到 {FilePath}。", _configFilePath); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
_logger.LogError(ex, "保存测试客户端配置文件失败。"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ClientConfig GetDefaultTestConfig() |
|
|
|
|
|
{ |
|
|
|
|
|
return new ClientConfig |
|
|
{ |
|
|
{ |
|
|
Name = "TestClient", |
|
|
Name = "TestClient", |
|
|
Enabled = true, |
|
|
Enabled = true, |
|
|
Address = "192.168.13.12:9001", |
|
|
Address = "192.168.13.12:9001", |
|
|
Ssl = false, |
|
|
Ssl = false, |
|
|
ReconnectDelay = 15000, |
|
|
ReconnectDelay = 15000, |
|
|
Pause = false, |
|
|
Password = "test123", |
|
|
Readonly = false, |
|
|
|
|
|
SkipLogMenu = false, |
|
|
|
|
|
Locked = false, |
|
|
|
|
|
Active = true, |
|
|
|
|
|
Logs = new Dictionary<string, object> |
|
|
Logs = new Dictionary<string, object> |
|
|
{ |
|
|
{ |
|
|
["layers"] = new Dictionary<string, object> |
|
|
["layers"] = new Dictionary<string, object> |
|
|
{ |
|
|
{ |
|
|
["PHY"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = true, ["filter"] = "info" }, |
|
|
["PHY"] = new LogLayerConfig { Level = "info", Filter = "warn", MaxSize = 1000, Payload = true }, |
|
|
["MAC"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = true, ["filter"] = "info" }, |
|
|
["MAC"] = new LogLayerConfig { Level = "info", Filter = "warn", MaxSize = 1000, Payload = true }, |
|
|
["RLC"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = false, ["filter"] = "info" }, |
|
|
["RLC"] = new LogLayerConfig { Level = "info", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["PDCP"] = new Dictionary<string, object> { ["level"] = "warn", ["max_size"] = 1, ["payload"] = false, ["filter"] = "warn" }, |
|
|
["PDCP"] = new LogLayerConfig { Level = "warn", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["RRC"] = new Dictionary<string, object> { ["level"] = "debug", ["max_size"] = 1, ["payload"] = true, ["filter"] = "debug" }, |
|
|
["RRC"] = new LogLayerConfig { Level = "debug", Filter = "warn", MaxSize = 1000, Payload = true }, |
|
|
["NAS"] = new Dictionary<string, object> { ["level"] = "debug", ["max_size"] = 1, ["payload"] = true, ["filter"] = "debug" }, |
|
|
["NAS"] = new LogLayerConfig { Level = "debug", Filter = "warn", MaxSize = 1000, Payload = true }, |
|
|
["S1AP"] = new Dictionary<string, object> { ["level"] = "debug", ["max_size"] = 1, ["payload"] = false, ["filter"] = "debug" }, |
|
|
["S1AP"] = new LogLayerConfig { Level = "debug", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["NGAP"] = new Dictionary<string, object> { ["level"] = "debug", ["max_size"] = 1, ["payload"] = false, ["filter"] = "debug" }, |
|
|
["NGAP"] = new LogLayerConfig { Level = "debug", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["GTPU"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = false, ["filter"] = "info" }, |
|
|
["GTPU"] = new LogLayerConfig { Level = "info", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["X2AP"] = new Dictionary<string, object> { ["level"] = "debug", ["max_size"] = 1, ["payload"] = false, ["filter"] = "debug" }, |
|
|
["X2AP"] = new LogLayerConfig { Level = "debug", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["XnAP"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = false, ["filter"] = "info" }, |
|
|
["XnAP"] = new LogLayerConfig { Level = "info", Filter = "warn", MaxSize = 1000, Payload = false }, |
|
|
["M2AP"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = false, ["filter"] = "info" }, |
|
|
["M2AP"] = new LogLayerConfig { Level = "info", Filter = "warn", MaxSize = 1000, Payload = false } |
|
|
["EVENT"] = new Dictionary<string, object> { ["level"] = "info", ["max_size"] = 1, ["payload"] = false, ["filter"] = "info" } |
|
|
}, |
|
|
} |
|
|
["signal"] = true, |
|
|
|
|
|
["cch"] = true |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
_logger.LogInformation("WebSocketManagerService 初始化"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
@ -408,6 +457,7 @@ namespace LTEMvcApp.Services |
|
|
|
|
|
|
|
|
_logger.LogInformation($"更新测试客户端配置: {config.Name}"); |
|
|
_logger.LogInformation($"更新测试客户端配置: {config.Name}"); |
|
|
_testClientConfig = config; |
|
|
_testClientConfig = config; |
|
|
|
|
|
SaveTestClientConfig(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|