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
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;
46 prox_rte_ether_addr mac;
49 struct rte_ring *ctrl_plane_ring;
50 struct task_base *tmaster;
53 uint8_t reachable_port_id;
57 uint32_t arp_update_time;
59 struct arp_table optimized_arp_table[4];
60 struct rte_hash *ip_hash;
61 struct arp_table *arp_table;
62 struct rte_mempool *arp_pool;
66 void task_init_l3(struct task_base *tbase, struct task_args *targ);
67 void task_start_l3(struct task_base *tbase, struct task_args *targ);
68 int write_dst_mac(struct task_base *tbase, struct rte_mbuf *mbuf, uint32_t *ip_dst, uint64_t **time);
69 void task_set_gateway_ip(struct task_base *tbase, uint32_t ip);
70 void task_set_local_ip(struct task_base *tbase, uint32_t ip);
71 void handle_ctrl_plane_pkts(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
72 static inline void update_arp_update_time(struct l3_base *l3, uint64_t *ptr, uint32_t base)
74 // randomize timers - from 0.5 to 1.5 * configured time
75 const uint64_t hz = rte_get_tsc_hz();
76 uint64_t tsc = rte_rdtsc();
77 uint64_t rand = 500 + (1000L * rand_r(&l3->seed)) / RAND_MAX;
78 *ptr = tsc + (base * rand / 1000) * hz / 1000;
81 #endif /* _PACKET_UTILS_H_ */