forked from cisco-system-traffic-generator/trex-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrex_platform.h
272 lines (188 loc) · 7.3 KB
/
trex_platform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#ifndef TREX_PLATFORM_H
#define TREX_PLATFORM_H
/*
Hanoh Haim
Cisco Systems, Inc.
*/
/*
Copyright (c) 2015-2016 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "trex_defs.h"
typedef uint8_t socket_id_t;
typedef uint8_t port_id_t;
/* the real phsical thread id */
typedef uint8_t physical_thread_id_t;
typedef uint8_t virtual_thread_id_t;
class CPlatformCoresYamlInfo;
/*
virtual thread 0 (v0)- is always the master
for 2 dual ports ( 2x2 =4 ports) the virtual thread looks like that
-----------------
DEFAULT:
-----------------
(0,1) (2,3)
dual-if0 dual-if-1
v1 v2
v3 v4
v5 v6
v7 v8
rx is v9
*/
class CPlatformSocketInfoBase {
public:
/* sockets API */
/* is socket enabled */
virtual bool is_sockets_enable(socket_id_t socket)=0;
/* number of main active sockets. socket #0 is always used */
virtual socket_id_t max_num_active_sockets()=0;
virtual ~CPlatformSocketInfoBase() {}
public:
/* which socket to allocate memory to each port */
virtual socket_id_t port_to_socket(port_id_t port)=0;
public:
/* this is from CLI, number of thread per dual port */
virtual void set_number_of_threads_per_ports(uint8_t num_threads)=0;
virtual void set_rx_thread_is_enabled(bool enable)=0;
virtual void set_number_of_dual_ports(uint8_t num_dual_ports)=0;
virtual bool sanity_check()=0;
/* return the core list */
virtual void get_cores_list(char *)=0;
virtual void get_cores_list_lowend(char *)=0;
/* virtual thread_id is always from 1..number of threads virtual */
virtual virtual_thread_id_t thread_phy_to_virt(physical_thread_id_t phy_id)=0;
/* return the map betwean virtual to phy id */
virtual physical_thread_id_t thread_virt_to_phy(virtual_thread_id_t virt_id)=0;
virtual physical_thread_id_t get_master_phy_id() = 0;
virtual bool thread_phy_is_rx(physical_thread_id_t phy_id)=0;
virtual void dump(FILE *fd)=0;
bool thread_phy_is_master(physical_thread_id_t phy_id) {
return (get_master_phy_id() == phy_id);
}
};
class CPlatformSocketInfoNoConfig : public CPlatformSocketInfoBase {
public:
CPlatformSocketInfoNoConfig(){
m_dual_if=0;
m_threads_per_dual_if=0;
m_rx_is_enabled=false;
}
/* is socket enabled */
bool is_sockets_enable(socket_id_t socket);
/* number of main active sockets. socket #0 is always used */
socket_id_t max_num_active_sockets();
public:
/* which socket to allocate memory to each port */
socket_id_t port_to_socket(port_id_t port);
public:
/* this is from CLI, number of thread per dual port */
void set_number_of_threads_per_ports(uint8_t num_threads);
void set_rx_thread_is_enabled(bool enable);
void set_number_of_dual_ports(uint8_t num_dual_ports);
bool sanity_check();
/* return the core list */
void get_cores_list(char *);
void get_cores_list_lowend(char *);
uint32_t get_cores_count(void);
/* virtual thread_id is always from 1..number of threads virtual */
virtual_thread_id_t thread_phy_to_virt(physical_thread_id_t phy_id);
/* return the map betwean virtual to phy id */
physical_thread_id_t thread_virt_to_phy(virtual_thread_id_t virt_id);
physical_thread_id_t get_master_phy_id();
bool thread_phy_is_rx(physical_thread_id_t phy_id);
virtual void dump(FILE *fd);
private:
uint32_t m_dual_if;
uint32_t m_threads_per_dual_if;
bool m_rx_is_enabled;
};
/* there is a configuration file */
class CPlatformSocketInfoConfig : public CPlatformSocketInfoBase {
public:
bool Create(CPlatformCoresYamlInfo * platform);
void Delete();
/* is socket enabled */
bool is_sockets_enable(socket_id_t socket);
/* number of main active sockets. socket #0 is always used */
socket_id_t max_num_active_sockets();
public:
/* which socket to allocate memory to each port */
socket_id_t port_to_socket(port_id_t port);
public:
/* this is from CLI, number of thread per dual port */
void set_number_of_threads_per_ports(uint8_t num_threads);
void set_rx_thread_is_enabled(bool enable);
void set_number_of_dual_ports(uint8_t num_dual_ports);
bool sanity_check();
/* return the core list */
void get_cores_list(char *);
void get_cores_list_lowend(char *);
/* virtual thread_id is always from 1..number of threads virtual */
virtual_thread_id_t thread_phy_to_virt(physical_thread_id_t phy_id);
/* return the map betwean virtual to phy id */
physical_thread_id_t thread_virt_to_phy(virtual_thread_id_t virt_id);
physical_thread_id_t get_master_phy_id();
bool thread_phy_is_rx(physical_thread_id_t phy_id);
public:
virtual void dump(FILE *fd);
private:
void reset();
bool init();
private:
bool m_sockets_enable[MAX_SOCKETS_SUPPORTED];
uint32_t m_sockets_enabled;
socket_id_t m_socket_per_dual_if[(TREX_MAX_PORTS >> 1)];
uint32_t m_max_threads_per_dual_if;
uint32_t m_num_dual_if;
uint32_t m_threads_per_dual_if;
bool m_rx_is_enabled;
uint8_t m_thread_virt_to_phy[MAX_THREADS_SUPPORTED];
uint8_t m_thread_phy_to_virtual[MAX_THREADS_SUPPORTED];
CPlatformCoresYamlInfo * m_platform;
};
class CPlatformSocketInfo {
public:
bool Create(CPlatformCoresYamlInfo * platform);
void Delete();
public:
/* sockets API */
/* is socket enabled */
bool is_sockets_enable(socket_id_t socket);
/* number of main active sockets. socket #0 is always used */
socket_id_t max_num_active_sockets();
public:
/* which socket to allocate memory to each port */
socket_id_t port_to_socket(port_id_t port);
public:
/* this is from CLI, number of thread per dual port */
void set_number_of_threads_per_ports(uint8_t num_threads);
void set_rx_thread_is_enabled(bool enable);
void set_number_of_dual_ports(uint8_t num_dual_ports);
bool sanity_check();
/* return the core list */
void get_cores_list(char *);
void get_cores_list_lowend(char *);
/* virtual thread_id is always from 1..number of threads virtual */
virtual_thread_id_t thread_phy_to_virt(physical_thread_id_t phy_id);
/* return the map betwean virtual to phy id */
physical_thread_id_t thread_virt_to_phy(virtual_thread_id_t virt_id);
bool thread_phy_is_master(physical_thread_id_t phy_id);
physical_thread_id_t get_master_phy_id();
bool thread_phy_is_rx(physical_thread_id_t phy_id);
void dump(FILE *fd);
private:
CPlatformSocketInfoBase * m_obj;
CPlatformCoresYamlInfo * m_platform;
};
#endif