Now able to log udpecho OWD
This commit is contained in:
parent
22d31a872e
commit
8b04b391b0
3 changed files with 27 additions and 8 deletions
|
@ -19,7 +19,7 @@ void measure_parse(int size, struct measure_conf* mc) {
|
||||||
micro_sec = elapsed_micros (&head->emit_time, &curr);
|
micro_sec = elapsed_micros (&head->emit_time, &curr);
|
||||||
printf("[%s] Packet %llu latency %luµs\n", ctime_no_newline, (unsigned long long)head->counter, micro_sec);
|
printf("[%s] Packet %llu latency %luµs\n", ctime_no_newline, (unsigned long long)head->counter, micro_sec);
|
||||||
|
|
||||||
if (mc->max_measure > 0 && head->counter >= mc->max_measure) {
|
if (!mc->inhibit_exit && head->counter >= mc->max_measure) {
|
||||||
printf("Measurement done\n");
|
printf("Measurement done\n");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ struct measure_conf {
|
||||||
uint64_t interval;
|
uint64_t interval;
|
||||||
char* payload;
|
char* payload;
|
||||||
uint64_t counter;
|
uint64_t counter;
|
||||||
|
uint8_t inhibit_exit;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct measure_packet {
|
struct measure_packet {
|
||||||
|
|
|
@ -4,22 +4,30 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "evt_core.h"
|
#include "evt_core.h"
|
||||||
#include "net_tools.h"
|
#include "net_tools.h"
|
||||||
|
#include "measure.h"
|
||||||
|
|
||||||
|
struct udpecho_ctx {
|
||||||
|
struct measure_conf mc;
|
||||||
|
uint8_t is_measlat;
|
||||||
|
};
|
||||||
|
|
||||||
int on_udp(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
int on_udp(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
char buffer[1500];
|
|
||||||
ssize_t nread, nwritten;
|
ssize_t nread, nwritten;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
socklen_t addrlen = sizeof(addr);
|
socklen_t addrlen = sizeof(addr);
|
||||||
|
struct udpecho_ctx *uctx = fdinfo->cat->app_ctx;
|
||||||
|
|
||||||
nread = recvfrom(fdinfo->fd, buffer, sizeof(buffer), MSG_TRUNC, (struct sockaddr*)&addr, &addrlen);
|
nread = recvfrom(fdinfo->fd, uctx->mc.payload, uctx->mc.payload_size, MSG_TRUNC, (struct sockaddr*)&addr, &addrlen);
|
||||||
if (nread == -1 && errno == EAGAIN) return 1; // Read done
|
if (nread == -1 && errno == EAGAIN) return 1; // Read done
|
||||||
if (nread <= 0 || nread > sizeof(buffer)) {
|
if (nread <= 0 || nread > uctx->mc.payload_size) {
|
||||||
fprintf(stderr, "Message is either truncated or an error occured. nread=%ld\n", nread);
|
fprintf(stderr, "Message is either truncated or an error occured. nread=%ld, expected=%ld\n", nread, uctx->mc.payload_size);
|
||||||
perror("read errno");
|
perror("read errno");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
nwritten = sendto(fdinfo->fd, buffer, nread, 0, (struct sockaddr*)&addr, addrlen);
|
if (uctx->is_measlat) measure_parse (nread, &uctx->mc);
|
||||||
|
|
||||||
|
nwritten = sendto(fdinfo->fd, uctx->mc.payload, nread, 0, (struct sockaddr*)&addr, addrlen);
|
||||||
// @FIXME don't support EAGAIN on write. Could be intended, you don't think so?
|
// @FIXME don't support EAGAIN on write. Could be intended, you don't think so?
|
||||||
if (nwritten != nread) {
|
if (nwritten != nread) {
|
||||||
fprintf(stderr, "Didn't write the same number of bytes as read. nread=%ld, nwritten=%ld\n", nread, nwritten);
|
fprintf(stderr, "Didn't write the same number of bytes as read. nread=%ld, nwritten=%ld\n", nread, nwritten);
|
||||||
|
@ -33,12 +41,15 @@ int main(int argc, char** argv) {
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
printf("~ udpecho ~\n");
|
printf("~ udpecho ~\n");
|
||||||
|
|
||||||
|
struct udpecho_ctx uctx = {0};
|
||||||
int opt, udp_sock, verbose = 0;
|
int opt, udp_sock, verbose = 0;
|
||||||
char *port = NULL, *bindhost = NULL;
|
char *port = NULL, *bindhost = NULL;
|
||||||
struct evt_core_ctx evts = {0};
|
struct evt_core_ctx evts = {0};
|
||||||
|
uctx.mc.inhibit_exit = 1;
|
||||||
|
uctx.mc.payload_size = 1500;
|
||||||
|
|
||||||
// 1. Parse parameters
|
// 1. Parse parameters
|
||||||
while ((opt = getopt(argc, argv, "b:p:v")) != -1) {
|
while ((opt = getopt(argc, argv, "b:p:vms:")) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
|
@ -49,15 +60,22 @@ int main(int argc, char** argv) {
|
||||||
case 'b':
|
case 'b':
|
||||||
bindhost = optarg;
|
bindhost = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'm':
|
||||||
|
uctx.is_measlat = 1;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
uctx.mc.payload_size = atoi(optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bindhost == NULL) bindhost = "127.0.0.1";
|
if (bindhost == NULL) bindhost = "127.0.0.1";
|
||||||
|
measure_prepare (&uctx.mc);
|
||||||
|
|
||||||
// 2. Register category
|
// 2. Register category
|
||||||
struct evt_core_cat udp_read = {
|
struct evt_core_cat udp_read = {
|
||||||
.app_ctx = NULL,
|
.app_ctx = &uctx,
|
||||||
.free_app_ctx = NULL,
|
.free_app_ctx = NULL,
|
||||||
.cb = on_udp,
|
.cb = on_udp,
|
||||||
.err_cb = NULL,
|
.err_cb = NULL,
|
||||||
|
|
Loading…
Reference in a new issue