Add support for multisocket memory reservation
[samplevnf.git] / VNFs / DPPD-PROX / handle_lb_net.c
index 878b815..1bfb6c3 100644 (file)
@@ -37,6 +37,7 @@
 #include "hash_utils.h"
 #include "quit.h"
 #include "flow_iter.h"
+#include "prox_compat.h"
 
 #if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
 #define RTE_CACHE_LINE_SIZE CACHE_LINE_SIZE
@@ -87,18 +88,29 @@ static struct rte_table_hash *setup_gre_to_wt_lookup(struct task_args *targ, uin
                }
        }
 
-       struct rte_table_hash_ext_params table_hash_params = {
+       static char hash_name[30];
+       sprintf(hash_name, "lb_hash_table_%03d", targ->lconf->id);
+
+       // The key offset in the real packets might depend of the packet type; hence we need to extract the
+       // keys and copy them.
+       // The packets will be parsed runtime and keys will be created and stored in the metadata of fake mbufs.
+       // Then hash functions will be used on the fake mbufs.
+       // Keys are stored in (metadata of) fake mbufs to reduce the memory/cache usage: in this way we use only
+       // 64  cache lines for all keys (we always use the same fake mbufs). If using metadata of real packets/mbufs,
+       // we would use as many cache lines as there are mbufs, which might be very high in if QoS is supported for instance.
+       //
+       struct prox_rte_table_params table_hash_params = {
+               .name = hash_name,
                .key_size = 4,
                .n_keys = count,
                .n_buckets = count,
-               .n_buckets_ext = count >> 1,
-               .f_hash = hash_crc32,
+               .f_hash = (rte_table_hash_op_hash)hash_crc32,
                .seed = 0,
-               .signature_offset = HASH_METADATA_OFFSET(0),
                .key_offset = HASH_METADATA_OFFSET(0),
+               .key_mask = NULL
        };
 
-       ret = rte_table_hash_ext_dosig_ops.f_create(&table_hash_params, socket_id, sizeof(uint8_t));
+       ret = prox_rte_table_create(&table_hash_params, socket_id, sizeof(uint8_t));
 
        for (int i = 0; i < n_workers; ++i) {
                struct core_task ct = targ->core_task_set[0].core_task[i];
@@ -113,7 +125,7 @@ static struct rte_table_hash *setup_gre_to_wt_lookup(struct task_args *targ, uin
                        uint32_t gre_id = it->get_gre_id(it, t);
                        uint8_t dst = i;
 
-                       r = rte_table_hash_ext_dosig_ops.f_add(ret, &gre_id, &dst, &key_found, &entry_in_hash);
+                       r = prox_rte_table_add(ret, &gre_id, &dst, &key_found, &entry_in_hash);
                        if (r) {
                                plog_err("Failed to add gre_id = %x, dest worker = %u\n", gre_id, i);
                        }
@@ -274,7 +286,7 @@ static int handle_lb_net_lut_bulk(struct task_base *tbase, struct rte_mbuf **mbu
        }
 #endif
        // keys have been extracted for all packets, now do the lookup
-       rte_table_hash_ext_dosig_ops.f_lookup(task->worker_hash_table, task->fake_packets, pkts_mask, &lookup_hit_mask, (void**)wt);
+       prox_rte_table_lookup(task->worker_hash_table, task->fake_packets, pkts_mask, &lookup_hit_mask, (void**)wt);
        /* mbufs now contains the packets that have not been dropped */
        if (likely(lookup_hit_mask == RTE_LEN2MASK(n_pkts, uint64_t))) {
                for (j = 0; j < n_pkts; ++j) {
@@ -345,9 +357,9 @@ static inline uint8_t worker_from_mask(struct task_lb_net *task, uint32_t val)
 static inline int extract_gre_key(struct task_lb_net_lut *task, uint32_t *key, struct rte_mbuf *mbuf)
 {
        // For all packets, one by one, remove MPLS tag if any and fills in keys used by "fake" packets
-       struct ether_hdr *peth = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
+       prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
        // Check for MPLS TAG
-       struct ipv4_hdr *ip;
+       prox_rte_ipv4_hdr *ip;
        if (peth->ether_type == ETYPE_MPLSU) {
                struct mpls_hdr *mpls = (struct mpls_hdr *)(peth + 1);
                uint32_t mpls_len = 0;
@@ -356,12 +368,12 @@ static inline int extract_gre_key(struct task_lb_net_lut *task, uint32_t *key, s
                        mpls_len += sizeof(struct mpls_hdr);
                }
                mpls_len += sizeof(struct mpls_hdr);
-               ip = (struct ipv4_hdr *)(mpls + 1);
+               ip = (prox_rte_ipv4_hdr *)(mpls + 1);
                switch (ip->version_ihl >> 4) {
                case 4:
                        // Remove MPLS Tag if requested
                        if (task->runtime_flags & TASK_MPLS_TAGGING) {
-                               peth = (struct ether_hdr *)rte_pktmbuf_adj(mbuf, mpls_len);
+                               peth = (prox_rte_ether_hdr *)rte_pktmbuf_adj(mbuf, mpls_len);
                                peth->ether_type = ETYPE_IPv4;
                        }
                        break;
@@ -374,7 +386,7 @@ static inline int extract_gre_key(struct task_lb_net_lut *task, uint32_t *key, s
                }
        }
        else {
-               ip = (struct ipv4_hdr *)(peth + 1);
+               ip = (prox_rte_ipv4_hdr *)(peth + 1);
        }
        // Entry point for the packet => check for packet validity
        // => do not use extract_key_core(mbufs[j], &task->keys[j]);
@@ -398,13 +410,13 @@ static inline int extract_gre_key(struct task_lb_net_lut *task, uint32_t *key, s
                }
        }
        else {
-               plog_warn("Invalid protocol: GRE xas expected, got 0x%x\n", ip->next_proto_id);
+               plog_warn("Invalid protocol: GRE was expected, got 0x%x\n", ip->next_proto_id);
                return 1;
        }
        return 0;
 }
 
-static inline uint8_t lb_ip4(struct task_lb_net *task, struct ipv4_hdr *ip)
+static inline uint8_t lb_ip4(struct task_lb_net *task, prox_rte_ipv4_hdr *ip)
 {
        if (unlikely(ip->version_ihl >> 4 != 4)) {
                plog_warn("Expected to receive IPv4 packet but IP version was %d\n",
@@ -441,7 +453,7 @@ static inline uint8_t lb_ip4(struct task_lb_net *task, struct ipv4_hdr *ip)
        return OUT_DISCARD;
 }
 
-static inline uint8_t lb_ip6(struct task_lb_net *task, struct ipv6_hdr *ip)
+static inline uint8_t lb_ip6(struct task_lb_net *task, prox_rte_ipv6_hdr *ip)
 {
        if (unlikely((*(uint8_t*)ip) >> 4 != 6)) {
                plog_warn("Expected to receive IPv6 packet but IP version was %d\n",
@@ -453,7 +465,7 @@ static inline uint8_t lb_ip6(struct task_lb_net *task, struct ipv6_hdr *ip)
        return worker + task->nb_worker_threads * IPV6;
 }
 
-static inline uint8_t lb_mpls(struct task_lb_net *task, struct ether_hdr *peth, struct rte_mbuf *mbuf)
+static inline uint8_t lb_mpls(struct task_lb_net *task, prox_rte_ether_hdr *peth, struct rte_mbuf *mbuf)
 {
        struct mpls_hdr *mpls = (struct mpls_hdr *)(peth + 1);
        uint32_t mpls_len = 0;
@@ -462,21 +474,21 @@ static inline uint8_t lb_mpls(struct task_lb_net *task, struct ether_hdr *peth,
                mpls_len += sizeof(struct mpls_hdr);
        }
        mpls_len += sizeof(struct mpls_hdr);
-       struct ipv4_hdr *ip = (struct ipv4_hdr *)(mpls + 1);
+       prox_rte_ipv4_hdr *ip = (prox_rte_ipv4_hdr *)(mpls + 1);
 
        switch (ip->version_ihl >> 4) {
        case 4:
                if (task->runtime_flags & TASK_MPLS_TAGGING) {
-                       peth = (struct ether_hdr *)rte_pktmbuf_adj(mbuf, mpls_len);
+                       peth = (prox_rte_ether_hdr *)rte_pktmbuf_adj(mbuf, mpls_len);
                        peth->ether_type = ETYPE_IPv4;
                }
                return lb_ip4(task, ip);
        case 6:
                if (task->runtime_flags & TASK_MPLS_TAGGING) {
-                       peth = (struct ether_hdr *)rte_pktmbuf_adj(mbuf, mpls_len);
+                       peth = (prox_rte_ether_hdr *)rte_pktmbuf_adj(mbuf, mpls_len);
                        peth->ether_type = ETYPE_IPv6;
                }
-               return lb_ip6(task, (struct ipv6_hdr *)ip);
+               return lb_ip6(task, (prox_rte_ipv6_hdr *)ip);
        default:
                plogd_warn(mbuf, "Failed Decoding MPLS Packet - neither IPv4 neither IPv6: version %u for packet : \n", ip->version_ihl);
                return OUT_DISCARD;
@@ -495,7 +507,7 @@ static inline uint8_t lb_qinq(struct task_lb_net *task, struct qinq_hdr *qinq)
 
 static inline uint8_t handle_lb_net(struct task_lb_net *task, struct rte_mbuf *mbuf)
 {
-       struct ether_hdr *peth = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
+       prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
        const uint16_t len = rte_pktmbuf_pkt_len(mbuf);
        if (len < 60) {
                plogd_warn(mbuf, "Unexpected frame len = %d for packet : \n", len);
@@ -508,9 +520,9 @@ static inline uint8_t handle_lb_net(struct task_lb_net *task, struct rte_mbuf *m
        case ETYPE_8021ad:
                return lb_qinq(task, (struct qinq_hdr *)peth);
        case ETYPE_IPv4:
-               return lb_ip4(task, (struct ipv4_hdr *)(peth + 1));
+               return lb_ip4(task, (prox_rte_ipv4_hdr *)(peth + 1));
        case ETYPE_IPv6:
-               return lb_ip6(task, (struct ipv6_hdr *)(peth + 1));
+               return lb_ip6(task, (prox_rte_ipv6_hdr *)(peth + 1));
        case ETYPE_LLDP:
                return OUT_DISCARD;
        default: