|
|
@ -16,6 +16,7 @@ public class NetworkConfigCopier : INetworkConfigCopier |
|
|
|
private readonly ILogger<NetworkConfigCopier> _logger; |
|
|
|
private readonly ISystemCommandExecutor _commandExecutor; |
|
|
|
private const string COM_ADDR_TEMPLATE = "cat {0} | grep com_addr | awk -F'\"' '{{print $4}}'"; |
|
|
|
private const string PLMN_TEMPLATE = "cat {0} | grep plmn | awk -F'\"' '{{print $4}}'"; |
|
|
|
|
|
|
|
public NetworkConfigCopier( |
|
|
|
ILogger<NetworkConfigCopier> logger, |
|
|
@ -38,13 +39,6 @@ public class NetworkConfigCopier : INetworkConfigCopier |
|
|
|
// 复制 RAG 配置文件
|
|
|
|
if (!string.IsNullOrEmpty(networkConfig.RagConfig)) |
|
|
|
{ |
|
|
|
// 获取com_addr值
|
|
|
|
var (isSuccess, comAddr, errorMessage) = await GetComAddrValueAsync(networkConfig.RagConfig, "RAG"); |
|
|
|
if (!isSuccess) |
|
|
|
{ |
|
|
|
return NetworkConfigCopyResult.Failure($"RAG配置文件验证失败: {errorMessage}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!CopyConfigFile(networkConfig.RagConfig, appSettings.RanConfigDirectory, |
|
|
|
path => networkConfig.RagConfig = path, "RAG")) |
|
|
|
{ |
|
|
@ -57,13 +51,6 @@ public class NetworkConfigCopier : INetworkConfigCopier |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(config.CoreNetworkConfig)) |
|
|
|
{ |
|
|
|
// 获取CN com_addr值
|
|
|
|
var (isSuccess, comAddr, errorMessage) = await GetComAddrValueAsync(config.CoreNetworkConfig, "CN"); |
|
|
|
if (!isSuccess) |
|
|
|
{ |
|
|
|
return NetworkConfigCopyResult.Failure($"CN配置文件验证失败: {errorMessage}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!CopyConfigFile(config.CoreNetworkConfig, appSettings.MmeConfigDirectory, |
|
|
|
path => config.CoreNetworkConfig = path, "核心网络")) |
|
|
|
{ |
|
|
@ -73,13 +60,6 @@ public class NetworkConfigCopier : INetworkConfigCopier |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(config.ImsConfig)) |
|
|
|
{ |
|
|
|
// 获取IMS com_addr值
|
|
|
|
var (isSuccess, comAddr, errorMessage) = await GetComAddrValueAsync(config.ImsConfig, "IMS"); |
|
|
|
if (!isSuccess) |
|
|
|
{ |
|
|
|
return NetworkConfigCopyResult.Failure($"IMS配置文件验证失败: {errorMessage}"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!CopyConfigFile(config.ImsConfig, appSettings.MmeConfigDirectory, |
|
|
|
path => config.ImsConfig = path, "IMS")) |
|
|
|
{ |
|
|
@ -132,6 +112,48 @@ public class NetworkConfigCopier : INetworkConfigCopier |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取配置文件中的 plmn 值
|
|
|
|
/// </summary>
|
|
|
|
private async Task<(bool IsSuccess, List<string> Plmns, string ErrorMessage)> GetPlmnValuesAsync(string configPath, string configType) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(configPath)) |
|
|
|
{ |
|
|
|
return (false, null, $"{configType}配置文件路径为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!File.Exists(configPath)) |
|
|
|
{ |
|
|
|
return (false, null, $"{configType}配置文件不存在: {configPath}"); |
|
|
|
} |
|
|
|
|
|
|
|
var result = await _commandExecutor.ExecuteCommandAsync( |
|
|
|
string.Format(PLMN_TEMPLATE, configPath), |
|
|
|
new CancellationTokenSource()); |
|
|
|
|
|
|
|
if (result.IsSuccess) |
|
|
|
{ |
|
|
|
var plmns = result.Output |
|
|
|
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) |
|
|
|
.Select(p => p.Trim()) |
|
|
|
.Where(p => !string.IsNullOrEmpty(p)) |
|
|
|
.Distinct() |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
if (plmns.Count == 0) |
|
|
|
{ |
|
|
|
return (false, null, $"{configType}配置文件中未找到 plmn 值"); |
|
|
|
} |
|
|
|
|
|
|
|
_logger.LogInformation("获取到{ConfigType} plmn值: {Plmns}", configType, string.Join(", ", plmns)); |
|
|
|
return (true, plmns, null); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return (false, null, $"获取{configType} plmn值失败: {result.Error}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void EnsureDirectoriesExist(AppSettings appSettings) |
|
|
|
{ |
|
|
|
if (!Directory.Exists(appSettings.TempDirectory)) |
|
|
@ -177,4 +199,74 @@ public class NetworkConfigCopier : INetworkConfigCopier |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取所有配置文件的 IP 端点信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="networkConfig">网络配置</param>
|
|
|
|
/// <returns>(EndPoints: IP 端点信息集合, HasAnyEndPoint: 是否成功获取到任何端点信息)</returns>
|
|
|
|
public async Task<(NetworkIPEndPoints EndPoints, bool HasAnyEndPoint)> GetComAddrInfoAsync(NetworkConfiguration networkConfig) |
|
|
|
{ |
|
|
|
var endPoints = new NetworkIPEndPoints(); |
|
|
|
bool hasAnyEndPoint = false; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
// 获取 RAN com_addr 和 plmn
|
|
|
|
if (!string.IsNullOrEmpty(networkConfig.RagConfig)) |
|
|
|
{ |
|
|
|
var (isSuccess, comAddr, _) = await GetComAddrValueAsync(networkConfig.RagConfig, "RAG"); |
|
|
|
var (plmnSuccess, plmns, _) = await GetPlmnValuesAsync(networkConfig.RagConfig, "RAG"); |
|
|
|
|
|
|
|
if (isSuccess && plmnSuccess) |
|
|
|
{ |
|
|
|
endPoints.RanEndPoint = new RanIPEndPoint |
|
|
|
{ |
|
|
|
ComAddr = comAddr, |
|
|
|
Plmns = plmns |
|
|
|
}; |
|
|
|
hasAnyEndPoint = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取 CN 和 IMS com_addr
|
|
|
|
foreach (var config in networkConfig.CoreOrImsConfigs) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(config.CoreNetworkConfig)) |
|
|
|
{ |
|
|
|
var (isSuccess, comAddr, _) = await GetComAddrValueAsync(config.CoreNetworkConfig, "CN"); |
|
|
|
if (isSuccess) |
|
|
|
{ |
|
|
|
endPoints.CnEndPoints.Add(new CnIPEndPoint |
|
|
|
{ |
|
|
|
ComAddr = comAddr, |
|
|
|
Plmn = config.Plmn |
|
|
|
}); |
|
|
|
hasAnyEndPoint = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(config.ImsConfig)) |
|
|
|
{ |
|
|
|
var (isSuccess, comAddr, _) = await GetComAddrValueAsync(config.ImsConfig, "IMS"); |
|
|
|
if (isSuccess) |
|
|
|
{ |
|
|
|
endPoints.ImsEndPoints.Add(new ImsIPEndPoint |
|
|
|
{ |
|
|
|
ComAddr = comAddr, |
|
|
|
Plmn = config.Plmn |
|
|
|
}); |
|
|
|
hasAnyEndPoint = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return (EndPoints: endPoints, HasAnyEndPoint: hasAnyEndPoint); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
_logger.LogError(ex, "获取 IP 端点信息时发生错误"); |
|
|
|
return (EndPoints: endPoints, HasAnyEndPoint: false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |