Skip to content

Commit 7375dc6

Browse files
committed
++ cache
1 parent f5b3724 commit 7375dc6

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

storage/cache.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ void NHTFlowCache::push_to_export_queue(size_t flow_index) noexcept
175175

176176
void NHTFlowCache::finish()
177177
{
178-
auto it = std::find_if(m_hashes_in_ctt.begin(), m_hashes_in_ctt.end(), [](const auto& pair) {
178+
/*auto it = std::find_if(m_hashes_in_ctt.begin(), m_hashes_in_ctt.end(), [](const auto& pair) {
179179
return pair.second <= 0;
180-
});
180+
});*/
181181
for (decltype(m_cache_size) i = 0; i < m_cache_size; i++) {
182182
if (!m_flow_table[i]->is_empty()) {
183183
#ifdef WITH_CTT
@@ -189,10 +189,10 @@ void NHTFlowCache::finish()
189189
export_flow(i, FLOW_END_FORCED);
190190
}
191191
}
192-
if (m_hashes_in_ctt.size() > 0){
192+
/*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;
195+
std::cout << "CTT hash collisions: " << m_ctt_hash_collision << std::endl;*/
196196
}
197197

198198
void NHTFlowCache::flush(Packet &pkt, size_t flow_index, int return_flags)
@@ -269,6 +269,12 @@ bool NHTFlowCache::try_to_export_on_inactive_timeout(size_t flow_index, const ti
269269
return false;
270270
}
271271

272+
bool NHTFlowCache::needs_to_be_offloaded(size_t flow_index) const noexcept
273+
{
274+
return only_metadata_required(m_flow_table[flow_index]->m_flow) && m_flow_table[flow_index]->m_flow.src_packets + m_flow_table[flow_index]->m_flow.dst_packets > 30;
275+
}
276+
277+
272278
void NHTFlowCache::create_record(const Packet& packet, size_t flow_index, size_t hash_value) noexcept
273279
{
274280
m_cache_stats.flows_in_cache++;
@@ -285,8 +291,8 @@ void NHTFlowCache::create_record(const Packet& packet, size_t flow_index, size_t
285291
return;
286292
}
287293
m_flow_table[flow_index]->m_flow.flow_hash_ctt = packet.cttmeta.flow_hash;
288-
if (only_metadata_required(m_flow_table[flow_index]->m_flow)) {
289-
m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
294+
if (needs_to_be_offloaded(flow_index)) {
295+
/*m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
290296
if (m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt] >= 2) {
291297
m_ctt_hash_collision++;
292298
std::vector<FlowRecord*> filtered;
@@ -295,7 +301,7 @@ void NHTFlowCache::create_record(const Packet& packet, size_t flow_index, size_t
295301
[&](FlowRecord* flow) { return flow->m_flow.flow_hash_ctt == m_flow_table[flow_index]->m_flow.flow_hash_ctt; });
296302
filtered.size();
297303
}
298-
auto x = m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt];
304+
auto x = m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt];*/
299305
m_ctt_controller.create_record(m_flow_table[flow_index]->m_flow.flow_hash_ctt, m_flow_table[flow_index]->m_flow.time_first);
300306
m_flow_table[flow_index]->is_in_ctt = true;
301307
}
@@ -308,8 +314,8 @@ void NHTFlowCache::try_to_add_flow_to_ctt(size_t flow_index) noexcept
308314
if (m_flow_table[flow_index]->is_in_ctt || m_flow_table[flow_index]->m_flow.flow_hash_ctt == 0) {
309315
return;
310316
}
311-
if (only_metadata_required(m_flow_table[flow_index]->m_flow)) {
312-
m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
317+
if (needs_to_be_offloaded(flow_index)) {
318+
/*m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt]++;
313319
auto x = m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt];
314320
if (m_hashes_in_ctt[m_flow_table[flow_index]->m_flow.flow_hash_ctt] >= 2) {
315321
m_ctt_hash_collision++;
@@ -318,7 +324,7 @@ void NHTFlowCache::try_to_add_flow_to_ctt(size_t flow_index) noexcept
318324
std::copy_if(m_flow_table.begin(), m_flow_table.end(), std::back_inserter(filtered),
319325
[&](FlowRecord* flow) { return flow->m_flow.flow_hash_ctt == m_flow_table[flow_index]->m_flow.flow_hash_ctt; });
320326
filtered.size();
321-
}
327+
}*/
322328
m_ctt_controller.create_record(m_flow_table[flow_index]->m_flow.flow_hash_ctt, m_flow_table[flow_index]->m_flow.time_first);
323329
m_flow_table[flow_index]->is_in_ctt = true;
324330
}
@@ -390,13 +396,13 @@ bool NHTFlowCache::try_to_export(size_t flow_index, bool call_pre_export, const
390396
#ifdef WITH_CTT
391397
void NHTFlowCache::send_export_request_to_ctt(size_t ctt_flow_hash) noexcept
392398
{
393-
if (--m_hashes_in_ctt[ctt_flow_hash] < 0)
399+
/*if (--m_hashes_in_ctt[ctt_flow_hash] < 0)
394400
{
395401
throw "missing hash in send_export_request_to_ctt!";
396402
}
397403
if (m_hashes_in_ctt[ctt_flow_hash] == 0) {
398404
m_hashes_in_ctt.erase(ctt_flow_hash);
399-
}
405+
}*/
400406
m_ctt_controller.export_record(ctt_flow_hash);
401407
}
402408
#endif /* WITH_CTT */

storage/cache.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ 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};
121120
#ifdef WITH_CTT
122121
void set_ctt_config(const std::string& device_name, unsigned comp_index) override;
123122
std::string m_ctt_device;
124123
unsigned m_ctt_comp_index;
125124
CttController m_ctt_controller;
126-
std::unordered_map<size_t, int> m_hashes_in_ctt;
125+
//std::unordered_map<size_t, int> m_hashes_in_ctt;
126+
//size_t m_ctt_hash_collision{0};
127127
#endif /* WITH_CTT */
128128

129129
void try_to_fill_ports_to_fragmented_packet(Packet& packet);
@@ -152,6 +152,7 @@ class NHTFlowCache : TelemetryUtils, public StoragePlugin
152152
void send_export_request_to_ctt(size_t ctt_flow_hash) noexcept;
153153
void export_expired(const timeval& now);
154154
void try_to_add_flow_to_ctt(size_t flow_index) noexcept;
155+
bool needs_to_be_offloaded(size_t flow_index) const noexcept;
155156
};
156157

157158
}

0 commit comments

Comments
 (0)