18b52a31eSHanoh Haim/*
2e33e37efSIdo Barnea  Hanoh Haim
3e33e37efSIdo Barnea  Cisco Systems, Inc.
48b52a31eSHanoh Haim*/
58b52a31eSHanoh Haim
68b52a31eSHanoh Haim/*
788089080SIdo Barnea  Copyright (c) 2015-2017 Cisco Systems, Inc.
88b52a31eSHanoh Haim
9e33e37efSIdo Barnea  Licensed under the Apache License, Version 2.0 (the "License");
10e33e37efSIdo Barnea  you may not use this file except in compliance with the License.
11e33e37efSIdo Barnea  You may obtain a copy of the License at
128b52a31eSHanoh Haim
13e33e37efSIdo Barnea  http://www.apache.org/licenses/LICENSE-2.0
148b52a31eSHanoh Haim
15e33e37efSIdo Barnea  Unless required by applicable law or agreed to in writing, software
16e33e37efSIdo Barnea  distributed under the License is distributed on an "AS IS" BASIS,
17e33e37efSIdo Barnea  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e33e37efSIdo Barnea  See the License for the specific language governing permissions and
19e33e37efSIdo Barnea  limitations under the License.
208b52a31eSHanoh Haim*/
218ea0aeb8SIdo Barnea#include <assert.h>
228ea0aeb8SIdo Barnea#include <pthread.h>
23344e3045Simarom#include <signal.h>
248b52a31eSHanoh Haim#include <pwd.h>
258ea0aeb8SIdo Barnea#include <stdio.h>
268ea0aeb8SIdo Barnea#include <string.h>
278ea0aeb8SIdo Barnea#include <unistd.h>
288ea0aeb8SIdo Barnea#include <zmq.h>
298b52a31eSHanoh Haim#include <rte_common.h>
308b52a31eSHanoh Haim#include <rte_log.h>
318b52a31eSHanoh Haim#include <rte_memory.h>
328b52a31eSHanoh Haim#include <rte_memcpy.h>
338b52a31eSHanoh Haim#include <rte_memzone.h>
348b52a31eSHanoh Haim#include <rte_tailq.h>
358b52a31eSHanoh Haim#include <rte_eal.h>
368b52a31eSHanoh Haim#include <rte_per_lcore.h>
378b52a31eSHanoh Haim#include <rte_launch.h>
388b52a31eSHanoh Haim#include <rte_atomic.h>
398b52a31eSHanoh Haim#include <rte_cycles.h>
408b52a31eSHanoh Haim#include <rte_prefetch.h>
418b52a31eSHanoh Haim#include <rte_lcore.h>
428b52a31eSHanoh Haim#include <rte_per_lcore.h>
438b52a31eSHanoh Haim#include <rte_branch_prediction.h>
448b52a31eSHanoh Haim#include <rte_interrupts.h>
458b52a31eSHanoh Haim#include <rte_pci.h>
468b52a31eSHanoh Haim#include <rte_debug.h>
478b52a31eSHanoh Haim#include <rte_ether.h>
488b52a31eSHanoh Haim#include <rte_ethdev.h>
498b52a31eSHanoh Haim#include <rte_ring.h>
508b52a31eSHanoh Haim#include <rte_mempool.h>
518b52a31eSHanoh Haim#include <rte_mbuf.h>
528b52a31eSHanoh Haim#include <rte_random.h>
53b19ca363SIdo Barnea#include <rte_version.h>
54659ba260SMartin Weiser#include <rte_ip.h>
568b52a31eSHanoh Haim#include "bp_sim.h"
578b52a31eSHanoh Haim#include "os_time.h"
588ea0aeb8SIdo Barnea#include "common/arg/SimpleGlob.h"
598ea0aeb8SIdo Barnea#include "common/arg/SimpleOpt.h"
608ea0aeb8SIdo Barnea#include "common/basic_utils.h"
618ea0aeb8SIdo Barnea#include "stateless/cp/trex_stateless.h"
628ea0aeb8SIdo Barnea#include "stateless/dp/trex_stream_node.h"
638ea0aeb8SIdo Barnea#include "stateless/messaging/trex_stateless_messaging.h"
64582d3f74SIdo Barnea#include "stateless/rx/trex_stateless_rx_core.h"
658ea0aeb8SIdo Barnea#include "publisher/trex_publisher.h"
668ea0aeb8SIdo Barnea#include "../linux_dpdk/version.h"
678b52a31eSHanoh Haimextern "C" {
683c106ce7SIdo Barnea#include "dpdk/drivers/net/ixgbe/base/ixgbe_type.h"
6958f1ee52SIdo Barnea#include "dpdk_funcs.h"
708b52a31eSHanoh Haim}
713c106ce7SIdo Barnea#include "dpdk/drivers/net/e1000/base/e1000_regs.h"
728b52a31eSHanoh Haim#include "global_io_mode.h"
738b52a31eSHanoh Haim#include "utl_term_io.h"
748b52a31eSHanoh Haim#include "msg_manager.h"
758b52a31eSHanoh Haim#include "platform_cfg.h"
76af781231SIdo Barnea#include "pre_test.h"
77efb88737SIdo Barnea#include "stateful_rx_core.h"
78429c0e40SIdo Barnea#include "debug.h"
79efb88737SIdo Barnea#include "pkt_gen.h"
8000bfc58eSYaroslav Brustinov#include "trex_port_attr.h"
818ea0aeb8SIdo Barnea#include "internal_api/trex_platform_api.h"
828ea0aeb8SIdo Barnea#include "main_dpdk.h"
833c4a29e1Simarom#include "trex_watchdog.h"
848b52a31eSHanoh Haim
858b52a31eSHanoh Haim#define RX_CHECK_MIX_SAMPLE_RATE 8
868b52a31eSHanoh Haim#define RX_CHECK_MIX_SAMPLE_RATE_1G 2
878b52a31eSHanoh Haim
888b52a31eSHanoh Haim#define MAX_PKT_BURST   32
898b52a31eSHanoh Haim
908b52a31eSHanoh Haim#define BP_MAX_CORES 32
918b52a31eSHanoh Haim#define BP_MAX_TX_QUEUE 16
928b52a31eSHanoh Haim#define BP_MASTER_AND_LATENCY 2
938b52a31eSHanoh Haim
9488089080SIdo Barnea#define RX_DESC_NUM_DROP_Q 64
9588089080SIdo Barnea#define RX_DESC_NUM_DATA_Q 1024
9688089080SIdo Barnea#define RX_DESC_NUM_DROP_Q_MLX 8
9788089080SIdo Barnea#define RX_DESC_NUM_DATA_Q_VM 512
9888089080SIdo Barnea#define TX_DESC_NUM 512
998b52a31eSHanoh Haim
1008b52a31eSHanoh Haimtypedef struct rte_mbuf * (*rte_mbuf_convert_to_one_seg_t)(struct rte_mbuf *m);
1018b52a31eSHanoh Haimstruct rte_mbuf *  rte_mbuf_convert_to_one_seg(struct rte_mbuf *m);
10200c9ca3bSYaroslav Brustinovextern "C" int rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id);
1032ba80c6aSYaroslav Brustinovvoid set_driver();
10400c9ca3bSYaroslav Brustinovvoid reorder_dpdk_ports();
1058b52a31eSHanoh Haim
1068714436fSIdo Barneastatic int max_stat_hw_id_seen = 0;
107d3b66fddSIdo Barneastatic int max_stat_hw_id_seen_payload = 0;
1088714436fSIdo Barnea
109e33e37efSIdo Barneastatic inline int get_is_rx_thread_enabled() {
110582d3f74SIdo Barnea    return ((CGlobalInfo::m_options.is_rx_enabled() || CGlobalInfo::m_options.is_stateless()) ?1:0);
1118b52a31eSHanoh Haim}
1128b52a31eSHanoh Haim
1138b52a31eSHanoh Haimstruct port_cfg_t;
1148b52a31eSHanoh Haim
1157b8fd5a8SYaroslav Brustinov#define MAX_DPDK_ARGS 50
11600bfc58eSYaroslav Brustinovstatic CPlatformYamlInfo global_platform_cfg_info;
11700bfc58eSYaroslav Brustinovstatic int global_dpdk_args_num ;
11800bfc58eSYaroslav Brustinovstatic char * global_dpdk_args[MAX_DPDK_ARGS];
11900bfc58eSYaroslav Brustinovstatic char global_cores_str[100];
12000bfc58eSYaroslav Brustinovstatic char global_prefix_str[100];
12100bfc58eSYaroslav Brustinovstatic char global_loglevel_str[20];
1225ab7411fSimaromstatic char global_master_id_str[10];
1235d2b2709SHanoh Haimstatic char global_mlx5_so_id_str[50];
124a933bd1aSHanoh Haimstatic char global_mlx4_so_id_str[50];
1255d2b2709SHanoh Haimstatic char global_image_postfix[10];
1265d2b2709SHanoh Haim#define TREX_NAME "_t-rex-64"
1275d2b2709SHanoh Haim
1288b52a31eSHanoh Haimclass CTRexExtendedDriverBase {
1290e80bd4fSIdo Barneaprotected:
1300e80bd4fSIdo Barnea    enum {
1310e80bd4fSIdo Barnea        // Is there HW support for dropping packets arriving to certain queue?
1320e80bd4fSIdo Barnea        TREX_DRV_CAP_DROP_Q = 0x1,
1330e80bd4fSIdo Barnea        /* Does this NIC type support automatic packet dropping in case of a link down?
1340e80bd4fSIdo Barnea           in case it is supported the packets will be dropped, else there would be a back pressure to tx queues
1350e80bd4fSIdo Barnea           this interface is used as a workaround to let TRex work without link in stateless mode, driver that
1360e80bd4fSIdo Barnea           does not support that will be failed at init time because it will cause watchdog due to watchdog hang */
1370e80bd4fSIdo Barnea        TREX_DRV_CAP_DROP_PKTS_IF_LNK_DOWN = 0x2,
1380e80bd4fSIdo Barnea        // Does the driver support changing MAC address?
1390e80bd4fSIdo Barnea        TREX_DRV_CAP_MAC_ADDR_CHG = 0x4,
1400e80bd4fSIdo Barnea        /* Mellanox driver does not work well with the DPDK port reorder we do */
1410e80bd4fSIdo Barnea        TREX_DRV_CAP_NO_PORT_REORDER_POSSIBLE = 0x8,
1420e80bd4fSIdo Barnea    } trex_drv_cap;
1432ba80c6aSYaroslav Brustinov
1440e80bd4fSIdo Barneapublic:
1458b52a31eSHanoh Haim    virtual int get_min_sample_rate(void)=0;
1468b52a31eSHanoh Haim    virtual void update_configuration(port_cfg_t * cfg)=0;
1478b52a31eSHanoh Haim    virtual void update_global_config_fdir(port_cfg_t * cfg)=0;
1488b52a31eSHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if)=0;
1497cecfd8aSIdo Barnea    virtual int add_del_rx_flow_stat_rule(uint8_t port_id, enum rte_filter_op op, uint16_t l3, uint8_t l4
150f0416b93SIdo Barnea                                          , uint8_t ipv6_next_h, uint16_t id) {return 0;}
1510e80bd4fSIdo Barnea    bool is_hardware_support_drop_queue() {
1520e80bd4fSIdo Barnea        return ((m_cap & TREX_DRV_CAP_DROP_Q) != 0);
1530e80bd4fSIdo Barnea    }
1540e80bd4fSIdo Barnea    bool hardware_support_mac_change() {
1550e80bd4fSIdo Barnea        return ((m_cap & TREX_DRV_CAP_MAC_ADDR_CHG) != 0);
1560e80bd4fSIdo Barnea    }
1570e80bd4fSIdo Barnea    bool drop_packets_incase_of_linkdown() {
1580e80bd4fSIdo Barnea        return ((m_cap & TREX_DRV_CAP_DROP_PKTS_IF_LNK_DOWN) != 0);
1590e80bd4fSIdo Barnea    }
16088089080SIdo Barnea    bool supports_port_reorder() {
1610e80bd4fSIdo Barnea        // Since only Mellanox does not support, logic here is reveresed compared to other flags.
1620e80bd4fSIdo Barnea        // Put this only if not supported.
1630e80bd4fSIdo Barnea        return ((m_cap & TREX_DRV_CAP_NO_PORT_REORDER_POSSIBLE) == 0);
1648b52a31eSHanoh Haim    }
16558f1ee52SIdo Barnea    virtual int stop_queue(CPhyEthIF * _if, uint16_t q_num);
1662155c64bSIdo Barnea    void get_extended_stats_fixed(CPhyEthIF * _if, CPhyEthIFStats *stats, int fix_i, int fix_o);
1678b52a31eSHanoh Haim    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats)=0;
1688b52a31eSHanoh Haim    virtual void clear_extended_stats(CPhyEthIF * _if)=0;
169c9a62ebaSYaroslav Brustinov    virtual int  wait_for_stable_link();
170c9a62ebaSYaroslav Brustinov    virtual void wait_after_link_up();
17105a61d70SIdo Barnea    virtual bool hw_rx_stat_supported(){return false;}
172582d3f74SIdo Barnea    virtual int get_rx_stats(CPhyEthIF * _if, uint32_t *pkts, uint32_t *prev_pkts, uint32_t *bytes, uint32_t *prev_bytes
173582d3f74SIdo Barnea                             , int min, int max) {return -1;}
1742c00ae27SIdo Barnea    virtual void reset_rx_stats(CPhyEthIF * _if, uint32_t *stats, int min, int len) {}
175f0ab9ebaSIdo Barnea    virtual int dump_fdir_global_stats(CPhyEthIF * _if, FILE *fd) { return -1;}
176fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) = 0;
177ce1de344SIdo Barnea    virtual int verify_fw_ver(int i) {return 0;}
1784099c61aSIdo Barnea    virtual CFlowStatParser *get_flow_stat_parser();
17958f1ee52SIdo Barnea    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on)=0;
180111bd366SYaroslav Brustinov    virtual TRexPortAttr * create_port_attr(uint8_t port_id) = 0;
1815d52395cSHanoh Haim
1820d3f6dffSIdo Barnea    virtual rte_mempool_t * get_rx_mem_pool(int socket_id) {
1830d3f6dffSIdo Barnea        return CGlobalInfo::m_mem_pool[socket_id].m_mbuf_pool_9k;
1840d3f6dffSIdo Barnea    }
18588089080SIdo Barnea    virtual void get_dpdk_drv_params(CTrexDpdkParams &p) {
18688089080SIdo Barnea        p.rx_data_q_num = 1;
1870d3f6dffSIdo Barnea        if (CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_ONE_QUEUE) {
1880d3f6dffSIdo Barnea            p.rx_drop_q_num = 0;
1890d3f6dffSIdo Barnea        } else {
1900d3f6dffSIdo Barnea            p.rx_drop_q_num = 1;
1910d3f6dffSIdo Barnea        }
19288089080SIdo Barnea        p.rx_desc_num_data_q = RX_DESC_NUM_DATA_Q;
19388089080SIdo Barnea        p.rx_desc_num_drop_q = RX_DESC_NUM_DROP_Q;
19488089080SIdo Barnea        p.tx_desc_num = TX_DESC_NUM;
19529695101SHanoh Haim    }
19629695101SHanoh Haim
1970e80bd4fSIdo Barneaprotected:
1980e80bd4fSIdo Barnea    // flags describing interface capabilities
1990e80bd4fSIdo Barnea    uint32_t m_cap;
2008b52a31eSHanoh Haim};
2018b52a31eSHanoh Haim
2028b52a31eSHanoh Haim
2038b52a31eSHanoh Haimclass CTRexExtendedDriverBase1G : public CTRexExtendedDriverBase {
2048b52a31eSHanoh Haim
2058b52a31eSHanoh Haimpublic:
2068b52a31eSHanoh Haim    CTRexExtendedDriverBase1G(){
207c8560f23SIdo Barnea        m_cap = TREX_DRV_CAP_DROP_Q | TREX_DRV_CAP_MAC_ADDR_CHG;
208111bd366SYaroslav Brustinov    }
209111bd366SYaroslav Brustinov
210111bd366SYaroslav Brustinov    TRexPortAttr * create_port_attr(uint8_t port_id) {
211111bd366SYaroslav Brustinov        return new DpdkTRexPortAttr(port_id, false, true);
2128b52a31eSHanoh Haim    }
2138b52a31eSHanoh Haim
2148b52a31eSHanoh Haim    static CTRexExtendedDriverBase * create(){
2158b52a31eSHanoh Haim        return ( new CTRexExtendedDriverBase1G() );
2168b52a31eSHanoh Haim    }
2178b52a31eSHanoh Haim
2188b52a31eSHanoh Haim    virtual void update_global_config_fdir(port_cfg_t * cfg);
2198b52a31eSHanoh Haim
2208b52a31eSHanoh Haim    virtual int get_min_sample_rate(void){
2218b52a31eSHanoh Haim        return ( RX_CHECK_MIX_SAMPLE_RATE_1G);
2228b52a31eSHanoh Haim    }
2238b52a31eSHanoh Haim    virtual void update_configuration(port_cfg_t * cfg);
22458f1ee52SIdo Barnea    virtual int stop_queue(CPhyEthIF * _if, uint16_t q_num);
2258b52a31eSHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if);
22605a61d70SIdo Barnea    virtual int configure_rx_filter_rules_statefull(CPhyEthIF * _if);
22705a61d70SIdo Barnea    virtual int configure_rx_filter_rules_stateless(CPhyEthIF * _if);
22858f1ee52SIdo Barnea    virtual void clear_rx_filter_rules(CPhyEthIF * _if);
2298b52a31eSHanoh Haim    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
2308b52a31eSHanoh Haim    virtual void clear_extended_stats(CPhyEthIF * _if);
23105a61d70SIdo Barnea    virtual int dump_fdir_global_stats(CPhyEthIF * _if, FILE *fd) {return 0;}
232fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) {
233fa606839SIdo Barnea        flags = TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_RX_BYTES_COUNT
234d3b66fddSIdo Barnea            | TrexPlatformApi::IF_STAT_PAYLOAD;
235fa606839SIdo Barnea
236fa606839SIdo Barnea        if (CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_ONE_QUEUE
237fa606839SIdo Barnea            || CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_RSS) {
238fa606839SIdo Barnea            num_counters = MAX_FLOW_STATS;
239fa606839SIdo Barnea            base_ip_id = IP_ID_RESERVE_BASE;
240fa606839SIdo Barnea        } else {
241fa606839SIdo Barnea            num_counters = UINT8_MAX;
242fa606839SIdo Barnea            // Must be 0xff00, since we configure HW filter for the 0xff byte
243fa606839SIdo Barnea            // The filter must catch all flow stat packets, and latency packets (having 0xffff in IP ID)
244fa606839SIdo Barnea            base_ip_id = 0xff00;
245fa606839SIdo Barnea        }
246d3b66fddSIdo Barnea    }
2478b52a31eSHanoh Haim    virtual int wait_for_stable_link();
24805a61d70SIdo Barnea    virtual void wait_after_link_up();
24958f1ee52SIdo Barnea    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on);
2508b52a31eSHanoh Haim};
2518b52a31eSHanoh Haim
25274a55c27SIdo Barnea// Base for all virtual drivers. No constructor. Should not create object from this type.
25374a55c27SIdo Barneaclass CTRexExtendedDriverVirtBase : public CTRexExtendedDriverBase {
2548b52a31eSHanoh Haimpublic:
255111bd366SYaroslav Brustinov    TRexPortAttr * create_port_attr(uint8_t port_id) {
256111bd366SYaroslav Brustinov        return new DpdkTRexPortAttr(port_id, true, true);
2578b52a31eSHanoh Haim    }
2582155c64bSIdo Barnea    virtual void update_global_config_fdir(port_cfg_t * cfg) {}
2598b52a31eSHanoh Haim
2608b52a31eSHanoh Haim    virtual int get_min_sample_rate(void){
2618b52a31eSHanoh Haim        return ( RX_CHECK_MIX_SAMPLE_RATE_1G);
2628b52a31eSHanoh Haim    }
26388089080SIdo Barnea    virtual void get_dpdk_drv_params(CTrexDpdkParams &p) {
26488089080SIdo Barnea        p.rx_data_q_num = 1;
26588089080SIdo Barnea        p.rx_drop_q_num = 0;
26688089080SIdo Barnea        p.rx_desc_num_data_q = RX_DESC_NUM_DATA_Q_VM;
26788089080SIdo Barnea        p.rx_desc_num_drop_q = RX_DESC_NUM_DROP_Q;
26888089080SIdo Barnea        p.tx_desc_num = TX_DESC_NUM;
26988089080SIdo Barnea    }
2700d3f6dffSIdo Barnea    virtual rte_mempool_t * get_rx_mem_pool(int socket_id) {
2710d3f6dffSIdo Barnea        // In VMs there is usually less memory available
2720d3f6dffSIdo Barnea        return CGlobalInfo::m_mem_pool[socket_id].m_mbuf_pool_2048;
2730d3f6dffSIdo Barnea    }
2748b52a31eSHanoh Haim    virtual void update_configuration(port_cfg_t * cfg);
2758b52a31eSHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if);
27658f1ee52SIdo Barnea    virtual int stop_queue(CPhyEthIF * _if, uint16_t q_num);
27774a55c27SIdo Barnea    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats)=0;
2788b52a31eSHanoh Haim    virtual void clear_extended_stats(CPhyEthIF * _if);
2798b52a31eSHanoh Haim    virtual int wait_for_stable_link();
280fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) {
281fa606839SIdo Barnea        flags = TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_RX_BYTES_COUNT
282d3b66fddSIdo Barnea            | TrexPlatformApi::IF_STAT_PAYLOAD;
283fa606839SIdo Barnea        num_counters = MAX_FLOW_STATS;
284fa606839SIdo Barnea        base_ip_id = IP_ID_RESERVE_BASE;
285d3b66fddSIdo Barnea    }
286fa606839SIdo Barnea
28758f1ee52SIdo Barnea    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on) {return 0;}
288af25eb9bSIdo Barnea    CFlowStatParser *get_flow_stat_parser();
2898b52a31eSHanoh Haim};
2908b52a31eSHanoh Haim
29174a55c27SIdo Barneaclass CTRexExtendedDriverVirtio : public CTRexExtendedDriverVirtBase {
29274a55c27SIdo Barneapublic:
29374a55c27SIdo Barnea    CTRexExtendedDriverVirtio() {
29488089080SIdo Barnea        CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_ONE_QUEUE);
2950e80bd4fSIdo Barnea        m_cap = /*TREX_DRV_CAP_DROP_Q  | TREX_DRV_CAP_MAC_ADDR_CHG */ 0;
29674a55c27SIdo Barnea    }
29774a55c27SIdo Barnea    static CTRexExtendedDriverBase * create(){
29874a55c27SIdo Barnea        return ( new CTRexExtendedDriverVirtio() );
29974a55c27SIdo Barnea    }
30074a55c27SIdo Barnea    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
30174a55c27SIdo Barnea};
30274a55c27SIdo Barnea
30374a55c27SIdo Barneaclass CTRexExtendedDriverVmxnet3 : public CTRexExtendedDriverVirtBase {
304030c1244SHanoh Haimpublic:
3052155c64bSIdo Barnea    CTRexExtendedDriverVmxnet3(){
30688089080SIdo Barnea        CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_ONE_QUEUE);
3070e80bd4fSIdo Barnea        m_cap = /*TREX_DRV_CAP_DROP_Q  | TREX_DRV_CAP_MAC_ADDR_CHG*/0;
308030c1244SHanoh Haim    }
309030c1244SHanoh Haim
3102155c64bSIdo Barnea    static CTRexExtendedDriverBase * create() {
3112155c64bSIdo Barnea        return ( new CTRexExtendedDriverVmxnet3() );
3122155c64bSIdo Barnea    }
31374a55c27SIdo Barnea    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
3142155c64bSIdo Barnea    virtual void update_configuration(port_cfg_t * cfg);
315030c1244SHanoh Haim};
316e532c2a1SIdo Barnea
31774a55c27SIdo Barneaclass CTRexExtendedDriverI40evf : public CTRexExtendedDriverVirtBase {
318e532c2a1SIdo Barneapublic:
3192155c64bSIdo Barnea    CTRexExtendedDriverI40evf(){
32088089080SIdo Barnea        CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_ONE_QUEUE);
321c8560f23SIdo Barnea        m_cap = /*TREX_DRV_CAP_DROP_Q  | TREX_DRV_CAP_MAC_ADDR_CHG */0;
322e532c2a1SIdo Barnea    }
323e532c2a1SIdo Barnea    virtual void get_extended_stats(CPhyEthIF * _if, CPhyEthIFStats *stats) {
3246e3418f5SYaroslav Brustinov        get_extended_stats_fixed(_if, stats, 4, 4);
325030c1244SHanoh Haim    }
3262155c64bSIdo Barnea    virtual void update_configuration(port_cfg_t * cfg);
3272155c64bSIdo Barnea    static CTRexExtendedDriverBase * create() {
3282155c64bSIdo Barnea        return ( new CTRexExtendedDriverI40evf() );
329e532c2a1SIdo Barnea    }
330030c1244SHanoh Haim};
331030c1244SHanoh Haim
3322155c64bSIdo Barneaclass CTRexExtendedDriverIxgbevf : public CTRexExtendedDriverI40evf {
333e532c2a1SIdo Barnea
334e532c2a1SIdo Barneapublic:
3352155c64bSIdo Barnea    CTRexExtendedDriverIxgbevf(){
33688089080SIdo Barnea        CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_ONE_QUEUE);
337c8560f23SIdo Barnea        m_cap = /*TREX_DRV_CAP_DROP_Q  | TREX_DRV_CAP_MAC_ADDR_CHG */0;
338e532c2a1SIdo Barnea    }
339e532c2a1SIdo Barnea    virtual void get_extended_stats(CPhyEthIF * _if, CPhyEthIFStats *stats) {
3402155c64bSIdo Barnea        get_extended_stats_fixed(_if, stats, 4, 4);
341e532c2a1SIdo Barnea    }
3422155c64bSIdo Barnea
3432155c64bSIdo Barnea    static CTRexExtendedDriverBase * create() {
3442155c64bSIdo Barnea        return ( new CTRexExtendedDriverIxgbevf() );
345e532c2a1SIdo Barnea    }
346e532c2a1SIdo Barnea};
347e532c2a1SIdo Barnea
34874a55c27SIdo Barneaclass CTRexExtendedDriverBaseE1000 : public CTRexExtendedDriverVirtBase {
3499464519dSIdo Barnea    CTRexExtendedDriverBaseE1000() {
3509464519dSIdo Barnea        // E1000 driver is only relevant in VM in our case
35188089080SIdo Barnea        CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_ONE_QUEUE);
3520e80bd4fSIdo Barnea        m_cap = /*TREX_DRV_CAP_DROP_Q  | TREX_DRV_CAP_MAC_ADDR_CHG */0;
3539464519dSIdo Barnea    }
3549464519dSIdo Barneapublic:
3559464519dSIdo Barnea    static CTRexExtendedDriverBase * create() {
3569464519dSIdo Barnea        return ( new CTRexExtendedDriverBaseE1000() );
3579464519dSIdo Barnea    }
3589464519dSIdo Barnea    // e1000 driver handing us packets with ethernet CRC, so we need to chop them
35974a55c27SIdo Barnea    virtual void update_configuration(port_cfg_t * cfg);
360030c1244SHanoh Haim    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
361030c1244SHanoh Haim
3629464519dSIdo Barnea};
3638b52a31eSHanoh Haim
3648b52a31eSHanoh Haimclass CTRexExtendedDriverBase10G : public CTRexExtendedDriverBase {
3658b52a31eSHanoh Haimpublic:
3668b52a31eSHanoh Haim    CTRexExtendedDriverBase10G(){
367c8560f23SIdo Barnea        m_cap = TREX_DRV_CAP_DROP_Q | TREX_DRV_CAP_MAC_ADDR_CHG;
368111bd366SYaroslav Brustinov    }
369111bd366SYaroslav Brustinov
370111bd366SYaroslav Brustinov    TRexPortAttr * create_port_attr(uint8_t port_id) {
371111bd366SYaroslav Brustinov        return new DpdkTRexPortAttr(port_id, false, true);
3728b52a31eSHanoh Haim    }
3748b52a31eSHanoh Haim    static CTRexExtendedDriverBase * create(){
3758b52a31eSHanoh Haim        return ( new CTRexExtendedDriverBase10G() );
3768b52a31eSHanoh Haim    }
3778b52a31eSHanoh Haim
3788b52a31eSHanoh Haim    virtual void update_global_config_fdir(port_cfg_t * cfg);
3798b52a31eSHanoh Haim
3808b52a31eSHanoh Haim    virtual int get_min_sample_rate(void){
3818b52a31eSHanoh Haim        return (RX_CHECK_MIX_SAMPLE_RATE);
3828b52a31eSHanoh Haim    }
3838b52a31eSHanoh Haim    virtual void update_configuration(port_cfg_t * cfg);
3848b52a31eSHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if);
3859c03844bSIdo Barnea    virtual int configure_rx_filter_rules_stateless(CPhyEthIF * _if);
3869c03844bSIdo Barnea    virtual int configure_rx_filter_rules_statefull(CPhyEthIF * _if);
3878b52a31eSHanoh Haim    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
3888b52a31eSHanoh Haim    virtual void clear_extended_stats(CPhyEthIF * _if);
3898b52a31eSHanoh Haim    virtual int wait_for_stable_link();
390fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) {
391fa606839SIdo Barnea        flags = TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_RX_BYTES_COUNT
392d3b66fddSIdo Barnea            | TrexPlatformApi::IF_STAT_PAYLOAD;
393fa606839SIdo Barnea        if ((CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_RSS)
394fa606839SIdo Barnea            || (CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_ONE_QUEUE)) {
395fa606839SIdo Barnea            num_counters = MAX_FLOW_STATS;
396fa606839SIdo Barnea        } else {
397fa606839SIdo Barnea            num_counters = 127;
398fa606839SIdo Barnea        }
399fa606839SIdo Barnea        base_ip_id = IP_ID_RESERVE_BASE;
400a53f6be0SIdo Barnea    }
4014099c61aSIdo Barnea    virtual CFlowStatParser *get_flow_stat_parser();
4022ded6e3dSIdo Barnea    int add_del_eth_filter(CPhyEthIF * _if, bool is_add, uint16_t ethertype);
4032ded6e3dSIdo Barnea    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on);
4048b52a31eSHanoh Haim};
4058b52a31eSHanoh Haim
406de2af4ebSYaroslav Brustinovclass CTRexExtendedDriverBase40G : public CTRexExtendedDriverBase {
4078b52a31eSHanoh Haimpublic:
4088b52a31eSHanoh Haim    CTRexExtendedDriverBase40G(){
409fa606839SIdo Barnea        // 4 will make us support 127 flow stat counters
410eb899d68SIdo Barnea        // If we want to support more counters in case of card having less interfaces, we
411f0ab9ebaSIdo Barnea        // Will have to identify the number of interfaces dynamically.
412f0ab9ebaSIdo Barnea        m_if_per_card = 4;
413fa606839SIdo Barnea
415111bd366SYaroslav Brustinov    }
416111bd366SYaroslav Brustinov
417111bd366SYaroslav Brustinov    TRexPortAttr * create_port_attr(uint8_t port_id) {
4182dab6b6dSYaroslav Brustinov        // disabling flow control on 40G using DPDK API causes the interface to malfunction
419111bd366SYaroslav Brustinov        return new DpdkTRexPortAttr(port_id, false, false);
4208b52a31eSHanoh Haim    }
4218b52a31eSHanoh Haim
4228b52a31eSHanoh Haim    static CTRexExtendedDriverBase * create(){
4238b52a31eSHanoh Haim        return ( new CTRexExtendedDriverBase40G() );
4248b52a31eSHanoh Haim    }
4258b52a31eSHanoh Haim
4268b52a31eSHanoh Haim    virtual void update_global_config_fdir(port_cfg_t * cfg){
4278b52a31eSHanoh Haim    }
428de2af4ebSYaroslav Brustinov    virtual int get_min_sample_rate(void){
429de2af4ebSYaroslav Brustinov        return (RX_CHECK_MIX_SAMPLE_RATE);
430de2af4ebSYaroslav Brustinov    }
4318b52a31eSHanoh Haim    virtual void update_configuration(port_cfg_t * cfg);
4328b52a31eSHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if);
4337cecfd8aSIdo Barnea    virtual int add_del_rx_flow_stat_rule(uint8_t port_id, enum rte_filter_op op, uint16_t l3_proto
4347cecfd8aSIdo Barnea                                          , uint8_t l4_proto, uint8_t ipv6_next_h, uint16_t id);
4358b52a31eSHanoh Haim    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
4368b52a31eSHanoh Haim    virtual void clear_extended_stats(CPhyEthIF * _if);
4372c00ae27SIdo Barnea    virtual void reset_rx_stats(CPhyEthIF * _if, uint32_t *stats, int min, int len);
43805a61d70SIdo Barnea    virtual int get_rx_stats(CPhyEthIF * _if, uint32_t *pkts, uint32_t *prev_pkts, uint32_t *bytes, uint32_t *prev_bytes, int min, int max);
43905a61d70SIdo Barnea    virtual int dump_fdir_global_stats(CPhyEthIF * _if, FILE *fd);
440fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) {
441fa606839SIdo Barnea        flags = TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_PAYLOAD;
442f48443a1SIdo Barnea        // HW counters on x710 does not support coutning bytes.
443af25eb9bSIdo Barnea        if ( CGlobalInfo::m_options.preview.get_disable_hw_flow_stat()
444af25eb9bSIdo Barnea             || CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_ONE_QUEUE
445af25eb9bSIdo Barnea             || CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_RSS) {
446fa606839SIdo Barnea            flags |= TrexPlatformApi::IF_STAT_RX_BYTES_COUNT;
447fa606839SIdo Barnea            num_counters = MAX_FLOW_STATS;
448fa606839SIdo Barnea        } else {
449fa606839SIdo Barnea            if (m_if_per_card == 4) {
450fa606839SIdo Barnea                num_counters = MAX_FLOW_STATS_X710;
451fa606839SIdo Barnea            } else {
452fa606839SIdo Barnea                num_counters = MAX_FLOW_STATS_XL710;
453fa606839SIdo Barnea            }
454f48443a1SIdo Barnea        }
455fa606839SIdo Barnea        base_ip_id = IP_ID_RESERVE_BASE;
456fa606839SIdo Barnea        m_max_flow_stats = num_counters;
457d3b66fddSIdo Barnea    }
4588b52a31eSHanoh Haim    virtual int wait_for_stable_link();
459f48443a1SIdo Barnea    virtual bool hw_rx_stat_supported(){
460af25eb9bSIdo Barnea        if (CGlobalInfo::m_options.preview.get_disable_hw_flow_stat()
461af25eb9bSIdo Barnea            || CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_ONE_QUEUE
462af25eb9bSIdo Barnea            || CGlobalInfo::get_queues_mode() == CGlobalInfo::Q_MODE_RSS) {
463f48443a1SIdo Barnea            return false;
464f48443a1SIdo Barnea        } else {
465f48443a1SIdo Barnea            return true;
466f48443a1SIdo Barnea        }
467f48443a1SIdo Barnea    }
468ce1de344SIdo Barnea    virtual int verify_fw_ver(int i);
4694099c61aSIdo Barnea    virtual CFlowStatParser *get_flow_stat_parser();
47058f1ee52SIdo Barnea    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on);
4714099c61aSIdo Barnea
472e33e37efSIdo Barneaprivate:
47366c49a9dSIdo Barnea    virtual void add_del_rules(enum rte_filter_op op, uint8_t port_id, uint16_t type, uint8_t ttl
47421ebf559SHanoh Haim                               , uint16_t ip_id, uint8_t l4_proto, int queue, uint16_t stat_idx);
47558f1ee52SIdo Barnea    virtual int add_del_eth_type_rule(uint8_t port_id, enum rte_filter_op op, uint16_t eth_type);
47658f1ee52SIdo Barnea    virtual int configure_rx_filter_rules_statefull(CPhyEthIF * _if);
4774099c61aSIdo Barnea
4788b52a31eSHanoh Haimprivate:
479f0ab9ebaSIdo Barnea    uint8_t m_if_per_card;
480fa606839SIdo Barnea    uint16_t m_max_flow_stats;
4818b52a31eSHanoh Haim};
4828b52a31eSHanoh Haim
48342d71595SHanoh Haimclass CTRexExtendedDriverBaseVIC : public CTRexExtendedDriverBase {
4847e37a0aaSHanoh Haimpublic:
4857e37a0aaSHanoh Haim    CTRexExtendedDriverBaseVIC(){
486c8560f23SIdo Barnea        m_cap = TREX_DRV_CAP_DROP_Q  | TREX_DRV_CAP_MAC_ADDR_CHG;
487111bd366SYaroslav Brustinov    }
488111bd366SYaroslav Brustinov
489111bd366SYaroslav Brustinov    TRexPortAttr * create_port_attr(uint8_t port_id) {
490111bd366SYaroslav Brustinov        return new DpdkTRexPortAttr(port_id, false, false);
4917e37a0aaSHanoh Haim    }
4927e37a0aaSHanoh Haim
4937e37a0aaSHanoh Haim    static CTRexExtendedDriverBase * create(){
4947e37a0aaSHanoh Haim        return ( new CTRexExtendedDriverBaseVIC() );
4957e37a0aaSHanoh Haim    }
49642d71595SHanoh Haim    virtual void update_global_config_fdir(port_cfg_t * cfg){
49742d71595SHanoh Haim    }
49842d71595SHanoh Haim    void clear_extended_stats(CPhyEthIF * _if);
49942d71595SHanoh Haim    void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
50042d71595SHanoh Haim
50142d71595SHanoh Haim    virtual int get_min_sample_rate(void){
50242d71595SHanoh Haim        return (RX_CHECK_MIX_SAMPLE_RATE);
50342d71595SHanoh Haim    }
5047e37a0aaSHanoh Haim
5059d9f3dd8SHanoh Haim    virtual int verify_fw_ver(int i);
5065f530a21SHanoh Haim
5077e37a0aaSHanoh Haim    virtual void update_configuration(port_cfg_t * cfg);
5088d0a50a3SHanoh Haim
5098d0a50a3SHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if);
5108d0a50a3SHanoh Haim    virtual void reset_rx_stats(CPhyEthIF * _if, uint32_t *stats, int min, int len);
5118d0a50a3SHanoh Haim    virtual int get_rx_stats(CPhyEthIF * _if, uint32_t *pkts, uint32_t *prev_pkts, uint32_t *bytes, uint32_t *prev_bytes, int min, int max);
5128d0a50a3SHanoh Haim    virtual int get_stat_counters_num() {return MAX_FLOW_STATS;}
513fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) {
514fa606839SIdo Barnea        flags = TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_RX_BYTES_COUNT
515fa606839SIdo Barnea            | TrexPlatformApi::IF_STAT_PAYLOAD;
516fa606839SIdo Barnea        num_counters = MAX_FLOW_STATS;
517fa606839SIdo Barnea        base_ip_id = IP_ID_RESERVE_BASE;
5188d0a50a3SHanoh Haim    }
519fa606839SIdo Barnea
5208d0a50a3SHanoh Haim    virtual CFlowStatParser *get_flow_stat_parser();
5218d0a50a3SHanoh Haim    virtual int dump_fdir_global_stats(CPhyEthIF * _if, FILE *fd);
5228d0a50a3SHanoh Haim    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on);
5238d0a50a3SHanoh Haim
5248d0a50a3SHanoh Haimprivate:
5258d0a50a3SHanoh Haim
526fd9485d6SIdo Barnea    virtual void add_del_rules(enum rte_filter_op op, uint8_t port_id, uint16_t type, uint16_t id
527fd9485d6SIdo Barnea                               , uint8_t l4_proto, uint8_t tos, int queue);
5288d0a50a3SHanoh Haim    virtual int add_del_eth_type_rule(uint8_t port_id, enum rte_filter_op op, uint16_t eth_type);
5298d0a50a3SHanoh Haim    virtual int configure_rx_filter_rules_statefull(CPhyEthIF * _if);
5308d0a50a3SHanoh Haim
5317e37a0aaSHanoh Haim};
5327e37a0aaSHanoh Haim
5337e37a0aaSHanoh Haim
534de2af4ebSYaroslav Brustinovclass CTRexExtendedDriverBaseMlnx5G : public CTRexExtendedDriverBase {
5358e9aa6d8SHanoh Haimpublic:
5368e9aa6d8SHanoh Haim    CTRexExtendedDriverBaseMlnx5G(){
53888089080SIdo Barnea        CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_MANY_DROP_Q);
5398e9aa6d8SHanoh Haim    }
5408e9aa6d8SHanoh Haim
5418e9aa6d8SHanoh Haim    TRexPortAttr * create_port_attr(uint8_t port_id) {
5428e9aa6d8SHanoh Haim        // disabling flow control on 40G using DPDK API causes the interface to malfunction
5438e9aa6d8SHanoh Haim        return new DpdkTRexPortAttr(port_id, false, false);
5448e9aa6d8SHanoh Haim    }
5458e9aa6d8SHanoh Haim
5468e9aa6d8SHanoh Haim    static CTRexExtendedDriverBase * create(){
5478e9aa6d8SHanoh Haim        return ( new CTRexExtendedDriverBaseMlnx5G() );
5488e9aa6d8SHanoh Haim    }
5498e9aa6d8SHanoh Haim
5508e9aa6d8SHanoh Haim    virtual void update_global_config_fdir(port_cfg_t * cfg){
5518e9aa6d8SHanoh Haim    }
5528e9aa6d8SHanoh Haim
553de2af4ebSYaroslav Brustinov    virtual int get_min_sample_rate(void){
554de2af4ebSYaroslav Brustinov        return (RX_CHECK_MIX_SAMPLE_RATE);
555de2af4ebSYaroslav Brustinov    }
55688089080SIdo Barnea    virtual void get_dpdk_drv_params(CTrexDpdkParams &p) {
55788089080SIdo Barnea        p.rx_data_q_num = 1;
55888089080SIdo Barnea        /* Mellanox ConnectX-4 can drop only 35MPPS per Rx queue.
55988089080SIdo Barnea         * to workaround this issue we will create multi rx queue and enable RSS. for Queue1 we will disable RSS
56088089080SIdo Barnea         * return zero for disable patch and rx queues number for enable.
56188089080SIdo Barnea        */
56288089080SIdo Barnea        p.rx_drop_q_num = 4;
56388089080SIdo Barnea        p.rx_desc_num_data_q = RX_DESC_NUM_DATA_Q;
56488089080SIdo Barnea        p.rx_desc_num_drop_q = RX_DESC_NUM_DROP_Q_MLX;
56588089080SIdo Barnea        p.tx_desc_num = TX_DESC_NUM;
56688089080SIdo Barnea    }
5678e9aa6d8SHanoh Haim    virtual void update_configuration(port_cfg_t * cfg);
5688e9aa6d8SHanoh Haim    virtual int configure_rx_filter_rules(CPhyEthIF * _if);
5698e9aa6d8SHanoh Haim    virtual void get_extended_stats(CPhyEthIF * _if,CPhyEthIFStats *stats);
5708e9aa6d8SHanoh Haim    virtual void clear_extended_stats(CPhyEthIF * _if);
5718e9aa6d8SHanoh Haim    virtual void reset_rx_stats(CPhyEthIF * _if, uint32_t *stats, int min, int len);
5728e9aa6d8SHanoh Haim    virtual int get_rx_stats(CPhyEthIF * _if, uint32_t *pkts, uint32_t *prev_pkts, uint32_t *bytes, uint32_t *prev_bytes, int min, int max);
5738e9aa6d8SHanoh Haim    virtual int dump_fdir_global_stats(CPhyEthIF * _if, FILE *fd);
574fa606839SIdo Barnea    virtual void get_rx_stat_capabilities(uint16_t &flags, uint16_t &num_counters, uint16_t &base_ip_id) {
575fa606839SIdo Barnea        flags = TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_RX_BYTES_COUNT
576fa606839SIdo Barnea            | TrexPlatformApi::IF_STAT_PAYLOAD;
577fa606839SIdo Barnea        num_counters = 127; //With MAX_FLOW_STATS we saw packet failures in rx_test. Need to check.
578fa606839SIdo Barnea        base_ip_id = IP_ID_RESERVE_BASE;
5798e9aa6d8SHanoh Haim    }
5808e9aa6d8SHanoh Haim    virtual int wait_for_stable_link();
5818e9aa6d8SHanoh Haim    // disabling flow control on 40G using DPDK API causes the interface to malfunction
5828e9aa6d8SHanoh Haim    virtual bool flow_control_disable_supported(){return false;}
5838e9aa6d8SHanoh Haim    virtual CFlowStatParser *get_flow_stat_parser();
584f0416b93SIdo Barnea    virtual int set_rcv_all(CPhyEthIF * _if, bool set_on);
5858e9aa6d8SHanoh Haim
5868e9aa6d8SHanoh Haimprivate:
587f0416b93SIdo Barnea    virtual void add_del_rules(enum rte_filter_op op, uint8_t port_id, uint16_t type, uint16_t ip_id, uint8_t l4_proto
588f0416b93SIdo Barnea                               , int queue);
589f0416b93SIdo Barnea    virtual int add_del_rx_filter_rules(CPhyEthIF * _if, bool set_on);
5908e9aa6d8SHanoh Haim};
5918e9aa6d8SHanoh Haim
5928b52a31eSHanoh Haimtypedef CTRexExtendedDriverBase * (*create_object_t) (void);
5938b52a31eSHanoh Haim
5948b52a31eSHanoh Haim
5958b52a31eSHanoh Haimclass CTRexExtendedDriverRec {
5968b52a31eSHanoh Haimpublic:
5978b52a31eSHanoh Haim    std::string         m_driver_name;
5988b52a31eSHanoh Haim    create_object_t     m_constructor;
5998b52a31eSHanoh Haim};
6008b52a31eSHanoh Haim
6018b52a31eSHanoh Haimclass CTRexExtendedDriverDb {
6028b52a31eSHanoh Haimpublic:
604e33e37efSIdo Barnea    const std::string & get_driver_name() {
605e33e37efSIdo Barnea        return m_driver_name;
606e33e37efSIdo Barnea    }
608e33e37efSIdo Barnea    bool is_driver_exists(std::string name);
6098b52a31eSHanoh Haim
6108b52a31eSHanoh Haim
6118b52a31eSHanoh Haim
612e33e37efSIdo Barnea    void set_driver_name(std::string name){
613e33e37efSIdo Barnea        m_driver_was_set=true;
614e33e37efSIdo Barnea        m_driver_name=name;
615e33e37efSIdo Barnea        printf(" set driver name %s \n",name.c_str());
616e33e37efSIdo Barnea        m_drv=create_driver(m_driver_name);
617e33e37efSIdo Barnea        assert(m_drv);
618e33e37efSIdo Barnea    }
6198b52a31eSHanoh Haim
620e33e37efSIdo Barnea    CTRexExtendedDriverBase * get_drv(){
621e33e37efSIdo Barnea        if (!m_driver_was_set) {
622e33e37efSIdo Barnea            printf(" ERROR too early to use this object !\n");
623e33e37efSIdo Barnea            printf(" need to set the right driver \n");
624e33e37efSIdo Barnea            assert(0);
625e33e37efSIdo Barnea        }
626e33e37efSIdo Barnea        assert(m_drv);
627e33e37efSIdo Barnea        return (m_drv);
628e33e37efSIdo Barnea    }
6298b52a31eSHanoh Haim
6308b52a31eSHanoh Haimpublic:
6318b52a31eSHanoh Haim
6328b52a31eSHanoh Haim    static CTRexExtendedDriverDb * Ins();
6338b52a31eSHanoh Haim
6348b52a31eSHanoh Haimprivate:
6358b52a31eSHanoh Haim    CTRexExtendedDriverBase * create_driver(std::string name);
6368b52a31eSHanoh Haim
6378b52a31eSHanoh Haim    CTRexExtendedDriverDb(){
6388957b863SIdo Barnea        register_driver(std::string("net_ixgbe"),CTRexExtendedDriverBase10G::create);
6398957b863SIdo Barnea        register_driver(std::string("net_e1000_igb"),CTRexExtendedDriverBase1G::create);
6408957b863SIdo Barnea        register_driver(std::string("net_i40e"),CTRexExtendedDriverBase40G::create);
6418957b863SIdo Barnea        register_driver(std::string("net_enic"),CTRexExtendedDriverBaseVIC::create);
6420f54b830SHanoh Haim        register_driver(std::string("net_mlx5"),CTRexExtendedDriverBaseMlnx5G::create);
6438b52a31eSHanoh Haim
6448b52a31eSHanoh Haim        /* virtual devices */
6458957b863SIdo Barnea        register_driver(std::string("net_e1000_em"), CTRexExtendedDriverBaseE1000::create);
6468957b863SIdo Barnea        register_driver(std::string("net_vmxnet3"), CTRexExtendedDriverVmxnet3::create);
6478957b863SIdo Barnea        register_driver(std::string("net_virtio"), CTRexExtendedDriverVirtio::create);
6488957b863SIdo Barnea        register_driver(std::string("net_i40e_vf"), CTRexExtendedDriverI40evf::create);
6498957b863SIdo Barnea        register_driver(std::string("net_ixgbe_vf"), CTRexExtendedDriverIxgbevf::create);
6508b52a31eSHanoh Haim
6518b52a31eSHanoh Haim        m_driver_was_set=false;
6528b52a31eSHanoh Haim        m_drv=0;
6538b52a31eSHanoh Haim        m_driver_name="";
6548b52a31eSHanoh Haim    }
6558b52a31eSHanoh Haim    void register_driver(std::string name,create_object_t func);
6568b52a31eSHanoh Haim    static CTRexExtendedDriverDb * m_ins;
6578b52a31eSHanoh Haim    bool        m_driver_was_set;
6588b52a31eSHanoh Haim    std::string m_driver_name;
6598b52a31eSHanoh Haim    CTRexExtendedDriverBase * m_drv;
6608b52a31eSHanoh Haim    std::vector <CTRexExtendedDriverRec*>     m_list;
6618b52a31eSHanoh Haim
6628b52a31eSHanoh Haim};
6638b52a31eSHanoh Haim
6648b52a31eSHanoh HaimCTRexExtendedDriverDb * CTRexExtendedDriverDb::m_ins;
6658b52a31eSHanoh Haim
6668b52a31eSHanoh Haim
6678b52a31eSHanoh Haimvoid CTRexExtendedDriverDb::register_driver(std::string name,
6688b52a31eSHanoh Haim                                            create_object_t func){
6698b52a31eSHanoh Haim    CTRexExtendedDriverRec * rec;
6708b52a31eSHanoh Haim    rec = new CTRexExtendedDriverRec();
6718b52a31eSHanoh Haim    rec->m_driver_name=name;
6728b52a31eSHanoh Haim    rec->m_constructor=func;
6738b52a31eSHanoh Haim    m_list.push_back(rec);
6748b52a31eSHanoh Haim}
6758b52a31eSHanoh Haim
6768b52a31eSHanoh Haim
6778b52a31eSHanoh Haimbool CTRexExtendedDriverDb::is_driver_exists(std::string name){
6788b52a31eSHanoh Haim    int i;
6798b52a31eSHanoh Haim    for (i=0; i<(int)m_list.size(); i++) {
6808b52a31eSHanoh Haim        if (m_list[i]->m_driver_name == name) {
6818b52a31eSHanoh Haim            return (true);
6828b52a31eSHanoh Haim        }
6838b52a31eSHanoh Haim    }
6848b52a31eSHanoh Haim    return (false);
6858b52a31eSHanoh Haim}
6868b52a31eSHanoh Haim
6878b52a31eSHanoh Haim
6888b52a31eSHanoh HaimCTRexExtendedDriverBase * CTRexExtendedDriverDb::create_driver(std::string name){
6898b52a31eSHanoh Haim    int i;
6908b52a31eSHanoh Haim    for (i=0; i<(int)m_list.size(); i++) {
6918b52a31eSHanoh Haim        if (m_list[i]->m_driver_name == name) {
6928b52a31eSHanoh Haim            return ( m_list[i]->m_constructor() );
6938b52a31eSHanoh Haim        }
6948b52a31eSHanoh Haim    }
6958b52a31eSHanoh Haim    return( (CTRexExtendedDriverBase *)0);
6968b52a31eSHanoh Haim}
6978b52a31eSHanoh Haim
6988b52a31eSHanoh Haim
6998b52a31eSHanoh Haim
7008b52a31eSHanoh HaimCTRexExtendedDriverDb * CTRexExtendedDriverDb::Ins(){
7018b52a31eSHanoh Haim    if (!m_ins) {
7028b52a31eSHanoh Haim        m_ins = new CTRexExtendedDriverDb();
7038b52a31eSHanoh Haim    }
7048b52a31eSHanoh Haim    return (m_ins);
7058b52a31eSHanoh Haim}
7068b52a31eSHanoh Haim
7078b52a31eSHanoh Haimstatic CTRexExtendedDriverBase *  get_ex_drv(){
7088b52a31eSHanoh Haim
7098b52a31eSHanoh Haim    return ( CTRexExtendedDriverDb::Ins()->get_drv());
7108b52a31eSHanoh Haim}
7118b52a31eSHanoh Haim
7128b52a31eSHanoh Haimstatic inline int get_min_sample_rate(void){
7138b52a31eSHanoh Haim    return ( get_ex_drv()->get_min_sample_rate());
7148b52a31eSHanoh Haim}
7158b52a31eSHanoh Haim
7168b52a31eSHanoh Haim// cores =0==1,1*2,2,3,4,5,6
7178b52a31eSHanoh Haim// An enum for all the option types
718e33e37efSIdo Barneaenum { OPT_HELP,
719e33e37efSIdo Barnea       OPT_MODE_BATCH,
720e33e37efSIdo Barnea       OPT_MODE_INTERACTIVE,
721e33e37efSIdo Barnea       OPT_NODE_DUMP,
72208def8d3SYaroslav Brustinov       OPT_DUMP_INTERFACES,
723e33e37efSIdo Barnea       OPT_UT,
724e33e37efSIdo Barnea       OPT_CORES,
725e33e37efSIdo Barnea       OPT_SINGLE_CORE,
726e33e37efSIdo Barnea       OPT_FLIP_CLIENT_SERVER,
727e33e37efSIdo Barnea       OPT_FLOW_FLIP_CLIENT_SERVER,
728e33e37efSIdo Barnea       OPT_FLOW_FLIP_CLIENT_SERVER_SIDE,
7291738989bSIdo Barnea       OPT_RATE_MULT,
730e33e37efSIdo Barnea       OPT_DURATION,
731e33e37efSIdo Barnea       OPT_PLATFORM_FACTOR,
732e33e37efSIdo Barnea       OPT_PUB_DISABLE,
733e33e37efSIdo Barnea       OPT_LIMT_NUM_OF_PORTS,
734e33e37efSIdo Barnea       OPT_PLAT_CFG_FILE,
735392f47fbSHanoh Haim       OPT_MBUF_FACTOR,
736e33e37efSIdo Barnea       OPT_LATENCY,
737e33e37efSIdo Barnea       OPT_NO_CLEAN_FLOW_CLOSE,
738e33e37efSIdo Barnea       OPT_LATENCY_MASK,
739e33e37efSIdo Barnea       OPT_ONLY_LATENCY,
740e33e37efSIdo Barnea       OPT_LATENCY_PREVIEW ,
741c9a62ebaSYaroslav Brustinov       OPT_WAIT_BEFORE_TRAFFIC,
742e33e37efSIdo Barnea       OPT_PCAP,
743e33e37efSIdo Barnea       OPT_RX_CHECK,
744e33e37efSIdo Barnea       OPT_IO_MODE,
745e33e37efSIdo Barnea       OPT_IPV6,
746e33e37efSIdo Barnea       OPT_LEARN,
747e33e37efSIdo Barnea       OPT_LEARN_MODE,
748e33e37efSIdo Barnea       OPT_LEARN_VERIFY,
749e33e37efSIdo Barnea       OPT_L_PKT_MODE,
750e33e37efSIdo Barnea       OPT_NO_FLOW_CONTROL,
751f48443a1SIdo Barnea       OPT_NO_HW_FLOW_STAT,
752dbff547fSYaroslav Brustinov       OPT_X710_RESET_THRESHOLD,
753bd6dc8e4SIdo Barnea       OPT_VLAN,
754e33e37efSIdo Barnea       OPT_RX_CHECK_HOPS,
7551dfd42ceSimarom       OPT_CLIENT_CFG_FILE,
756e33e37efSIdo Barnea       OPT_NO_KEYBOARD_INPUT,
757e33e37efSIdo Barnea       OPT_VIRT_ONE_TX_RX_QUEUE,
758e33e37efSIdo Barnea       OPT_PREFIX,
759ca8b613fSHanoh Haim       OPT_SEND_DEBUG_PKT,
7605f846485Simarom       OPT_NO_WATCHDOG,
761659ba260SMartin Weiser       OPT_ALLOW_COREDUMP,
762659ba260SMartin Weiser       OPT_CHECKSUM_OFFLOAD,
76344b5db37SIdo Barnea       OPT_CLOSE,
7642223955bSIdo Barnea       OPT_ARP_REF_PER,
765de2af4ebSYaroslav Brustinov       OPT_NO_OFED_CHECK,
7669fb4cf6fSYaroslav Brustinov       OPT_NO_SCAPY_SERVER,
767aee39c9dSimarom       OPT_ACTIVE_FLOW,
7685d2b2709SHanoh Haim       OPT_RT,
769a933bd1aSHanoh Haim       OPT_MLX4_SO,
77088089080SIdo Barnea       OPT_MLX5_SO
7718b52a31eSHanoh Haim};
7728b52a31eSHanoh Haim
7738b52a31eSHanoh Haim/* these are the argument types:
7748b52a31eSHanoh Haim   SO_NONE --    no argument needed
7758b52a31eSHanoh Haim   SO_REQ_SEP -- single required argument
7768b52a31eSHanoh Haim   SO_MULTI --   multiple arguments needed
7778b52a31eSHanoh Haim*/
7788b52a31eSHanoh Haimstatic CSimpleOpt::SOption parser_options[] =
779e33e37efSIdo Barnea    {
780de2af4ebSYaroslav Brustinov        { OPT_HELP,                   "-?",                SO_NONE    },
781de2af4ebSYaroslav Brustinov        { OPT_HELP,                   "-h",                SO_NONE    },
782de2af4ebSYaroslav Brustinov        { OPT_HELP,                   "--help",            SO_NONE    },
783de2af4ebSYaroslav Brustinov        { OPT_UT,                     "--ut",              SO_NONE    },
784de2af4ebSYaroslav Brustinov        { OPT_MODE_BATCH,             "-f",                SO_REQ_SEP },
785de2af4ebSYaroslav Brustinov        { OPT_MODE_INTERACTIVE,       "-i",                SO_NONE    },
786de2af4ebSYaroslav Brustinov        { OPT_PLAT_CFG_FILE,          "--cfg",             SO_REQ_SEP },
787de2af4ebSYaroslav Brustinov        { OPT_SINGLE_CORE,            "-s",                SO_NONE    },
788de2af4ebSYaroslav Brustinov        { OPT_FLIP_CLIENT_SERVER,     "--flip",            SO_NONE    },
789de2af4ebSYaroslav Brustinov        { OPT_FLOW_FLIP_CLIENT_SERVER,"-p",                SO_NONE    },
790de2af4ebSYaroslav Brustinov        { OPT_FLOW_FLIP_CLIENT_SERVER_SIDE, "-e",          SO_NONE    },
791de2af4ebSYaroslav Brustinov        { OPT_NO_CLEAN_FLOW_CLOSE,    "--nc",              SO_NONE    },
792de2af4ebSYaroslav Brustinov        { OPT_LIMT_NUM_OF_PORTS,      "--limit-ports",     SO_REQ_SEP },
793de2af4ebSYaroslav Brustinov        { OPT_CORES,                  "-c",                SO_REQ_SEP },
794de2af4ebSYaroslav Brustinov        { OPT_NODE_DUMP,              "-v",                SO_REQ_SEP },
795de2af4ebSYaroslav Brustinov        { OPT_DUMP_INTERFACES,        "--dump-interfaces", SO_MULTI   },
796de2af4ebSYaroslav Brustinov        { OPT_LATENCY,                "-l",                SO_REQ_SEP },
797de2af4ebSYaroslav Brustinov        { OPT_DURATION,               "-d",                SO_REQ_SEP },
798de2af4ebSYaroslav Brustinov        { OPT_PLATFORM_FACTOR,        "-pm",               SO_REQ_SEP },
799de2af4ebSYaroslav Brustinov        { OPT_PUB_DISABLE,            "-pubd",             SO_NONE    },
800de2af4ebSYaroslav Brustinov        { OPT_RATE_MULT,              "-m",                SO_REQ_SEP },
801de2af4ebSYaroslav Brustinov        { OPT_LATENCY_MASK,           "--lm",              SO_REQ_SEP },
802de2af4ebSYaroslav Brustinov        { OPT_ONLY_LATENCY,           "--lo",              SO_NONE    },
803de2af4ebSYaroslav Brustinov        { OPT_LATENCY_PREVIEW,        "-k",                SO_REQ_SEP },
804de2af4ebSYaroslav Brustinov        { OPT_WAIT_BEFORE_TRAFFIC,    "-w",                SO_REQ_SEP },
805de2af4ebSYaroslav Brustinov        { OPT_PCAP,                   "--pcap",            SO_NONE    },
806de2af4ebSYaroslav Brustinov        { OPT_RX_CHECK,               "--rx-check",        SO_REQ_SEP },
807de2af4ebSYaroslav Brustinov        { OPT_IO_MODE,                "--iom",             SO_REQ_SEP },
808de2af4ebSYaroslav Brustinov        { OPT_RX_CHECK_HOPS,          "--hops",            SO_REQ_SEP },
809de2af4ebSYaroslav Brustinov        { OPT_IPV6,                   "--ipv6",            SO_NONE    },
810de2af4ebSYaroslav Brustinov        { OPT_LEARN,                  "--learn",           SO_NONE    },
811de2af4ebSYaroslav Brustinov        { OPT_LEARN_MODE,             "--learn-mode",      SO_REQ_SEP },
812de2af4ebSYaroslav Brustinov        { OPT_LEARN_VERIFY,           "--learn-verify",    SO_NONE    },
813de2af4ebSYaroslav Brustinov        { OPT_L_PKT_MODE,             "--l-pkt-mode",      SO_REQ_SEP },
814de2af4ebSYaroslav Brustinov        { OPT_NO_FLOW_CONTROL,        "--no-flow-control-change", SO_NONE },
815f48443a1SIdo Barnea        { OPT_NO_HW_FLOW_STAT,        "--no-hw-flow-stat", SO_NONE },
816dbff547fSYaroslav Brustinov        { OPT_X710_RESET_THRESHOLD,   "--x710-reset-threshold", SO_REQ_SEP },
817de2af4ebSYaroslav Brustinov        { OPT_VLAN,                   "--vlan",            SO_NONE    },
818de2af4ebSYaroslav Brustinov        { OPT_CLIENT_CFG_FILE,        "--client_cfg",      SO_REQ_SEP },
819de2af4ebSYaroslav Brustinov        { OPT_CLIENT_CFG_FILE,        "--client-cfg",      SO_REQ_SEP },
820de2af4ebSYaroslav Brustinov        { OPT_NO_KEYBOARD_INPUT,      "--no-key",          SO_NONE    },
821af25eb9bSIdo Barnea        { OPT_VIRT_ONE_TX_RX_QUEUE,   "--software",        SO_NONE    },
822de2af4ebSYaroslav Brustinov        { OPT_PREFIX,                 "--prefix",          SO_REQ_SEP },
823de2af4ebSYaroslav Brustinov        { OPT_SEND_DEBUG_PKT,         "--send-debug-pkt",  SO_REQ_SEP },
824de2af4ebSYaroslav Brustinov        { OPT_MBUF_FACTOR,            "--mbuf-factor",     SO_REQ_SEP },
825de2af4ebSYaroslav Brustinov        { OPT_NO_WATCHDOG,            "--no-watchdog",     SO_NONE    },
826de2af4ebSYaroslav Brustinov        { OPT_ALLOW_COREDUMP,         "--allow-coredump",  SO_NONE    },
827de2af4ebSYaroslav Brustinov        { OPT_CHECKSUM_OFFLOAD,       "--checksum-offload", SO_NONE   },
8289fb4cf6fSYaroslav Brustinov        { OPT_ACTIVE_FLOW,            "--active-flows",   SO_REQ_SEP  },
8295d2b2709SHanoh Haim        { OPT_MLX5_SO,                "--mlx5-so", SO_NONE    },
830a933bd1aSHanoh Haim        { OPT_MLX4_SO,                "--mlx4-so", SO_NONE    },
831de2af4ebSYaroslav Brustinov        { OPT_CLOSE,                  "--close-at-end",    SO_NONE    },
832de2af4ebSYaroslav Brustinov        { OPT_ARP_REF_PER,            "--arp-refresh-period", SO_REQ_SEP },
833de2af4ebSYaroslav Brustinov        { OPT_NO_OFED_CHECK,          "--no-ofed-check",   SO_NONE    },
8349fb4cf6fSYaroslav Brustinov        { OPT_NO_SCAPY_SERVER,        "--no-scapy-server", SO_NONE    },
835aee39c9dSimarom        { OPT_RT,                     "--rt",              SO_NONE    },
836e33e37efSIdo Barnea        SO_END_OF_OPTIONS
837e33e37efSIdo Barnea    };
8388b52a31eSHanoh Haim
8398b52a31eSHanoh Haimstatic int usage(){
8408b52a31eSHanoh Haim
8411738989bSIdo Barnea    printf(" Usage: t-rex-64 [mode] <options>\n\n");
8421738989bSIdo Barnea    printf(" mode is one of:\n");
8431738989bSIdo Barnea    printf("   -f <file> : YAML file with traffic template configuration (Will run TRex in 'stateful' mode)\n");
8441738989bSIdo Barnea    printf("   -i        : Run TRex in 'stateless' mode\n");
8451738989bSIdo Barnea    printf("\n");
846e33e37efSIdo Barnea
8471738989bSIdo Barnea    printf(" Available options are:\n");
848f48443a1SIdo Barnea    printf(" --active-flows             : An experimental switch to scale up or down the number of active flows.  \n");
849f48443a1SIdo Barnea    printf("                              It is not accurate due to the quantization of flow scheduler and in some case does not work. \n");
850f48443a1SIdo Barnea    printf("                              Example --active-flows 500000 wil set the ballpark of the active flow to be ~0.5M \n");
8511738989bSIdo Barnea    printf(" --allow-coredump           : Allow creation of core dump \n");
8521738989bSIdo Barnea    printf(" --arp-refresh-period       : Period in seconds between sending of gratuitous ARP for our addresses. Value of 0 means 'never send' \n");
8531738989bSIdo Barnea    printf(" -c <num>>                  : Number of hardware threads to allocate for each port pair. Overrides the 'c' argument from config file \n");
8541738989bSIdo Barnea    printf(" --cfg <file>               : Use file as TRex config file instead of the default /etc/trex_cfg.yaml \n");
8551738989bSIdo Barnea    printf(" --checksum-offload         : Enable IP, TCP and UDP tx checksum offloading, using DPDK. This requires all used interfaces to support this \n");
8561738989bSIdo Barnea    printf(" --client_cfg <file>        : YAML file describing clients configuration \n");
8571738989bSIdo Barnea    printf(" --close-at-end             : Call rte_eth_dev_stop and close at exit. Calling these functions caused link down issues in older versions, \n");
8581738989bSIdo Barnea    printf("                               so we do not call them by default for now. Leaving this as option in case someone thinks it is helpful for him \n");
8591738989bSIdo Barnea    printf("                               This it temporary option. Will be removed in the future \n");
8601738989bSIdo Barnea    printf(" -d                         : Duration of the test in sec (default is 3600). Look also at --nc \n");
8611738989bSIdo Barnea    printf(" -e                         : Like -p but src/dst IP will be chosen according to the port (i.e. on client port send all packets with client src and server dest, and vice versa on server port \n");
8621738989bSIdo Barnea    printf(" --flip                     : Each flow will be sent both from client to server and server to client. This can acheive better port utilization when flow traffic is asymmetric \n");
8631738989bSIdo Barnea    printf(" --hops <hops>              : If rx check is enabled, the hop number can be assigned. See manual for details \n");
8641738989bSIdo Barnea    printf(" --iom  <mode>              : IO mode  for server output [0- silent, 1- normal , 2- short] \n");
8651738989bSIdo Barnea    printf(" --ipv6                     : Work in ipv6 mode \n");
8661738989bSIdo Barnea    printf(" -k  <num>                  : Run 'warm up' traffic for num seconds before starting the test. \n");
8671738989bSIdo Barnea    printf(" -l <rate>                  : In parallel to the test, run latency check, sending packets at rate/sec from each interface \n");
868d9934626SIdo Barnea    printf(" --l-pkt-mode <0-3>         : Set mode for sending latency packets \n");
869d9934626SIdo Barnea    printf("      0 (default)    send SCTP packets  \n");
870d9934626SIdo Barnea    printf("      1              Send ICMP request packets  \n");
871d9934626SIdo Barnea    printf("      2              Send ICMP requests from client side, and response from server side (for working with firewall) \n");
872d9934626SIdo Barnea    printf("      3              Send ICMP requests with sequence ID 0 from both sides \n");
8731738989bSIdo Barnea    printf("    Rate of zero means no latency check \n");
8741738989bSIdo Barnea    printf(" --learn (deprecated). Replaced by --learn-mode. To get older behaviour, use --learn-mode 2 \n");
875d9934626SIdo Barnea    printf(" --learn-mode [1-3]         : Used for working in NAT environments. Dynamically learn the NAT translation done by the DUT \n");
876d9934626SIdo Barnea    printf("      1    In case of TCP flow, use TCP ACK in first SYN to pass NAT translation information. Initial SYN packet must be first packet in the TCP flow \n");
877d9934626SIdo Barnea    printf("           In case of UDP stream, NAT translation information will pass in IP ID field of first packet in flow. This means that this field is changed by TRex\n");
878d9934626SIdo Barnea    printf("      2    Add special IP option to pass NAT translation information to first packet of each flow. Will not work on certain firewalls if they drop packets with IP options \n");
879dbff547fSYaroslav Brustinov    printf("      3    Like 1, but without support for sequence number randomization in server->client direction. Performance (flow/second) better than 1 \n");
8801738989bSIdo Barnea    printf(" --learn-verify             : Test the NAT translation mechanism. Should be used when there is no NAT in the setup \n");
8811738989bSIdo Barnea    printf(" --limit-ports              : Limit number of ports used. Must be even number (TRex always uses port pairs) \n");
8821738989bSIdo Barnea    printf(" --lm                       : Hex mask of cores that should send traffic \n");
8831738989bSIdo Barnea    printf("    For example: Value of 0x5 will cause only ports 0 and 2 to send traffic \n");
8841738989bSIdo Barnea    printf(" --lo                       : Only run latency test \n");
8851738989bSIdo Barnea    printf(" -m <num>                   : Rate multiplier.  Multiply basic rate of templates by this number \n");
8862223955bSIdo Barnea    printf(" --mbuf-factor              : Factor for packet memory \n");
8871738989bSIdo Barnea    printf(" --nc                       : If set, will not wait for all flows to be closed, before terminating - see manual for more information \n");
8881738989bSIdo Barnea    printf(" --no-flow-control-change   : By default TRex disables flow-control. If this option is given, it does not touch it \n");
889f48443a1SIdo Barnea    printf(" --no-hw-flow-stat          : Relevant only for Intel x710 stateless mode. Do not use HW counters for flow stats\n");
890f48443a1SIdo Barnea    printf("                            : Enabling this will support lower traffic rate, but will also report RX byte count statistics. See manual for more details\n");
8911738989bSIdo Barnea    printf(" --no-key                   : Daemon mode, don't get input from keyboard \n");
892de2af4ebSYaroslav Brustinov    printf(" --no-ofed-check            : Disable the check of OFED version \n");
89383861b49SYaroslav Brustinov    printf(" --no-scapy-server          : Disable Scapy server implicit start at stateless \n");
8941738989bSIdo Barnea    printf(" --no-watchdog              : Disable watchdog \n");
895aee39c9dSimarom    printf(" --rt                       : Run TRex DP/RX cores in realtime priority \n");
8961738989bSIdo Barnea    printf(" -p                         : Send all flow packets from the same interface (choosed randomly between client ad server ports) without changing their src/dst IP \n");
8971738989bSIdo Barnea    printf(" -pm                        : Platform factor. If you have splitter in the setup, you can multiply the total results by this factor \n");
8981738989bSIdo Barnea    printf("    e.g --pm 2.0 will multiply all the results bps in this factor \n");
8991738989bSIdo Barnea    printf(" --prefix <nam>             : For running multi TRex instances on the same machine. Each instance should have different name \n");
9001738989bSIdo Barnea    printf(" -pubd                      : Disable monitors publishers \n");
9011738989bSIdo Barnea    printf(" --rx-check  <rate>         : Enable rx check. TRex will sample flows at 1/rate and check order, latency and more \n");
9021738989bSIdo Barnea    printf(" -s                         : Single core. Run only one data path core. For debug \n");
9031738989bSIdo Barnea    printf(" --send-debug-pkt <proto>   : Do not run traffic generator. Just send debug packet and dump receive queues \n");
9041738989bSIdo Barnea    printf("    Supported protocols are 1 for icmp, 2 for UDP, 3 for TCP, 4 for ARP, 5 for 9K UDP \n");
9050d3f6dffSIdo Barnea    printf(" --software                 : Do not configure any hardware rules. In this mode we use 1 core, and one RX queue and one TX queue per port\n");
9061738989bSIdo Barnea    printf(" -v <verbosity level>       : The higher the value, print more debug information \n");
9071738989bSIdo Barnea    printf(" --vlan                     : Relevant only for stateless mode with Intel 82599 10G NIC \n");
9081738989bSIdo Barnea    printf("                              When configuring flow stat and latency per stream rules, assume all streams uses VLAN \n");
9091738989bSIdo Barnea    printf(" -w  <num>                  : Wait num seconds between init of interfaces and sending traffic, default is 1 \n");
9105b7974b8SHanoh Haim
9118b52a31eSHanoh Haim    printf("\n");
9121738989bSIdo Barnea    printf(" Examples: ");
9131738989bSIdo Barnea    printf(" basic trex run for 20 sec and multiplier of 10 \n");
9141738989bSIdo Barnea    printf("  t-rex-64 -f cap2/dns.yaml -m 10 -d 20 \n");
9151738989bSIdo Barnea    printf("\n\n");
916af25eb9bSIdo Barnea    printf(" Copyright (c) 2015-2017 Cisco Systems, Inc.    \n");
91752ada6a5SHanoh Haim    printf("                                                                  \n");
91852ada6a5SHanoh Haim    printf(" Licensed under the Apache License, Version 2.0 (the 'License') \n");
91952ada6a5SHanoh Haim    printf(" you may not use this file except in compliance with the License. \n");
92052ada6a5SHanoh Haim    printf(" You may obtain a copy of the License at                          \n");
92152ada6a5SHanoh Haim    printf("                                                                  \n");
92252ada6a5SHanoh Haim    printf("    http://www.apache.org/licenses/LICENSE-2.0                    \n");
92352ada6a5SHanoh Haim    printf("                                                                  \n");
92452ada6a5SHanoh Haim    printf(" Unless required by applicable law or agreed to in writing, software \n");
92552ada6a5SHanoh Haim    printf(" distributed under the License is distributed on an \"AS IS\" BASIS,   \n");
92652ada6a5SHanoh Haim    printf(" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n");
92752ada6a5SHanoh Haim    printf(" See the License for the specific language governing permissions and      \n");
92852ada6a5SHanoh Haim    printf(" limitations under the License.                                           \n");
92952ada6a5SHanoh Haim    printf(" \n");
93052ada6a5SHanoh Haim    printf(" Open Source Components / Libraries \n");
931301341ddSHanoh Haim    printf(" DPDK       (BSD)       \n");
93252ada6a5SHanoh Haim    printf(" YAML-CPP   (BSD)       \n");
933d7af282dSimarom    printf(" JSONCPP    (MIT)       \n");
93452ada6a5SHanoh Haim    printf(" \n");
93552ada6a5SHanoh Haim    printf(" Open Source Binaries \n");
93652ada6a5SHanoh Haim    printf(" ZMQ        (LGPL v3plus) \n");
93752ada6a5SHanoh Haim    printf(" \n");
93852ada6a5SHanoh Haim    printf(" Version : %s   \n",VERSION_BUILD_NUM);
939b19ca363SIdo Barnea    printf(" DPDK version : %s   \n",rte_version());
94052ada6a5SHanoh Haim    printf(" User    : %s   \n",VERSION_USER);
94152ada6a5SHanoh Haim    printf(" Date    : %s , %s \n",get_build_date(),get_build_time());
94252ada6a5SHanoh Haim    printf(" Uuid    : %s    \n",VERSION_UIID);
943301341ddSHanoh Haim    printf(" Git SHA : %s    \n",VERSION_GIT_SHA);
9448b52a31eSHanoh Haim    return (0);
9458b52a31eSHanoh Haim}
9468b52a31eSHanoh Haim
9478b52a31eSHanoh Haim
9488b52a31eSHanoh Haimint gtest_main(int argc, char **argv) ;
9498b52a31eSHanoh Haim
950d7af282dSimaromstatic void parse_err(const std::string &msg) {
951d7af282dSimarom    std::cout << "\nArgument Parsing Error: \n\n" << "*** "<< msg << "\n\n";
952d7af282dSimarom    exit(-1);
9558b52a31eSHanoh Haimstatic int parse_options(int argc, char *argv[], CParserOption* po, bool first_time ) {
956e33e37efSIdo Barnea    CSimpleOpt args(argc, argv, parser_options);
9578b52a31eSHanoh Haim
958e33e37efSIdo Barnea    bool latency_was_set=false;
959e33e37efSIdo Barnea    (void)latency_was_set;
96008def8d3SYaroslav Brustinov    char ** rgpszArg = NULL;
961a842c1ffSIdo Barnea    bool opt_vlan_was_set = false;
963e33e37efSIdo Barnea    int a=0;
964e33e37efSIdo Barnea    int node_dump=0;
9658b52a31eSHanoh Haim
966e33e37efSIdo Barnea    po->preview.setFileWrite(true);
967e33e37efSIdo Barnea    po->preview.setRealTime(true);
968e33e37efSIdo Barnea    uint32_t tmp_data;
9695b7974b8SHanoh Haim    float tmp_double;
9708b52a31eSHanoh Haim
971e33e37efSIdo Barnea    po->m_run_mode = CParserOption::RUN_MODE_INVALID;
9728b52a31eSHanoh Haim
973e33e37efSIdo Barnea    while ( args.Next() ){
9748b52a31eSHanoh Haim        if (args.LastError() == SO_SUCCESS) {
9758b52a31eSHanoh Haim            switch (args.OptionId()) {
9778b52a31eSHanoh Haim            case OPT_UT :
978d7af282dSimarom                parse_err("Supported only in simulation");
9798b52a31eSHanoh Haim                break;
981e33e37efSIdo Barnea            case OPT_HELP:
9828b52a31eSHanoh Haim                usage();
9838b52a31eSHanoh Haim                return -1;
985d7af282dSimarom            case OPT_MODE_BATCH:
986d7af282dSimarom                if (po->m_run_mode != CParserOption::RUN_MODE_INVALID) {
987d7af282dSimarom                    parse_err("Please specify single run mode");
988d7af282dSimarom                }
989d7af282dSimarom                po->m_run_mode = CParserOption::RUN_MODE_BATCH;
9908b52a31eSHanoh Haim                po->cfg_file = args.OptionArg();
9918b52a31eSHanoh Haim                break;
993d7af282dSimarom            case OPT_MODE_INTERACTIVE:
994d7af282dSimarom                if (po->m_run_mode != CParserOption::RUN_MODE_INVALID) {
995d7af282dSimarom                    parse_err("Please specify single run mode");
996d7af282dSimarom                }
997d7af282dSimarom                po->m_run_mode = CParserOption::RUN_MODE_INTERACTIVE;
998d7af282dSimarom                break;
10008b52a31eSHanoh Haim            case OPT_NO_KEYBOARD_INPUT  :
10018b52a31eSHanoh Haim                po->preview.set_no_keyboard(true);
10028b52a31eSHanoh Haim                break;
10041dfd42ceSimarom            case OPT_CLIENT_CFG_FILE :
10051dfd42ceSimarom                po->client_cfg_file = args.OptionArg();
10068b52a31eSHanoh Haim                break;
10088b52a31eSHanoh Haim            case OPT_PLAT_CFG_FILE :
10098b52a31eSHanoh Haim                po->platform_cfg_file = args.OptionArg();
10108b52a31eSHanoh Haim                break;
10128b52a31eSHanoh Haim            case OPT_SINGLE_CORE :
10138b52a31eSHanoh Haim                po->preview.setSingleCore(true);
10148b52a31eSHanoh Haim                break;
10168b52a31eSHanoh Haim            case OPT_IPV6:
10178b52a31eSHanoh Haim                po->preview.set_ipv6_mode_enable(true);
10188b52a31eSHanoh Haim                break;
1020aee39c9dSimarom            case OPT_RT:
1021aee39c9dSimarom                po->preview.set_rt_prio_mode(true);
1022aee39c9dSimarom                break;
10238b52a31eSHanoh Haim
10245d2b2709SHanoh Haim            case OPT_MLX5_SO:
10255d2b2709SHanoh Haim                po->preview.set_mlx5_so_mode(true);
10265d2b2709SHanoh Haim                break;
10275d2b2709SHanoh Haim
1028a933bd1aSHanoh Haim            case OPT_MLX4_SO:
1029a933bd1aSHanoh Haim                po->preview.set_mlx4_so_mode(true);
1030a933bd1aSHanoh Haim                break;
1031a933bd1aSHanoh Haim
10328b52a31eSHanoh Haim            case OPT_LEARN :
103362623efcSIdo Barnea                po->m_learn_mode = CParserOption::LEARN_MODE_IP_OPTION;
103462623efcSIdo Barnea                break;
103562623efcSIdo Barnea
103662623efcSIdo Barnea            case OPT_LEARN_MODE :
103762623efcSIdo Barnea                sscanf(args.OptionArg(),"%d", &tmp_data);
1038e33e37efSIdo Barnea                if (! po->is_valid_opt_val(tmp_data, CParserOption::LEARN_MODE_DISABLED, CParserOption::LEARN_MODE_MAX, "--learn-mode")) {
1039e33e37efSIdo Barnea                    exit(-1);
1040e33e37efSIdo Barnea                }
104162623efcSIdo Barnea                po->m_learn_mode = (uint8_t)tmp_data;
10428b52a31eSHanoh Haim                break;
10438b52a31eSHanoh Haim
10448b52a31eSHanoh Haim            case OPT_LEARN_VERIFY :
1045e33e37efSIdo Barnea                // must configure learn_mode for learn verify to work. If different learn mode will be given later, it will be set instead.
1046e33e37efSIdo Barnea                if (po->m_learn_mode == 0) {
1047e33e37efSIdo Barnea                    po->m_learn_mode = CParserOption::LEARN_MODE_IP_OPTION;
1048e33e37efSIdo Barnea                }
104962623efcSIdo Barnea                po->preview.set_learn_and_verify_mode_enable(true);
10508b52a31eSHanoh Haim                break;
10518b52a31eSHanoh Haim
1052c181e882SIdo Barnea            case OPT_L_PKT_MODE :
1053c181e882SIdo Barnea                sscanf(args.OptionArg(),"%d", &tmp_data);
1054e33e37efSIdo Barnea                if (! po->is_valid_opt_val(tmp_data, 0, L_PKT_SUBMODE_0_SEQ, "--l-pkt-mode")) {
1055e33e37efSIdo Barnea                    exit(-1);
1056e33e37efSIdo Barnea                }
1057c181e882SIdo Barnea                po->m_l_pkt_mode=(uint8_t)tmp_data;
1058c181e882SIdo Barnea                break;
1059c181e882SIdo Barnea
1060f48443a1SIdo Barnea            case OPT_NO_HW_FLOW_STAT:
1061f48443a1SIdo Barnea                po->preview.set_disable_hw_flow_stat(true);
1062f48443a1SIdo Barnea                break;
10638b52a31eSHanoh Haim            case OPT_NO_FLOW_CONTROL:
10648b52a31eSHanoh Haim                po->preview.set_disable_flow_control_setting(true);
10658b52a31eSHanoh Haim                break;
1066dbff547fSYaroslav Brustinov            case OPT_X710_RESET_THRESHOLD:
1067dbff547fSYaroslav Brustinov                po->set_x710_fdir_reset_threshold(atoi(args.OptionArg()));
1068dbff547fSYaroslav Brustinov                break;
1069bd6dc8e4SIdo Barnea            case OPT_VLAN:
1070a842c1ffSIdo Barnea                opt_vlan_was_set = true;
1071bd6dc8e4SIdo Barnea                break;
10728b52a31eSHanoh Haim            case OPT_LIMT_NUM_OF_PORTS :
10738b52a31eSHanoh Haim                po->m_expected_portd =atoi(args.OptionArg());
10748b52a31eSHanoh Haim                break;
10758b52a31eSHanoh Haim            case  OPT_CORES  :
10768b52a31eSHanoh Haim                po->preview.setCores(atoi(args.OptionArg()));
10778b52a31eSHanoh Haim                break;
10788b52a31eSHanoh Haim            case OPT_FLIP_CLIENT_SERVER :
10798b52a31eSHanoh Haim                po->preview.setClientServerFlip(true);
10808b52a31eSHanoh Haim                break;
10818b52a31eSHanoh Haim            case OPT_NO_CLEAN_FLOW_CLOSE :
10828b52a31eSHanoh Haim                po->preview.setNoCleanFlowClose(true);
10838b52a31eSHanoh Haim                break;
10848b52a31eSHanoh Haim            case OPT_FLOW_FLIP_CLIENT_SERVER :
10858b52a31eSHanoh Haim                po->preview.setClientServerFlowFlip(true);
10868b52a31eSHanoh Haim                break;
10878b52a31eSHanoh Haim            case OPT_FLOW_FLIP_CLIENT_SERVER_SIDE:
10888b52a31eSHanoh Haim                po->preview.setClientServerFlowFlipAddr(true);
10898b52a31eSHanoh Haim                break;
10908b52a31eSHanoh Haim            case OPT_NODE_DUMP:
10918b52a31eSHanoh Haim                a=atoi(args.OptionArg());
10928b52a31eSHanoh Haim                node_dump=1;
10938b52a31eSHanoh Haim                po->preview.setFileWrite(false);
10948b52a31eSHanoh Haim                break;
109508def8d3SYaroslav Brustinov            case OPT_DUMP_INTERFACES:
109608def8d3SYaroslav Brustinov                if (first_time) {
109708def8d3SYaroslav Brustinov                    rgpszArg = args.MultiArg(1);
109808def8d3SYaroslav Brustinov                    while (rgpszArg != NULL) {
109908def8d3SYaroslav Brustinov                        po->dump_interfaces.push_back(rgpszArg[0]);
110008def8d3SYaroslav Brustinov                        rgpszArg = args.MultiArg(1);
110108def8d3SYaroslav Brustinov                    }
110208def8d3SYaroslav Brustinov                }
110308def8d3SYaroslav Brustinov                if (po->m_run_mode != CParserOption::RUN_MODE_INVALID) {
1104a842c1ffSIdo Barnea                    parse_err("Please specify single run mode (-i for stateless, or -f <file> for stateful");
110508def8d3SYaroslav Brustinov                }
110608def8d3SYaroslav Brustinov                po->m_run_mode = CParserOption::RUN_MODE_DUMP_INFO;
110708def8d3SYaroslav Brustinov                break;
1108392f47fbSHanoh Haim            case OPT_MBUF_FACTOR:
1109392f47fbSHanoh Haim                sscanf(args.OptionArg(),"%f", &po->m_mbuf_factor);
1110392f47fbSHanoh Haim                break;
11111738989bSIdo Barnea            case OPT_RATE_MULT :
11128b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%f", &po->m_factor);
11138b52a31eSHanoh Haim                break;
11148b52a31eSHanoh Haim            case OPT_DURATION :
11158b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%f", &po->m_duration);
11168b52a31eSHanoh Haim                break;
11178b52a31eSHanoh Haim            case OPT_PUB_DISABLE:
11188b52a31eSHanoh Haim                po->preview.set_zmq_publish_enable(false);
11198b52a31eSHanoh Haim                break;
11208b52a31eSHanoh Haim            case OPT_PLATFORM_FACTOR:
11218b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%f", &po->m_platform_factor);
11228b52a31eSHanoh Haim                break;
11238b52a31eSHanoh Haim            case OPT_LATENCY :
11248b52a31eSHanoh Haim                latency_was_set=true;
11258b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%d", &po->m_latency_rate);
11268b52a31eSHanoh Haim                break;
11278b52a31eSHanoh Haim            case OPT_LATENCY_MASK :
11288b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%x", &po->m_latency_mask);
11298b52a31eSHanoh Haim                break;
11308b52a31eSHanoh Haim            case OPT_ONLY_LATENCY :
11318b52a31eSHanoh Haim                po->preview.setOnlyLatency(true);
11328b52a31eSHanoh Haim                break;
1133ca8b613fSHanoh Haim            case OPT_NO_WATCHDOG :
1134ca8b613fSHanoh Haim                po->preview.setWDDisable(true);
1135ca8b613fSHanoh Haim                break;
11365f846485Simarom            case OPT_ALLOW_COREDUMP :
11375f846485Simarom                po->preview.setCoreDumpEnable(true);
11385f846485Simarom                break;
11398b52a31eSHanoh Haim            case  OPT_LATENCY_PREVIEW :
11408b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%d", &po->m_latency_prev);
11418b52a31eSHanoh Haim                break;
1142c9a62ebaSYaroslav Brustinov            case  OPT_WAIT_BEFORE_TRAFFIC :
1143c9a62ebaSYaroslav Brustinov                sscanf(args.OptionArg(),"%d", &po->m_wait_before_traffic);
1144c9a62ebaSYaroslav Brustinov                break;
11458b52a31eSHanoh Haim            case OPT_PCAP:
11468b52a31eSHanoh Haim                po->preview.set_pcap_mode_enable(true);
11478b52a31eSHanoh Haim                break;
11485b7974b8SHanoh Haim            case OPT_ACTIVE_FLOW:
11495b7974b8SHanoh Haim                sscanf(args.OptionArg(),"%f", &tmp_double);
11505b7974b8SHanoh Haim                po->m_active_flows=(uint32_t)tmp_double;
11515b7974b8SHanoh Haim                break;
11528b52a31eSHanoh Haim            case OPT_RX_CHECK :
11538b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%d", &tmp_data);
1154e33e37efSIdo Barnea                po->m_rx_check_sample=(uint16_t)tmp_data;
11558b52a31eSHanoh Haim                po->preview.set_rx_check_enable(true);
11568b52a31eSHanoh Haim                break;
11578b52a31eSHanoh Haim            case OPT_RX_CHECK_HOPS :
11588b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%d", &tmp_data);
11598b52a31eSHanoh Haim                po->m_rx_check_hops = (uint16_t)tmp_data;
11608b52a31eSHanoh Haim                break;
11618b52a31eSHanoh Haim            case OPT_IO_MODE :
11628b52a31eSHanoh Haim                sscanf(args.OptionArg(),"%d", &tmp_data);
11638b52a31eSHanoh Haim                po->m_io_mode=(uint16_t)tmp_data;
11648b52a31eSHanoh Haim                break;
11658b52a31eSHanoh Haim
11668b52a31eSHanoh Haim            case OPT_VIRT_ONE_TX_RX_QUEUE:
116788089080SIdo Barnea                CGlobalInfo::set_queues_mode(CGlobalInfo::Q_MODE_ONE_QUEUE);
1168af25eb9bSIdo Barnea                po->preview.setCores(1); // Only one TX core supported in software mode currently
11698b52a31eSHanoh Haim                break;
11708b52a31eSHanoh Haim
11718b52a31eSHanoh Haim            case OPT_PREFIX:
11728b52a31eSHanoh Haim                po->prefix = args.OptionArg();
11738b52a31eSHanoh Haim                break;
11748b52a31eSHanoh Haim