Skip to content

Commit b59ddf7

Browse files
committed
++ cache
1 parent 0e67254 commit b59ddf7

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

storage/cache.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,7 @@ void NHTFlowCache::create_record(const Packet& packet, size_t flow_index, size_t
279279
}
280280
m_flow_table[flow_index]->m_flow.flow_hash_ctt = packet.cttmeta.flow_hash;
281281
if (only_metadata_required(m_flow_table[flow_index]->m_flow)) {
282-
if (m_hashes_in_ctt.find(m_flow_table[flow_index]->m_flow.flow_hash_ctt) != m_hashes_in_ctt.end())
283-
{
284-
//throw "hash collision in create record!";
285-
}
286-
m_hashes_in_ctt.insert(m_flow_table[flow_index]->m_flow.flow_hash_ctt);
282+
m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
287283
m_ctt_controller.create_record(m_flow_table[flow_index]->m_flow.flow_hash_ctt, m_flow_table[flow_index]->m_flow.time_first);
288284
m_flow_table[flow_index]->is_in_ctt = true;
289285
}
@@ -297,11 +293,7 @@ void NHTFlowCache::try_to_add_flow_to_ctt(size_t flow_index) noexcept
297293
return;
298294
}
299295
if (only_metadata_required(m_flow_table[flow_index]->m_flow)) {
300-
if (m_hashes_in_ctt.find(m_flow_table[flow_index]->m_flow.flow_hash_ctt) != m_hashes_in_ctt.end())
301-
{
302-
//throw "hash collision in try_to_add_flow_to_ctt!";
303-
}
304-
m_hashes_in_ctt.insert(m_flow_table[flow_index]->m_flow.flow_hash_ctt);
296+
m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
305297
m_ctt_controller.create_record(m_flow_table[flow_index]->m_flow.flow_hash_ctt, m_flow_table[flow_index]->m_flow.time_first);
306298
m_flow_table[flow_index]->is_in_ctt = true;
307299
}
@@ -373,11 +365,13 @@ bool NHTFlowCache::try_to_export(size_t flow_index, bool call_pre_export, const
373365
#ifdef WITH_CTT
374366
void NHTFlowCache::send_export_request_to_ctt(size_t ctt_flow_hash) noexcept
375367
{
376-
if (m_hashes_in_ctt.find(ctt_flow_hash) == m_hashes_in_ctt.end())
368+
if (--m_hashes_in_ctt[ctt_flow_hash] < 0)
377369
{
378370
throw "missing hash in send_export_request_to_ctt!";
379371
}
380-
m_hashes_in_ctt.erase(ctt_flow_hash);
372+
if (m_hashes_in_ctt[ctt_flow_hash] == 0) {
373+
m_hashes_in_ctt.erase(ctt_flow_hash);
374+
}
381375
m_ctt_controller.export_record(ctt_flow_hash);
382376
}
383377
#endif /* WITH_CTT */

storage/cache.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <optional>
3939
#include <ipfixprobe/flowifc.hpp>
4040
#include <ipfixprobe/telemetry-utils.hpp>
41-
#include <unordered_set>
41+
#include <unordered_map>
4242
#include "fragmentationCache/fragmentationCache.hpp"
4343
#include "cacheOptParser.hpp"
4444
#include "flowKey.tpp"
@@ -122,7 +122,7 @@ class NHTFlowCache : TelemetryUtils, public StoragePlugin
122122
std::string m_ctt_device;
123123
unsigned m_ctt_comp_index;
124124
CttController m_ctt_controller;
125-
std::unordered_set<size_t> m_hashes_in_ctt;
125+
std::unordered_map<size_t, size_t> m_hashes_in_ctt;
126126
#endif /* WITH_CTT */
127127

128128
void try_to_fill_ports_to_fragmented_packet(Packet& packet);

0 commit comments

Comments
 (0)