Browse Source

1111232

feature/LteClientLogFun
hyh 1 month ago
parent
commit
d8794dd24e
  1. 91
      LTEMvcApp/Models/LogLayerConfig.cs
  2. 69
      LTEMvcApp/Models/LogsManager.cs

91
LTEMvcApp/Models/LogLayerConfig.cs

@ -76,6 +76,12 @@ namespace LTEMvcApp.Models
/// </summary>
public static class LogLayerTypes
{
// 方向值缓存,避免重复计算
private static readonly Dictionary<int, string[]> _directionCache = new();
// 层配置缓存,避免重复创建字典
private static readonly Dictionary<string, LogLayerConfig> _layerConfigsCache = new();
public const string PHY = "PHY";
public const string MAC = "MAC";
public const string RLC = "RLC";
@ -173,7 +179,14 @@ namespace LTEMvcApp.Models
/// <returns>层配置字典</returns>
public static Dictionary<string, LogLayerConfig> GetLayerConfigs()
{
return new Dictionary<string, LogLayerConfig>
// 如果缓存已存在,直接返回
if (_layerConfigsCache.Count > 0)
{
return _layerConfigsCache;
}
// 初始化层配置
var configs = new Dictionary<string, LogLayerConfig>
{
[PHY] = new() { Color = "#606070", Direction = new() { ["UE"] = 2, ["PROBE"] = 3, ["ENB"] = 1 }, Debug = new() { Level = "debug", MaxSize = 1 } },
[MAC] = new() { Color = "#10A0FF", Direction = new() { ["UE"] = 2, ["PROBE"] = 3, ["ENB"] = 1 }, Debug = new() { Level = "debug", MaxSize = 1 } },
@ -225,6 +238,14 @@ namespace LTEMvcApp.Models
[OTS] = new() { Color = "#8080FF", Direction = new() { } },
[ERROR] = new() { Color = "#ff0000", Direction = new() { } }
};
// 缓存配置
foreach (var kvp in configs)
{
_layerConfigsCache[kvp.Key] = kvp.Value;
}
return _layerConfigsCache;
}
/// <summary>
@ -238,6 +259,57 @@ namespace LTEMvcApp.Models
return configs.TryGetValue(layerName, out var config) ? config : null;
}
/// <summary>
/// 根据方向值获取匹配的层名称数组
/// </summary>
/// <param name="directionValue">方向值</param>
/// <returns>包含指定方向值的层名称数组</returns>
public static string[] GetLayersByDirectionValue(int directionValue)
{
// 使用静态缓存避免重复创建字典
var configs = GetLayerConfigs();
return configs
.Where(kvp => kvp.Value.Direction.ContainsValue(directionValue))
.Select(kvp => kvp.Key)
.ToArray();
}
/// <summary>
/// 根据方向值获取匹配的层名称数组(带缓存版本)
/// </summary>
/// <param name="directionValue">方向值</param>
/// <returns>包含指定方向值的层名称数组</returns>
public static string[] GetLayersByDirectionValueCached(int directionValue)
{
// 使用静态字典缓存结果,避免重复计算
if (_directionCache.TryGetValue(directionValue, out var cachedResult))
{
return cachedResult;
}
var configs = GetLayerConfigs();
var result = configs
.Where(kvp => kvp.Value.Direction.ContainsValue(directionValue))
.Select(kvp => kvp.Key)
.ToArray();
_directionCache[directionValue] = result;
return result;
}
/// <summary>
/// 获取所有可用的方向值
/// </summary>
/// <returns>所有方向值的集合</returns>
public static HashSet<int> GetAllDirectionValues()
{
var configs = GetLayerConfigs();
return configs
.SelectMany(kvp => kvp.Value.Direction.Values)
.ToHashSet();
}
/// <summary>
/// 验证层名称是否有效
/// </summary>
@ -247,5 +319,22 @@ namespace LTEMvcApp.Models
{
return AllLayers.Contains(layerName);
}
/// <summary>
/// 清除所有缓存
/// </summary>
public static void ClearCache()
{
_layerConfigsCache.Clear();
_directionCache.Clear();
}
/// <summary>
/// 清除方向值缓存
/// </summary>
public static void ClearDirectionCache()
{
_directionCache.Clear();
}
}
}

69
LTEMvcApp/Models/LogsManager.cs

