Commit b725a254 authored by Andreas Schmidt's avatar Andreas Schmidt

Merge branch 'develop' into timer

parents 0c850fd9 fb9d8722
Pipeline #2417 passed with stages
in 1 minute and 46 seconds
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Clock synchronization between sending stack and receiving stack * Clock synchronization between sending stack and receiving stack
* Applications can specify packet-level expiration times * Applications can specify packet-level expiration times
* Different receive modes for ASAP and time-synchronized operation * Different receive modes for ASAP and time-synchronized operation
* Passive measurement of propagation delay, bottleneck data rate and packet loss rate
* Packet-level timing analysis using [X-Lap](http://xlap.larn.systems) * Packet-level timing analysis using [X-Lap](http://xlap.larn.systems)
* [Hardware timestamping support](https://git.nt.uni-saarland.de/LARN/PRRT/wikis/hardware-timestamping) * [Hardware timestamping support](https://git.nt.uni-saarland.de/LARN/PRRT/wikis/hardware-timestamping)
...@@ -25,7 +26,7 @@ import prrt ...@@ -25,7 +26,7 @@ import prrt
port = int(sys.argv[1]) port = int(sys.argv[1])
s = prrt.PrrtSocket(port=port, isSender=False) s = prrt.PrrtSocket(port=port)
while True: while True:
d = s.recv() d = s.recv()
...@@ -44,7 +45,7 @@ import prrt ...@@ -44,7 +45,7 @@ import prrt
host = sys.argv[1] host = sys.argv[1]
port = int(sys.argv[2]) port = int(sys.argv[2])
s = prrt.PrrtSocket(port=port, isSender=True) s = prrt.PrrtSocket(port=port)
s.connect(host, port) s.connect(host, port)
for i in range(10): for i in range(10):
......
...@@ -3,11 +3,12 @@ import prrt ...@@ -3,11 +3,12 @@ import prrt
port = int(sys.argv[1]) port = int(sys.argv[1])
s = prrt.PrrtSocket(port=port, isSender=False) s = prrt.PrrtSocket(("127.0.0.1", port))
while True: while True:
d = s.recv() d, addr = s.recv()
d = d.decode("utf8")
if d != "Close": if d != "Close":
print d print(d, addr)
else: else:
break break
...@@ -3,10 +3,11 @@ import prrt ...@@ -3,10 +3,11 @@ import prrt
host = sys.argv[1] host = sys.argv[1]
port = int(sys.argv[2]) port = int(sys.argv[2])
localport = int(sys.argv[3])
s = prrt.PrrtSocket(port=port, isSender=True) s = prrt.PrrtSocket(("127.0.1.1", localport), mtu=150)
s.connect(host, port) s.connect((host, port))
for i in range(10): for i in range(10):
s.send("Packet {}".format(i)) s.send("Packet {}".format(i).encode("utf8"))
s.send("Close") s.send("Close".encode("utf8"))
...@@ -15,7 +15,7 @@ add_subdirectory(proto) ...@@ -15,7 +15,7 @@ add_subdirectory(proto)
add_subdirectory(util) add_subdirectory(util)
add_executable(sender sender.c) add_executable(sender sender.c)
add_executable(receiver receiver.c) add_executable(receiver receiver.c ../tests/common.h)
target_link_libraries(sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
include "posix/time.pxd" include "posix/time.pxd"
include "sockets.pxd"
from libc.stdint cimport uint32_t, uint16_t, uint8_t, int32_t from libc.stdint cimport uint32_t, uint16_t, uint8_t, int32_t
from libc.string cimport const_char from libc.string cimport const_char
cdef extern from "pthread.h" nogil: cdef extern from "pthread.h" nogil:
ctypedef struct pthread_t: ctypedef struct pthread_t:
pass pass
...@@ -26,18 +28,17 @@ cdef extern from "proto/channelStateInformation.h": ...@@ -26,18 +28,17 @@ cdef extern from "proto/channelStateInformation.h":
ctypedef prrtChannelStateInformation PrrtChannelStateInformation ctypedef prrtChannelStateInformation PrrtChannelStateInformation
cdef extern from "proto/codingParams.h": cdef extern from "proto/codingParams.h":
ctypedef struct prrtCodingParams: ctypedef struct prrtCodingConfiguration:
uint8_t k uint8_t k
uint8_t r uint8_t r
uint8_t n uint8_t n
uint8_t c uint8_t c
uint8_t *n_cycle uint8_t *n_cycle
ctypedef prrtCodingParams PrrtCodingParams ctypedef prrtCodingConfiguration PrrtCodingConfiguration
PrrtCodingParams *PrrtCodingParams_create() PrrtCodingConfiguration *PrrtCodingConfiguration_create()
PrrtCodingParams *PrrtCodingParams_copy(PrrtCodingParams *cpar) PrrtCodingConfiguration *PrrtCodingConfiguration_copy(PrrtCodingConfiguration *cpar)
bint PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) bint PrrtCodingConfiguration_destroy(PrrtCodingConfiguration *cpar)
bint PrrtCodingParams_destroy(PrrtCodingParams *cpar)
cdef extern from "util/list.h": cdef extern from "util/list.h":
cdef struct list: cdef struct list:
...@@ -62,7 +63,7 @@ cdef extern from "proto/block.h": ...@@ -62,7 +63,7 @@ cdef extern from "proto/block.h":
cdef struct prrtBlock: cdef struct prrtBlock:
uint32_t data_count uint32_t data_count
uint32_t redundancy_count uint32_t redundancy_count
PrrtCodingParams coding_params PrrtCodingConfiguration coding_params
uint32_t largest_data_length uint32_t largest_data_length
uint16_t baseSequenceNumber uint16_t baseSequenceNumber
List* data_blocks List* data_blocks
...@@ -94,9 +95,7 @@ cdef extern from "proto/receiver.h": ...@@ -94,9 +95,7 @@ cdef extern from "proto/receiver.h":
cdef extern from "proto/socket.h": cdef extern from "proto/socket.h":
cdef struct prrtSocket: cdef struct prrtSocket:
int dataSocketFd int socketFd
int feedbackSocketFd
pthread_t receiveFeedbackThread
pthread_t sendDataThread pthread_t sendDataThread
pthread_mutex_t outQueueFilledMutex pthread_mutex_t outQueueFilledMutex
...@@ -120,34 +119,41 @@ cdef extern from "proto/socket.h": ...@@ -120,34 +119,41 @@ cdef extern from "proto/socket.h":
ctypedef prrtSocket PrrtSocket ctypedef prrtSocket PrrtSocket
cdef PrrtSocket* PrrtSocket_create(bint isSender, const uint32_t target_delay) cdef PrrtSocket* PrrtSocket_create(const uint32_t mtu, const uint32_t target_delay)
bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port) bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
int PrrtSocket_close(const PrrtSocket *sock_ptr) int PrrtSocket_close(const PrrtSocket *sock_ptr)
int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port) 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) 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) nogil int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr, sockaddr* addr) nogil
int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr) nogil int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr, sockaddr* addr) nogil
int32_t PrrtSocket_receive_asap_wait(PrrtSocket *s, void *buf_ptr) nogil int32_t PrrtSocket_receive_asap_wait(PrrtSocket *s, void *buf_ptr, sockaddr* addr) nogil
int32_t PrrtSocket_receive_asap_timedwait(PrrtSocket *s, void *buf_ptr, timespec* deadline) nogil int32_t PrrtSocket_receive_asap_timedwait(PrrtSocket *s, void *buf_ptr, sockaddr* addr, timespec* deadline) nogil
int32_t PrrtSocket_receive_ordered(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us) nogil int32_t PrrtSocket_receive_ordered(PrrtSocket *s, void *buf_ptr, sockaddr* addr, prrtTimedelta_t time_window_us) nogil
int32_t PrrtSocket_receive_ordered_wait(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us) nogil int32_t PrrtSocket_receive_ordered_wait(PrrtSocket *s, void *buf_ptr, sockaddr* addr, prrtTimedelta_t time_window_us) nogil
int32_t PrrtSocket_receive_ordered_timedwait(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us, timespec* deadline) nogil int32_t PrrtSocket_receive_ordered_timedwait(PrrtSocket *s, void *buf_ptr, sockaddr* addr, prrtTimedelta_t time_window_us, timespec* deadline) nogil
bint PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const_char *name, const uint32_t value) bint PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const_char *name, const uint32_t value)
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const_char *name) uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const_char *name)
bint PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) bint PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s) PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s)
bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket) bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket)
uint32_t PrrtSocket_get_rtprop(PrrtSocket *socket)
bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket) bint PrrtSocket_uses_thread_pinning(PrrtSocket *socket)
uint32_t PrrtSocket_get_rtt(PrrtSocket *socket) uint32_t PrrtSocket_get_rtprop_fwd(PrrtSocket *socket)
float PrrtSocket_get_plr(PrrtSocket *socket) float PrrtSocket_get_plr_fwd(PrrtSocket *socket)
uint32_t PrrtSocket_get_delivery_rate(PrrtSocket *socket) uint32_t PrrtSocket_get_delivery_rate_fwd(PrrtSocket *socket)
uint32_t PrrtSocket_get_btlbw_fwd(PrrtSocket *s);
uint32_t PrrtSocket_get_btlbw_back(PrrtSocket *s);
bint PrrtSocket_get_app_limited(PrrtSocket *socket)
bint PrrtSocket_enable_thread_pinning(PrrtSocket *socket) bint PrrtSocket_enable_thread_pinning(PrrtSocket *socket)
char *PrrtSocket_inet_ntoa(in_addr*)
uint16_t PrrtSocket_ntohs(uint16_t v)
cdef extern from "proto/stores/packetDeliveryStore.h": cdef extern from "proto/stores/packetDeliveryStore.h":
ctypedef struct PrrtPacketDeliveryStore: ctypedef struct PrrtPacketDeliveryStore:
pass pass
...@@ -170,3 +176,4 @@ cdef extern from "util/pipe.h": ...@@ -170,3 +176,4 @@ cdef extern from "util/pipe.h":
cdef extern from "util/mpsc_queue.h": cdef extern from "util/mpsc_queue.h":
ctypedef struct MPSCQueue: ctypedef struct MPSCQueue:
pass pass
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
# define __builtin_ia32_rdtsc() (0) # define __builtin_ia32_rdtsc() (0)
#endif #endif
#ifndef __cplusplus
# include <stdatomic.h>
#else
# include <atomic>
# define _Atomic(X) std::atomic< X >
#endif
#ifndef MAX #ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif #endif
...@@ -29,6 +36,8 @@ ...@@ -29,6 +36,8 @@
#define RRT_ALPHA 0.125 #define RRT_ALPHA 0.125
#define MIN_RTT 300
// Uncomment the line below if you are compiling on Windows. // Uncomment the line below if you are compiling on Windows.
// #define WINDOWS // #define WINDOWS
#include <stdio.h> #include <stdio.h>
......
add_library(PRRT ../defines.h set (PRRT_SOURCES ../defines.h
block.c block.h block.c block.h
channelStateInformation.c channelStateInformation.h channelStateInformation.c channelStateInformation.h
clock.c clock.h clock.c clock.h
...@@ -9,7 +9,6 @@ add_library(PRRT ../defines.h ...@@ -9,7 +9,6 @@ add_library(PRRT ../defines.h
../xlap/xlap.c ../xlap/xlap.h ../xlap/xlap.c ../xlap/xlap.h
applicationConstraints.c applicationConstraints.h applicationConstraints.c applicationConstraints.h
processes/dataReceiver.c processes/dataReceiver.h processes/dataReceiver.c processes/dataReceiver.h
processes/feedbackReceiver.c processes/feedbackReceiver.h
processes/dataTransmitter.c processes/dataTransmitter.h processes/dataTransmitter.c processes/dataTransmitter.h
stores/dataPacketStore.c stores/dataPacketStore.h stores/dataPacketStore.c stores/dataPacketStore.h
stores/deliveredPacketTable.c stores/deliveredPacketTable.h stores/deliveredPacketTable.c stores/deliveredPacketTable.h
...@@ -23,4 +22,10 @@ add_library(PRRT ../defines.h ...@@ -23,4 +22,10 @@ add_library(PRRT ../defines.h
types/packet.c types/packet.h types/packet.c types/packet.h
vdmcode/block_code.c vdmcode/block_code.h) vdmcode/block_code.c vdmcode/block_code.h)
if (XLAP)
set(PRRT_SOURCES ${PRRT_SOURCES} ../xlap/xlap.c ../xlap/xlap.h)
endif()
add_library(PRRT ${PRRT_SOURCES})
target_link_libraries(PRRT rt) target_link_libraries(PRRT rt)
...@@ -57,6 +57,14 @@ bool PrrtBlock_destroy(PrrtBlock *block_ptr) ...@@ -57,6 +57,14 @@ bool PrrtBlock_destroy(PrrtBlock *block_ptr)
PrrtPacket_destroy(pkt); PrrtPacket_destroy(pkt);
} }
if(block_ptr->coder != NULL) {
PrrtCoder_destroy(block_ptr->coder);
}
if(block_ptr->codingParams != NULL) {
PrrtCodingConfiguration_destroy(block_ptr->codingParams);
}
List_destroy(block_ptr->dataPackets); List_destroy(block_ptr->dataPackets);
List_destroy(block_ptr->redundancyPackets); List_destroy(block_ptr->redundancyPackets);
free(block_ptr); free(block_ptr);
...@@ -68,17 +76,17 @@ bool PrrtBlock_destroy(PrrtBlock *block_ptr) ...@@ -68,17 +76,17 @@ bool PrrtBlock_destroy(PrrtBlock *block_ptr)
return false; return false;
} }
PrrtBlock * PrrtBlock_create(PrrtCodingParams *cpar, prrtSequenceNumber_t baseSequenceNumber) PrrtBlock * PrrtBlock_create(PrrtCodingConfiguration *cpar, PrrtCoder* coder, prrtSequenceNumber_t baseSequenceNumber)
{ {
PrrtBlock *block_ptr = calloc(1, sizeof(PrrtBlock)); PrrtBlock *block_ptr = calloc(1, sizeof(PrrtBlock));
check_mem(block_ptr); check_mem(block_ptr);
block_ptr->coder = coder;
block_ptr->codingParams = cpar; block_ptr->codingParams = cpar;
block_ptr->dataPackets = List_create(); block_ptr->dataPackets = List_create();
block_ptr->redundancyPackets = List_create(); block_ptr->redundancyPackets = List_create();
block_ptr->baseSequenceNumber = baseSequenceNumber; block_ptr->baseSequenceNumber = baseSequenceNumber;
block_ptr->largestPayloadLength = 0; block_ptr->largestPayloadLength = 0;
block_ptr->coder = NULL;
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
check(pthread_mutexattr_init(&attr) == EXIT_SUCCESS, "Mutex attr init failed."); check(pthread_mutexattr_init(&attr) == EXIT_SUCCESS, "Mutex attr init failed.");
...@@ -184,8 +192,6 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno) ...@@ -184,8 +192,6 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno)
prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber; prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber;
prrtPacketLength_t length = block_ptr->largestPayloadLength; prrtPacketLength_t length = block_ptr->largestPayloadLength;
PrrtCoder *coder = block_ptr->codingParams->coder;
gf **src = calloc(k, sizeof(gf *)); gf **src = calloc(k, sizeof(gf *));
check_mem(src); check_mem(src);
...@@ -203,7 +209,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno) ...@@ -203,7 +209,7 @@ void PrrtBlock_encode(PrrtBlock *block_ptr, prrtSequenceNumber_t *seqno)
for(j = 0; j < r; j++) { for(j = 0; j < r; j++) {
fec[j] = calloc(length, sizeof(gf)); fec[j] = calloc(length, sizeof(gf));
check_mem(fec[j]); check_mem(fec[j]);
PrrtCoder_encode(coder, src, fec[j], j + k, length); PrrtCoder_encode(block_ptr->coder, src, fec[j], j + k, length);
PrrtPacket *red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void *) fec[j], length, *seqno, PrrtPacket *red_packet_ptr = PrrtPacket_create_redundancy_packet(0, (void *) fec[j], length, *seqno,
(uint8_t) (k + j), block_ptr->baseSequenceNumber, (uint8_t) (k + j), block_ptr->baseSequenceNumber,
block_ptr->codingParams); block_ptr->codingParams);
...@@ -237,8 +243,6 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr) ...@@ -237,8 +243,6 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber; prrtSequenceNumber_t baseSequenceNumber = block_ptr->baseSequenceNumber;
prrtPacketLength_t length = block_ptr->largestPayloadLength; prrtPacketLength_t length = block_ptr->largestPayloadLength;
PrrtCoder *coder = block_ptr->codingParams->coder;
fec = calloc(k, sizeof(gf *)); fec = calloc(k, sizeof(gf *));
check_mem(fec); check_mem(fec);
for(i = 0; i < k; i++) { for(i = 0; i < k; i++) {
...@@ -254,7 +258,7 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr) ...@@ -254,7 +258,7 @@ bool PrrtBlock_decode(PrrtBlock *block_ptr)
gather_data_packets(block_ptr, fec, idx_p); gather_data_packets(block_ptr, fec, idx_p);
gather_redundancy_packets(block_ptr, fec, idx_p); gather_redundancy_packets(block_ptr, fec, idx_p);
check(PrrtCoder_decode(coder, fec, idx_p, length) == EXIT_SUCCESS, "Could not decode current block."); check(PrrtCoder_decode(block_ptr->coder, fec, idx_p, length) == EXIT_SUCCESS, "Could not decode current block.");
for(j = 0; j < k; j++) { for(j = 0; j < k; j++) {
if(idx_p[j] >= k) { if(idx_p[j] >= k) {
......
...@@ -8,21 +8,21 @@ ...@@ -8,21 +8,21 @@
#include "vdmcode/block_code.h" #include "vdmcode/block_code.h"
typedef struct prrtBlock { typedef struct prrtBlock {
PrrtCodingParams* codingParams; PrrtCodingConfiguration* codingParams;
prrtPacketLength_t largestPayloadLength; prrtPacketLength_t largestPayloadLength;
prrtSequenceNumber_t baseSequenceNumber; prrtSequenceNumber_t baseSequenceNumber;
List*dataPackets; List*dataPackets;
List*redundancyPackets; List*redundancyPackets;
bool isCoded; bool isCoded;
PrrtCoder *coder;
pthread_mutex_t lock; pthread_mutex_t lock;
PrrtCoder *coder;
} PrrtBlock; } PrrtBlock;
/** /**
* Allocate space for a block. * Allocate space for a block.
*/ */
PrrtBlock * PrrtBlock_create(PrrtCodingParams *cpar, prrtSequenceNumber_t baseSequenceNumber); PrrtBlock * PrrtBlock_create(PrrtCodingConfiguration *cpar, PrrtCoder* coder, prrtSequenceNumber_t baseSequenceNumber);
/** /**
* Frees the PrrtBlock data structure. * Frees the PrrtBlock data structure.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../util/dbg.h" #include "../util/dbg.h"
#include "channelStateInformation.h" #include "channelStateInformation.h"
#include "clock.h" #include "clock.h"
#include "receiver.h"
PrrtChannelStateInformation * PrrtChannelStateInformation_create() PrrtChannelStateInformation * PrrtChannelStateInformation_create()
{ {
...@@ -15,6 +16,15 @@ PrrtChannelStateInformation * PrrtChannelStateInformation_create() ...@@ -15,6 +16,15 @@ PrrtChannelStateInformation * PrrtChannelStateInformation_create()
csi->rtprop = TIMESTAMP_SPACE; csi->rtprop = TIMESTAMP_SPACE;
csi->rtprop_filter_length_us = 2 * 1000 * 1000; // 2 seconds csi->rtprop_filter_length_us = 2 * 1000 * 1000; // 2 seconds
csi->deliveryRate = 0; csi->deliveryRate = 0;
csi->btlbw = 0;
csi->btlbw_next_round_delivered = 0;
csi->btlbw_round_start = false;
csi->btlbw_round_count = 0;
csi->btlbw_filter_length = 10;
csi->appLimited = 0;
csi->plr = 0.0;
return csi; return csi;
error: error:
...@@ -42,11 +52,16 @@ void PrrtChannelStateInformation_update_plr(PrrtChannelStateInformation *csi, pr ...@@ -42,11 +52,16 @@ void PrrtChannelStateInformation_update_plr(PrrtChannelStateInformation *csi, pr
} }
void PrrtChannelStateInformation_update_delivery_rate(PrrtChannelStateInformation *csi, prrtDeliveryRate_t rate) { void PrrtChannelStateInformation_update_delivery_rate(PrrtChannelStateInformation *csi, PrrtPacket* packet, prrtDeliveryRate_t rate) {
pthread_mutex_lock(&csi->lock); pthread_mutex_lock(&csi->lock);
csi->deliveryRate = rate; csi->deliveryRate = rate;
pthread_mutex_unlock(&csi->lock); pthread_mutex_unlock(&csi->lock);
} }
void PrrtChannelStateInformation_update_app_limited(PrrtChannelStateInformation *csi, bool appLimited) {
pthread_mutex_lock(&csi->lock);
csi->appLimited = appLimited;
pthread_mutex_unlock(&csi->lock);
}
prrtTimedelta_t PrrtChannelStateInformation_get_rtprop(PrrtChannelStateInformation *csi) prrtTimedelta_t PrrtChannelStateInformation_get_rtprop(PrrtChannelStateInformation *csi)
{ {
...@@ -71,4 +86,12 @@ prrtPacketLossRate_t PrrtChannelStateInformation_get_plr(PrrtChannelStateInforma ...@@ -71,4 +86,12 @@ prrtPacketLossRate_t PrrtChannelStateInformation_get_plr(PrrtChannelStateInforma
prrtDeliveryRate_t PrrtChannelStateInformation_get_delivery_rate(PrrtChannelStateInformation *csi) { prrtDeliveryRate_t PrrtChannelStateInformation_get_delivery_rate(PrrtChannelStateInformation *csi) {
return csi->deliveryRate; return csi->deliveryRate;
}
prrtDeliveryRate_t PrrtChannelStateInformation_get_btlbw(PrrtChannelStateInformation *csi) {
return csi->btlbw;
}
bool PrrtChannelStateInformation_get_app_limited(PrrtChannelStateInformation *csi) {
return csi->appLimited;
} }
\ No newline at end of file
...@@ -6,22 +6,37 @@ ...@@ -6,22 +6,37 @@
typedef struct prrtChannelStateInformation { typedef struct prrtChannelStateInformation {
pthread_mutex_t lock; pthread_mutex_t lock;
prrtTimedelta_t rtprop; prrtTimedelta_t rtprop;
prrtTimestamp_t rtprop_stamp; prrtTimestamp_t rtprop_stamp;
prrtTimedelta_t rtprop_filter_length_us; prrtTimedelta_t rtprop_filter_length_us;
bool rtprop_expired; bool rtprop_expired;
prrtPacketLossRate_t plr; prrtPacketLossRate_t plr;
prrtDeliveryRate_t deliveryRate; prrtDeliveryRate_t deliveryRate;
prrtDeliveryRate_t btlbw;
prrtByteCount_t btlbw_next_round_delivered;
bool btlbw_round_start;
uint32_t btlbw_round_count;
uint8_t btlbw_filter_length;
bool appLimited;
} PrrtChannelStateInformation; } PrrtChannelStateInformation;
PrrtChannelStateInformation* PrrtChannelStateInformation_create(void); PrrtChannelStateInformation* PrrtChannelStateInformation_create(void);
void PrrtChannelStateInformation_update_rtprop(PrrtChannelStateInformation *csi, prrtTimedelta_t rtprop); void PrrtChannelStateInformation_update_rtprop(PrrtChannelStateInformation *csi, prrtTimedelta_t rtprop);
prrtTimedelta_t PrrtChannelStateInformation_get_rtprop(PrrtChannelStateInformation *csi); prrtTimedelta_t PrrtChannelStateInformation_get_rtprop(PrrtChannelStateInformation *csi);
prrtDeliveryRate_t PrrtChannelStateInformation_get_delivery_rate(PrrtChannelStateInformation *csi); prrtDeliveryRate_t PrrtChannelStateInformation_get_delivery_rate(PrrtChannelStateInformation *csi);
prrtDeliveryRate_t PrrtChannelStateInformation_get_btlbw(PrrtChannelStateInformation *csi);
bool PrrtChannelStateInformation_get_app_limited(PrrtChannelStateInformation *csi);
prrtPacketLossRate_t PrrtChannelStateInformation_get_plr(PrrtChannelStateInformation* csi); prrtPacketLossRate_t PrrtChannelStateInformation_get_plr(PrrtChannelStateInformation* csi);
void PrrtChannelStateInformation_update_plr(PrrtChannelStateInformation *csi, prrtSequenceNumber_t erasures, void PrrtChannelStateInformation_update_plr(PrrtChannelStateInformation *csi, prrtSequenceNumber_t erasures,
prrtSequenceNumber_t packets); prrtSequenceNumber_t packets);
void PrrtChannelStateInformation_update_delivery_rate(PrrtChannelStateInformation *csi, prrtDeliveryRate_t rate); void PrrtChannelStateInformation_update_delivery_rate(PrrtChannelStateInformation *csi, PrrtPacket* packet, prrtDeliveryRate_t rate);
void PrrtChannelStateInformation_update_app_limited(PrrtChannelStateInformation *csi, bool appLimited);
bool PrrtChannelStateInformation_destroy(PrrtChannelStateInformation* csi); bool PrrtChannelStateInformation_destroy(PrrtChannelStateInformation* csi);
void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi); void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi);
......
...@@ -2,70 +2,37 @@ ...@@ -2,70 +2,37 @@
#include "../util/common.h" #include "../util/common.h"
#include "../util/dbg.h" #include "../util/dbg.h"
#include "../defines.h" #include "../defines.h"
#include "codingParams.h"
PrrtCodingParams *PrrtCodingParams_create(void)
{
PrrtCodingParams *cpar = calloc(1, sizeof(PrrtCodingParams));
check_mem(cpar);
pthread_mutex_init(&cpar->lock, NULL);
cpar->coder = NULL;
uint8_t* n_cycle = calloc(1, sizeof(uint8_t)); PrrtCodingConfiguration *PrrtCodingConfiguration_create(uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
n_cycle[0] = N_START - K_START; {
PrrtCodingParams_update(cpar, K_START, N_START, 1, n_cycle); PrrtCodingConfiguration *cc = calloc(1, sizeof(PrrtCodingConfiguration));
check_mem(cc);
cc->k = k;
cc->n = n;
cc->r = cc->n - cc->k;
cc->c = c;
if(n_cycle != NULL) {
cc->n_cycle = (uint8_t*) realloc(cc->n_cycle, cc->c * sizeof(int8_t));
memcpy(cc->n_cycle, n_cycle, cc->c * sizeof(int8_t));
}
return cpar; return cc;
error: error:
PERROR("Memory issue.%s",""); PERROR("Memory issue.%s","");
return NULL; return NULL;
} }
bool PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) { PrrtCodingConfiguration *PrrtCodingConfiguration_copy(PrrtCodingConfiguration *codingConfiguration) {
cpar->k = k; return PrrtCodingConfiguration_create(codingConfiguration->k, codingConfiguration->n, codingConfiguration->c, codingConfiguration->n_cycle);
cpar->n = n;
cpar->r = cpar->n - cpar->k;
cpar->c = c;
if(cpar->n_cycle != NULL) {
free(cpar->n_cycle);
}
cpar->n_cycle = n_cycle;
PrrtCoder_get_coder(&cpar->coder, n, k);
return true;
} }
PrrtCodingParams* PrrtCodingParams_copy(PrrtCodingParams *cpar) { bool PrrtCodingConfiguration_destroy(PrrtCodingConfiguration *codingConfiguration) {
PrrtCodingParams *result = PrrtCodingParams_create(); if(codingConfiguration->n_cycle != NULL) {
check(pthread_mutex_lock(&cpar->lock) == EXIT_SUCCESS, "Lock failed."); free(codingConfiguration->n_cycle);
result->k = cpar->k;
result->n = cpar->n;
result->r = cpar->r;
result->c = cpar->c;
result->n_cycle = (uint8_t*) realloc(result->n_cycle, result->c * sizeof(int8_t));
memcpy(result->n_cycle, cpar->n_cycle, result->c * sizeof(int8_t));
// PrrtCoder_get_coder(&result->coder, result->n, result->k); // TODO
check(pthread_mutex_unlock(&cpar->lock) == EXIT_SUCCESS, "Unlock failed");
return result;
error:
PERROR("Could not copy%s", "");
return NULL;
}
bool PrrtCodingParams_destroy(PrrtCodingParams * cpar) {
pthread_mutex_destroy(&cpar->lock);
PrrtCoder_destroy(cpar->coder);
if(cpar->n_cycle != NULL) {
free(cpar->n_cycle);
} }
free(cpar); free(codingConfiguration);
return true; return true;
} }
...@@ -4,23 +4,17 @@ ...@@ -4,23 +4,17 @@
#include <pthread.h> #include <pthread.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "vdmcode/block_code.h"
typedef struct prrtCodingParams {
pthread_mutex_t lock;
typedef struct prrtCodingConfiguration {
uint8_t k; uint8_t k;
uint8_t r; uint8_t r;
uint8_t n; uint8_t n;
uint8_t c; uint8_t c;
uint8_t* n_cycle; uint8_t* n_cycle;
} PrrtCodingConfiguration;
PrrtCoder* coder;