Commit 1a0866a7 authored by Andreas Schmidt's avatar Andreas Schmidt

Fix decoding.

parent eec89693
......@@ -11,6 +11,10 @@ void *encode_data_header(void *buf_ptr, void *payload);
void *encode_feedback_header(void *buf_ptr, void *payload);
void *decode_data_header(void *buf_ptr, const void *payload_ptr);
void *decode_feedback_header(void *buf_ptr, void *payload_ptr);
uint8_t packet_type(prrt_packet *packet_ptr) {
return (uint8_t) ((packet_ptr->type_priority >> 4) & 0x0F);
}
......@@ -79,7 +83,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
memcpy(buf_ptr, payload + PRRT_PACKET_DATA_HEADER_SIZE, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else if (type == PACKET_TYPE_FEEDBACK) {
buf_ptr = encode_feedback_header(buf_ptr, payload);
memcpy(buf_ptr, payload + PRRT_PACKET_FEEDBACK_SIZE, packet_ptr->payload_len - PRRT_PACKET_FEEDBACK_SIZE);
memcpy(buf_ptr, payload + PRRT_PACKET_FEEDBACK_HEADER_SIZE, packet_ptr->payload_len - PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else {
perror("NOT IMPLEMENTED");
return -1;
......@@ -106,7 +110,6 @@ void *encode_feedback_header(void *buf_ptr, void *payload) {
*packet_loss_rate = htonl(feedback_payload->packet_loss_rate);
buf_ptr+=4;
uint16_t *gap = (uint16_t *) buf_ptr;
*gap = htons(feedback_payload->gap);
buf_ptr+=2;
......@@ -134,7 +137,6 @@ void *encode_feedback_header(void *buf_ptr, void *payload) {
return buf_ptr;
}
void *encode_data_header(void *buf_ptr, void *payload) {
prrt_packet_data_payload * data_payload = payload;
......@@ -179,46 +181,99 @@ void *encode_general_header(void *buf_ptr, const prrt_packet *packet) {
int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
uint32_t payload_len = (uint32_t) (buf_size - PRRT_PACKET_GENERAL_HEADER_SIZE);
packet_ptr->type_priority = *(uint8_t*) buf_ptr;
uint8_t* index_ptr = (uint8_t*) (buf_ptr+1);
buf_ptr += 1;
uint8_t* index_ptr = (uint8_t*) buf_ptr;
packet_ptr->index = *index_ptr;
uint16_t* seqno_prt = (uint16_t*) (buf_ptr+2);
buf_ptr += 1;
uint16_t* seqno_prt = (uint16_t*) buf_ptr;
packet_ptr->seqno = ntohs(*seqno_prt);
buf_ptr += 2;
void* payload_buffer = malloc(payload_len);
packet_ptr->payload = payload_buffer;
packet_ptr->payload_len = payload_len;
if(packet_type(packet_ptr) == PACKET_TYPE_DATA+100) {
prrt_packet_data_payload * data_payload = (prrt_packet_data_payload *) payload_buffer;
if(packet_type(packet_ptr) == PACKET_TYPE_DATA) {
buf_ptr = decode_data_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_DATA_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else if(packet_type(packet_ptr) == PACKET_TYPE_FEEDBACK) {
buf_ptr = decode_feedback_header(buf_ptr, payload_buffer);
memcpy(payload_buffer + PRRT_PACKET_FEEDBACK_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else {
uint32_t *timestamp = (uint32_t *) buf_ptr;
data_payload->timestamp = *timestamp;
buf_ptr += 4;
}
return 0;
}
uint16_t *group_round_trip_time = (uint16_t *) buf_ptr;
data_payload->group_round_trip_time = *group_round_trip_time;
buf_ptr += 2;
void *decode_feedback_header(void *buf_ptr, void *payload_ptr) {
prrt_packet_feedback_payload *feedback_payload = (prrt_packet_feedback_payload *) payload_ptr;
uint16_t *packet_timeout = (uint16_t *) buf_ptr;
data_payload->packet_timeout = *packet_timeout;
buf_ptr += 2;
uint32_t *receiver_addr = (uint32_t *) buf_ptr;
feedback_payload->receiver_addr = ntohl(*receiver_addr);
buf_ptr += 4;
uint16_t *decoding_timeout = (uint16_t *) buf_ptr;
data_payload->decoding_timeout = *decoding_timeout;
buf_ptr += 2;
uint32_t *group_round_trip_time = (uint32_t *) buf_ptr;
feedback_payload->group_round_trip_time = ntohl(*group_round_trip_time);
buf_ptr += 4;
uint16_t *feedback_timeout = (uint16_t *) buf_ptr;
data_payload->feedback_timeout = *feedback_timeout;
buf_ptr += 2;
uint32_t *forward_trip_time = (uint32_t *) buf_ptr;
feedback_payload->forward_trip_time = ntohl(*forward_trip_time);
buf_ptr += 4;
memcpy(payload_buffer, buf_ptr, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else {
// TODO: packet specific transformation
memcpy(payload_buffer, buf_ptr, payload_len);
}
uint32_t *packet_loss_rate = (uint32_t *) buf_ptr;
feedback_payload->packet_loss_rate = ntohl(*packet_loss_rate);
buf_ptr += 4;
packet_ptr->payload = payload_buffer;
packet_ptr->payload_len = payload_len;
uint16_t *gap = (uint16_t *) buf_ptr;
feedback_payload->gap = ntohs(*gap);
buf_ptr += 2;
return 0;
uint16_t *ngap = (uint16_t *) buf_ptr;
feedback_payload->ngap = ntohs(*ngap);
buf_ptr += 2;
uint16_t *burst = (uint16_t *) buf_ptr;
feedback_payload->burst = ntohs(*burst);
buf_ptr += 2;
uint16_t *nburst = (uint16_t *) buf_ptr;
feedback_payload->nburst = ntohs(*nburst);
buf_ptr += 2;
uint32_t *bandwidth_estimate = (uint32_t *) buf_ptr;
feedback_payload->bandwidth_estimate = ntohl(*bandwidth_estimate);
buf_ptr += 4;
uint32_t *buffer_feedback = (uint32_t *) buf_ptr;
feedback_payload->buffer_feedback = ntohl(*buffer_feedback);
buf_ptr += 4;
return buf_ptr;
}
void *decode_data_header(void *buf_ptr, const void *payload_ptr) {
prrt_packet_data_payload * data_payload = (prrt_packet_data_payload *) payload_ptr;
uint32_t *timestamp = (uint32_t *) buf_ptr;
data_payload->timestamp = ntohl(*timestamp);
buf_ptr += 4;
uint16_t *group_round_trip_time = (uint16_t *) buf_ptr;
data_payload->group_round_trip_time = ntohs(*group_round_trip_time);
buf_ptr += 2;
uint16_t *packet_timeout = (uint16_t *) buf_ptr;
data_payload->packet_timeout = ntohs(*packet_timeout);
buf_ptr += 2;
uint16_t *decoding_timeout = (uint16_t *) buf_ptr;
data_payload->decoding_timeout = ntohs(*decoding_timeout);
buf_ptr += 2;
uint16_t *feedback_timeout = (uint16_t *) buf_ptr;
data_payload->feedback_timeout = ntohs(*feedback_timeout);
buf_ptr += 2;
return buf_ptr;
}
int delete_packet(prrt_packet *packet_ptr) {
......
......@@ -26,7 +26,7 @@ typedef struct {
uint16_t feedback_timeout;
} prrt_packet_data_payload;
# define PRRT_PACKET_FEEDBACK_SIZE 32
# define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32
typedef struct {
uint32_t receiver_addr;
uint32_t group_round_trip_time;
......
Markdown is supported
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