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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
25 #include <sys/types.h>
31 printf (APP_NAME ":%s:%d: ", __func__, __LINE__); \
32 printf (__VA_ARGS__); \
43 printf ("INFO: " __VA_ARGS__); \
48 /* maximum tx/rx memif buffers */
49 #define MAX_MEMIF_BUFS 256
51 struct memif_connection;
53 typedef int (memif_packet_handler_t) (struct memif_connection *conn);
55 typedef int (packet_generator_t) (struct memif_connection *c,
58 typedef struct memif_connection
61 /* memif conenction handle */
62 memif_conn_handle_t conn;
64 /* transmit queue id */
67 memif_buffer_t *tx_bufs;
68 /* allocated tx buffers counter */
69 /* number of tx buffers pointing to shared memory */
72 memif_buffer_t *rx_bufs;
73 /* allcoated rx buffers counter */
74 /* number of rx buffers pointing to shared memory */
76 memif_packet_handler_t *packet_handler;
77 /* interface ip address */
79 /* interface hw address */
83 void print_version ();
85 int parse_ip4 (const char *input, uint8_t out[4]);
87 int parse_mac (const char *input, uint8_t out[6]);
89 void alloc_memif_buffers (memif_connection_t *c);
91 void free_memif_buffers (memif_connection_t *c);
93 void print_memif_details (memif_connection_t *c);
95 void print_memif_rx_ring_details (memif_connection_t *c, uint16_t qid);
97 void print_memif_tx_ring_details (memif_connection_t *c, uint16_t qid);
99 int send_packets (memif_connection_t *conn, uint16_t qid,
100 packet_generator_t *gen, uint32_t num_pkts,
101 uint16_t max_pkt_size);
103 /* Expect packets smaller than 2048b */
104 int responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid);
106 /* Expect packets smaller than 2048b */
107 int responder_zero_copy (memif_conn_handle_t conn, void *private_ctx,
110 /* reply with the same data */
111 int basic_packet_handler (memif_connection_t *conn);
113 /* ICMPv4 and ARP handler */
114 int icmp_packet_handler (memif_connection_t *conn);
116 #endif /* COMMON_H */