-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetStat.cpp
More file actions
139 lines (120 loc) · 5.2 KB
/
Copy pathnetStat.cpp
File metadata and controls
139 lines (120 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "netStat.h"
#include <limits>
#include <numeric>
netStat::netStat(double LambdaParam, size_t HostLimit, size_t HostSimplexLimit)
: HostLimit(HostLimit),
SessionLimit(HostSimplexLimit * HostLimit * HostLimit),
MAC_HostLimit(HostLimit * 10) {
// 初始化Lambdas
if (std::isnan(LambdaParam)) {
// 使用默认值
Lambdas = {5.0, 3.0, 1.0, 0.1, 0.01};
} else {
// 使用单个Lambda值
Lambdas = {LambdaParam};
}
// 初始化统计数据库
HT_jit.reset(new incStatDB(HostLimit * HostLimit));
HT_MI.reset(new incStatDB(MAC_HostLimit));
HT_H.reset(new incStatDB(HostLimit));
HT_Hp.reset(new incStatDB(SessionLimit));
}
std::vector<double> netStat::updateGetStats(
int IPtype, const std::string &srcMAC, const std::string &dstMAC,
const std::string &srcIP, const std::string &srcProtocol,
const std::string &dstIP, const std::string &dstProtocol, int datagramSize,
double timestamp) {
// MAC.IP: 源MAC-IP关系的统计
std::vector<double> MIstat(3 * Lambdas.size(), 0.0);
for (size_t i = 0; i < Lambdas.size(); ++i) {
std::vector<double> stats = HT_MI->update_get_1D_Stats(
srcMAC + srcIP, timestamp, datagramSize, Lambdas[i]);
std::copy(stats.begin(), stats.end(), MIstat.begin() + i * 3);
}
// Host-Host BW: 源IP和目标IP之间的双向流量行为统计
std::vector<double> HHstat(7 * Lambdas.size(), 0.0);
for (size_t i = 0; i < Lambdas.size(); ++i) {
std::vector<double> stats = HT_H->update_get_1D2D_Stats(
srcIP, dstIP, timestamp, datagramSize, Lambdas[i]);
std::copy(stats.begin(), stats.end(), HHstat.begin() + i * 7);
}
// Host-Host Jitter: 抖动统计
std::vector<double> HHstat_jit(3 * Lambdas.size(), 0.0);
for (size_t i = 0; i < Lambdas.size(); ++i) {
std::vector<double> stats = HT_jit->update_get_1D_Stats(
srcIP + dstIP, timestamp, 0, Lambdas[i], true);
std::copy(stats.begin(), stats.end(), HHstat_jit.begin() + i * 3);
}
// Host-Host BW: 基于协议的双向流量行为统计
std::vector<double> HpHpstat(7 * Lambdas.size(), 0.0);
if (srcProtocol == "arp") {
for (size_t i = 0; i < Lambdas.size(); ++i) {
std::vector<double> stats = HT_Hp->update_get_1D2D_Stats(
srcMAC, dstMAC, timestamp, datagramSize, Lambdas[i]);
std::copy(stats.begin(), stats.end(), HpHpstat.begin() + i * 7);
}
} else { // 其他协议(如TCP/UDP)
for (size_t i = 0; i < Lambdas.size(); ++i) {
std::vector<double> stats = HT_Hp->update_get_1D2D_Stats(
srcIP + srcProtocol, dstIP + dstProtocol, timestamp,
datagramSize, Lambdas[i]);
std::copy(stats.begin(), stats.end(), HpHpstat.begin() + i * 7);
}
}
// 连接所有统计数据成一个向量
std::vector<double> result;
result.reserve(MIstat.size() + HHstat.size() + HHstat_jit.size() +
HpHpstat.size());
result.insert(result.end(), MIstat.begin(), MIstat.end());
result.insert(result.end(), HHstat.begin(), HHstat.end());
result.insert(result.end(), HHstat_jit.begin(), HHstat_jit.end());
result.insert(result.end(), HpHpstat.begin(), HpHpstat.end());
return result;
}
std::vector<std::string> netStat::getNetStatHeaders() {
std::vector<std::string> MIstat_headers;
std::vector<std::string> Hstat_headers;
std::vector<std::string> HHstat_headers;
std::vector<std::string> HHjitstat_headers;
std::vector<std::string> HpHpstat_headers;
// 为每个Lambda生成对应的标题
for (size_t i = 0; i < Lambdas.size(); ++i) {
// MAC-IP关系标题
std::vector<std::string> mi_headers =
HT_MI->getHeaders_1D(Lambdas[i], "");
for (const auto &h : mi_headers) {
MIstat_headers.push_back("MI_dir_" + h);
}
// 主机-主机双向流量标题
std::vector<std::string> hh_headers =
HT_H->getHeaders_1D2D(Lambdas[i], nullptr, 2);
for (const auto &h : hh_headers) {
HHstat_headers.push_back("HH_" + h);
}
// 抖动统计标题
std::vector<std::string> jit_headers =
HT_jit->getHeaders_1D(Lambdas[i], "");
for (const auto &h : jit_headers) {
HHjitstat_headers.push_back("HH_jit_" + h);
}
// 协议级双向流量标题
std::vector<std::string> hphp_headers =
HT_Hp->getHeaders_1D2D(Lambdas[i], nullptr, 2);
for (const auto &h : hphp_headers) {
HpHpstat_headers.push_back("HpHp_" + h);
}
}
// 连接所有标题成一个向量
std::vector<std::string> result;
result.reserve(MIstat_headers.size() + Hstat_headers.size() +
HHstat_headers.size() + HHjitstat_headers.size() +
HpHpstat_headers.size());
result.insert(result.end(), MIstat_headers.begin(), MIstat_headers.end());
result.insert(result.end(), Hstat_headers.begin(), Hstat_headers.end());
result.insert(result.end(), HHstat_headers.begin(), HHstat_headers.end());
result.insert(result.end(), HHjitstat_headers.begin(),
HHjitstat_headers.end());
result.insert(result.end(), HpHpstat_headers.begin(),
HpHpstat_headers.end());
return result;
}