diff options
-rw-r--r-- | VNFs/DPPD-PROX/handle_gen.c | 47 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/prox_args.c | 12 | ||||
-rw-r--r-- | VNFs/DPPD-PROX/task_init.h | 12 |
3 files changed, 70 insertions, 1 deletions
diff --git a/VNFs/DPPD-PROX/handle_gen.c b/VNFs/DPPD-PROX/handle_gen.c index 6a517c3f..77e9acad 100644 --- a/VNFs/DPPD-PROX/handle_gen.c +++ b/VNFs/DPPD-PROX/handle_gen.c @@ -65,6 +65,8 @@ struct pkt_template { #define FROM_PCAP 1 #define NOT_FROM_PCAP 0 +#define MAX_RANGES 64 + #define TASK_OVERWRITE_SRC_MAC_WITH_PORT_MAC 1 static void pkt_template_init_mbuf(struct pkt_template *pkt_template, struct rte_mbuf *mbuf, uint8_t *pkt) @@ -114,6 +116,7 @@ struct task_gen { uint32_t socket_id; uint8_t generator_id; uint8_t n_rands; /* number of randoms */ + uint8_t n_ranges; /* number of ranges */ uint8_t min_bulk_size; uint8_t max_bulk_size; uint8_t lat_enabled; @@ -125,6 +128,7 @@ struct task_gen { uint16_t rand_offset; /* each random has an offset*/ uint8_t rand_len; /* # bytes to take from random (no bias introduced) */ } rand[64]; + struct range ranges[MAX_RANGES]; uint64_t accur[ACCURACY_WINDOW]; uint64_t pkt_tsc_offset[64]; struct pkt_template *pkt_template_orig; /* packet templates (from inline or from pcap) */ @@ -379,6 +383,25 @@ static void task_gen_apply_all_random_fields(struct task_gen *task, uint8_t **pk task_gen_apply_random_fields(task, pkt_hdr[i]); } +static void task_gen_apply_all_ranges(struct task_gen *task, uint8_t **pkt_hdr, uint32_t count) +{ + uint32_t ret; + if (!task->n_ranges) + return; + + for (uint16_t i = 0; i < count; ++i) { + for (uint16_t j = 0; j < task->n_ranges; ++j) { + if (unlikely(task->ranges[j].value == task->ranges[j].max)) + task->ranges[j].value = task->ranges[j].min; + else + task->ranges[j].value++; + ret = rte_bswap32(task->ranges[j].value); + uint8_t *pret = (uint8_t*)&ret; + rte_memcpy(pkt_hdr[i] + task->ranges[j].offset, pret + 4 - task->ranges[j].range_len, task->ranges[j].range_len); + } + } +} + static void task_gen_apply_accur_pos(struct task_gen *task, uint8_t *pkt_hdr, uint32_t accuracy) { *(uint32_t *)(pkt_hdr + task->accur_pos) = accuracy; @@ -953,6 +976,7 @@ static int handle_gen_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uin task_gen_load_and_prefetch(new_pkts, pkt_hdr, send_bulk); task_gen_build_packets(task, new_pkts, pkt_hdr, send_bulk); task_gen_apply_all_random_fields(task, pkt_hdr, send_bulk); + task_gen_apply_all_ranges(task, pkt_hdr, send_bulk); task_gen_apply_all_accur_pos(task, new_pkts, pkt_hdr, send_bulk); task_gen_apply_all_unique_id(task, new_pkts, pkt_hdr, send_bulk); @@ -1428,6 +1452,26 @@ static int task_gen_find_random_with_offset(struct task_gen *task, uint32_t offs return UINT32_MAX; } +static int task_gen_add_range(struct task_base *tbase, struct range *range) +{ + struct task_gen *task = (struct task_gen *)tbase; + if (task->n_ranges == MAX_RANGES) { + plog_err("Too many ranges\n"); + return -1; + } + task->ranges[task->n_ranges].min = range->min; + task->ranges[task->n_ranges].value = range->min; + uint32_t m = range->max; + task->ranges[task->n_ranges].range_len = 0; + while (m != 0) { + m >>= 8; + task->ranges[task->n_ranges].range_len++; + } + task->ranges[task->n_ranges].offset = range->offset; + task->ranges[task->n_ranges++].max = range->max; + return 0; +} + int task_gen_add_rand(struct task_base *tbase, const char *rand_str, uint32_t offset, uint32_t rand_id) { struct task_gen *task = (struct task_gen *)tbase; @@ -1609,6 +1653,9 @@ static void init_task_gen(struct task_base *tbase, struct task_args *targ) PROX_PANIC(task_gen_add_rand(tbase, targ->rand_str[i], targ->rand_offset[i], UINT32_MAX), "Failed to add random\n"); } + for (uint32_t i = 0; i < targ->n_ranges; ++i) { + PROX_PANIC(task_gen_add_range(tbase, &targ->range[i]), "Failed to add range\n"); + } } static struct task_init task_init_gen = { diff --git a/VNFs/DPPD-PROX/prox_args.c b/VNFs/DPPD-PROX/prox_args.c index 9b76a43c..d8c41021 100644 --- a/VNFs/DPPD-PROX/prox_args.c +++ b/VNFs/DPPD-PROX/prox_args.c @@ -1019,6 +1019,18 @@ static int get_core_cfg(unsigned sindex, char *str, void *data) if (STR_EQ(str, "random")) { return parse_str(targ->rand_str[targ->n_rand_str++], pkey, sizeof(targ->rand_str[0])); } + if (STR_EQ(str, "range")) { + int rc = parse_range(&targ->range[targ->n_ranges].min, &targ->range[targ->n_ranges].max, pkey); + targ->n_ranges++; + return rc; + } + if (STR_EQ(str, "range_offset")) { + if (targ->n_ranges == 0) { + set_errf("No range defined previously (use range=...)"); + return -1; + } + return parse_int(&targ->range[targ->n_ranges - 1].offset, pkey); + } if (STR_EQ(str, "rand_offset")) { if (targ->n_rand_str == 0) { set_errf("No random defined previously (use random=...)"); diff --git a/VNFs/DPPD-PROX/task_init.h b/VNFs/DPPD-PROX/task_init.h index 54c30304..6a14aae0 100644 --- a/VNFs/DPPD-PROX/task_init.h +++ b/VNFs/DPPD-PROX/task_init.h @@ -100,6 +100,14 @@ enum police_action { ACT_INVALID = 4 }; +struct range { + uint32_t min; + uint32_t value; + uint32_t max; + uint32_t offset; + uint8_t range_len; +}; + /* Configuration for task that is only used during startup. */ struct task_args { struct task_base *tbase; @@ -191,8 +199,10 @@ struct task_args { /* gen related*/ uint64_t rate_bps; uint32_t n_rand_str; - char rand_str[64][64]; + uint32_t n_ranges; uint32_t rand_offset[64]; + char rand_str[64][64]; + struct range range[64]; char pcap_file[256]; uint32_t accur_pos; uint32_t sig_pos; |