From cdf2c85647214440a624b59ac3351de105068832 Mon Sep 17 00:00:00 2001
From: root <295172551@qq.com>
Date: Tue, 22 Jul 2025 21:44:01 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8E=9F=E5=85=88protocol?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Network/ICellularNetworkContext.cs | 5 -
.../Models/Protocol/BaseNetworkLog.cs | 55 ---
.../Models/Protocol/DirectionLogsType.cs | 34 --
.../Models/Protocol/ImsLayerLog.cs | 80 ----
CoreAgent.Domain/Models/Protocol/LogLevel.cs | 27 --
.../Models/Protocol/MobileUserIdentity.cs | 200 ----------
.../Models/Protocol/NetworkLayerLogs.cs | 54 ---
.../Models/Protocol/ProtocolLayerType.cs | 242 ------------
.../Protocol/ProtocolLayerTypeExtensions.cs | 258 -------------
.../Models/Protocol/ProtocolLog.cs | 97 -----
.../Models/Protocol/ProtocolLogDetail.cs | 76 ----
.../Protocol/ProtocolLogParsedResult.cs | 338 ----------------
.../Models/Protocol/RanLayerLog.cs | 136 -------
.../Models/Protocol/UserNetworkIdentity.cs | 219 -----------
.../Contexts/CellularNetworkContext.cs | 8 -
.../IMSLogMessageHandler.cs | 256 -------------
.../ProtocolLogsProviderObserver.cs | 147 -------
.../ProtocolMSHandleLogs.cs | 30 --
.../ProtocolMSParesHandleLogs.cs | 12 -
.../ProtocolParesHandleLogs.cs | 41 --
.../ProtocolRanHandleLogs.cs | 30 --
.../ProtocolRanParesHandleLogs.cs | 83 ----
.../RanLogMessageHandler.cs | 362 ------------------
23 files changed, 2790 deletions(-)
delete mode 100644 CoreAgent.Domain/Models/Protocol/BaseNetworkLog.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/DirectionLogsType.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/ImsLayerLog.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/LogLevel.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/MobileUserIdentity.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/NetworkLayerLogs.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/ProtocolLayerType.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/ProtocolLayerTypeExtensions.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/ProtocolLog.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/ProtocolLogDetail.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/ProtocolLogParsedResult.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/RanLayerLog.cs
delete mode 100644 CoreAgent.Domain/Models/Protocol/UserNetworkIdentity.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/IMSLogMessageHandler.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolLogsProviderObserver.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSHandleLogs.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSParesHandleLogs.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolParesHandleLogs.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanHandleLogs.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanParesHandleLogs.cs
delete mode 100644 CoreAgent.Infrastructure/Services/ProtocolLogHandlers/RanLogMessageHandler.cs
diff --git a/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs b/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
index 06145e7..7f4d63b 100644
--- a/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
+++ b/CoreAgent.Domain/Interfaces/Network/ICellularNetworkContext.cs
@@ -1,5 +1,4 @@
using CoreAgent.Domain.Models.Network;
-using CoreAgent.Domain.Models.Protocol;
using CoreAgent.Domain.Models.System;
namespace CoreAgent.Domain.Interfaces.Network;
@@ -31,10 +30,6 @@ public interface ICellularNetworkContext
///
NetworkConfigType CurrentConfigType { get; }
- ///
- /// 网络层日志配置
- ///
- NetworkLayerLogs NetworkLogs { get; }
#endregion
diff --git a/CoreAgent.Domain/Models/Protocol/BaseNetworkLog.cs b/CoreAgent.Domain/Models/Protocol/BaseNetworkLog.cs
deleted file mode 100644
index 0f2d285..0000000
--- a/CoreAgent.Domain/Models/Protocol/BaseNetworkLog.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using Newtonsoft.Json;
-using System;
-using System.Text.Json.Serialization;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 基础网络日志实体类
-/// 提供网络日志的通用属性和配置
-///
-/// 日志层类型(如ImsLayerLog或RanLayerLog)
-public class BaseNetworkLog
-{
- ///
- /// 超时时间(毫秒)
- ///
- [JsonProperty("timeout")]
- public int Timeout { get; set; }
-
- ///
- /// 最小日志数量
- ///
- [JsonProperty("min")]
- public int MinLogCount { get; set; }
-
- ///
- /// 最大日志数量
- ///
- [JsonProperty("max")]
- public int MaxLogCount { get; set; }
-
- ///
- /// 日志层配置
- ///
- [JsonProperty("layers")]
- public T LayerConfig { get; set; }
-
- ///
- /// 日志消息
- ///
- [JsonProperty("message")]
- public string Message { get; set; }
-
- ///
- /// 是否包含消息头
- ///
- [JsonProperty("headers")]
- public bool IncludeHeaders { get; set; }
-
- ///
- /// 消息ID
- ///
- [JsonProperty("message_id")]
- public int MessageId { get; set; }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/DirectionLogsType.cs b/CoreAgent.Domain/Models/Protocol/DirectionLogsType.cs
deleted file mode 100644
index 490e9e8..0000000
--- a/CoreAgent.Domain/Models/Protocol/DirectionLogsType.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 日志方向类型枚举
-/// 定义了协议日志的传输方向
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public enum DirectionLogsType
-{
- ///
- /// 未知方向
- ///
- Unknown = 0,
-
- ///
- /// 上行方向(UE到网络)
- ///
- Uplink = 1,
-
- ///
- /// 下行方向(网络到UE)
- ///
- Downlink = 2,
-
- ///
- /// 双向
- ///
- Bidirectional = 3,
-
- ///
- /// 内部处理
- ///
- Internal = 4
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/ImsLayerLog.cs b/CoreAgent.Domain/Models/Protocol/ImsLayerLog.cs
deleted file mode 100644
index f2cd466..0000000
--- a/CoreAgent.Domain/Models/Protocol/ImsLayerLog.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-using System;
-using System.Text.Json.Serialization;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// IMS层日志实体类
-/// 该实体用于记录IMS(IP多媒体子系统)相关的各层日志信息
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public class ImsLayerLog
-{
- ///
- /// CX协议层日志级别
- ///
- public string CX { get; set; }
-
- ///
- /// IMS协议层日志级别
- ///
- public string IMS { get; set; }
-
- ///
- /// IPSEC协议层日志级别
- ///
- public string IPSEC { get; set; }
-
- ///
- /// MEDIA协议层日志级别
- ///
- public string MEDIA { get; set; }
-
- ///
- /// MMS协议层日志级别
- ///
- public string MMS { get; set; }
-
- ///
- /// RX协议层日志级别
- ///
- public string RX { get; set; }
-
- ///
- /// SIP协议层日志级别
- ///
- public string SIP { get; set; }
-
- ///
- /// 初始化IMS层日志级别
- ///
- public void InitializeLogLevels()
- {
- CX = LogLevel.Warn.ToString().ToLower();
- IMS = LogLevel.Warn.ToString().ToLower();
- IPSEC = LogLevel.Warn.ToString().ToLower();
- MEDIA = LogLevel.Warn.ToString().ToLower();
- MMS = LogLevel.Warn.ToString().ToLower();
- RX = LogLevel.Warn.ToString().ToLower();
- SIP = LogLevel.Debug.ToString().ToLower();
- }
-
- ///
- /// 更新指定层的日志级别
- ///
- /// 层名称
- /// 日志级别
- /// 是否更新成功
- public bool UpdateLogLevel(string layerName, LogLevel logLevel)
- {
- if (string.IsNullOrEmpty(layerName))
- return false;
-
- var property = GetType().GetProperty(layerName);
- if (property == null)
- return false;
-
- property.SetValue(this, logLevel.ToString().ToLower());
- return true;
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/LogLevel.cs b/CoreAgent.Domain/Models/Protocol/LogLevel.cs
deleted file mode 100644
index 5a7abfd..0000000
--- a/CoreAgent.Domain/Models/Protocol/LogLevel.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 日志级别枚举
-///
-public enum LogLevel
-{
- ///
- /// 调试级别
- ///
- Debug,
-
- ///
- /// 信息级别
- ///
- Info,
-
- ///
- /// 警告级别
- ///
- Warn,
-
- ///
- /// 错误级别
- ///
- Error
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/MobileUserIdentity.cs b/CoreAgent.Domain/Models/Protocol/MobileUserIdentity.cs
deleted file mode 100644
index 7bd940d..0000000
--- a/CoreAgent.Domain/Models/Protocol/MobileUserIdentity.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-using Newtonsoft.Json;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 移动用户身份信息
-/// 用于存储移动网络用户的基本身份和位置信息
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public class MobileUserIdentity
-{
- ///
- /// 公共陆地移动网络标识
- /// Public Land Mobile Network Identifier
- ///
- [JsonProperty("plmn")]
- public string? Plmn { get; set; }
-
- ///
- /// 旧的临时移动用户标识
- /// Old Temporary Mobile Subscriber Identity
- ///
- [JsonProperty("oldTmsi")]
- public string? OldTmsi { get; set; }
-
- ///
- /// 临时移动用户标识
- /// Temporary Mobile Subscriber Identity
- ///
- [JsonProperty("tmsi")]
- public string? Tmsi { get; set; }
-
- ///
- /// 国际移动用户标识
- /// International Mobile Subscriber Identity
- ///
- [JsonProperty("imsi")]
- public string? Imsi { get; set; }
-
- ///
- /// 小区ID
- /// Cell Identifier
- ///
- [JsonProperty("cellId")]
- public int? CellId { get; set; }
-
- ///
- /// 用户设备ID
- /// User Equipment Identifier
- ///
- [JsonProperty("ueId")]
- public int? UeId { get; set; }
-
- ///
- /// 初始化移动用户身份信息的新实例
- ///
- public MobileUserIdentity()
- {
- }
-
- ///
- /// 初始化移动用户身份信息的新实例
- ///
- /// 公共陆地移动网络标识
- /// 旧的临时移动用户标识
- /// 临时移动用户标识
- /// 国际移动用户标识
- /// 小区ID
- /// 用户设备ID
- public MobileUserIdentity(
- string? plmn = null,
- string? oldTmsi = null,
- string? tmsi = null,
- string? imsi = null,
- int? cellId = null,
- int? ueId = null)
- {
- Plmn = plmn;
- OldTmsi = oldTmsi;
- Tmsi = tmsi;
- Imsi = imsi;
- CellId = cellId;
- UeId = ueId;
- }
-
- ///
- /// 检查是否包含有效的用户身份信息
- ///
- /// 是否包含有效信息
- public bool HasValidIdentity()
- {
- return !string.IsNullOrWhiteSpace(Imsi) ||
- !string.IsNullOrWhiteSpace(Tmsi) ||
- UeId.HasValue;
- }
-
- ///
- /// 检查是否包含位置信息
- ///
- /// 是否包含位置信息
- public bool HasLocationInfo()
- {
- return !string.IsNullOrWhiteSpace(Plmn) || CellId.HasValue;
- }
-
- ///
- /// 获取用户身份摘要信息
- ///
- /// 摘要信息
- public string GetIdentitySummary()
- {
- var parts = new List();
-
- if (!string.IsNullOrWhiteSpace(Imsi))
- parts.Add($"IMSI:{Imsi}");
-
- if (!string.IsNullOrWhiteSpace(Tmsi))
- parts.Add($"TMSI:{Tmsi}");
-
- if (UeId.HasValue)
- parts.Add($"UE:{UeId}");
-
- if (!string.IsNullOrWhiteSpace(Plmn))
- parts.Add($"PLMN:{Plmn}");
-
- if (CellId.HasValue)
- parts.Add($"Cell:{CellId}");
-
- return parts.Count > 0 ? string.Join(" | ", parts) : "No Identity Info";
- }
-
- ///
- /// 检查TMSI是否发生变化
- ///
- /// TMSI是否发生变化
- public bool HasTmsiChanged()
- {
- return !string.IsNullOrWhiteSpace(OldTmsi) &&
- !string.IsNullOrWhiteSpace(Tmsi) &&
- !OldTmsi.Equals(Tmsi, StringComparison.OrdinalIgnoreCase);
- }
-
- ///
- /// 创建身份信息的副本
- ///
- /// 新的移动用户身份信息
- public MobileUserIdentity Copy()
- {
- return new MobileUserIdentity
- {
- Plmn = Plmn,
- OldTmsi = OldTmsi,
- Tmsi = Tmsi,
- Imsi = Imsi,
- CellId = CellId,
- UeId = UeId
- };
- }
-
- ///
- /// 更新TMSI信息
- ///
- /// 新的TMSI
- public void UpdateTmsi(string? newTmsi)
- {
- if (!string.IsNullOrWhiteSpace(Tmsi))
- {
- OldTmsi = Tmsi;
- }
- Tmsi = newTmsi;
- }
-
- ///
- /// 转换为JSON字符串
- ///
- /// JSON字符串
- public string ToJson()
- {
- return JsonConvert.SerializeObject(this, Formatting.Indented);
- }
-
- ///
- /// 从JSON字符串创建移动用户身份信息
- ///
- /// JSON字符串
- /// 移动用户身份信息
- public static MobileUserIdentity FromJson(string json)
- {
- return JsonConvert.DeserializeObject(json) ?? new MobileUserIdentity();
- }
-
- ///
- /// 重写ToString方法
- ///
- /// 字符串表示
- public override string ToString()
- {
- return GetIdentitySummary();
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/NetworkLayerLogs.cs b/CoreAgent.Domain/Models/Protocol/NetworkLayerLogs.cs
deleted file mode 100644
index 158a238..0000000
--- a/CoreAgent.Domain/Models/Protocol/NetworkLayerLogs.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using System;
-using System.Text.Json.Serialization;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 网络层日志集合
-/// 用于统一管理不同网络层的日志配置
-///
-public class NetworkLayerLogs
-{
- ///
- /// IMS层日志配置
- ///
- public ImsLayerLog ImsLog { get; set; }
-
- ///
- /// RAN层日志配置
- ///
- public RanLayerLog RanLog { get; set; }
-
- ///
- /// 初始化所有网络层的日志级别
- ///
- /// 是否为非独立组网模式(NSA模式)
- public void InitializeAllLogLevels(bool isNonStandaloneMode = false)
- {
- ImsLog = new ImsLayerLog();
- RanLog = new RanLayerLog();
-
- ImsLog.InitializeLogLevels();
- RanLog.InitializeLogLevels(isNonStandaloneMode);
- }
-
- ///
- /// 更新指定网络层和指定层的日志级别
- ///
- /// 网络类型("IMS" 或 "RAN")
- /// 层名称
- /// 日志级别
- /// 是否更新成功
- public bool UpdateLogLevel(string networkType, string layerName, LogLevel logLevel)
- {
- if (string.IsNullOrEmpty(networkType) || string.IsNullOrEmpty(layerName))
- return false;
-
- return networkType.ToUpper() switch
- {
- "IMS" => ImsLog?.UpdateLogLevel(layerName, logLevel) ?? false,
- "RAN" => RanLog?.UpdateLogLevel(layerName, logLevel) ?? false,
- _ => false
- };
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/ProtocolLayerType.cs b/CoreAgent.Domain/Models/Protocol/ProtocolLayerType.cs
deleted file mode 100644
index 8a38597..0000000
--- a/CoreAgent.Domain/Models/Protocol/ProtocolLayerType.cs
+++ /dev/null
@@ -1,242 +0,0 @@
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 协议层类型枚举
-/// 定义了系统中支持的各种协议层类型
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public enum ProtocolLayerType
-{
- ///
- /// 无协议层类型
- ///
- NONE = 0,
-
- ///
- /// GTP-U协议层
- /// GPRS Tunnelling Protocol User Plane
- ///
- GTPU = 1,
-
- ///
- /// LPPa协议层
- /// LTE Positioning Protocol Annex
- ///
- LPPa = 2,
-
- ///
- /// M2AP协议层
- /// M2 Application Protocol
- ///
- M2AP = 3,
-
- ///
- /// MAC协议层
- /// Medium Access Control
- ///
- MAC = 4,
-
- ///
- /// NAS协议层
- /// Non-Access Stratum
- ///
- NAS = 5,
-
- ///
- /// NGAP协议层
- /// Next Generation Application Protocol
- ///
- NGAP = 6,
-
- ///
- /// NRPPa协议层
- /// NR Positioning Protocol Annex
- ///
- NRPPa = 7,
-
- ///
- /// PDCP协议层
- /// Packet Data Convergence Protocol
- ///
- PDCP = 8,
-
- ///
- /// PROD协议层
- /// Production Protocol
- ///
- PROD = 9,
-
- ///
- /// PHY协议层
- /// Physical Layer
- ///
- PHY = 10,
-
- ///
- /// RLC协议层
- /// Radio Link Control
- ///
- RLC = 11,
-
- ///
- /// RRC协议层
- /// Radio Resource Control
- ///
- RRC = 12,
-
- ///
- /// S1AP协议层
- /// S1 Application Protocol
- ///
- S1AP = 13,
-
- ///
- /// TRX协议层
- /// Transceiver Protocol
- ///
- TRX = 14,
-
- ///
- /// X2AP协议层
- /// X2 Application Protocol
- ///
- X2AP = 15,
-
- ///
- /// XnAP协议层
- /// Xn Application Protocol
- ///
- XnAP = 16,
-
- ///
- /// IP协议层
- /// Internet Protocol
- ///
- IP = 17,
-
- ///
- /// IMS协议层
- /// IP Multimedia Subsystem
- ///
- IMS = 18,
-
- ///
- /// CX协议层
- /// Diameter CX Interface
- ///
- CX = 19,
-
- ///
- /// RX协议层
- /// Diameter RX Interface
- ///
- RX = 20,
-
- ///
- /// S6协议层
- /// Diameter S6 Interface
- ///
- S6 = 21,
-
- ///
- /// S13协议层
- /// Diameter S13 Interface
- ///
- S13 = 22,
-
- ///
- /// SGsAP协议层
- /// SGs Application Protocol
- ///
- SGsAP = 23,
-
- ///
- /// SBcAP协议层
- /// SBc Application Protocol
- ///
- SBcAP = 24,
-
- ///
- /// LCSAP协议层
- /// LCS Application Protocol
- ///
- LCSAP = 25,
-
- ///
- /// N12协议层
- /// Diameter N12 Interface
- ///
- N12 = 26,
-
- ///
- /// N8协议层
- /// Diameter N8 Interface
- ///
- N8 = 27,
-
- ///
- /// N17协议层
- /// Diameter N17 Interface
- ///
- N17 = 28,
-
- ///
- /// N50协议层
- /// Diameter N50 Interface
- ///
- N50 = 29,
-
- ///
- /// N13协议层
- /// Diameter N13 Interface
- ///
- N13 = 30,
-
- ///
- /// NL1协议层
- /// Network Layer 1
- ///
- NL1 = 31,
-
- ///
- /// HTTP2协议层
- /// Hypertext Transfer Protocol 2
- ///
- HTTP2 = 32,
-
- ///
- /// EPDG协议层
- /// Evolved Packet Data Gateway
- ///
- EPDG = 33,
-
- ///
- /// IKEV2协议层
- /// Internet Key Exchange Version 2
- ///
- IKEV2 = 34,
-
- ///
- /// IPSEC协议层
- /// Internet Protocol Security
- ///
- IPSEC = 35,
-
- ///
- /// MEDIA协议层
- /// Media Protocol
- ///
- MEDIA = 36,
-
- ///
- /// MMS协议层
- /// Multimedia Messaging Service
- ///
- MMS = 37,
-
- ///
- /// SIP协议层
- /// Session Initiation Protocol
- ///
- SIP = 38
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/ProtocolLayerTypeExtensions.cs b/CoreAgent.Domain/Models/Protocol/ProtocolLayerTypeExtensions.cs
deleted file mode 100644
index fa6f1c3..0000000
--- a/CoreAgent.Domain/Models/Protocol/ProtocolLayerTypeExtensions.cs
+++ /dev/null
@@ -1,258 +0,0 @@
-using System.ComponentModel;
-using System.Reflection;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// ProtocolLayerType 枚举扩展方法
-/// 提供协议层类型的实用功能
-///
-public static class ProtocolLayerTypeExtensions
-{
- ///
- /// 获取协议层类型的描述信息
- ///
- /// 协议层类型
- /// 描述信息
- public static string GetDescription(this ProtocolLayerType protocolLayerType)
- {
- var field = protocolLayerType.GetType().GetField(protocolLayerType.ToString());
- var attribute = field?.GetCustomAttribute();
- return attribute?.Description ?? protocolLayerType.ToString();
- }
-
- ///
- /// 获取协议层类型的显示名称
- ///
- /// 协议层类型
- /// 显示名称
- public static string GetDisplayName(this ProtocolLayerType protocolLayerType)
- {
- return protocolLayerType switch
- {
- ProtocolLayerType.NONE => "无",
- ProtocolLayerType.GTPU => "GTP-U",
- ProtocolLayerType.LPPa => "LPPa",
- ProtocolLayerType.M2AP => "M2AP",
- ProtocolLayerType.MAC => "MAC",
- ProtocolLayerType.NAS => "NAS",
- ProtocolLayerType.NGAP => "NGAP",
- ProtocolLayerType.NRPPa => "NRPPa",
- ProtocolLayerType.PDCP => "PDCP",
- ProtocolLayerType.PROD => "PROD",
- ProtocolLayerType.PHY => "PHY",
- ProtocolLayerType.RLC => "RLC",
- ProtocolLayerType.RRC => "RRC",
- ProtocolLayerType.S1AP => "S1AP",
- ProtocolLayerType.TRX => "TRX",
- ProtocolLayerType.X2AP => "X2AP",
- ProtocolLayerType.XnAP => "XnAP",
- ProtocolLayerType.IP => "IP",
- ProtocolLayerType.IMS => "IMS",
- ProtocolLayerType.CX => "CX",
- ProtocolLayerType.RX => "RX",
- ProtocolLayerType.S6 => "S6",
- ProtocolLayerType.S13 => "S13",
- ProtocolLayerType.SGsAP => "SGsAP",
- ProtocolLayerType.SBcAP => "SBcAP",
- ProtocolLayerType.LCSAP => "LCSAP",
- ProtocolLayerType.N12 => "N12",
- ProtocolLayerType.N8 => "N8",
- ProtocolLayerType.N17 => "N17",
- ProtocolLayerType.N50 => "N50",
- ProtocolLayerType.N13 => "N13",
- ProtocolLayerType.NL1 => "NL1",
- ProtocolLayerType.HTTP2 => "HTTP/2",
- ProtocolLayerType.EPDG => "EPDG",
- ProtocolLayerType.IKEV2 => "IKEv2",
- ProtocolLayerType.IPSEC => "IPSec",
- ProtocolLayerType.MEDIA => "MEDIA",
- ProtocolLayerType.MMS => "MMS",
- ProtocolLayerType.SIP => "SIP",
- _ => protocolLayerType.ToString()
- };
- }
-
- ///
- /// 判断是否为RAN相关协议层
- ///
- /// 协议层类型
- /// 是否为RAN协议层
- public static bool IsRanProtocol(this ProtocolLayerType protocolLayerType)
- {
- return protocolLayerType switch
- {
- ProtocolLayerType.GTPU or
- ProtocolLayerType.LPPa or
- ProtocolLayerType.M2AP or
- ProtocolLayerType.MAC or
- ProtocolLayerType.NAS or
- ProtocolLayerType.NGAP or
- ProtocolLayerType.NRPPa or
- ProtocolLayerType.PDCP or
- ProtocolLayerType.PHY or
- ProtocolLayerType.RLC or
- ProtocolLayerType.RRC or
- ProtocolLayerType.S1AP or
- ProtocolLayerType.TRX or
- ProtocolLayerType.X2AP or
- ProtocolLayerType.XnAP => true,
- _ => false
- };
- }
-
- ///
- /// 判断是否为IMS相关协议层
- ///
- /// 协议层类型
- /// 是否为IMS协议层
- public static bool IsImsProtocol(this ProtocolLayerType protocolLayerType)
- {
- return protocolLayerType switch
- {
- ProtocolLayerType.IMS or
- ProtocolLayerType.CX or
- ProtocolLayerType.RX or
- ProtocolLayerType.S6 or
- ProtocolLayerType.S13 or
- ProtocolLayerType.SGsAP or
- ProtocolLayerType.SBcAP or
- ProtocolLayerType.LCSAP or
- ProtocolLayerType.N12 or
- ProtocolLayerType.N8 or
- ProtocolLayerType.N17 or
- ProtocolLayerType.N50 or
- ProtocolLayerType.N13 or
- ProtocolLayerType.HTTP2 or
- ProtocolLayerType.EPDG or
- ProtocolLayerType.IKEV2 or
- ProtocolLayerType.IPSEC or
- ProtocolLayerType.MEDIA or
- ProtocolLayerType.MMS or
- ProtocolLayerType.SIP => true,
- _ => false
- };
- }
-
- ///
- /// 判断是否为Diameter协议层
- ///
- /// 协议层类型
- /// 是否为Diameter协议层
- public static bool IsDiameterProtocol(this ProtocolLayerType protocolLayerType)
- {
- return protocolLayerType switch
- {
- ProtocolLayerType.CX or
- ProtocolLayerType.RX or
- ProtocolLayerType.S6 or
- ProtocolLayerType.S13 or
- ProtocolLayerType.N12 or
- ProtocolLayerType.N8 or
- ProtocolLayerType.N17 or
- ProtocolLayerType.N50 or
- ProtocolLayerType.N13 => true,
- _ => false
- };
- }
-
- ///
- /// 获取协议层类型的分类
- ///
- /// 协议层类型
- /// 协议层分类
- public static string GetCategory(this ProtocolLayerType protocolLayerType)
- {
- return protocolLayerType switch
- {
- ProtocolLayerType.NONE => "None",
- ProtocolLayerType.GTPU or
- ProtocolLayerType.LPPa or
- ProtocolLayerType.M2AP or
- ProtocolLayerType.MAC or
- ProtocolLayerType.NAS or
- ProtocolLayerType.NGAP or
- ProtocolLayerType.NRPPa or
- ProtocolLayerType.PDCP or
- ProtocolLayerType.PHY or
- ProtocolLayerType.RLC or
- ProtocolLayerType.RRC or
- ProtocolLayerType.S1AP or
- ProtocolLayerType.TRX or
- ProtocolLayerType.X2AP or
- ProtocolLayerType.XnAP => "RAN",
- ProtocolLayerType.IMS or
- ProtocolLayerType.CX or
- ProtocolLayerType.RX or
- ProtocolLayerType.S6 or
- ProtocolLayerType.S13 or
- ProtocolLayerType.SGsAP or
- ProtocolLayerType.SBcAP or
- ProtocolLayerType.LCSAP or
- ProtocolLayerType.N12 or
- ProtocolLayerType.N8 or
- ProtocolLayerType.N17 or
- ProtocolLayerType.N50 or
- ProtocolLayerType.N13 or
- ProtocolLayerType.HTTP2 or
- ProtocolLayerType.EPDG or
- ProtocolLayerType.IKEV2 or
- ProtocolLayerType.IPSEC or
- ProtocolLayerType.MEDIA or
- ProtocolLayerType.MMS or
- ProtocolLayerType.SIP => "IMS",
- ProtocolLayerType.IP => "Network",
- ProtocolLayerType.NL1 => "Network",
- ProtocolLayerType.PROD => "Production",
- _ => "Other"
- };
- }
-
- ///
- /// 从字符串转换为ProtocolLayerType枚举
- ///
- /// 字符串值
- /// ProtocolLayerType枚举值,如果转换失败返回NONE
- public static ProtocolLayerType FromString(string value)
- {
- if (string.IsNullOrWhiteSpace(value))
- return ProtocolLayerType.NONE;
-
- return Enum.TryParse(value, true, out var result)
- ? result
- : ProtocolLayerType.NONE;
- }
-
- ///
- /// 获取所有RAN协议层类型
- ///
- /// RAN协议层类型数组
- public static ProtocolLayerType[] GetRanProtocols()
- {
- return Enum.GetValues()
- .Where(p => p.IsRanProtocol())
- .ToArray();
- }
-
- ///
- /// 获取所有IMS协议层类型
- ///
- /// IMS协议层类型数组
- public static ProtocolLayerType[] GetImsProtocols()
- {
- return Enum.GetValues()
- .Where(p => p.IsImsProtocol())
- .ToArray();
- }
-
- ///
- /// 获取所有Diameter协议层类型
- ///
- /// Diameter协议层类型数组
- public static ProtocolLayerType[] GetDiameterProtocols()
- {
- return Enum.GetValues()
- .Where(p => p.IsDiameterProtocol())
- .ToArray();
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/ProtocolLog.cs b/CoreAgent.Domain/Models/Protocol/ProtocolLog.cs
deleted file mode 100644
index 4c05e6b..0000000
--- a/CoreAgent.Domain/Models/Protocol/ProtocolLog.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using System.Collections.Generic;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 协议日志实体类
-///
-public record class ProtocolLog
-{
- ///
- /// 消息ID
- ///
- [JsonProperty("message_id")]
- public int? MessageId { get; set; }
-
- ///
- /// 消息头信息
- ///
- [JsonProperty("headers")]
- public string[]? Headers { get; set; }
-
- ///
- /// 消息内容
- ///
- [JsonProperty("message")]
- public string Message { get; set; }
-
- ///
- /// 消息类型
- ///
- [JsonProperty("type")]
- public string? Type { get; set; }
-
- ///
- /// 消息名称
- ///
- [JsonProperty("name")]
- public string? Name { get; set; }
-
- ///
- /// 协议版本
- ///
- [JsonProperty("version")]
- public string? Version { get; set; }
-
- ///
- /// 时间戳
- ///
- [JsonProperty("time")]
- public double? Time { get; set; }
-
- ///
- /// UTC时间戳
- ///
- [JsonProperty("utc")]
- public double? Utc { get; set; }
-
- ///
- /// 日志明细
- ///
- [JsonProperty("logs")]
- public JToken? Logs { get; set; }
-
- ///
- /// 初始化协议日志实体类的新实例
- ///
- /// 消息内容
- /// 消息类型
- /// 协议版本
- /// 时间戳
- /// UTC时间戳
- /// 日志明细
- /// 消息ID
- /// 消息头信息
- public ProtocolLog(
- string message,
- string? type,
- string? version,
- double? time,
- double? utc,
- JToken? logs,
- int? messageId,
- string[]? headers)
- {
- Message = message;
- Type = type;
- Version = version;
- Name = type;
- Utc = utc;
- Time = time;
- Logs = logs;
- MessageId = messageId ?? 0;
- Headers = headers;
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/ProtocolLogDetail.cs b/CoreAgent.Domain/Models/Protocol/ProtocolLogDetail.cs
deleted file mode 100644
index 20e59af..0000000
--- a/CoreAgent.Domain/Models/Protocol/ProtocolLogDetail.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-using System.Collections.Generic;
-using Newtonsoft.Json;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 协议日志明细
-///
-public class ProtocolLogDetail
-{
- ///
- /// 源信息
- ///
- [JsonProperty("src")]
- public string Src { get; set; }
-
- ///
- /// 索引
- ///
- [JsonProperty("idx")]
- public int Idx { get; set; }
-
- ///
- /// 日志级别
- ///
- [JsonProperty("level")]
- public int Level { get; set; }
-
- ///
- /// 方向
- ///
- [JsonProperty("dir")]
- public string Dir { get; set; }
-
- ///
- /// 时间戳
- ///
- [JsonProperty("timestamp")]
- public long Timestamp { get; set; }
-
- ///
- /// 小区信息
- ///
- [JsonProperty("cell")]
- public int? Cell { get; set; }
-
- ///
- /// 数据列表
- ///
- [JsonProperty("data")]
- public List Data { get; set; }
-
- ///
- /// 层信息
- ///
- [JsonProperty("layer")]
- public string Layer { get; set; }
-
- ///
- /// UE标识
- ///
- [JsonProperty("ue_id")]
- public int? UeId { get; set; }
-
- ///
- /// 帧信息
- ///
- [JsonProperty("frame")]
- public int? Frame { get; set; }
-
- ///
- /// 时隙信息
- ///
- [JsonProperty("slot")]
- public int? Slot { get; set; }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/ProtocolLogParsedResult.cs b/CoreAgent.Domain/Models/Protocol/ProtocolLogParsedResult.cs
deleted file mode 100644
index 6089aae..0000000
--- a/CoreAgent.Domain/Models/Protocol/ProtocolLogParsedResult.cs
+++ /dev/null
@@ -1,338 +0,0 @@
-using Newtonsoft.Json;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 协议日志解析结果
-/// 用于存储ProtocolLog解析后的分析结果,用于数据传输和处理
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public class ProtocolLogParsedResult
-{
- ///
- /// 唯一标识符
- ///
- [JsonProperty("id")]
- public string Id { get; set; } = Guid.NewGuid().ToString();
-
- ///
- /// 日志索引
- ///
- [JsonProperty("index")]
- public int? Index { get; set; }
-
- ///
- /// 消息ID
- ///
- [JsonProperty("messageId")]
- public int? MessageId { get; set; }
-
- ///
- /// 协议层类型
- ///
- [JsonProperty("protocolLayer")]
- public ProtocolLayerType ProtocolLayer { get; set; }
-
- ///
- /// 协议类型描述
- ///
- [JsonProperty("protocolType")]
- public string ProtocolType { get; set; } = string.Empty;
-
- ///
- /// 用户设备ID
- ///
- [JsonProperty("ueId")]
- public int? UeId { get; set; }
-
- ///
- /// 公共陆地移动网络标识
- ///
- [JsonProperty("plmn")]
- public string? Plmn { get; set; }
-
- ///
- /// 临时移动用户标识
- ///
- [JsonProperty("tmsi")]
- public string? Tmsi { get; set; }
-
- ///
- /// 国际移动设备标识
- ///
- [JsonProperty("imei")]
- public string? Imei { get; set; }
-
- ///
- /// 国际移动用户标识
- ///
- [JsonProperty("imsi")]
- public string? Imsi { get; set; }
-
- ///
- /// 小区ID
- ///
- [JsonProperty("cellId")]
- public int? CellId { get; set; }
-
- ///
- /// 小区信息
- ///
- [JsonProperty("cell")]
- public string? Cell { get; set; }
-
- ///
- /// 日志信息
- ///
- [JsonProperty("info")]
- public string? Info { get; set; }
-
- ///
- /// 消息内容
- ///
- [JsonProperty("message")]
- public string? Message { get; set; }
-
- ///
- /// 消息数据数组
- ///
- [JsonProperty("messageData")]
- public string[]? MessageData { get; set; }
-
- ///
- /// 时间间隔
- ///
- [JsonProperty("time")]
- public TimeSpan Time { get; set; }
-
- ///
- /// 时间戳
- ///
- [JsonProperty("timestamp")]
- public long Timestamp { get; set; }
-
- ///
- /// 日志方向
- ///
- [JsonProperty("direction")]
- public DirectionLogsType Direction { get; set; }
-
- ///
- /// 协议层分类
- ///
- [JsonProperty("category")]
- public string Category => ProtocolLayer.GetCategory();
-
- ///
- /// 协议层显示名称
- ///
- [JsonProperty("displayName")]
- public string DisplayName => ProtocolLayer.GetDisplayName();
-
- ///
- /// 初始化协议日志解析结果的新实例
- ///
- public ProtocolLogParsedResult()
- {
- }
-
- ///
- /// 初始化协议日志解析结果的新实例
- ///
- /// 消息ID
- /// 日志索引
- /// 协议层类型
- /// 用户设备ID
- /// 公共陆地移动网络标识
- /// 临时移动用户标识
- /// 国际移动设备标识
- /// 国际移动用户标识
- /// 小区ID
- /// 小区信息
- /// 日志信息
- /// 消息内容
- /// 消息数据数组
- /// 日志方向
- public ProtocolLogParsedResult(
- int? messageId = null,
- int? index = null,
- ProtocolLayerType protocolLayer = ProtocolLayerType.NONE,
- int? ueId = null,
- string? plmn = null,
- string? tmsi = null,
- string? imei = null,
- string? imsi = null,
- int? cellId = null,
- string? cell = null,
- string? info = null,
- string? message = null,
- string[]? messageData = null,
- DirectionLogsType direction = DirectionLogsType.Unknown)
- {
- MessageId = messageId;
- Index = index;
- ProtocolLayer = protocolLayer;
- UeId = ueId;
- Plmn = plmn;
- Tmsi = tmsi;
- Imei = imei;
- Imsi = imsi;
- CellId = cellId;
- Cell = cell;
- Info = info;
- Message = message;
- MessageData = messageData;
- Direction = direction;
- ProtocolType = protocolLayer.GetDisplayName();
- }
-
- ///
- /// 从ProtocolLog创建ProtocolLogParsedResult
- ///
- /// 协议日志
- /// 日志索引
- /// 协议日志解析结果
- public static ProtocolLogParsedResult FromProtocolLog(ProtocolLog protocolLog, int? index = null)
- {
- // 处理时间戳转换
- long timestamp;
- if (protocolLog.Time.HasValue)
- {
- // 如果 Time 是秒为单位,转换为毫秒
- timestamp = (long)(protocolLog.Time.Value * 1000);
- }
- else if (protocolLog.Utc.HasValue)
- {
- // 如果 Utc 是秒为单位,转换为毫秒
- timestamp = (long)(protocolLog.Utc.Value * 1000);
- }
- else
- {
- // 默认使用当前时间
- timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- }
-
- return new ProtocolLogParsedResult
- {
- MessageId = protocolLog.MessageId,
- Index = index,
- ProtocolLayer = ProtocolLayerType.NONE, // 需要根据实际内容解析
- Message = protocolLog.Message,
- MessageData = protocolLog.Headers,
- Timestamp = timestamp,
- Time = TimeSpan.FromMilliseconds(protocolLog.Time ?? 0),
- Direction = DirectionLogsType.Unknown,
- ProtocolType = protocolLog.Type ?? string.Empty
- };
- }
-
- ///
- /// 从ProtocolLogDetail创建ProtocolLogParsedResult
- ///
- /// 协议日志明细
- /// 日志索引
- /// 协议日志解析结果
- public static ProtocolLogParsedResult FromProtocolLogDetail(ProtocolLogDetail detail, int? index = null)
- {
- return new ProtocolLogParsedResult
- {
- Index = index ?? detail.Idx,
- ProtocolLayer = ProtocolLayerTypeExtensions.FromString(detail.Layer),
- UeId = detail.UeId,
- CellId = detail.Cell,
- Info = detail.Src,
- MessageData = detail.Data?.ToArray(),
- Timestamp = detail.Timestamp,
- Time = TimeSpan.FromMilliseconds(detail.Timestamp),
- Direction = ParseDirection(detail.Dir),
- ProtocolType = detail.Layer
- };
- }
-
- ///
- /// 解析方向字符串为DirectionLogsType
- ///
- /// 方向字符串
- /// 方向类型
- private static DirectionLogsType ParseDirection(string? direction)
- {
- if (string.IsNullOrWhiteSpace(direction))
- return DirectionLogsType.Unknown;
-
- return direction.ToLower() switch
- {
- "up" or "uplink" or "ul" => DirectionLogsType.Uplink,
- "down" or "downlink" or "dl" => DirectionLogsType.Downlink,
- "bidirectional" or "bi" => DirectionLogsType.Bidirectional,
- "internal" or "int" => DirectionLogsType.Internal,
- _ => DirectionLogsType.Unknown
- };
- }
-
- ///
- /// 检查解析结果是否包含有效数据
- ///
- /// 是否包含有效数据
- public bool HasValidData()
- {
- return !string.IsNullOrEmpty(Id) &&
- (ProtocolLayer != ProtocolLayerType.NONE || !string.IsNullOrEmpty(ProtocolType));
- }
-
- ///
- /// 获取解析结果摘要信息
- ///
- /// 摘要信息
- public string GetSummary()
- {
- return $"ProtocolLogParsed[{Id}] - {ProtocolLayer.GetDisplayName()} - {Direction} - UE:{UeId} - Cell:{CellId}";
- }
-
- ///
- /// 创建解析结果的副本
- ///
- /// 新的协议日志解析结果
- public ProtocolLogParsedResult Copy()
- {
- return new ProtocolLogParsedResult
- {
- Id = Guid.NewGuid().ToString(), // 生成新的ID
- Index = Index,
- MessageId = MessageId,
- ProtocolLayer = ProtocolLayer,
- ProtocolType = ProtocolType,
- UeId = UeId,
- Plmn = Plmn,
- Tmsi = Tmsi,
- Imei = Imei,
- Imsi = Imsi,
- CellId = CellId,
- Cell = Cell,
- Info = Info,
- Message = Message,
- MessageData = MessageData?.Clone() as string[],
- Time = Time,
- Timestamp = Timestamp,
- Direction = Direction
- };
- }
-
- ///
- /// 转换为JSON字符串
- ///
- /// JSON字符串
- public string ToJson()
- {
- return JsonConvert.SerializeObject(this, Formatting.Indented);
- }
-
- ///
- /// 从JSON字符串创建解析结果
- ///
- /// JSON字符串
- /// 协议日志解析结果
- public static ProtocolLogParsedResult FromJson(string json)
- {
- return JsonConvert.DeserializeObject(json) ?? new ProtocolLogParsedResult();
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/RanLayerLog.cs b/CoreAgent.Domain/Models/Protocol/RanLayerLog.cs
deleted file mode 100644
index 1ad1803..0000000
--- a/CoreAgent.Domain/Models/Protocol/RanLayerLog.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-using System;
-using System.Text.Json.Serialization;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// RAN层日志实体类
-/// 该实体用于记录RAN(无线接入网)相关的各层日志信息
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public class RanLayerLog
-{
- ///
- /// GTP-U协议层日志级别
- ///
- public string GTPU { get; set; }
-
- ///
- /// LPPa协议层日志级别
- ///
- public string LPPa { get; set; }
-
- ///
- /// M2AP协议层日志级别
- ///
- public string M2AP { get; set; }
-
- ///
- /// MAC协议层日志级别
- ///
- public string MAC { get; set; }
-
- ///
- /// NAS协议层日志级别
- ///
- public string NAS { get; set; }
-
- ///
- /// NGAP协议层日志级别
- ///
- public string NGAP { get; set; }
-
- ///
- /// NRPPa协议层日志级别
- ///
- public string NRPPa { get; set; }
-
- ///
- /// PDCP协议层日志级别
- ///
- public string PDCP { get; set; }
-
- ///
- /// PHY协议层日志级别
- ///
- public string PHY { get; set; }
-
- ///
- /// RLC协议层日志级别
- ///
- public string RLC { get; set; }
-
- ///
- /// RRC协议层日志级别
- ///
- public string RRC { get; set; }
-
- ///
- /// S1AP协议层日志级别
- ///
- public string S1AP { get; set; }
-
- ///
- /// TRX协议层日志级别
- ///
- public string TRX { get; set; }
-
- ///
- /// X2AP协议层日志级别
- ///
- public string X2AP { get; set; }
-
- ///
- /// XnAP协议层日志级别
- ///
- public string XnAP { get; set; }
-
- ///
- /// PROD协议层日志级别
- ///
- [JsonIgnore]
- public string PROD { get; set; }
-
- ///
- /// 初始化RAN层日志级别
- ///
- /// 是否为非独立组网模式(NSA模式)
- public void InitializeLogLevels(bool isNonStandaloneMode = false)
- {
- GTPU = LogLevel.Warn.ToString().ToLower();
- LPPa = LogLevel.Warn.ToString().ToLower();
- M2AP = LogLevel.Warn.ToString().ToLower();
- MAC = LogLevel.Warn.ToString().ToLower();
- NAS = LogLevel.Warn.ToString().ToLower();
- NGAP = LogLevel.Warn.ToString().ToLower();
- NRPPa = LogLevel.Warn.ToString().ToLower();
- PDCP = LogLevel.Warn.ToString().ToLower();
- PHY = LogLevel.Warn.ToString().ToLower();
- RLC = LogLevel.Warn.ToString().ToLower();
- RRC = LogLevel.Warn.ToString().ToLower();
- S1AP = LogLevel.Warn.ToString().ToLower();
- TRX = LogLevel.Warn.ToString().ToLower();
- X2AP = LogLevel.Warn.ToString().ToLower();
- XnAP = LogLevel.Warn.ToString().ToLower();
- PROD = LogLevel.Warn.ToString().ToLower();
- }
-
- ///
- /// 更新指定层的日志级别
- ///
- /// 层名称
- /// 日志级别
- /// 是否更新成功
- public bool UpdateLogLevel(string layerName, LogLevel logLevel)
- {
- if (string.IsNullOrEmpty(layerName))
- return false;
-
- var property = GetType().GetProperty(layerName);
- if (property == null)
- return false;
-
- property.SetValue(this, logLevel.ToString().ToLower());
- return true;
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Domain/Models/Protocol/UserNetworkIdentity.cs b/CoreAgent.Domain/Models/Protocol/UserNetworkIdentity.cs
deleted file mode 100644
index 2cc08d3..0000000
--- a/CoreAgent.Domain/Models/Protocol/UserNetworkIdentity.cs
+++ /dev/null
@@ -1,219 +0,0 @@
-using Newtonsoft.Json;
-
-namespace CoreAgent.Domain.Models.Protocol;
-
-///
-/// 用户网络身份信息
-/// 用于存储移动网络用户的基本身份和位置信息
-/// 遵循DDD(领域驱动设计)原则,作为领域模型的一部分
-///
-public class UserNetworkIdentity
-{
- ///
- /// 公共陆地移动网络标识
- ///
- [JsonProperty("plmn")]
- public string? Plmn { get; set; }
-
- ///
- /// 旧的临时移动用户标识
- ///
- [JsonProperty("oldTmsi")]
- public string? OldTmsi { get; set; }
-
- ///
- /// 临时移动用户标识
- ///
- [JsonProperty("tmsi")]
- public string? Tmsi { get; set; }
-
- ///
- /// 国际移动用户标识
- ///
- [JsonProperty("imsi")]
- public string? Imsi { get; set; }
-
- ///
- /// 小区ID
- ///
- [JsonProperty("cellId")]
- public int? CellId { get; set; }
-
- ///
- /// 用户设备ID
- ///
- [JsonProperty("ueId")]
- public int? UeId { get; set; }
-
- ///
- /// 初始化用户网络身份信息的新实例
- ///
- public UserNetworkIdentity()
- {
- }
-
- ///
- /// 初始化用户网络身份信息的新实例
- ///
- /// 公共陆地移动网络标识
- /// 旧的临时移动用户标识
- /// 临时移动用户标识
- /// 国际移动用户标识
- /// 小区ID
- /// 用户设备ID
- public UserNetworkIdentity(
- string? plmn = null,
- string? oldTmsi = null,
- string? tmsi = null,
- string? imsi = null,
- int? cellId = null,
- int? ueId = null)
- {
- Plmn = plmn;
- OldTmsi = oldTmsi;
- Tmsi = tmsi;
- Imsi = imsi;
- CellId = cellId;
- UeId = ueId;
- }
-
- ///
- /// 检查是否包含有效的用户身份信息
- ///
- /// 是否包含有效信息
- public bool HasValidIdentity()
- {
- return !string.IsNullOrWhiteSpace(Imsi) ||
- !string.IsNullOrWhiteSpace(Tmsi) ||
- UeId.HasValue;
- }
-
- ///
- /// 检查是否包含位置信息
- ///
- /// 是否包含位置信息
- public bool HasLocationInfo()
- {
- return !string.IsNullOrWhiteSpace(Plmn) || CellId.HasValue;
- }
-
- ///
- /// 获取用户身份摘要信息
- ///
- /// 摘要信息
- public string GetIdentitySummary()
- {
- var parts = new List();
-
- if (!string.IsNullOrWhiteSpace(Imsi))
- parts.Add($"IMSI:{Imsi}");
-
- if (!string.IsNullOrWhiteSpace(Tmsi))
- parts.Add($"TMSI:{Tmsi}");
-
- if (UeId.HasValue)
- parts.Add($"UE:{UeId}");
-
- if (!string.IsNullOrWhiteSpace(Plmn))
- parts.Add($"PLMN:{Plmn}");
-
- if (CellId.HasValue)
- parts.Add($"Cell:{CellId}");
-
- return parts.Count > 0 ? string.Join(" | ", parts) : "No Identity Info";
- }
-
- ///
- /// 检查TMSI是否发生变化
- ///
- /// TMSI是否发生变化
- public bool HasTmsiChanged()
- {
- return !string.IsNullOrWhiteSpace(OldTmsi) &&
- !string.IsNullOrWhiteSpace(Tmsi) &&
- !OldTmsi.Equals(Tmsi, StringComparison.OrdinalIgnoreCase);
- }
-
- ///
- /// 获取TMSI变化信息
- ///
- /// TMSI变化信息
- public string GetTmsiChangeInfo()
- {
- if (HasTmsiChanged())
- {
- return $"TMSI Changed: {OldTmsi} -> {Tmsi}";
- }
- return "TMSI Unchanged";
- }
-
- ///
- /// 创建用户网络身份信息的副本
- ///
- /// 新的用户网络身份信息
- public UserNetworkIdentity Copy()
- {
- return new UserNetworkIdentity
- {
- Plmn = Plmn,
- OldTmsi = OldTmsi,
- Tmsi = Tmsi,
- Imsi = Imsi,
- CellId = CellId,
- UeId = UeId
- };
- }
-
- ///
- /// 更新TMSI信息
- ///
- /// 新的TMSI
- public void UpdateTmsi(string? newTmsi)
- {
- if (!string.IsNullOrWhiteSpace(Tmsi))
- {
- OldTmsi = Tmsi;
- }
- Tmsi = newTmsi;
- }
-
- ///
- /// 转换为JSON字符串
- ///
- /// JSON字符串
- public string ToJson()
- {
- return JsonConvert.SerializeObject(this, Formatting.Indented);
- }
-
- ///
- /// 从JSON字符串创建用户网络身份信息
- ///
- /// JSON字符串
- /// 用户网络身份信息
- public static UserNetworkIdentity FromJson(string json)
- {
- return JsonConvert.DeserializeObject(json) ?? new UserNetworkIdentity();
- }
-
- ///
- /// 合并另一个用户网络身份信息
- ///
- /// 另一个用户网络身份信息
- /// 合并后的用户网络身份信息
- public UserNetworkIdentity Merge(UserNetworkIdentity other)
- {
- if (other == null)
- return this;
-
- return new UserNetworkIdentity
- {
- Plmn = Plmn ?? other.Plmn,
- OldTmsi = OldTmsi ?? other.OldTmsi,
- Tmsi = Tmsi ?? other.Tmsi,
- Imsi = Imsi ?? other.Imsi,
- CellId = CellId ?? other.CellId,
- UeId = UeId ?? other.UeId
- };
- }
-}
\ No newline at end of file
diff --git a/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs b/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
index 89dbe64..c3bc1bc 100644
--- a/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
+++ b/CoreAgent.Infrastructure/Contexts/CellularNetworkContext.cs
@@ -4,7 +4,6 @@ using CoreAgent.Domain.Models.Network;
using CoreAgent.Domain.Models.System;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
-using CoreAgent.Domain.Models.Protocol;
namespace CoreAgent.Infrastructure.Contexts;
@@ -24,7 +23,6 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
private readonly INetworkIPEndPointManager _networkIPEndPointManager;
private NetworkConfigType _currentConfigType;
private readonly ILogger _logger;
- private NetworkLayerLogs _networkLogs;
///
/// 获取取消令牌源
@@ -46,10 +44,6 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
///
public NetworkConfigType CurrentConfigType => _currentConfigType;
- ///
- /// 网络层日志配置
- ///
- public NetworkLayerLogs NetworkLogs => _networkLogs;
public CellularNetworkContext(
IOptions networkCommandConfig,
@@ -65,7 +59,6 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
_networkIPEndPointManager = networkIPEndPointManager ?? throw new ArgumentNullException(nameof(networkIPEndPointManager));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_currentConfigType = NetworkConfigType.None;
- _networkLogs = new NetworkLayerLogs();
}
///
@@ -257,7 +250,6 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable
_networkState = new CellularNetworkState(string.Empty);
_networkIPEndPointManager.Clear();
_currentConfigType = NetworkConfigType.None;
- _networkLogs = new NetworkLayerLogs();
_logger.LogInformation("CellularNetworkContext 重置完成");
}
catch (Exception ex)
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/IMSLogMessageHandler.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/IMSLogMessageHandler.cs
deleted file mode 100644
index 040f257..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/IMSLogMessageHandler.cs
+++ /dev/null
@@ -1,256 +0,0 @@
-using CoreAgent.Domain.Interfaces.CustomWSClient;
-using CoreAgent.Domain.Interfaces.Network;
-using CoreAgent.Domain.Models.Protocol;
-using CoreAgent.Infrastructure.Contexts;
-using Microsoft.Extensions.Logging;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Concurrent;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- ///
- /// IMS协议消息处理器
- /// 负责处理IMS相关的WebSocket消息,包括用户更新、短信、邀请等功能
- ///
- public class IMSLogMessageHandler : ICustomMessageHandler, IDisposable
- {
- private readonly ILogger _logger;
- private int _messageId = 0;
- private string _currentMessageId = string.Empty;
- private readonly Action _messageCallback;
- private readonly ICellularNetworkContext _context;
- private readonly BlockingCollection<(string MessageData, IObserverCustomWebSocketClient Observer)> _messageQueue;
- private readonly CancellationTokenSource _cancellationTokenSource;
- private readonly Task _processTask;
- private bool _disposed;
-
- public IMSLogMessageHandler(ILogger logger, ICellularNetworkContext context, Action action)
- {
- _logger = logger ?? throw new ArgumentNullException(nameof(logger));
- _messageCallback = action ?? throw new ArgumentNullException(nameof(action));
- _context = context ?? throw new ArgumentNullException(nameof(context));
-
- _messageQueue = new BlockingCollection<(string, IObserverCustomWebSocketClient)>();
- _cancellationTokenSource = new CancellationTokenSource();
- _processTask = Task.Run(ProcessMessageQueue);
-
- _logger.LogInformation("IMS协议消息处理器初始化完成,消息队列已启动");
- }
-
- public void HandleMessage(string messageData, IObserverCustomWebSocketClient observer)
- {
- try
- {
- _logger.LogDebug("将消息加入处理队列: {MessageData}", messageData);
- _messageQueue.Add((messageData, observer));
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "将消息加入队列时发生错误: {MessageData}", messageData);
- }
- }
-
- private async Task ProcessMessageQueue()
- {
- try
- {
- _logger.LogInformation("开始处理IMS消息队列");
- foreach (var (messageData, observer) in _messageQueue.GetConsumingEnumerable(_cancellationTokenSource.Token))
- {
- try
- {
- await ProcessMessageAsync(messageData, observer);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "处理队列中的消息时发生错误: {MessageData}", messageData);
- }
- }
- }
- catch (OperationCanceledException)
- {
- _logger.LogInformation("IMS消息队列处理已取消");
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "IMS消息队列处理过程中发生错误");
- }
- }
-
- private async Task ProcessMessageAsync(string messageData, IObserverCustomWebSocketClient observer)
- {
- try
- {
- _logger.LogDebug("开始处理IMS协议消息: {MessageData}", messageData);
- var data = JObject.Parse(messageData);
- string messageType = data["message"]!.ToString();
- _logger.LogInformation("收到IMS协议消息类型: {MessageType}", messageData);
- await HandleMessageByTypeAsync(messageType, data, observer);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "处理IMS协议消息时发生错误: {MessageData}", messageData);
- }
- }
-
- private async Task HandleMessageByTypeAsync(string messageType, JObject data, IObserverCustomWebSocketClient observer)
- {
- _currentMessageId = _messageId.ToString();
-
- switch (messageType)
- {
- case "ready":
- await HandleReadyMessageAsync(observer);
- break;
- case "config_get":
- await HandleConfigGetMessageAsync(data, observer);
- break;
- case "config_set":
- await HandleConfigSetMessageAsync(observer);
- break;
- case "log_get":
- await HandleLogGetMessageAsync(data, observer);
- break;
- case "stats":
- await HandleStatsMessageAsync(observer);
- break;
- default:
- _logger.LogWarning("收到未知的IMS协议消息类型: {MessageType}", messageType);
- await Task.Run(() => observer.SendMessage(LayerLogslevelSetting(false)));
- break;
- }
- }
-
- private async Task HandleReadyMessageAsync(IObserverCustomWebSocketClient observer)
- {
- string readyResponse = CreateMessage("config_get");
- _logger.LogInformation("发送ready响应: {Response}", readyResponse);
- await Task.Run(() => observer.SendMessage(readyResponse));
- }
-
- private async Task HandleConfigGetMessageAsync(JObject data, IObserverCustomWebSocketClient observer)
- {
- if (_currentMessageId == data["message_id"]!.ToString())
- {
- _logger.LogInformation("处理config_get请求");
- var responseArray = new JArray
- {
- CreateRegisterMessage("users_update"),
- CreateRegisterMessage("sms"),
- CreateRegisterMessage("invite"),
- CreateStatsMessage(),
- SettingBaseLayerLogslevel(JObject.Parse(data["logs"].ToString()))
- };
- _logger.LogInformation("发送config_get响应: {Response}", responseArray.ToString());
- await Task.Run(() => observer.SendMessage(responseArray.ToString()));
- }
- else
- {
- _logger.LogWarning("config_get消息ID不匹配: 收到={ReceivedId}, 期望={ExpectedId}",
- data["message_id"]!.ToString(), _currentMessageId);
- }
- }
-
- private async Task HandleConfigSetMessageAsync(IObserverCustomWebSocketClient observer)
- {
- string configResponse = LayerLogslevelSetting(true);
- _logger.LogInformation("发送config_set响应: {Response}", configResponse);
- await Task.Run(() => observer.SendMessage(configResponse));
- //_currentMessageId = _messageId.ToString();
- }
-
- private async Task HandleLogGetMessageAsync(JObject data, IObserverCustomWebSocketClient observer)
- {
- if (JArray.FromObject(data["logs"]).Count > 0)
- {
- string logResponse = LayerLogslevelSetting(false);
- _logger.LogInformation("发送log_get响应: {Response}", logResponse);
- await Task.Run(() => observer.SendMessage(logResponse));
- //_currentMessageId = _messageId.ToString();
- await Task.Run(() => _messageCallback.Invoke(data.ToString()));
- }
- }
-
- private async Task HandleStatsMessageAsync(IObserverCustomWebSocketClient observer)
- {
- string statsResponse = CreateStatsMessage();
- _logger.LogInformation("发送stats响应: {Response}", statsResponse);
- await Task.Run(() => observer.SendMessage(statsResponse));
- }
-
- private string CreateMessage(string message)
- {
- return JObject.FromObject(new { message, message_id = Interlocked.Increment(ref _messageId) }).ToString();
- }
-
- private JObject CreateRegisterMessage(string register)
- {
- return JObject.FromObject(new { message = "register", message_id = Interlocked.Increment(ref _messageId), register });
- }
-
- private string CreateStatsMessage()
- {
- return CreateMessage("stats");
- }
-
- private JObject SettingBaseLayerLogslevel(JObject keyValues, bool isCloseSystemInfo = false)
- {
- keyValues.Remove("rotate");
- keyValues.Remove("path");
- keyValues.Remove("count");
- keyValues["bcch"] = isCloseSystemInfo;
-
- return JObject.FromObject(new
- {
- message = "config_set",
- logs = keyValues,
- message_id = Interlocked.Increment(ref _messageId)
- });
- }
-
- private string LayerLogslevelSetting(bool isHead = false)
- {
- BaseNetworkLog logtype = new BaseNetworkLog
- {
- Timeout = isHead ? 0 : 1,
- MinLogCount = 64,
- MaxLogCount = 2048,
- LayerConfig = _context.NetworkLogs.ImsLog,
- Message = "log_get",
- IncludeHeaders = isHead,
- MessageId = Interlocked.Increment(ref _messageId)
- };
- return JObject.FromObject(logtype).ToString();
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposed)
- {
- if (disposing)
- {
- _cancellationTokenSource.Cancel();
- _messageQueue.CompleteAdding();
- _processTask.Wait();
- _cancellationTokenSource.Dispose();
- _messageQueue.Dispose();
- }
- _disposed = true;
- }
- }
-
- ~IMSLogMessageHandler()
- {
- Dispose(false);
- }
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolLogsProviderObserver.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolLogsProviderObserver.cs
deleted file mode 100644
index dabb207..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolLogsProviderObserver.cs
+++ /dev/null
@@ -1,147 +0,0 @@
-using CoreAgent.Domain.Interfaces.Network;
-using CoreAgent.Domain.Interfaces.ProtocolLogHandlers;
-using CoreAgent.Domain.Models.Network;
-using CoreAgent.Infrastructure.Contexts;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- ///
- /// 协议日志提供者观察者
- /// 负责接收、缓存和转发协议日志数据
- /// 使用生产者-消费者模式处理日志数据流
- ///
- public class ProtocolLogsProviderObserver : IProtocolLogsProviderObserver
- {
- ///
- /// 用于存储待处理的协议日志消息的阻塞队列
- ///
- private readonly static BlockingCollection BlockingQueue = new BlockingCollection();
-
- ///
- /// 日志记录器
- ///
- private readonly ILogger logger;
-
- ///
- /// 网络上下文,用于检查网络状态
- ///
- private readonly CellularNetworkContext networkContext;
-
-
- ///
- /// 初始化协议日志提供者观察者
- ///
- /// 网络上下文
- /// 日志记录器
- public ProtocolLogsProviderObserver(CellularNetworkContext networkContext, ILogger logger)
- {
- this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
- this.networkContext = networkContext ?? throw new ArgumentNullException(nameof(networkContext));
-
- logger.LogInformation("ProtocolLogsProviderObserver 初始化完成");
- _ = Task.Run(Consumer);
- logger.LogInformation("消费者任务已启动");
- }
-
- ///
- /// 接收并处理新的协议日志数据
- ///
- /// 协议日志消息
- public void OnData(string msg)
- {
- if (string.IsNullOrEmpty(msg))
- {
- logger.LogWarning("收到空的协议日志消息");
- return;
- }
-
- try
- {
- logger.LogDebug("收到新的协议日志消息: {Message}", msg);
- Producer(msg);
- }
- catch (Exception ex)
- {
- logger.LogError(ex, "处理协议日志消息时发生错误: {Message}", msg);
- }
- }
-
- ///
- /// 生产者方法:将消息添加到阻塞队列中
- ///
- /// 要添加的消息
- private void Producer(string message)
- {
- try
- {
- var networkState = networkContext.GetNetworkState();
- if (networkState.CurrentStatus == NetworkStatus.Connected)
- {
- logger.LogDebug("网络已连接,将消息添加到队列: {Message}", message);
- BlockingQueue.Add(message);
- }
- else
- {
- logger.LogWarning("网络未连接,丢弃消息: {Message}", message);
- }
- }
- catch (Exception ex)
- {
- logger.LogError(ex, "添加消息到队列时发生错误: {Message}", message);
- throw;
- }
- }
-
- ///
- /// 消费者方法:从队列中获取并处理消息
- ///
- public async Task Consumer()
- {
- logger.LogInformation("消费者任务开始运行");
-
- try
- {
- while (networkContext.GetNetworkState().CurrentStatus == NetworkStatus.Connected)
- {
- try
- {
- if (BlockingQueue.TryTake(out var message, TimeSpan.FromMilliseconds(1000)))
- {
- logger.LogDebug("从队列中获取到消息: {Message}", message);
- // TODO: 实现消息发送逻辑
- // await client.SendAsync(message, true);
- }
- else
- {
- await Task.Delay(1000);
- }
- }
- catch (Exception ex)
- {
- logger.LogError(ex, "处理队列消息时发生错误");
- await Task.Delay(1000); // 发生错误时等待一段时间再继续
- }
- }
- }
- catch (OperationCanceledException)
- {
- logger.LogWarning("消费者任务被取消");
- }
- catch (Exception ex)
- {
- logger.LogError(ex, "消费者任务发生未处理的错误");
- }
- finally
- {
- logger.LogInformation("消费者任务已结束");
- }
- }
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSHandleLogs.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSHandleLogs.cs
deleted file mode 100644
index c0f987c..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSHandleLogs.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using CoreAgent.Domain.Interfaces.CustomWSClient;
-using CoreAgent.Domain.Interfaces.ProtocolLogHandlers;
-using CoreAgent.Infrastructure.Services.CustomWSClient;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- public class ProtocolMSHandleLogs : CustomWebSocketClient, IProtocollHandleLogs
- {
- protected ProtocolMSHandleLogs(ILogger logger, string serverUrl, ICustomMessageHandler messageHandler) : base(logger, serverUrl, messageHandler)
- {
-
- }
-
- public void RunStart()
- {
-
- }
-
- public void RunStop()
- {
-
- }
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSParesHandleLogs.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSParesHandleLogs.cs
deleted file mode 100644
index 7630c1f..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolMSParesHandleLogs.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- internal class ProtocolMSParesHandleLogs
- {
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolParesHandleLogs.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolParesHandleLogs.cs
deleted file mode 100644
index bdfcd0b..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolParesHandleLogs.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using CoreAgent.Domain.Models.Protocol;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- public abstract class ProtocolParesHandleLogs
- {
- #region Regex
- public readonly Regex _regExpPhy = new Regex(@"^([a-f0-9\-]+)\s+([a-f0-9\-]+)\s+([\d\.\-]+) (\w+): (.+)");
- public readonly Regex _regExpInfo1 = new Regex(@"^([\w\-]+): (.+)");
- public readonly Regex _regExpInfo2 = new Regex(@"^([\w]+) (.+)");
- public readonly Regex _regExpParams1 = new Regex(@"\s+");
- public readonly Regex _regExpParams2 = new Regex(@"=|:");
- public readonly Regex _regExpIP = new Regex(@"^(len=\d+)\s+(\S+)\s+(.*)");
- public readonly Regex _regExpIPsec = new Regex(@"^len=(\d+)\s+(.*)");
- public readonly Regex _regExpIKEV2 = new Regex(@"^(\S+)\s+(.*)");
- public readonly Regex _regExpSDULen = new Regex(@"SDU_len=(\d+)");
- public readonly Regex _regExpSIP = new Regex(@"^([:\.\[\]\da-f]+)\s+(\S+) (.+)");
- public readonly Regex _regExpMediaReq = new Regex(@"^(\S+) (.+)");
- public readonly Regex _regExpSignalRecord = new Regex(@"Link:\s([\w\d]+)@(\d+)");
- public readonly Regex _regExpCellID = new Regex(@"^([a-f0-9\-]+) (.+)");
- public readonly Regex _regExpRRC_UE_ID = new Regex(@"Changing UE_ID to 0x(\d+)");
- public readonly Regex _regExpRRC_TMSI = new Regex(@"(5G|m)-TMSI '([\dA-F]+)'H");
- public readonly Regex _regExpRRC_NEW_ID = new Regex(@"newUE-Identity (['\dA-FH]+)");
- public readonly Regex _regExpRRC_CRNTI = new Regex(@"c-RNTI '([\dA-F]+)'H");
- public readonly Regex _regExpNAS_TMSI = new Regex(@"m-TMSI = 0x([\da-f]+)");
- public readonly Regex _regExpNAS_5GTMSI = new Regex(@"5G-TMSI = 0x([\da-f]+)");
- public readonly Regex _regExpRRC_BC = new Regex(@"(EUTRA|MRDC|NR|NRDC) band combinations");
- public readonly Regex _regExpPDCCH = new Regex(@"^\s*(.+)=(\d+)$");
- public readonly Regex _regExpS1NGAP = new Regex(@"^([\da-f\-]+)\s+([\da-f\-]+) (([^\s]+) .+)");
- public readonly Regex _regExpECPRI = new Regex(@"len=(\d+)");
- public readonly Regex _regExpHexDump = new Regex(@"^[\da-f]+:(\s+[\da-f]{2}){1,16}\s+.{1,16}$");
- #endregion
- public abstract Task GetTryParesLogDataHandle(ProtocolLog model);
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanHandleLogs.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanHandleLogs.cs
deleted file mode 100644
index e842f8a..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanHandleLogs.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using CoreAgent.Domain.Interfaces.CustomWSClient;
-using CoreAgent.Domain.Interfaces.ProtocolLogHandlers;
-using CoreAgent.Infrastructure.Services.CustomWSClient;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- public class ProtocolRanHandleLogs : CustomWebSocketClient, IProtocollHandleLogs
- {
- protected ProtocolRanHandleLogs(ILogger logger, string serverUrl, ICustomMessageHandler messageHandler) : base(logger, serverUrl, messageHandler)
- {
-
- }
-
- public void RunStart()
- {
-
- }
-
- public void RunStop()
- {
-
- }
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanParesHandleLogs.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanParesHandleLogs.cs
deleted file mode 100644
index 76e64d9..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/ProtocolRanParesHandleLogs.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using CoreAgent.Domain.Helpers;
-using CoreAgent.Domain.Interfaces.ProtocolLogHandlers;
-using CoreAgent.Domain.Models.Protocol;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
-
-
-
- public class ProtocolLogsParesRanHandle : ProtocolParesHandleLogs
- {
- private readonly ILogger logger;
- private readonly IProtocolLogsProviderObserver observer;
- public ProtocolLogsParesRanHandle(IProtocolLogsProviderObserver observer, ILogger logger)
- {
- this.observer = observer;
- this.logger = logger;
- }
-
- public override async Task GetTryParesLogDataHandle(ProtocolLog model)
- {
- try
- {
- if (model is { Logs: null })
- {
- logger.LogError($"logs is null =====>GetTryParesLogDataHandle Data {model?.ObjToJson()}");
- return;
- }
- var ParseJsonData = model.Logs.ToString().JsonToObj();
- var parseResultData = LogParsedResultHandle(ParseJsonData, (model.MessageId ?? 0));
- //if (parseResultData.Any())
- //{
- // var MsgData = new { data = parseResultData, MessageType = CSCIMessageType.ProtocolLogsRAN }.ObjToJson();
- // logger.LogInformation($"OnData:{MsgData}");
- // observer.OnData(MsgData);
- //}
- }
- catch (Exception ex)
- {
- logger.LogError($"GetTryParesLogDataHandle Data {model?.ObjToJson()}");
- logger.LogError(ex.ToString());
- }
- }
-
- public ProtocolLogParsedResult[] LogParsedResultHandle(ProtocolLogDetail[] logDetails, int MessageId)
- {
- List parsedResults = new List();
-
- return parsedResults.ToArray();
- }
-
- public void LogListParse(ProtocolLogDetail[] list)
- {
- int length = list.Length;
- for (int i = 0; i < length; i++)
- {
- var log= list[i];
- switch (log.Layer)
- {
- case "PHY":
- break;
- case "MAC":
- break;
- case "RRC":
- break;
- case "NAS":
- break;
-
- default:
- break;
-
- }
- }
- }
- }
-}
diff --git a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/RanLogMessageHandler.cs b/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/RanLogMessageHandler.cs
deleted file mode 100644
index 20ac73a..0000000
--- a/CoreAgent.Infrastructure/Services/ProtocolLogHandlers/RanLogMessageHandler.cs
+++ /dev/null
@@ -1,362 +0,0 @@
-using CoreAgent.Domain.Interfaces.CustomWSClient;
-using CoreAgent.Domain.Interfaces.Network;
-using CoreAgent.Domain.Models.Protocol;
-using Microsoft.Extensions.Logging;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace CoreAgent.Infrastructure.Services.ProtocolLogHandlers
-{
- ///
- /// RAN协议WebSocket消息处理器
- /// 负责处理无线接入网(RAN)相关的WebSocket消息,包括配置获取、日志获取等功能
- ///
- public class RanLogMessageHandler : ICustomMessageHandler, IDisposable
- {
- private readonly ILogger _logger;
- private int _messageId = 0;
- private string _currentMessageId = string.Empty;
- private readonly Action _messageCallback;
- private readonly ICellularNetworkContext _networkContext;
- private readonly BlockingCollection<(string MessageData, IObserverCustomWebSocketClient Observer)> _messageQueue;
- private readonly CancellationTokenSource _cancellationTokenSource;
- private readonly Task _processTask;
- private bool _disposed;
-
- ///
- /// 初始化RAN协议消息处理器
- ///
- /// 日志记录器
- /// 蜂窝网络上下文
- /// 消息回调处理函数
- public RanLogMessageHandler(ILogger logger, ICellularNetworkContext context, Action action)
- {
- _logger = logger ?? throw new ArgumentNullException(nameof(logger));
- _messageCallback = action ?? throw new ArgumentNullException(nameof(action));
- _networkContext = context ?? throw new ArgumentNullException(nameof(context));
-
- _messageQueue = new BlockingCollection<(string, IObserverCustomWebSocketClient)>();
- _cancellationTokenSource = new CancellationTokenSource();
- _processTask = Task.Run(ProcessMessageQueue);
-
- _logger.LogInformation("RAN协议消息处理器初始化完成,消息队列已启动");
- }
-
- ///
- /// 处理接收到的WebSocket消息
- /// 将消息加入处理队列,由队列处理器异步处理
- ///
- /// 接收到的消息数据
- /// WebSocket客户端观察者
- public void HandleMessage(string messageData, IObserverCustomWebSocketClient observer)
- {
- try
- {
- _logger.LogDebug("将消息加入处理队列: {MessageData}", messageData);
- _messageQueue.Add((messageData, observer));
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "将消息加入队列时发生错误: {MessageData}", messageData);
- }
- }
-
- ///
- /// 处理消息队列中的消息
- /// 持续从队列中获取消息并处理,直到队列关闭或取消
- ///
- private async Task ProcessMessageQueue()
- {
- try
- {
- _logger.LogInformation("开始处理消息队列");
- foreach (var (messageData, observer) in _messageQueue.GetConsumingEnumerable(_cancellationTokenSource.Token))
- {
- try
- {
- await ProcessMessageAsync(messageData, observer);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "处理队列中的消息时发生错误: {MessageData}", messageData);
- }
- }
- }
- catch (OperationCanceledException)
- {
- _logger.LogInformation("消息队列处理已取消");
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "消息队列处理过程中发生错误");
- }
- }
-
- ///
- /// 处理单条消息
- /// 解析消息类型并分发到对应的处理方法
- ///
- /// 消息数据
- /// WebSocket客户端观察者
- private async Task ProcessMessageAsync(string messageData, IObserverCustomWebSocketClient observer)
- {
- try
- {
- _logger.LogDebug("开始处理RAN协议消息: {MessageData}", messageData);
- var jsonData = JObject.Parse(messageData);
- string messageType = jsonData["message"]!.ToString();
- _logger.LogInformation("收到RAN协议消息类型: {MessageType}", messageType);
- await ProcessMessageByTypeAsync(messageType, jsonData, observer);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "处理RAN协议消息时发生错误: {MessageData}", messageData);
- }
- }
-
- ///
- /// 根据消息类型分发到对应的处理方法
- ///
- /// 消息类型
- /// 消息数据
- /// WebSocket客户端观察者
- private async Task ProcessMessageByTypeAsync(string messageType, JObject data, IObserverCustomWebSocketClient observer)
- {
- _logger.LogDebug("开始处理RAN协议消息类型: {MessageType}", messageType);
- switch (messageType)
- {
- case "ready":
- await HandleReadyMessageAsync(observer);
- break;
- case "config_get":
- await HandleConfigGetMessageAsync(data, observer);
- break;
- case "config_set":
- await HandleConfigSetMessageAsync(observer);
- break;
- case "log_get":
- await HandleLogGetMessageAsync(data, observer);
- break;
- case "stats":
- await HandleStatsMessageAsync(observer);
- break;
- default:
- _logger.LogWarning("收到未知的RAN协议消息类型: {MessageType}", messageType);
- break;
- }
- }
-
- ///
- /// 处理ready消息
- /// 发送config_get请求,准备获取配置信息
- ///
- /// WebSocket客户端观察者
- private async Task HandleReadyMessageAsync(IObserverCustomWebSocketClient observer)
- {
- string readyResponse = JObject.FromObject(new { message = "config_get", message_id = Interlocked.Increment(ref _messageId) }).ToString();
- _logger.LogInformation("发送ready响应: {Response}", readyResponse);
- await Task.Run(() => observer.SendMessage(readyResponse));
- _currentMessageId = _messageId.ToString();
- }
-
- ///
- /// 处理config_get消息
- /// 发送统计信息和基础层日志配置
- ///
- /// 消息数据
- /// WebSocket客户端观察者
- private async Task HandleConfigGetMessageAsync(JObject data, IObserverCustomWebSocketClient observer)
- {
- if (_currentMessageId == data["message_id"]!.ToString())
- {
- _logger.LogInformation("处理config_get请求");
- var responseArray = new JArray();
-
- var statsConfig = new { message = "stats", message_id = Interlocked.Increment(ref _messageId), rf = false, samples = false };
- responseArray.Add(JObject.FromObject(statsConfig));
-
- string baseLayerConfig = ConfigureBaseLayerLogs(data);
- responseArray.Add(JObject.Parse(baseLayerConfig));
-
- _logger.LogInformation("发送config_get响应: {Response}", responseArray.ToString());
- await Task.Run(() => observer.SendMessage(responseArray.ToString()));
- }
- else
- {
- _logger.LogWarning("config_get消息ID不匹配: 收到={ReceivedId}, 期望={ExpectedId}",
- data["message_id"]!.ToString(), _currentMessageId);
- }
- }
-
- ///
- /// 处理config_set消息
- /// 发送层日志配置
- ///
- /// WebSocket客户端观察者
- private async Task HandleConfigSetMessageAsync(IObserverCustomWebSocketClient observer)
- {
- string configResponse = ConfigureLayerLogs(true);
- await Task.Run(() => observer.SendMessage(configResponse));
- _currentMessageId = _messageId.ToString();
- _logger.LogInformation("发送config_set响应: {Response}", configResponse);
- }
-
- ///
- /// 处理log_get消息
- /// 发送日志配置并触发回调
- ///
- /// 消息数据
- /// WebSocket客户端观察者
- private async Task HandleLogGetMessageAsync(JObject data, IObserverCustomWebSocketClient observer)
- {
- if (_currentMessageId == data["message_id"]!.ToString())
- {
- string logResponse = ConfigureLayerLogs(false);
- await Task.Run(() => observer.SendMessage(logResponse));
- _currentMessageId = _messageId.ToString();
- _logger.LogInformation("发送log_get响应: {Response}", logResponse);
- }
- else
- {
- _logger.LogWarning("log_get消息ID不匹配: 收到={ReceivedId}, 期望={ExpectedId}",
- data["message_id"]!.ToString(), _currentMessageId);
- }
- await Task.Run(() => _messageCallback.Invoke(data.ToString()));
- }
-
- ///
- /// 处理stats消息
- /// 发送统计信息请求
- ///
- /// WebSocket客户端观察者
- private async Task HandleStatsMessageAsync(IObserverCustomWebSocketClient observer)
- {
- string statsResponse = JObject.FromObject(new
- {
- message = "stats",
- message_id = Interlocked.Increment(ref _messageId),
- rf = false,
- samples = false
- }).ToString();
- await Task.Run(() => observer.SendMessage(statsResponse));
- _logger.LogInformation("发送stats响应: {Response}", statsResponse);
- }
-
- ///
- /// 配置基础层日志
- /// 设置各种日志级别的开关状态
- ///
- /// 配置键值对
- /// 是否关闭系统信息
- /// 配置后的JSON字符串
- private string ConfigureBaseLayerLogs(JObject keyValues, bool isCloseSystemInfo = false)
- {
- _logger.LogDebug("开始配置基础层日志: {KeyValues}", keyValues.ToString());
-
- // 移除不需要的配置项
- if (keyValues.Remove("rotate") && keyValues.Remove("path") && keyValues.Remove("count"))
- {
- _logger.LogDebug("已移除rotate、path和count配置项");
- }
-
- // 设置系统信息相关配置
- keyValues["bcch"] = isCloseSystemInfo;
- keyValues["cch"] = isCloseSystemInfo;
- keyValues["cell_meas"] = isCloseSystemInfo;
- keyValues["csi"] = isCloseSystemInfo;
-
- // 设置其他配置项
- keyValues["dci_size"] = false;
- keyValues["mib"] = false;
- keyValues["rep"] = false;
- keyValues["signal"] = false;
-
- var configMessage = new
- {
- message = "config_set",
- logs = keyValues,
- message_id = Interlocked.Increment(ref _messageId),
- };
-
- string response = JObject.FromObject(configMessage).ToString();
- _logger.LogInformation("基础层日志配置完成: {Response}", response);
- return response;
- }
-
- ///
- /// 配置层日志
- /// 设置日志超时、计数等参数
- ///
- /// 是否包含头部信息
- /// 配置后的JSON字符串
- private string ConfigureLayerLogs(bool includeHeaders = false)
- {
- _logger.LogDebug("开始配置层日志: IncludeHeaders={IncludeHeaders}", includeHeaders);
-
- var logConfig = new BaseNetworkLog
- {
- Timeout = includeHeaders ? 0 : 1,
- MinLogCount = 64,
- MaxLogCount = 2048,
- LayerConfig = _networkContext.NetworkLogs.RanLog,
- Message = "log_get",
- IncludeHeaders = includeHeaders,
- MessageId = Interlocked.Increment(ref _messageId),
- };
-
- string response = JObject.FromObject(logConfig).ToString();
- _logger.LogInformation("层日志配置完成: {Response}", response);
- return response;
- }
-
- ///
- /// 释放资源
- ///
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// 释放资源的具体实现
- ///
- /// 是否正在释放托管资源
- protected virtual void Dispose(bool disposing)
- {
- if (!_disposed)
- {
- if (disposing)
- {
- _cancellationTokenSource.Cancel();
- _messageQueue.CompleteAdding();
- try
- {
- _processTask.Wait(TimeSpan.FromSeconds(5));
- }
- catch (AggregateException ex)
- {
- _logger.LogError(ex, "等待消息队列处理完成时发生错误");
- }
- _messageQueue.Dispose();
- _cancellationTokenSource.Dispose();
- }
- _disposed = true;
- }
- }
-
- ///
- /// 析构函数
- ///
- ~RanLogMessageHandler()
- {
- Dispose(false);
- }
- }
-}