common: Adding common library for sample vnf
[samplevnf.git] / common / VIL / pipeline_arpicmp / pipeline_arpicmp.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
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 #ifndef __INCLUDE_PIPELINE_ARPICMP_H__
18 #define __INCLUDE_PIPELINE_ARPICMP_H__
19
20 #include "pipeline.h"
21 #include "pipeline_arpicmp_be.h"
22
23 /*
24  * Pipeline type
25  */
26 extern struct pipeline_type pipeline_arpicmp;
27 //uint16_t verbose_level = 1; /**< should be Silent by default. */
28 #define MAX_PKT_BURST 512
29 #define DEF_PKT_BURST 32
30 /**< Number of packets per burst. */
31 //uint16_t nb_pkt_per_burst = DEF_PKT_BURST;
32 typedef uint8_t  portid_t;
33 typedef uint16_t queueid_t;
34 typedef uint16_t streamid_t;
35 /**
36  * The data structure associated with a forwarding stream between a receive
37  * port/queue and a transmit port/queue.
38  */
39 struct fwd_stream {
40         /* "read-only" data */
41         /**< port to poll for received packets */
42         portid_t   rx_port;
43         /**< RX queue to poll on "rx_port" */
44         queueid_t  rx_queue;
45         /**< forwarding port of received packets */
46         portid_t   tx_port;
47         /**< TX queue to send forwarded packets */
48         queueid_t  tx_queue;
49         /**< index of peer ethernet address of packets */
50         streamid_t peer_addr;
51
52         /* "read-write" results */
53         /**< received packets */
54         unsigned int rx_packets;
55         /**< received packets transmitted */
56         unsigned int tx_packets;
57         /**< received packets not forwarded */
58         unsigned int fwd_dropped;
59         /**< received packets has bad ip checksum */
60         unsigned int rx_bad_ip_csum;
61         /**< received packets has bad l4 checksum */
62         unsigned int rx_bad_l4_csum;
63         #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
64         uint64_t     core_cycles; /**< used for RX and TX processing */
65         #endif
66         #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
67         struct pkt_burst_stats rx_burst_stats;
68         struct pkt_burst_stats tx_burst_stats;
69         #endif
70 };
71 /*
72  * Forwarding mode operations:
73  *   - IO forwarding mode (default mode)
74  *     Forwards packets unchanged.
75  *
76  *   - MAC forwarding mode
77  *     Set the source and the destination Ethernet addresses of packets
78  *     before forwarding them.
79  *
80  *   - IEEE1588 forwarding mode
81  *     Check that received IEEE1588 Precise Time Protocol (PTP) packets are
82  *     filtered and timestamped by the hardware.
83  *     Forwards packets unchanged on the same port.
84  *     Check that sent IEEE1588 PTP packets are timestamped by the hardware.
85  */
86 typedef void (*port_fwd_begin_t)(portid_t pi);
87 typedef void (*port_fwd_end_t)(portid_t pi);
88 typedef void (*packet_fwd_t)(struct fwd_stream *fs);
89 struct fwd_engine {
90         /**< Forwarding mode name. */
91         const char       *fwd_mode_name;
92         /**< NULL if nothing special to do. */
93         port_fwd_begin_t port_fwd_begin;
94         /**< NULL if nothing special to do. */
95         port_fwd_end_t   port_fwd_end;
96         /**< Mandatory. */
97         packet_fwd_t     packet_fwd;
98 };
99 #define IPV4_ADDR_TO_UINT(ip_addr, ip)                  \
100 do {                                                    \
101         if ((ip_addr).family == AF_INET)                \
102                 (ip) = (ip_addr).addr.ipv4.s_addr;      \
103         else {                                          \
104                 printf("invalid parameter.\n");         \
105                 return;                                 \
106         }                                               \
107 } while (0)
108
109 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip)                 \
110 do {                                                    \
111         if ((ip_addr).family == AF_INET6)               \
112         (void)rte_memcpy(&(ip),                         \
113                 &((ip_addr).addr.ipv6),                 \
114                 sizeof(struct in6_addr));               \
115         else {                                          \
116                 printf("invalid parameter.\n");         \
117                 return;                                 \
118         }                                               \
119 } while (0)
120
121 void set_pkt_forwarding_mode(const char *fwd_mode_name);
122 #endif