blob: aba85d8d8712b4f0ccf7a8bbb77195d8c770c9dd (
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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
#!/bin/bash
############################################################################
# CONSTANTS
############################################################################
INTERFACE_CMD="ip route get 1 | grep -Po '(?<=(dev )).*(?= src| proto)'"
ADDRESS_CMD="ip route get 1 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}'"
CTRL_CMD="docker exec test-hicn \
/hicn-build/build/build-root/bin/hicn-light-control"
PING_SERVER_CMD="docker exec -d test-hicn \
/hicn-build/build/build-root/bin/hicn-ping-server \
-z hicnlightng_module"
PING_CLIENT_CMD="docker exec test-hicn \
/hicn-build/build/build-root/bin/hicn-ping-client \
-z hicnlightng_module"
PING_CLIENT_DETACHED_CMD="docker exec -d test-hicn \
/hicn-build/build/build-root/bin/hicn-ping-client \
-z hicnlightng_module"
LISTENER_NAME="udp0"
CONN_NAME="conn0"
PREFIX="c001::/64"
COST=1
FIVE_SECONDS=5000
############################################################################
# UTILS
############################################################################
set_up() {
docker build -t hicn-dev .
run_forwarder
}
tear_down() {
docker stop --time 0 test-hicn
}
get_address() {
echo $(docker exec test-hicn sh -c "${ADDRESS_CMD}")
}
get_interface() {
echo $(docker exec test-hicn sh -c "${INTERFACE_CMD}")
}
#---------------------------------------------------------------------------
# Exec
#---------------------------------------------------------------------------
run_forwarder() {
capacity=${1:-"100000"}
loglevel=${2:-"trace"}
config=${3:-""}
config_file_arg=""
if [[ $config != "" ]]; then
config_file_arg="--config ${config}"
fi
docker run --rm -d --name test-hicn \
-v $(pwd)/..:/hicn-build \
-e LD_LIBRARY_PATH=/hicn-build/build/build-root/lib \
hicn-dev \
/hicn-build/build/build-root/bin/hicn-light-daemon \
--log ${loglevel} --capacity ${capacity} $config_file_arg
}
exec_controller() {
command=$1
# Redirect stderr to stdout
output=$(${CTRL_CMD} ${command} 2>&1)
assert_exit_code
echo ${output}
}
exec_ping_server() {
data_lifetime=${1:-""}
lifetime_arg=""
if [[ $data_lifetime != "" ]]; then
lifetime_arg="-l ${data_lifetime}"
fi
${PING_SERVER_CMD} ${lifetime_arg}
}
exec_ping_client() {
num_packets=$1
output=$(${PING_CLIENT_CMD} -m ${num_packets})
assert_exit_code
echo ${output}
}
exec_ping_client_detached() {
num_packets=$1
interest_lifetime=$2
${PING_CLIENT_DETACHED_CMD} -m ${num_packets} -l ${interest_lifetime}
}
#---------------------------------------------------------------------------
# Asserts
#---------------------------------------------------------------------------
assert_exit_code() {
if [[ $? -ne 0 ]]; then
exit_with_failure
fi
}
assert_forwarder() {
# Print forwarder logs for debug info
echo "******** Forwarder Logs ********"
docker logs test-hicn
echo "********************************"
output=$(docker logs test-hicn)
if [[ $output == "" ]]; then
exit_with_failure
fi
if [[ "${output}" == *"ERROR"* ]]; then
exit_with_failure
fi
if [[ "${output}" == *"Aborted (core dumped)"* ]]; then
exit_with_failure
fi
}
assert_ack() {
# Print controller logs for debug info
echo "******** Controller Logs ********"
echo $1
echo "********************************"
output=$1
if [[ "$output" == *"Error"* ]]; then
exit_with_failure
fi
}
assert_nack() {
# Print controller logs for debug info
echo "******** Controller Logs ********"
echo $1
echo "********************************"
output=$1
if [[ "$output" != *"Error"* ]]; then
exit_with_failure
fi
}
assert_ping_client() {
# Print ping client logs for debug info
echo "******** Ping Client Logs ********"
echo $1
echo "********************************"
ping_client_output=$1
pkts_sent=$2
pkts_recv=$3
pkts_timeout=$4
match_str="Sent: ${pkts_sent} Received: ${pkts_recv} Timeouts: ${pkts_timeout}"
if [[ ! ${ping_client_output} == *"${match_str}"* ]]; then
exit_with_failure
fi
}
assert_forwarder_stats() {
satisfied_from_cs=${1:-""}
no_route_in_fib=${2:-""}
aggregated=${3:-""}
fwder_stats=$(docker logs test-hicn | grep "Forwarder: received" | tail -n 1)
if [[ $satisfied_from_cs != "" &&
"${fwder_stats}" != *"satisfied_from_cs = ${satisfied_from_cs}"* ]]; then
exit_with_failure
fi
if [[ $no_route_in_fib != "" &&
"${fwder_stats}" != *"no_route_in_fib = ${no_route_in_fib}"* ]]; then
exit_with_failure
fi
if [[ $aggregated != "" &&
"${fwder_stats}" != *"aggregated = ${aggregated}"* ]]; then
exit_with_failure
fi
}
assert_pkt_cache_stats() {
total_size=${1:-""}
pit_size=${2:-""}
cs_size=${3:-""}
pkt_cache_stats=$(docker logs test-hicn | grep "Packet cache:" | tail -n 1)
if [[ $total_size != "" &&
"${pkt_cache_stats}" != *"total size = ${total_size}"* ]]; then
exit_with_failure
fi
if [[ $pit_size != "" &&
"${pkt_cache_stats}" != *"PIT size = ${pit_size}"* ]]; then
exit_with_failure
fi
if [[ $cs_size != "" &&
"${pkt_cache_stats}" != *"CS size = ${cs_size}"* ]]; then
exit_with_failure
fi
}
assert_cs_stats() {
evictions=${1:-""}
cs_stats=$(docker logs test-hicn | grep "Content store:" | tail -n 1)
if [[ $evictions != "" &&
"${cs_stats}" != *"evictions = ${evictions}"* ]]; then
exit_with_failure
fi
}
############################################################################
# TEST SUITE
############################################################################
#---------------------------------------------------------------------------
# Commands
#---------------------------------------------------------------------------
test_add_listener() {
# Exec hicn-light-control command and capture its output
INTERFACE=$(get_interface)
ADDRESS=$(get_address)
command="add listener udp ${LISTENER_NAME} ${ADDRESS} 9695 ${INTERFACE}"
ctrl_output=$(exec_controller "${command}")
# Check hicn-light-control and hicn-light-daemon outputs
assert_ack "$ctrl_output"
assert_forwarder
}
test_remove_listener() {
INTERFACE=$(get_interface)
ADDRESS=$(get_address)
command="add listener udp ${LISTENER_NAME} ${ADDRESS} 9695 ${INTERFACE}"
ctrl_output=$(exec_controller "${command}")
assert_ack "$ctrl_output"
command="remove listener udp0"
ctrl_output=$(exec_controller "${command}")
assert_ack "$ctrl_output"
assert_forwarder
}
test_remove_non_existing_listener() {
command="remove listener udp0"
ctrl_output=$(exec_controller "${command}")
assert_nack "$ctrl_output"
assert_forwarder
}
test_add_duplicated_listener() {
# Exec hicn-light-control command and capture its output
INTERFACE=$(get_interface)
ADDRESS=$(get_address)
command="add listener udp ${LISTENER_NAME} ${ADDRESS} 9695 ${INTERFACE}"
exec_controller "${command}"
ctrl_output=$(exec_controller "${command}")
# Check hicn-light-control and hicn-light-daemon outputs
assert_nack "$ctrl_output"
assert_forwarder
}
test_list_listeners() {
# Exec hicn-light-control command and capture its output
command="list listener"
ctrl_output=$(exec_controller "${command}")
# Check hicn-light-control and hicn-light-daemon outputs
assert_forwarder
# Only the local listener should be present
[[ "${ctrl_output}" =~ "inet4://127.0.0.1:9695" ]] && return 0 || exit_with_failure
}
test_commands_from_config() {
# Create config file
INTERFACE=$(get_interface)
ADDRESS=$(get_address)
echo "# Teset config file
add listener udp $LISTENER_NAME $ADDRESS 9695 ${INTERFACE}
add connection udp $CONN_NAME $ADDRESS 12345 $ADDRESS 9695 ${INTERFACE}
add route $CONN_NAME $PREFIX $COST
set strategy c001::/64 random
" >forwarder.conf
# Restart the forwarder specifying the config file
tear_down
run_forwarder "" "" "/hicn-build/tests/forwarder.conf"
rm forwarder.conf
# Check for errors in the output
assert_forwarder
}
#---------------------------------------------------------------------------
# Ping
#---------------------------------------------------------------------------
test_ping_one_packet() {
# Exec hicn-ping-server
exec_ping_server
# Exec hicn-ping-client (w/ 1 packet) and capture its output
output=$(exec_ping_client 1)
# Check hicn-ping-client (1 pkt sent, 1 pkt received, 0 timeouts)
# and hicn-light-daemon outputs
assert_ping_client "${output}" 1 1 0
assert_forwarder
}
test_ping_two_packets() {
exec_ping_server
output=$(exec_ping_client 2)
assert_ping_client "${output}" 2 2 0
assert_forwarder
}
test_ping_using_cs() {
exec_ping_server
exec_ping_client 2
output=$(exec_ping_client 1)
assert_ping_client "${output}" 1 1 0
assert_forwarder
assert_forwarder_stats 1
}
test_ping_using_cs_different_order() {
exec_ping_server
exec_ping_client 1
output=$(exec_ping_client 2)
assert_ping_client "${output}" 2 2 0
assert_forwarder
assert_forwarder_stats 1
}
test_ping_timeout() {
# Send ping without the ping server being run
output=$(exec_ping_client 1)
assert_ping_client "${output}" 1 0 1
assert_forwarder
assert_forwarder_stats 0 1
}
test_ping_aggregation() {
# Send ping without server, waiting for a reply
exec_ping_client_detached 1 ${FIVE_SECONDS}
exec_ping_server
# This new ping interest will be aggregated with the previous one
# and the forwarder will reply to both ping clients
output=$(exec_ping_client 1)
assert_ping_client "${output}" 1 1 0
assert_forwarder
assert_forwarder_stats "" "" 1
}
test_ping_with_cs_store_disabled() {
command="store cache off"
exec_controller "${command}"
exec_ping_server
exec_ping_client 1
output=$(exec_ping_client 1)
assert_ping_client "${output}" 1 1 0
assert_forwarder
assert_forwarder_stats 0 "" ""
# The packet is not stored in the CS
assert_pkt_cache_stats "" "" 0
}
test_ping_with_cs_serve_disabled() {
command="serve cache off"
exec_controller "${command}"
exec_ping_server
exec_ping_client 1
output=$(exec_ping_client 1)
assert_ping_client "${output}" 1 1 0
assert_forwarder
assert_forwarder_stats 0 "" ""
# The packet is stored in the CS, but CS is not used
assert_pkt_cache_stats "" "" 1
}
test_ping_with_eviction() {
# Restart the forwarder with CS capacity = 1
tear_down
run_forwarder 1
exec_ping_server
exec_ping_client 1
output=$(exec_ping_client 2)
assert_ping_client "${output}" 2 2 0
assert_forwarder
# Check if eviction happened
assert_cs_stats 1
assert_pkt_cache_stats "" "" 1
}
test_ping_with_zero_data_lifetime() {
exec_ping_server 0
exec_ping_client 1
output=$(exec_ping_client 1)
assert_ping_client "${output}" 1 1 0
assert_forwarder
# The data is not taken from the CS because expired
assert_forwarder_stats 0 "" ""
}
"$@"
|