18b52a31eSHanoh Haim/*
28b52a31eSHanoh Haim Hanoh Haim
38b52a31eSHanoh Haim Cisco Systems, Inc.
48b52a31eSHanoh Haim*/
58b52a31eSHanoh Haim
68b52a31eSHanoh Haim/*
78b52a31eSHanoh HaimCopyright (c) 2015-2015 Cisco Systems, Inc.
88b52a31eSHanoh Haim
98b52a31eSHanoh HaimLicensed under the Apache License, Version 2.0 (the "License");
108b52a31eSHanoh Haimyou may not use this file except in compliance with the License.
118b52a31eSHanoh HaimYou may obtain a copy of the License at
128b52a31eSHanoh Haim
138b52a31eSHanoh Haim    http://www.apache.org/licenses/LICENSE-2.0
148b52a31eSHanoh Haim
158b52a31eSHanoh HaimUnless required by applicable law or agreed to in writing, software
168b52a31eSHanoh Haimdistributed under the License is distributed on an "AS IS" BASIS,
178b52a31eSHanoh HaimWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188b52a31eSHanoh HaimSee the License for the specific language governing permissions and
198b52a31eSHanoh Haimlimitations under the License.
208b52a31eSHanoh Haim*/
218b52a31eSHanoh Haim
228b52a31eSHanoh Haim#include "bp_sim.h"
23cf0b463eSIdo Barnea#include <stdlib.h>
248b52a31eSHanoh Haim#include <common/gtest.h>
258b52a31eSHanoh Haim#include <common/basic_utils.h>
268b52a31eSHanoh Haim#include "utl_cpuu.h"
278b52a31eSHanoh Haim#include "timer_wheel_pq.h"
288b52a31eSHanoh Haim#include "rx_check.h"
298b52a31eSHanoh Haim#include "time_histogram.h"
308b52a31eSHanoh Haim#include "utl_jitter.h"
318b52a31eSHanoh Haim#include "CRing.h"
328b52a31eSHanoh Haim#include "msg_manager.h"
338b52a31eSHanoh Haim#include <common/cgen_map.h>
348b52a31eSHanoh Haim#include "platform_cfg.h"
35efb88737SIdo Barnea#include "stateful_rx_core.h"
367b9d1088SIdo Barnea#include "nat_check_flow_table.h"
37eae78d43SHanoh Haim#include "utl_ipg_bucket.h"
38b3c544bdSIdo Barnea#include "bp_gtest.h"
398b52a31eSHanoh Haim
408b52a31eSHanoh Haimint test_policer(){
418b52a31eSHanoh Haim    CPolicer policer;
428b52a31eSHanoh Haim
438b52a31eSHanoh Haim    policer.set_cir( 100.0);
448b52a31eSHanoh Haim    policer.set_level(0.0);
458b52a31eSHanoh Haim    policer.set_bucket_size(100.0);
468b52a31eSHanoh Haim
478b52a31eSHanoh Haim    double t;
488b52a31eSHanoh Haim    uint32_t c=0;
498b52a31eSHanoh Haim    for (t=0.001;t<10.0; t=t+0.001) {
508b52a31eSHanoh Haim        if ( policer.update(1.0,t) ){
518b52a31eSHanoh Haim            c++;
528b52a31eSHanoh Haim            printf(" %f \n",t);
538b52a31eSHanoh Haim        }
548b52a31eSHanoh Haim    }
558b52a31eSHanoh Haim    printf(" %u \n",c);
568b52a31eSHanoh Haim    if ( ( c > 970.0) &&  ( c < 1000.0) ) {
578b52a31eSHanoh Haim        printf(" ok \n");
588b52a31eSHanoh Haim        return (0);
598b52a31eSHanoh Haim    }else{
608b52a31eSHanoh Haim        printf("error \n");
618b52a31eSHanoh Haim        return (-1);
628b52a31eSHanoh Haim    }
638b52a31eSHanoh Haim}
648b52a31eSHanoh Haim
658b52a31eSHanoh Haim
668b52a31eSHanoh Haim
678b52a31eSHanoh Haim
688b52a31eSHanoh Haimint test_priorty_queue(void){
698b52a31eSHanoh Haim    CGenNode * node;
708b52a31eSHanoh Haim    std::priority_queue<CGenNode *, std::vector<CGenNode *>,CGenNodeCompare> p_queue;
718b52a31eSHanoh Haim    int i;
728b52a31eSHanoh Haim    for (i=0; i<10; i++) {
738b52a31eSHanoh Haim         node = new CGenNode();
7438dc2db8Simarom         printf(" +%p \n",node);
75cf0b463eSIdo Barnea         node->m_flow_id = 10-i;
76cf0b463eSIdo Barnea         node->m_pkt_info = (CFlowPktInfo *)(uintptr_t)i;
77cf0b463eSIdo Barnea         node->m_time = (double)i+0.1;
788b52a31eSHanoh Haim         p_queue.push(node);
798b52a31eSHanoh Haim    }
808b52a31eSHanoh Haim    while (!p_queue.empty()) {
818b52a31eSHanoh Haim        node = p_queue.top();
8238dc2db8Simarom        printf(" -->%p \n",node);
838b52a31eSHanoh Haim        //node->Dump(stdout);
848b52a31eSHanoh Haim        p_queue.pop();
858b52a31eSHanoh Haim        //delete node;
868b52a31eSHanoh Haim    }
878b52a31eSHanoh Haim    return (0);
888b52a31eSHanoh Haim}
898b52a31eSHanoh Haim
908b52a31eSHanoh Haim
918b52a31eSHanoh Haim
928b52a31eSHanoh Haimvoid histogram_test(){
938b52a31eSHanoh Haim    CTimeHistogram t;
948b52a31eSHanoh Haim    t.Create();
958b52a31eSHanoh Haim    t.Add(0.0001);
968b52a31eSHanoh Haim    t.Add(0.0002);
978b52a31eSHanoh Haim    t.Add(0.0003);
988b52a31eSHanoh Haim    int i;
998b52a31eSHanoh Haim    for (i=0; i<100;i++) {
1008b52a31eSHanoh Haim        t.Add(1.0/1000000.0);
1018b52a31eSHanoh Haim    }
1028b52a31eSHanoh Haim    t.Dump(stdout);
1038b52a31eSHanoh Haim    t.Delete();
1048b52a31eSHanoh Haim}
1058b52a31eSHanoh Haim
1068b52a31eSHanoh Haim
1078b52a31eSHanoh Haim
1088b52a31eSHanoh Haim
1098b52a31eSHanoh Haimint test_human_p(){
1108b52a31eSHanoh Haim    printf ("%s \n",double_to_human_str(1024.0*1024.0,"Byte",KBYE_1024).c_str());
1118b52a31eSHanoh Haim    printf ("%s \n",double_to_human_str(1.0,"Byte",KBYE_1024).c_str());
1128b52a31eSHanoh Haim    printf ("%s \n",double_to_human_str(-3000.0,"Byte",KBYE_1024).c_str());
1138b52a31eSHanoh Haim    printf ("%s \n",double_to_human_str(-3000000.0,"Byte",KBYE_1024).c_str());
1148b52a31eSHanoh Haim    printf ("%s \n",double_to_human_str(-30000000.0,"Byte",KBYE_1024).c_str());
1158b52a31eSHanoh Haim    return (0);
1168b52a31eSHanoh Haim}
1178b52a31eSHanoh Haim
118cf0b463eSIdo Barneaclass basic : public trexTest {};
119cf0b463eSIdo Barneaclass cpu : public trexTest {};
1208b52a31eSHanoh Haim
1218b52a31eSHanoh HaimTEST_F(basic, limit_single_pkt) {
1228b52a31eSHanoh Haim
1238b52a31eSHanoh Haim     CTestBasic t1;
1248b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
1258b52a31eSHanoh Haim     po->preview.setVMode(3);
1268b52a31eSHanoh Haim     po->preview.setFileWrite(true);
1278b52a31eSHanoh Haim     po->cfg_file ="cap2/limit_single_pkt.yaml";
1288b52a31eSHanoh Haim     po->out_file ="exp/limit_single_pkt";
1298b52a31eSHanoh Haim     bool res=t1.init();
1308b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
1318b52a31eSHanoh Haim}
1328b52a31eSHanoh Haim
13389309695SHanoh HaimTEST_F(basic, limit_multi_pkt) {
1348b52a31eSHanoh Haim
1358b52a31eSHanoh Haim     CTestBasic t1;
1368b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
1378b52a31eSHanoh Haim     po->preview.setVMode(3);
1388b52a31eSHanoh Haim     po->preview.setFileWrite(true);
1398b52a31eSHanoh Haim     po->cfg_file ="cap2/limit_multi_pkt.yaml";
1408b52a31eSHanoh Haim     po->out_file ="exp/limit_multi_pkt";
1418b52a31eSHanoh Haim     bool res=t1.init();
1428b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
143cf0b463eSIdo Barnea}
1448b52a31eSHanoh Haim
1458b52a31eSHanoh HaimTEST_F(basic, imix) {
1468b52a31eSHanoh Haim
1478b52a31eSHanoh Haim     CTestBasic t1;
1488b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
1498b52a31eSHanoh Haim     po->preview.setVMode(3);
1508b52a31eSHanoh Haim     po->preview.setFileWrite(true);
1518b52a31eSHanoh Haim     po->cfg_file ="cap2/imix.yaml";
1528b52a31eSHanoh Haim     po->out_file ="exp/imix";
1538b52a31eSHanoh Haim     bool res=t1.init();
1548b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
1558b52a31eSHanoh Haim}
1568b52a31eSHanoh Haim
15789309695SHanoh HaimTEST_F(basic, imix_fast) {
15889309695SHanoh Haim
15989309695SHanoh Haim     CTestBasic t1;
16089309695SHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
16189309695SHanoh Haim     po->preview.setVMode(3);
16289309695SHanoh Haim     po->preview.setFileWrite(true);
16389309695SHanoh Haim     po->cfg_file ="cap2/imix_64_fast.yaml";
16489309695SHanoh Haim     po->out_file ="exp/imix_64_fast";
16589309695SHanoh Haim     bool res=t1.init();
16689309695SHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
16789309695SHanoh Haim}
16889309695SHanoh Haim
1698b52a31eSHanoh Haim
1708b52a31eSHanoh HaimTEST_F(basic, dns) {
1718b52a31eSHanoh Haim
1728b52a31eSHanoh Haim     CTestBasic t1;
1738b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
1748b52a31eSHanoh Haim     po->preview.setVMode(3);
1758b52a31eSHanoh Haim     po->preview.setFileWrite(true);
1768b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
1778b52a31eSHanoh Haim     po->out_file ="exp/dns";
1788b52a31eSHanoh Haim     bool res=t1.init();
1798b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
1808b52a31eSHanoh Haim}
1818b52a31eSHanoh Haim
1828b52a31eSHanoh Haim/* test -p function */
1838b52a31eSHanoh HaimTEST_F(basic, dns_flow_flip) {
1848b52a31eSHanoh Haim
1858b52a31eSHanoh Haim     CTestBasic t1;
1868b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
1878b52a31eSHanoh Haim     po->preview.setVMode(3);
1888b52a31eSHanoh Haim     po->preview.setFileWrite(true);
1898b52a31eSHanoh Haim     po->preview.setClientServerFlowFlip(true);
1908b52a31eSHanoh Haim
1918b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
1928b52a31eSHanoh Haim     po->out_file ="exp/dns_p";
1938b52a31eSHanoh Haim     bool res=t1.init();
1948b52a31eSHanoh Haim     po->preview.setClientServerFlowFlip(false);
1958b52a31eSHanoh Haim
1968b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
1978b52a31eSHanoh Haim}
1988b52a31eSHanoh Haim
1998b52a31eSHanoh HaimTEST_F(basic, dns_flip) {
2008b52a31eSHanoh Haim
2018b52a31eSHanoh Haim     CTestBasic t1;
2028b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2038b52a31eSHanoh Haim     po->preview.setVMode(3);
2048b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2058b52a31eSHanoh Haim     po->preview.setClientServerFlip(true);
2068b52a31eSHanoh Haim
2078b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
2088b52a31eSHanoh Haim     po->out_file ="exp/dns_flip";
2098b52a31eSHanoh Haim     bool res=t1.init();
2108b52a31eSHanoh Haim     po->preview.setClientServerFlip(false);
2118b52a31eSHanoh Haim
2128b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2138b52a31eSHanoh Haim}
2148b52a31eSHanoh Haim
2158b52a31eSHanoh HaimTEST_F(basic, dns_e) {
2168b52a31eSHanoh Haim
2178b52a31eSHanoh Haim     CTestBasic t1;
2188b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2198b52a31eSHanoh Haim     po->preview.setVMode(3);
2208b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2218b52a31eSHanoh Haim     po->preview.setClientServerFlowFlipAddr(true);
2228b52a31eSHanoh Haim
2238b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
2248b52a31eSHanoh Haim     po->out_file ="exp/dns_e";
2258b52a31eSHanoh Haim     bool res=t1.init();
2268b52a31eSHanoh Haim     po->preview.setClientServerFlowFlipAddr(false);
2278b52a31eSHanoh Haim
2288b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2298b52a31eSHanoh Haim}
2308b52a31eSHanoh Haim
2318b52a31eSHanoh Haim
2328b52a31eSHanoh Haim
2338b52a31eSHanoh Haim/* test the packet padding , must be valid for --rx-check to work */
2348b52a31eSHanoh HaimTEST_F(basic, dns_packet_padding_test) {
2358b52a31eSHanoh Haim
2368b52a31eSHanoh Haim     CTestBasic t1;
2378b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2388b52a31eSHanoh Haim     po->preview.setVMode(3);
2398b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2408b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
2418b52a31eSHanoh Haim     po->out_file ="exp/dns";
2428b52a31eSHanoh Haim     bool res=t1.init();
2438b52a31eSHanoh Haim     EXPECT_EQ_UINT32(t1.get_padd_offset_first_packet(),0);
2448b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2458b52a31eSHanoh Haim}
2468b52a31eSHanoh Haim
2478b52a31eSHanoh Haim
2488b52a31eSHanoh HaimTEST_F(basic, dns_ipv6) {
2498b52a31eSHanoh Haim
2508b52a31eSHanoh Haim     CTestBasic t1;
2518b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2528b52a31eSHanoh Haim     po->preview.setVMode(3);
2538b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2548b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
2558b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
2568b52a31eSHanoh Haim     po->out_file ="exp/dns_ipv6";
2578b52a31eSHanoh Haim     bool res=t1.init();
2588b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2598b52a31eSHanoh Haim     EXPECT_EQ_UINT32(t1.get_padd_offset_first_packet(),0);
2608b52a31eSHanoh Haim}
2618b52a31eSHanoh Haim
2628b52a31eSHanoh HaimTEST_F(basic, dns_json) {
2638b52a31eSHanoh Haim     CTestBasic t1;
2648b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2658b52a31eSHanoh Haim     t1.m_dump_json=true;
2668b52a31eSHanoh Haim     po->preview.setVMode(3);
2678b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2688b52a31eSHanoh Haim     po->cfg_file ="cap2/dns.yaml";
2698b52a31eSHanoh Haim     po->out_file ="exp/dns";
2708b52a31eSHanoh Haim     bool res=t1.init();
2718b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2728b52a31eSHanoh Haim}
2738b52a31eSHanoh Haim
2748b52a31eSHanoh Haim
2758b52a31eSHanoh Haim#if 0
2768b52a31eSHanoh Haim
2778b52a31eSHanoh HaimTEST_F(basic, dns_wlen) {
2788b52a31eSHanoh Haim
2798b52a31eSHanoh Haim     CTestBasic t1;
2808b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2818b52a31eSHanoh Haim     po->preview.setVMode(3);
2828b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2838b52a31eSHanoh Haim     po->cfg_file ="cap2/dns_wlen.yaml";
2848b52a31eSHanoh Haim     po->out_file ="exp/dns_wlen";
2858b52a31eSHanoh Haim     bool res=t1.init();
2868b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2878b52a31eSHanoh Haim}
2888b52a31eSHanoh Haim
2898b52a31eSHanoh HaimTEST_F(basic, dns_wlen1) {
2908b52a31eSHanoh Haim
2918b52a31eSHanoh Haim     CTestBasic t1;
2928b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
2938b52a31eSHanoh Haim     po->preview.setVMode(3);
2948b52a31eSHanoh Haim     po->preview.setFileWrite(true);
2958b52a31eSHanoh Haim     po->cfg_file ="cap2/dns_wlen1.yaml";
2968b52a31eSHanoh Haim     po->out_file ="exp/dns_wlen1";
2978b52a31eSHanoh Haim     bool res=t1.init();
2988b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
2998b52a31eSHanoh Haim}
3008b52a31eSHanoh Haim
3018b52a31eSHanoh HaimTEST_F(basic, dns_wlen2) {
3028b52a31eSHanoh Haim
3038b52a31eSHanoh Haim     CTestBasic t1;
3048b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
3058b52a31eSHanoh Haim     po->preview.setVMode(3);
3068b52a31eSHanoh Haim     po->preview.setFileWrite(true);
3078b52a31eSHanoh Haim     po->cfg_file ="cap2/dns_wlen2.yaml";
3088b52a31eSHanoh Haim     po->out_file ="exp/dns_wlen2";
3098b52a31eSHanoh Haim     bool res=t1.init();
3108b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
3118b52a31eSHanoh Haim}
3128b52a31eSHanoh Haim
3138b52a31eSHanoh Haim
3148b52a31eSHanoh Haim
3158b52a31eSHanoh HaimTEST_F(basic, dns_one_server_2) {
3168b52a31eSHanoh Haim
3178b52a31eSHanoh Haim     CTestBasic t1;
3188b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
3198b52a31eSHanoh Haim     po->preview.setVMode(3);
3208b52a31eSHanoh Haim     po->preview.setFileWrite(true);
3218b52a31eSHanoh Haim     po->cfg_file ="cap2/dns_single_server.yaml";
3228b52a31eSHanoh Haim     po->out_file ="exp/dns_single_server";
3238b52a31eSHanoh Haim     bool res=t1.init();
3248b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
3258b52a31eSHanoh Haim}
3268b52a31eSHanoh Haim
3278b52a31eSHanoh Haim#endif
3288b52a31eSHanoh Haim
3298b52a31eSHanoh HaimTEST_F(basic, dns_one_server) {
3308b52a31eSHanoh Haim
3318b52a31eSHanoh Haim     CTestBasic t1;
3328b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
3338b52a31eSHanoh Haim     po->preview.setVMode(3);
3348b52a31eSHanoh Haim     po->preview.setFileWrite(true);
3358b52a31eSHanoh Haim     po->cfg_file ="cap2/dns_one_server.yaml";
3368b52a31eSHanoh Haim     po->out_file ="exp/dns_one_server";
3378b52a31eSHanoh Haim     bool res=t1.init();
3388b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
3398b52a31eSHanoh Haim}
3408b52a31eSHanoh Haim
3418b52a31eSHanoh Haim
3428b52a31eSHanoh HaimTEST_F(basic, sfr2) {
3438b52a31eSHanoh Haim
3448b52a31eSHanoh Haim     CTestBasic t1;
3458b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
3468b52a31eSHanoh Haim
3478b52a31eSHanoh Haim     po->preview.setVMode(0);
3488b52a31eSHanoh Haim     po->preview.setFileWrite(true);
3498b52a31eSHanoh Haim     po->cfg_file ="cap2/sfr2.yaml";
3508b52a31eSHanoh Haim     po->out_file ="exp/sfr2";
3518b52a31eSHanoh Haim     bool res=t1.init();
3528b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
3538b52a31eSHanoh Haim}
3548b52a31eSHanoh Haim
3558b52a31eSHanoh Haim
3568b52a31eSHanoh HaimTEST_F(basic, sfr3) {
3578b52a31eSHanoh Haim
3588b52a31eSHanoh Haim     CTestBasic t1;
3598b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
3608b52a31eSHanoh Haim     po->preview.setVMode(0);
3618b52a31eSHanoh Haim     po->preview.setFileWrite(true);
3628b52a31eSHanoh Haim     po->cfg_file ="cap2/sfr3.yaml";
3638b52a31eSHanoh Haim     po->out_file ="exp/sfr3";
3648b52a31eSHanoh Haim     bool res=t1.init();
3658b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
3668b52a31eSHanoh Haim}
3678b52a31eSHanoh Haim
3688b52a31eSHanoh Haim
3698b52a31eSHanoh HaimTEST_F(basic, sfr4) {
3708b52a31eSHanoh Haim
3718b52a31eSHanoh Haim     CTestBasic t1;
3728b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
3738b52a31eSHanoh Haim     po->preview.setVMode(0);
3748b52a31eSHanoh Haim     po->preview.setFileWrite(true);
3758b52a31eSHanoh Haim     po->cfg_file ="cap2/sfr4.yaml";
3768b52a31eSHanoh Haim     po->out_file ="exp/sfr_4";
3778b52a31eSHanoh Haim     bool res=t1.init();
3788b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
3798b52a31eSHanoh Haim}
3808b52a31eSHanoh Haim
381569ca4f3SWenxian LiTEST_F(basic, per_template_gen1) {
382569ca4f3SWenxian Li
383569ca4f3SWenxian Li     CTestBasic t1;
384569ca4f3SWenxian Li     CParserOption * po =&CGlobalInfo::m_options;
385569ca4f3SWenxian Li     po->preview.setVMode(0);
386569ca4f3SWenxian Li     po->preview.setFileWrite(true);
387569ca4f3SWenxian Li     po->cfg_file ="cap2/per_template_gen1.yaml";
388569ca4f3SWenxian Li     po->out_file ="exp/sfr_4";
389569ca4f3SWenxian Li     bool res=t1.init();
390569ca4f3SWenxian Li     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
391569ca4f3SWenxian Li}
392569ca4f3SWenxian LiTEST_F(basic, per_template_gen2) {
393569ca4f3SWenxian Li
394569ca4f3SWenxian Li     CTestBasic t1;
395569ca4f3SWenxian Li     CParserOption * po =&CGlobalInfo::m_options;
396569ca4f3SWenxian Li     po->preview.setVMode(0);
397569ca4f3SWenxian Li     po->preview.setFileWrite(true);
398569ca4f3SWenxian Li     po->cfg_file ="cap2/per_template_gen2.yaml";
399569ca4f3SWenxian Li     po->out_file ="exp/sfr_4";
400569ca4f3SWenxian Li     bool res=t1.init();
401569ca4f3SWenxian Li     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
402569ca4f3SWenxian Li}
403569ca4f3SWenxian Li
404569ca4f3SWenxian Li
405569ca4f3SWenxian Li/*
406569ca4f3SWenxian LiTEST_F(basic, sfr5) {
407569ca4f3SWenxian Li
408569ca4f3SWenxian Li     CTestBasic t1;
409569ca4f3SWenxian Li     CParserOption * po =&CGlobalInfo::m_options;
410569ca4f3SWenxian Li     po->preview.setVMode(0);
411569ca4f3SWenxian Li     po->preview.setFileWrite(true);
412569ca4f3SWenxian Li     po->cfg_file ="cap2/sfr5.yaml";
413569ca4f3SWenxian Li     po->out_file ="exp/sfr_5";
414569ca4f3SWenxian Li     bool res=t1.init();
415569ca4f3SWenxian Li     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
416569ca4f3SWenxian Li}
417569ca4f3SWenxian Li*/
418569ca4f3SWenxian Li
4198b52a31eSHanoh Haim
4208b52a31eSHanoh HaimTEST_F(basic, ipv6_convert) {
4218b52a31eSHanoh Haim
4228b52a31eSHanoh Haim     CTestBasic t1;
4238b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
4248b52a31eSHanoh Haim     po->preview.setVMode(3);
4258b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
4268b52a31eSHanoh Haim     po->preview.setFileWrite(true);
4278b52a31eSHanoh Haim     po->cfg_file ="cap2/imix.yaml";
4288b52a31eSHanoh Haim     po->out_file ="exp/imix_v6";
4298b52a31eSHanoh Haim     bool res=t1.init();
4308b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
4318b52a31eSHanoh Haim}
4328b52a31eSHanoh Haim
4338b52a31eSHanoh HaimTEST_F(basic, ipv6) {
4348b52a31eSHanoh Haim
4358b52a31eSHanoh Haim     CTestBasic t1;
4368b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
4378b52a31eSHanoh Haim     po->preview.setVMode(3);
4388b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
4398b52a31eSHanoh Haim     po->preview.setFileWrite(true);
4408b52a31eSHanoh Haim     po->cfg_file ="cap2/ipv6.yaml";
4418b52a31eSHanoh Haim     po->out_file ="exp/ipv6";
4428b52a31eSHanoh Haim     bool res=t1.init();
4438b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
4448b52a31eSHanoh Haim}
4458b52a31eSHanoh Haim
4468b52a31eSHanoh HaimTEST_F(basic, ipv4_vlan) {
4478b52a31eSHanoh Haim
4488b52a31eSHanoh Haim     CTestBasic t1;
4498b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
4508b52a31eSHanoh Haim     po->preview.setVMode(3);
4518b52a31eSHanoh Haim     po->preview.setFileWrite(true);
452af52e17fSIdo Barnea     po->cfg_file ="cap2/ipv4_load_balance.yaml";
453af52e17fSIdo Barnea     po->out_file ="exp/ipv4_load_balance";
4548b52a31eSHanoh Haim     bool res=t1.init();
4558b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
4568b52a31eSHanoh Haim}
4578b52a31eSHanoh Haim
4588b52a31eSHanoh HaimTEST_F(basic, ipv6_vlan) {
4598b52a31eSHanoh Haim
4608b52a31eSHanoh Haim     CTestBasic t1;
4618b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
4628b52a31eSHanoh Haim     po->preview.setVMode(3);
4638b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
4648b52a31eSHanoh Haim     po->preview.setFileWrite(true);
465af52e17fSIdo Barnea     po->cfg_file ="cap2/ipv6_load_balance.yaml";
466af52e17fSIdo Barnea     po->out_file ="exp/ipv6_load_balance";
4678b52a31eSHanoh Haim     bool res=t1.init();
4688b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
4698b52a31eSHanoh Haim}
4708b52a31eSHanoh Haim
4718b52a31eSHanoh Haim
4728b52a31eSHanoh Haim/* exacly like cap file */
4738b52a31eSHanoh HaimTEST_F(basic, test_pcap_mode1) {
4748b52a31eSHanoh Haim
4758b52a31eSHanoh Haim     CTestBasic t1;
4768b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
4778b52a31eSHanoh Haim     po->preview.setVMode(3);
4788b52a31eSHanoh Haim     po->preview.setFileWrite(true);
4798b52a31eSHanoh Haim     po->cfg_file ="cap2/test_pcap_mode1.yaml";
4808b52a31eSHanoh Haim     po->out_file ="exp/pcap_mode1";
481cf0b463eSIdo Barnea     t1.m_time_diff = 0.000005; // 5 nsec
4828b52a31eSHanoh Haim     bool res=t1.init();
4838b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
4848b52a31eSHanoh Haim}
4858b52a31eSHanoh Haim
4868b52a31eSHanoh Haim/* check override the low IPG */
4878b52a31eSHanoh HaimTEST_F(basic, test_pcap_mode2) {
4888b52a31eSHanoh Haim
4898b52a31eSHanoh Haim     CTestBasic t1;
4908b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
4918b52a31eSHanoh Haim     po->preview.setVMode(3);
4928b52a31eSHanoh Haim     po->preview.setFileWrite(true);
4938b52a31eSHanoh Haim     po->cfg_file ="cap2/test_pcap_mode2.yaml";
4948b52a31eSHanoh Haim     po->out_file ="exp/pcap_mode2";
495cf0b463eSIdo Barnea     t1.m_time_diff = 0.000005; // 5 nsec
4968b52a31eSHanoh Haim     bool res=t1.init();
4978b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
4988b52a31eSHanoh Haim}
4998b52a31eSHanoh Haim
500c181e882SIdo Barnea#define l_pkt_test_s_ip 0x01020304
501c181e882SIdo Barnea#define l_pkt_test_d_ip 0x05060708
502c181e882SIdo Barnea
503c181e882SIdo BarneaCLatencyPktMode *
504c181e882SIdo Barnealatency_pkt_mod_create(uint8_t l_pkt_mode) {
505c181e882SIdo Barnea    switch (l_pkt_mode) {
506c181e882SIdo Barnea    default:
507c181e882SIdo Barnea        return  new CLatencyPktModeSCTP(l_pkt_mode);
508c181e882SIdo Barnea        break;
509c181e882SIdo Barnea    case L_PKT_SUBMODE_NO_REPLY:
510c181e882SIdo Barnea    case L_PKT_SUBMODE_REPLY:
511c181e882SIdo Barnea    case L_PKT_SUBMODE_0_SEQ:
512c181e882SIdo Barnea        return new CLatencyPktModeICMP(l_pkt_mode);
513c181e882SIdo Barnea        break;
5148b52a31eSHanoh Haim    }
5158b52a31eSHanoh Haim}
5168b52a31eSHanoh Haim
517c181e882SIdo Barnearte_mbuf_t *
518c181e882SIdo Barneacreate_latency_test_pkt(uint8_t l_pkt_mode, uint16_t &pkt_size, uint8_t port_id, uint8_t pkt_num) {
519c181e882SIdo Barnea    rte_mbuf_t * m;
520c181e882SIdo Barnea    CLatencyPktMode *c_l_pkt_mode;
5218b52a31eSHanoh Haim    CCPortLatency port0;
522c181e882SIdo Barnea    CLatencyPktInfo info;
523c181e882SIdo Barnea    CLatencyManager mgr;
524c181e882SIdo Barnea
525c181e882SIdo Barnea    c_l_pkt_mode = latency_pkt_mod_create(l_pkt_mode);
526c181e882SIdo Barnea
527c181e882SIdo Barnea    mgr.c_l_pkt_mode = c_l_pkt_mode;
528c181e882SIdo Barnea    info.Create(c_l_pkt_mode);
529c181e882SIdo Barnea    port0.Create(&mgr, 0, info.get_payload_offset(), info.get_l4_offset(), info.get_pkt_size(), 0);
530c181e882SIdo Barnea    info.set_ip(l_pkt_test_s_ip ,l_pkt_test_d_ip, 0x01000000);
531c181e882SIdo Barnea    m=info.generate_pkt(0);
532c181e882SIdo Barnea    while (pkt_num > 0) {
533c181e882SIdo Barnea        pkt_num--;
534c181e882SIdo Barnea        port0.update_packet(m, port_id);
535c181e882SIdo Barnea    }
536c181e882SIdo Barnea    pkt_size = info.get_pkt_size();
537c181e882SIdo Barnea    port0.Delete();
538c181e882SIdo Barnea    info.Delete();
539c181e882SIdo Barnea    delete c_l_pkt_mode;
540c181e882SIdo Barnea
541c181e882SIdo Barnea    return m;
542c181e882SIdo Barnea}
543c181e882SIdo Barnea
544c181e882SIdo Barneabool
545c181e882SIdo Barneaverify_latency_pkt(uint8_t *p, uint8_t proto, uint16_t icmp_seq, uint8_t icmp_type) {
546c181e882SIdo Barnea    EthernetHeader *eth = (EthernetHeader *)p;
547c181e882SIdo Barnea    IPHeader *ip = (IPHeader *)(p + 14);
548cf0b463eSIdo Barnea    uint8_t  srcmac[]={0x10,0x10,0x10,0x10,0x10,0x10};
549f6901ca1SHanoh Haim    //uint8_t  dstmac[]={0x0,0x0,0x0,0x0,0x0,0x0};
550c181e882SIdo Barnea    latency_header * h;
551cf0b463eSIdo Barnea
552c181e882SIdo Barnea    // eth
553c181e882SIdo Barnea    EXPECT_EQ_UINT32(eth->getNextProtocol(), 0x0800)<< "Failed ethernet next protocol check";
554c181e882SIdo Barnea    EXPECT_EQ_UINT32(memcmp(p, srcmac, 6), 0)<<  "Failed ethernet source MAC check";
555f6901ca1SHanoh Haim    //EXPECT_EQ_UINT32(memcmp(p, dstmac, 6), 0)<<  "Failed ethernet dest MAC check";
556c181e882SIdo Barnea    // IP
557c181e882SIdo Barnea    EXPECT_EQ_UINT32(ip->getSourceIp(), l_pkt_test_s_ip)<<  "Failed IP src check";
558c181e882SIdo Barnea    EXPECT_EQ_UINT32(ip->getDestIp(), l_pkt_test_d_ip)<<  "Failed IP dst check";
559c181e882SIdo Barnea    EXPECT_EQ_UINT32(ip->getProtocol(), proto)<<  "Failed IP protocol check";
560c181e882SIdo Barnea    EXPECT_EQ_UINT32(ip->isChecksumOK()?0:1, 0)<<  "Failed IP checksum check";
561c181e882SIdo Barnea    EXPECT_EQ_UINT32(ip->getTimeToLive(), 0xff)<<  "Failed IP ttl check";
562c181e882SIdo Barnea    EXPECT_EQ_UINT32(ip->getTotalLength(), 48)<<  "Failed IP total length check";
563cf0b463eSIdo Barnea
564c181e882SIdo Barnea    // payload
565c181e882SIdo Barnea    h=(latency_header *)(p+42);
566c181e882SIdo Barnea    EXPECT_EQ_UINT32(h->magic, LATENCY_MAGIC)<<  "Failed latency magic check";
567c181e882SIdo Barnea
568c181e882SIdo Barnea    if (proto == 0x84)
569c181e882SIdo Barnea        return true;
570c181e882SIdo Barnea    // ICMP
571c181e882SIdo Barnea    ICMPHeader *icmp = (ICMPHeader *)(p + 34);
572c181e882SIdo Barnea    EXPECT_EQ_UINT32(icmp->isCheckSumOk(28)?0:1, 0)<<  "Failed ICMP checksum verification";
573c181e882SIdo Barnea    EXPECT_EQ_UINT32(icmp->getSeqNum(), icmp_seq)<< "Failed ICMP sequence number check";
574c181e882SIdo Barnea    EXPECT_EQ_UINT32(icmp->getType(), icmp_type)<<  "Failed ICMP type check";
575c181e882SIdo Barnea    EXPECT_EQ_UINT32(icmp->getCode(), 0)<<  "Failed ICMP code check";
576c181e882SIdo Barnea    EXPECT_EQ_UINT32(icmp->getId(), 0xaabb)<<  "Failed ICMP ID check";
577c181e882SIdo Barnea
578c181e882SIdo Barnea    return true;
579c181e882SIdo Barnea}
580c181e882SIdo Barnea
581c181e882SIdo Barneabool
582c181e882SIdo Barneatest_latency_pkt_rcv(rte_mbuf_t *m, uint8_t l_pkt_mode, uint8_t port_num, uint16_t num_pkt, bool exp_pkt_ok
583c181e882SIdo Barnea                     , uint16_t exp_tx_seq, uint16_t exp_rx_seq) {
584c181e882SIdo Barnea    CLatencyPktMode *c_l_pkt_mode;
585c181e882SIdo Barnea    CCPortLatency port;
586c181e882SIdo Barnea    CLatencyPktInfo info;
587c181e882SIdo Barnea    CLatencyManager mgr;
588c181e882SIdo Barnea    CRx_check_header *rxc;
589c181e882SIdo Barnea    CGlobalInfo::m_options.m_l_pkt_mode = l_pkt_mode;
590c181e882SIdo Barnea
591c181e882SIdo Barnea    c_l_pkt_mode = latency_pkt_mod_create(l_pkt_mode);
592c181e882SIdo Barnea    mgr.c_l_pkt_mode = c_l_pkt_mode;
593c181e882SIdo Barnea    info.Create(c_l_pkt_mode);
594c181e882SIdo Barnea    port.Create(&mgr, 0, info.get_payload_offset(), info.get_l4_offset(), info.get_pkt_size(), 0);
595c181e882SIdo Barnea    bool pkt_ok = port.check_packet(m, rxc);
596c181e882SIdo Barnea
597c181e882SIdo Barnea    while (num_pkt > 0) {
598c181e882SIdo Barnea        num_pkt--;
599c181e882SIdo Barnea        if (port.can_send_packet(port_num)) {
600c181e882SIdo Barnea            port.update_packet(m, 0);
6018b52a31eSHanoh Haim        }
6028b52a31eSHanoh Haim    }
6038b52a31eSHanoh Haim
604c181e882SIdo Barnea    EXPECT_EQ_UINT32(pkt_ok ?0:1, exp_pkt_ok?0:1)<<  "Failed packet OK check";
605c181e882SIdo Barnea    EXPECT_EQ_UINT32(port.get_icmp_tx_seq(), exp_tx_seq)<<  "Failed tx check";
606c181e882SIdo Barnea    EXPECT_EQ_UINT32(port.get_icmp_rx_seq(), exp_rx_seq)<<  "Failed rx check";
607c181e882SIdo Barnea    // if packet is bad, check_packet raise the error counter
608c181e882SIdo Barnea    EXPECT_EQ_UINT32(port.m_unsup_prot, exp_pkt_ok?0:1)<<  "Failed unsupported packets count";
609c181e882SIdo Barnea
610c181e882SIdo Barnea    return true;
6118b52a31eSHanoh Haim}
6128b52a31eSHanoh Haim
6138b52a31eSHanoh Haim
614c181e882SIdo Barnea// Testing latency packet generation
615c181e882SIdo BarneaTEST_F(basic, latency1) {
616c181e882SIdo Barnea    uint8_t *p;
617c181e882SIdo Barnea    rte_mbuf_t * m;
618c181e882SIdo Barnea    uint16_t pkt_size;
6198b52a31eSHanoh Haim
620c181e882SIdo Barnea    // SCTP packet
621c181e882SIdo Barnea    m = create_latency_test_pkt(0, pkt_size, 0, 1);
622c181e882SIdo Barnea    p=rte_pktmbuf_mtod(m, uint8_t*);
623c181e882SIdo Barnea    verify_latency_pkt(p, 0x84, 0, 0);
624c181e882SIdo Barnea    rte_pktmbuf_free(m);
6258b52a31eSHanoh Haim
626c181e882SIdo Barnea    m = create_latency_test_pkt(L_PKT_SUBMODE_NO_REPLY, pkt_size, 1, 2);
627c181e882SIdo Barnea    p=rte_pktmbuf_mtod(m, uint8_t*);
628c181e882SIdo Barnea    verify_latency_pkt(p, 0x01, 2, 8);
629c181e882SIdo Barnea    rte_pktmbuf_free(m);
6308b52a31eSHanoh Haim
631c181e882SIdo Barnea    // ICMP reply mode client side
632c181e882SIdo Barnea    m = create_latency_test_pkt(L_PKT_SUBMODE_REPLY, pkt_size, 0, 3);
633c181e882SIdo Barnea    p = rte_pktmbuf_mtod(m, uint8_t*);
634c181e882SIdo Barnea    verify_latency_pkt(p, 0x01, 3, 8);
635c181e882SIdo Barnea    rte_pktmbuf_free(m);
6368b52a31eSHanoh Haim
637c181e882SIdo Barnea    // ICMP reply mode server side
638c181e882SIdo Barnea    m = create_latency_test_pkt(L_PKT_SUBMODE_REPLY, pkt_size, 1, 4);
639c181e882SIdo Barnea    p=rte_pktmbuf_mtod(m, uint8_t*);
640c181e882SIdo Barnea    verify_latency_pkt(p, 0x01, 4, 0);
641c181e882SIdo Barnea    rte_pktmbuf_free(m);
6428b52a31eSHanoh Haim
643c181e882SIdo Barnea    m = create_latency_test_pkt(L_PKT_SUBMODE_0_SEQ, pkt_size, 1, 5);
644c181e882SIdo Barnea    p=rte_pktmbuf_mtod(m, uint8_t*);
645c181e882SIdo Barnea    verify_latency_pkt(p, 0x01, 0, 8);
646c181e882SIdo Barnea    rte_pktmbuf_free(m);
647c181e882SIdo Barnea}
6488b52a31eSHanoh Haim
649c181e882SIdo Barnea// Testing latency packet receive path
650c181e882SIdo BarneaTEST_F(basic, latency2) {
651c181e882SIdo Barnea    rte_mbuf_t *m;
652c181e882SIdo Barnea    uint16_t pkt_size;
653c181e882SIdo Barnea    uint8_t port_id = 0;
654c181e882SIdo Barnea    uint8_t pkt_num = 1;
655c181e882SIdo Barnea    uint8_t l_pkt_mode;
6568b52a31eSHanoh Haim
657c181e882SIdo Barnea    l_pkt_mode = 0;
658c181e882SIdo Barnea    m = create_latency_test_pkt(l_pkt_mode, pkt_size, port_id, pkt_num);
659c181e882SIdo Barnea    test_latency_pkt_rcv(m, l_pkt_mode, 0, 2, true, 1, 0);
6608b52a31eSHanoh Haim
661c181e882SIdo Barnea    l_pkt_mode = L_PKT_SUBMODE_NO_REPLY;
662c181e882SIdo Barnea    m = create_latency_test_pkt(l_pkt_mode, pkt_size, port_id, pkt_num);
663c181e882SIdo Barnea    test_latency_pkt_rcv(m, l_pkt_mode, 1, 2, true, 3, 1);
6648b52a31eSHanoh Haim
665c181e882SIdo Barnea    // reply mode server
666c181e882SIdo Barnea    l_pkt_mode = L_PKT_SUBMODE_REPLY;
667c181e882SIdo Barnea    m = create_latency_test_pkt(l_pkt_mode, pkt_size, port_id, pkt_num);
668c181e882SIdo Barnea    test_latency_pkt_rcv(m, l_pkt_mode, 1, 2, true, 2, 1);
6698b52a31eSHanoh Haim
670c181e882SIdo Barnea    // reply mode client
671c181e882SIdo Barnea    l_pkt_mode = L_PKT_SUBMODE_REPLY;
672c181e882SIdo Barnea    m = create_latency_test_pkt(l_pkt_mode, pkt_size, port_id, pkt_num);
673c181e882SIdo Barnea    test_latency_pkt_rcv(m, l_pkt_mode, 0, 2, true, 3, 1);
6748b52a31eSHanoh Haim
675c181e882SIdo Barnea    l_pkt_mode = L_PKT_SUBMODE_0_SEQ;
676c181e882SIdo Barnea    m = create_latency_test_pkt(l_pkt_mode, pkt_size, port_id, pkt_num);
677c181e882SIdo Barnea    test_latency_pkt_rcv(m, l_pkt_mode, 0, 2, true, 0, 0);
6788b52a31eSHanoh Haim
679c181e882SIdo Barnea    // bad packet
680c181e882SIdo Barnea    m = create_latency_test_pkt(l_pkt_mode, pkt_size, port_id, pkt_num);
681c181e882SIdo Barnea    EthernetHeader *eth = (EthernetHeader *)rte_pktmbuf_mtod(m, uint8_t*);
682c181e882SIdo Barnea    eth->setNextProtocol(0x5);
683c181e882SIdo Barnea    test_latency_pkt_rcv(m, l_pkt_mode, 0, 2, false, 1, 0);
684c181e882SIdo Barnea}
6858b52a31eSHanoh Haim
6868b52a31eSHanoh Haimclass CDummyLatencyHWBase : public CPortLatencyHWBase {
6878b52a31eSHanoh Haimpublic:
6888b52a31eSHanoh Haim    CDummyLatencyHWBase(){
6898b52a31eSHanoh Haim        m_queue=0;
6908b52a31eSHanoh Haim        m_port_id=0;
6918b52a31eSHanoh Haim    }
6928b52a31eSHanoh Haim
693abc0cb87Simarom    virtual int tx(rte_mbuf_t *m) {
6948b52a31eSHanoh Haim        assert(m_queue==0);
6958b52a31eSHanoh Haim        //printf(" tx on port %d \n",m_port_id);
6968b52a31eSHanoh Haim      //  utl_DumpBuffer(stdout,rte_pktmbuf_mtod(m, uint8_t*),rte_pktmbuf_pkt_len(m),0);
6978b52a31eSHanoh Haim        m_queue=m;
6988b52a31eSHanoh Haim        return (0);
6998b52a31eSHanoh Haim    }
7008b52a31eSHanoh Haim
701abc0cb87Simarom    virtual int tx_latency(rte_mbuf_t *m) {
702abc0cb87Simarom        return tx(m);
703abc0cb87Simarom    }
704cf0b463eSIdo Barnea
7058b52a31eSHanoh Haim    virtual rte_mbuf_t * rx(){
7068b52a31eSHanoh Haim        //printf(" rx on port %d \n",m_port_id);
7078b52a31eSHanoh Haim        rte_mbuf_t * m=0;
7088b52a31eSHanoh Haim        if (m_queue ) {
7098b52a31eSHanoh Haim            m=m_queue;
7108b52a31eSHanoh Haim            m_queue=0;
7118b52a31eSHanoh Haim        }
7128b52a31eSHanoh Haim
7138b52a31eSHanoh Haim        /*if ( m ){
7148b52a31eSHanoh Haim            utl_DumpBuffer(stdout,rte_pktmbuf_mtod(m , uint8_t*),rte_pktmbuf_pkt_len(m ),0);
7158b52a31eSHanoh Haim        } */
7168b52a31eSHanoh Haim        return ( m );
7178b52a31eSHanoh Haim    }
7188b52a31eSHanoh Haim
719cf0b463eSIdo Barnea    virtual uint16_t rx_burst(struct rte_mbuf **rx_pkts,
7208b52a31eSHanoh Haim                               uint16_t nb_pkts){
7218b52a31eSHanoh Haim        //printf(" rx on port %d \n",m_port_id);
7228b52a31eSHanoh Haim        rte_mbuf_t * m=rx();
7238b52a31eSHanoh Haim        if (m) {
7248b52a31eSHanoh Haim            rx_pkts[0]=m;
7258b52a31eSHanoh Haim            return (1);
7268b52a31eSHanoh Haim        }else{
7278b52a31eSHanoh Haim            return (0);
7288b52a31eSHanoh Haim        }
7298b52a31eSHanoh Haim    }
7308b52a31eSHanoh Haim
7318b52a31eSHanoh Haim
7328b52a31eSHanoh Haimprivate:
7338b52a31eSHanoh Haim    rte_mbuf_t * m_queue;
7348b52a31eSHanoh Haimpublic:
7358b52a31eSHanoh Haim    uint8_t      m_port_id;
7368b52a31eSHanoh Haim};
7378b52a31eSHanoh Haim
738c181e882SIdo Barnea// Testing latency statistics functions
739c181e882SIdo BarneaTEST_F(basic, latency3) {
7408b52a31eSHanoh Haim    CLatencyManager mg;
7418b52a31eSHanoh Haim    CLatencyManagerCfg  cfg;
742e33e37efSIdo Barnea    CDummyLatencyHWBase dports[TREX_MAX_PORTS];
7438b52a31eSHanoh Haim    cfg.m_cps =10;
7448b52a31eSHanoh Haim    cfg.m_max_ports=4;
7458b52a31eSHanoh Haim    int i;
746e33e37efSIdo Barnea    for (i = 0; i < TREX_MAX_PORTS; i++) {
7478b52a31eSHanoh Haim        dports[i].m_port_id=i;
7488b52a31eSHanoh Haim        cfg.m_ports[i] = &dports[i];
7498b52a31eSHanoh Haim    }
7508b52a31eSHanoh Haim
7518b52a31eSHanoh Haim    mg.Create(&cfg);
7528b52a31eSHanoh Haim
7538b52a31eSHanoh Haim    printf(" before sending \n");
7548b52a31eSHanoh Haim    mg.Dump(stdout);
7558b52a31eSHanoh Haim    std::string json;
7568b52a31eSHanoh Haim    mg.dump_json_v2(json);
7578b52a31eSHanoh Haim    printf(" %s \n",json.c_str());
7588b52a31eSHanoh Haim
7598b52a31eSHanoh Haim
7608b52a31eSHanoh Haim    EXPECT_EQ_UINT32(mg.is_active()?1:0, (uint32_t)0)<< "pass";
7618b52a31eSHanoh Haim
7623ca8be80Simarom    mg.start(8, false);
7638b52a31eSHanoh Haim    mg.stop();
7648b52a31eSHanoh Haim    mg.Dump(stdout);
7658b52a31eSHanoh Haim    mg.DumpShort(stdout);
7668b52a31eSHanoh Haim    mg.dump_json_v2(json);
7678b52a31eSHanoh Haim    printf(" %s \n",json.c_str());
7688b52a31eSHanoh Haim
7698b52a31eSHanoh Haim    mg.Delete();
7708b52a31eSHanoh Haim}
7718b52a31eSHanoh Haim
7728b52a31eSHanoh HaimTEST_F(basic, hist1) {
7738b52a31eSHanoh Haim
7748b52a31eSHanoh Haim    CTimeHistogram  hist1;
7758b52a31eSHanoh Haim
7768b52a31eSHanoh Haim    dsec_t dusec=1.0/1000000.0;
7778b52a31eSHanoh Haim
7788b52a31eSHanoh Haim    hist1.Create();
7798b52a31eSHanoh Haim    hist1.Add(dusec);
7808b52a31eSHanoh Haim    hist1.Add(2.0*dusec);
7818b52a31eSHanoh Haim    hist1.Add(11.0*dusec);
7828b52a31eSHanoh Haim    hist1.Add(110.0*dusec);
7838b52a31eSHanoh Haim    hist1.Add(1110.0*dusec);
7848b52a31eSHanoh Haim    hist1.Add(10110.0*dusec);
7858b52a31eSHanoh Haim    hist1.Add(40110.0*dusec);
7868b52a31eSHanoh Haim    hist1.Add(400110.0*dusec);
7878b52a31eSHanoh Haim    hist1.Dump(stdout);
7888b52a31eSHanoh Haim    hist1.Delete();
7898b52a31eSHanoh Haim}
7908b52a31eSHanoh Haim
7918b52a31eSHanoh HaimTEST_F(basic, rtsp1) {
7928b52a31eSHanoh Haim
7938b52a31eSHanoh Haim     CTestBasic t1;
7948b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
7958b52a31eSHanoh Haim     po->preview.setVMode(3);
7968b52a31eSHanoh Haim     po->preview.setFileWrite(true);
7978b52a31eSHanoh Haim     po->cfg_file ="cap2/rtsp_short1.yaml";
7988b52a31eSHanoh Haim     po->out_file ="exp/rtsp_short1";
7998b52a31eSHanoh Haim     bool res=t1.init();
8008b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
801cf0b463eSIdo Barnea}
8028b52a31eSHanoh Haim
8038b52a31eSHanoh HaimTEST_F(basic, rtsp2) {
8048b52a31eSHanoh Haim
8058b52a31eSHanoh Haim     CTestBasic t1;
8068b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8078b52a31eSHanoh Haim     po->preview.setVMode(3);
8088b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8098b52a31eSHanoh Haim     po->cfg_file ="cap2/rtsp_short2.yaml";
8108b52a31eSHanoh Haim     po->out_file ="exp/rtsp_short2";
8118b52a31eSHanoh Haim     bool res=t1.init();
8128b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
813cf0b463eSIdo Barnea}
8148b52a31eSHanoh Haim
8158b52a31eSHanoh HaimTEST_F(basic, rtsp3) {
8168b52a31eSHanoh Haim
8178b52a31eSHanoh Haim     CTestBasic t1;
8188b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8198b52a31eSHanoh Haim     po->preview.setVMode(3);
8208b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8218b52a31eSHanoh Haim     po->cfg_file ="cap2/rtsp_short3.yaml";
8228b52a31eSHanoh Haim     po->out_file ="exp/rtsp_short3";
8238b52a31eSHanoh Haim     t1.m_req_ports = 32000;
8248b52a31eSHanoh Haim     bool res=t1.init();
8258b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
826cf0b463eSIdo Barnea}
8278b52a31eSHanoh Haim
8288b52a31eSHanoh Haim
8298b52a31eSHanoh HaimTEST_F(basic, rtsp1_ipv6) {
8308b52a31eSHanoh Haim
8318b52a31eSHanoh Haim     CTestBasic t1;
8328b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8338b52a31eSHanoh Haim     po->preview.setVMode(3);
8348b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
8358b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8368b52a31eSHanoh Haim     po->cfg_file ="cap2/rtsp_short1.yaml";
8378b52a31eSHanoh Haim     po->out_file ="exp/rtsp_short1_v6";
8388b52a31eSHanoh Haim     bool res=t1.init();
8398b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
840cf0b463eSIdo Barnea}
8418b52a31eSHanoh Haim
8428b52a31eSHanoh HaimTEST_F(basic, rtsp2_ipv6) {
8438b52a31eSHanoh Haim
8448b52a31eSHanoh Haim     CTestBasic t1;
8458b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8468b52a31eSHanoh Haim     po->preview.setVMode(3);
8478b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
8488b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8498b52a31eSHanoh Haim     po->cfg_file ="cap2/rtsp_short2.yaml";
8508b52a31eSHanoh Haim     po->out_file ="exp/rtsp_short2_v6";
8518b52a31eSHanoh Haim     bool res=t1.init();
8528b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
853cf0b463eSIdo Barnea}
8548b52a31eSHanoh Haim
8558b52a31eSHanoh HaimTEST_F(basic, rtsp3_ipv6) {
8568b52a31eSHanoh Haim
8578b52a31eSHanoh Haim     CTestBasic t1;
8588b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8598b52a31eSHanoh Haim     po->preview.setVMode(3);
8608b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
8618b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8628b52a31eSHanoh Haim     po->cfg_file ="cap2/rtsp_short3.yaml";
8638b52a31eSHanoh Haim     po->out_file ="exp/rtsp_short3_v6";
8648b52a31eSHanoh Haim     t1.m_req_ports = 32000;
8658b52a31eSHanoh Haim     bool res=t1.init();
8668b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
867cf0b463eSIdo Barnea}
8688b52a31eSHanoh Haim
8698b52a31eSHanoh Haim
8708b52a31eSHanoh HaimTEST_F(basic, sip1) {
8718b52a31eSHanoh Haim
8728b52a31eSHanoh Haim     CTestBasic t1;
8738b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8748b52a31eSHanoh Haim     po->preview.setVMode(3);
8758b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8768b52a31eSHanoh Haim     po->cfg_file ="cap2/sip_short1.yaml";
8778b52a31eSHanoh Haim     po->out_file ="exp/sip_short1";
8788b52a31eSHanoh Haim     bool res=t1.init();
8798b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
880cf0b463eSIdo Barnea}
8818b52a31eSHanoh Haim
8828b52a31eSHanoh Haim
8838b52a31eSHanoh HaimTEST_F(basic, sip2) {
8848b52a31eSHanoh Haim
8858b52a31eSHanoh Haim     CTestBasic t1;
8868b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8878b52a31eSHanoh Haim     po->preview.setVMode(3);
8888b52a31eSHanoh Haim     po->preview.setFileWrite(true);
8898b52a31eSHanoh Haim     po->cfg_file ="cap2/sip_short2.yaml";
8908b52a31eSHanoh Haim     po->out_file ="exp/sip_short2";
8918b52a31eSHanoh Haim     bool res=t1.init();
8928b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
893cf0b463eSIdo Barnea}
8948b52a31eSHanoh Haim
8958b52a31eSHanoh HaimTEST_F(basic, sip3) {
8968b52a31eSHanoh Haim
8978b52a31eSHanoh Haim     CTestBasic t1;
8988b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
8998b52a31eSHanoh Haim     po->preview.setVMode(3);
9008b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9018b52a31eSHanoh Haim     po->cfg_file ="cap2/sip_short2.yaml";
9028b52a31eSHanoh Haim     po->out_file ="exp/sip_short3";
9038b52a31eSHanoh Haim     t1.m_req_ports = 32000;
9048b52a31eSHanoh Haim     bool res=t1.init();
9058b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
906cf0b463eSIdo Barnea}
9078b52a31eSHanoh Haim
9088b52a31eSHanoh Haim
9098b52a31eSHanoh HaimTEST_F(basic, sip1_ipv6) {
9108b52a31eSHanoh Haim
9118b52a31eSHanoh Haim     CTestBasic t1;
9128b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
9138b52a31eSHanoh Haim     po->preview.setVMode(3);
9148b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
9158b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9168b52a31eSHanoh Haim     po->cfg_file ="cap2/sip_short1.yaml";
9178b52a31eSHanoh Haim     po->out_file ="exp/sip_short1_v6";
9188b52a31eSHanoh Haim     bool res=t1.init();
9198b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
920cf0b463eSIdo Barnea}
9218b52a31eSHanoh Haim
9228b52a31eSHanoh Haim
9238b52a31eSHanoh HaimTEST_F(basic, sip2_ipv6) {
9248b52a31eSHanoh Haim
9258b52a31eSHanoh Haim     CTestBasic t1;
9268b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
9278b52a31eSHanoh Haim     po->preview.setVMode(3);
9288b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
9298b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9308b52a31eSHanoh Haim     po->cfg_file ="cap2/sip_short2.yaml";
9318b52a31eSHanoh Haim     po->out_file ="exp/sip_short2_v6";
9328b52a31eSHanoh Haim     bool res=t1.init();
9338b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
934cf0b463eSIdo Barnea}
9358b52a31eSHanoh Haim
9368b52a31eSHanoh HaimTEST_F(basic, sip3_ipv6) {
9378b52a31eSHanoh Haim
9388b52a31eSHanoh Haim     CTestBasic t1;
9398b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
9408b52a31eSHanoh Haim     po->preview.setVMode(3);
9418b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
9428b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9438b52a31eSHanoh Haim     po->cfg_file ="cap2/sip_short2.yaml";
9448b52a31eSHanoh Haim     po->out_file ="exp/sip_short3_v6";
9458b52a31eSHanoh Haim     t1.m_req_ports = 32000;
9468b52a31eSHanoh Haim     bool res=t1.init();
9478b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
948cf0b463eSIdo Barnea}
9498b52a31eSHanoh Haim
9508b52a31eSHanoh Haim
9518b52a31eSHanoh HaimTEST_F(basic, dyn1) {
9528b52a31eSHanoh Haim
9538b52a31eSHanoh Haim     CTestBasic t1;
9548b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
955cf0b463eSIdo Barnea     srand(1);
9568b52a31eSHanoh Haim     po->preview.setVMode(3);
9578b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9588b52a31eSHanoh Haim     po->cfg_file ="cap2/dyn_pyld1.yaml";
9598b52a31eSHanoh Haim     po->out_file ="exp/dyn_pyld1";
9608b52a31eSHanoh Haim     bool res=t1.init();
9618b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
962cf0b463eSIdo Barnea}
9638b52a31eSHanoh Haim
9648b52a31eSHanoh HaimTEST_F(basic, http1) {
9658b52a31eSHanoh Haim
9668b52a31eSHanoh Haim     CTestBasic t1;
9678b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
9688b52a31eSHanoh Haim     po->preview.setVMode(3);
9698b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9708b52a31eSHanoh Haim     po->cfg_file ="cap2/http_plugin.yaml";
9718b52a31eSHanoh Haim     po->out_file ="exp/http_plugin";
9728b52a31eSHanoh Haim     bool res=t1.init();
9738b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
974cf0b463eSIdo Barnea}
9758b52a31eSHanoh Haim
9768b52a31eSHanoh HaimTEST_F(basic, http1_ipv6) {
9778b52a31eSHanoh Haim
9788b52a31eSHanoh Haim     CTestBasic t1;
9798b52a31eSHanoh Haim     CParserOption * po =&CGlobalInfo::m_options;
9808b52a31eSHanoh Haim     po->preview.setVMode(3);
9818b52a31eSHanoh Haim     po->preview.set_ipv6_mode_enable(true);
9828b52a31eSHanoh Haim     po->preview.setFileWrite(true);
9838b52a31eSHanoh Haim     po->cfg_file ="cap2/http_plugin.yaml";
9848b52a31eSHanoh Haim     po->out_file ="exp/http_plugin_v6";
9858b52a31eSHanoh Haim     bool res=t1.init();
9868b52a31eSHanoh Haim     EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
987cf0b463eSIdo Barnea}
9888b52a31eSHanoh Haim
9898b52a31eSHanoh Haim
9908b52a31eSHanoh Haim
9918b52a31eSHanoh Haimvoid delay(int msec);
9928b52a31eSHanoh Haim
993c2912dfcSHanoh Haim#if 0
9948b52a31eSHanoh Haim
9958b52a31eSHanoh HaimTEST_F(cpu, cpu1) {
9968b52a31eSHanoh Haim    CCpuUtlDp cpu_dp;
9978b52a31eSHanoh Haim    CCpuUtlCp cpu_cp;
9988b52a31eSHanoh Haim    cpu_cp.Create(&cpu_dp);
9998b52a31eSHanoh Haim    int i;
10008b52a31eSHanoh Haim    for (i=0; i<5;i++) {
10018b52a31eSHanoh Haim        cpu_cp.Update();
10028b52a31eSHanoh Haim        double c=cpu_cp.GetVal();
10038b52a31eSHanoh Haim        printf (" %f \n",c);
10048b52a31eSHanoh Haim        EXPECT_EQ(c,(double)0.0);
10058b52a31eSHanoh Haim
10068b52a31eSHanoh Haim        delay(100);
10078b52a31eSHanoh Haim    }
10088b52a31eSHanoh Haim
10098b52a31eSHanoh Haim    cpu_cp.Delete();
10108b52a31eSHanoh Haim}
10118b52a31eSHanoh Haim
10128b52a31eSHanoh HaimTEST_F(cpu, cpu2) {
10138b52a31eSHanoh Haim    CCpuUtlDp cpu_dp;
10148b52a31eSHanoh Haim    CCpuUtlCp cpu_cp;
10158b52a31eSHanoh Haim    cpu_cp.Create(&cpu_dp);
10168b52a31eSHanoh Haim    int i;
10178b52a31eSHanoh Haim    for (i=0; i<100;i++) {
10188b52a31eSHanoh Haim        cpu_dp.start_work();
10198b52a31eSHanoh Haim        cpu_cp.Update();
10208b52a31eSHanoh Haim        double c1 = cpu_cp.GetVal();
10218b52a31eSHanoh Haim        printf(" cpu %2.0f \n",c1);
10228b52a31eSHanoh Haim        if (i>50) {
10238b52a31eSHanoh Haim            int s=( c1<80 && c1>30)?1:0;
10248b52a31eSHanoh Haim            EXPECT_EQ(s,1);
10258b52a31eSHanoh Haim        }
10268b52a31eSHanoh Haim        delay(1);
10278b52a31eSHanoh Haim        if ((i%2)==1) {
10288b52a31eSHanoh Haim            cpu_dp.commit();
10298b52a31eSHanoh Haim        }else{
10308b52a31eSHanoh Haim            cpu_dp.revert();
10318b52a31eSHanoh Haim        }
10328b52a31eSHanoh Haim    }
10338b52a31eSHanoh Haim
10348b52a31eSHanoh Haim    cpu_cp.Delete();
10358b52a31eSHanoh Haim}
1036c2912dfcSHanoh Haim#endif
10378b52a31eSHanoh Haim
10388b52a31eSHanoh Haim#if 0
10398b52a31eSHanoh HaimTEST_F(cpu, cpu3) {
10408b52a31eSHanoh Haim    CCpuUtlDp cpu_dp;
10418b52a31eSHanoh Haim    CCpuUtlCp cpu_cp;
10428b52a31eSHanoh Haim    cpu_cp.Create(&cpu_dp);
10438b52a31eSHanoh Haim    int i;
10448b52a31eSHanoh Haim    for (i=0; i<200;i++) {
10458b52a31eSHanoh Haim        cpu_dp.start_work();
10468b52a31eSHanoh Haim        if (i%10==0) {
10478b52a31eSHanoh Haim            cpu_cp.Update();
10488b52a31eSHanoh Haim        }
10498b52a31eSHanoh Haim        double c1 = cpu_cp.GetVal();
10508b52a31eSHanoh Haim        if (i>150) {
10518b52a31eSHanoh Haim            printf(" cpu %2.0f \n",c1);
10528b52a31eSHanoh Haim            int s=( c1<11 && c1>8)?1:0;
10538b52a31eSHanoh Haim            EXPECT_EQ(s,1);
1054cf0b463eSIdo Barnea        }
10558b52a31eSHanoh Haim        delay(1);
10568b52a31eSHanoh Haim        if ((i%10)==1) {
10578b52a31eSHanoh Haim            cpu_dp.commit();
10588b52a31eSHanoh Haim        }else{
10598b52a31eSHanoh Haim            cpu_dp.revert();
10608b52a31eSHanoh Haim        }
10618b52a31eSHanoh Haim    }
10628b52a31eSHanoh Haim    cpu_cp.Delete();
10638b52a31eSHanoh Haim}
10648b52a31eSHanoh Haim#endif
10658b52a31eSHanoh Haim
1066cf0b463eSIdo Barneaclass timerwl  : public trexTest {};
10678b52a31eSHanoh Haim
10688b52a31eSHanoh Haimvoid  flow_callback(CFlowTimerHandle * timer_handle);
10698b52a31eSHanoh Haim
10708b52a31eSHanoh Haimclass CTestFlow {
10718b52a31eSHanoh Haimpublic:
1072cf0b463eSIdo Barnea    CTestFlow(){
1073cf0b463eSIdo Barnea        flow_id = 0;
10748b52a31eSHanoh Haim        m_timer_handle.m_callback=flow_callback;
1075cf0b463eSIdo Barnea        m_timer_handle.m_object = (void *)this;
1076cf0b463eSIdo Barnea        m_timer_handle.m_id = 0x1234;
1077cf0b463eSIdo Barnea    }
10788b52a31eSHanoh Haim
1079cf0b463eSIdo Barnea    uint32_t		flow_id;
1080cf0b463eSIdo Barnea    CFlowTimerHandle m_timer_handle;
10818b52a31eSHanoh Haimpublic:
1082cf0b463eSIdo Barnea    void OnTimeOut(){
10838b52a31eSHanoh Haim        printf(" timeout %d \n",flow_id);
1084cf0b463eSIdo Barnea    }
10858b52a31eSHanoh Haim};
10868b52a31eSHanoh Haim
10878b52a31eSHanoh Haimvoid  flow_callback(CFlowTimerHandle * t){
10888b52a31eSHanoh Haim    CTestFlow * lp=(CTestFlow *)t->m_object;
10898b52a31eSHanoh Haim    assert(lp);
10908b52a31eSHanoh Haim    assert(t->m_id==0x1234);
10918b52a31eSHanoh Haim    lp->OnTimeOut();
10928b52a31eSHanoh Haim}
10938b52a31eSHanoh Haim
10948b52a31eSHanoh Haim
10958b52a31eSHanoh HaimTEST_F(timerwl, tw1) {
10968b52a31eSHanoh Haim    CTimerWheel  my_tw;
10978b52a31eSHanoh Haim
10988b52a31eSHanoh Haim    CTestFlow f1;
10998b52a31eSHanoh Haim    CTestFlow f2;
11008b52a31eSHanoh Haim    CTestFlow f3;
11018b52a31eSHanoh Haim    CTestFlow f4;
11028b52a31eSHanoh Haim
11038b52a31eSHanoh Haim    f1.flow_id=1;
11048b52a31eSHanoh Haim    f2.flow_id=2;
11058b52a31eSHanoh Haim    f3.flow_id=3;
11068b52a31eSHanoh Haim    f4.flow_id=4;
11078b52a31eSHanoh Haim    double time;
11088b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time),false);
11098b52a31eSHanoh Haim    my_tw.restart_timer(&f1.m_timer_handle,10.0);
11108b52a31eSHanoh Haim    my_tw.restart_timer(&f2.m_timer_handle,5.0);
11118b52a31eSHanoh Haim    my_tw.restart_timer(&f3.m_timer_handle,1.0);
11128b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time),true);
11138b52a31eSHanoh Haim    printf(" time %f \n",time);
11148b52a31eSHanoh Haim    EXPECT_EQ(time ,1.0);
11158b52a31eSHanoh Haim
11168b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time),true);
11178b52a31eSHanoh Haim    printf(" time %f \n",time);
11188b52a31eSHanoh Haim    EXPECT_EQ(time ,1.0);
11198b52a31eSHanoh Haim
11208b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time),true);
11218b52a31eSHanoh Haim    printf(" time %f \n",time);
11228b52a31eSHanoh Haim    EXPECT_EQ(time ,1.0);
11238b52a31eSHanoh Haim
11248b52a31eSHanoh Haim    EXPECT_EQ(my_tw.handle(),true);
11258b52a31eSHanoh Haim
11268b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time),true);
11278b52a31eSHanoh Haim    printf(" time %f \n",time);
11288b52a31eSHanoh Haim    EXPECT_EQ(time ,5.0);
11298b52a31eSHanoh Haim
11308b52a31eSHanoh Haim    EXPECT_EQ(my_tw.handle(),true);
11318b52a31eSHanoh Haim
11328b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time),true);
11338b52a31eSHanoh Haim    printf(" time %f \n",time);
11348b52a31eSHanoh Haim    EXPECT_EQ(time ,10.0);
11358b52a31eSHanoh Haim
11368b52a31eSHanoh Haim    EXPECT_EQ(my_tw.handle(),true);
11378b52a31eSHanoh Haim
11388b52a31eSHanoh Haim}
11398b52a31eSHanoh Haim
11408b52a31eSHanoh HaimTEST_F(timerwl, tw2) {
11418b52a31eSHanoh Haim    CTimerWheel  my_tw;
11428b52a31eSHanoh Haim
11438b52a31eSHanoh Haim    double mytime=0.1;
11448b52a31eSHanoh Haim    int i;
11458b52a31eSHanoh Haim    CTestFlow * af[100];
11468b52a31eSHanoh Haim
11478b52a31eSHanoh Haim    for (i=0; i<100; i++) {
11488b52a31eSHanoh Haim        CTestFlow * f=new CTestFlow();
11498b52a31eSHanoh Haim        af[i]=f;
11508b52a31eSHanoh Haim        f->flow_id=i;
11518b52a31eSHanoh Haim        my_tw.restart_timer(&f->m_timer_handle,mytime+10.0);
11528b52a31eSHanoh Haim    }
11538b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_alloc-my_tw.m_st_free,100);
11548b52a31eSHanoh Haim
11558b52a31eSHanoh Haim    my_tw.try_handle_events(mytime);
11568b52a31eSHanoh Haim
11578b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_alloc-my_tw.m_st_free,100);
11588b52a31eSHanoh Haim
11598b52a31eSHanoh Haim    for (i=0; i<100; i++) {
11608b52a31eSHanoh Haim        CTestFlow * f=af[i];
11618b52a31eSHanoh Haim        my_tw.stop_timer(&f->m_timer_handle);
11628b52a31eSHanoh Haim    }
11638b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_alloc-my_tw.m_st_free,100);
11648b52a31eSHanoh Haim
11658b52a31eSHanoh Haim    my_tw.try_handle_events(mytime);
11668b52a31eSHanoh Haim
11678b52a31eSHanoh Haim    /* expect to free all the object */
11688b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_alloc-my_tw.m_st_free,0);
11698b52a31eSHanoh Haim
11708b52a31eSHanoh Haim}
11718b52a31eSHanoh Haim
11728b52a31eSHanoh HaimTEST_F(timerwl, check_stop_timer) {
11738b52a31eSHanoh Haim
11748b52a31eSHanoh Haim    CTimerWheel  my_tw;
11758b52a31eSHanoh Haim
11768b52a31eSHanoh Haim
11778b52a31eSHanoh Haim    CTestFlow f1;
11788b52a31eSHanoh Haim    CTestFlow f2;
11798b52a31eSHanoh Haim    CTestFlow f3;
11808b52a31eSHanoh Haim    CTestFlow f4;
11818b52a31eSHanoh Haim
11828b52a31eSHanoh Haim    f1.flow_id=1;
11838b52a31eSHanoh Haim    f2.flow_id=2;
11848b52a31eSHanoh Haim    f3.flow_id=3;
11858b52a31eSHanoh Haim    f4.flow_id=4;
11868b52a31eSHanoh Haim    double time;
11878b52a31eSHanoh Haim    assert(my_tw.peek_top_time(time)==false);
11888b52a31eSHanoh Haim    my_tw.restart_timer(&f1.m_timer_handle,10.0);
11898b52a31eSHanoh Haim    my_tw.restart_timer(&f2.m_timer_handle,5.0);
11908b52a31eSHanoh Haim    my_tw.restart_timer(&f3.m_timer_handle,1.0);
11918b52a31eSHanoh Haim    my_tw.stop_timer(&f1.m_timer_handle);
11928b52a31eSHanoh Haim
11938b52a31eSHanoh Haim    assert(my_tw.peek_top_time(time)==true);
11948b52a31eSHanoh Haim    printf(" time %f \n",time);
11958b52a31eSHanoh Haim    EXPECT_EQ(time ,1.0);
11968b52a31eSHanoh Haim
11978b52a31eSHanoh Haim    assert(my_tw.peek_top_time(time)==true);
11988b52a31eSHanoh Haim    printf(" time %f \n",time);
11998b52a31eSHanoh Haim    EXPECT_EQ(time ,1.0);
12008b52a31eSHanoh Haim
12018b52a31eSHanoh Haim    assert(my_tw.peek_top_time(time)==true);
12028b52a31eSHanoh Haim    printf(" time %f \n",time);
12038b52a31eSHanoh Haim    EXPECT_EQ(time ,1.0);
12048b52a31eSHanoh Haim
12058b52a31eSHanoh Haim    assert(my_tw.handle());
12068b52a31eSHanoh Haim
12078b52a31eSHanoh Haim    assert(my_tw.peek_top_time(time)==true);
12088b52a31eSHanoh Haim    printf(" time %f \n",time);
12098b52a31eSHanoh Haim    EXPECT_EQ(time ,5.0);
12108b52a31eSHanoh Haim
12118b52a31eSHanoh Haim
12128b52a31eSHanoh Haim    assert(my_tw.handle());
12138b52a31eSHanoh Haim
12148b52a31eSHanoh Haim    EXPECT_EQ(my_tw.peek_top_time(time) ,false);
12158b52a31eSHanoh Haim    my_tw.Dump(stdout);
12168b52a31eSHanoh Haim}
12178b52a31eSHanoh Haim
12188b52a31eSHanoh Haim
12198b52a31eSHanoh Haimstatic int many_timers_flow_id=0;
12208b52a31eSHanoh Haim
12218b52a31eSHanoh Haimvoid  many_timers_flow_callback(CFlowTimerHandle * t){
12228b52a31eSHanoh Haim    CTestFlow * lp=(CTestFlow *)t->m_object;
12238b52a31eSHanoh Haim    assert(lp);
12248b52a31eSHanoh Haim    assert(t->m_id==0x1234);
12258b52a31eSHanoh Haim    assert(many_timers_flow_id==lp->flow_id);
12268b52a31eSHanoh Haim    many_timers_flow_id--;
12278b52a31eSHanoh Haim}
12288b52a31eSHanoh Haim
12298b52a31eSHanoh Haim
12308b52a31eSHanoh HaimTEST_F(timerwl, many_timers) {
12318b52a31eSHanoh Haim
12328b52a31eSHanoh Haim    CTimerWheel  my_tw;
12338b52a31eSHanoh Haim
1234cf0b463eSIdo Barnea    int i;
12358b52a31eSHanoh Haim    for (i=0; i<100; i++) {
12368b52a31eSHanoh Haim        CTestFlow * f= new CTestFlow();
12378b52a31eSHanoh Haim        f->m_timer_handle.m_callback=many_timers_flow_callback;
12388b52a31eSHanoh Haim        f->flow_id=(uint32_t)i;
12398b52a31eSHanoh Haim        my_tw.restart_timer(&f->m_timer_handle,100.0-(double)i);
12408b52a31eSHanoh Haim    }
12418b52a31eSHanoh Haim    many_timers_flow_id=99;
12428b52a31eSHanoh Haim
1243cf0b463eSIdo Barnea    double time;
12448b52a31eSHanoh Haim    double ex_time=1.0;
12458b52a31eSHanoh Haim    while (true) {
12468b52a31eSHanoh Haim        if ( my_tw.peek_top_time(time) ){
12478b52a31eSHanoh Haim            assert(time==ex_time);
12488b52a31eSHanoh Haim            ex_time+=1.0;
12498b52a31eSHanoh Haim            assert(my_tw.handle());
1250cf0b463eSIdo Barnea        }
1251cf0b463eSIdo Barnea        else{
1252cf0b463eSIdo Barnea            break;
1253cf0b463eSIdo Barnea        }
12548b52a31eSHanoh Haim    }
12558b52a31eSHanoh Haim
12568b52a31eSHanoh Haim    my_tw.Dump(stdout);
12578b52a31eSHanoh Haim
12588b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_handle ,100);
12598b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_alloc ,100);
12608b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_free ,100);
12618b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_start ,100);
1262cf0b463eSIdo Barnea
12638b52a31eSHanoh Haim}
12648b52a31eSHanoh Haim
12658b52a31eSHanoh Haimvoid  many_timers_stop_flow_callback(CFlowTimerHandle * t){
12668b52a31eSHanoh Haim    CTestFlow * lp=(CTestFlow *)t->m_object;
12678b52a31eSHanoh Haim    assert(lp);
12688b52a31eSHanoh Haim    assert(t->m_id==0x1234);
12698b52a31eSHanoh Haim    assert(0);
12708b52a31eSHanoh Haim}
12718b52a31eSHanoh Haim
12728b52a31eSHanoh HaimTEST_F(timerwl, many_timers_with_stop) {
12738b52a31eSHanoh Haim    CTimerWheel  my_tw;
12748b52a31eSHanoh Haim
12758b52a31eSHanoh Haim    int i;
12768b52a31eSHanoh Haim    for (i=0; i<100; i++) {
12778b52a31eSHanoh Haim        CTestFlow * f= new CTestFlow();
12788b52a31eSHanoh Haim        f->m_timer_handle.m_callback=many_timers_stop_flow_callback;
12798b52a31eSHanoh Haim        f->flow_id=(uint32_t)i;
12808b52a31eSHanoh Haim        my_tw.restart_timer(&f->m_timer_handle, 500.0 - (double)i);
12818b52a31eSHanoh Haim        my_tw.restart_timer(&f->m_timer_handle, 1000.0 - (double)i);
12828b52a31eSHanoh Haim        my_tw.restart_timer(&f->m_timer_handle, 100.0 - (double)i);
12838b52a31eSHanoh Haim        my_tw.stop_timer(&f->m_timer_handle);
12848b52a31eSHanoh Haim    }
12858b52a31eSHanoh Haim
12868b52a31eSHanoh Haim    double time;
12878b52a31eSHanoh Haim    while (true) {
12888b52a31eSHanoh Haim        if ( my_tw.peek_top_time(time) ){
12898b52a31eSHanoh Haim            assert(0);
12908b52a31eSHanoh Haim            assert(my_tw.handle());
12918b52a31eSHanoh Haim        }
12928b52a31eSHanoh Haim        else{
12938b52a31eSHanoh Haim            break;
12948b52a31eSHanoh Haim        }
12958b52a31eSHanoh Haim    }
12968b52a31eSHanoh Haim
12978b52a31eSHanoh Haim    my_tw.Dump(stdout);
12988b52a31eSHanoh Haim
12998b52a31eSHanoh Haim
13008b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_handle ,0);
13018b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_alloc-my_tw.m_st_free ,0);
13028b52a31eSHanoh Haim    EXPECT_EQ(my_tw.m_st_start ,300);
13038b52a31eSHanoh Haim}
13048b52a31eSHanoh Haim
13058b52a31eSHanoh Haim//////////////////////////////////////////////
1306cf0b463eSIdo Barneaclass rx_check : public trexTest {
13078b52a31eSHanoh Haim protected:
13088b52a31eSHanoh Haim  virtual void SetUp() {
1309cf0b463eSIdo Barnea      trexTest::SetUp();
13108b52a31eSHanoh Haim      m_rx_check.Create();
13118b52a31eSHanoh Haim  }
13128b52a31eSHanoh Haim  virtual void TearDown() {
13138b52a31eSHanoh Haim      m_rx_check.Delete();
13148b52a31eSHanoh Haim  }
13158b52a31eSHanoh Haimpublic:
13168b52a31eSHanoh Haim    RxCheckManager m_rx_check;
13178b52a31eSHanoh Haim};
13188b52a31eSHanoh Haim
13198b52a31eSHanoh Haim
13208b52a31eSHanoh HaimTEST_F(rx_check, rx_check_normal) {
13218b52a31eSHanoh Haim    int i;
13228b52a31eSHanoh Haim
13238b52a31eSHanoh Haim    for (i=0; i<10; i++) {
13248b52a31eSHanoh Haim        CRx_check_header rxh;
13254ad6ed17SHanoh Haim        rxh.clean();
13264ad6ed17SHanoh Haim
13278b52a31eSHanoh Haim        rxh.m_option_type=RX_CHECK_V4_OPT_TYPE;
13288b52a31eSHanoh Haim        rxh.m_option_len=RX_CHECK_V4_OPT_LEN;
13298b52a31eSHanoh Haim        rxh.m_time_stamp=0;
13308b52a31eSHanoh Haim        rxh.m_magic=RX_CHECK_MAGIC;
13318b52a31eSHanoh Haim        rxh.m_aging_sec=10;
13328b52a31eSHanoh Haim        rxh.m_pkt_id=i;
13338b52a31eSHanoh Haim        rxh.m_flow_size=10;
13348b52a31eSHanoh Haim
13358b52a31eSHanoh Haim        rxh.m_flow_id=7;
13368b52a31eSHanoh Haim        rxh.set_dir(0);
13378b52a31eSHanoh Haim        rxh.set_both_dir(0);
13388b52a31eSHanoh Haim
13398b52a31eSHanoh Haim        m_rx_check.handle_packet(&rxh);
13408b52a31eSHanoh Haim    }
13418b52a31eSHanoh Haim
13428b52a31eSHanoh Haim    EXPECT_EQ(m_rx_check.m_stats.get_total_err(),0);
13438b52a31eSHanoh Haim    EXPECT_EQ(m_rx_check.m_stats.m_add,1);
13448b52a31eSHanoh Haim    EXPECT_EQ(m_rx_check.m_stats.m_remove,1);
13458b52a31eSHanoh Haim    m_rx_check.Dump(stdout);
13468b52a31eSHanoh Haim}
13478b52a31eSHanoh Haim
13488b52a31eSHanoh Haim
13498b52a31eSHanoh HaimTEST_F(rx_check, rx_check_drop) {
13508b52a31eSHanoh Haim
13518b52a31eSHanoh Haim    int i;
13528b52a31eSHanoh Haim
13538b52a31eSHanoh Haim    for (i=0; i<10; i++) {
13548b52a31eSHanoh Haim        CRx_check_header rxh;
13554ad6ed17SHanoh Haim        rxh.clean();
13564ad6ed17SHanoh Haim
13578b52a31eSHanoh Haim        rxh.m_option_type=RX_CHECK_V4_OPT_TYPE;
13588b52a31eSHanoh Haim        rxh.m_option_len=RX_CHECK_V4_OPT_LEN;
13598b52a31eSHanoh Haim        rxh.m_time_stamp=0;
13608b52a31eSHanoh Haim        rxh.m_magic=RX_CHECK_MAGIC;
13618b52a31eSHanoh Haim        rxh.m_aging_sec=10;
13628b52a31eSHanoh Haim
13638b52a31eSHanoh Haim        if (i==4) {
13648b52a31eSHanoh Haim            /* drop packet 4 */
13658b52a31eSHanoh Haim            continue;
13668b52a31eSHanoh Haim        }
13678b52a31eSHanoh Haim        rxh.m_pkt_id=i;
13688b52a31eSHanoh Haim
13698b52a31eSHanoh Haim        rxh.m_flow_size=10;
13708b52a31eSHanoh Haim
13718b52a31eSHanoh Haim        rxh.set_dir(0);
13728b52a31eSHanoh Haim        rxh.set_both_dir(0);
13738b52a31eSHanoh Haim
13748b52a31eSHanoh Haim        rxh.m_flow_id=7;
13758b52a31eSHanoh Haim
13768b52a31eSHanoh Haim        rxh.m_flags=0;
13778b52a31eSHanoh Haim        m_rx_check.handle_packet(&rxh);
13788b52a31eSHanoh Haim    }
13798b52a31eSHanoh Haim    m_rx_check.tw_drain();
13808b52a31eSHanoh Haim    EXPECT_EQ(m_rx_check.m_stats.m_err_oo_late,1);
13818b52a31eSHanoh Haim    EXPECT_EQ(m_rx_check.m_stats.m_add,1);
13828b52a31eSHanoh Haim    EXPECT_EQ(m_rx_check.m_stats.m_remove,1);
13838b52a31eSHanoh Haim    m_rx_check.Dump(stdout);
13848b52a31eSHanoh Haim}
13858b52a31eSHanoh Haim
13868b52a31eSHanoh HaimTEST_F(rx_check, rx_check_ooo) {
13878b52a31eSHanoh Haim
1388cf0b463eSIdo Barnea    m_rx_check.Create();
1389cf0b463eSIdo Barnea    int i;
13908b52a31eSHanoh Haim
1391cf0b463eSIdo Barnea    for (i=0; i<10; i++) {
1392cf0b463eSIdo Barnea        CRx_check_header rxh;
13934ad6ed17SHanoh Haim        rxh.clean();
13944ad6ed17SHanoh Haim
13954ad6ed17SHanoh Haim        rxh.m_option_type=RX_CHECK_V4_OPT_TYPE;
13964ad6ed17SHanoh Haim        rxh.m_option_len=RX_CHECK_V4_OPT_LEN;
1397cf0b463eSIdo Barnea        rxh.m_time_stamp=0;
1398cf0b463eSIdo Barnea        rxh.m_magic=RX_CHECK_MAGIC;
13998b52a31eSHanoh Haim        rxh.m_aging_sec=10;
14008b52a31eSHanoh Haim
1401