trex_stateless_dp_core.cpp revision 51ad0781
1/*
2 Itay Marom
3 Cisco Systems, Inc.
4*/
5
6/*
7Copyright (c) 2015-2015 Cisco Systems, Inc.
8
9Licensed under the Apache License, Version 2.0 (the "License");
10you may not use this file except in compliance with the License.
11You may obtain a copy of the License at
12
13    http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing, software
16distributed under the License is distributed on an "AS IS" BASIS,
17WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18See the License for the specific language governing permissions and
19limitations under the License.
20*/
21
22#include <trex_stateless_dp_core.h>
23#include <stdio.h>
24#include <unistd.h>
25#include <trex_stateless.h>
26
27#include <bp_sim.h>
28
29#ifndef TREX_RPC_MOCK_SERVER
30
31// DPDK c++ issue
32#define UINT8_MAX 255
33#define UINT16_MAX 0xFFFF
34// DPDK c++ issue
35#endif
36
37#include <rte_ethdev.h>
38#include "mbuf.h"
39
40/**
41 * TEST
42 *
43 */
44static const uint8_t udp_pkt[]={
45    0x00,0x00,0x00,0x01,0x00,0x00,
46    0x00,0x00,0x00,0x01,0x00,0x00,
47    0x08,0x00,
48
49    0x45,0x00,0x00,0x81,
50    0xaf,0x7e,0x00,0x00,
51    0x12,0x11,0xd9,0x23,
52    0x01,0x01,0x01,0x01,
53    0x3d,0xad,0x72,0x1b,
54
55    0x11,0x11,
56    0x11,0x11,
57
58    0x00,0x6d,
59	0x00,0x00,
60
61    0x64,0x31,0x3a,0x61,
62    0x64,0x32,0x3a,0x69,0x64,
63    0x32,0x30,0x3a,0xd0,0x0e,
64    0xa1,0x4b,0x7b,0xbd,0xbd,
65    0x16,0xc6,0xdb,0xc4,0xbb,0x43,
66    0xf9,0x4b,0x51,0x68,0x33,0x72,
67    0x20,0x39,0x3a,0x69,0x6e,0x66,0x6f,
68    0x5f,0x68,0x61,0x73,0x68,0x32,0x30,0x3a,0xee,0xc6,0xa3,
69    0xd3,0x13,0xa8,0x43,0x06,0x03,0xd8,0x9e,0x3f,0x67,0x6f,
70    0xe7,0x0a,0xfd,0x18,0x13,0x8d,0x65,0x31,0x3a,0x71,0x39,
71    0x3a,0x67,0x65,0x74,0x5f,0x70,0x65,0x65,0x72,0x73,0x31,
72    0x3a,0x74,0x38,0x3a,0x3d,0xeb,0x0c,0xbf,0x0d,0x6a,0x0d,
73    0xa5,0x31,0x3a,0x79,0x31,0x3a,0x71,0x65,0x87,0xa6,0x7d,
74    0xe7
75};
76
77static int
78test_inject_pkt(uint8_t *pkt, uint32_t pkt_size) {
79
80    #ifndef TREX_RPC_MOCK_SERVER
81        rte_mempool_t * mp= CGlobalInfo::m_mem_pool[0].m_big_mbuf_pool ;
82    #else
83        rte_mempool_t * mp = NULL;
84    #endif
85
86    rte_mbuf_t *m = rte_pktmbuf_alloc(mp);
87    if ( unlikely(m==0) )  {
88        printf("ERROR no packets \n");
89        return (-1);
90    }
91    char *p = rte_pktmbuf_append(m, pkt_size);
92    assert(p);
93    /* set pkt data */
94    memcpy(p,pkt,pkt_size);
95
96    rte_mbuf_t *tx_pkts[32];
97    tx_pkts[0] = m;
98    uint8_t nb_pkts = 1;
99    uint16_t ret = rte_eth_tx_burst(0, 0, tx_pkts, nb_pkts);
100    (void)ret;
101    rte_pktmbuf_free(m);
102
103    return (0);
104}
105
106static int
107test_inject_udp_pkt(){
108    return (test_inject_pkt((uint8_t*)udp_pkt,sizeof(udp_pkt)));
109}
110
111void
112TrexStatelessDpCore::test_inject_dummy_pkt() {
113    test_inject_udp_pkt();
114}
115
116/***************************
117 * DP core
118 *
119 **************************/
120TrexStatelessDpCore::TrexStatelessDpCore(uint8_t core_id) : m_core_id(core_id) {
121}
122
123/**
124 * main function for DP core
125 *
126 */
127void
128TrexStatelessDpCore::run() {
129    printf("\nOn DP core %d\n", m_core_id);
130    while (true) {
131        test_inject_dummy_pkt();
132        rte_pause();
133    }
134}
135
136