From dfbc44f3f54d1aebc5b5a05c02ffb424f819f150 Mon Sep 17 00:00:00 2001 From: bvierno Date: Tue, 14 Jul 2020 04:15:18 -0500 Subject: [PATCH 01/27] Bug fix: Not setting action after adding to table. --- examples/test_flow_dir/test_flow_dir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index e9b61876d..a2d3d7d68 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -176,7 +176,8 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, memset(flow_entry, 0, sizeof(struct onvm_flow_entry)); flow_entry->sc = onvm_sc_create(); onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, destination); - // onvm_sc_print(flow_entry->sc); + meta->destination = destination; + meta->action = ONVM_NF_ACTION_TONF; } return 0; } From 66d172507eb8ed6736b0f56ae9d04bb6224aee04 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 14 Jul 2020 09:18:40 +0000 Subject: [PATCH 02/27] Bug fix: Not setting action after adding to table. --- examples/test_flow_dir/test_flow_dir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index e9b61876d..a2d3d7d68 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -176,7 +176,8 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, memset(flow_entry, 0, sizeof(struct onvm_flow_entry)); flow_entry->sc = onvm_sc_create(); onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, destination); - // onvm_sc_print(flow_entry->sc); + meta->destination = destination; + meta->action = ONVM_NF_ACTION_TONF; } return 0; } From f6d04a9d0b8283fb2de3dbb7231619b1e4a3f318 Mon Sep 17 00:00:00 2001 From: bvierno Date: Thu, 16 Jul 2020 22:58:22 -0500 Subject: [PATCH 03/27] Removed memset when filling key in flow dir --- examples/load_balancer/load_balancer.c | 1 + examples/speed_tester/speed_tester.c | 1 + examples/test_flow_dir/test_flow_dir.c | 14 +++++++++++--- onvm/onvm_nflib/onvm_flow_table.h | 1 - 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/load_balancer/load_balancer.c b/examples/load_balancer/load_balancer.c index a945cf110..9f24e8686 100644 --- a/examples/load_balancer/load_balancer.c +++ b/examples/load_balancer/load_balancer.c @@ -456,6 +456,7 @@ table_lookup_entry(struct rte_mbuf *pkt, struct flow_info **flow) { return -1; } + memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); int ret = onvm_ft_fill_key_symmetric(&key, pkt); if (ret < 0) return -1; diff --git a/examples/speed_tester/speed_tester.c b/examples/speed_tester/speed_tester.c index c0321c7cc..2d5132ef7 100644 --- a/examples/speed_tester/speed_tester.c +++ b/examples/speed_tester/speed_tester.c @@ -345,6 +345,7 @@ nf_setup(struct onvm_nf_local_ctx *nf_local_ctx) { pmeta->action = ONVM_NF_ACTION_TONF; pmeta->flags = ONVM_SET_BIT(0, SPEED_TESTER_BIT); + memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); onvm_ft_fill_key(&key, pkt); pkt->hash.rss = onvm_softrss(&key); diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index a2d3d7d68..50a99d6a4 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -158,16 +158,24 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, struct onvm_flow_entry *flow_entry = NULL; int ret; + if (!onvm_pkt_is_ipv4(pkt)) { + meta->action = ONVM_NF_ACTION_DROP; + return 0; + } + if (++counter == print_delay) { do_stats_display(pkt); counter = 0; } - ret = onvm_flow_dir_get_pkt(pkt, &flow_entry); + struct onvm_ft_ipv4_5tuple key; + memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); + onvm_ft_fill_key(&key, pkt); + ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)flow_entry); if (ret >= 0) { meta->action = ONVM_NF_ACTION_NEXT; } else { - ret = onvm_flow_dir_add_pkt(pkt, &flow_entry); + ret = onvm_ft_add_key(sdn_ft, &key, (char **)&flow_entry); if (ret < 0) { meta->action = ONVM_NF_ACTION_DROP; meta->destination = 0; @@ -176,8 +184,8 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, memset(flow_entry, 0, sizeof(struct onvm_flow_entry)); flow_entry->sc = onvm_sc_create(); onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, destination); - meta->destination = destination; meta->action = ONVM_NF_ACTION_TONF; + meta->destination = destination; } return 0; } diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index 45c3b00e0..b5ba2b586 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -148,7 +148,6 @@ onvm_ft_fill_key(struct onvm_ft_ipv4_5tuple *key, struct rte_mbuf *pkt) { return -EPROTONOSUPPORT; } ipv4_hdr = onvm_pkt_ipv4_hdr(pkt); - memset(key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); key->proto = ipv4_hdr->next_proto_id; key->src_addr = ipv4_hdr->src_addr; key->dst_addr = ipv4_hdr->dst_addr; From 524db7f37d737c9df8f07379c0fe529afbc04c5a Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Fri, 17 Jul 2020 04:54:50 +0000 Subject: [PATCH 04/27] Styling --- examples/test_flow_dir/test_flow_dir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 7cc4ab119..50a99d6a4 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -184,9 +184,8 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, memset(flow_entry, 0, sizeof(struct onvm_flow_entry)); flow_entry->sc = onvm_sc_create(); onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, destination); - meta->action = ONVM_NF_ACTION_TONF; - meta->destination = destination + meta->destination = destination; } return 0; } From 289eaf3eb3a6be39a5ba1879df243bff430e978d Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Fri, 17 Jul 2020 05:19:33 +0000 Subject: [PATCH 05/27] Update onvm ipv4 tuple size. --- examples/test_flow_dir/test_flow_dir.c | 2 +- onvm/onvm_nflib/onvm_flow_table.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 50a99d6a4..e746d53e5 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -155,7 +155,7 @@ static int packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, __attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) { static uint32_t counter = 0; - struct onvm_flow_entry *flow_entry = NULL; + struct onvm_flow_entry *flow_entry; int ret; if (!onvm_pkt_is_ipv4(pkt)) { diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index b5ba2b586..4382a8043 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -71,8 +71,8 @@ struct onvm_ft { struct onvm_ft_ipv4_5tuple { uint32_t src_addr; uint32_t dst_addr; - uint16_t src_port; - uint16_t dst_port; + uint32_t src_port; + uint32_t dst_port; uint8_t proto; }; From 785a6823951a2ce45dc04579c1459b9d0645ce61 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Sun, 19 Jul 2020 03:25:39 +0000 Subject: [PATCH 06/27] Convert port to big endian when filling key. --- onvm/onvm_nflib/onvm_flow_table.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index 4382a8043..d3ef39ada 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -71,8 +71,8 @@ struct onvm_ft { struct onvm_ft_ipv4_5tuple { uint32_t src_addr; uint32_t dst_addr; - uint32_t src_port; - uint32_t dst_port; + uint16_t src_port; + uint16_t dst_port; uint8_t proto; }; @@ -153,12 +153,12 @@ onvm_ft_fill_key(struct onvm_ft_ipv4_5tuple *key, struct rte_mbuf *pkt) { key->dst_addr = ipv4_hdr->dst_addr; if (key->proto == IP_PROTOCOL_TCP) { tcp_hdr = onvm_pkt_tcp_hdr(pkt); - key->src_port = tcp_hdr->src_port; - key->dst_port = tcp_hdr->dst_port; + key->src_port = rte_cpu_to_be_16(tcp_hdr->src_port); + key->dst_port = rte_cpu_to_be_16(tcp_hdr->dst_port); } else if (key->proto == IP_PROTOCOL_UDP) { udp_hdr = onvm_pkt_udp_hdr(pkt); - key->src_port = udp_hdr->src_port; - key->dst_port = udp_hdr->dst_port; + key->src_port = rte_cpu_to_be_16(udp_hdr->src_port); + key->dst_port = rte_cpu_to_be_16(udp_hdr->dst_port); } else { key->src_port = 0; key->dst_port = 0; From 0888f1abee9fa551b88aa7ccc1207b9603995c95 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Mon, 20 Jul 2020 03:50:50 -0500 Subject: [PATCH 07/27] Initialize flow entry to NULL & new feature --- examples/test_flow_dir/test_flow_dir.c | 74 ++++++++++++++++++++++++-- onvm/onvm_nflib/onvm_flow_table.h | 12 ++--- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index e746d53e5..ebc6ad636 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -71,6 +71,9 @@ static uint32_t print_delay = 1000000; static uint32_t destination; +/* Populate flow disabled by default */ +static int populate_flow = 0; + /* * Print a usage message */ @@ -91,7 +94,7 @@ static int parse_app_args(int argc, char *argv[], const char *progname) { int c; - while ((c = getopt(argc, argv, "d:p:")) != -1) { + while ((c = getopt(argc, argv, "d:p:f")) != -1) { switch (c) { case 'd': destination = strtoul(optarg, NULL, 10); @@ -99,6 +102,9 @@ parse_app_args(int argc, char *argv[], const char *progname) { case 'p': print_delay = strtoul(optarg, NULL, 10); break; + case 'f': + populate_flow = 1; + break; case '?': usage(progname); if (optopt == 'd') @@ -151,11 +157,66 @@ do_stats_display(struct rte_mbuf *pkt) { } } +/* + * This function populates a set of flows to the sdn flow table. + * For each new flow a service chain is created and appended. + * Each service chain is of max 4 length. This function is not enabled by default. + */ + +static void +populate_ipv4_flow_table(void){ + struct test_add_key { + struct onvm_ft_ipv4_5tuple key; + uint8_t destinations[ONVM_MAX_CHAIN_LENGTH]; + }; + + struct test_add_key keys[] = { + {{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1), 0, 1, IPPROTO_TCP}, {0,1,2,3}}, + {{IPv4(102, 0, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {3,2,1,0}}, + {{IPv4(103, 0, 0, 0), IPv4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, + }; + + uint32_t num_keys = RTE_DIM(keys); + struct onvm_flow_entry *flow_entry = NULL; + flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); + for (uint32_t i = 0; i < num_keys; i++){ + struct onvm_ft_ipv4_5tuple key; + memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); + key = keys[i].key; + int ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)flow_entry); + if (ret >= 0) { + continue; + } else { + printf("\nAdding Key: "); + _onvm_ft_print_key(&key); + ret = onvm_ft_add_key(sdn_ft, &key, (char **)&flow_entry); + if (ret < 0) { + printf("Unable to add key."); + continue; + } + printf("Creating new service chain.\n"); + flow_entry->sc = onvm_sc_create(); + uint32_t num_dest = RTE_DIM(keys[i].destinations); + for (uint32_t j = 0; j < num_dest; j++) { + printf("Appending Destination: %d \n", keys[i].destinations[j]); + onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, keys[i].destinations[j]); + } + } + } + flow_entry = NULL; + rte_free(flow_entry); +} + static int packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, __attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) { static uint32_t counter = 0; - struct onvm_flow_entry *flow_entry; + struct onvm_flow_entry *flow_entry = NULL; + flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); + if (flow_entry == NULL) { + printf("Unable to allocate flow entry"); + return -1; + } int ret; if (!onvm_pkt_is_ipv4(pkt)) { @@ -179,14 +240,16 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, if (ret < 0) { meta->action = ONVM_NF_ACTION_DROP; meta->destination = 0; + rte_free(flow_entry); return 0; } - memset(flow_entry, 0, sizeof(struct onvm_flow_entry)); flow_entry->sc = onvm_sc_create(); onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, destination); meta->action = ONVM_NF_ACTION_TONF; meta->destination = destination; } + flow_entry = NULL; + rte_free(flow_entry); return 0; } @@ -223,6 +286,11 @@ main(int argc, char *argv[]) { /* Map the sdn_ft table */ onvm_flow_dir_nf_init(); + if (populate_flow) { + printf("Populating flow table. \n"); + populate_ipv4_flow_table(); + } + onvm_nflib_run(nf_local_ctx); onvm_nflib_stop(nf_local_ctx); diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index d3ef39ada..b7c5d446d 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -126,10 +126,10 @@ onvm_ft_free(struct onvm_ft *table); static inline void _onvm_ft_print_key(struct onvm_ft_ipv4_5tuple *key) { - printf("IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8, key->src_addr & 0xFF, (key->src_addr >> 8) & 0xFF, - (key->src_addr >> 16) & 0xFF, (key->src_addr >> 24) & 0xFF); - printf("-%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 " ", key->dst_addr & 0xFF, (key->dst_addr >> 8) & 0xFF, - (key->dst_addr >> 16) & 0xFF, (key->dst_addr >> 24) & 0xFF); + printf("IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8, (key->src_addr >> 24) & 0xFF, (key->src_addr >> 16) & 0xFF, + (key->src_addr >> 8) & 0xFF, key->src_addr & 0xFF); + printf("-%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 " ", (key->dst_addr >> 24) & 0xFF, (key->dst_addr >> 16) & 0xFF, + (key->dst_addr >> 8) & 0xFF, key->dst_addr & 0xFF); printf("Port: %d %d Proto: %d\n", key->src_port, key->dst_port, key->proto); } @@ -149,8 +149,8 @@ onvm_ft_fill_key(struct onvm_ft_ipv4_5tuple *key, struct rte_mbuf *pkt) { } ipv4_hdr = onvm_pkt_ipv4_hdr(pkt); key->proto = ipv4_hdr->next_proto_id; - key->src_addr = ipv4_hdr->src_addr; - key->dst_addr = ipv4_hdr->dst_addr; + key->src_addr = rte_cpu_to_be_32(ipv4_hdr->src_addr); + key->dst_addr = rte_cpu_to_be_32(ipv4_hdr->dst_addr); if (key->proto == IP_PROTOCOL_TCP) { tcp_hdr = onvm_pkt_tcp_hdr(pkt); key->src_port = rte_cpu_to_be_16(tcp_hdr->src_port); From ac0865102ba7076e5f2dddf71abe7a3b2ec8b5e7 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Mon, 20 Jul 2020 03:57:55 -0500 Subject: [PATCH 08/27] Conform to Linter --- examples/test_flow_dir/test_flow_dir.c | 4 ++-- onvm/onvm_nflib/onvm_flow_table.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index ebc6ad636..fcbf52a8f 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -164,7 +164,7 @@ do_stats_display(struct rte_mbuf *pkt) { */ static void -populate_ipv4_flow_table(void){ +populate_ipv4_flow_table(void) { struct test_add_key { struct onvm_ft_ipv4_5tuple key; uint8_t destinations[ONVM_MAX_CHAIN_LENGTH]; @@ -179,7 +179,7 @@ populate_ipv4_flow_table(void){ uint32_t num_keys = RTE_DIM(keys); struct onvm_flow_entry *flow_entry = NULL; flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); - for (uint32_t i = 0; i < num_keys; i++){ + for (uint32_t i = 0; i < num_keys; i++) { struct onvm_ft_ipv4_5tuple key; memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); key = keys[i].key; diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index b7c5d446d..915d641b4 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -126,10 +126,10 @@ onvm_ft_free(struct onvm_ft *table); static inline void _onvm_ft_print_key(struct onvm_ft_ipv4_5tuple *key) { - printf("IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8, (key->src_addr >> 24) & 0xFF, (key->src_addr >> 16) & 0xFF, - (key->src_addr >> 8) & 0xFF, key->src_addr & 0xFF); - printf("-%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 " ", (key->dst_addr >> 24) & 0xFF, (key->dst_addr >> 16) & 0xFF, - (key->dst_addr >> 8) & 0xFF, key->dst_addr & 0xFF); + printf("IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8, (key->src_addr >> 24) & 0xFF, + (key->src_addr >> 16) & 0xFF, (key->src_addr >> 8) & 0xFF, key->src_addr & 0xFF); + printf("-%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 " ", (key->dst_addr >> 24) & 0xFF, + (key->dst_addr >> 16) & 0xFF, (key->dst_addr >> 8) & 0xFF, key->dst_addr & 0xFF); printf("Port: %d %d Proto: %d\n", key->src_port, key->dst_port, key->proto); } From 179afc0ba2ba035f6f118e5096dda090a3e889f4 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Mon, 20 Jul 2020 05:15:21 -0500 Subject: [PATCH 09/27] Update print default service chain. --- onvm/onvm_mgr/onvm_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onvm/onvm_mgr/onvm_init.c b/onvm/onvm_mgr/onvm_init.c index 28535f051..9f549829a 100644 --- a/onvm/onvm_mgr/onvm_init.c +++ b/onvm/onvm_mgr/onvm_init.c @@ -251,7 +251,7 @@ init(int argc, char *argv[]) { printf("Chain length can not be larger than the maximum chain length\n"); exit(1); } - printf("Default service chain: send to sdn NF\n"); + printf("Default service chain: send to NF with service ID 1\n"); /* set up service chain pointer shared to NFs*/ mz_scp = rte_memzone_reserve(MZ_SCP_INFO, sizeof(struct onvm_service_chain *), rte_socket_id(), NO_FLAGS); From a312d3f6e8fba8bb2dea6238a372a78829fcb800 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Mon, 20 Jul 2020 09:20:50 -0500 Subject: [PATCH 10/27] Update flow entry variable to be global. --- examples/test_flow_dir/test_flow_dir.c | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index fcbf52a8f..423d04d63 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -66,7 +66,7 @@ #define NF_TAG "test_flow_dir" -/* number of package between each print */ +/* Number of packets between each print. */ static uint32_t print_delay = 1000000; static uint32_t destination; @@ -74,6 +74,7 @@ static uint32_t destination; /* Populate flow disabled by default */ static int populate_flow = 0; +static struct onvm_flow_entry *flow_entry = NULL; /* * Print a usage message */ @@ -85,6 +86,8 @@ usage(const char *progname) { printf("Flags:\n"); printf(" - `-d `: destination service ID to foward to\n"); printf(" - `-p `: number of packets between each print, e.g. `-p 1` prints every packets.\n"); + printf(" - `-f : Enable populating sdn flow table. \n"); + } /* @@ -177,8 +180,6 @@ populate_ipv4_flow_table(void) { }; uint32_t num_keys = RTE_DIM(keys); - struct onvm_flow_entry *flow_entry = NULL; - flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); for (uint32_t i = 0; i < num_keys; i++) { struct onvm_ft_ipv4_5tuple key; memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); @@ -203,20 +204,20 @@ populate_ipv4_flow_table(void) { } } } - flow_entry = NULL; - rte_free(flow_entry); +} + +static void +nf_setup(__attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) { + flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); + if (flow_entry == NULL) { + rte_exit(EXIT_FAILURE, "Unable to allocate flow entry\n"); + } } static int packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, __attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) { static uint32_t counter = 0; - struct onvm_flow_entry *flow_entry = NULL; - flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); - if (flow_entry == NULL) { - printf("Unable to allocate flow entry"); - return -1; - } int ret; if (!onvm_pkt_is_ipv4(pkt)) { @@ -240,7 +241,6 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, if (ret < 0) { meta->action = ONVM_NF_ACTION_DROP; meta->destination = 0; - rte_free(flow_entry); return 0; } flow_entry->sc = onvm_sc_create(); @@ -248,8 +248,6 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, meta->action = ONVM_NF_ACTION_TONF; meta->destination = destination; } - flow_entry = NULL; - rte_free(flow_entry); return 0; } @@ -265,6 +263,7 @@ main(int argc, char *argv[]) { nf_function_table = onvm_nflib_init_nf_function_table(); nf_function_table->pkt_handler = &packet_handler; + nf_function_table->setup = &nf_setup; if ((arg_offset = onvm_nflib_init(argc, argv, NF_TAG, nf_local_ctx, nf_function_table)) < 0) { onvm_nflib_stop(nf_local_ctx); @@ -294,6 +293,7 @@ main(int argc, char *argv[]) { onvm_nflib_run(nf_local_ctx); onvm_nflib_stop(nf_local_ctx); + rte_free(flow_entry); printf("If we reach here, program is ending\n"); return 0; } From d88f41226566bc133a34caa8ec89162b830c5b32 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Mon, 20 Jul 2020 21:44:38 -0500 Subject: [PATCH 11/27] Update destination structs --- examples/test_flow_dir/test_flow_dir.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 423d04d63..68a240c67 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -174,8 +174,8 @@ populate_ipv4_flow_table(void) { }; struct test_add_key keys[] = { - {{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1), 0, 1, IPPROTO_TCP}, {0,1,2,3}}, - {{IPv4(102, 0, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {3,2,1,0}}, + {{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1), 0, 1, IPPROTO_TCP}, {1,2,3,4}}, + {{IPv4(102, 0, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {4,3,2,1}}, {{IPv4(103, 0, 0, 0), IPv4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, }; @@ -199,6 +199,9 @@ populate_ipv4_flow_table(void) { flow_entry->sc = onvm_sc_create(); uint32_t num_dest = RTE_DIM(keys[i].destinations); for (uint32_t j = 0; j < num_dest; j++) { + if (keys[i].destinations[j] == 0) { + continue; + } printf("Appending Destination: %d \n", keys[i].destinations[j]); onvm_sc_append_entry(flow_entry->sc, ONVM_NF_ACTION_TONF, keys[i].destinations[j]); } From 1c20d9edc882340a66d4e780e48497e8b9cca462 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno <54540257+bdevierno1@users.noreply.github.com> Date: Tue, 21 Jul 2020 16:42:34 +0800 Subject: [PATCH 12/27] Update readme with new functionality. --- examples/test_flow_dir/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/test_flow_dir/README.md b/examples/test_flow_dir/README.md index 5200b67f0..8bbefff79 100644 --- a/examples/test_flow_dir/README.md +++ b/examples/test_flow_dir/README.md @@ -3,6 +3,8 @@ Flow Director Test This NF demonstrates how to use ONVM's Flow Director. When a packet arrives the NF checks whether it is from a flow that already has a service chain rule. If not, it creates a new rule so the packet will be sent to the destination NF indicated on the command line. Packets that match a rule are processed with the ONVM_NF_ACTION_NEXT action. +This NF demonstrates how to populate the SDN flow table as well as how to create service chain rules for specific flows. To enable this functionality use the -f flag. + Compilation and Execution -- ``` @@ -24,6 +26,7 @@ App Specific Arguments -- - `-d `: destination service ID to foward to - `-p `: number of packets between each print, e.g. `-p 1` prints every packets. + - `f`: populate ONVM's flow director table with predefined flows. Config File Support -- From 6e419cbbe19f470952c6778ba4d4149305262b13 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Wed, 22 Jul 2020 04:25:23 -0500 Subject: [PATCH 13/27] Removed memset --- examples/test_flow_dir/test_flow_dir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 68a240c67..bda412fc5 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -168,6 +168,10 @@ do_stats_display(struct rte_mbuf *pkt) { static void populate_ipv4_flow_table(void) { + struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); + if (flow_entry == NULL) { + rte_exit(EXIT_FAILURE, "Unable to populate flow.\n"); + } struct test_add_key { struct onvm_ft_ipv4_5tuple key; uint8_t destinations[ONVM_MAX_CHAIN_LENGTH]; @@ -182,7 +186,6 @@ populate_ipv4_flow_table(void) { uint32_t num_keys = RTE_DIM(keys); for (uint32_t i = 0; i < num_keys; i++) { struct onvm_ft_ipv4_5tuple key; - memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); key = keys[i].key; int ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)flow_entry); if (ret >= 0) { @@ -207,6 +210,8 @@ populate_ipv4_flow_table(void) { } } } + flow_entry = NULL; + rte_free(flow_entry); } static void From 94446c6e3a855aef7ce25f0bf330f45bda665628 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Wed, 22 Jul 2020 04:34:11 -0500 Subject: [PATCH 14/27] Conform to Linter --- examples/test_flow_dir/test_flow_dir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index bda412fc5..1179b6b03 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -168,7 +168,8 @@ do_stats_display(struct rte_mbuf *pkt) { static void populate_ipv4_flow_table(void) { - struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); + struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) + rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); if (flow_entry == NULL) { rte_exit(EXIT_FAILURE, "Unable to populate flow.\n"); } From 31447bd58e3a7167a5aa76caa9eee2b884eac44b Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Wed, 22 Jul 2020 04:37:24 -0500 Subject: [PATCH 15/27] Linter: whitespace --- examples/test_flow_dir/test_flow_dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 1179b6b03..21cf68d51 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -168,7 +168,7 @@ do_stats_display(struct rte_mbuf *pkt) { static void populate_ipv4_flow_table(void) { - struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) + struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); if (flow_entry == NULL) { rte_exit(EXIT_FAILURE, "Unable to populate flow.\n"); From 7c7ae8f993b6b92f47cb26a8d82f98c4154ab87a Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Thu, 23 Jul 2020 07:39:44 -0500 Subject: [PATCH 16/27] First review. TODO: Resolve memset placement. --- examples/test_flow_dir/README.md | 4 ++-- examples/test_flow_dir/test_flow_dir.c | 16 ++++++++++------ onvm/onvm_nflib/onvm_pkt_helper.c | 10 ++++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/test_flow_dir/README.md b/examples/test_flow_dir/README.md index 8bbefff79..132081b2f 100644 --- a/examples/test_flow_dir/README.md +++ b/examples/test_flow_dir/README.md @@ -3,7 +3,7 @@ Flow Director Test This NF demonstrates how to use ONVM's Flow Director. When a packet arrives the NF checks whether it is from a flow that already has a service chain rule. If not, it creates a new rule so the packet will be sent to the destination NF indicated on the command line. Packets that match a rule are processed with the ONVM_NF_ACTION_NEXT action. -This NF demonstrates how to populate the SDN flow table as well as how to create service chain rules for specific flows. To enable this functionality use the -f flag. +This NF demonstrates how to populate the Manager's flow table as well as how to create service chain rules for specific flows. To enable this functionality use the -s flag. Compilation and Execution -- @@ -26,7 +26,7 @@ App Specific Arguments -- - `-d `: destination service ID to foward to - `-p `: number of packets between each print, e.g. `-p 1` prints every packets. - - `f`: populate ONVM's flow director table with predefined flows. + - `s`: Prepopulate sample flow table rules. Config File Support -- diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 21cf68d51..332860a5a 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -75,6 +75,9 @@ static uint32_t destination; static int populate_flow = 0; static struct onvm_flow_entry *flow_entry = NULL; + +/* Pointer to the manager flow table */ +extern struct onvm_ft* sdn_ft; /* * Print a usage message */ @@ -86,7 +89,7 @@ usage(const char *progname) { printf("Flags:\n"); printf(" - `-d `: destination service ID to foward to\n"); printf(" - `-p `: number of packets between each print, e.g. `-p 1` prints every packets.\n"); - printf(" - `-f : Enable populating sdn flow table. \n"); + printf(" - -s : Prepopulate sample flow table rules. \n"); } @@ -97,7 +100,7 @@ static int parse_app_args(int argc, char *argv[], const char *progname) { int c; - while ((c = getopt(argc, argv, "d:p:f")) != -1) { + while ((c = getopt(argc, argv, "d:p:s")) != -1) { switch (c) { case 'd': destination = strtoul(optarg, NULL, 10); @@ -105,7 +108,7 @@ parse_app_args(int argc, char *argv[], const char *progname) { case 'p': print_delay = strtoul(optarg, NULL, 10); break; - case 'f': + case 's': populate_flow = 1; break; case '?': @@ -164,10 +167,11 @@ do_stats_display(struct rte_mbuf *pkt) { * This function populates a set of flows to the sdn flow table. * For each new flow a service chain is created and appended. * Each service chain is of max 4 length. This function is not enabled by default. + * Users may update the predefined struct with their own rules here. */ static void -populate_ipv4_flow_table(void) { +populate_sample_ipv4(void) { struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); if (flow_entry == NULL) { @@ -194,7 +198,7 @@ populate_ipv4_flow_table(void) { } else { printf("\nAdding Key: "); _onvm_ft_print_key(&key); - ret = onvm_ft_add_key(sdn_ft, &key, (char **)&flow_entry); + ret = onvm_ft_add_key(sdn_ft, &key, (char **)flow_entry); if (ret < 0) { printf("Unable to add key."); continue; @@ -296,7 +300,7 @@ main(int argc, char *argv[]) { if (populate_flow) { printf("Populating flow table. \n"); - populate_ipv4_flow_table(); + populate_sample_ipv4(); } onvm_nflib_run(nf_local_ctx); diff --git a/onvm/onvm_nflib/onvm_pkt_helper.c b/onvm/onvm_nflib/onvm_pkt_helper.c index c90c1e5bd..54d70066a 100644 --- a/onvm/onvm_nflib/onvm_pkt_helper.c +++ b/onvm/onvm_nflib/onvm_pkt_helper.c @@ -305,12 +305,10 @@ onvm_pkt_print_ipv4(struct ipv4_hdr* hdr) { printf("\n"); printf("Header Checksum: %" PRIu16 "\n", hdr->hdr_checksum); - printf("Source IP: %" PRIu32 " (%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 ")\n", hdr->src_addr, - hdr->src_addr & 0xFF, (hdr->src_addr >> 8) & 0xFF, (hdr->src_addr >> 16) & 0xFF, - (hdr->src_addr >> 24) & 0xFF); - printf("Destination IP: %" PRIu32 " (%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 ")\n", hdr->dst_addr, - hdr->dst_addr & 0xFF, (hdr->dst_addr >> 8) & 0xFF, (hdr->dst_addr >> 16) & 0xFF, - (hdr->dst_addr >> 24) & 0xFF); + printf("Source IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\n", (hdr->src_addr >> 24) & 0xFF, + (hdr->src_addr >> 16) & 0xFF, (hdr->src_addr >> 8) & 0xFF, hdr->src_addr & 0xFF); + printf("Destination IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\n", (hdr->dst_addr >> 24) & 0xFF, + (hdr->dst_addr >> 16) & 0xFF, (hdr->dst_addr >> 8) & 0xFF, hdr->dst_addr & 0xFF); } void From 05dff7be45c698f9a4436f07ad493ec3e4fe98a4 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Thu, 23 Jul 2020 07:46:46 -0500 Subject: [PATCH 17/27] Revert pkt helper changes --- onvm/onvm_nflib/onvm_pkt_helper.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/onvm/onvm_nflib/onvm_pkt_helper.c b/onvm/onvm_nflib/onvm_pkt_helper.c index 54d70066a..c90c1e5bd 100644 --- a/onvm/onvm_nflib/onvm_pkt_helper.c +++ b/onvm/onvm_nflib/onvm_pkt_helper.c @@ -305,10 +305,12 @@ onvm_pkt_print_ipv4(struct ipv4_hdr* hdr) { printf("\n"); printf("Header Checksum: %" PRIu16 "\n", hdr->hdr_checksum); - printf("Source IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\n", (hdr->src_addr >> 24) & 0xFF, - (hdr->src_addr >> 16) & 0xFF, (hdr->src_addr >> 8) & 0xFF, hdr->src_addr & 0xFF); - printf("Destination IP: %" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\n", (hdr->dst_addr >> 24) & 0xFF, - (hdr->dst_addr >> 16) & 0xFF, (hdr->dst_addr >> 8) & 0xFF, hdr->dst_addr & 0xFF); + printf("Source IP: %" PRIu32 " (%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 ")\n", hdr->src_addr, + hdr->src_addr & 0xFF, (hdr->src_addr >> 8) & 0xFF, (hdr->src_addr >> 16) & 0xFF, + (hdr->src_addr >> 24) & 0xFF); + printf("Destination IP: %" PRIu32 " (%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 ")\n", hdr->dst_addr, + hdr->dst_addr & 0xFF, (hdr->dst_addr >> 8) & 0xFF, (hdr->dst_addr >> 16) & 0xFF, + (hdr->dst_addr >> 24) & 0xFF); } void From 785ee446ab37412669de72a0be99f8d26e306107 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Fri, 24 Jul 2020 08:10:41 -0500 Subject: [PATCH 18/27] Tested with service chains. --- examples/test_flow_dir/test_flow_dir.c | 14 ++++++++------ onvm/onvm_nflib/onvm_flow_table.h | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 332860a5a..daa38715c 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -183,22 +183,23 @@ populate_sample_ipv4(void) { }; struct test_add_key keys[] = { - {{IPv4(101, 0, 0, 0), IPv4(100, 10, 0, 1), 0, 1, IPPROTO_TCP}, {1,2,3,4}}, - {{IPv4(102, 0, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {4,3,2,1}}, - {{IPv4(103, 0, 0, 0), IPv4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, + {{IPv4(100, 10, 0, 0), IPv4(100, 10, 0, 0), 1, 1, IPPROTO_TCP}, {2,3}}, + {{IPv4(102, 10, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {4,3,2,1}}, + {{IPv4(103, 10, 0, 0), IPv4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, }; uint32_t num_keys = RTE_DIM(keys); for (uint32_t i = 0; i < num_keys; i++) { struct onvm_ft_ipv4_5tuple key; + memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); key = keys[i].key; - int ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)flow_entry); + int ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)&flow_entry); if (ret >= 0) { continue; } else { printf("\nAdding Key: "); _onvm_ft_print_key(&key); - ret = onvm_ft_add_key(sdn_ft, &key, (char **)flow_entry); + ret = onvm_ft_add_key(sdn_ft, &key, (char **)&flow_entry); if (ret < 0) { printf("Unable to add key."); continue; @@ -246,7 +247,7 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, struct onvm_ft_ipv4_5tuple key; memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); onvm_ft_fill_key(&key, pkt); - ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)flow_entry); + ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)&flow_entry); if (ret >= 0) { meta->action = ONVM_NF_ACTION_NEXT; } else { @@ -306,6 +307,7 @@ main(int argc, char *argv[]) { onvm_nflib_run(nf_local_ctx); onvm_nflib_stop(nf_local_ctx); + flow_entry = NULL; rte_free(flow_entry); printf("If we reach here, program is ending\n"); return 0; diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index dba82dfe5..5117a6916 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -149,16 +149,16 @@ onvm_ft_fill_key(struct onvm_ft_ipv4_5tuple *key, struct rte_mbuf *pkt) { } ipv4_hdr = onvm_pkt_ipv4_hdr(pkt); key->proto = ipv4_hdr->next_proto_id; - key->src_addr = rte_cpu_to_be_32(ipv4_hdr->src_addr); - key->dst_addr = rte_cpu_to_be_32(ipv4_hdr->dst_addr); + key->src_addr = rte_be_to_cpu_32(ipv4_hdr->src_addr); + key->dst_addr = rte_be_to_cpu_32(ipv4_hdr->dst_addr); if (key->proto == IP_PROTOCOL_TCP) { tcp_hdr = onvm_pkt_tcp_hdr(pkt); - key->src_port = rte_cpu_to_be_16(tcp_hdr->src_port); - key->dst_port = rte_cpu_to_be_16(tcp_hdr->dst_port); + key->src_port = rte_be_to_cpu_16(tcp_hdr->src_port); + key->dst_port = rte_be_to_cpu_16(tcp_hdr->dst_port); } else if (key->proto == IP_PROTOCOL_UDP) { udp_hdr = onvm_pkt_udp_hdr(pkt); - key->src_port = rte_cpu_to_be_16(udp_hdr->src_port); - key->dst_port = rte_cpu_to_be_16(udp_hdr->dst_port); + key->src_port = rte_be_to_cpu_16(udp_hdr->src_port); + key->dst_port = rte_be_to_cpu_16(udp_hdr->dst_port); } else { key->src_port = 0; key->dst_port = 0; From 92092ee5223ea98c2be31373289dc9affc8a8547 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 28 Jul 2020 01:45:06 -0500 Subject: [PATCH 19/27] Test flow dir.c Ready for review. --- examples/test_flow_dir/test_flow_dir.c | 3 +-- onvm/onvm_nflib/onvm_flow_table.c | 16 +++++++++++++--- onvm/onvm_nflib/onvm_flow_table.h | 9 +++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index daa38715c..54c5d7791 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -186,12 +186,12 @@ populate_sample_ipv4(void) { {{IPv4(100, 10, 0, 0), IPv4(100, 10, 0, 0), 1, 1, IPPROTO_TCP}, {2,3}}, {{IPv4(102, 10, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {4,3,2,1}}, {{IPv4(103, 10, 0, 0), IPv4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, + {{IPv4(10, 11, 1, 17), IPv4(10, 11, 1, 17), 1234, 1234, IPPROTO_UDP}, {4,3,2}}, }; uint32_t num_keys = RTE_DIM(keys); for (uint32_t i = 0; i < num_keys; i++) { struct onvm_ft_ipv4_5tuple key; - memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); key = keys[i].key; int ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)&flow_entry); if (ret >= 0) { @@ -245,7 +245,6 @@ packet_handler(struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, } struct onvm_ft_ipv4_5tuple key; - memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); onvm_ft_fill_key(&key, pkt); ret = onvm_ft_lookup_key(sdn_ft, &key, (char **)&flow_entry); if (ret >= 0) { diff --git a/onvm/onvm_nflib/onvm_flow_table.c b/onvm/onvm_nflib/onvm_flow_table.c index a78bafdf7..6e8b070ef 100644 --- a/onvm/onvm_nflib/onvm_flow_table.c +++ b/onvm/onvm_nflib/onvm_flow_table.c @@ -121,12 +121,15 @@ onvm_ft_add_pkt(struct onvm_ft *table, struct rte_mbuf *pkt, char **data) { int32_t tbl_index; struct onvm_ft_ipv4_5tuple key; int err; + uint32_t softrss; err = onvm_ft_fill_key(&key, pkt); if (err < 0) { return err; } - tbl_index = rte_hash_add_key_with_hash(table->hash, (const void *)&key, pkt->hash.rss); + + softrss = onvm_softrss(&key); + tbl_index = rte_hash_add_key_with_hash(table->hash, (const void *)&key, softrss); if (tbl_index >= 0) { *data = &table->data[tbl_index * table->entry_size]; } @@ -144,12 +147,15 @@ onvm_ft_lookup_pkt(struct onvm_ft *table, struct rte_mbuf *pkt, char **data) { int32_t tbl_index; struct onvm_ft_ipv4_5tuple key; int ret; + uint32_t softrss; ret = onvm_ft_fill_key(&key, pkt); if (ret < 0) { return ret; } - tbl_index = rte_hash_lookup_with_hash(table->hash, (const void *)&key, pkt->hash.rss); + + softrss = onvm_softrss(&key); + tbl_index = rte_hash_lookup_with_hash(table->hash, (const void *)&key, softrss); if (tbl_index >= 0) { *data = onvm_ft_get_data(table, tbl_index); } @@ -167,12 +173,16 @@ int32_t onvm_ft_remove_pkt(struct onvm_ft *table, struct rte_mbuf *pkt) { struct onvm_ft_ipv4_5tuple key; int ret; + uint32_t softrss; ret = onvm_ft_fill_key(&key, pkt); if (ret < 0) { return ret; } - return rte_hash_del_key_with_hash(table->hash, (const void *)&key, pkt->hash.rss); + + softrss = onvm_softrss(&key); + + return rte_hash_del_key_with_hash(table->hash, (const void *)&key, softrss); } int diff --git a/onvm/onvm_nflib/onvm_flow_table.h b/onvm/onvm_nflib/onvm_flow_table.h index 5117a6916..bc2a3bde1 100644 --- a/onvm/onvm_nflib/onvm_flow_table.h +++ b/onvm/onvm_nflib/onvm_flow_table.h @@ -148,6 +148,7 @@ onvm_ft_fill_key(struct onvm_ft_ipv4_5tuple *key, struct rte_mbuf *pkt) { return -EPROTONOSUPPORT; } ipv4_hdr = onvm_pkt_ipv4_hdr(pkt); + memset(key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); key->proto = ipv4_hdr->next_proto_id; key->src_addr = rte_be_to_cpu_32(ipv4_hdr->src_addr); key->dst_addr = rte_be_to_cpu_32(ipv4_hdr->dst_addr); @@ -223,10 +224,10 @@ onvm_softrss(struct onvm_ft_ipv4_5tuple *key) { rte_convert_rss_key((uint32_t *)rss_symmetric_key, (uint32_t *)rss_key_be, RTE_DIM(rss_symmetric_key)); - tuple.v4.src_addr = rte_be_to_cpu_32(key->src_addr); - tuple.v4.dst_addr = rte_be_to_cpu_32(key->dst_addr); - tuple.v4.sport = rte_be_to_cpu_16(key->src_port); - tuple.v4.dport = rte_be_to_cpu_16(key->dst_port); + tuple.v4.src_addr = key->src_addr; + tuple.v4.dst_addr = key->dst_addr; + tuple.v4.sport = key->src_port; + tuple.v4.dport = key->dst_port; rss_l3l4 = rte_softrss_be((uint32_t *)&tuple, RTE_THASH_V4_L4_LEN, rss_key_be); From 7c79874c3bbae66117a14af21499a73ebe786453 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 28 Jul 2020 01:49:42 -0500 Subject: [PATCH 20/27] Styling and undo changes to speed tester. --- examples/load_balancer/load_balancer.c | 1 - examples/speed_tester/speed_tester.c | 1 - onvm/onvm_nflib/onvm_flow_table.c | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/load_balancer/load_balancer.c b/examples/load_balancer/load_balancer.c index 2d569bc06..46e6ea764 100644 --- a/examples/load_balancer/load_balancer.c +++ b/examples/load_balancer/load_balancer.c @@ -456,7 +456,6 @@ table_lookup_entry(struct rte_mbuf *pkt, struct flow_info **flow) { return -1; } - memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); int ret = onvm_ft_fill_key_symmetric(&key, pkt); if (ret < 0) return -1; diff --git a/examples/speed_tester/speed_tester.c b/examples/speed_tester/speed_tester.c index 2d5132ef7..c0321c7cc 100644 --- a/examples/speed_tester/speed_tester.c +++ b/examples/speed_tester/speed_tester.c @@ -345,7 +345,6 @@ nf_setup(struct onvm_nf_local_ctx *nf_local_ctx) { pmeta->action = ONVM_NF_ACTION_TONF; pmeta->flags = ONVM_SET_BIT(0, SPEED_TESTER_BIT); - memset(&key, 0, sizeof(struct onvm_ft_ipv4_5tuple)); onvm_ft_fill_key(&key, pkt); pkt->hash.rss = onvm_softrss(&key); diff --git a/onvm/onvm_nflib/onvm_flow_table.c b/onvm/onvm_nflib/onvm_flow_table.c index 6e8b070ef..f0673e225 100644 --- a/onvm/onvm_nflib/onvm_flow_table.c +++ b/onvm/onvm_nflib/onvm_flow_table.c @@ -153,7 +153,7 @@ onvm_ft_lookup_pkt(struct onvm_ft *table, struct rte_mbuf *pkt, char **data) { if (ret < 0) { return ret; } - + softrss = onvm_softrss(&key); tbl_index = rte_hash_lookup_with_hash(table->hash, (const void *)&key, softrss); if (tbl_index >= 0) { From 90b77a106f8c4b1031136d0000aed2b28e5cdda0 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 28 Jul 2020 04:20:44 -0500 Subject: [PATCH 21/27] Set Next action when destination is 255 --- onvm/onvm_nflib/onvm_nflib.c | 3 +++ onvm/onvm_nflib/onvm_pkt_common.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/onvm/onvm_nflib/onvm_nflib.c b/onvm/onvm_nflib/onvm_nflib.c index 2e5ecb33b..75e526239 100755 --- a/onvm/onvm_nflib/onvm_nflib.c +++ b/onvm/onvm_nflib/onvm_nflib.c @@ -555,6 +555,9 @@ onvm_nflib_start_nf(struct onvm_nf_local_ctx *nf_local_ctx, struct onvm_nf_init_ int onvm_nflib_run(struct onvm_nf_local_ctx *nf_local_ctx) { + /* Map the sdn_ft table */ + onvm_flow_dir_nf_init(); + int ret; pthread_t main_loop_thread; diff --git a/onvm/onvm_nflib/onvm_pkt_common.c b/onvm/onvm_nflib/onvm_pkt_common.c index 2a6d88c90..5a0fb65cd 100644 --- a/onvm/onvm_nflib/onvm_pkt_common.c +++ b/onvm/onvm_nflib/onvm_pkt_common.c @@ -102,7 +102,7 @@ onvm_pkt_process_tx_batch(struct queue_mgr *tx_mgr, struct rte_mbuf *pkts[], uin // and ! is 1. nf->stats.act_drop++; nf->stats.tx += !onvm_pkt_drop(pkts[i]); - } else if (meta->action == ONVM_NF_ACTION_NEXT) { + } else if (meta->action == ONVM_NF_ACTION_NEXT || meta->destination == 255) { /* TODO: Here we drop the packet : there will be a flow table in the future to know what to do with the packet next */ nf->stats.act_next++; From 98b4530d0355242200e80b703f2e7bc9746f270f Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 28 Jul 2020 10:03:21 -0500 Subject: [PATCH 22/27] Use pkt rss --- onvm/onvm_nflib/onvm_flow_table.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/onvm/onvm_nflib/onvm_flow_table.c b/onvm/onvm_nflib/onvm_flow_table.c index f0673e225..a78bafdf7 100644 --- a/onvm/onvm_nflib/onvm_flow_table.c +++ b/onvm/onvm_nflib/onvm_flow_table.c @@ -121,15 +121,12 @@ onvm_ft_add_pkt(struct onvm_ft *table, struct rte_mbuf *pkt, char **data) { int32_t tbl_index; struct onvm_ft_ipv4_5tuple key; int err; - uint32_t softrss; err = onvm_ft_fill_key(&key, pkt); if (err < 0) { return err; } - - softrss = onvm_softrss(&key); - tbl_index = rte_hash_add_key_with_hash(table->hash, (const void *)&key, softrss); + tbl_index = rte_hash_add_key_with_hash(table->hash, (const void *)&key, pkt->hash.rss); if (tbl_index >= 0) { *data = &table->data[tbl_index * table->entry_size]; } @@ -147,15 +144,12 @@ onvm_ft_lookup_pkt(struct onvm_ft *table, struct rte_mbuf *pkt, char **data) { int32_t tbl_index; struct onvm_ft_ipv4_5tuple key; int ret; - uint32_t softrss; ret = onvm_ft_fill_key(&key, pkt); if (ret < 0) { return ret; } - - softrss = onvm_softrss(&key); - tbl_index = rte_hash_lookup_with_hash(table->hash, (const void *)&key, softrss); + tbl_index = rte_hash_lookup_with_hash(table->hash, (const void *)&key, pkt->hash.rss); if (tbl_index >= 0) { *data = onvm_ft_get_data(table, tbl_index); } @@ -173,16 +167,12 @@ int32_t onvm_ft_remove_pkt(struct onvm_ft *table, struct rte_mbuf *pkt) { struct onvm_ft_ipv4_5tuple key; int ret; - uint32_t softrss; ret = onvm_ft_fill_key(&key, pkt); if (ret < 0) { return ret; } - - softrss = onvm_softrss(&key); - - return rte_hash_del_key_with_hash(table->hash, (const void *)&key, softrss); + return rte_hash_del_key_with_hash(table->hash, (const void *)&key, pkt->hash.rss); } int From c92b77a005aeaf90a6c3c4a9ff524e075d8b5701 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno <54540257+bdevierno1@users.noreply.github.com> Date: Tue, 28 Jul 2020 23:36:01 +0800 Subject: [PATCH 23/27] Documentation update. Service ID 255. --- docs/NF_Dev.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/NF_Dev.md b/docs/NF_Dev.md index 1c008e7ac..e9dcd3c88 100644 --- a/docs/NF_Dev.md +++ b/docs/NF_Dev.md @@ -24,6 +24,8 @@ Each NF needs to have a packet handler function. It must match this specificati - `ONVM_NF_ACTION_NEXT`: Forward the packet using the rule from the SDN controller stored in the flow table - `ONVM_NF_ACTION_TONF`: Forward the packet to the specified NF - `ONVM_NF_ACTION_OUT`: Forward the packet to the specified NIC port + +NFs that set destination ID to 255 will be forwarded with the `ONVM_NF_ACTION_NEXT` action. NF Library -- From d1136960c068f53fd13445296cdaa3b1443d8b90 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 28 Jul 2020 22:14:07 -0500 Subject: [PATCH 24/27] Define 255 --- onvm/onvm_nflib/onvm_common.h | 2 ++ onvm/onvm_nflib/onvm_pkt_common.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/onvm/onvm_nflib/onvm_common.h b/onvm/onvm_nflib/onvm_common.h index bb623d5b1..2231fab5f 100755 --- a/onvm/onvm_nflib/onvm_common.h +++ b/onvm/onvm_nflib/onvm_common.h @@ -79,6 +79,8 @@ #define ONVM_NF_ACTION_TONF 2 // send to the NF specified in the argument field (assume it is on the same host) #define ONVM_NF_ACTION_OUT 3 // send the packet out the NIC port set in the argument field +#define ACTION_NEXT_DEST_ID 255 // Destination service ID that will set the manager to perform flow table lookup. + #define PKT_WAKEUP_THRESHOLD 1 // for shared core mode, how many packets are required to wake up the NF #define MSG_WAKEUP_THRESHOLD 1 // for shared core mode, how many messages on an NF's ring are required to wake up the NF diff --git a/onvm/onvm_nflib/onvm_pkt_common.c b/onvm/onvm_nflib/onvm_pkt_common.c index 5a0fb65cd..f7158e029 100644 --- a/onvm/onvm_nflib/onvm_pkt_common.c +++ b/onvm/onvm_nflib/onvm_pkt_common.c @@ -102,9 +102,8 @@ onvm_pkt_process_tx_batch(struct queue_mgr *tx_mgr, struct rte_mbuf *pkts[], uin // and ! is 1. nf->stats.act_drop++; nf->stats.tx += !onvm_pkt_drop(pkts[i]); - } else if (meta->action == ONVM_NF_ACTION_NEXT || meta->destination == 255) { - /* TODO: Here we drop the packet : there will be a flow table - in the future to know what to do with the packet next */ + } else if (meta->action == ONVM_NF_ACTION_NEXT || meta->destination == ACTION_NEXT_DEST_ID) { + //Perform next action is configured by the manager's flow table nf->stats.act_next++; onvm_pkt_process_next_action(tx_mgr, pkts[i], nf); } else if (meta->action == ONVM_NF_ACTION_TONF) { From 0ff3053a9843782f2d5b69fbd9bf1e3a2ea500cf Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Tue, 28 Jul 2020 22:35:56 -0500 Subject: [PATCH 25/27] Style --- onvm/onvm_nflib/onvm_pkt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onvm/onvm_nflib/onvm_pkt_common.c b/onvm/onvm_nflib/onvm_pkt_common.c index f7158e029..cb039e3a2 100644 --- a/onvm/onvm_nflib/onvm_pkt_common.c +++ b/onvm/onvm_nflib/onvm_pkt_common.c @@ -103,7 +103,7 @@ onvm_pkt_process_tx_batch(struct queue_mgr *tx_mgr, struct rte_mbuf *pkts[], uin nf->stats.act_drop++; nf->stats.tx += !onvm_pkt_drop(pkts[i]); } else if (meta->action == ONVM_NF_ACTION_NEXT || meta->destination == ACTION_NEXT_DEST_ID) { - //Perform next action is configured by the manager's flow table + // Perform next action is configured by the manager's flow table nf->stats.act_next++; onvm_pkt_process_next_action(tx_mgr, pkts[i], nf); } else if (meta->action == ONVM_NF_ACTION_TONF) { From 02cf1a4ace5e103b67db86918c153667a22c95b4 Mon Sep 17 00:00:00 2001 From: Benjamin De Vierno Date: Thu, 30 Jul 2020 03:57:12 +0000 Subject: [PATCH 26/27] Update to use latest pktgen --- examples/test_flow_dir/test_flow_dir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 54c5d7791..118b38d8b 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -183,10 +183,10 @@ populate_sample_ipv4(void) { }; struct test_add_key keys[] = { - {{IPv4(100, 10, 0, 0), IPv4(100, 10, 0, 0), 1, 1, IPPROTO_TCP}, {2,3}}, - {{IPv4(102, 10, 0, 0), IPv4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {4,3,2,1}}, - {{IPv4(103, 10, 0, 0), IPv4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, - {{IPv4(10, 11, 1, 17), IPv4(10, 11, 1, 17), 1234, 1234, IPPROTO_UDP}, {4,3,2}}, + {{RTE_IPV4(100, 10, 0, 0), RTE_IPV4(100, 10, 0, 0), 1, 1, IPPROTO_TCP}, {2,3}}, + {{RTE_IPV4(102, 10, 0, 0), RTE_IPV4(101, 10, 0, 1), 0, 1, IPPROTO_TCP}, {4,3,2,1}}, + {{RTE_IPV4(103, 10, 0, 0), RTE_IPV4(102, 10, 0, 1), 0, 1, IPPROTO_TCP}, {2,1}}, + {{RTE_IPV4(10, 11, 1, 17), RTE_IPV4(10, 11, 1, 17), 1234, 1234, IPPROTO_UDP}, {4,3,2}}, }; uint32_t num_keys = RTE_DIM(keys); From 965329af3b6ed1bc1e391bd1149b19144cb0b678 Mon Sep 17 00:00:00 2001 From: bdevierno1 Date: Thu, 14 Jan 2021 03:15:51 -0600 Subject: [PATCH 27/27] Remove multiple defn for var flow_entry --- examples/test_flow_dir/test_flow_dir.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/test_flow_dir/test_flow_dir.c b/examples/test_flow_dir/test_flow_dir.c index 5c1b1ea20..756049023 100644 --- a/examples/test_flow_dir/test_flow_dir.c +++ b/examples/test_flow_dir/test_flow_dir.c @@ -172,11 +172,6 @@ do_stats_display(struct rte_mbuf *pkt) { static void populate_sample_ipv4(void) { - struct onvm_flow_entry *flow_entry = (struct onvm_flow_entry *) - rte_calloc(NULL, 1, sizeof(struct onvm_flow_entry), 0); - if (flow_entry == NULL) { - rte_exit(EXIT_FAILURE, "Unable to populate flow.\n"); - } struct test_add_key { struct onvm_ft_ipv4_5tuple key; uint8_t destinations[ONVM_MAX_CHAIN_LENGTH]; @@ -216,8 +211,6 @@ populate_sample_ipv4(void) { } } } - flow_entry = NULL; - rte_free(flow_entry); } static void @@ -306,8 +299,8 @@ main(int argc, char *argv[]) { onvm_nflib_run(nf_local_ctx); onvm_nflib_stop(nf_local_ctx); - flow_entry = NULL; rte_free(flow_entry); + flow_entry = NULL; printf("If we reach here, program is ending\n"); return 0; }