Add support for configurable arp timers in L3 mode
[samplevnf.git] / VNFs / DPPD-PROX / packet_utils.h
1 /*
2 // Copyright (c) 2010-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 #ifndef _PACKET_UTILS_H_
17 #define _PACKET_UTILS_H_
18
19 #include "arp.h"
20 #include "quit.h"
21 #include "prox_malloc.h"
22 #include "defaults.h"
23 #include "prox_cfg.h"
24 #include "etypes.h"
25
26 #define FLAG_DST_MAC_KNOWN      1
27 #define MAX_ARP_ENTRIES 65536
28
29 #define IP4(x) x & 0xff, (x >> 8) & 0xff, (x >> 16) & 0xff, x >> 24
30 enum {
31         SEND_MBUF_AND_ARP,
32         SEND_MBUF,
33         SEND_ARP,
34         DROP_MBUF
35 };
36 #define DEFAULT_ARP_TIMEOUT     (1000 * 3600 * 24 * 15) // ~15 days = disabled by default
37 #define DEFAULT_ARP_UPDATE_TIME (1000)                  // 1 second
38
39 struct task_base;
40 struct task_args;
41 struct arp_table {
42         uint64_t arp_update_time;
43         uint64_t arp_timeout;
44         uint32_t ip;
45         struct ether_addr mac;
46 };
47 struct l3_base {
48         struct rte_ring *ctrl_plane_ring;
49         struct task_base *tmaster;
50         uint32_t flags;
51         uint32_t n_pkts;
52         uint8_t reachable_port_id;
53         uint8_t core_id;
54         uint8_t task_id;
55         uint32_t arp_timeout;
56         uint32_t arp_update_time;
57         struct arp_table gw;
58         struct arp_table optimized_arp_table[4];
59         struct rte_hash *ip_hash;
60         struct arp_table *arp_table;
61         struct rte_mempool *arp_pool;
62 };
63
64 void task_init_l3(struct task_base *tbase, struct task_args *targ);
65 void task_start_l3(struct task_base *tbase, struct task_args *targ);
66 int write_dst_mac(struct task_base *tbase, struct rte_mbuf *mbuf, uint32_t *ip_dst);
67 void task_set_gateway_ip(struct task_base *tbase, uint32_t ip);
68 void task_set_local_ip(struct task_base *tbase, uint32_t ip);
69 void handle_ctrl_plane_pkts(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
70
71 #endif /* _PACKET_UTILS_H_ */