Commit 4c5f38ef authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Consistent naming. Small fixes.

parent 526cb9fc
...@@ -6,18 +6,18 @@ ...@@ -6,18 +6,18 @@
#include "socket.h" #include "socket.h"
void * send_data_loop(void *ptr) { void * send_data_loop(void *ptr) {
prrt_socket *sock_ptr = ptr; PrrtSocket *sock_ptr = ptr;
while(1) { while(1) {
pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex); pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex);
while(List_count(sock_ptr->out_queue) == 0) { while(List_count(sock_ptr->out_queue) == 0) {
pthread_cond_wait(&sock_ptr->out_queue_filled_cv, &sock_ptr->out_queue_filled_mutex); pthread_cond_wait(&sock_ptr->out_queue_filled_cv, &sock_ptr->out_queue_filled_mutex);
} }
prrt_packet* packet = List_shift(sock_ptr->out_queue); PrrtPacket * packet = List_shift(sock_ptr->out_queue);
uint8_t buf[MAX_PAYLOAD_LENGTH]; uint8_t buf[MAX_PAYLOAD_LENGTH];
uint32_t length = packet_size(packet); uint32_t length = PrrtPacket_size(packet);
if(encode_packet(buf, MAX_PAYLOAD_LENGTH, packet) < 0) { if(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet) < 0) {
perror("BUF too small."); perror("BUF too small.");
exit(0); exit(0);
} }
...@@ -25,7 +25,7 @@ void * send_data_loop(void *ptr) { ...@@ -25,7 +25,7 @@ void * send_data_loop(void *ptr) {
// SENDING TO ALL RECEIVERS // SENDING TO ALL RECEIVERS
int i; int i;
for(i = 0; i < sock_ptr->receiver_len; i++) { for(i = 0; i < sock_ptr->receiver_len; i++) {
prrt_receiver recv = sock_ptr->receivers[i]; PrrtReceiver recv = sock_ptr->receivers[i];
struct hostent *hp; struct hostent *hp;
...@@ -43,7 +43,7 @@ void * send_data_loop(void *ptr) { ...@@ -43,7 +43,7 @@ void * send_data_loop(void *ptr) {
break; break;
} }
} }
delete_packet(packet); PrrtPacket_destroy(packet);
pthread_mutex_unlock(&sock_ptr->out_queue_filled_mutex); pthread_mutex_unlock(&sock_ptr->out_queue_filled_mutex);
usleep(1); usleep(1);
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
void *receive_feedback_loop(void *ptr) { void *receive_feedback_loop(void *ptr) {
char bufin[MAX_PAYLOAD_LENGTH]; char bufin[MAX_PAYLOAD_LENGTH];
prrt_socket *sock_ptr = ptr; PrrtSocket *sock_ptr = ptr;
while(1) { while(1) {
memset(bufin, 0, MAX_PAYLOAD_LENGTH); memset(bufin, 0, MAX_PAYLOAD_LENGTH);
prrt_packet *t = prrt_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH); PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
if(t != NULL) { if(t != NULL) {
delete_packet(t); PrrtPacket_destroy(t);
} }
usleep(1000); usleep(1000);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include "packet.h" #include "packet.h"
void *encode_general_header(void *buf_ptr, const prrt_packet *packet); void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
void *encode_data_header(void *buf_ptr, void *payload); void *encode_data_header(void *buf_ptr, void *payload);
...@@ -15,36 +15,36 @@ void *decode_data_header(void *buf_ptr, const void *payload_ptr); ...@@ -15,36 +15,36 @@ void *decode_data_header(void *buf_ptr, const void *payload_ptr);
void *decode_feedback_header(void *buf_ptr, void *payload_ptr); void *decode_feedback_header(void *buf_ptr, void *payload_ptr);
uint8_t packet_type(prrt_packet *packet_ptr) { uint8_t PrrtPacket_type(PrrtPacket *packet_ptr) {
return (uint8_t) ((packet_ptr->type_priority >> 4) & 0x0F); return (uint8_t) ((packet_ptr->type_priority >> 4) & 0x0F);
} }
uint8_t packet_priority(prrt_packet *packet_ptr) { uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr) {
return (uint8_t) (packet_ptr->type_priority & 0x0F); return (uint8_t) (packet_ptr->type_priority & 0x0F);
} }
uint16_t packet_size(prrt_packet *packet_ptr) { uint16_t PrrtPacket_size(PrrtPacket *packet_ptr) {
return (uint16_t) (packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE); return (uint16_t) (packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE);
} }
int print_packet(prrt_packet *packet_ptr) { int PrrtPacket_print(PrrtPacket *packet_ptr) {
printf(" 0 1 2 3\n" printf(" 0 1 2 3\n"
" 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n" " 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n"
"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
uint8_t type = packet_type(packet_ptr); uint8_t type = PrrtPacket_type(packet_ptr);
printf("| %5u | %5u | %13u | %29u |\n", type, packet_priority(packet_ptr), packet_ptr->index, packet_ptr->seqno); printf("| %5u | %5u | %13u | %29u |\n", type, PrrtPacket_priority(packet_ptr), packet_ptr->index, packet_ptr->seqno);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
if(type == PACKET_TYPE_DATA) { if(type == PACKET_TYPE_DATA) {
prrt_packet_data_payload * payload = packet_ptr->payload; PrrtPacketDataPayload * payload = packet_ptr->payload;
printf("| %61u |\n", payload->timestamp); printf("| %61u |\n", payload->timestamp);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %29u | %29u |\n", payload->group_round_trip_time, payload->packet_timeout); printf("| %29u | %29u |\n", payload->group_round_trip_time, payload->packet_timeout);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
} }
else if(type == PACKET_TYPE_FEEDBACK) { else if(type == PACKET_TYPE_FEEDBACK) {
prrt_packet_feedback_payload * payload = packet_ptr->payload; PrrtPacketFeedbackPayload * payload = packet_ptr->payload;
printf("| %61u |\n", payload->group_round_trip_time); printf("| %61u |\n", payload->group_round_trip_time);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->forward_trip_time); printf("| %61u |\n", payload->forward_trip_time);
...@@ -67,7 +67,7 @@ int print_packet(prrt_packet *packet_ptr) { ...@@ -67,7 +67,7 @@ int print_packet(prrt_packet *packet_ptr) {
return 0; return 0;
} }
int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) { int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
void * payload = packet_ptr->payload; void * payload = packet_ptr->payload;
if(buf_size < packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE) { if(buf_size < packet_ptr->payload_len + PRRT_PACKET_GENERAL_HEADER_SIZE) {
...@@ -77,7 +77,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) { ...@@ -77,7 +77,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
buf_ptr = encode_general_header(buf_ptr, packet_ptr); buf_ptr = encode_general_header(buf_ptr, packet_ptr);
uint8_t type = packet_type(packet_ptr); uint8_t type = PrrtPacket_type(packet_ptr);
if(type == PACKET_TYPE_DATA) { if(type == PACKET_TYPE_DATA) {
buf_ptr = encode_data_header(buf_ptr, payload); buf_ptr = encode_data_header(buf_ptr, payload);
memcpy(buf_ptr, payload + PRRT_PACKET_DATA_HEADER_SIZE, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE); memcpy(buf_ptr, payload + PRRT_PACKET_DATA_HEADER_SIZE, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
...@@ -92,7 +92,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) { ...@@ -92,7 +92,7 @@ int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
} }
void *encode_feedback_header(void *buf_ptr, void *payload) { void *encode_feedback_header(void *buf_ptr, void *payload) {
prrt_packet_feedback_payload * feedback_payload = payload; PrrtPacketFeedbackPayload * feedback_payload = payload;
uint32_t *receiver_ip = (uint32_t *) buf_ptr; uint32_t *receiver_ip = (uint32_t *) buf_ptr;
*receiver_ip = htonl(feedback_payload->receiver_addr); *receiver_ip = htonl(feedback_payload->receiver_addr);
...@@ -138,7 +138,7 @@ void *encode_feedback_header(void *buf_ptr, void *payload) { ...@@ -138,7 +138,7 @@ void *encode_feedback_header(void *buf_ptr, void *payload) {
} }
void *encode_data_header(void *buf_ptr, void *payload) { void *encode_data_header(void *buf_ptr, void *payload) {
prrt_packet_data_payload * data_payload = payload; PrrtPacketDataPayload * data_payload = payload;
uint32_t *timestamp = (uint32_t *) buf_ptr; uint32_t *timestamp = (uint32_t *) buf_ptr;
*timestamp = htonl(data_payload->timestamp); *timestamp = htonl(data_payload->timestamp);
...@@ -162,7 +162,7 @@ void *encode_data_header(void *buf_ptr, void *payload) { ...@@ -162,7 +162,7 @@ void *encode_data_header(void *buf_ptr, void *payload) {
return buf_ptr; return buf_ptr;
} }
void *encode_general_header(void *buf_ptr, const prrt_packet *packet) { void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) {
uint8_t *type_priority = (uint8_t *) buf_ptr; uint8_t *type_priority = (uint8_t *) buf_ptr;
*type_priority = packet->type_priority; *type_priority = packet->type_priority;
buf_ptr += 1; buf_ptr += 1;
...@@ -178,7 +178,7 @@ void *encode_general_header(void *buf_ptr, const prrt_packet *packet) { ...@@ -178,7 +178,7 @@ void *encode_general_header(void *buf_ptr, const prrt_packet *packet) {
return buf_ptr; return buf_ptr;
} }
int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) { int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
uint32_t payload_len = (uint32_t) (buf_size - PRRT_PACKET_GENERAL_HEADER_SIZE); uint32_t payload_len = (uint32_t) (buf_size - PRRT_PACKET_GENERAL_HEADER_SIZE);
packet_ptr->type_priority = *(uint8_t*) buf_ptr; packet_ptr->type_priority = *(uint8_t*) buf_ptr;
buf_ptr += 1; buf_ptr += 1;
...@@ -193,10 +193,10 @@ int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) { ...@@ -193,10 +193,10 @@ int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
packet_ptr->payload = payload_buffer; packet_ptr->payload = payload_buffer;
packet_ptr->payload_len = payload_len; packet_ptr->payload_len = payload_len;
if(packet_type(packet_ptr) == PACKET_TYPE_DATA) { if(PrrtPacket_type(packet_ptr) == PACKET_TYPE_DATA) {
buf_ptr = decode_data_header(buf_ptr, payload_buffer); 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); 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) { } else if(PrrtPacket_type(packet_ptr) == PACKET_TYPE_FEEDBACK) {
buf_ptr = decode_feedback_header(buf_ptr, payload_buffer); 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); memcpy(payload_buffer + PRRT_PACKET_FEEDBACK_HEADER_SIZE, buf_ptr, payload_len - PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else { } else {
...@@ -206,7 +206,7 @@ int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) { ...@@ -206,7 +206,7 @@ int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr) {
} }
void *decode_feedback_header(void *buf_ptr, void *payload_ptr) { void *decode_feedback_header(void *buf_ptr, void *payload_ptr) {
prrt_packet_feedback_payload *feedback_payload = (prrt_packet_feedback_payload *) payload_ptr; PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) payload_ptr;
uint32_t *receiver_addr = (uint32_t *) buf_ptr; uint32_t *receiver_addr = (uint32_t *) buf_ptr;
feedback_payload->receiver_addr = ntohl(*receiver_addr); feedback_payload->receiver_addr = ntohl(*receiver_addr);
...@@ -252,7 +252,7 @@ void *decode_feedback_header(void *buf_ptr, void *payload_ptr) { ...@@ -252,7 +252,7 @@ void *decode_feedback_header(void *buf_ptr, void *payload_ptr) {
} }
void *decode_data_header(void *buf_ptr, const void *payload_ptr) { void *decode_data_header(void *buf_ptr, const void *payload_ptr) {
prrt_packet_data_payload * data_payload = (prrt_packet_data_payload *) payload_ptr; PrrtPacketDataPayload * data_payload = (PrrtPacketDataPayload *) payload_ptr;
uint32_t *timestamp = (uint32_t *) buf_ptr; uint32_t *timestamp = (uint32_t *) buf_ptr;
data_payload->timestamp = ntohl(*timestamp); data_payload->timestamp = ntohl(*timestamp);
...@@ -276,7 +276,7 @@ void *decode_data_header(void *buf_ptr, const void *payload_ptr) { ...@@ -276,7 +276,7 @@ void *decode_data_header(void *buf_ptr, const void *payload_ptr) {
return buf_ptr; return buf_ptr;
} }
int delete_packet(prrt_packet *packet_ptr) { int PrrtPacket_destroy(PrrtPacket *packet_ptr) {
if(packet_ptr->payload != NULL) { if(packet_ptr->payload != NULL) {
free(packet_ptr->payload); free(packet_ptr->payload);
} }
...@@ -285,17 +285,18 @@ int delete_packet(prrt_packet *packet_ptr) { ...@@ -285,17 +285,18 @@ int delete_packet(prrt_packet *packet_ptr) {
} }
// PACKET SPECIFIC CODE // PACKET SPECIFIC CODE
int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *data_ptr, unsigned long data_len) { int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
uint32_t payload_length = (uint32_t) (data_len + sizeof(prrt_packet_data_payload)); unsigned long data_len) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(PrrtPacketDataPayload));
packet_ptr->type_priority = PACKET_TYPE_DATA << 4; packet_ptr->type_priority = PACKET_TYPE_DATA << 4;
packet_ptr->type_priority |= priority & 0x0F; packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = 17; // TODO: replace with sensible value packet_ptr->index = 17; // TODO: replace with sensible value
packet_ptr->seqno = 4711; // TODO: replace with sensible value packet_ptr->seqno = 4711; // TODO: replace with sensible value
void *content_buf = malloc(sizeof(prrt_packet_data_payload) + data_len); void *content_buf = malloc(sizeof(PrrtPacketDataPayload) + data_len);
prrt_packet_data_payload * source_payload = content_buf; PrrtPacketDataPayload * source_payload = content_buf;
struct timeval tv; struct timeval tv;
gettimeofday(&tv,NULL); gettimeofday(&tv,NULL);
...@@ -308,22 +309,24 @@ int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *da ...@@ -308,22 +309,24 @@ int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *da
source_payload->feedback_timeout = 170; // TODO: payload->feedback_timer source_payload->feedback_timeout = 170; // TODO: payload->feedback_timer
packet_ptr->payload = content_buf; packet_ptr->payload = content_buf;
memcpy(content_buf + sizeof(prrt_packet_data_payload), data_ptr, data_len); memcpy(content_buf + sizeof(PrrtPacketDataPayload), data_ptr, data_len);
packet_ptr->payload_len = payload_length; packet_ptr->payload_len = payload_length;
return 0; return 0;
} }
prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time, PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap, uint16_t ngap, uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
uint16_t burst, uint16_t nburst, uint32_t bandwidth, uint32_t buffer_feedback) { uint16_t ngap,
prrt_packet *packet_ptr = malloc(sizeof(prrt_packet)); uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback) {
PrrtPacket *packet_ptr = malloc(sizeof(PrrtPacket));
packet_ptr->type_priority = PACKET_TYPE_FEEDBACK << 4; packet_ptr->type_priority = PACKET_TYPE_FEEDBACK << 4;
packet_ptr->type_priority |= priority & 0x0F; packet_ptr->type_priority |= priority & 0x0F;
packet_ptr->index = index; packet_ptr->index = index;
packet_ptr->seqno = seqno; packet_ptr->seqno = seqno;
prrt_packet_feedback_payload * payload = malloc(sizeof(prrt_packet_feedback_payload)); PrrtPacketFeedbackPayload * payload = malloc(sizeof(PrrtPacketFeedbackPayload));
payload->group_round_trip_time = round_trip_time; payload->group_round_trip_time = round_trip_time;
payload->forward_trip_time = forward_trip_time; payload->forward_trip_time = forward_trip_time;
...@@ -336,7 +339,7 @@ prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t se ...@@ -336,7 +339,7 @@ prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t se
payload->buffer_feedback = buffer_feedback; payload->buffer_feedback = buffer_feedback;
packet_ptr->payload = (void*) payload; packet_ptr->payload = (void*) payload;
packet_ptr->payload_len = (uint32_t) (sizeof(prrt_packet_feedback_payload)); packet_ptr->payload_len = (uint32_t) (sizeof(PrrtPacketFeedbackPayload));
return packet_ptr; return packet_ptr;
} }
\ No newline at end of file
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#define PACKET_TYPE_DATA 0 #define PACKET_TYPE_DATA 0
#define PACKET_TYPE_REPETITION 1 #define PACKET_TYPE_REPETITION 1
#define PACKET_TYPE_PARITY 2 #define PACKET_TYPE_REDUNDANCY 2
#define PACKET_TYPE_FEEDBACK 3 #define PACKET_TYPE_FEEDBACK 3
#define PACKET_TYPE_PRE_REDUNDANCY 4
#define PACKET_TYPE_CHANNEL_FEEDBACK 5
#define PRRT_PACKET_GENERAL_HEADER_SIZE 4 #define PRRT_PACKET_GENERAL_HEADER_SIZE 4
typedef struct { typedef struct {
...@@ -15,7 +17,7 @@ typedef struct { ...@@ -15,7 +17,7 @@ typedef struct {
uint16_t seqno; uint16_t seqno;
void* payload; void* payload;
uint32_t payload_len; uint32_t payload_len;
} prrt_packet; } PrrtPacket;
#define PRRT_PACKET_DATA_HEADER_SIZE 12 #define PRRT_PACKET_DATA_HEADER_SIZE 12
typedef struct { typedef struct {
...@@ -24,7 +26,7 @@ typedef struct { ...@@ -24,7 +26,7 @@ typedef struct {
uint16_t packet_timeout; uint16_t packet_timeout;
uint16_t decoding_timeout; uint16_t decoding_timeout;
uint16_t feedback_timeout; uint16_t feedback_timeout;
} prrt_packet_data_payload; } PrrtPacketDataPayload;
# define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32 # define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32
typedef struct { typedef struct {
...@@ -38,33 +40,29 @@ typedef struct { ...@@ -38,33 +40,29 @@ typedef struct {
uint16_t nburst; uint16_t nburst;
uint32_t bandwidth_estimate; uint32_t bandwidth_estimate;
uint32_t buffer_feedback; uint32_t buffer_feedback;
} prrt_packet_feedback_payload; } PrrtPacketFeedbackPayload;
uint8_t packet_type(prrt_packet *packet_ptr); uint8_t PrrtPacket_type(PrrtPacket *packet_ptr);
uint8_t packet_priority(prrt_packet *packet_ptr); uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr);
uint16_t packet_size(prrt_packet *packet_ptr); uint16_t PrrtPacket_size(PrrtPacket *packet_ptr);
int print_packet(prrt_packet *packet_ptr); int PrrtPacket_print(PrrtPacket *packet_ptr);
// CREATE: PRRT_PACKET // CREATE: PRRT_PACKET
// ENCODE: PRRT_PACKET -> BYTES // ENCODE: PRRT_PACKET -> BYTES
// DECODE: BYTES -> PRRT_PACKET // DECODE: BYTES -> PRRT_PACKET
// DELETE: // DESTROY:
int decode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr);
int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, const void *data_ptr,
unsigned long data_len);
int create_packet_data(prrt_packet *packet_ptr, uint8_t priority, const void *data_ptr, unsigned long data_len); PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
int encode_packet(void *buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr); uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap,
int delete_packet(prrt_packet *packet_ptr); uint16_t ngap, uint16_t burst, uint16_t nburst, uint32_t bandwidth,
uint32_t buffer_feedback);
int create_packet_repetition(prrt_packet packet, uint8_t priority); int PrrtPacket_decode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int create_packet_parity(prrt_packet packet, uint8_t priority); int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet_ptr);
prrt_packet *create_packet_feedback(uint8_t priority, uint8_t index, uint16_t seqno, uint32_t round_trip_time,
uint32_t forward_trip_time, uint32_t packet_loss_rate, uint16_t gap, uint16_t ngap,
uint16_t burst, uint16_t nburst, uint32_t bandwidth, uint32_t buffer_feedback);
int encode_packet_feedback(void *buf_ptr, uint16_t buf_size, prrt_packet *pkt_ptr);
int decode_packet_feedback(void* buf_ptr, uint16_t buf_size, prrt_packet *packet_ptr);
#endif //PRRT_FRAME_H #endif //PRRT_FRAME_H
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "feedback_receiver.h" #include "feedback_receiver.h"
#include "data_transmitter.h" #include "data_transmitter.h"
int prrt_create_socket(prrt_socket *sock_ptr, uint16_t port, uint8_t is_sender) { int PrrtSocket_create(PrrtSocket *sock_ptr, uint16_t port, uint8_t is_sender) {
// Create Data Socket // Create Data Socket
if((sock_ptr->fd_data = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { if((sock_ptr->fd_data = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("cannot create socket"); perror("cannot create socket");
...@@ -70,8 +70,8 @@ int prrt_create_socket(prrt_socket *sock_ptr, uint16_t port, uint8_t is_sender) ...@@ -70,8 +70,8 @@ int prrt_create_socket(prrt_socket *sock_ptr, uint16_t port, uint8_t is_sender)
return 0; return 0;
} }
int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port) { int PrrtSocket_connect(PrrtSocket *sock_ptr, char *host, uint16_t port) {
prrt_receiver recv = {host , port}; PrrtReceiver recv = {host , port};
if(sock_ptr->receiver_len < PRRT_MAX_RECEIVER_COUNT) { if(sock_ptr->receiver_len < PRRT_MAX_RECEIVER_COUNT) {
sock_ptr->receivers[sock_ptr->receiver_len] =recv; sock_ptr->receivers[sock_ptr->receiver_len] =recv;
...@@ -83,11 +83,11 @@ int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port) { ...@@ -83,11 +83,11 @@ int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port) {
return 0; return 0;
} }
int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) { int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len) {
pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex); pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex);
prrt_packet* packet = malloc(sizeof(prrt_packet)); PrrtPacket * packet = malloc(sizeof(PrrtPacket));
create_packet_data(packet, 5, data, data_len); PrrtPacket_create_data_packet(packet, 5, data, data_len);
List_push(sock_ptr->out_queue, packet); List_push(sock_ptr->out_queue, packet);
pthread_cond_signal(&sock_ptr->out_queue_filled_cv); pthread_cond_signal(&sock_ptr->out_queue_filled_cv);
...@@ -96,7 +96,7 @@ int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) { ...@@ -96,7 +96,7 @@ int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) {
return 0; return 0;
} }
prrt_packet *prrt_recv(prrt_socket *sock_ptr) { PrrtPacket *PrrtSocket_recv(PrrtSocket *sock_ptr) {
unsigned char buffer[MAX_PAYLOAD_LENGTH]; unsigned char buffer[MAX_PAYLOAD_LENGTH];
// RECEIVE DATA // RECEIVE DATA
...@@ -108,8 +108,8 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) { ...@@ -108,8 +108,8 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
uint16_t remote_port = ntohs(remote.sin_port); uint16_t remote_port = ntohs(remote.sin_port);
char *remote_host = inet_ntoa(remote.sin_addr); char *remote_host = inet_ntoa(remote.sin_addr);
prrt_packet *packet = malloc(sizeof(prrt_packet)); PrrtPacket *packet = malloc(sizeof(PrrtPacket));
decode_packet(buffer, (uint16_t) n, packet); PrrtPacket_decode(buffer, (uint16_t) n, packet);
// REPLY // REPLY
struct sockaddr_in targetaddr; struct sockaddr_in targetaddr;
...@@ -121,11 +121,11 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) { ...@@ -121,11 +121,11 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
hp = gethostbyname(remote_host); hp = gethostbyname(remote_host);
memcpy((void *)&targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length); memcpy((void *)&targetaddr.sin_addr, hp->h_addr_list[0], (size_t) hp->h_length);
prrt_packet* feedback_pkt_ptr = create_packet_feedback(0, 19, 4715, 7, 3, 50, 4, 6, 8, 9, 5, 1); PrrtPacket * feedback_pkt_ptr = PrrtPacket_create_feedback_packet(0, 19, 4715, 7, 3, 50, 4, 6, 8, 9, 5, 1);
uint8_t buf[MAX_PAYLOAD_LENGTH]; uint8_t buf[MAX_PAYLOAD_LENGTH];
uint32_t length = packet_size(feedback_pkt_ptr); uint32_t length = PrrtPacket_size(feedback_pkt_ptr);
if(encode_packet(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr) < 0) { if(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr) < 0) {
perror("BUF too small."); perror("BUF too small.");
} else { } else {
if((sendto(sock_ptr->fd_feedback, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) < 0)) { if((sendto(sock_ptr->fd_feedback, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) < 0)) {
...@@ -137,7 +137,7 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) { ...@@ -137,7 +137,7 @@ prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
return packet; return packet;
} }
int prrt_close_socket(prrt_socket *sock_ptr) { int PrrtSocket_close(PrrtSocket *sock_ptr) {
// TODO: shut down threads; // TODO: shut down threads;
// TODO: clean up all receivers // TODO: clean up all receivers
...@@ -151,7 +151,7 @@ int prrt_close_socket(prrt_socket *sock_ptr) { ...@@ -151,7 +151,7 @@ int prrt_close_socket(prrt_socket *sock_ptr) {
return 0; return 0;
} }
prrt_packet * prrt_recv_feedback(prrt_socket *sock_ptr, void *bufin, size_t length) {