Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / task_init.c
index 2361d32..97f7188 100644 (file)
@@ -1,5 +1,5 @@
 /*
-// Copyright (c) 2010-2017 Intel Corporation
+// Copyright (c) 2010-2020 Intel Corporation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -176,6 +176,8 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
                if (targ->nb_rxports == 1) {
                        if (targ->flags & TASK_ARG_L3)
                                tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw1_multi_l3 : rx_pkt_hw1_l3;
+                       else if (targ->flags & TASK_ARG_NDP)
+                               tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw1_multi_ndp : rx_pkt_hw1_ndp;
                        else
                                tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw1_multi : rx_pkt_hw1;
                        tbase->rx_params_hw1.rx_pq.port =  targ->rx_port_queue[0].port;
@@ -185,6 +187,8 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
                        PROX_ASSERT((targ->nb_rxports != 0) || (targ->task_init->flag_features & TASK_FEATURE_NO_RX));
                        if (targ->flags & TASK_ARG_L3)
                                tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw_multi_l3 : rx_pkt_hw_l3;
+                       else if (targ->flags & TASK_ARG_NDP)
+                               tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw_multi_ndp : rx_pkt_hw_ndp;
                        else
                                tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw_multi : rx_pkt_hw;
                        tbase->rx_params_hw.nb_rxports = targ->nb_rxports;
@@ -198,6 +202,8 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
                        if (rte_is_power_of_2(targ->nb_rxports)) {
                                if (targ->flags & TASK_ARG_L3)
                                        tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw_pow2_multi_l3 : rx_pkt_hw_pow2_l3;
+                               else if (targ->flags & TASK_ARG_NDP)
+                                       tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw_pow2_multi_ndp : rx_pkt_hw_pow2_ndp;
                                else
                                        tbase->rx_pkt = (targ->task_init->flag_features & TASK_FEATURE_MULTI_RX)? rx_pkt_hw_pow2_multi : rx_pkt_hw_pow2;
                                tbase->rx_params_hw.rxport_mask = targ->nb_rxports - 1;
@@ -208,7 +214,7 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
        if ((targ->nb_txrings != 0) && (!targ->tx_opt_ring) && (!(targ->flags & TASK_ARG_DROP))) {
                // Transmitting to a ring in NO DROP. We need to make sure the receiving task in not running on the same core.
                // Otherwise we might end up in a dead lock: trying in a loop to transmit to a task which cannot receive anymore
-               // (as npt being scheduled).
+               // (as not being scheduled).
                struct core_task ct;
                struct task_args *dtarg;
                for (unsigned int j = 0; j < targ->nb_txrings; j++) {
@@ -277,6 +283,7 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
                        prev = prev->tx_opt_ring_task;
                }
        }
+
        if (targ->nb_txrings == 1 || targ->nb_txports == 1 || targ->tx_opt_ring) {
                if (targ->task_init->flag_features & TASK_FEATURE_NEVER_DISCARDS) {
                        if (targ->tx_opt_ring) {
@@ -295,7 +302,7 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
                                        tbase->tx_pkt = targ->nb_txrings ? tx_pkt_no_drop_never_discard_sw1 : tx_pkt_no_drop_never_discard_hw1_lat_opt;
                        }
                        if ((targ->nb_txrings) || ((targ->task_init->flag_features & TASK_FEATURE_THROUGHPUT_OPT) == 0))
-                               tbase->flags |= FLAG_NEVER_FLUSH;
+                               tbase->flags |= TBASE_FLAG_NEVER_FLUSH;
                        else
                                targ->lconf->flush_queues[targ->task] = flush_function(targ);
                }
@@ -309,7 +316,7 @@ static size_t init_rx_tx_rings_ports(struct task_args *targ, struct task_base *t
                        else {
                                tbase->tx_pkt = targ->nb_txrings ? tx_pkt_no_drop_sw1 : tx_pkt_no_drop_hw1;
                        }
-                       tbase->flags |= FLAG_NEVER_FLUSH;
+                       tbase->flags |= TBASE_FLAG_NEVER_FLUSH;
                }
        }
        else {
@@ -345,22 +352,11 @@ struct task_base *init_task_struct(struct task_args *targ)
        offset += t->size;
 
        if (targ->nb_txrings == 0 && targ->nb_txports == 0)
-               tbase->flags |= FLAG_NEVER_FLUSH;
+               tbase->flags |= TBASE_FLAG_NEVER_FLUSH;
 
        offset = init_rx_tx_rings_ports(targ, tbase, offset);
        tbase->aux = (struct task_base_aux *)(((uint8_t *)tbase) + offset);
 
-       if (targ->nb_txports != 0) {
-               if (targ->flags & TASK_ARG_L3) {
-                       tbase->aux->tx_pkt_l2 = tbase->tx_pkt;
-                       tbase->tx_pkt = tx_pkt_l3;
-               }
-       }
-
-       if (targ->task_init->flag_features & TASK_FEATURE_RX_ALL) {
-               task_base_add_rx_pkt_function(tbase, rx_pkt_all);
-               tbase->aux->all_mbufs = prox_zmalloc(MAX_RX_PKT_ALL * sizeof(* tbase->aux->all_mbufs), task_socket);
-       }
        if (targ->task_init->flag_features & TASK_FEATURE_TSC_RX) {
                task_base_add_rx_pkt_function(tbase, rx_pkt_tsc);
        }
@@ -369,13 +365,21 @@ struct task_base *init_task_struct(struct task_args *targ)
 
        tbase->handle_bulk = t->handle;
 
-       if (targ->flags & TASK_ARG_L3) {
-               plog_info("\tTask configured in L3 mode\n");
+       if (targ->flags & (TASK_ARG_L3|TASK_ARG_NDP)) {
+               plog_info("\t\tTask (%d,%d) configured in L3/NDP mode\n", targ->lconf->id, targ->id);
                tbase->l3.ctrl_plane_ring = targ->ctrl_plane_ring;
-       }
-       if (targ->nb_txports != 0) {
-               if (targ->flags & TASK_ARG_L3)
-                       task_init_l3(tbase, targ);
+               if (targ->nb_txports != 0) {
+                       tbase->aux->tx_pkt_l2 = tbase->tx_pkt;
+                       tbase->aux->tx_ctrlplane_pkt = targ->nb_txrings ? tx_ctrlplane_sw : tx_ctrlplane_hw;
+                       if (targ->flags & TASK_ARG_L3) {
+                               tbase->tx_pkt = tx_pkt_l3;
+                               task_init_l3(tbase, targ);
+                       } else if (targ->flags & TASK_ARG_NDP) {
+                               tbase->tx_pkt = tx_pkt_ndp;
+                               task_init_l3(tbase, targ);
+                       }
+                       // Make sure control plane packets such as arp are not dropped
+               }
        }
 
        targ->tbase = tbase;