summaryrefslogtreecommitdiff
path: root/src/vf/spp_vf.h
blob: 10742bc5cf070b8db38eaa927f0b0d0adef94854 (plain)
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/*
 *   BSD LICENSE
 *
 *   Copyright(c) 2017 Nippon Telegraph and Telephone Corporation
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Nippon Telegraph and Telephone Corporation
 *       nor the names of its contributors may be used to endorse or
 *       promote products derived from this software without specific
 *       prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __SPP_VF_H__
#define __SPP_VF_H__

/**
 * @file
 * SPP_VF main
 *
 * Main function of spp_vf.
 * This provides the function for initializing and starting the threads.
 */

#include "common.h"

/** Identifier string for each component (status command) @{*/
#define SPP_TYPE_CLASSIFIER_MAC_STR "classifier_mac"
#define SPP_TYPE_MERGE_STR          "merge"
#define SPP_TYPE_FORWARD_STR        "forward"
#define SPP_TYPE_UNUSE_STR          "unuse"
/**@}*/

/** Identifier string for each interface @{*/
#define SPP_IFTYPE_NIC_STR   "phy"
#define SPP_IFTYPE_VHOST_STR "vhost"
#define SPP_IFTYPE_RING_STR  "ring"
/**@}*/

/** The max number of client ID */
#define SPP_CLIENT_MAX    128

/** The max number of buffer for management */
#define SPP_INFO_AREA_MAX 2

/** The length of shortest character string */
#define SPP_MIN_STR_LEN   32

/** The length of NAME string */
#define SPP_NAME_STR_LEN  128

/** Update wait timer (micro sec) */
#define SPP_CHANGE_UPDATE_INTERVAL 10

/** Character sting for default port of classifier */
#define SPP_DEFAULT_CLASSIFIED_SPEC_STR     "default"

/** Character sting for default MAC address of classifier */
#define SPP_DEFAULT_CLASSIFIED_DMY_ADDR_STR "00:00:00:00:00:01"

/** Value for default MAC address of classifier */
#define SPP_DEFAULT_CLASSIFIED_DMY_ADDR     0x010000000000

/**
 * State on component
 */
enum spp_core_status {
	SPP_CORE_UNUSE,        /**< Not used */
	SPP_CORE_STOP,         /**< Stopped */
	SPP_CORE_IDLE,         /**< Idling */
	SPP_CORE_FORWARD,      /**< Forwarding  */
	SPP_CORE_STOP_REQUEST, /**< Request stopping */
	SPP_CORE_IDLE_REQUEST  /**< Request idling */
};

/**
 * Process type for each component
 */
enum spp_component_type {
	SPP_COMPONENT_UNUSE,          /**< Not used */
	SPP_COMPONENT_CLASSIFIER_MAC, /**< Classifier_mac */
	SPP_COMPONENT_MERGE,          /**< Merger */
	SPP_COMPONENT_FORWARD,        /**< Forwarder */
};

/**
 * Classifier Type
 */
enum spp_classifier_type {
	SPP_CLASSIFIER_TYPE_NONE, /**< Type none */
	SPP_CLASSIFIER_TYPE_MAC   /**< MAC address */
};

/**
 * API Return value
 */
enum spp_return_value {
	SPP_RET_OK = 0,  /**< succeeded */
	SPP_RET_NG = -1, /**< failed */
};

/** Port type (rx or tx) */
enum spp_port_rxtx {
	SPP_PORT_RXTX_NONE, /**< none */
	SPP_PORT_RXTX_RX,   /**< rx port */
	SPP_PORT_RXTX_TX,   /**< tx port */
	SPP_PORT_RXTX_ALL,  /**< rx/tx port */
};

/** command setting type */
enum spp_command_action {
	SPP_CMD_ACTION_NONE,  /**< none */
	SPP_CMD_ACTION_START, /**< start */
	SPP_CMD_ACTION_STOP,  /**< stop */
	SPP_CMD_ACTION_ADD,   /**< add */
	SPP_CMD_ACTION_DEL,   /**< delete */
};

/**
 * Interface information structure
 */
struct spp_port_index {
	enum port_type  iface_type; /**< Interface type (phy/vhost/ring) */
	int             iface_no;   /**< Interface number */
};

/**
 * Port info
 */
