89 lines
2.8 KiB
C++
89 lines
2.8 KiB
C++
|
|
#include "config_template.hpp"
|
||
|
|
#include <sstream>
|
||
|
|
#include <cmath>
|
||
|
|
|
||
|
|
ConfigTemplate::ConfigTemplate(std::string scenarioName,
|
||
|
|
std::vector<std::string> components,
|
||
|
|
std::string topologyRef,
|
||
|
|
uint32_t portsPerCabinet,
|
||
|
|
double spareRatio)
|
||
|
|
: scenarioName(std::move(scenarioName))
|
||
|
|
, components(std::move(components))
|
||
|
|
, topologyRef(std::move(topologyRef))
|
||
|
|
, portsPerCabinet(portsPerCabinet)
|
||
|
|
, spareRatio(spareRatio)
|
||
|
|
{}
|
||
|
|
|
||
|
|
std::string ConfigTemplate::generateBomSummary(uint32_t cabinetCount) const {
|
||
|
|
uint32_t totalPorts = portsPerCabinet * cabinetCount;
|
||
|
|
uint32_t sparePorts = static_cast<uint32_t>(std::round(totalPorts * spareRatio));
|
||
|
|
uint32_t totalWithSpare = totalPorts + sparePorts;
|
||
|
|
|
||
|
|
std::ostringstream oss;
|
||
|
|
oss << "场景: " << scenarioName << "\n"
|
||
|
|
<< " 机柜数量: " << cabinetCount << "\n"
|
||
|
|
<< " 基础端口量: " << totalPorts << "\n"
|
||
|
|
<< " 备用余量 (" << (spareRatio * 100.0) << "%): " << sparePorts << "\n"
|
||
|
|
<< " 含余量总端口数: " << totalWithSpare << "\n"
|
||
|
|
<< " 组件清单:\n";
|
||
|
|
for (const auto& comp : components) {
|
||
|
|
oss << " - " << comp << "\n";
|
||
|
|
}
|
||
|
|
oss << " 拓扑参考: " << topologyRef << "\n";
|
||
|
|
return oss.str();
|
||
|
|
}
|
||
|
|
|
||
|
|
std::string ConfigTemplate::summary() const {
|
||
|
|
std::ostringstream oss;
|
||
|
|
oss << "配置模板: " << scenarioName << "\n"
|
||
|
|
<< " 单柜端口密度: " << portsPerCabinet << "\n"
|
||
|
|
<< " 备用余量比例: " << (spareRatio * 100.0) << "%\n"
|
||
|
|
<< " 拓扑: " << topologyRef << "\n";
|
||
|
|
return oss.str();
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<ConfigTemplate> ConfigTemplate::builtInTemplates() {
|
||
|
|
std::vector<ConfigTemplate> templates;
|
||
|
|
|
||
|
|
templates.emplace_back(
|
||
|
|
"数据中心LC单模预端接",
|
||
|
|
std::vector<std::string>{
|
||
|
|
"LC单模适配器(双工)",
|
||
|
|
"LC单模尾纤(1.5m)",
|
||
|
|
"LC单模跳线(3m)",
|
||
|
|
"光纤收发器 SFP+ 10G"
|
||
|
|
},
|
||
|
|
"topo_dc_lc_sm_v1",
|
||
|
|
48,
|
||
|
|
0.15
|
||
|
|
);
|
||
|
|
|
||
|
|
templates.emplace_back(
|
||
|
|
"机房SC多模通用配线",
|
||
|
|
std::vector<std::string>{
|
||
|
|
"SC多模适配器(双工)",
|
||
|
|
"SC多模尾纤(2m)",
|
||
|
|
"SC多模跳线(5m)",
|
||
|
|
"光纤收发器 SFP 1G"
|
||
|
|
},
|
||
|
|
"topo_room_sc_mm_v1",
|
||
|
|
24,
|
||
|
|
0.10
|
||
|
|
);
|
||
|
|
|
||
|
|
templates.emplace_back(
|
||
|
|
"数据中心MPO高密度预端接",
|
||
|
|
std::vector<std::string>{
|
||
|
|
"MPO适配器(12芯)",
|
||
|
|
"MPO干线光缆(12芯)",
|
||
|
|
"MPO-LC分支跳线",
|
||
|
|
"光纤收发器 QSFP 40G"
|
||
|
|
},
|
||
|
|
"topo_dc_mpo_high_density_v1",
|
||
|
|
96,
|
||
|
|
0.20
|
||
|
|
);
|
||
|
|
|
||
|
|
return templates;
|
||
|
|
}
|