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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
/*
* MPTCP Scheduler to reduce latency and jitter.
*
* This scheduler sends all packets redundantly on all available subflows.
*
* Initial Design & Implementation:
* Tobias Erbshaeusser <erbshauesser@dvs.tu-darmstadt.de>
* Alexander Froemmgen <froemmge@dvs.tu-darmstadt.de>
*
* Initial corrections & modifications:
* Christian Pinedo <christian.pinedo@ehu.eus>
* Igor Lopez <igor.lopez@ehu.eus>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/module.h>
#include <net/mptcp.h>
/* Struct to store the data of a single subflow */
struct redsched_sock_data {
/* The skb or NULL */
struct sk_buff *skb;
/* End sequence number of the skb. This number should be checked
* to be valid before the skb field is used
*/
u32 skb_end_seq;
};
/* Struct to store the data of the control block */
struct redsched_cb_data {
/* The next subflow where a skb should be sent or NULL */
struct tcp_sock *next_subflow;
};
/* Returns the socket data from a given subflow socket */
static struct redsched_sock_data *redsched_get_sock_data(struct tcp_sock *tp)
{
return (struct redsched_sock_data *)&tp->mptcp->mptcp_sched[0];
}
/* Returns the control block data from a given meta socket */
static struct redsched_cb_data *redsched_get_cb_data(struct tcp_sock *tp)
{
return (struct redsched_cb_data *)&tp->mpcb->mptcp_sched[0];
}
static bool redsched_get_active_valid_sks(struct sock *meta_sk)
{
struct tcp_sock *meta_tp = tcp_sk(meta_sk);
struct mptcp_cb *mpcb = meta_tp->mpcb;
struct sock *sk;
int active_valid_sks = 0;
mptcp_for_each_sk(mpcb, sk) {
if (subflow_is_active((struct tcp_sock *)sk) &&
!mptcp_is_def_unavailable(sk))
active_valid_sks++;
}
return active_valid_sks;
}
static bool redsched_use_subflow(struct sock *meta_sk,
int active_valid_sks,
struct tcp_sock *tp,
struct sk_buff *skb)
{
if (!skb || !mptcp_is_available((struct sock *)tp, skb, false))
return false;
if (TCP_SKB_CB(skb)->path_mask != 0)
return subflow_is_active(tp);
if (TCP_SKB_CB(skb)->path_mask == 0) {
if (active_valid_sks == -1)
active_valid_sks = redsched_get_active_valid_sks(meta_sk);
if (subflow_is_backup(tp) && active_valid_sks > 0)
return false;
else
return true;
}
return false;
}
static struct sock *redundant_get_subflow(struct sock *meta_sk,
struct sk_buff *skb,
bool zero_wnd_test)
{
struct tcp_sock *meta_tp = tcp_sk(meta_sk);
struct mptcp_cb *mpcb = meta_tp->mpcb;
struct redsched_cb_data *cb_data = redsched_get_cb_data(meta_tp);
struct tcp_sock *first_tp = cb_data->next_subflow;
struct sock *sk;
struct tcp_sock *tp;
/* Answer data_fin on same subflow */
if (meta_sk->sk_shutdown & RCV_SHUTDOWN &&
skb && mptcp_is_data_fin(skb)) {
mptcp_for_each_sk(mpcb, sk) {
if (tcp_sk(sk)->mptcp->path_index ==
mpcb->dfin_path_index &&
mptcp_is_available(sk, skb, zero_wnd_test))
return sk;
}
}
if (!first_tp)
first_tp = mpcb->connection_list;
tp = first_tp;
/* Search for any subflow to send it */
do {
if (mptcp_is_available((struct sock *)tp, skb,
zero_wnd_test)) {
cb_data->next_subflow = tp->mptcp->next;
return (struct sock *)tp;
}
tp = tp->mptcp->next;
if (!tp)
tp = mpcb->connection_list;
} while (tp != first_tp);
/* No space */
return NULL;
}
/* Corrects the stored skb pointers if they are invalid */
static void redsched_correct_skb_pointers(struct sock *meta_sk,
struct redsched_sock_data *sk_data)
{
struct tcp_sock *meta_tp = tcp_sk(meta_sk);
if (sk_data->skb && !after(sk_data->skb_end_seq, meta_tp->snd_una))
sk_data->skb = NULL;
}
/* Returns the next skb from the queue */
static struct sk_buff *redundant_next_skb_from_queue(struct sk_buff_head *queue,
struct sk_buff *previous)
{
if (skb_queue_empty(queue))
return NULL;
if (!previous)
return skb_peek(queue);
if (skb_queue_is_last(queue, previous))
return NULL;
return skb_queue_next(queue, previous);
}
static struct sk_buff *redundant_next_segment(struct sock *meta_sk,
int *reinject,
struct sock **subsk,
unsigned int *limit)
{
struct tcp_sock *meta_tp = tcp_sk(meta_sk);
struct mptcp_cb *mpcb = meta_tp->mpcb;
struct redsched_cb_data *cb_data = redsched_get_cb_data(meta_tp);
struct tcp_sock *first_tp = cb_data->next_subflow;
struct tcp_sock *tp;
struct sk_buff *skb;
int active_valid_sks = -1;
if (skb_queue_empty(&mpcb->reinject_queue) &&
skb_queue_empty(&meta_sk->sk_write_queue))
/* Nothing to send */
return NULL;
/* First try reinjections */
skb = skb_peek(&mpcb->reinject_queue);
if (skb) {
*subsk = get_available_subflow(meta_sk, skb, false);
if (!*subsk)
return NULL;
*reinject = 1;
return skb;
}
/* Then try indistinctly redundant and normal skbs */
if (!first_tp)
first_tp = mpcb->connection_list;
tp = first_tp;
*reinject = 0;
active_valid_sks = redsched_get_active_valid_sks(meta_sk);
do {
struct redsched_sock_data *sk_data;
/* Correct the skb pointers of the current subflow */
sk_data = redsched_get_sock_data(tp);
redsched_correct_skb_pointers(meta_sk, sk_data);
skb = redundant_next_skb_from_queue(&meta_sk->sk_write_queue,
sk_data->skb);
if (skb && redsched_use_subflow(meta_sk, active_valid_sks, tp,
skb)) {
sk_data->skb = skb;
sk_data->skb_end_seq = TCP_SKB_CB(skb)->end_seq;
cb_data->next_subflow = tp->mptcp->next;
*subsk = (struct sock *)tp;
if (TCP_SKB_CB(skb)->path_mask)
*reinject = -1;
return skb;
}
tp = tp->mptcp->next;
if (!tp)
tp = mpcb->connection_list;
} while (tp != first_tp);
/* Nothing to send */
return NULL;
}
static void redundant_release(struct sock *sk)
{
struct tcp_sock *tp = tcp_sk(sk);
struct redsched_cb_data *cb_data = redsched_get_cb_data(tp);
/* Check if the next subflow would be the released one. If yes correct
* the pointer
*/
if (cb_data->next_subflow == tp)
cb_data->next_subflow = tp->mptcp->next;
}
struct mptcp_sched_ops mptcp_sched_redundant = {
.get_subflow = redundant_get_subflow,
.next_segment = redundant_next_segment,
.release = redundant_release,
.name = "redundant",
.owner = THIS_MODULE,
};
static int __init redundant_register(void)
{
BUILD_BUG_ON(sizeof(struct redsched_sock_data) > MPTCP_SCHED_SIZE);
BUILD_BUG_ON(sizeof(struct redsched_cb_data) > MPTCP_SCHED_DATA_SIZE);
if (mptcp_register_scheduler(&mptcp_sched_redundant))
return -1;
return 0;
}
static void redundant_unregister(void)
{
mptcp_unregister_scheduler(&mptcp_sched_redundant);
}
module_init(redundant_register);
module_exit(redundant_unregister);
MODULE_AUTHOR("Tobias Erbshaeusser, Alexander Froemmgen");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("REDUNDANT MPTCP");
MODULE_VERSION("0.90");
|