struct spp_port_info {
	enum port_type iface_type; /**< Interface type (phy/vhost/ring) */
	int            iface_no;   /**< Interface number */
	int            dpdk_port;  /**< DPDK port number */
	uint64_t       mac_addr;   /**< Mac address for classifying */
	char           mac_addr_str[SPP_MIN_STR_LEN]; /**< Mac address */
};

/**
 * Component info
 */
struct spp_component_info {
	char name[SPP_NAME_STR_LEN];    /**< Component name */
	enum spp_component_type type;   /**< Component type */
	unsigned int lcore_id;          /**< Logical core ID for component */
	int component_id;               /**< Component ID */
	int num_rx_port;                /**< The number of rx ports */
	int num_tx_port;                /**< The number of tx ports */
	struct spp_port_info *rx_ports[RTE_MAX_ETHPORTS];
					/**< Array of pointers to rx ports */
	struct spp_port_info *tx_ports[RTE_MAX_ETHPORTS];
					/**< Array of pointers to tx ports */
};

/**
 * Get client ID
 *
 * @return Client ID(0~127)
 */
int spp_get_client_id(void);

/**
 * Update Classifier_table
 *
 * @param action
 *  Action identifier (add or del)
 * @param type
 *  Classify type (currently only for mac)
 * @param data
 *  Value to be classified
 * @param port
 *  Destination port type and number
 *
 * @retval SPP_RET_OK succeeded.
 * @retval SPP_RET_NG failed.
 */
int spp_update_classifier_table(
		enum spp_command_action action,
		enum spp_classifier_type type,
		const char *data,
		const struct spp_port_index *port);

/**
 * Update component
 *
 * @param action
 *  Action identifier (start or stop)
 * @param name
 *  Component name
 * @param lcore_id
 *  Logical core number
 * @param type
 *  Component type
 *
 * @retval SPP_RET_OK succeeded.
 * @retval SPP_RET_NG failed.
 */
int spp_update_component(
		enum spp_command_action action,
		const char *name, unsigned int lcore_id,
		enum spp_component_type type);

/**
 * Update port
 *
 * @param action
 *  Action identifier (add or del)
 * @param port
 *  Port type and number
 * @param rxtx
 *  rx/tx identifier
 * @param name
 *  Attached component name
 *
 * @retval SPP_RET_OK succeeded.
 * @retval SPP_RET_NG failed.
 */
int spp_update_port(
		enum spp_command_action action,
		const struct spp_port_index *port,
		enum spp_port_rxtx rxtx,
		const char *name);

/**
 * Flush SPP component
 *
 * @retval SPP_RET_OK succeeded.
 * @retval SPP_RET_NG failed.
 */
int spp_flush(void);

/**
 * Cancel data that is not flushing
 */
void spp_cancel(void);

/** definition of iterated core element procedure function */
struct spp_iterate_core_params;
typedef int (*spp_iterate_core_element_proc)(
		struct spp_iterate_core_params *params,
		const unsigned int lcore_id,
		const char *name,
		const char *type,
		const int num_rx,
		const struct spp_port_index *rx_ports,
		const int num_tx,
		const struct spp_port_index *tx_ports);

/** iterate core information parameters */
struct spp_iterate_core_params {
	/** Output buffer */
	char *output;

	/** The function for creating core information */
	spp_iterate_core_element_proc element_proc;
};

/**
 * Iterate core information
 *
 * @param params
 *  The pointer to struct spp_iterate_core_params.@n
 *  The value for generating core information (status command).
 *
 * @retval SPP_RET_OK succeeded.
 * @retval SPP_RET_NG failed.
 */
int spp_iterate_core_info(struct spp_iterate_core_params *params);

/** definition of iterated classifier element procedure function */
struct spp_iterate_classifier_table_params;
typedef int (*spp_iterate_classifier_element_proc)(
		struct spp_iterate_classifier_table_params *params,
		enum spp_classifier_type type,
		const char *data,
		const struct spp_port_index *port);

/** iterate classifier table parameters */
struct spp_iterate_classifier_table_params {
	void *output;
	spp_iterate_classifier_element_proc element_proc;
};

/**
 * Iterate Classifier_table
 *
 * @param params
 *  The pointer to struct spp_iterate_classifier_table_params.@n
 *  The value for generating classifier table.
 *
 * @retval SPP_RET_OK succeeded.
 * @retval SPP_RET_NG failed.
 */
