Support packets in flight
[samplevnf.git] / common / VIL / l2l3_stack / l2_proto.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 /**
18  *      @file
19  *      L2 Protocol Handler
20  *      Reads the packet from the interface and sets the
21  *      masks for a burst of packets based on ethertype and
22  *      calls the relevant function registered for that ethertype
23  *
24  */
25
26 #ifndef L2_PROTO_H
27 #define L2_PROTO_H
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <stdint.h>
33 #include <inttypes.h>
34 #include <sys/types.h>
35 #include <sys/queue.h>
36 #include <netinet/in.h>
37 #include <setjmp.h>
38 #include <stdarg.h>
39 #include <ctype.h>
40 #include <errno.h>
41 #include <getopt.h>
42 #include <signal.h>
43 #include <stdbool.h>
44
45 #include <rte_common.h>
46 #include <rte_log.h>
47 #include <rte_malloc.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
51 #include <rte_eal.h>
52 #include <rte_per_lcore.h>
53 #include <rte_launch.h>
54 #include <rte_atomic.h>
55 #include <rte_cycles.h>
56 #include <rte_prefetch.h>
57 #include <rte_lcore.h>
58 #include <rte_per_lcore.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_interrupts.h>
61 #include <rte_pci.h>
62 #include <rte_random.h>
63 #include <rte_debug.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
66 #include <rte_ip.h>
67 #include <rte_ring.h>
68 #include <rte_mempool.h>
69 #include <rte_mbuf.h>
70 #include <rte_eth_ctrl.h>
71 #include <interface.h>
72
73 /* Array indexes of proto_packet_type structure */
74 #define IPv4_VAL 0 /**< Array index for IPv4 */
75 #define ARP_VAL 1 /**< Array index for ARP */
76 #define IPv6_VAL 2 /**< Array index for IPv6 */
77
78 /* Enable to print L2_Proto debugs */
79 #define L2_PROTO_DBG 1 /**< Enable to print L2 Proto debugs */
80
81 /**
82  * A structure used to call the function handlers for a certain ethertype
83  */
84 struct proto_packet_type {
85         uint16_t type;          /**< Ethertype  */
86         void (*func) (struct rte_mbuf **m, uint16_t nb_pkts, uint64_t pkt_mask, l2_phy_interface_t *port);  /**< Function pointer to the registered callback function */
87 } __rte_cache_aligned;/**< RTE Cache alignment */
88
89 /**
90  * Function called from other modules to add the certain rx functions for particular ethertypes
91  *
92  * @param type
93  * Ethertype
94  * @param (*func)()
95  * Function pointer to the function being registered by different modules
96  */
97 void
98 list_add_type(uint16_t type,
99                                 void (*func) (struct rte_mbuf **, uint16_t, uint64_t,
100                                         l2_phy_interface_t *));
101
102 /**
103  * Function to check whether the destination mac address of the packet is the mac address of the received port.
104  * Drop the packet if it is not destined to the host.
105  * If it is destined to this host, then set the packet masks for IPv4, IPv6 and ARP packet types for a burst of packets.
106  *
107  * @param m
108  * rte_mbuf packet
109  *
110  * @param portid
111  * Portid from which the packet was received
112  *
113  * @param pos
114  * Index of the packet in the burst
115  *
116  * @param pkts_mask
117  * Packet mask where bits are set at positions for the packets in the burst which were destined to the host
118  *
119  * @param arp_pkts_mask
120  * Packet mask for ARP where bits are set for valid ARP packets
121  *
122  * @param ipv4_pkts_mask
123  * Packet mask for IPv4 where bits are set for valid IPv4 packets
124  *
125  * @param ipv6_pkts_mask
126  * Packet mask for IPv6 where bits are set for valid IPv6 packets
127  *
128  */
129 void
130 l2_check_mac(struct rte_mbuf *m[IFM_BURST_SIZE], l2_phy_interface_t *port,
131                          uint8_t pos, uint64_t *pkts_mask, uint64_t *arp_pkts_mask,
132                          uint64_t *ipv4_pkts_mask, uint64_t *ipv6_pkts_mask);
133
134 /**
135  * Entry function to L2 Protocol Handler where appropriate functions are called for particular ethertypes
136  *
137  * @param m
138  * rte_mbuf packet
139  *
140  * @param nb_rx
141  * Number of packets read
142  *
143  * @param portid
144  * Port-id of the port in which packet was received
145  */
146 void
147 protocol_handler_recv(struct rte_mbuf *m[IFM_BURST_SIZE], uint16_t nb_rx,
148                                         l2_phy_interface_t *port);
149
150 #endif