-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
159 lines (129 loc) · 5.7 KB
/
tests.c
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
/**
* Testing suite for the mptcplib
*
* By CLAREMBEAU Alexis
* 01/24/2017
*/
#include "mptcplib.h"
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/ip.h>
void test(const char *name, int condition, char *success, char *failure){
if(condition){
printf(" [ ] %s : %s\n", name, success);
}
else{
printf(" [X] %s : %s\n", name, failure);
}
}
int main(int argc, char **argv){
// initializing the connection
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct mptcplib_flow flow_main = mptcplib_make_flow("192.168.33.10", 64001, "multipath-tcp.org", 80);
int bind_res = bind(sockfd, flow_main.local, flow_main.local_len);
if(bind_res != 0){
perror("bind");
return;
}
int connect_res = connect(sockfd, flow_main.remote, flow_main.remote_len);
if(connect_res != 0){
perror("connect");
return;
}
// making the request
char *sndbuf = "GET / HTTP/1.0\r\n\r\n";
int n_sent = send(sockfd, sndbuf, strlen(sndbuf), 0);
if(n_sent <= 0){
perror("send");
return;
}
mptcplib_free_flow(flow_main);
// opening some flow
puts("opening some subflows");
struct mptcplib_flow flow1 = mptcplib_make_flow("192.168.33.10", 64002, "multipath-tcp.org", 80);
struct mptcplib_flow flow2 = mptcplib_make_flow("192.168.34.10", 64003, "multipath-tcp.org", 80);
struct mptcplib_flow flow3 = mptcplib_make_flow("::", 64004, "multipath-tcp.org", 80);
struct mptcplib_flow flow4 = mptcplib_make_flow("192.168.33.10", 10, "multipath-tcp.org", 80);
struct mptcplib_flow flow5 = mptcplib_make_flow("192.168.33.10", 64002, "multisdsdpath-tcp.org", 80);
flow1.low_prio = 1;
flow2.low_prio = 1;
flow3.low_prio = 1;
flow4.low_prio = 1;
flow5.low_prio = 1;
int errSub1 = mptcplib_open_sub(sockfd, &flow1);
int errSub2 = mptcplib_open_sub(sockfd, &flow2);
int errSub3 = mptcplib_open_sub(sockfd, &flow3);
int errSub4 = mptcplib_open_sub(sockfd, &flow4);
int errSub5 = mptcplib_open_sub(sockfd, &flow5);
test("opening flow #1", errSub1 == 0, "success", "failure");
test("opening flow #2", errSub2 == 0, "success", "failure");
test("opening flow #3", errSub3 == 0, "success", "failure");
test("opening flow #4", errSub4 != 0, "failure", "success");
test("opening flow #5", errSub5 != 0, "failure", "success");
test("subflow #1 id set by opensub > 0", flow1.id > 0, "success", "failure");
test("subflow #2 id set by opensub > 0", flow2.id > 0, "success", "failure");
test("subflow #3 id set by opensub > 0", flow3.id > 0, "success", "failure");
mptcplib_free_flow(flow1);
mptcplib_free_flow(flow2);
mptcplib_free_flow(flow3);
mptcplib_free_flow(flow4);
mptcplib_free_flow(flow5);
// reading some data from the socket
char buf[10];
int n_recv = recv(sockfd, buf, 10, 0);
if(n_recv <= 0){
perror("recv");
return;
}
// listing some subflows
puts("listing subflows");
struct mptcplib_getsubids_result subidsres = mptcplib_get_sub_ids(sockfd);
test("listing subflows success", subidsres.errnoValue == 0 , "success", "failure");
test("counting subflows", subidsres.ids.count == 4, "== 4", "!= 4");
puts("showing content of the subflows");
int i;
for(i = 0 ; i < subidsres.ids.count; i++){
struct mptcplib_getsubtuple_result tupleRes = mptcplib_get_sub_tuple(sockfd, subidsres.ids.values[i]);
test("test inspection succeeded", tupleRes.errnoValue == 0, "success", "failure");
test("tuple id >= 0", tupleRes.flow.id >= 0, ">= 0", "< 0");
test("tuple prio == 1", tupleRes.flow.low_prio == 1, "==1", "!=1");
mptcplib_free_flow(tupleRes.flow);
}
struct mptcplib_getsubtuple_result invalidTuple = mptcplib_get_sub_tuple(sockfd, 100);
test("getting invalid tuple", invalidTuple.errnoValue != 0,"failed", "success");
// removing some subflows and listing again to show the result
puts("removing some subflows");
int closedId1 = subidsres.ids.values[0];
int closedId2 = subidsres.ids.values[1];
int errClose1 = mptcplib_close_sub(sockfd, closedId1, 0);
test("close test valid", errClose1 == 0, "success", "failure");
int errClose2 = mptcplib_close_sub(sockfd, closedId2, 0);
test("close test valid", errClose2 == 0, "success", "failure");
int errClose3 = mptcplib_close_sub(sockfd, 100,0);
test("close test invalid", errClose3 != 0, "failure", "success");
usleep(100000);
puts("listing again");
struct mptcplib_getsubids_result subidsres2 = mptcplib_get_sub_ids(sockfd);
test("listing subflow status", subidsres2.errnoValue == 0, "succeeded", "failed");
for(i = 0 ; i< subidsres2.ids.count; i++){
int id = subidsres2.ids.values[i];
test("removed ID doesn't belong to result", id != closedId1 && id != closedId2, "success", "failure");
}
// finally, setting and reading a socket option from a subflow
puts("testing socket options");
int setId = subidsres2.ids.values[0];
int val = 28;
int resSet = mptcplib_set_sub_sockopt(sockfd,setId, SOL_IP, IP_TOS, &val, sizeof(val));
test("set subflow sockopt", resSet == 0, "success", "failure");
struct mptcplib_getsubsockopt_result getRes = mptcplib_get_sub_sockopt(sockfd,setId, SOL_IP, IP_TOS, sizeof(val));
test("get subflow sockopt", getRes.errnoValue == 0, "success", "failure");
test("get subflow sockopt value", *((int*)getRes.value) == 28, "28", "!= 28");
// closing the test suite
mptcplib_free_getsubtockopt_result(getRes);
mptcplib_free_intarray(subidsres.ids);
mptcplib_free_intarray(subidsres2.ids);
shutdown(sockfd, 0);
}