glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / ats / test_ats_reservation_api.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010-2015 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14 */
15 /**
16  * @file ats/test_ats_reservation_api.c
17  * @brief test ATS bandwidth reservation API
18  * @author Christian Grothoff
19  */
20 #include "platform.h"
21 #include "test_ats_lib.h"
22
23 /**
24  * Global timeout for the testcase.
25  */
26 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
27
28 /**
29  * Definition of the test as a sequence of commands.
30  */
31 static struct Command test_commands[] = {
32   /* 0: add initial address */
33   {
34     .code = CMD_ADD_ADDRESS,
35     .label = "add-address-0-0",
36     .details.add_address = {
37       .pid = 0,
38       .addr_num = 0,
39       .session = 0,
40       .properties = {
41         /* use network with 65k quota! */
42         .scope = GNUNET_ATS_NET_WAN
43       }
44     }
45   },
46   /* 1: some solver still require explicit start */
47   {
48     .code = CMD_REQUEST_CONNECTION_START,
49     .label = "request-0",
50     .details.request_connection_start = {
51       .pid = 0
52     }
53   },
54   /* 2: check we got an address */
55   {
56     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
57     .details.await_address_suggestion = {
58       .add_label = "add-address-0-0"
59     }
60   },
61   /* 3: sleep 7s, should give us 5s * 64k/s = 320k buffer;
62      Note that this depends on MAX_BANDWIDTH_CARRY_S.  We
63      sleep more than 5s to show that only MAX_BANDWIDTH carries. */
64   {
65     .code = CMD_SLEEP,
66     .label = "sleep",
67     .details.sleep.delay = { 7 * 1000LL * 1000LL }
68   },
69   /* 4: reserve 128k -- should work (5s carry, so we had 320k) */
70   {
71     .code = CMD_RESERVE_BANDWIDTH,
72     .details.reserve_bandwidth = {
73       .pid = 0,
74       .amount = 128 * 1024,
75       .expected_result = GNUNET_YES
76     }
77   },
78   /* 5: reserve another 192k -- should just work (now exactly pushing the limit) */
79   {
80     .code = CMD_RESERVE_BANDWIDTH,
81     .label = "big reservation",
82     .details.reserve_bandwidth = {
83       .pid = 0,
84       .amount = 192 * 1024,
85       .expected_result = GNUNET_YES
86     }
87   },
88   /* 6: reserve another 32k -- should now fail (if MAX_BANDWIDTH_CARRY_S
89      is precisely observed) */
90   {
91     .code = CMD_RESERVE_BANDWIDTH,
92     .label = "failing reservation",
93     .details.reserve_bandwidth = {
94       .pid = 0,
95       .amount = 32 * 1024,
96       .expected_result = GNUNET_SYSERR
97     }
98   },
99   /* 7: sleep 3s, should give us 3s * 64k/s - 32k = 160k buffer */
100   {
101     .code = CMD_SLEEP,
102     .label = "sleep",
103     .details.sleep.delay = { 6 * 1000LL * 1000LL }
104   },
105   /* 8: reserve another 160k -- should now work */
106   {
107     .code = CMD_RESERVE_BANDWIDTH,
108     .label = "successful final reservation",
109     .details.reserve_bandwidth = {
110       .pid = 0,
111       .amount = 160 * 1024,
112       .expected_result = GNUNET_YES
113     }
114   },
115   /* 9: remove address */
116   {
117     .code = CMD_DEL_ADDRESS,
118     .details.del_address = {
119       .add_label = "add-address-0-0"
120     }
121   },
122   /* 10: check we got disconnected */
123   {
124     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
125     .details.await_disconnect_suggestion = {
126       .pid = 0
127     }
128   },
129   /* 11: just for symmetry, also stop asking for the connection */
130   {
131     .code = CMD_REQUEST_CONNECTION_STOP,
132     .details.request_connection_stop = {
133       .connect_label = "request-0",
134     }
135   },
136   /* Test ends successfully */
137   {
138     .code = CMD_END_PASS
139   }
140 };
141
142
143 int
144 main (int argc,
145       char *argv[])
146 {
147   return TEST_ATS_run (argc,
148                        argv,
149                        test_commands,
150                        TIMEOUT);
151 }
152
153
154 /* end of file test_ats_reservation_api.c */