socket.h 5.21 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.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 {
30
    int socketFd;
31

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

Andreas Schmidt's avatar
Andreas Schmidt committed
36 37
    bool pacingEnabled;

Stefan Reif's avatar
Stefan Reif committed
38
    PrrtClock clock;
39
    PrrtBlock* receiveBlock;
40

Andreas Schmidt's avatar
Andreas Schmidt committed
41
    pthread_t sendDataThread;
42
    Pipe *sendDataQueue;
43 44

    pthread_t receiveDataThread;
45
    PrrtPacketDeliveryStore* packetDeliveryStore;
46

Andreas Schmidt's avatar
Andreas Schmidt committed
47 48 49
    PrrtPacketTimeoutTable *packetTimeoutTable;
    PrrtDataPacketStore *dataPacketStore;
    PrrtRepairBlockStore *repairBlockStore;
50

51
    PrrtDeliveredPacketTable *deliveredPacketTable;
52

53
    PrrtReceiver* receiver;
54

55
    atomic_bool closing;
56

Andreas Schmidt's avatar
Andreas Schmidt committed
57 58
    prrtTimestamp_t nextSendTime;

59 60 61 62 63
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
64

65 66
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
67

Andreas Schmidt's avatar
Andreas Schmidt committed
68 69 70 71 72
    PrrtLossStatistics lossStatistics;

    PrrtReceptionTable* dataReceptionTable;
    PrrtReceptionTable* redundancyReceptionTable;

73
    PrrtApplicationConstraints *applicationConstraints;
74

75 76
    PrrtCodingConfiguration *codingParameters;
    PrrtCoder *coder;
77

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

Andreas Schmidt's avatar
Andreas Schmidt committed
80 81
    pthread_attr_t *sendDataThreadAttr;
    pthread_attr_t *receiveDataThreadAttr;
82

83
    atomic_bool isHardwareTimestamping;
84
    char *interfaceName;
85

86 87
    PrrtChannelStateInformation* senderChannelStateInformation;

88
    atomic_bool isThreadPinning;
rna's avatar
rna committed
89
    prrtByteCount_t maximum_payload_size;
90
} PrrtSocket;
91

92

rna's avatar
rna committed
93
PrrtSocket *PrrtSocket_create(prrtByteCount_t maximum_payload_size, prrtTimedelta_t target_delay_us);
94 95

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

97 98
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

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

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

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

rna's avatar
rna committed
105
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
106

107 108 109
PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s);

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

111
int PrrtSocket_interrupt(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
112

113
int PrrtSocket_close(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
114

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

117 118 119 120
int PrrtSocket_send_async(PrrtSocket *s, const uint8_t *data, const size_t data_len);
int PrrtSocket_send_sync(PrrtSocket *s, const uint8_t *data, size_t data_len);
void PrrtSocket_pace(PrrtSocket *s);

Andreas Schmidt's avatar
Andreas Schmidt committed
121

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

124 125 126
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);
127

128 129 130
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);
131

132
bool PrrtSocket_cleanup(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
133

134
bool PrrtSocket_closing(PrrtSocket *s);
135

136
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
137

Andreas Schmidt's avatar
Andreas Schmidt committed
138 139 140 141 142
uint32_t PrrtSocket_get_rtprop_fwd(PrrtSocket *s);
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);
143 144 145
uint64_t PrrtSocket_get_full_bw(PrrtSocket *s);
bool PrrtSocket_get_filled_pipe(PrrtSocket *s);
uint32_t PrrtSocket_get_bbr_state(PrrtSocket *s);
146 147
uint32_t PrrtSocket_get_bbr_app_limited(PrrtSocket *s);
bool PrrtSocket_get_bbr_is_app_limited(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
148 149
uint32_t PrrtSocket_get_cycle_index(PrrtSocket *s);
float PrrtSocket_get_pacing_gain(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
150 151
uint32_t PrrtSocket_get_cwnd(PrrtSocket *s);
uint32_t PrrtSocket_get_inflight(PrrtSocket *s);
152
uint32_t PrrtSocket_get_pacing_rate(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
153
prrtByteCount_t PrrtSocket_get_send_quantum(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
154
prrtByteCount_t PrrtSocket_get_pipe(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
155
prrtByteCount_t PrrtSocket_get_delivered(PrrtSocket *s);
Andreas Schmidt's avatar
Fixes.  
Andreas Schmidt committed
156
bool PrrtSocket_get_bbr_round_start(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
157

158
#endif // PRRT_SOCKET_H