Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / handle_routing.c
index 9dd45ed..4683ede 100644 (file)
 #include "mpls.h"
 #include "qinq.h"
 #include "prox_cfg.h"
-#include "ip6_addr.h"
 #include "prox_shared.h"
 #include "prox_cksum.h"
 #include "mbuf_utils.h"
+#include "prox_compat.h"
 
 struct task_routing {
        struct task_base                base;
@@ -48,7 +48,6 @@ struct task_routing {
        struct lcore_cfg                *lconf;
        struct rte_lpm                  *ipv4_lpm;
        struct next_hop                 *next_hops;
-       int                             offload_crc;
        uint32_t                        number_free_rules;
        uint16_t                        qinq_tag;
        uint32_t                        marking[4];
@@ -144,9 +143,6 @@ static void init_task_routing(struct task_base *tbase, struct task_args *targ)
        }
 
        struct prox_port_cfg *port = find_reachable_port(targ);
-       if (port) {
-               task->offload_crc = port->capabilities.tx_offload_cksum;
-       }
 
        targ->lconf->ctrl_func_m[targ->task] = routing_update;
        targ->lconf->ctrl_timeout = freq_to_tsc(20);
@@ -181,16 +177,14 @@ static int handle_routing_bulk(struct task_base *tbase, struct rte_mbuf **mbufs,
 
 static void set_l2(struct task_routing *task, struct rte_mbuf *mbuf, uint8_t nh_idx)
 {
-       struct ether_hdr *peth = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
+       prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
        *((uint64_t *)(&peth->d_addr)) = task->next_hops[nh_idx].mac_port_8bytes;
        *((uint64_t *)(&peth->s_addr)) = task->src_mac[task->next_hops[nh_idx].mac_port.out_idx];
 }
 
-static void set_l2_mpls(struct task_routing *task, struct rte_mbuf *mbuf, uint8_t nh_idx, uint16_t l2_len)
+static void set_l2_mpls(struct task_routing *task, struct rte_mbuf *mbuf, uint8_t nh_idx)
 {
-       struct ether_hdr *peth = (struct ether_hdr *)rte_pktmbuf_prepend(mbuf, sizeof(struct mpls_hdr));
-       l2_len += sizeof(struct mpls_hdr);
-       prox_ip_cksum(mbuf, (struct ipv4_hdr *)((uint8_t *)peth + l2_len), l2_len, sizeof(struct ipv4_hdr), task->offload_crc);
+       prox_rte_ether_hdr *peth = (prox_rte_ether_hdr *)rte_pktmbuf_prepend(mbuf, sizeof(struct mpls_hdr));
 
        *((uint64_t *)(&peth->d_addr)) = task->next_hops[nh_idx].mac_port_8bytes;
        *((uint64_t *)(&peth->s_addr)) = task->src_mac[task->next_hops[nh_idx].mac_port.out_idx];
@@ -198,8 +192,7 @@ static void set_l2_mpls(struct task_routing *task, struct rte_mbuf *mbuf, uint8_
        struct mpls_hdr *mpls = (struct mpls_hdr *)(peth + 1);
 
        if (task->runtime_flags & TASK_MARK) {
-                  enum rte_meter_color color = rte_sched_port_pkt_read_color(mbuf);
-
+                  enum prox_rte_color color = rte_sched_port_pkt_read_color(mbuf);
                 *(uint32_t *)mpls = task->next_hops[nh_idx].mpls | task->marking[color] | 0x00010000; // Set BoS to 1
        }
        else {
@@ -209,8 +202,8 @@ static void set_l2_mpls(struct task_routing *task, struct rte_mbuf *mbuf, uint8_
 
 static uint8_t route_ipv4(struct task_routing *task, uint8_t *beg, uint32_t ip_offset, struct rte_mbuf *mbuf)
 {
-       struct ipv4_hdr *ip = (struct ipv4_hdr*)(beg + ip_offset);
-       struct ether_hdr *peth_out;
+       prox_rte_ipv4_hdr *ip = (prox_rte_ipv4_hdr*)(beg + ip_offset);
+       prox_rte_ether_hdr *peth_out;
        uint8_t tx_port;
        uint32_t dst_ip;
 
@@ -224,7 +217,7 @@ static uint8_t route_ipv4(struct task_routing *task, uint8_t *beg, uint32_t ip_o
        switch(ip->next_proto_id) {
        case IPPROTO_GRE: {
                struct gre_hdr *pgre = (struct gre_hdr *)(ip + 1);
-               dst_ip = ((struct ipv4_hdr *)(pgre + 1))->dst_addr;
+               dst_ip = ((prox_rte_ipv4_hdr *)(pgre + 1))->dst_addr;
                break;
        }
        case IPPROTO_TCP:
@@ -255,7 +248,7 @@ static uint8_t route_ipv4(struct task_routing *task, uint8_t *beg, uint32_t ip_o
                        rte_pktmbuf_trim(mbuf, padlen);
                 }
 
-                set_l2_mpls(task, mbuf, next_hop_index, ip_offset);
+                set_l2_mpls(task, mbuf, next_hop_index);
         }
        else {
                set_l2(task, mbuf, next_hop_index);
@@ -266,7 +259,7 @@ static uint8_t route_ipv4(struct task_routing *task, uint8_t *beg, uint32_t ip_o
 static inline uint8_t handle_routing(struct task_routing *task, struct rte_mbuf *mbuf)
 {
        struct qinq_hdr *qinq;
-       struct ether_hdr *peth = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
+       prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbuf, prox_rte_ether_hdr *);
 
        switch (peth->ether_type) {
        case ETYPE_8021ad: {
@@ -283,7 +276,7 @@ static inline uint8_t handle_routing(struct task_routing *task, struct rte_mbuf
        case ETYPE_MPLSU: {
                /* skip MPLS headers if any for routing */
                struct mpls_hdr *mpls = (struct mpls_hdr *)(peth + 1);
-               uint32_t count = sizeof(struct ether_hdr);
+               uint32_t count = sizeof(prox_rte_ether_hdr);
                while (!(mpls->bytes & 0x00010000)) {
                        mpls++;
                        count += sizeof(struct mpls_hdr);
@@ -311,7 +304,7 @@ static struct task_init task_init_routing = {
        .mode_str = "routing",
        .init = init_task_routing,
        .handle = handle_routing_bulk,
-       .flag_features = TASK_FEATURE_ROUTING,
+       .flag_features = TASK_FEATURE_ROUTING|TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS,
        .size = sizeof(struct task_routing)
 };