Refactor delta in a function
This commit is contained in:
parent
4cb27b1420
commit
9c1971af34
1 changed files with 43 additions and 17 deletions
|
@ -12,26 +12,62 @@ struct thunder_ctx {
|
|||
uint8_t total_links;
|
||||
uint8_t delta_t_per_link[64];
|
||||
uint8_t blacklisted[64];
|
||||
struct timespec prev_link_time;
|
||||
size_t monit_pkt_size;
|
||||
struct timespec prev_link_time, prev_packet_time;
|
||||
};
|
||||
|
||||
uint64_t compute_delta(struct timespec* prev_time, uint64_t max) {
|
||||
struct timespec curr;
|
||||
int secs, nsecs;
|
||||
uint64_t mili_sec;
|
||||
|
||||
// 4. We compute the time difference
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &curr) == -1){
|
||||
perror("clock_gettime error");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
secs = curr.tv_sec - prev_time->tv_sec;
|
||||
nsecs = curr.tv_nsec - prev_time->tv_nsec;
|
||||
*prev_time = curr;
|
||||
mili_sec = secs * 1000 + nsecs / 1000000;
|
||||
if (mili_sec > max) mili_sec = max;
|
||||
|
||||
return mili_sec;
|
||||
}
|
||||
|
||||
void prepare(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
||||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||
struct thunder_ctx* thunderc = app_ctx->misc;
|
||||
|
||||
uint64_t delta_pkt = compute_delta(&thunderc->prev_packet_time, 200);
|
||||
|
||||
thunderc->emit_id++;
|
||||
union abstract_packet metadata = {
|
||||
.fmt.headers.cmd = CMD_UDP_METADATA_THUNDER,
|
||||
.fmt.headers.size = sizeof(metadata.fmt.headers) + sizeof(metadata.fmt.content.udp_metadata_thunder),
|
||||
.fmt.headers.flags = 0,
|
||||
.fmt.content.udp_metadata_thunder.id = thunderc->emit_id,
|
||||
.fmt.content.udp_metadata_thunder.deltat = 0 //@FIXME delta t must be set
|
||||
.fmt.content.udp_metadata_thunder.deltat = delta_pkt
|
||||
};
|
||||
buffer_append_ap (bp, &metadata);
|
||||
}
|
||||
|
||||
void pad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
||||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||
struct thunder_ctx* thunderc = app_ctx->misc;
|
||||
uint64_t ref = 0l + thunderc->emit_id;
|
||||
|
||||
dup_buffer_toa (&app_ctx->br, bp, (void *)ref);
|
||||
|
||||
if (ref > 10 && get_app_buffer (&app_ctx->br, (void *)ref - 10l)) {
|
||||
mv_buffer_atof (&app_ctx->br, (void *)ref - 10l);
|
||||
}
|
||||
|
||||
//@FIXME we must add the delta t of the current packet
|
||||
for (uint64_t add_ref = ref; add_ref >= 0 && get_app_buffer (&app_ctx->br, (void *)add_ref); add_ref--) {
|
||||
struct buffer_packet *bpa = get_app_buffer (&app_ctx->br, (void *)add_ref);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,11 +77,6 @@ int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu
|
|||
struct evt_core_fdinfo *to_fdinfo = NULL;
|
||||
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "tcp-write");
|
||||
|
||||
struct timespec curr;
|
||||
int secs, nsecs;
|
||||
uint64_t mili_sec;
|
||||
|
||||
|
||||
do {
|
||||
// 1. We choose the link
|
||||
thunderc->selected_link = (thunderc->selected_link + 1) % cat->socklist->len;
|
||||
|
@ -53,7 +84,7 @@ int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu
|
|||
// 2. We create the packet template
|
||||
union abstract_packet links = {
|
||||
.fmt.headers.cmd = CMD_LINK_MONITORING_THUNDER,
|
||||
.fmt.headers.size = sizeof(links.fmt.headers) + sizeof(links.fmt.content.link_monitoring_thunder) + sizeof(struct link_info) * (thunderc->total_links - 1),
|
||||
.fmt.headers.size = thunderc->monit_pkt_size,
|
||||
.fmt.headers.flags = 0,
|
||||
.fmt.content.link_monitoring_thunder.links_status = {}
|
||||
};
|
||||
|
@ -65,15 +96,7 @@ int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu
|
|||
union abstract_packet *new_ap = buffer_append_ap (bp_dup, &links);
|
||||
|
||||
// 4. We compute the time difference
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &curr) == -1){
|
||||
perror("clock_gettime error");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
secs = curr.tv_sec - thunderc->prev_link_time.tv_sec;
|
||||
nsecs = curr.tv_nsec - thunderc->prev_link_time.tv_nsec;
|
||||
thunderc->prev_link_time = curr;
|
||||
mili_sec = secs * 1000 + nsecs / 1000000;
|
||||
if (mili_sec > 200) mili_sec = 200;
|
||||
uint64_t mili_sec = compute_delta (&thunderc->prev_link_time, 200);
|
||||
|
||||
// 5. We create the array
|
||||
struct link_info *li = &new_ap->fmt.content.link_monitoring_thunder.links_status;
|
||||
|
@ -103,6 +126,9 @@ void algo_thunder_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struc
|
|||
memset(app_ctx->misc, 0, sizeof(struct thunder_ctx));
|
||||
struct thunder_ctx* thunderc = app_ctx->misc;
|
||||
thunderc->selected_link = UINT8_MAX - 1;
|
||||
|
||||
union abstract_packet links = {};
|
||||
thunderc->monit_pkt_size = sizeof(links.fmt.headers) + sizeof(links.fmt.content.link_monitoring_thunder) + sizeof(struct link_info) * (thunderc->total_links - 1);
|
||||
}
|
||||
|
||||
void classify() {
|
||||
|
|
Loading…
Reference in a new issue