Pipeline ping rate tests, small=1 large=2 in-flight
This commit is contained in:
@@ -164,8 +164,10 @@ struct ping_rate_state {
|
|||||||
responder resp;
|
responder resp;
|
||||||
timer_handle timer = nullptr;
|
timer_handle timer = nullptr;
|
||||||
uint16_t ping_id;
|
uint16_t ping_id;
|
||||||
uint16_t count = 0;
|
uint16_t sent = 0;
|
||||||
|
uint16_t received = 0;
|
||||||
uint16_t target;
|
uint16_t target;
|
||||||
|
uint16_t pipeline;
|
||||||
uint16_t payload_len;
|
uint16_t payload_len;
|
||||||
uint32_t start_us;
|
uint32_t start_us;
|
||||||
peer_info peer;
|
peer_info peer;
|
||||||
@@ -177,16 +179,15 @@ struct ping_rate_state {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ping_rate_send(std::shared_ptr<ping_rate_state> st,
|
static void ping_rate_send_one(std::shared_ptr<ping_rate_state> st) {
|
||||||
std::shared_ptr<std::function<void(std::span<const uint8_t>)>> cb) {
|
|
||||||
prepend_buffer<4096> buf;
|
prepend_buffer<4096> buf;
|
||||||
if (st->payload_len > 0)
|
if (st->payload_len > 0)
|
||||||
memset(buf.append(st->payload_len), 0xAA, st->payload_len);
|
memset(buf.append(st->payload_len), 0xAA, st->payload_len);
|
||||||
icmp::prepend_echo_request(buf, st->our_mac, st->our_ip,
|
icmp::prepend_echo_request(buf, st->our_mac, st->our_ip,
|
||||||
st->peer.mac, st->peer.ip, st->ping_id,
|
st->peer.mac, st->peer.ip, st->ping_id,
|
||||||
st->count + 1, st->payload_len);
|
st->sent + 1, st->payload_len);
|
||||||
net_send_raw(buf.span());
|
net_send_raw(buf.span());
|
||||||
net_add_frame_callback(*cb);
|
st->sent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ping_rate_recv(std::shared_ptr<ping_rate_state> st,
|
static void ping_rate_recv(std::shared_ptr<ping_rate_state> st,
|
||||||
@@ -202,19 +203,19 @@ static void ping_rate_recv(std::shared_ptr<ping_rate_state> st,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
st->count++;
|
st->received++;
|
||||||
if (st->count >= st->target) {
|
if (st->received >= st->target) {
|
||||||
dispatch_cancel_timer(st->timer);
|
dispatch_cancel_timer(st->timer);
|
||||||
uint32_t elapsed_us = time_us_32() - st->start_us;
|
uint32_t elapsed_us = time_us_32() - st->start_us;
|
||||||
uint32_t elapsed_ms = elapsed_us / 1000;
|
uint32_t elapsed_ms = elapsed_us / 1000;
|
||||||
uint32_t pps = static_cast<uint32_t>(
|
uint32_t pps = static_cast<uint32_t>(
|
||||||
static_cast<uint64_t>(st->count) * 1000000 / elapsed_us);
|
static_cast<uint64_t>(st->received) * 1000000 / elapsed_us);
|
||||||
uint64_t total_bytes = static_cast<uint64_t>(st->count) * 2 * st->frame_size();
|
uint64_t total_bytes = static_cast<uint64_t>(st->received) * 2 * st->frame_size();
|
||||||
uint32_t kbps = static_cast<uint32_t>(total_bytes * 1000 / elapsed_us);
|
uint32_t kbps = static_cast<uint32_t>(total_bytes * 1000 / elapsed_us);
|
||||||
char msg[128];
|
char msg[128];
|
||||||
snprintf(msg, sizeof(msg),
|
snprintf(msg, sizeof(msg),
|
||||||
"%u rt in %lu ms, %lu pps, %lu bytes, %lu KB/s",
|
"%u rt in %lu ms, %lu pps, %lu bytes, %lu KB/s",
|
||||||
st->count, static_cast<unsigned long>(elapsed_ms),
|
st->received, static_cast<unsigned long>(elapsed_ms),
|
||||||
static_cast<unsigned long>(pps),
|
static_cast<unsigned long>(pps),
|
||||||
static_cast<unsigned long>(total_bytes),
|
static_cast<unsigned long>(total_bytes),
|
||||||
static_cast<unsigned long>(kbps));
|
static_cast<unsigned long>(kbps));
|
||||||
@@ -222,19 +223,22 @@ static void ping_rate_recv(std::shared_ptr<ping_rate_state> st,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ping_rate_send(st, cb);
|
if (st->sent < st->target)
|
||||||
|
ping_rate_send_one(st);
|
||||||
|
net_add_frame_callback(*cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_ping_rate(const responder& resp, uint16_t target,
|
static void start_ping_rate(const responder& resp, uint16_t target,
|
||||||
uint16_t payload_len) {
|
uint16_t payload_len, uint16_t pipeline) {
|
||||||
auto& ns = net_get_state();
|
auto& ns = net_get_state();
|
||||||
|
|
||||||
discover_peer(
|
discover_peer(
|
||||||
[resp, ns, target, payload_len](const peer_info& peer) {
|
[resp, ns, target, payload_len, pipeline](const peer_info& peer) {
|
||||||
auto st = std::make_shared<ping_rate_state>();
|
auto st = std::make_shared<ping_rate_state>();
|
||||||
st->resp = resp;
|
st->resp = resp;
|
||||||
st->ping_id = 0x5678;
|
st->ping_id = 0x5678;
|
||||||
st->target = target;
|
st->target = target;
|
||||||
|
st->pipeline = pipeline;
|
||||||
st->payload_len = payload_len;
|
st->payload_len = payload_len;
|
||||||
st->our_mac = ns.mac;
|
st->our_mac = ns.mac;
|
||||||
st->our_ip = ns.ip;
|
st->our_ip = ns.ip;
|
||||||
@@ -246,15 +250,18 @@ static void start_ping_rate(const responder& resp, uint16_t target,
|
|||||||
ping_rate_recv(st, cb, frame);
|
ping_rate_recv(st, cb, frame);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < st->pipeline && st->sent < st->target; i++)
|
||||||
|
ping_rate_send_one(st);
|
||||||
|
net_add_frame_callback(*cb);
|
||||||
|
|
||||||
st->timer = dispatch_schedule_ms(60000, [st]() {
|
st->timer = dispatch_schedule_ms(60000, [st]() {
|
||||||
uint32_t elapsed_us = time_us_32() - st->start_us;
|
uint32_t elapsed_us = time_us_32() - st->start_us;
|
||||||
char msg[64];
|
char msg[64];
|
||||||
snprintf(msg, sizeof(msg), "timeout after %u rt in %lu ms",
|
snprintf(msg, sizeof(msg), "timeout after %u/%u rt in %lu ms",
|
||||||
st->count, static_cast<unsigned long>(elapsed_us / 1000));
|
st->received, st->sent,
|
||||||
|
static_cast<unsigned long>(elapsed_us / 1000));
|
||||||
st->resp.respond(ResponseTest{false, {msg}});
|
st->resp.respond(ResponseTest{false, {msg}});
|
||||||
});
|
});
|
||||||
|
|
||||||
ping_rate_send(st, cb);
|
|
||||||
},
|
},
|
||||||
[resp]() {
|
[resp]() {
|
||||||
resp.respond(ResponseTest{false, {"no peer found"}});
|
resp.respond(ResponseTest{false, {"no peer found"}});
|
||||||
@@ -262,11 +269,11 @@ static void start_ping_rate(const responder& resp, uint16_t target,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_ping_rate(const responder& resp) {
|
static void test_ping_rate(const responder& resp) {
|
||||||
start_ping_rate(resp, 8192, 0);
|
start_ping_rate(resp, 8192, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_ping_rate_1k(const responder& resp) {
|
static void test_ping_rate_1k(const responder& resp) {
|
||||||
start_ping_rate(resp, 1024, 1024);
|
start_ping_rate(resp, 1024, 1024, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
using sync_test_fn = ResponseTest (*)(const responder&);
|
using sync_test_fn = ResponseTest (*)(const responder&);
|
||||||
|
|||||||
Reference in New Issue
Block a user