Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 51 | struct memif_connection; |
| 52 | |
| 53 | typedef int (memif_packet_handler_t) (struct memif_connection *conn); |
| 54 | |
| 55 | typedef int (packet_generator_t) (struct memif_connection *c, |
| 56 | uint16_t num_pkts); |
| 57 | |
| 58 | typedef 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]; |
| 81 | } memif_connection_t; |
| 82 | |
| 83 | void print_version (); |
| 84 | |
| 85 | int parse_ip4 (const char *input, uint8_t out[4]); |
| 86 | |
| 87 | int parse_mac (const char *input, uint8_t out[6]); |
| 88 | |
| 89 | void alloc_memif_buffers (memif_connection_t *c); |
| 90 | |
| 91 | void free_memif_buffers (memif_connection_t *c); |
| 92 | |
| 93 | void print_memif_details (memif_connection_t *c); |
| 94 | |
| 95 | void print_memif_rx_ring_details (memif_connection_t *c, uint16_t qid); |
| 96 | |
| 97 | void print_memif_tx_ring_details (memif_connection_t *c, uint16_t qid); |
| 98 | |
| 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); |
| 102 | |
| 103 | /* Expect packets smaller than 2048b */ |
| 104 | int responder (memif_conn_handle_t conn, void *private_ctx, uint16_t qid); |
| 105 | |
| 106 | /* Expect packets smaller than 2048b */ |
| 107 | int responder_zero_copy (memif_conn_handle_t conn, void *private_ctx, |
| 108 | uint16_t qid); |
| 109 | |
| 110 | /* reply with the same data */ |
| 111 | int basic_packet_handler (memif_connection_t *conn); |
| 112 | |
| 113 | /* ICMPv4 and ARP handler */ |
| 114 | int icmp_packet_handler (memif_connection_t *conn); |
| 115 | |
| 116 | #endif /* COMMON_H */ |