socket.h 4.27 KB
Newer Older
1
2
3
#ifndef PRRT_SOCKET_H
#define PRRT_SOCKET_H

4
5
#include "../defines.h"
#include "../util/list.h"
Stefan Reif's avatar
Stefan Reif committed
6
#include "../util/pipe.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
7
#include "../util/mpsc_queue.h"
8
#include "../util/bptree.h"
9
#include "channelStateInformation.h"
10
#include "applicationConstraints.h"
11
#include "stores/dataPacketStore.h"
12
#include "stores/deliveredPacketTable.h"
13
#include "stores/packetTimeoutTable.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
14
#include "stores/receptionTable.h"
15
#include "stores/repairBlockStore.h"
16
#include "stores/packetDeliveryStore.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
17
#include "types/lossStatistics.h"
18
#include "types/packet.h"
19
#include "clock.h"
20
#include "../xlap/xlap.h"
21
#include "receiver.h"
22

23
24
25
26
27
#ifndef SIOCSHWTSTAMP
# define SIOCSHWTSTAMP  0x89b0
# define SIOCGHWTSTAMP  0x89b1
#endif

28

29
typedef struct prrtSocket {
Andreas Schmidt's avatar
Andreas Schmidt committed
30
    int socketFd;
31

Andreas Schmidt's avatar
Andreas Schmidt committed
32
    struct sockaddr_in *address;
Andreas Schmidt's avatar
Andreas Schmidt committed
33
34
    bool isBound;

Stefan Reif's avatar
Stefan Reif committed
35
    PrrtClock clock;
36

Andreas Schmidt's avatar
Andreas Schmidt committed
37
    pthread_t sendDataThread;
38
    Pipe *sendDataQueue;
39
40

    pthread_t receiveDataThread;
41
    PrrtPacketDeliveryStore* packetDeliveryStore;
42

Andreas Schmidt's avatar
Andreas Schmidt committed
43
44
45
    PrrtPacketTimeoutTable *packetTimeoutTable;
    PrrtDataPacketStore *dataPacketStore;
    PrrtRepairBlockStore *repairBlockStore;
46

47
    PrrtDeliveredPacketTable *deliveredPacketTable;
48

49
    PrrtReceiver* receiver;
50

51
    atomic_bool closing;
52

53
54
55
56
57
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
58

59
60
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
61

Andreas Schmidt's avatar
Andreas Schmidt committed
62
63
64
65
66
    PrrtLossStatistics lossStatistics;

    PrrtReceptionTable* dataReceptionTable;
    PrrtReceptionTable* redundancyReceptionTable;

67
    PrrtApplicationConstraints *applicationConstraints;
68

69
70
    PrrtCodingConfiguration *codingParameters;
    PrrtCoder *coder;
71

Andreas Schmidt's avatar
Andreas Schmidt committed
72
    _Atomic (XlapTimestampTable *) tstable[2];
73

Andreas Schmidt's avatar
Andreas Schmidt committed
74
75
    pthread_attr_t *sendDataThreadAttr;
    pthread_attr_t *receiveDataThreadAttr;
76

77
    atomic_bool isHardwareTimestamping;
78
    char *interfaceName;
79
80

    atomic_bool isThreadPinning;
81
} PrrtSocket;
82

83

Andreas Schmidt's avatar
Andreas Schmidt committed
84
PrrtSocket *PrrtSocket_create(prrtTimedelta_t target_delay_us);
85
86

bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interface_name);
Andreas Schmidt's avatar
Andreas Schmidt committed
87

88
89
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

90
bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
91

92
bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t value);
Andreas Schmidt's avatar
Andreas Schmidt committed
93

94
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name);
Andreas Schmidt's avatar
Andreas Schmidt committed
95

rna's avatar
rna committed
96
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle);
Andreas Schmidt's avatar
Andreas Schmidt committed
97

98
99
100
PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s);

PrrtCoder *PrrtSocket_get_matching_coder(PrrtSocket *s, PrrtCodingConfiguration *codingParams);
101

102
int PrrtSocket_interrupt(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
103

104
int PrrtSocket_close(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
105

106
int PrrtSocket_connect(PrrtSocket *s, const char *host, uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
107

108
int PrrtSocket_send(PrrtSocket *s, const uint8_t *data, size_t data_len);
Andreas Schmidt's avatar
Andreas Schmidt committed
109

110
int32_t PrrtSocket_recv(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr);
Andreas Schmidt's avatar
Andreas Schmidt committed
111

112
113
114
int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr);
int32_t PrrtSocket_receive_asap_wait(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr);
int32_t PrrtSocket_receive_asap_timedwait(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr, struct timespec* deadline);
115

116
117
118
int32_t PrrtSocket_receive_ordered(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr, prrtTimedelta_t time_window_us);
int32_t PrrtSocket_receive_ordered_wait(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr, prrtTimedelta_t time_window_us);
int32_t PrrtSocket_receive_ordered_timedwait(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr, prrtTimedelta_t time_window_us, struct timespec* deadline);
119

Andreas Schmidt's avatar
Andreas Schmidt committed
120

121
bool PrrtSocket_cleanup(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
122

123
bool PrrtSocket_closing(PrrtSocket *s);
124

125
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
126

Andreas Schmidt's avatar
Andreas Schmidt committed
127
uint32_t PrrtSocket_get_rtprop_fwd(PrrtSocket *s);
128

Andreas Schmidt's avatar
Andreas Schmidt committed
129
130
131
132
prrtPacketLossRate_t PrrtSocket_get_plr_fwd(PrrtSocket *s);
prrtDeliveryRate_t PrrtSocket_get_delivery_rate_fwd(PrrtSocket *s);
prrtDeliveryRate_t PrrtSocket_get_btlbw_fwd(PrrtSocket *s);
prrtDeliveryRate_t PrrtSocket_get_btlbw_back(PrrtSocket *s);
133
bool PrrtSocket_get_app_limited(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
134

135
136
137
char *PrrtSocket_inet_ntoa(struct in_addr* in);
uint16_t PrrtSocket_ntohs(uint16_t v);

138
#endif // PRRT_SOCKET_H