int spp_iterate_classifier_table(
		struct spp_iterate_classifier_table_params *params);

/**
 * Get core status
 *
 * @param lcore_id
 *  Logical core ID.
 *
 * @return
 *  Status of specified logical core.
 */
enum spp_core_status spp_get_core_status(unsigned int lcore_id);

/**
 * Get component type of target core
 *
 * @param lcore_id
 *  Logical core ID.
 *
 * @return
 *  Type of component executed on specified logical core
 */
enum spp_component_type spp_get_component_type(unsigned int lcore_id);

/**
 * Get component type being updated on target core
 *
 * @param lcore_id
 *  Logical core ID.
 *
 * @return
 *  Type of component that will be executed on
 *  specified logical core after update.
 */
enum spp_component_type spp_get_component_type_update(unsigned int lcore_id);

/**
 * Get core ID of target component
 *
 * @param component_id
 *  unique component ID.
 *
 * @return
 *  Logical core id of specified component.
 */
unsigned int spp_get_component_core(int component_id);

/**
 * Check core index change
 *
 * @param lcore_id
 *  Logical core ID.
 *
 * @return
 *  True if index has changed.
 */
int spp_check_core_index(unsigned int lcore_id);

/**
 * Get name matching component ID
 *
 * @param name
 *  Component name.
 *
 * @retval 0~127      Component ID.
 * @retval SPP_RET_NG failed.
 */
int spp_get_component_id(const char *name);

/**
 * Check mac address used on the port for registering or removing
 *
 * @param mac_addr
 *  Mac address to be validated.
 * @param iface_type
 *  Interface to be validated.
 * @param iface_no
 *  Interface number to be validated.
 *
 * @return
 *  True if target MAC address matches MAC address of port.
 */
int spp_check_mac_used_port(
		uint64_t mac_addr,
		enum port_type iface_type,
		int iface_no);

/**
 * Check if port has been added.
 *
 * @param iface_type
 *  Interface to be validated.
 * @param iface_no
 *  Interface number to be validated.
 *
 * @return
 *  True if port has been added.
 */
int spp_check_added_port(enum port_type iface_type, int iface_no);

/**
 * Check if port has been flushed.
 *
 * @param iface_type
 *  Interface to be validated.
 * @param iface_no
 *  Interface number to be validated.
 *
 * @return
 *  True if port has been flushed.
 */
int spp_check_flush_port(enum port_type iface_type, int iface_no);

/**
 * Check if component is using port.
 *
 * @param iface_type
 *  Interface type to be validated.
 * @param iface_no
 *  Interface number to be validated.
 * @param rxtx
 *  tx/rx type to be validated.
 *
 * @retval 0~127      match component ID
 * @retval SPP_RET_NG failed.
 */
int spp_check_used_port(
		enum port_type iface_type,
		int iface_no,
		enum spp_port_rxtx rxtx);

/**
 * Change mac address string to int64
 *
 * @param mac
 *  Character string of MAC address to be converted.
 *
 * @retval 0< int64 that store mac address
 * @retval -1
 */
int64_t spp_change_mac_str_to_int64(const char *mac);

/**
 * Extract if-type/if-number from port string
 *
 * @param port
 *  Character string expressing the port, e.g. "phy:0","ring:1"
 * @param iface_type
 *  Interface type obtained from port.
 * @param iface_no
 *  Interface number obtained from port.
 *
 * @retval 0  succeeded.
 * @retval -1 failed.
 */
int spp_get_iface_index(
		const char *port,
		enum port_type *iface_type,
		int *iface_no);

/**
 * Format port string form if-type/if-number
 *
 * @param port
 *  Character string expressing the port, e.g. "phy:0","ring:1"
 * @param iface_type
 *  Interface type.
 * @param iface_no
 *  Interface number.
 *
 * @retval 0  succeeded.
 * @retval -1 failed.
 */
int spp_format_port_string(char *port, enum port_type iface_type, int iface_no);

/**
 * Change component type from string to type value.
 *
 * @param type_str
 *  Name string for each component
 *
 * @return
 *  Component type corresponding to type_str.
 */
enum spp_component_type spp_change_component_type(const char *type_str);

#endif /* __SPP_VF_H__ */