Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
500d672c
Commit
500d672c
authored
Dec 20, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for UDP ordering
parent
8164dc6a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
176 additions
and
18 deletions
+176
-18
libcaf_io/caf/io/network/test_multiplexer.hpp
libcaf_io/caf/io/network/test_multiplexer.hpp
+6
-2
libcaf_io/src/instance.cpp
libcaf_io/src/instance.cpp
+17
-14
libcaf_io/src/test_multiplexer.cpp
libcaf_io/src/test_multiplexer.cpp
+9
-2
libcaf_io/test/basp.cpp
libcaf_io/test/basp.cpp
+144
-0
No files found.
libcaf_io/caf/io/network/test_multiplexer.hpp
View file @
500d672c
...
@@ -120,6 +120,12 @@ public:
...
@@ -120,6 +120,12 @@ public:
/// input buffer usually managed by the operating system.
/// input buffer usually managed by the operating system.
buffer_type
&
virtual_network_buffer
(
dgram_scribe_handle
hdl
);
buffer_type
&
virtual_network_buffer
(
dgram_scribe_handle
hdl
);
/// Models pending data on the network, i.e., the network
/// input buffer usually manged by the operating system.
/// Allows enqueueing messages to the front to allow
/// simulation of out of order delivery.
buffer_type
&
virtual_network_buffer_front
(
dgram_scribe_handle
hdl
);
/// Models pending data on the network, i.e., the network
/// Models pending data on the network, i.e., the network
/// input buffer usually managed by the operating system.
/// input buffer usually managed by the operating system.
buffer_type
&
virtual_network_buffer
(
dgram_doorman_handle
hdl
);
buffer_type
&
virtual_network_buffer
(
dgram_doorman_handle
hdl
);
...
@@ -302,8 +308,6 @@ private:
...
@@ -302,8 +308,6 @@ private:
uint16_t
local_port
;
uint16_t
local_port
;
std
::
deque
<
buffer_type
>
xbuf
;
std
::
deque
<
buffer_type
>
xbuf
;
std
::
deque
<
buffer_type
>
wr_buf
;
std
::
deque
<
buffer_type
>
wr_buf
;
//buffer_type xbuf;
//buffer_type wr_buf;
buffer_type
rd_buf
;
buffer_type
rd_buf
;
size_t
rcv_buffer_size
=
1500
;
size_t
rcv_buffer_size
=
1500
;
bool
stopped_reading
=
false
;
bool
stopped_reading
=
false
;
...
...
libcaf_io/src/instance.cpp
View file @
500d672c
...
@@ -58,6 +58,9 @@ bool instance::deliver_pending(execution_unit* ctx, endpoint_context& ep) {
...
@@ -58,6 +58,9 @@ bool instance::deliver_pending(execution_unit* ctx, endpoint_context& ep) {
std
::
vector
<
char
>*
payload
=
nullptr
;
std
::
vector
<
char
>*
payload
=
nullptr
;
auto
itr
=
ep
.
pending
.
find
(
ep
.
seq_incoming
);
auto
itr
=
ep
.
pending
.
find
(
ep
.
seq_incoming
);
while
(
itr
!=
ep
.
pending
.
end
())
{
while
(
itr
!=
ep
.
pending
.
end
())
{
//std::cerr << "[++] '" << to_string(itr->second.first.operation)
// << "' with seq '" << itr->second.first.sequence_number
// << "' (was pending)" << std::endl;
ep
.
hdr
=
std
::
move
(
itr
->
second
.
first
);
ep
.
hdr
=
std
::
move
(
itr
->
second
.
first
);
payload
=
&
itr
->
second
.
second
;
payload
=
&
itr
->
second
.
second
;
if
(
!
handle_msg
(
ctx
,
get
<
dgram_scribe_handle
>
(
ep
.
hdl
),
if
(
!
handle_msg
(
ctx
,
get
<
dgram_scribe_handle
>
(
ep
.
hdl
),
...
@@ -160,7 +163,7 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm,
...
@@ -160,7 +163,7 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm,
auto
e
=
bd
(
ep
.
hdr
);
auto
e
=
bd
(
ep
.
hdr
);
if
(
e
||
!
valid
(
ep
.
hdr
))
{
if
(
e
||
!
valid
(
ep
.
hdr
))
{
CAF_LOG_WARNING
(
"received invalid header:"
<<
CAF_ARG
(
ep
.
hdr
));
CAF_LOG_WARNING
(
"received invalid header:"
<<
CAF_ARG
(
ep
.
hdr
));
std
::
cerr
<<
"[!!] invalid header!"
<<
std
::
endl
;
//
std::cerr << "[!!] invalid header!" << std::endl;
return
err
();
return
err
();
}
}
CAF_LOG_DEBUG
(
CAF_ARG
(
ep
.
hdr
));
CAF_LOG_DEBUG
(
CAF_ARG
(
ep
.
hdr
));
...
@@ -173,12 +176,12 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm,
...
@@ -173,12 +176,12 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm,
}
}
}
}
// TODO: Ordering
// TODO: Ordering
std
::
cerr
<<
"[<<] '"
<<
to_string
(
ep
.
hdr
.
operation
)
//
std::cerr << "[<<] '" << to_string(ep.hdr.operation)
<<
"' with seq '"
<<
ep
.
hdr
.
sequence_number
<<
"'"
<<
std
::
endl
;
//
<< "' with seq '" << ep.hdr.sequence_number << "'" << std::endl;
if
(
ep
.
hdr
.
sequence_number
!=
ep
.
seq_incoming
)
{
if
(
ep
.
hdr
.
sequence_number
!=
ep
.
seq_incoming
)
{
std
::
cerr
<<
"[!!] '"
<<
to_string
(
ep
.
hdr
.
operation
)
<<
"' with seq '"
//
std::cerr << "[!!] '" << to_string(ep.hdr.operation) << "' with seq '"
<<
ep
.
hdr
.
sequence_number
<<
"' (!= "
<<
ep
.
seq_incoming
//
<< ep.hdr.sequence_number << "' (!= " << ep.seq_incoming
<<
")"
<<
std
::
endl
;
//
<< ")" << std::endl;
auto
s
=
ep
.
hdr
.
sequence_number
;
auto
s
=
ep
.
hdr
.
sequence_number
;
auto
h
=
std
::
move
(
ep
.
hdr
);
auto
h
=
std
::
move
(
ep
.
hdr
);
auto
b
=
std
::
move
(
pl_buf
);
auto
b
=
std
::
move
(
pl_buf
);
...
@@ -220,18 +223,18 @@ bool instance::handle(execution_unit* ctx, new_endpoint_msg& em,
...
@@ -220,18 +223,18 @@ bool instance::handle(execution_unit* ctx, new_endpoint_msg& em,
// client handshake for UDP should be sequence number 0
// client handshake for UDP should be sequence number 0
if
(
e
||
!
valid
(
ep
.
hdr
))
{
if
(
e
||
!
valid
(
ep
.
hdr
))
{
CAF_LOG_WARNING
(
"received invalid header:"
<<
CAF_ARG
(
ep
.
hdr
));
CAF_LOG_WARNING
(
"received invalid header:"
<<
CAF_ARG
(
ep
.
hdr
));
std
::
cerr
<<
"[<<] invalid header!"
<<
std
::
endl
;
//
std::cerr << "[<<] invalid header!" << std::endl;
return
err
();
return
err
();
}
}
if
(
ep
.
hdr
.
sequence_number
!=
ep
.
seq_incoming
)
{
if
(
ep
.
hdr
.
sequence_number
!=
ep
.
seq_incoming
)
{
CAF_LOG_WARNING
(
"Handshake with unexected sequence number: "
CAF_LOG_WARNING
(
"Handshake with unexected sequence number: "
<<
CAF_ARG
(
ep
.
hdr
.
sequence_number
));
<<
CAF_ARG
(
ep
.
hdr
.
sequence_number
));
std
::
cerr
<<
"[<<] Unexpected sequence number '"
<<
ep
.
hdr
.
sequence_number
//
std::cerr << "[<<] Unexpected sequence number '" << ep.hdr.sequence_number
<<
"'in client handshake"
<<
std
::
endl
;
//
<< "'in client handshake" << std::endl;
ep
.
seq_incoming
=
ep
.
hdr
.
sequence_number
+
1
;
ep
.
seq_incoming
=
ep
.
hdr
.
sequence_number
+
1
;
}
else
{
}
else
{
std
::
cerr
<<
"[<<] '"
<<
to_string
(
ep
.
hdr
.
operation
)
<<
"' with seq '"
//
std::cerr << "[<<] '" << to_string(ep.hdr.operation) << "' with seq '"
<<
ep
.
hdr
.
sequence_number
<<
"'"
<<
std
::
endl
;
//
<< ep.hdr.sequence_number << "'" << std::endl;
ep
.
seq_incoming
+=
1
;
ep
.
seq_incoming
+=
1
;
}
}
CAF_LOG_DEBUG
(
CAF_ARG
(
ep
.
hdr
));
CAF_LOG_DEBUG
(
CAF_ARG
(
ep
.
hdr
));
...
@@ -369,9 +372,9 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
...
@@ -369,9 +372,9 @@ bool instance::dispatch(execution_unit* ctx, const strong_actor_ptr& sender,
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
void
instance
::
write
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
header
&
hdr
,
payload_writer
*
pw
)
{
header
&
hdr
,
payload_writer
*
pw
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
));
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
));
std
::
cerr
<<
"[>>] '"
<<
to_string
(
hdr
.
operation
)
//
std::cerr << "[>>] '" << to_string(hdr.operation)
<<
"' with seq '"
<<
hdr
.
sequence_number
<<
"'"
//
<< "' with seq '" << hdr.sequence_number << "'"
<<
std
::
endl
;
//
<< std::endl;
error
err
;
error
err
;
if
(
pw
)
{
if
(
pw
)
{
auto
pos
=
buf
.
size
();
auto
pos
=
buf
.
size
();
...
...
libcaf_io/src/test_multiplexer.cpp
View file @
500d672c
...
@@ -444,8 +444,8 @@ void test_multiplexer::provide_acceptor(uint16_t desired_port,
...
@@ -444,8 +444,8 @@ void test_multiplexer::provide_acceptor(uint16_t desired_port,
}
}
void
test_multiplexer
::
provide_dgram_scribe
(
std
::
string
host
,
void
test_multiplexer
::
provide_dgram_scribe
(
std
::
string
host
,
uint16_t
desired_port
,
uint16_t
desired_port
,
dgram_scribe_handle
hdl
)
{
dgram_scribe_handle
hdl
)
{
dgram_scribes_
.
emplace
(
std
::
make_pair
(
std
::
move
(
host
),
desired_port
),
hdl
);
dgram_scribes_
.
emplace
(
std
::
make_pair
(
std
::
move
(
host
),
desired_port
),
hdl
);
dgram_scribe_data_
[
hdl
].
remote_port
=
desired_port
;
dgram_scribe_data_
[
hdl
].
remote_port
=
desired_port
;
}
}
...
@@ -471,6 +471,13 @@ test_multiplexer::virtual_network_buffer(dgram_scribe_handle hdl) {
...
@@ -471,6 +471,13 @@ test_multiplexer::virtual_network_buffer(dgram_scribe_handle hdl) {
return
buf
.
back
();
return
buf
.
back
();
}
}
test_multiplexer
::
buffer_type
&
test_multiplexer
::
virtual_network_buffer_front
(
dgram_scribe_handle
hdl
)
{
auto
&
buf
=
dgram_scribe_data_
[
hdl
].
xbuf
;
buf
.
emplace_front
();
return
buf
.
front
();
}
test_multiplexer
::
buffer_type
&
test_multiplexer
::
buffer_type
&
test_multiplexer
::
virtual_network_buffer
(
dgram_doorman_handle
hdl
)
{
test_multiplexer
::
virtual_network_buffer
(
dgram_doorman_handle
hdl
)
{
auto
&
buf
=
dgram_doorman_data_
[
hdl
].
xbuf
;
auto
&
buf
=
dgram_doorman_data_
[
hdl
].
xbuf
;
...
...
libcaf_io/test/basp.cpp
View file @
500d672c
...
@@ -540,6 +540,36 @@ public:
...
@@ -540,6 +540,36 @@ public:
return
*
this
;
return
*
this
;
}
}
template
<
class
...
Ts
>
mock_t
&
enqueue_back
(
dgram_scribe_handle
hdl
,
basp
::
header
hdr
,
const
Ts
&
...
xs
)
{
buffer
buf
;
this_
->
to_buf
(
buf
,
hdr
,
nullptr
,
xs
...);
CAF_MESSAGE
(
"adding msg "
<<
to_string
(
hdr
.
operation
)
<<
" with "
<<
(
buf
.
size
()
-
basp
::
header_size
)
<<
" bytes payload to back of queue"
);
this_
->
mpx
()
->
virtual_network_buffer
(
hdl
)
=
buf
;
return
*
this
;
}
template
<
class
...
Ts
>
mock_t
&
enqueue_front
(
dgram_scribe_handle
hdl
,
basp
::
header
hdr
,
const
Ts
&
...
xs
)
{
buffer
buf
;
this_
->
to_buf
(
buf
,
hdr
,
nullptr
,
xs
...);
CAF_MESSAGE
(
"adding msg "
<<
to_string
(
hdr
.
operation
)
<<
" with "
<<
(
buf
.
size
()
-
basp
::
header_size
)
<<
" bytes payload to front of queue"
);
this_
->
mpx
()
->
virtual_network_buffer_front
(
hdl
)
=
buf
;
return
*
this
;
}
mock_t
&
deliver
(
dgram_scribe_handle
hdl
,
size_t
num_messages
=
1
)
{
for
(
size_t
i
=
0
;
i
<
num_messages
;
++
i
)
this_
->
mpx
()
->
read_datagram
(
hdl
);
return
*
this
;
}
private:
private:
fixture
*
this_
;
fixture
*
this_
;
size_t
num
=
1
;
size_t
num
=
1
;
...
@@ -1180,6 +1210,120 @@ CAF_TEST(remote_actor_and_send_udp) {
...
@@ -1180,6 +1210,120 @@ CAF_TEST(remote_actor_and_send_udp) {
);
);
}
}
CAF_TEST
(
out_of_order_delivery_udp
)
{
constexpr
const
char
*
prot
=
"udp"
;
constexpr
const
char
*
lo
=
"localhost"
;
constexpr
uint16_t
port
=
4242
;
auto
u
=
uri
::
make
(
std
::
string
(
prot
)
+
"://"
+
std
::
string
(
lo
)
+
":"
+
std
::
to_string
(
port
));
CAF_REQUIRE
(
u
);
CAF_MESSAGE
(
"self: "
<<
to_string
(
self
()
->
address
()));
mpx
()
->
provide_dgram_scribe
(
lo
,
4242
,
jupiter
().
connection
);
CAF_REQUIRE
(
mpx
()
->
has_pending_dgram_scribe
(
lo
,
4242
));
auto
mm1
=
system
.
middleman
().
actor_handle
();
actor
result
;
auto
f
=
self
()
->
request
(
mm1
,
infinite
,
connect_atom
::
value
,
*
u
);
// wait until BASP broker has received and processed the connect message
while
(
!
aut
()
->
valid
(
jupiter
().
connection
))
mpx
()
->
exec_runnable
();
CAF_REQUIRE
(
!
mpx
()
->
has_pending_dgram_scribe
(
lo
,
4242
));
// build a fake server handshake containing the id of our first pseudo actor
CAF_MESSAGE
(
"server handshake => client handshake + proxy announcement"
);
auto
na
=
registry
()
->
named_actors
();
mock
(
jupiter
().
connection
,
{
basp
::
message_type
::
server_handshake
,
0
,
0
,
basp
::
version
,
jupiter
().
id
,
none
,
jupiter
().
dummy_actor
->
id
(),
invalid_actor_id
},
std
::
string
{},
jupiter
().
dummy_actor
->
id
(),
uint32_t
{
0
})
.
expect
(
jupiter
().
connection
,
basp
::
message_type
::
client_handshake
,
no_flags
,
1u
,
no_operation_data
,
this_node
(),
node_id
{
none
},
invalid_actor_id
,
invalid_actor_id
,
std
::
string
{})
.
expect
(
jupiter
().
connection
,
basp
::
message_type
::
dispatch_message
,
basp
::
header
::
named_receiver_flag
,
any_vals
,
no_operation_data
,
this_node
(),
jupiter
().
id
,
any_vals
,
invalid_actor_id
,
spawn_serv_atom
,
std
::
vector
<
actor_id
>
{},
make_message
(
sys_atom
::
value
,
get_atom
::
value
,
"info"
))
.
expect
(
jupiter
().
connection
,
basp
::
message_type
::
announce_proxy
,
no_flags
,
no_payload
,
no_operation_data
,
this_node
(),
jupiter
().
id
,
invalid_actor_id
,
jupiter
().
dummy_actor
->
id
());
CAF_MESSAGE
(
"BASP broker should've send the proxy"
);
f
.
receive
(
[
&
](
node_id
nid
,
strong_actor_ptr
res
,
std
::
set
<
std
::
string
>
ifs
)
{
CAF_REQUIRE
(
res
);
auto
aptr
=
actor_cast
<
abstract_actor
*>
(
res
);
CAF_REQUIRE
(
dynamic_cast
<
forwarding_actor_proxy
*>
(
aptr
)
!=
nullptr
);
CAF_CHECK_EQUAL
(
proxies
().
count_proxies
(
jupiter
().
id
),
1u
);
CAF_CHECK_EQUAL
(
nid
,
jupiter
().
id
);
CAF_CHECK_EQUAL
(
res
->
node
(),
jupiter
().
id
);
CAF_CHECK_EQUAL
(
res
->
id
(),
jupiter
().
dummy_actor
->
id
());
CAF_CHECK
(
ifs
.
empty
());
auto
proxy
=
proxies
().
get
(
jupiter
().
id
,
jupiter
().
dummy_actor
->
id
());
CAF_REQUIRE
(
proxy
!=
nullptr
);
CAF_REQUIRE
(
proxy
==
res
);
result
=
actor_cast
<
actor
>
(
res
);
},
[
&
](
error
&
err
)
{
CAF_FAIL
(
"error: "
<<
system
.
render
(
err
));
}
);
CAF_MESSAGE
(
"send message to proxy"
);
anon_send
(
actor_cast
<
actor
>
(
result
),
42
);
mpx
()
->
flush_runnables
();
mock
()
.
expect
(
jupiter
().
connection
,
basp
::
message_type
::
dispatch_message
,
no_flags
,
any_vals
,
no_operation_data
,
this_node
(),
jupiter
().
id
,
invalid_actor_id
,
jupiter
().
dummy_actor
->
id
(),
std
::
vector
<
actor_id
>
{},
make_message
(
42
));
// auto msg = make_message("hi there!");
uint16_t
seq_number
=
1
;
auto
next_hdr
=
[
&
]()
->
basp
::
header
{
return
{
basp
::
message_type
::
dispatch_message
,
0
,
0
,
0
,
jupiter
().
id
,
this_node
(),
jupiter
().
dummy_actor
->
id
(),
self
()
->
id
(),
seq_number
++
};
};
mock
()
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
0
))
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
1
))
.
enqueue_front
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
2
))
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
3
))
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
4
))
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
5
))
.
enqueue_front
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
6
))
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
7
))
.
enqueue_back
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
8
))
.
enqueue_front
(
jupiter
().
connection
,
next_hdr
(),
std
::
vector
<
actor_id
>
{},
make_message
(
9
))
.
deliver
(
jupiter
().
connection
,
10
);
int
expected_next
=
0
;
self
()
->
receive_while
([
&
]
{
return
expected_next
<
9
;
})
(
[
&
](
int
val
)
{
CAF_CHECK_EQUAL
(
to_string
(
self
()
->
current_sender
()),
to_string
(
result
));
CAF_CHECK_EQUAL
(
self
()
->
current_sender
(),
result
.
address
());
CAF_CHECK_EQUAL
(
expected_next
,
val
);
++
expected_next
;
}
);
}
CAF_TEST
(
actor_serialize_and_deserialize_udp
)
{
CAF_TEST
(
actor_serialize_and_deserialize_udp
)
{
auto
testee_impl
=
[](
event_based_actor
*
testee_self
)
->
behavior
{
auto
testee_impl
=
[](
event_based_actor
*
testee_self
)
->
behavior
{
testee_self
->
set_default_handler
(
reflect_and_quit
);
testee_self
->
set_default_handler
(
reflect_and_quit
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment