Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
PRRT
Commits
8d65f984
Commit
8d65f984
authored
Mar 10, 2016
by
Andreas Schmidt
Browse files
Extract channel state information
parent
ccfecaef
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/prrt/CMakeLists.txt
View file @
8d65f984
add_library
(
PRRT ../defines.h socket.c block.c block.h packet.c packet.h receiver.c receiver.h clock.c clock.h processes/feedback_receiver.c processes/feedback_receiver.h processes/data_transmitter.c processes/data_transmitter.h coding_params.c coding_params.h vdmcode/block_code.c vdmcode/block_code.h coding_params.c coding_params.h stores/forward_packet_table.c stores/forward_packet_table.h processes/data_receiver.c processes/data_receiver.h
)
\ No newline at end of file
add_library
(
PRRT ../defines.h socket.c block.c block.h packet.c packet.h receiver.c receiver.h clock.c clock.h channelStateInformation.c channelStateInformation.h processes/feedback_receiver.c processes/feedback_receiver.h processes/data_transmitter.c processes/data_transmitter.h coding_params.c coding_params.h vdmcode/block_code.c vdmcode/block_code.h coding_params.c coding_params.h stores/forward_packet_table.c stores/forward_packet_table.h processes/data_receiver.c processes/data_receiver.h
)
\ No newline at end of file
src/prrt/channelStateInformation.c
0 → 100644
View file @
8d65f984
#include
<stdlib.h>
#include
"../defines.h"
#include
"../util/common.h"
#include
"../util/dbg.h"
#include
"channelStateInformation.h"
void
PrrtChannelStateInformation_init
(
PrrtChannelStateInformation
*
csi
)
{
check
(
csi
!=
NULL
,
"Input should not be NULL."
);
csi
->
rttMean
=
0
;
csi
->
rttDev
=
0
;
return
;
error:
PERROR
(
"Should not happen.%s"
,
""
);
}
void
PrrtChannelStateInformation_update_rtt
(
PrrtChannelStateInformation
*
csi
,
uint32_t
rtt
)
{
int32_t
delta
=
rtt
-
csi
->
rttMean
;
// TODO: ensure that there are no arithemtic problems via rounding etc.
csi
->
rttMean
=
(
uint32_t
)
(
csi
->
rttMean
+
RRT_ALPHA
*
delta
);
csi
->
rttDev
=
(
uint32_t
)
(
csi
->
rttDev
+
RRT_ALPHA
*
(
labs
(
delta
)
-
csi
->
rttDev
));
}
void
PrrtChannelStateInformation_print
(
PrrtChannelStateInformation
*
csi
)
{
check
(
csi
!=
NULL
,
"Input should not be NULL."
);
printf
(
"RTT [us]: %d +- %d
\n
"
,
csi
->
rttMean
,
csi
->
rttDev
);
return
;
error:
PERROR
(
"Should not happen.%s"
,
""
);
}
\ No newline at end of file
src/prrt/channelStateInformation.h
0 → 100644
View file @
8d65f984
#ifndef PRRT_CHANNELSTATEINFORMATION_H
#define PRRT_CHANNELSTATEINFORMATION_H
#include
<stdint.h>
typedef
struct
prrtChannelStateInformation
{
uint32_t
rttMean
;
uint32_t
rttDev
;
}
PrrtChannelStateInformation
;
void
PrrtChannelStateInformation_init
(
PrrtChannelStateInformation
*
csi
);
void
PrrtChannelStateInformation_update_rtt
(
PrrtChannelStateInformation
*
csi
,
uint32_t
rtt
);
void
PrrtChannelStateInformation_print
(
PrrtChannelStateInformation
*
csi
);
#endif //PRRT_CHANNELSTATEINFORMATION_H
src/prrt/socket.c
View file @
8d65f984
...
...
@@ -26,8 +26,7 @@ PrrtSocket* PrrtSocket_create(const uint16_t port, const uint8_t is_sender) {
sock_ptr
->
sequenceNumberSource
=
1
;
sock_ptr
->
sequenceNumberRedundancy
=
1
;
sock_ptr
->
rttMean
=
0
;
sock_ptr
->
rttDev
=
0
;
PrrtChannelStateInformation_init
(
&
sock_ptr
->
csi
);
sock_ptr
->
dataStore
=
NULL
;
...
...
@@ -256,7 +255,7 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
return
-
1
;
}
PrrtPacket
*
PrrtSocket_recv_feedback
(
PrrtSocket
*
sock_ptr
,
const
size_t
length
)
PrrtPacket
*
PrrtSocket_recv_feedback
(
PrrtSocket
*
prrtSocket
,
const
size_t
length
)
{
char
bufin
[
MAX_PAYLOAD_LENGTH
];
ssize_t
n
;
...
...
@@ -265,7 +264,7 @@ PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, const size_t length)
struct
pollfd
fds
;
int
timeout_msecs
=
1000
;
fds
.
fd
=
sock_ptr
->
feedbackSocketFd
;
fds
.
fd
=
prrtSocket
->
feedbackSocketFd
;
fds
.
events
=
POLLIN
;
n
=
poll
(
&
fds
,
1
,
timeout_msecs
);
...
...
@@ -273,22 +272,19 @@ PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, const size_t length)
if
(
n
==
0
)
{
return
NULL
;
}
uint32_t
receive
_t
ime
=
PrrtClock_get_current_time
();
uint32_t
receive
T
ime
=
PrrtClock_get_current_time
();
n
=
recvfrom
(
sock_ptr
->
feedbackSocketFd
,
bufin
,
length
,
0
,
(
struct
sockaddr
*
)
&
remote
,
&
addrlen
);
n
=
recvfrom
(
prrtSocket
->
feedbackSocketFd
,
bufin
,
length
,
0
,
(
struct
sockaddr
*
)
&
remote
,
&
addrlen
);
check
(
n
>=
0
,
"Receiving feedback failed."
);
PrrtPacket
*
packet
_ptr
=
calloc
(
1
,
sizeof
(
PrrtPacket
));
check_mem
(
packet
_ptr
);
PrrtPacket_decode
(
bufin
,
(
uint16_t
)
n
,
packet
_ptr
);
PrrtPacket
*
p
rrtP
acket
=
calloc
(
1
,
sizeof
(
PrrtPacket
));
check_mem
(
p
rrtP
acket
);
PrrtPacket_decode
(
bufin
,
(
uint16_t
)
n
,
p
rrtP
acket
);
PrrtPacketFeedbackPayload
*
feedbackPayload
=
packet_ptr
->
payload
;
int32_t
delta
=
(
receive_time
-
feedbackPayload
->
forward_trip_timestamp
)
-
sock_ptr
->
rttMean
;
// TODO: ensure that there are no arithemtic problems via rounding etc.
sock_ptr
->
rttMean
=
(
uint32_t
)
(
sock_ptr
->
rttMean
+
RRT_ALPHA
*
delta
);
sock_ptr
->
rttDev
=
(
uint32_t
)
(
sock_ptr
->
rttDev
+
RRT_ALPHA
*
(
labs
(
delta
)
-
sock_ptr
->
rttDev
));
uint32_t
forwardTripTimestamp
=
((
PrrtPacketFeedbackPayload
*
)
prrtPacket
->
payload
)
->
forward_trip_timestamp
;
PrrtChannelStateInformation_update_rtt
(
&
prrtSocket
->
csi
,
receiveTime
-
forwardTripTimestamp
);
return
packet
_ptr
;
return
p
rrtP
acket
;
error:
return
NULL
;
...
...
src/prrt/socket.h
View file @
8d65f984
...
...
@@ -6,6 +6,7 @@
#include
"stores/forward_packet_table.h"
#include
"../util/list.h"
#include
"../util/bptree.h"
#include
"channelStateInformation.h"
typedef
struct
prrtSocket
{
...
...
@@ -44,6 +45,7 @@ typedef struct prrtSocket {
uint32_t
lastSentTimestamp
;
uint32_t
lastReceivedTimestamp
;
PrrtChannelStateInformation
csi
;
uint32_t
rttMean
;
uint32_t
rttDev
;
}
PrrtSocket
;
...
...
@@ -55,6 +57,6 @@ int PrrtSocket_close(PrrtSocket *sock_ptr);
int
PrrtSocket_connect
(
PrrtSocket
*
sock_ptr
,
const
char
*
host
,
const
uint16_t
port
);
int
PrrtSocket_send
(
PrrtSocket
*
sock_ptr
,
const
uint8_t
*
data
,
const
size_t
data_len
);
int32_t
PrrtSocket_recv
(
PrrtSocket
*
sock_ptr
,
void
*
buf_ptr
);
PrrtPacket
*
PrrtSocket_recv_feedback
(
PrrtSocket
*
sock_ptr
,
const
size_t
length
);
PrrtPacket
*
PrrtSocket_recv_feedback
(
PrrtSocket
*
prrtSocket
,
const
size_t
length
);
#endif // PRRT_SOCKET_H
Write
Preview
Supports
Markdown
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