Skip to content

Commit e743b2f

Browse files
committed
++ cachr
1 parent f3aa441 commit e743b2f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

storage/cache.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ NHTFlowCache::NHTFlowCache() :
7272

7373
NHTFlowCache::~NHTFlowCache()
7474
{
75-
close();
75+
NHTFlowCache::close();
7676
print_report();
7777
}
7878

@@ -192,6 +192,7 @@ void NHTFlowCache::finish()
192192
if (m_hashes_in_ctt.size() > 0){
193193
throw "bad CTT size";
194194
}
195+
std::cout << "CTT hash collisions: " << m_ctt_hash_collision << std::endl;
195196
}
196197

197198
void NHTFlowCache::flush(Packet &pkt, size_t flow_index, int return_flags)
@@ -286,6 +287,14 @@ void NHTFlowCache::create_record(const Packet& packet, size_t flow_index, size_t
286287
m_flow_table[flow_index]->m_flow.flow_hash_ctt = packet.cttmeta.flow_hash;
287288
if (only_metadata_required(m_flow_table[flow_index]->m_flow)) {
288289
m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
290+
if (m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt] >= 2) {
291+
m_ctt_hash_collision++;
292+
std::vector<FlowRecord*> filtered;
293+
294+
std::copy_if(m_flow_table, m_flow_table + m_cache_size, std::back_inserter(filtered),
295+
[&](FlowRecord* flow) { return flow->m_flow.flow_hash_ctt == m_flow_table[flow_index]->m_flow.flow_hash_ctt; });
296+
filtered.size();
297+
}
289298
auto x = m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt];
290299
m_ctt_controller.create_record(m_flow_table[flow_index]->m_flow.flow_hash_ctt, m_flow_table[flow_index]->m_flow.time_first);
291300
m_flow_table[flow_index]->is_in_ctt = true;
@@ -302,6 +311,14 @@ void NHTFlowCache::try_to_add_flow_to_ctt(size_t flow_index) noexcept
302311
if (only_metadata_required(m_flow_table[flow_index]->m_flow)) {
303312
m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
304313
auto x = m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt];
314+
if (m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt] >= 2) {
315+
m_ctt_hash_collision++;
316+
std::vector<FlowRecord*> filtered;
317+
318+
std::copy_if(m_flow_table, m_flow_table + m_cache_size, std::back_inserter(filtered),
319+
[&](FlowRecord* flow) { return flow->m_flow.flow_hash_ctt == m_flow_table[flow_index]->m_flow.flow_hash_ctt; });
320+
filtered.size();
321+
}
305322
m_ctt_controller.create_record(m_flow_table[flow_index]->m_flow.flow_hash_ctt, m_flow_table[flow_index]->m_flow.time_first);
306323
m_flow_table[flow_index]->is_in_ctt = true;
307324
}

storage/cache.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class NHTFlowCache : TelemetryUtils, public StoragePlugin
117117
FlowEndReasonStats m_flow_end_reason_stats = {};
118118
FlowRecordStats m_flow_record_stats = {};
119119
FlowCacheStats m_cache_stats = {};
120+
size_t m_ctt_hash_collision{0};
120121
#ifdef WITH_CTT
121122
void set_ctt_config(const std::string& device_name, unsigned comp_index) override;
122123
std::string m_ctt_device;

0 commit comments

Comments
 (0)