blob: 3538e39e23b23906b2408f4e74d5e978d4f3777e [file] [log] [blame]
Jakub Grajciare74c04f2021-01-04 11:28:33 +01001/*
2 *------------------------------------------------------------------
3 * Copyright (c) 2020 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
16 */
17
18#ifndef _COMMON_H_
19#define _COMMON_H_
20
21#include <libmemif.h>
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25#include <sys/types.h>
26
27#ifdef ICMP_DBG
28#define DBG(...) \
29 do \
30 { \
31 printf (APP_NAME ":%s:%d: ", __func__, __LINE__); \
32 printf (__VA_ARGS__); \
33 printf ("\n"); \
34 } \
35 while (0)
36#else
37#define DBG(...)
38#endif
39
40#define INFO(...) \
41 do \
42 { \
43 printf ("INFO: " __VA_ARGS__); \
44 printf ("\n"); \
45 } \
46 while (0)
47
48/* maximum tx/rx memif buffers */
49#define MAX_MEMIF_BUFS 256
50
51struct memif_connection;
52
53typedef int (memif_packet_handler_t) (struct memif_connection *conn);
54
55typedef int (packet_generator_t) (struct memif_connection *c,
56 uint16_t num_pkts);
57
58typedef struct memif_connection
59{
60 uint16_t index;
61 /* memif conenction handle */
62 memif_conn_handle_t conn;
63 uint8_t is_connected;
64 /* transmit queue id */
65 uint16_t tx_qid;
66 /* tx buffers */
67 memif_buffer_t *tx_bufs;
68 /* allocated tx buffers counter */
69 /* number of tx buffers pointing to shared memory */
70 uint16_t tx_buf_num;
71 /* rx buffers */
72 memif_buffer_t *rx_bufs;
73 /* allcoated rx buffers counter */
74 /* number of rx buffers pointing to shared memory */
75 uint16_t rx_buf_num;
76 memif_packet_handler_t *packet_handler;
77 /* interface ip address */
78 uint8_t ip_addr[4];
79 /* interface hw address */
80 uint8_t hw_addr[6];
Mohsin Kazmi6e284ef2022-07-27 15:04:01 +000081 /* buffer size */
82 uint16_t buffer_size;
83 /* headroom size */
84 uint16_t headroom_size;
Jakub Grajciare74c04f2021-01-04 11:28:33 +010085} memif_connection_t;
86
87void print_version ();
88
89int parse_ip4 (const char *input, uint8_t out[4]);
90
91int parse_mac (const char *input, uint8_t out[6]);
92
93void alloc_memif_buffers (memif_connection_t *c);
94
95void free_memif_buffers (memif_connection_t *c);
96
97void print_memif_details (memif_connection_t *c);
98
99void print_memif_rx_ring_details (memif_connection_t *c, uint16_t qid);
100
101void print_memif_tx_ring_details (memif_connection_t *c, uint16_t qid);
102
103int send_packets (memif_connection_t *conn, uint16_t qid,
104 packet_generator_t *gen, uint32_t num_pkts,
105 uint16_t max_pkt_size);
106
107/* Expect packets smaller than 2048b */
108int responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid);
109
110/* Expect packets smaller than 2048b */
111int responder_zero_copy (memif_conn_handle_t conn, void *private_ctx,
112 uint16_t qid);
113
114/* reply with the same data */
115int basic_packet_handler (memif_connection_t *conn);
116
117/* ICMPv4 and ARP handler */
118int icmp_packet_handler (memif_connection_t *conn);
119
Mohsin Kazmi6e284ef2022-07-27 15:04:01 +0000120#endif /* COMMON_H */