From: Russ Combs (rucombs) Date: Tue, 15 Mar 2016 13:12:42 +0000 (-0400) Subject: Merge pull request #335 in SNORT/snort3 from lru_cache_stats5 to master X-Git-Tag: 3.0.0-233~532 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cff746ef732b0d64c9c0bb75ceefdfd5d6f9679a;p=thirdparty%2Fsnort3.git Merge pull request #335 in SNORT/snort3 from lru_cache_stats5 to master Squashed commit of the following: commit bf528e34f81b4ee80b25b1e76ebb675928fb1fea Author: Steve Chew Date: Tue Mar 15 08:41:08 2016 -0400 Updated dev_notes.txt commit fc38136d2ee7846ac4fcc1382aaf50ca197c255f Author: Steve Chew Date: Tue Mar 15 07:37:33 2016 -0400 Moved LruCacheSharedStats struct definition. commit 04c3009392c0d990f89297de970a0c1899e71ed0 Author: Steve Chew Date: Tue Mar 15 06:56:59 2016 -0400 Removed size from peg counts. commit 110ea678e118ed2502d71df71f9146dfee5fe6d9 Author: Steve Chew Date: Fri Mar 11 16:19:46 2016 -0500 Changes based on review. commit dceb06c73adcfcdb320de4943c936a3c5abcb191 Author: Steve Chew Date: Thu Mar 10 18:05:19 2016 -0500 Add statistics to LruCachedShared. Create host_cache module to allow host_cache size to be configured. Renamed host_module to host_tracker_module. --- diff --git a/src/hash/CMakeLists.txt b/src/hash/CMakeLists.txt index 36f2ff86c..313fe4401 100644 --- a/src/hash/CMakeLists.txt +++ b/src/hash/CMakeLists.txt @@ -22,6 +22,7 @@ add_library( hash STATIC ${HASH_SOURCES} hashes.cc lru_cache_shared.h + lru_cache_shared.cc sfghash.cc sfhashfcn.cc sfprimetable.cc diff --git a/src/hash/Makefile.am b/src/hash/Makefile.am index b67c81125..41058226b 100644 --- a/src/hash/Makefile.am +++ b/src/hash/Makefile.am @@ -12,6 +12,7 @@ sfhashfcn.h libhash_a_SOURCES = \ hashes.cc \ +lru_cache_shared.cc \ sfghash.cc \ sfhashfcn.cc \ sfprimetable.cc sfprimetable.h \ diff --git a/src/hash/lru_cache_shared.cc b/src/hash/lru_cache_shared.cc new file mode 100644 index 000000000..c1031e42c --- /dev/null +++ b/src/hash/lru_cache_shared.cc @@ -0,0 +1,34 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2016-2016 Cisco and/or its affiliates. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License Version 2 as published +// by the Free Software Foundation. You may not use, modify or distribute +// this program under any other version of the GNU General Public License. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +//-------------------------------------------------------------------------- + +// lru_cache_shared.cc author Steve Chew + +#include "hash/lru_cache_shared.h" + +const PegInfo lru_cache_shared_peg_names[] = +{ + { "lru cache adds", "lru cache added new entry" }, + { "lru cache replaces", "lru cache replaced existing entry" }, + { "lru cache prunes", "lru cache pruned entry to make space for new entry" }, + { "lru cache find hits", "lru cache found entry in cache" }, + { "lru cache find misses", "lru cache did not find entry in cache" }, + { "lru cache removes", "lru cache found entry and removed it" }, + { "lru cache clears", "lru cache clear API calls" }, + { nullptr, nullptr }, +}; + diff --git a/src/hash/lru_cache_shared.h b/src/hash/lru_cache_shared.h index b3cde419a..86d0e916d 100644 --- a/src/hash/lru_cache_shared.h +++ b/src/hash/lru_cache_shared.h @@ -29,6 +29,22 @@ #include #include +#include "framework/counts.h" + +extern const PegInfo lru_cache_shared_peg_names[]; + +struct LruCacheSharedStats +{ + PegCount adds = 0; // An insert that added new entry. + PegCount replaces = 0; // An insert that replaced existing entry + PegCount prunes = 0; // When an old entry is removed to make + // room for a new entry. + PegCount find_hits = 0; // Found entry in cache. + PegCount find_misses = 0; // Did not find entry in cache. + PegCount removes = 0; // Found entry and removed it. + PegCount clears = 0; // Calls to clear API. +}; + template class LruCacheShared { @@ -59,6 +75,10 @@ public: return max_size; } + // Modify the maximum number of entries allowed in the cache. + // If the size is reduced, the oldest entries are removed. + bool set_max_size(size_t newsize); + // Add data to cache or replace data if it already exists. void insert(const Key& key, const Data& data); @@ -83,6 +103,16 @@ public: // least). std::vector > get_all_data(void); + const PegInfo* get_pegs() const + { + return lru_cache_shared_peg_names; + } + + PegCount* get_counts() const + { + return (PegCount*)&stats; + } + private: using LruList = std::list >; using LruListIter = typename LruList::iterator; @@ -101,8 +131,33 @@ private: // least recently used at the end. LruMap map; // Maps key to list iterator for fast lookup. + struct LruCacheSharedStats stats; }; +template +bool LruCacheShared::set_max_size(size_t newsize) +{ + LruListIter list_iter; + + if (newsize <= 0) + return false; // Not allowed to set size to zero. + + std::lock_guard cache_lock(cache_mutex); + + // Remove the oldest entries if we have to reduce cache size. + list_iter=list.end(); + while (current_size > newsize) + { + list_iter--; + current_size--; + map.erase(list_iter->first); + list.erase(list_iter); + } + + max_size = newsize; + return true; +} + template void LruCacheShared::insert(const Key& key, const Data& data) { @@ -116,6 +171,11 @@ void LruCacheShared::insert(const Key& key, const Data& data) current_size--; list.erase(map_iter->second); map.erase(map_iter); + stats.replaces++; + } + else + { + stats.adds++; } // Add key/data pair to front of list. @@ -132,6 +192,7 @@ void LruCacheShared::insert(const Key& key, const Data& data) list_iter--; map.erase(list_iter->first); list.erase(list_iter); + stats.prunes++; } else { @@ -147,7 +208,10 @@ bool LruCacheShared::find(const Key& key, Data& data, bool upda map_iter = map.find(key); if (map_iter == map.end()) + { + stats.find_misses++; return false; // Key is not in LruCache. + } data = map_iter->second->second; @@ -155,6 +219,7 @@ bool LruCacheShared::find(const Key& key, Data& data, bool upda if (update) list.splice(list.begin(), list, map_iter->second); + stats.find_hits++; return true; } @@ -171,6 +236,7 @@ bool LruCacheShared::remove(const Key& key) current_size--; list.erase(map_iter->second); map.erase(map_iter); + stats.removes++; return(true); } @@ -189,6 +255,7 @@ bool LruCacheShared::remove(const Key& key, Data& data) current_size--; list.erase(map_iter->second); map.erase(map_iter); + stats.removes++; return(true); } @@ -207,6 +274,7 @@ void LruCacheShared::clear(void) } current_size = 0; + stats.clears++; } template diff --git a/src/hash/test/CMakeLists.txt b/src/hash/test/CMakeLists.txt new file mode 100644 index 000000000..15da405f3 --- /dev/null +++ b/src/hash/test/CMakeLists.txt @@ -0,0 +1,3 @@ + +add_cpputest(lru_cache_shared_test hash) + diff --git a/src/hash/test/Makefile.am b/src/hash/test/Makefile.am index ac43653e5..adf8ceed6 100644 --- a/src/hash/test/Makefile.am +++ b/src/hash/test/Makefile.am @@ -7,5 +7,5 @@ lru_cache_shared_test TESTS = $(check_PROGRAMS) lru_cache_shared_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@ -lru_cache_shared_test_LDADD = @CPPUTEST_LDFLAGS@ +lru_cache_shared_test_LDADD = ../lru_cache_shared.o @CPPUTEST_LDFLAGS@ diff --git a/src/hash/test/lru_cache_shared_test.cc b/src/hash/test/lru_cache_shared_test.cc index f5c220f39..94906bf04 100644 --- a/src/hash/test/lru_cache_shared_test.cc +++ b/src/hash/test/lru_cache_shared_test.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include "time/stopwatch.h" @@ -153,6 +154,60 @@ TEST(lru_cache_shared, remove_test) CHECK(0 == vec.size()); } +// Test statistics counters. +TEST(lru_cache_shared, stats_test) +{ + std::string data; + LruCacheShared > lru_cache(5); + + for (int i = 0; i < 10; i++) + { + lru_cache.insert(i, std::to_string(i)); + } + + lru_cache.insert(8, "new-eight"); // Replace entries. + lru_cache.insert(9, "new-nine"); + + CHECK(5 == lru_cache.size()); + + lru_cache.find(7, data); // Hits + lru_cache.find(8, data); + lru_cache.find(9, data); + + lru_cache.remove(7); + lru_cache.remove(8); + lru_cache.remove(9, data); + CHECK("new-nine" == data); + + lru_cache.find(8, data); // Misses now that they're removed. + lru_cache.find(9, data); + + lru_cache.remove(100); // Removing a non-existant entry does not + // increase remove count. + + lru_cache.clear(); + + PegCount* stats = lru_cache.get_counts(); + + CHECK(stats[0] == 10); // adds + CHECK(stats[1] == 2); // replaces + CHECK(stats[2] == 5); // prunes + CHECK(stats[3] == 3); // find hits + CHECK(stats[4] == 2); // find misses + CHECK(stats[5] == 3); // removes + CHECK(stats[6] == 1); // clears + + // Check statistics names. + const PegInfo* pegs = lru_cache.get_pegs(); + CHECK(!strcmp(pegs[0].name, "lru cache adds")); + CHECK(!strcmp(pegs[1].name, "lru cache replaces")); + CHECK(!strcmp(pegs[2].name, "lru cache prunes")); + CHECK(!strcmp(pegs[3].name, "lru cache find hits")); + CHECK(!strcmp(pegs[4].name, "lru cache find misses")); + CHECK(!strcmp(pegs[5].name, "lru cache removes")); + CHECK(!strcmp(pegs[6].name, "lru cache clears")); +} + int main(int argc, char** argv) { return CommandLineTestRunner::RunAllTests(argc, argv); diff --git a/src/host_tracker/CMakeLists.txt b/src/host_tracker/CMakeLists.txt index 2d5d29b39..82cb8eb43 100644 --- a/src/host_tracker/CMakeLists.txt +++ b/src/host_tracker/CMakeLists.txt @@ -2,8 +2,10 @@ add_library( host_tracker STATIC host_cache.cc host_cache.h - host_module.cc - host_module.h + host_cache_module.cc + host_cache_module.h + host_tracker_module.cc + host_tracker_module.h host_tracker.cc host_tracker.h ) diff --git a/src/host_tracker/Makefile.am b/src/host_tracker/Makefile.am index 9a2460fe8..1fadc5388 100644 --- a/src/host_tracker/Makefile.am +++ b/src/host_tracker/Makefile.am @@ -4,8 +4,10 @@ noinst_LIBRARIES = libhost_tracker.a libhost_tracker_a_SOURCES = \ host_cache.cc \ host_cache.h \ -host_module.cc \ -host_module.h \ +host_cache_module.cc \ +host_cache_module.h \ +host_tracker_module.cc \ +host_tracker_module.h \ host_tracker.cc \ host_tracker.h diff --git a/src/host_tracker/dev_notes.txt b/src/host_tracker/dev_notes.txt index 1cc819ccf..faff25c54 100644 --- a/src/host_tracker/dev_notes.txt +++ b/src/host_tracker/dev_notes.txt @@ -13,3 +13,12 @@ can be shared between threads. * The HostTrackerModule is used to read in initial known information about hosts, populate HostTracker objects, and place them in the host_cache. +* The HostCache object is a thread-safe global LRU cache. The cache is +shared between all packet threads. It contains HostTracker objects and +provides a way for packet threads to store and retrieve data about +hosts as it is discovered. In the long run this cache will replace the +current Hosts table and will be the central, shared repository for data +about hosts. + +* The HostCacheModule is used to configure the HostCache's size. + diff --git a/src/host_tracker/host_cache_module.cc b/src/host_tracker/host_cache_module.cc new file mode 100644 index 000000000..e5b841c36 --- /dev/null +++ b/src/host_tracker/host_cache_module.cc @@ -0,0 +1,64 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2016-2016 Cisco and/or its affiliates. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License Version 2 as published +// by the Free Software Foundation. You may not use, modify or distribute +// this program under any other version of the GNU General Public License. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +//-------------------------------------------------------------------------- + +// host_cache_module.cc author Steve Chew + +#include "host_cache_module.h" + +#include "host_cache.h" + +const Parameter HostCacheModule::host_cache_params[] = +{ + { "size", Parameter::PT_INT, nullptr, nullptr, + "size of host cache" }, + + { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } +}; + +bool HostCacheModule::set(const char*, Value& v, SnortConfig*) +{ + if ( v.is("size") ) + host_cache_size = v.get_long(); + else + return false; + + return true; +} + +bool HostCacheModule::begin(const char*, int, SnortConfig*) +{ + host_cache_size = 0; + return true; +} + +bool HostCacheModule::end(const char* fqn, int, SnortConfig*) +{ + if ( host_cache_size && !strcmp(fqn, "host_cache") ) + { + host_cache.set_max_size(host_cache_size); + } + + return true; +} + +const PegInfo* HostCacheModule::get_pegs() const +{ return host_cache.get_pegs(); } + +PegCount* HostCacheModule::get_counts() const +{ return (PegCount*)host_cache.get_counts(); } + diff --git a/src/host_tracker/host_cache_module.h b/src/host_tracker/host_cache_module.h new file mode 100644 index 000000000..ed7f5656d --- /dev/null +++ b/src/host_tracker/host_cache_module.h @@ -0,0 +1,54 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2015-2016 Cisco and/or its affiliates. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License Version 2 as published +// by the Free Software Foundation. You may not use, modify or distribute +// this program under any other version of the GNU General Public License. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +//-------------------------------------------------------------------------- + +// host_cache_module.h author Steve Chew + +#ifndef HOST_CACHE_MODULE_H +#define HOST_CACHE_MODULE_H + +// Loads host cache configuration data. + +#include "framework/module.h" +#include + +#define host_cache_help \ + "configure hosts" + +class HostCacheModule : public Module +{ +public: + HostCacheModule() : Module("host_cache", host_cache_help, host_cache_params, true) + { + } + + const PegInfo* get_pegs() const override; + PegCount* get_counts() const override; + + bool set(const char*, Value&, SnortConfig*) override; + bool begin(const char*, int, SnortConfig*) override; + bool end(const char*, int, SnortConfig*) override; + +private: + static const Parameter host_cache_params[]; + static const Parameter service_params[]; + + uint32_t host_cache_size; +}; + +#endif + diff --git a/src/host_tracker/host_module.cc b/src/host_tracker/host_tracker_module.cc similarity index 97% rename from src/host_tracker/host_module.cc rename to src/host_tracker/host_tracker_module.cc index dae6157ee..05a24deae 100644 --- a/src/host_tracker/host_module.cc +++ b/src/host_tracker/host_tracker_module.cc @@ -16,9 +16,9 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //-------------------------------------------------------------------------- -// host_module.cc author Steve Chew +// host_tracker_module.cc author Steve Chew -#include "host_tracker/host_module.h" +#include "host_tracker/host_tracker_module.h" #include "host_tracker/host_cache.h" #include "stream/stream_api.h" diff --git a/src/host_tracker/host_module.h b/src/host_tracker/host_tracker_module.h similarity index 94% rename from src/host_tracker/host_module.h rename to src/host_tracker/host_tracker_module.h index 61f31d837..8cb0c6239 100644 --- a/src/host_tracker/host_module.h +++ b/src/host_tracker/host_tracker_module.h @@ -16,10 +16,10 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //-------------------------------------------------------------------------- -// host_module.h author Steve Chew +// host_tracker_module.h author Steve Chew -#ifndef HOST_MODULE_H -#define HOST_MODULE_H +#ifndef HOST_TRACKER_MODULE_H +#define HOST_TRACKER_MODULE_H // Loads host configuration data. diff --git a/src/host_tracker/test/CMakeLists.txt b/src/host_tracker/test/CMakeLists.txt index 83ed281f3..29d952d1b 100644 --- a/src/host_tracker/test/CMakeLists.txt +++ b/src/host_tracker/test/CMakeLists.txt @@ -1,10 +1,18 @@ add_cpputest(host_cache_test host_tracker) -add_cpputest(host_module_test host_tracker) +add_cpputest(host_cache_module_test host_tracker) +add_cpputest(host_tracker_module_test host_tracker) add_cpputest(host_tracker_test host_tracker) -target_link_libraries(host_module_test +target_link_libraries(host_cache_module_test + ${CMAKE_BINARY_DIR}/src/framework/libframework.a + ${CMAKE_BINARY_DIR}/src/catch/libcatch_tests.a + ${CMAKE_BINARY_DIR}/src/sfip/libsfip.a + ${CMAKE_BINARY_DIR}/src/hash/libhash.a + ${DNET_LIBRARIES}) + +target_link_libraries(host_tracker_module_test ${CMAKE_BINARY_DIR}/src/framework/libframework.a ${CMAKE_BINARY_DIR}/src/catch/libcatch_tests.a ${CMAKE_BINARY_DIR}/src/sfip/libsfip.a diff --git a/src/host_tracker/test/Makefile.am b/src/host_tracker/test/Makefile.am index 1d48a4c53..d75f1edfc 100644 --- a/src/host_tracker/test/Makefile.am +++ b/src/host_tracker/test/Makefile.am @@ -2,17 +2,20 @@ AM_DEFAULT_SOURCE_EXT = .cc check_PROGRAMS = \ -host_module_test \ +host_tracker_module_test \ +host_cache_module_test \ host_cache_test \ host_tracker_test TESTS = $(check_PROGRAMS) -host_module_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@ +host_cache_module_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@ +host_tracker_module_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@ host_cache_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@ host_tracker_test_CPPFLAGS = @AM_CPPFLAGS@ @CPPUTEST_CPPFLAGS@ -host_module_test_LDADD = ../host_module.o ../host_cache.o ../host_tracker.o ../../framework/libframework.a ../../catch/libcatch_tests.a ../../sfip/libsfip.a @CPPUTEST_LDFLAGS@ +host_cache_module_test_LDADD = ../host_cache_module.o ../host_cache.o ../host_tracker.o ../../framework/libframework.a ../../catch/libcatch_tests.a ../../sfip/libsfip.a ../../hash/libhash.a @CPPUTEST_LDFLAGS@ +host_tracker_module_test_LDADD = ../host_tracker_module.o ../host_cache.o ../host_tracker.o ../../framework/libframework.a ../../catch/libcatch_tests.a ../../sfip/libsfip.a @CPPUTEST_LDFLAGS@ host_cache_test_LDADD = ../host_cache.o ../host_tracker.o @CPPUTEST_LDFLAGS@ host_tracker_test_LDADD = ../host_tracker.o @CPPUTEST_LDFLAGS@ diff --git a/src/host_tracker/test/host_cache_module_test.cc b/src/host_tracker/test/host_cache_module_test.cc new file mode 100644 index 000000000..8f75f0da4 --- /dev/null +++ b/src/host_tracker/test/host_cache_module_test.cc @@ -0,0 +1,109 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2016-2016 Cisco and/or its affiliates. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License Version 2 as published +// by the Free Software Foundation. You may not use, modify or distribute +// this program under any other version of the GNU General Public License. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +//-------------------------------------------------------------------------- + +// host_cache_module_test.cc author Steve Chew +// unit tests for the host module APIs + +#include "host_tracker/host_cache_module.h" + +#include +#include + +#include "host_tracker/host_cache.h" +#include "sfip/sf_ip.h" + +// Fake AddProtocolReference to avoid bringing in a ton of dependencies. +int16_t AddProtocolReference(const char* protocol) +{ + if (!strcmp("servicename", protocol)) + return 3; + if (!strcmp("tcp", protocol)) + return 2; + return 1; +} + +// Fake show_stats to avoid bringing in a ton of dependencies. +void show_stats( + PegCount*, const PegInfo*, unsigned, const char*) +{ +} + +void show_stats(PegCount*, const PegInfo*, IndexVec&, const char*) +{ +} + +#define FRAG_POLICY 33 +#define STREAM_POLICY 100 + +sfip_t expected_addr; + +TEST_GROUP(host_cache_module) +{ + void setup() + { + } + + void teardown() + { + } +}; + +// Test that HostCacheModule sets up host_cache size based on config. +TEST(host_cache_module, host_cache_module_test_values) +{ + Value size_val((double)2112); + Parameter size_param = { "size", Parameter::PT_INT, nullptr, nullptr, "cache size" }; + HostCacheModule module; + const PegInfo* ht_pegs = module.get_pegs(); + const PegCount* ht_stats = module.get_counts(); + + CHECK(!strcmp(ht_pegs[0].name, "lru cache adds")); + CHECK(!strcmp(ht_pegs[1].name, "lru cache replaces")); + CHECK(!strcmp(ht_pegs[2].name, "lru cache prunes")); + CHECK(!strcmp(ht_pegs[3].name, "lru cache find hits")); + CHECK(!strcmp(ht_pegs[4].name, "lru cache find misses")); + CHECK(!strcmp(ht_pegs[5].name, "lru cache removes")); + CHECK(!strcmp(ht_pegs[6].name, "lru cache clears")); + CHECK(!ht_pegs[7].name); + + CHECK(ht_stats[0] == 0); + CHECK(ht_stats[1] == 0); + CHECK(ht_stats[2] == 0); + CHECK(ht_stats[3] == 0); + CHECK(ht_stats[4] == 0); + CHECK(ht_stats[5] == 0); + CHECK(ht_stats[6] == 0); + + size_val.set(&size_param); + + // Set up the host_cache max size. + module.begin("host_cache", 0, nullptr); + module.set(nullptr, size_val, nullptr); + module.end("host_cache", 0, nullptr); + + ht_stats = module.get_counts(); + CHECK(ht_stats[0] == 0); + + CHECK(2112 == host_cache.get_max_size()); +} + +int main(int argc, char** argv) +{ + return CommandLineTestRunner::RunAllTests(argc, argv); +} + diff --git a/src/host_tracker/test/host_module_test.cc b/src/host_tracker/test/host_tracker_module_test.cc similarity index 93% rename from src/host_tracker/test/host_module_test.cc rename to src/host_tracker/test/host_tracker_module_test.cc index 125fe0f77..3fe7cc7c1 100644 --- a/src/host_tracker/test/host_module_test.cc +++ b/src/host_tracker/test/host_tracker_module_test.cc @@ -16,10 +16,10 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //-------------------------------------------------------------------------- -// host_module_test.cc author Steve Chew +// host_tracker_module_test.cc author Steve Chew // unit tests for the host module APIs -#include "host_tracker/host_module.h" +#include "host_tracker/host_tracker_module.h" #include #include @@ -52,7 +52,7 @@ void show_stats( PegCount* , const PegInfo* , IndexVec& , const char* ) sfip_t expected_addr; -TEST_GROUP(host_module) +TEST_GROUP(host_tracker_module) { void setup() { @@ -112,8 +112,8 @@ TEST_GROUP(host_module) } }; -// Test that HostModules variables are set correctly. -TEST(host_module, host_module_test_values) +// Test that HostTrackerModule variables are set correctly. +TEST(host_tracker_module, host_tracker_module_test_values) { sfip_t cached_addr; @@ -134,8 +134,8 @@ TEST(host_module, host_module_test_values) } -// Test that HostModules statistics are correct. -TEST(host_module, host_module_test_stats) +// Test that HostTrackerModule statistics are correct. +TEST(host_tracker_module, host_tracker_module_test_stats) { HostIpKey host_ip_key(expected_addr.ip8); std::shared_ptr ht; diff --git a/src/main/modules.cc b/src/main/modules.cc index 8f61acdb7..f48444802 100644 --- a/src/main/modules.cc +++ b/src/main/modules.cc @@ -36,7 +36,8 @@ #include "filters/sfthd.h" #include "filters/sfthreshold.h" #include "framework/module.h" -#include "host_tracker/host_module.h" +#include "host_tracker/host_tracker_module.h" +#include "host_tracker/host_cache_module.h" #include "latency/latency_module.h" #include "managers/module_manager.h" #include "managers/plugin_manager.h" @@ -2193,5 +2194,6 @@ void module_init() ModuleManager::add_module(new AttributeTableModule); ModuleManager::add_module(new HostsModule); ModuleManager::add_module(new HostTrackerModule); + ModuleManager::add_module(new HostCacheModule); }