@ -40,59 +40,6 @@ namespace LTEMvcApp.Models
{ "LICENSE", new { icon = "icon-file" } }
};
private static readonly Dictionary<string, object> layerConfig = new()
{
{ "PHY", new { color = "#606070", dir = new Dictionary<string, int> { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "MAC", new { color = "#10A0FF", dir = new Dictionary<string, int> { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "RLC", new { color = "#FFFF80", dir = new Dictionary<string, int> { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } } } },
{ "PDCP", new { color = "#B0D0B0", dir = new Dictionary<string, int> { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } } } },
{ "RRC", new { color = "#00FF60", dir = new Dictionary<string, int> { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "NAS", new { color = "#90FFC0", dir = new Dictionary<string, int> { { "UE", 2 }, { "PROBE", 3 }, { "ENB", 3 }, { "N3IWF", 3 }, { "MME", 1 } }, debug = new { level = "debug", max_size = 1 } } },
{ "GTPU", new { color = "#FF80FF", dir = new Dictionary<string, int> { { "ENB", 2 }, { "N3IWF", 2 }, { "MME", 1 }, { "MBMSGW", 1 }, { "UE", 1 }, { "RUE", 2 } }, epc = true, max = new { max_size = 32 } } },
{ "GTPC", new { color = "#FFC0FF", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "IP", new { color = "#E0E0E0", dir = new Dictionary<string, int> { { "RUE", 2 }, { "UE", 2 }, { "N3IWF", 3 }, { "PROBE", 3 }, { "MME", 3 } }, max = new { max_size = 32 } } },
{ "S1AP", new { color = "#80FF00", dir = new Dictionary<string, int> { { "ENB", 2 }, { "MME", 1 } }, epc = true, debug = new { level = "debug", max_size = 1 } } },
{ "NGAP", new { color = "#5DD122", dir = new Dictionary<string, int> { { "ENB", 2 }, { "MME", 1 }, { "N3IWF", 2 } }, epc = true, debug = new { level = "debug", max_size = 1 } } },
{ "X2AP", new { color = "#FF8000", dir = new Dictionary<string, int> { { "ENB", 2 } } } },
{ "XnAP", new { color = "#FFB020", dir = new Dictionary<string, int> { { "ENB", 2 } } } },
{ "M2AP", new { color = "#7F675B", dir = new Dictionary<string, int> { { "ENB", 2 }, { "MBMSGW", 1 } }, epc = true } },
{ "IMS", new { color = "#C0FF80", dir = new Dictionary<string, int> { { "MME", 2 }, { "IMS", 1 } }, debug = new { level = "debug", max_size = 1 }, epc = true } },
{ "CX", new { color = "#F49542", dir = new Dictionary<string, int> { { "MME", 2 }, { "IMS", 1 } }, epc = true } },
{ "RX", new { color = "#D4A190", dir = new Dictionary<string, int> { { "MME", 2 }, { "IMS", 1 } }, epc = true } },
{ "COM", new { color = "#C000FF", dir = new Dictionary<string, int> { { "*", 2 } } } },
{ "SIP", new { color = "#C080FF", dir = new Dictionary<string, int> { { "IMS", 1 } }, epc = true, debug = new { level = "debug", max_size = 1 } } },
{ "MEDIA", new { color = "#800040", dir = new Dictionary<string, int> { { "IMS", 1 } }, epc = true } },
{ "RTP", new { color = "#FF00C0", dir = new Dictionary<string, int> { { "IMS", 1 } }, epc = true } },
{ "PROD", new { color = "#80C0FF", dir = new Dictionary<string, int> { } } },
{ "S6", new { color = "#F44B42", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "S13", new { color = "#D6F953", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "SGsAP", new { color = "#FF7DB8", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "SBcAP", new { color = "#8FA00F", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "N8", new { color = "#106020", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "N12", new { color = "#602020", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "N13", new { color = "#202060", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "N17", new { color = "#D6F953", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "N50", new { color = "#8FA00F", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "MMS", new { color = "#B4D98F", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "HTTP2", new { color = "#644824", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "LCSAP", new { color = "#cfd50d", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "LPPa", new { color = "#0dcfd5", dir = new Dictionary<string, int> { { "ENB", 2 }, { "MME", 3 } }, epc = true } },
{ "NL1", new { color = "#d040cf", dir = new Dictionary<string, int> { { "MME", 2 } }, epc = true } },
{ "NRPPa", new { color = "#0dd5cf", dir = new Dictionary<string, int> { { "ENB", 2 }, { "MME", 3 } }, epc = true } },
{ "IKEV2", new { color = "#C0B732", dir = new Dictionary<string, int> { { "UE", 2 }, { "MME", 1 }, { "N3IWF", 1 } } } },
{ "SWU", new { color = "#101080", dir = new Dictionary<string, int> { { "UE", 2 }, { "MME", 1 } } } },
{ "NWU", new { color = "#2080B8", dir = new Dictionary<string, int> { { "UE", 2 }, { "MME", 1 } } } },
{ "IPSEC", new { color = "#F04010", dir = new Dictionary<string, int> { { "UE", 2 }, { "IMS", 1 }, { "N3IWF", 1 }, { "MME", 1 } }, epc = true, max = new { max_size = 32 } } },
{ "N3IWF", new { color = "#C080C0", dir = new Dictionary<string, int> { { "UE", 2 }, { "N3IWF", 1 } } } },
{ "TRX", new { color = "#42C0a0", dir = new Dictionary<string, int> { { "UE", 2 }, { "ENB", 1 } }, debug = new { level = "debug" } } },
{ "MON", new { color = "#C0C080", dir = new Dictionary<string, int> { } } },
{ "EVENT", new { color = "#80C0FF", dir = new Dictionary<string, int> { } } },
{ "ALARM", new { color = "#FF8040", dir = new Dictionary<string, int> { } } },
{ "LIC", new { color = "#ff80c0", dir = new Dictionary<string, int> { { "LICENSE", 1 } } } },
{ "OTS", new { color = "#8080FF", dir = new Dictionary<string, int> { } } },
{ "ERROR", new { color = "#ff0000", dir = new Dictionary<string, int> { } } }
};
#endregion
#region 实例字段
@ -900,7 +847,21 @@ namespace LTEMvcApp.Models
/// <returns>层配置字典</returns>
public Dictionary<string, object> GetLayerConfig()
{
return layerConfig;
var configs= LogLayerTypes.GetLayerConfigs();
var result = new Dictionary<string, object>();
foreach (var kvp in configs)
{
var config = kvp.Value;
result[kvp.Key] = new
{
color = config.Color,
dir = config.Direction,
debug = config.Debug != null ? new { level = config.Debug.Level, max_size = config.Debug.MaxSize } : null,
epc = config.EPC,
max = config.Max != null ? new { max_size = config.Max.MaxSize } : null
};
}
return result;
}
#endregion

Loading…
Cancel
Save