2 // Copyright (c) 2010-2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef _PACKET_UTILS_H_
17 #define _PACKET_UTILS_H_
19 #include "prox_compat.h"
22 #include "prox_malloc.h"
27 #define FLAG_DST_MAC_KNOWN 1
28 #define MAX_ARP_ENTRIES 65536
30 #define IP4(x) x & 0xff, (x >> 8) & 0xff, (x >> 16) & 0xff, x >> 24 // From Network (BE)
37 #define DEFAULT_ARP_TIMEOUT (1000 * 3600 * 24 * 15) // ~15 days = disabled by default
38 #define DEFAULT_ARP_UPDATE_TIME (1000) // 1 second
43 uint64_t arp_update_time;
47 prox_rte_ether_addr mac;
50 struct rte_ring *ctrl_plane_ring;
51 struct task_base *tmaster;
54 uint8_t reachable_port_id;
58 uint32_t arp_update_time;
60 prox_next_hop_index_type nb_gws;
62 struct arp_table optimized_arp_table[4];
63 struct rte_hash *ip_hash;
64 struct arp_table *arp_table;
65 struct rte_mempool *arp_pool;
66 struct rte_lpm *ipv4_lpm;
67 struct arp_table *next_hops;
70 void task_init_l3(struct task_base *tbase, struct task_args *targ);
71 void task_start_l3(struct task_base *tbase, struct task_args *targ);
72 int write_dst_mac(struct task_base *tbase, struct rte_mbuf *mbuf, uint32_t *ip_dst, uint64_t **time, uint64_t tsc);
73 void task_set_gateway_ip(struct task_base *tbase, uint32_t ip);
74 void task_set_local_ip(struct task_base *tbase, uint32_t ip);
75 void handle_ctrl_plane_pkts(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
77 static inline void update_arp_update_time(struct l3_base *l3, uint64_t *ptr, uint32_t base)
79 // randomize timers - from 0.5 to 1.5 * configured time
80 const uint64_t hz = rte_get_tsc_hz();
81 uint64_t tsc = rte_rdtsc();
82 uint64_t rand = 500 + (1000L * rand_r(&l3->seed)) / RAND_MAX;
83 *ptr = tsc + (base * rand / 1000) * hz / 1000;
85 #endif /* _PACKET_UTILS_H_ */