in katran/lib/testing/katran_tester.cpp [187:279]
void testLbCounters(katran::KatranLb& lb, KatranTestParam& testParam) {
katran::VipKey vip;
vip.address = "10.200.1.1";
vip.port = kVipPort;
vip.proto = kTcp;
LOG(INFO) << "Testing counter's sanity. Printing on errors only";
for (auto& vipCounter : testParam.perVipCounters) {
auto vipStats = lb.getStatsForVip(vip);
if ((vipStats.v1 != testParam.expectedTotalPktsForVip(vipCounter.first)) ||
(vipStats.v2 != testParam.expectedTotalBytesForVip(vipCounter.first))) {
VLOG(2) << "pckts: " << vipStats.v1 << ", bytes: " << vipStats.v2;
LOG(ERROR) << "per Vip counter is incorrect for vip:" << vip.address;
}
}
auto stats = lb.getLruStats();
if ((stats.v1 != testParam.expectedTotalPkts()) ||
(stats.v2 != testParam.expectedTotalLruMisses())) {
VLOG(2) << "Total pckts: " << stats.v1 << ", LRU misses: " << stats.v2;
LOG(ERROR) << "LRU counter is incorrect";
}
stats = lb.getLruMissStats();
if ((stats.v1 != testParam.expectedTotalTcpSyns()) ||
(stats.v2 != testParam.expectedTotalTcpNonSynLruMisses())) {
VLOG(2) << "TCP syns: " << stats.v1 << " TCP non-syns: " << stats.v2;
LOG(ERROR) << "per pckt type LRU miss counter is incorrect";
}
stats = lb.getLruFallbackStats();
if (stats.v1 != testParam.expectedTotalLruFallbackHits()) {
VLOG(2) << "FallbackLRU hits: " << stats.v1;
LOG(ERROR) << "LRU fallback counter is incorrect";
}
stats = lb.getQuicRoutingStats();
if (stats.v1 != testParam.expectedQuicRoutingWithCh() ||
stats.v2 != testParam.expectedQuicRoutingWithCid()) {
LOG(ERROR) << "Counters for QUIC packets routed with CH: " << stats.v1
<< ", with connection-id: " << stats.v2;
LOG(ERROR) << "Counters for routing of QUIC packets is wrong.";
}
stats = lb.getQuicCidVersionStats();
if (stats.v1 != testParam.expectedQuicCidV1Counts() ||
stats.v2 != testParam.expectedQuicCidV2Counts()) {
LOG(ERROR) << "QUIC CID version counters v1 " << stats.v1 << " v2 "
<< stats.v2;
LOG(ERROR) << "Counters for QUIC versions are wrong";
}
stats = lb.getQuicCidDropStats();
if (stats.v1 != testParam.expectedQuicCidDropsReal0Counts() ||
stats.v2 != testParam.expectedQuicCidDropsNoRealCounts()) {
LOG(ERROR) << "QUIC CID drop counters v1 " << stats.v1 << " v2 "
<< stats.v2;
LOG(ERROR) << "Counters for QUIC drops are wrong";
}
stats = lb.getTcpServerIdRoutingStats();
if (stats.v2 != testParam.expectedTcpServerIdRoutingCounts() ||
stats.v1 != testParam.expectedTcpServerIdRoutingFallbackCounts()) {
LOG(ERROR) << "Counters for TCP server-id routing with CH (v1): "
<< stats.v1 << ", with server-id (v2): " << stats.v2;
LOG(ERROR) << "Counters for TCP server-id based routing are wrong";
}
auto realStats = testParam.expectedRealStats();
for (int i = 0; i < kReals.size(); i++) {
auto real = kReals[i];
auto id = lb.getIndexForReal(real);
if (id < 0) {
LOG(INFO) << "Real does not exists: " << real;
continue;
}
stats = lb.getRealStats(id);
auto expected_stats = realStats[i];
if (stats.v1 != expected_stats.v1 || stats.v2 != expected_stats.v2) {
VLOG(2) << "stats for real: " << real << " v1: " << stats.v1
<< " v2: " << stats.v2;
LOG(INFO) << "incorrect stats for real: " << real;
LOG(INFO) << "Expected to be incorrect w/ non default build flags";
}
}
auto lb_stats = lb.getKatranLbStats();
if (lb_stats.bpfFailedCalls != testParam.expectedTotalFailedBpfCalls()) {
VLOG(2) << "failed bpf calls: " << lb_stats.bpfFailedCalls;
LOG(INFO) << "incorrect stats about katran library internals: "
<< "number of failed bpf syscalls is non zero";
}
if (lb_stats.addrValidationFailed !=
testParam.expectedTotalAddressValidations()) {
VLOG(2) << "failed ip address validations: "
<< lb_stats.addrValidationFailed;
LOG(INFO) << "incorrect stats about katran library internals: "
<< "number of failed ip address validations is non zero";
}
LOG(INFO) << "Testing of counters is complete";
return;
}