Skip to content

Commit

Permalink
add metric test
Browse files Browse the repository at this point in the history
  • Loading branch information
weyrick committed Apr 29, 2020
1 parent 0b176da commit 78e0712
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ add_executable(unit-tests
tests/test_parse_pcap.cpp
tests/test_sketches.cpp
tests/test_utils.cpp
tests/test_metrics.cpp
)

if (MMDB_ENABLE)
Expand Down
3 changes: 2 additions & 1 deletion src/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ void Metrics::newDNSPacket(pcpp::DnsLayer *dns, Direction dir, pcpp::ProtocolTyp
auto aggDomain = aggregateDomain(name);
_sketches->_dns_topQname2.update(std::string(aggDomain.first));
if (aggDomain.second.size()) {
_sketches->_dns_topQname3.update(std::string(aggDomain.second));
std::string s(aggDomain.second);
_sketches->_dns_topQname3.update(s);
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/test_metrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <DnsLayer.h>
#include <ProtocolType.h>
#include <catch2/catch.hpp>
#include <sstream>

#include "metrics.h"

TEST_CASE("metrics", "[metrics]")
{

SECTION("random qnames")
{
pktvisor::MetricsMgr mm(false, 5, 100);
mm.setInitialShiftTS();

for (int i = 0; i < 9; i++) {
for (int k = 0; k < 11; k++) {
pcpp::DnsLayer dns;
dns.getDnsHeader()->queryOrResponse = pktvisor::query;
std::stringstream name;
name << "0000" << k << ".0000" << i << ".com";
dns.addQuery(name.str(), pcpp::DnsType::DNS_TYPE_A, pcpp::DnsClass::DNS_CLASS_IN);
mm.newDNSPacket(&dns, pktvisor::Direction::toHost, pcpp::IPv4, pcpp::UDP);
}
}
}
}

0 comments on commit 78e0712

Please sign in to comment.