Commit d6bbe761 authored by rna's avatar rna
Browse files

Coding parameters can be changed.

parent 07e048f0
...@@ -36,7 +36,7 @@ cdef extern from "proto/codingParams.h": ...@@ -36,7 +36,7 @@ cdef extern from "proto/codingParams.h":
ctypedef prrtCodingParams PrrtCodingParams ctypedef prrtCodingParams PrrtCodingParams
PrrtCodingParams *PrrtCodingParams_create() PrrtCodingParams *PrrtCodingParams_create()
PrrtCodingParams *PrrtCodingParams_copy(PrrtCodingParams *cpar) PrrtCodingParams *PrrtCodingParams_copy(PrrtCodingParams *cpar)
bint PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n) bint PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
bint PrrtCodingParams_destroy(PrrtCodingParams *cpar) bint PrrtCodingParams_destroy(PrrtCodingParams *cpar)
cdef extern from "util/list.h": cdef extern from "util/list.h":
...@@ -137,7 +137,7 @@ cdef extern from "proto/socket.h": ...@@ -137,7 +137,7 @@ cdef extern from "proto/socket.h":
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) 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) PrrtCodingParams *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) uint32_t PrrtSocket_get_rtprop(PrrtSocket *socket)
......
...@@ -11,7 +11,9 @@ PrrtCodingParams *PrrtCodingParams_create(void) ...@@ -11,7 +11,9 @@ PrrtCodingParams *PrrtCodingParams_create(void)
pthread_mutex_init(&cpar->lock, NULL); pthread_mutex_init(&cpar->lock, NULL);
cpar->coder = NULL; cpar->coder = NULL;
PrrtCodingParams_update(cpar, K_START, N_START); uint8_t* n_cycle = calloc(1, sizeof(uint8_t));
n_cycle[0] = N_START - K_START;
PrrtCodingParams_update(cpar, K_START, N_START, 1, n_cycle);
return cpar; return cpar;
...@@ -20,16 +22,15 @@ PrrtCodingParams *PrrtCodingParams_create(void) ...@@ -20,16 +22,15 @@ PrrtCodingParams *PrrtCodingParams_create(void)
return NULL; return NULL;
} }
bool PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n) { bool PrrtCodingParams_update(PrrtCodingParams *cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) {
cpar->k = k; cpar->k = k;
cpar->n = n; cpar->n = n;
cpar->r = cpar->n - cpar->k; cpar->r = cpar->n - cpar->k;
cpar->c = 1; cpar->c = c;
if(cpar->n_cycle != NULL) { if(cpar->n_cycle != NULL) {
free(cpar->n_cycle); free(cpar->n_cycle);
} }
cpar->n_cycle = (uint8_t*) calloc(sizeof(uint8_t), cpar->c); cpar->n_cycle = n_cycle;
cpar->n_cycle[0] = (cpar->n - cpar->k);
PrrtCoder_get_coder(&cpar->coder, n, k); PrrtCoder_get_coder(&cpar->coder, n, k);
return true; return true;
} }
......
...@@ -20,7 +20,7 @@ typedef struct prrtCodingParams { ...@@ -20,7 +20,7 @@ typedef struct prrtCodingParams {
PrrtCodingParams * PrrtCodingParams_create(void); PrrtCodingParams * PrrtCodingParams_create(void);
PrrtCodingParams * PrrtCodingParams_copy(PrrtCodingParams *cpar); PrrtCodingParams * PrrtCodingParams_copy(PrrtCodingParams *cpar);
bool PrrtCodingParams_update(PrrtCodingParams * cpar, uint8_t k, uint8_t n); bool PrrtCodingParams_update(PrrtCodingParams * cpar, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle);
bool PrrtCodingParams_destroy(PrrtCodingParams * cpar); bool PrrtCodingParams_destroy(PrrtCodingParams * cpar);
#endif //PRRT_CODING_PARAMS_H #endif //PRRT_CODING_PARAMS_H
...@@ -184,7 +184,7 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) { ...@@ -184,7 +184,7 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) {
PrrtBlock *block = PrrtRepairBlockStore_get_block(socket->repairBlockStore, PrrtBlock *block = PrrtRepairBlockStore_get_block(socket->repairBlockStore,
redundancyPayload->baseSequenceNumber); redundancyPayload->baseSequenceNumber);
if (block == NULL) { if (block == NULL) {
PrrtCodingParams_update(socket->codingParameters, redundancyPayload->k, redundancyPayload->n); PrrtCodingParams_update(socket->codingParameters, redundancyPayload->k, redundancyPayload->n, 0, NULL);
block = PrrtBlock_create(socket->codingParameters, redundancyPayload->baseSequenceNumber); block = PrrtBlock_create(socket->codingParameters, redundancyPayload->baseSequenceNumber);
......
...@@ -513,8 +513,8 @@ bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t val ...@@ -513,8 +513,8 @@ bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t val
return true; return true;
} }
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n) { bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle) {
PrrtCodingParams_update(s->codingParameters, k, n); PrrtCodingParams_update(s->codingParameters, k, n, c, n_cycle);
return true; return true;
} }
......
...@@ -98,7 +98,7 @@ bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t val ...@@ -98,7 +98,7 @@ bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t val
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name); uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name);
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n); bool 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); PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s);
......
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.stdlib cimport malloc, free from libc.stdlib cimport malloc, free
from posix.time cimport timespec from posix.time cimport timespec
cimport cython
cimport cprrt cimport cprrt
...@@ -88,38 +89,21 @@ cdef extern from "util/pipe.c": ...@@ -88,38 +89,21 @@ cdef extern from "util/pipe.c":
cdef extern from "util/mpsc_queue.c": cdef extern from "util/mpsc_queue.c":
pass pass
cdef class PrrtCodingConfiguration: class PrrtCodingConfiguration:
cdef cprrt.PrrtCodingParams* _c_config def __init__(self, n, k, n_cycle):
# TODO: Validity checks
def __cinit__(self): # n >= k
self._c_config = cprrt.PrrtCodingParams_create() # sum(n_cycle) == n - k
self.n = n
def __dealloc__(self): self.k = k
if self._c_config != NULL: self.n_cycle = n_cycle
cprrt.PrrtCodingParams_destroy(self._c_config)
def __repr__(self): def __repr__(self):
return "PrrtCodingConfiguration(n={},k={},n_cycle=[{}])".format(self.n, self.k, ",".join(map(str, self.n_cycle))) return "PrrtCodingConfiguration(n={},k={},n_cycle={})".format(self.n, self.k, self.n_cycle)
cdef copy(self, cprrt.PrrtCodingParams* other): #property n_cycle:
cprrt.PrrtCodingParams_destroy(self._c_config) # def __get__(self):
self._c_config = other # return list(<uint8_t[:self._c_config.c]> self._c_config.n_cycle)
property k:
def __get__(self):
return int(self._c_config.k)
property n:
def __get__(self):
return int(self._c_config.n)
property r:
def __get__(self):
return int(self._c_config.r)
property c:
def __get__(self):
return int(self._c_config.c)
property n_cycle:
def __get__(self):
return list(<uint8_t[:self._c_config.c]> self._c_config.n_cycle)
cdef class PrrtSocket: cdef class PrrtSocket:
cdef cprrt.PrrtSocket* _c_socket cdef cprrt.PrrtSocket* _c_socket
...@@ -175,10 +159,16 @@ cdef class PrrtSocket: ...@@ -175,10 +159,16 @@ cdef class PrrtSocket:
def __get__(self): def __get__(self):
if not self.isSender: if not self.isSender:
raise Exception("Not a sender.") raise Exception("Not a sender.")
res = PrrtCodingConfiguration()
cdef cprrt.PrrtCodingParams *params = cprrt.PrrtSocket_get_coding_parameters(self._c_socket) cdef cprrt.PrrtCodingParams *params = cprrt.PrrtSocket_get_coding_parameters(self._c_socket)
res.copy(params) return PrrtCodingConfiguration(params.n, params.k, list(<uint8_t[:params.c]> params.n_cycle))
return res
def __set__(self, params: PrrtCodingConfiguration):
cdef uint8_t* n_cycle
c = len(params.n_cycle)
n_cycle = <uint8_t *> malloc(c * cython.sizeof(int))
for i, x in enumerate(params.n_cycle):
n_cycle[i] = x
cprrt.PrrtSocket_set_coding_parameters(self._c_socket, params.k, params.n, c, n_cycle)
property delivery_rate: property delivery_rate:
def __get__(self): def __get__(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment