Commit f28146f4 authored by Andreas Schmidt's avatar Andreas Schmidt

Add receiver address to feedback packet.Currently fixed to 10.0.0.1.

parent b8c06bb9
......@@ -6,6 +6,7 @@
#include "../util/common.h"
#include "../util/dbg.h"
#include <stdbool.h>
#include <arpa/inet.h>
#include "packet.h"
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
......@@ -64,6 +65,13 @@ int PrrtPacket_print(PrrtPacket *packet_ptr)
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
} else if(type == PACKET_TYPE_FEEDBACK) {
PrrtPacketFeedbackPayload *payload = packet_ptr->payload;
struct sockaddr_in receiver;
receiver.sin_addr.s_addr = payload->receiver_addr;
char* address = inet_ntoa(receiver.sin_addr);
printf("| %61s |\n", address);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->group_round_trip_time);
printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n");
printf("| %61u |\n", payload->forward_trip_time);
......@@ -142,8 +150,7 @@ bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
buf_ptr = encode_redundancy_header(buf_ptr, payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if(type == PACKET_TYPE_FEEDBACK) {
buf_ptr = encode_feedback_header(buf_ptr, payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_FEEDBACK_HEADER_SIZE);
encode_feedback_header(buf_ptr, payload);
} else {
perror("NOT IMPLEMENTED");
return false;
......@@ -178,7 +185,7 @@ void *encode_feedback_header(void *buf_ptr, const void *payload)
const PrrtPacketFeedbackPayload *feedbackPayload = payload;
uint32_t *receiver_ip = (uint32_t *) buf_ptr;
*receiver_ip = htonl(feedbackPayload->receiver_addr);
*receiver_ip = feedbackPayload->receiver_addr;
buf_ptr += 4;
uint32_t *group_round_trip_time = (uint32_t *) buf_ptr;
......@@ -281,15 +288,15 @@ bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targ
targetPacket->payload = payload_buffer;
targetPacket->payload_len = payload_len;
if(PrrtPacket_type(targetPacket) == PACKET_TYPE_DATA) {
uint8_t packetType = PrrtPacket_type(targetPacket);
if(packetType == PACKET_TYPE_DATA) {
srcBuffer = decode_data_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_DATA_HEADER_SIZE);
} else if(PrrtPacket_type(targetPacket)) {
} else if(packetType == PACKET_TYPE_REDUNDANCY) {
srcBuffer = decode_redundancy_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if(PrrtPacket_type(targetPacket) == PACKET_TYPE_FEEDBACK) {
srcBuffer = decode_feedback_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_FEEDBACK_HEADER_SIZE);
} else if(packetType == PACKET_TYPE_FEEDBACK) {
decode_feedback_header(srcBuffer, payload_buffer);
} else {
printf("NOT IMPLEMENTED\n");
}
......@@ -323,7 +330,7 @@ void *decode_feedback_header(void *dstBuffer, const void *srcBuffer)
PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) srcBuffer;
uint32_t *receiverAddr = (uint32_t *) dstBuffer;
feedback_payload->receiver_addr = ntohl(*receiverAddr);
feedback_payload->receiver_addr = *receiverAddr;
dstBuffer += 4;
uint32_t *groupRoundTripTime = (uint32_t *) dstBuffer;
......@@ -463,6 +470,7 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
check_mem(payload);
packet->payload = payload;
payload->receiver_addr = inet_addr("10.0.0.1");
payload->group_round_trip_time = roundTripTime;
payload->forward_trip_time = forwardTripTime;
payload->packet_loss_rate = packetLossRate;
......
......@@ -8,15 +8,12 @@
#include "feedback_receiver.h"
void * receive_feedback_loop(void *ptr) {
char bufin[MAX_PAYLOAD_LENGTH];
PrrtSocket *sock_ptr = ptr;
check(pthread_mutex_lock(&sock_ptr->closingMutex) == 0, "Lock failed.");
while (sock_ptr->closing == false) {
check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
memset(bufin, 0, MAX_PAYLOAD_LENGTH);
PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, MAX_PAYLOAD_LENGTH);
if (t != NULL) {
PrrtPacket_destroy(t);
}
......
......@@ -252,7 +252,9 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
return -1;
}
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length) {
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, const size_t length)
{
char bufin[MAX_PAYLOAD_LENGTH];
ssize_t n;
struct sockaddr_in remote;
socklen_t addrlen = sizeof(remote);
......
......@@ -49,6 +49,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(const PrrtSocket *sock_ptr, void *bufin, const size_t length);
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, const size_t length);
#endif // PRRT_SOCKET_H
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