Skip to content

Commit cb6b392

Browse files
Merge pull request #75 from CESNET/main
update staging
2 parents 13cca09 + c3f5e5c commit cb6b392

6 files changed

Lines changed: 84 additions & 7 deletions

File tree

modules/deduplicator/src/deduplicator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Deduplicator {
4646
std::function<bool(const Timestamp&, const Timestamp&)>,
4747
std::function<Timestamp(const Timestamp&, uint64_t)>>;
4848

49-
static inline const int DEFAULT_HASHMAP_TIMEOUT = 5000; ///< Default timeout - 5s
49+
static inline const uint64_t DEFAULT_HASHMAP_TIMEOUT = 5000; ///< Default timeout - 5s
5050

5151
/**
5252
* @brief Deduplicator constructor

modules/deduplicator/src/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ int main(int argc, char** argv)
112112
try {
113113
program.add_argument("-s", "--size")
114114
.required()
115-
.help("Size of the hash map. Default value is 2^20 for 1'048'576 records.")
115+
.help("Exponent N for the hash map size (2^N entries). Default: 20 (~1 048 576).")
116116
.default_value(Deduplicator::Deduplicator::DeduplicatorHashMap::
117117
TimeoutHashMapParameters::DEFAULT_HASHMAP_EXPONENT)
118-
.scan<'i', int>();
118+
.scan<'u', uint32_t>();
119119
program.add_argument("-t", "--timeout")
120120
.required()
121121
.help(
122-
"Count of millisecond to consider flows as duplicates. Default value is 5000(5s).")
122+
"Count of millisecond to consider flows as duplicates. Default value is 5000 (5s).")
123123
.default_value(Deduplicator::Deduplicator::DEFAULT_HASHMAP_TIMEOUT)
124-
.scan<'i', int>();
124+
.scan<'u', uint64_t>();
125125
program.add_argument("-m", "--appfs-mountpoint")
126126
.required()
127127
.help("path where the appFs directory will be mounted")
@@ -161,7 +161,7 @@ int main(int argc, char** argv)
161161
std::cerr << "Table size must be at least 8.\n";
162162
return EXIT_FAILURE;
163163
}
164-
const auto timeout = program.get<uint32_t>("--timeout");
164+
const auto timeout = program.get<uint64_t>("--timeout");
165165
if (timeout <= 0) {
166166
std::cerr << "Timeout must be higher than zero.\n";
167167
return EXIT_FAILURE;
@@ -185,6 +185,7 @@ int main(int argc, char** argv)
185185
biInterface.setRequieredFormat(
186186
"uint16 SRC_PORT, uint16 DST_PORT, ipaddr DST_IP,ipaddr SRC_IP, uint64 LINK_BIT_FIELD, "
187187
"uint8 PROTOCOL, time TIME_LAST");
188+
deduplicator.updateUnirecIds();
188189
processUnirecRecords(biInterface, deduplicator);
189190

190191
} catch (std::exception& ex) {

modules/deduplicator/src/timeoutHashMap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class TimeoutHashMap {
212212
/**
213213
* @brief Default size for the hash map.
214214
*/
215-
static inline const int DEFAULT_HASHMAP_EXPONENT = 20; // 1'048'576 records
215+
static inline const uint32_t DEFAULT_HASHMAP_EXPONENT = 20; // 1'048'576 records
216216

217217
uint32_t bucketCountExponent; ///< Total amount of records in table
218218
uint64_t timeout; ///< Time interval to consider flow unique

modules/deduplicator/tests/test.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
function exit_with_error {
4+
pkill logger
5+
pkill logreplay
6+
pkill deduplicator
7+
exit 1
8+
}
9+
10+
function process_started {
11+
pid=$1
12+
if ! ps -p $pid > /dev/null
13+
then
14+
echo "Failed to start process"
15+
exit_with_error
16+
fi
17+
}
18+
19+
data_path="$(dirname "$0")/testsData/"
20+
deduplicator=$1
21+
22+
set -e
23+
trap 'echo "Command \"$BASH_COMMAND\" failed!"; exit_with_error' ERR
24+
for input_file in $data_path/inputs/*; do
25+
index=$(echo "$input_file" | grep -o '[0-9]\+')
26+
echo "Running test $index"
27+
28+
res_file="/tmp/res"
29+
logger -i "u:deduplicator" -w $res_file &
30+
logger_pid=$!
31+
sleep 0.1
32+
33+
process_started $logger_pid
34+
35+
$deduplicator \
36+
-i "u:din,u:deduplicator" &
37+
38+
detector_pid=$!
39+
sleep 0.1
40+
process_started $detector_pid
41+
42+
logreplay -i "u:din" -f "$data_path/inputs/input$index.csv" 2>/dev/null &
43+
sleep 0.1
44+
process_started $!
45+
46+
wait $logger_pid
47+
wait $detector_pid
48+
49+
if [ -f "$res_file" ]; then
50+
if ! cmp -s "$data_path/results/res$index.csv" "$res_file"; then
51+
echo "Files results/res$index.csv and $res_file are not equal"
52+
exit_with_error
53+
fi
54+
else
55+
echo "File $res_file not found"
56+
exit_with_error
57+
fi
58+
done
59+
60+
echo "All tests passed"
61+
exit 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ipaddr SRC_IP, ipaddr DST_IP, uint16 SRC_PORT, uint16 DST_PORT, uint8 PROTOCOL, uint64 LINK_BIT_FIELD, time TIME_LAST
2+
154.175.219.8,155.175.219.8,123,123,6,10,2020-01-01T00:00:01Z
3+
54.175.29.123,54.175.219.24,123,80,6,10,2020-01-01T00:00:02Z
4+
54.175.21.66,54.175.219.77,443,22,6,10,2020-01-01T00:00:03Z
5+
54.175.3.17,54.175.219.99,8080,53,17,10,2020-01-01T00:00:04Z
6+
154.175.219.8,155.175.219.8,123,123,6,10,2020-01-01T00:00:01Z
7+
154.175.219.8,155.175.219.8,123,123,6,11,2020-01-01T00:00:01Z
8+
154.175.219.8,155.175.219.8,123,123,6,10,2020-01-01T00:00:01Z
9+
154.175.219.8,155.175.219.8,123,123,6,11,2020-01-01T00:00:01Z
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
155.175.219.8,154.175.219.8,10,2020-01-01T00:00:01.000000,123,123,6
2+
54.175.219.24,54.175.29.123,10,2020-01-01T00:00:02.000000,80,123,6
3+
54.175.219.77,54.175.21.66,10,2020-01-01T00:00:03.000000,22,443,6
4+
54.175.219.99,54.175.3.17,10,2020-01-01T00:00:04.000000,53,8080,17
5+
155.175.219.8,154.175.219.8,10,2020-01-01T00:00:01.000000,123,123,6
6+
155.175.219.8,154.175.219.8,10,2020-01-01T00:00:01.000000,123,123,6

0 commit comments

Comments
 (0)