Fix linker errors with recent GNU ld
[samplevnf.git] / VNFs / DPPD-PROX / handle_master.h
1 /*
2 // Copyright (c) 2010-2020 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 #include <poll.h>
18 #include "task_base.h"
19 #include "task_init.h"
20
21 enum arp_actions {
22         MAC_INFO_FROM_MASTER,
23         MAC_INFO_FROM_MASTER_FOR_IPV6,
24         IPV6_INFO_FROM_MASTER,
25         ROUTE_ADD_FROM_MASTER,
26         ROUTE_DEL_FROM_MASTER,
27         SEND_ARP_REQUEST_FROM_MASTER,
28         SEND_ARP_REPLY_FROM_MASTER,
29         SEND_NDP_FROM_MASTER,
30         SEND_ICMP_FROM_MASTER,
31         SEND_BGP_FROM_MASTER,
32         ARP_PKT_FROM_NET_TO_MASTER,
33         NDP_PKT_FROM_NET_TO_MASTER,
34         ICMP_TO_MASTER,
35         BGP_TO_MASTER,
36         IP4_REQ_MAC_TO_MASTER,
37         IP6_REQ_MAC_TO_MASTER,
38         PKT_FROM_TAP,
39         MAX_ACTIONS
40 };
41
42 #define PROX_MAX_ARP_REQUESTS   32      // Maximum number of tasks requesting the same MAC address
43
44 #define HANDLE_RANDOM_IP_FLAG           1
45 #define HANDLE_RANDOM_LOCAL_IP_FLAG     2
46 #define HANDLE_RANDOM_GLOBAL_IP_FLAG    4
47 #define IPV6_ROUTER                     8
48 #define RANDOM_IP               0xffffffff
49
50 #define PROX_PSEUDO_PKT_PORT 0xdead
51
52 struct port_table {
53         prox_rte_ether_addr     mac;
54         struct rte_ring         *ring;
55         uint32_t                ip;
56         uint8_t                 port;
57         uint8_t                 flags;
58         struct ipv6_addr        local_ipv6_addr;
59         struct ipv6_addr        global_ipv6_addr;
60         struct ipv6_addr        router_prefix;
61         uint64_t last_echo_req_rcvd_tsc;
62         uint64_t last_echo_rep_rcvd_tsc;
63         uint32_t n_echo_req;
64         uint32_t n_echo_rep;
65 };
66
67 struct ip_table {
68         prox_rte_ether_addr     mac;
69         struct rte_ring         *ring;
70 };
71
72 struct external_ip_table {
73         prox_rte_ether_addr     mac;
74         struct rte_ring         *rings[PROX_MAX_ARP_REQUESTS];
75         uint16_t                nb_requests;
76 };
77
78 struct vdev {
79         int port_id;
80         struct rte_ring *ring;
81 };
82
83 struct task_master {
84         struct task_base base;
85         struct rte_ring *ctrl_rx_ring;
86         struct rte_ring **ctrl_tx_rings;
87         struct ip_table *internal_ip_table;     // Store mac address from our IP
88         struct external_ip_table *external_ip_table;    // Store mac address from external systems
89         struct ip_table *internal_ip6_table;    // Store mac address from our IP
90         struct external_ip_table *external_ip6_table;   // Store mac address from external systems
91         struct rte_hash  *external_ip_hash;
92         struct rte_hash  *external_ip6_hash;
93         struct rte_hash  *internal_ip_hash;
94         struct rte_hash  *internal_ip6_hash;
95         struct port_table internal_port_table[PROX_MAX_PORTS];
96         struct vdev all_vdev[PROX_MAX_PORTS];
97         int max_vdev_id;
98         struct pollfd arp_fds;
99         struct pollfd route_fds;
100 };
101
102 extern const char *actions_string[MAX_ACTIONS];
103
104 void init_ctrl_plane(struct task_base *tbase);
105
106 extern int (*handle_ctrl_plane)(struct task_base *tbase, struct rte_mbuf **mbuf, uint16_t n_pkts);
107
108 static inline void tx_drop(struct rte_mbuf *mbuf)
109 {
110         rte_pktmbuf_free(mbuf);
111 }
112
113 void register_ip_to_ctrl_plane(struct task_base *task, uint32_t ip, uint8_t port_id, uint8_t core_id, uint8_t task_id);
114 void master_init_vdev(struct task_base *task, uint8_t port_id, uint8_t core_id, uint8_t task_id);
115 void register_router_to_ctrl_plane(struct task_base *tbase, uint8_t port_id, uint8_t core_id, uint8_t task_id, struct ipv6_addr *local_ipv6_addr, struct ipv6_addr *global_ipv6_addr, struct ipv6_addr *router_prefix);
116 void register_node_to_ctrl_plane(struct task_base *tbase, struct ipv6_addr *local_ipv6_addr, struct ipv6_addr *global_ipv6_addr, uint8_t port_id, uint8_t core_id, uint8_t task_id);