Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tansiv
TANSIV
Commits
7057d35c
Verified
Commit
7057d35c
authored
Apr 21, 2020
by
SIMONIN Matthieu
Browse files
vsg: add src, dst in header for Send and Deliver
align names: dst is 3 letters (not dest, 4 letters)
parent
12781f3d
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/fake-vm/capi/src/lib.rs
View file @
7057d35c
...
...
@@ -107,7 +107,7 @@ pub unsafe extern fn vsg_gettimeofday(context: *const Context, timeval: *mut lib
}
}
/// Sends a message having source address `src`, destination address `d
e
st` and a payload stored in
/// Sends a message having source address `src`, destination address `dst` and a payload stored in
/// `msg[0..msglen]`.
///
/// # Safety
...
...
@@ -125,7 +125,7 @@ pub unsafe extern fn vsg_gettimeofday(context: *const Context, timeval: *mut lib
///
/// * Fails with `libc::ENOMEM` whenever there is no more buffers to hold the message to send.
#[no_mangle]
pub
unsafe
extern
fn
vsg_send
(
context
:
*
const
Context
,
d
e
st
:
VsgAddress
,
msglen
:
u32
,
msg
:
*
const
u8
)
->
c_int
{
pub
unsafe
extern
fn
vsg_send
(
context
:
*
const
Context
,
dst
:
VsgAddress
,
msglen
:
u32
,
msg
:
*
const
u8
)
->
c_int
{
if
let
Some
(
context
)
=
context
.as_ref
()
{
// We can tolerate msg.is_null() if msglen == 0 but std::slice::from_raw_parts() requires
// non null pointers.
...
...
@@ -139,7 +139,7 @@ pub unsafe extern fn vsg_send(context: *const Context, dest: VsgAddress, msglen:
};
let
payload
=
std
::
slice
::
from_raw_parts
(
ptr
,
msglen
as
usize
);
match
(
*
context
)
.send
(
d
e
st
,
payload
)
{
match
(
*
context
)
.send
(
dst
,
payload
)
{
Ok
(
_
)
=>
0
,
Err
(
e
)
=>
match
e
{
Error
::
NoMemoryAvailable
=>
libc
::
ENOMEM
,
...
...
@@ -154,14 +154,14 @@ pub unsafe extern fn vsg_send(context: *const Context, dest: VsgAddress, msglen:
}
/// Picks the next message in the receive queue, stores its payload in `msg[0..*msglen]` and
/// optionnally returns sender and destination addresses in `*psrc` and `*pd
e
st` respectively. The
/// optionnally returns sender and destination addresses in `*psrc` and `*pdst` respectively. The
/// actual length of the received payload is stored in `*msglen`.
///
/// # Safety
///
/// * `context` should point to a valid context, as previously returned by [`vsg_init`].
///
/// * `psrc` and `pd
e
st` can be `NULL`, in which case the correponding addresses will not be returned.
/// * `psrc` and `pdst` can be `NULL`, in which case the correponding addresses will not be returned.
///
/// * If `msglen` is `NULL` or `*msglen` is `0`, only 0-length messages can be received. Note that
/// in that case it is allowed that `msg` is `NULL` too.
...
...
@@ -175,7 +175,7 @@ pub unsafe extern fn vsg_send(context: *const Context, dest: VsgAddress, msglen:
/// * Fails with `libc::EMSGSIZE` whenever the next message in the queue has a payload bigger than
/// the provided buffer. The message is lost.
#[no_mangle]
pub
unsafe
extern
fn
vsg_recv
(
context
:
*
const
Context
,
psrc
:
*
mut
VsgAddress
,
pd
e
st
:
*
mut
VsgAddress
,
msglen
:
*
mut
u32
,
msg
:
*
mut
u8
)
->
c_int
{
pub
unsafe
extern
fn
vsg_recv
(
context
:
*
const
Context
,
psrc
:
*
mut
VsgAddress
,
pdst
:
*
mut
VsgAddress
,
msglen
:
*
mut
u32
,
msg
:
*
mut
u8
)
->
c_int
{
const_assert!
(
fake_vm
::
MAX_PACKET_SIZE
<=
std
::
u32
::
MAX
as
usize
);
if
let
Some
(
context
)
=
context
.as_ref
()
{
...
...
@@ -197,12 +197,12 @@ pub unsafe extern fn vsg_recv(context: *const Context, psrc: *mut VsgAddress, pd
let
payload
=
std
::
slice
::
from_raw_parts_mut
(
ptr
,
len
as
usize
);
match
(
*
context
)
.recv
(
payload
)
{
Ok
((
src
,
d
e
st
,
payload
))
=>
{
Ok
((
src
,
dst
,
payload
))
=>
{
if
!
psrc
.is_null
()
{
*
psrc
=
src
;
}
if
!
pd
e
st
.is_null
()
{
*
pd
e
st
=
d
e
st
;
if
!
pdst
.is_null
()
{
*
pdst
=
dst
;
}
if
!
msglen
.is_null
()
{
*
msglen
=
payload
.len
()
as
u32
;
...
...
@@ -545,8 +545,8 @@ mod test {
assert_eq!
(
0
,
res
);
let
buffer
=
b"Foo msg"
;
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -568,8 +568,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_start
(
context
)
};
assert_eq!
(
0
,
res
);
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
0
,
std
::
ptr
::
null
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
0
,
std
::
ptr
::
null
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -591,13 +591,13 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_start
(
context
)
};
assert_eq!
(
0
,
res
);
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
1
,
std
::
ptr
::
null
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
1
,
std
::
ptr
::
null
())
};
assert_eq!
(
libc
::
EINVAL
,
res
);
// Terminate gracefully
let
buffer
=
b"Foo msg"
;
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -620,13 +620,13 @@ mod test {
assert_eq!
(
0
,
res
);
let
buffer
=
[
0u8
;
fake_vm
::
MAX_PACKET_SIZE
+
1
];
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
buffer
.len
()
as
u32
,
(
&
buffer
)
.as_ptr
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
buffer
.len
()
as
u32
,
(
&
buffer
)
.as_ptr
())
};
assert_eq!
(
libc
::
EMSGSIZE
,
res
);
// Terminate gracefully
let
buffer
=
b"Foo msg"
;
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -641,8 +641,8 @@ mod test {
init
();
let
buffer
=
b"Foo msg"
;
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
std
::
ptr
::
null
(),
d
e
st
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
std
::
ptr
::
null
(),
dst
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
libc
::
EINVAL
,
res
);
}
...
...
@@ -672,9 +672,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_recv
(
context
,
&
mut
src
,
&
mut
dst
,
&
mut
buffer_len
,
buffer
.as_mut
()
.as_mut_ptr
())
};
assert_eq!
(
0
,
res
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer_len
,
EXPECTED_MSG
.len
()
as
u32
);
assert_eq!
(
buffer
,
EXPECTED_MSG
);
...
...
@@ -710,7 +709,7 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_recv
(
context
,
std
::
ptr
::
null_mut
(),
&
mut
dst
,
&
mut
buffer_len
,
buffer
.as_mut
()
.as_mut_ptr
())
};
assert_eq!
(
0
,
res
);
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer_len
,
EXPECTED_MSG
.len
()
as
u32
);
assert_eq!
(
buffer
,
EXPECTED_MSG
);
...
...
@@ -782,9 +781,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_recv
(
context
,
&
mut
src
,
&
mut
dst
,
std
::
ptr
::
null_mut
(),
std
::
ptr
::
null_mut
())
};
assert_eq!
(
0
,
res
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
assert_eq!
(
0
,
res
);
...
...
@@ -818,9 +816,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_recv
(
context
,
&
mut
src
,
&
mut
dst
,
&
mut
buffer_len
,
std
::
ptr
::
null_mut
())
};
assert_eq!
(
0
,
res
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer_len
,
0
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -855,9 +852,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_recv
(
context
,
&
mut
src
,
&
mut
dst
,
std
::
ptr
::
null_mut
(),
buffer
.as_mut
()
.as_mut_ptr
())
};
assert_eq!
(
0
,
res
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer
,
EXPECTED_MSG
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -1033,9 +1029,8 @@ mod test {
let
res
:
c_int
=
unsafe
{
vsg_recv
(
context
,
&
mut
src
,
&
mut
dst
,
&
mut
buffer_len
,
buffer
.as_mut
()
.as_mut_ptr
())
};
assert_eq!
(
0
,
res
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer_len
,
EXPECTED_MSG
.len
()
as
u32
);
assert_eq!
(
buffer
,
EXPECTED_MSG
);
...
...
@@ -1065,8 +1060,8 @@ mod test {
assert_ne!
(
TIMEVAL_POISON
.tv_usec
,
tv
.tv_usec
);
let
buffer
=
b"This is the end"
;
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
@@ -1092,8 +1087,8 @@ mod test {
assert_eq!
(
0
,
res
);
let
buffer
=
b"This is the end"
;
let
d
e
st
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
d
e
st
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
let
dst
=
remote_vsg_address!
();
let
res
:
c_int
=
unsafe
{
vsg_send
(
context
,
dst
,
buffer
.len
()
as
u32
,
buffer
.as_ref
()
.as_ptr
())
};
assert_eq!
(
0
,
res
);
let
res
:
c_int
=
unsafe
{
vsg_stop
(
context
)
};
...
...
src/fake-vm/fake_vm/src/connector/mod.rs
View file @
7057d35c
...
...
@@ -35,6 +35,8 @@ struct Time {
#[repr(C)]
struct
Packet
{
size
:
u32
,
src
:
u32
,
dst
:
u32
,
}
#[derive(Clone,
Copy,
Debug,
FromLe,
IntoLe,
PartialEq,
ValidAsBytes,
Validate)]
...
...
@@ -120,8 +122,6 @@ impl ToBytes for MsgInType {
#[repr(C)]
struct
SendPacket
{
send_time
:
Time
,
src
:
u32
,
dest
:
u32
,
packet
:
Packet
,
}
...
...
@@ -190,7 +190,7 @@ fn allocate_buffer(buffer_pool: &BufferPool, size: usize) -> Result<Buffer> {
#[derive(Debug)]
pub
enum
MsgIn
{
DeliverPacket
(
Buffer
),
DeliverPacket
(
u32
,
u32
,
Buffer
),
GoToDeadline
(
Duration
),
EndSimulation
,
}
...
...
@@ -202,17 +202,19 @@ impl MsgIn {
usize
::
max
(
MsgInType
::
NUM_BYTES
,
max_msg_in_second_buf_size
)
}
fn
recv
<
'a
,
'b
>
(
src
:
&
mut
impl
Read
,
scratch_buffer
:
&
'a
mut
[
u8
],
buffer_pool
:
&
'b
BufferPool
,
src_endianness
:
Endianness
)
->
Result
<
MsgIn
>
{
let
msg_type
=
MsgInType
::
from_stream
(
src
,
scratch_buffer
,
src_endianness
)
?
;
fn
recv
<
'a
,
'b
>
(
reader
:
&
mut
impl
Read
,
scratch_buffer
:
&
'a
mut
[
u8
],
buffer_pool
:
&
'b
BufferPool
,
src_endianness
:
Endianness
)
->
Result
<
MsgIn
>
{
let
msg_type
=
MsgInType
::
from_stream
(
reader
,
scratch_buffer
,
src_endianness
)
?
;
match
msg_type
{
MsgInType
::
DeliverPacket
=>
{
let
msg
=
DeliverPacket
::
from_stream
(
src
,
scratch_buffer
,
src_endianness
)
?
;
let
msg
=
DeliverPacket
::
from_stream
(
reader
,
scratch_buffer
,
src_endianness
)
?
;
let
mut
buffer
=
allocate_buffer
(
buffer_pool
,
msg
.packet.size
as
usize
)
?
;
src
.read_exact
(
&
mut
buffer
)
?
;
Ok
(
MsgIn
::
DeliverPacket
(
buffer
))
let
src
=
msg
.packet.src
;
let
dst
=
msg
.packet.dst
;
reader
.read_exact
(
&
mut
buffer
)
?
;
Ok
(
MsgIn
::
DeliverPacket
(
src
,
dst
,
buffer
))
},
MsgInType
::
GoToDeadline
=>
{
let
deadline
=
GoToDeadline
::
from_stream
(
src
,
scratch_buffer
,
src_endianness
)
?
.deadline
;
let
deadline
=
GoToDeadline
::
from_stream
(
reader
,
scratch_buffer
,
src_endianness
)
?
.deadline
;
if
let
(
Ok
(
seconds
),
Ok
(
nseconds
))
=
(
u64
::
try_from
(
deadline
.seconds
),
u32
::
try_from
(
deadline
.useconds
)
.map_err
(|
_
|
())
.and_then
(|
usecs
|
...
...
@@ -232,26 +234,28 @@ impl MsgIn {
}
#[cfg(any(test,
feature
=
"test-helpers"
))]
fn
send
<
'b
>
(
self
,
dst
:
&
mut
impl
Write
,
scratch_buffer
:
&
'b
mut
[
u8
],
dst_endianness
:
Endianness
)
->
Result
<
()
>
{
fn
send
<
'b
>
(
self
,
writer
:
&
mut
impl
Write
,
scratch_buffer
:
&
'b
mut
[
u8
],
dst_endianness
:
Endianness
)
->
Result
<
()
>
{
let
msg_type
=
match
self
{
MsgIn
::
DeliverPacket
(
_
)
=>
MsgInType
::
DeliverPacket
,
MsgIn
::
DeliverPacket
(
_
,
_
,
_
)
=>
MsgInType
::
DeliverPacket
,
MsgIn
::
GoToDeadline
(
_
)
=>
MsgInType
::
GoToDeadline
,
MsgIn
::
EndSimulation
=>
MsgInType
::
EndSimulation
,
};
msg_type
.to_stream
(
dst
,
scratch_buffer
,
dst_endianness
)
?
;
msg_type
.to_stream
(
writer
,
scratch_buffer
,
dst_endianness
)
?
;
match
self
{
MsgIn
::
DeliverPacket
(
packet
)
=>
{
MsgIn
::
DeliverPacket
(
src
,
dst
,
packet
)
=>
{
const_assert!
(
crate
::
MAX_PACKET_SIZE
<=
std
::
u32
::
MAX
as
usize
);
assert
!
(
packet
.len
()
<=
std
::
u32
::
MAX
as
usize
);
let
deliver_packet_header
=
DeliverPacket
{
packet
:
Packet
{
size
:
packet
.len
()
as
u32
,
src
:
src
,
dst
:
dst
},
};
deliver_packet_header
.to_stream
(
dst
,
scratch_buffer
,
dst_endianness
)
?
;
dst
.write_all
(
&
packet
)
deliver_packet_header
.to_stream
(
writer
,
scratch_buffer
,
dst_endianness
)
?
;
writer
.write_all
(
&
packet
)
},
MsgIn
::
GoToDeadline
(
deadline
)
=>
{
let
go_to_deadline
=
GoToDeadline
{
...
...
@@ -260,7 +264,7 @@ impl MsgIn {
useconds
:
deadline
.subsec_micros
()
as
u64
,
},
};
go_to_deadline
.to_stream
(
dst
,
scratch_buffer
,
dst_endianness
)
go_to_deadline
.to_stream
(
writer
,
scratch_buffer
,
dst_endianness
)
},
MsgIn
::
EndSimulation
=>
Ok
(()),
}
...
...
@@ -278,15 +282,15 @@ impl MsgOut {
usize
::
max
(
MsgOutType
::
NUM_BYTES
,
SendPacket
::
NUM_BYTES
)
}
fn
send
(
self
,
dst
:
&
mut
impl
Write
,
scratch_buffer
:
&
mut
[
u8
],
dst_endianness
:
Endianness
)
->
Result
<
()
>
{
fn
send
(
self
,
writer
:
&
mut
impl
Write
,
scratch_buffer
:
&
mut
[
u8
],
dst_endianness
:
Endianness
)
->
Result
<
()
>
{
let
msg_type
=
match
self
{
MsgOut
::
AtDeadline
=>
MsgOutType
::
AtDeadline
,
MsgOut
::
SendPacket
(
_
,
_
,
_
,
_
)
=>
MsgOutType
::
SendPacket
,
};
msg_type
.to_stream
(
dst
,
scratch_buffer
,
dst_endianness
)
?
;
msg_type
.to_stream
(
writer
,
scratch_buffer
,
dst_endianness
)
?
;
match
self
{
MsgOut
::
AtDeadline
=>
Ok
(()),
MsgOut
::
SendPacket
(
send_time
,
src
,
d
e
st
,
packet
)
=>
{
MsgOut
::
SendPacket
(
send_time
,
src
,
dst
,
packet
)
=>
{
const_assert!
(
crate
::
MAX_PACKET_SIZE
<=
std
::
u32
::
MAX
as
usize
);
assert
!
(
packet
.len
()
<=
std
::
u32
::
MAX
as
usize
);
...
...
@@ -295,15 +299,15 @@ impl MsgOut {
seconds
:
send_time
.as_secs
(),
useconds
:
send_time
.subsec_micros
()
as
u64
,
},
src
:
src
,
dest
:
dest
,
packet
:
Packet
{
size
:
packet
.len
()
as
u32
,
src
:
src
,
dst
:
dst
},
};
send_packet_header
.to_stream
(
dst
,
scratch_buffer
,
dst_endianness
)
?
;
dst
.write_all
(
&
packet
)
send_packet_header
.to_stream
(
writer
,
scratch_buffer
,
dst_endianness
)
?
;
writer
.write_all
(
&
packet
)
},
}
}
...
...
@@ -315,7 +319,7 @@ impl MsgOut {
MsgOutType
::
AtDeadline
=>
Ok
(
MsgOut
::
AtDeadline
),
MsgOutType
::
SendPacket
=>
{
let
header
=
SendPacket
::
from_stream
(
reader
,
scratch_buffer
,
src_endianness
)
?
;
if
let
(
Ok
(
seconds
),
Ok
(
nseconds
)
,
Ok
(
src
),
Ok
(
dest
)
)
=
(
if
let
(
Ok
(
seconds
),
Ok
(
nseconds
))
=
(
u64
::
try_from
(
header
.send_time.seconds
),
u32
::
try_from
(
header
.send_time.useconds
)
.map_err
(|
_
|
())
.and_then
(|
usecs
|
if
usecs
<
1000000
{
...
...
@@ -323,13 +327,13 @@ impl MsgOut {
}
else
{
Err
(())
}),
u32
::
try_from
(
header
.src
),
u32
::
try_from
(
header
.dest
)
)
{
let
mut
buffer
=
allocate_buffer
(
buffer_pool
,
header
.packet.size
as
usize
)
?
;
let
src
=
header
.packet.src
;
let
dst
=
header
.packet.dst
;
reader
.read_exact
(
&
mut
buffer
)
?
;
Ok
(
MsgOut
::
SendPacket
(
Duration
::
new
(
seconds
,
nseconds
),
src
,
d
e
st
,
buffer
))
Ok
(
MsgOut
::
SendPacket
(
Duration
::
new
(
seconds
,
nseconds
),
src
,
dst
,
buffer
))
}
else
{
Err
(
Error
::
new
(
ErrorKind
::
InvalidData
,
"Time out of bounds"
))
}
...
...
src/fake-vm/fake_vm/src/connector/unix.rs
View file @
7057d35c
...
...
@@ -446,6 +446,8 @@ mod test {
static
DELIVER_PACKET
:
DeliverPacket
=
DeliverPacket
{
packet
:
Packet
{
size
:
42
,
src
:
0
,
dst
:
1
},
};
static
PACKET_PAYLOAD
:
&
[
u8
]
=
b"abcdefghijklmnopqrstuvwxyz0123456789ABCDEF"
;
...
...
@@ -496,6 +498,8 @@ mod test {
let
msg
=
DeliverPacket
{
packet
:
Packet
{
size
:
(
crate
::
MAX_PACKET_SIZE
+
1
)
as
u32
,
src
:
0
,
dst
:
1
},
};
let
mut
big_payload
=
vec!
(
0
;
msg
.packet.size
as
usize
);
...
...
@@ -537,7 +541,7 @@ mod test {
assert
!
(
msg
.is_ok
());
let
msg
=
msg
.unwrap
();
match
msg
{
MsgIn
::
DeliverPacket
(
payload
)
=>
{
MsgIn
::
DeliverPacket
(
_
,
_
,
payload
)
=>
{
assert_eq!
(
payload
.deref
(),
PACKET_PAYLOAD
)
},
_
=>
assert
!
(
false
),
...
...
src/fake-vm/fake_vm/src/lib.rs
View file @
7057d35c
...
...
@@ -137,7 +137,7 @@ impl InnerContext {
}
}
fn
send
(
&
self
,
d
e
st
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
fn
send
(
&
self
,
dst
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
let
mut
buffer
=
self
.output_buffer_pool
.allocate_buffer
(
msg
.len
())
?
;
buffer
.copy_from_slice
(
msg
);
...
...
@@ -147,7 +147,7 @@ impl InnerContext {
// This would violate the property that send times must be after the previous deadline
// (included) and (strictly) before the current deadline. To solve this, ::at_deadline()
// takes the latest time between the recorded time and the previous deadline.
self
.outgoing_messages
.insert
(
send_time
,
self
.address
,
d
e
st
,
buffer
)
?
;
self
.outgoing_messages
.insert
(
send_time
,
self
.address
,
dst
,
buffer
)
?
;
Ok
(())
}
...
...
@@ -223,7 +223,7 @@ impl Context {
let
messages
=
self
.0
.outgoing_messages
.drain
();
let
previous_deadline
=
self
.0
.timer_context
.simulation_previous_deadline
();
let
current_deadline
=
self
.0
.timer_context
.simulation_next_deadline
();
for
(
send_time
,
src
,
d
e
st
,
payload
)
in
messages
{
for
(
send_time
,
src
,
dst
,
payload
)
in
messages
{
let
send_time
=
if
send_time
<
previous_deadline
{
// This message was time-stamped before the previous deadline but inserted after.
// Fix the timestamp to stay between the deadlines.
...
...
@@ -236,7 +236,7 @@ impl Context {
send_time
};
if
let
Err
(
_e
)
=
connector
.send
(
MsgOut
::
SendPacket
(
send_time
,
src
,
d
e
st
,
payload
))
{
if
let
Err
(
_e
)
=
connector
.send
(
MsgOut
::
SendPacket
(
send_time
,
src
,
dst
,
payload
))
{
// error!("send(SendPacket) failed: {}", _e);
return
AfterDeadline
::
EndSimulation
;
}
...
...
@@ -274,11 +274,7 @@ impl Context {
fn
handle_actor_msg
(
&
self
,
msg
:
MsgIn
)
->
Option
<
AfterDeadline
>
{
match
msg
{
MsgIn
::
DeliverPacket
(
packet
)
=>
{
// FIXME: Use src address when available in the protocol
let
src
=
self
.0
.address
;
// Or use dst address when available in the protocol? Should be the same...
let
dst
=
self
.0
.address
;
MsgIn
::
DeliverPacket
(
src
,
dst
,
packet
)
=>
{
// let size = packet.len();
if
self
.0
.input_queue
.push
(
Packet
::
new
(
src
,
dst
,
packet
))
.is_err
()
{
// info!("Dropping input packet from {} of {} bytes", src, size);
...
...
@@ -294,8 +290,8 @@ impl Context {
self
.0
.gettimeofday
()
}
pub
fn
send
(
&
self
,
d
e
st
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
self
.0
.send
(
d
e
st
,
msg
)
pub
fn
send
(
&
self
,
dst
:
VsgAddress
,
msg
:
&
[
u8
])
->
Result
<
()
>
{
self
.0
.send
(
dst
,
msg
)
}
pub
fn
recv
<
'a
,
'b
>
(
&
'a
self
,
msg
:
&
'b
mut
[
u8
])
->
Result
<
(
VsgAddress
,
VsgAddress
,
&
'b
mut
[
u8
])
>
{
...
...
@@ -419,7 +415,9 @@ pub mod test_helpers {
let
next_slice
=
delay_micros
-
(
next_deadline_micros
-
slice_micros
);
actor
.send
(
MsgIn
::
GoToDeadline
(
Duration
::
from_micros
(
next_slice
)))
?
;
actor
.send
(
MsgIn
::
DeliverPacket
(
buffer
))
?
;
let
src
=
local_vsg_address!
();
let
dst
=
remote_vsg_address!
();
actor
.send
(
MsgIn
::
DeliverPacket
(
src
,
dst
,
buffer
))
?
;
actor
.send
(
MsgIn
::
EndSimulation
)
}
...
...
@@ -536,8 +534,8 @@ mod test {
context
.start
()
.expect
(
"start failed"
);
let
d
e
st
=
remote_vsg_address!
();
context
.send
(
d
e
st
,
b"Foo msg"
)
let
dst
=
remote_vsg_address!
();
context
.send
(
dst
,
b"Foo msg"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
@@ -556,15 +554,15 @@ mod test {
context
.start
()
.expect
(
"start failed"
);
let
d
e
st
=
remote_vsg_address!
();
let
dst
=
remote_vsg_address!
();
let
buffer
=
[
0u8
;
crate
::
MAX_PACKET_SIZE
+
1
];
match
context
.send
(
d
e
st
,
&
buffer
)
.expect_err
(
"send should have failed"
)
{
match
context
.send
(
dst
,
&
buffer
)
.expect_err
(
"send should have failed"
)
{
crate
::
error
::
Error
::
SizeTooBig
=>
(),
_
=>
assert
!
(
false
),
}
// Terminate gracefully
context
.send
(
d
e
st
,
b"Foo msg"
)
context
.send
(
dst
,
b"Foo msg"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
@@ -593,9 +591,8 @@ mod test {
let
(
src
,
dst
,
buffer
)
=
context
.recv
(
&
mut
buffer
)
.expect
(
"recv failed"
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer
,
EXPECTED_MSG
);
context
.stop
();
...
...
@@ -624,7 +621,7 @@ mod test {
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer
,
EXPECTED_MSG
);
let
total_usec
=
tv
.tv_sec
as
u64
*
1_000_000
+
tv
.tv_usec
as
u64
;
assert
!
(
delay_micros
<=
total_usec
&&
total_usec
<=
10
*
delay_micros
);
...
...
@@ -697,9 +694,8 @@ mod test {
let
(
src
,
dst
,
buffer
)
=
context
.recv
(
&
mut
buffer
)
.expect
(
"recv failed"
);
// FIXME: Use the remote address when available in the protocol
assert_eq!
(
src
,
local_vsg_address!
());
assert_eq!
(
dst
,
local
_vsg_address!
());
assert_eq!
(
dst
,
remote
_vsg_address!
());
assert_eq!
(
buffer
,
EXPECTED_MSG
);
context
.stop
();
...
...
@@ -723,8 +719,8 @@ mod test {
assert
!
(
tv
.tv_sec
>=
0
&&
tv
.tv_sec
<
10
);
assert
!
(
tv
.tv_usec
>=
0
&&
tv
.tv_usec
<
999999
);
let
d
e
st
=
remote_vsg_address!
();
context
.send
(
d
e
st
,
b"This is the end"
)
let
dst
=
remote_vsg_address!
();
context
.send
(
dst
,
b"This is the end"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
@@ -748,8 +744,8 @@ mod test {
assert
!
(
tv
.tv_sec
>=
3600
&&
tv
.tv_sec
<
3610
);
assert
!
(
tv
.tv_usec
>=
0
&&
tv
.tv_usec
<
999999
);
let
d
e
st
=
remote_vsg_address!
();
context
.send
(
d
e
st
,
b"This is the end"
)
let
dst
=
remote_vsg_address!
();
context
.send
(
dst
,
b"This is the end"
)
.expect
(
"send failed"
);
context
.stop
();
...
...
src/fake-vm/fake_vm/src/output_msg_set.rs
View file @
7057d35c
...
...
@@ -29,7 +29,7 @@ impl std::error::Error for Error {}
struct
OutputMsg
{
send_time
:
Duration
,
src
:
VsgAddress
,
d
e
st
:
VsgAddress
,
dst
:
VsgAddress
,
payload
:
Buffer
,
}
...
...
@@ -57,7 +57,7 @@ impl<'a> Iterator for OutputMsgDrain<'a> {
if
val
.is_some
()
{
self
.index
=
index
+
1
;
let
val
=
val
.unwrap
();
return
Some
((
val
.send_time
,
val
.src
,
val
.d
e
st
,
val
.payload
));
return
Some
((
val
.send_time
,
val
.src
,
val
.dst
,
val
.payload
));
}
}
...
...
@@ -81,13 +81,13 @@ impl OutputMsgSet {
}
}
pub
fn
insert
(
&
self
,
send_time
:
Duration
,
src
:
VsgAddress
,
d
e
st
:
VsgAddress
,
payload
:
Buffer
)
->
Result
<
()
>
{
pub
fn
insert
(
&
self
,
send_time
:
Duration
,
src
:
VsgAddress
,
dst
:
VsgAddress
,
payload
:
Buffer
)
->
Result
<
()
>
{
for
(
idx
,
slot
)
in
self
.slot_busy
.iter
()
.enumerate
()
{
if
!
slot
.swap
(
true
,
Ordering
::
AcqRel
)
{
let
output_msg
=
OutputMsg
{
send_time
:
send_time
,
src
:
src
,
d
e
st
:
d
e
st
,
dst
:
dst
,
payload
:
payload
,
};
unsafe
{
...
...
src/simgrid/VmsInterface.cpp
View file @
7057d35c
...
...
@@ -193,11 +193,11 @@ std::vector<message> VmsInterface::goTo(double deadline)
XBT_ERROR
(
"can not receive the data of the message from VM %s. The socket may be closed"
,
vm_name
.
c_str
());
end_simulation
();
}
char
d
e
st_addr
[
INET_ADDRSTRLEN
];
char
dst_addr
[
INET_ADDRSTRLEN
];
char
src_addr
[
INET_ADDRSTRLEN
];
vsg_decode_src_d
e
st
(
send_packet
,
src_addr
,
d
e
st_addr
);
vsg_decode_src_dst
(
send_packet
,
src_addr
,
dst_addr
);
XBT_INFO
(
"got the message [%s] (size %lu) from VM [%s](=ip(%s)) to VM [%d](=ip(%s)) with timestamp [%d.%06d]"
,
data
,
sizeof
(
data
),
vm_name
.
c_str
(),
src_addr
,
send_packet
.
d
e
st
,
d
e
st_addr
,
data
,
sizeof
(
data
),
vm_name
.
c_str
(),
src_addr
,
send_packet
.
packet
.
dst
,
dst_addr
,
send_packet
.