aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libtle_l4p/tcp_stream.h
blob: 04c2f889f109cfa962674e73d4ceba88dd74d58f (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright (c) 2016  Intel Corporation.
 * 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 _TCP_STREAM_H_
#define _TCP_STREAM_H_

#include <rte_vect.h>
#include <tle_dring.h>
#include <tle_tcp.h>
#include <tle_event.h>

#include "stream.h"
#include "misc.h"
#include "tcp_misc.h"

#ifdef __cplusplus
extern "C" {
#endif

enum {
	TCP_ST_CLOSED,
	TCP_ST_LISTEN,
	TCP_ST_SYN_SENT,
	TCP_ST_SYN_RCVD,
	TCP_ST_ESTABLISHED,
	TCP_ST_FIN_WAIT_1,
	TCP_ST_FIN_WAIT_2,
	TCP_ST_CLOSE_WAIT,
	TCP_ST_CLOSING,
	TCP_ST_LAST_ACK,
	TCP_ST_TIME_WAIT,
	TCP_ST_NUM
};

enum {
	TCP_OP_LISTEN =  0x1,
	TCP_OP_ACCEPT =  0x2,
	TCP_OP_CONNECT = 0x4,
	TCP_OP_CLOSE =   0x8,
};

struct tcb {
	volatile uint16_t state;
	volatile uint16_t uop; /* operations by user performed */
	struct {
		uint32_t nxt;
		uint32_t irs; /* initial received sequence */
		uint32_t wnd;
		uint32_t ts;
		struct {
			uint32_t seq;
			uint32_t on;
		} frs;
		uint32_t srtt;   /* smoothed round trip time (scaled by >> 3) */
		uint32_t rttvar; /* rtt variance */
		uint16_t mss;
		uint8_t  wscale;
		uint8_t  dupack;
	} rcv;
	struct {
		uint64_t nxt;
		uint64_t una;
		uint64_t rcvr; /* recover RFC 6582 */
		uint64_t fss;  /* FIN sequence # */
		uint32_t fastack; /* # of partial acks in fast retransmit */
		uint32_t wnd;
		union wui wu; /* window update */
		uint32_t ack; /* last sent ack */
		uint32_t ts;
		uint32_t cwnd;     /* congestion window */
		uint32_t ssthresh; /* slow start threshold */
		uint32_t rto;      /* retransmission timeout */
		uint32_t iss;      /* initial send sequence */
		uint16_t mss;
		uint8_t  wscale;
		uint8_t nb_retx; /* number of retransmission */
		uint8_t nb_retm; /**< max number of retx attempts. */
	} snd;
	struct syn_opts so; /* initial syn options. */
};


struct tle_tcp_stream {

	struct tle_stream s;

	struct stbl_entry *ste;     /* entry in streams table. */
	struct tcb tcb;

	struct {
		void *handle;
	} timer;

	struct {
		struct tle_event *ev;
		struct tle_stream_cb cb;
	} err;

	struct {
		rte_atomic32_t use;
		struct rte_ring *q;     /* listen (syn) queue */
		struct ofo *ofo;
		struct tle_event *ev;    /* user provided recv event. */
		struct tle_stream_cb cb; /* user provided recv callback. */
	} rx __rte_cache_aligned;

	struct {
		rte_atomic32_t use;
		rte_atomic32_t arm;  /* when > 0 stream is in to-send queue */
		struct {
			uint32_t nb_elem;  /* number of objects per drb. */
			uint32_t nb_max;   /* number of drbs per stream. */
			struct rte_ring *r;
		} drb;
		struct rte_ring *q;  /* (re)tx queue */
		struct tle_event *ev;
		struct tle_stream_cb cb;
		struct tle_dest dst;
	} tx __rte_cache_aligned;

} __rte_cache_aligned;

#define TCP_STREAM(p)	\
((struct tle_tcp_stream *)((uintptr_t)(p) - offsetof(struct tle_tcp_stream, s)))

#define TCP_STREAM_TX_PENDING(s)	\
	((s)->tx.drb.nb_max != rte_ring_count((s)->tx.drb.r))

#define TCP_STREAM_TX_FINISHED(s)	\
	((s)->tx.drb.nb_max == rte_ring_count((s)->tx.drb.r))

#include "stream_table.h"

struct sdr {
	rte_spinlock_t lock;
	STAILQ_HEAD(, tle_stream) fe;
	STAILQ_HEAD(, tle_stream) be;
};

struct tcp_streams {
	struct stbl st;
	struct tle_timer_wheel *tmr; /* timer wheel */
	struct rte_ring *tsq;        /* to-send streams queue */
	struct sdr dr;               /* death row for zombie streams */
	struct tle_tcp_stream s[];   /* array of allocated streams. */
};

#define CTX_TCP_STREAMS(ctx)	((struct tcp_streams *)(ctx)->streams.buf)
#define CTX_TCP_STLB(ctx)	(&CTX_TCP_STREAMS(ctx)->st)
#define CTX_TCP_TMWHL(ctx)	(CTX_TCP_STREAMS(ctx)->tmr)
#define CTX_TCP_TSQ(ctx)	(CTX_TCP_STREAMS(ctx)->tsq)
#define CTX_TCP_SDR(ctx)	(&CTX_TCP_STREAMS(ctx)->dr)

#ifdef __cplusplus
}
#endif

#endif /* _TCP_STREAM_H_ */