aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libtle_glue/ctx.h
blob: e78b68fdc736f5bfdad3f3669d087b74c2a2fa1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Copyright (c) 2018 Ant Financial Services Group.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _TLE_GLUE_SOCK_H_
#define _TLE_GLUE_SOCK_H_

#include <stdbool.h>
#include <pthread.h>

#include <rte_memzone.h>
#include <rte_mempool.h>
#include <rte_ether.h>
#include <rte_ip_frag.h>

#include <tle_ctx.h>
#include <tle_event.h>
#include <tle_stats.h>

#include <sys/queue.h>

#include "config.h"

#ifdef __cplusplus
extern "C" {
#endif

#define DPDK_IP				"DPDK_IP"
#define DPDK_IP_DEF			"0.0.0.0"
#define DPDK_IP_MASK			"DPDK_IP_MASK"
#define DPDK_IP_MASK_DEF		"16"
#define DPDK_IP_GATEWAY			"DPDK_IP_GATEWAY"
#define DPDK_IP_GATEWAY_DEF		"0.0.0.0"
#define DPDK_IPV6			"DPDK_IPV6"
#define DPDK_IPV6_DEF			"::"
#define DPDK_IPV6_MASK			"DPDK_IPV6_MASK"
#define DPDK_IPV6_MASK_DEF		"64"
#define DPDK_IPV6_GATEWAY		"DPDK_IPV6_GATEWAY"
#define DPDK_IPV6_GATEWAY_DEF		"::"

struct arp_entry {
	struct tle_dest dst;
	uint8_t inuse;
	uint8_t req_time;
	void* timer;
};

struct glue_ctx {
	struct tle_ctx *tcp_ctx;
	struct tle_dev *tcp_dev;
	struct tle_dev *lb_tcp_dev;
	struct tle_ctx *udp_ctx;
	struct tle_dev *udp_dev;
	struct tle_dev *lb_udp_dev;

	struct tle_evq *ereq;
	struct tle_evq *rxeq;
	struct tle_evq *txeq;

	uint16_t port_id;
	uint16_t queue_id;
	uint16_t lb_port_id;

	struct {
		uint8_t ipv4_ml;
		uint8_t ipv6_ml;
	};

	struct ether_addr mac;
	struct rte_mbuf *arp_wait;
	struct tle_timer_wheel *arp_tmw;
	uint32_t cycles_ms_shift;  /* to convert from cycles to ms */

	struct {
		uint32_t ipv4;
		struct in_addr ipv4_gw;
		bool lo4_enabled;

		uint32_t arp4_num;
		struct arp_entry *arp4;
		struct rte_hash *arp_hash;
	};

	struct {
		struct in6_addr ipv6;
		struct in6_addr ipv6_gw;
		bool lo6_enabled;

		uint32_t arp6_num;
		struct arp_entry *arp6;
		struct rte_hash *arp6_hash;
	};

	struct {
		rte_spinlock_t frag_lock;
		struct rte_ip_frag_tbl *frag_tbl;
		struct rte_ip_frag_death_row frag_dr;
	};

	struct tle_dest lb_dst;
	struct tle_dest lb_dst_v6;

	struct tle_mib mib;
} __rte_cache_aligned;

extern int nb_ctx;
extern struct glue_ctx *default_ctx;
extern struct glue_ctx ctx_array[MAX_NB_CTX];

RTE_DECLARE_PER_LCORE(struct glue_ctx *, glue_ctx);

static inline struct glue_ctx *
get_ctx(void)
{
	if (RTE_PER_LCORE(glue_ctx))
		return RTE_PER_LCORE(glue_ctx);
	return default_ctx;
}

static inline uint8_t
get_cid(void)
{
	return get_ctx() - ctx_array;
}

uint8_t glue_ctx_alloc(void);

struct glue_ctx * glue_ctx_lookup(uint16_t port_id, uint16_t queue_id);

void glue_ctx_free(struct glue_ctx *ctx);

#ifdef __cplusplus
}
#endif

#endif /* _TLE_GLUE_SOCK_H_ */