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

Andreas Schmidt's avatar
Andreas Schmidt committed
4

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

27 28 29 30 31
#ifndef SIOCSHWTSTAMP
# define SIOCSHWTSTAMP  0x89b0
# define SIOCGHWTSTAMP  0x89b1
#endif

32

33
typedef struct prrtSocket {
Andreas Schmidt's avatar
Andreas Schmidt committed
34
    int socketFd;
35

Andreas Schmidt's avatar
Andreas Schmidt committed
36
    struct sockaddr_in *address;
37
    bool isBound;
38 39 40
    bool withTimestamp;

    bool pacingEnabled;
41

42
    PrrtClock clock;
43
    PrrtBlock* receiveBlock;
44

Andreas Schmidt's avatar
Andreas Schmidt committed
45
    pthread_t sendDataThread;
46
    Pipe *sendDataQueue;
47 48

    pthread_t receiveDataThread;
49
    PrrtPacketDeliveryStore* packetDeliveryStore;
50

Andreas Schmidt's avatar
Andreas Schmidt committed
51 52 53
    PrrtPacketTimeoutTable *packetTimeoutTable;
    PrrtDataPacketStore *dataPacketStore;
    PrrtRepairBlockStore *repairBlockStore;
54

55
    PrrtDeliveredPacketTable *deliveredPacketTable;
56

57
    PrrtReceiver* receiver;
58

59
    atomic_bool closing;
60

61 62
    prrtTimestamp_t nextSendTime;

63 64 65 66 67
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
68

69 70
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
71

72 73 74 75 76
    PrrtLossStatistics lossStatistics;

    PrrtReceptionTable* dataReceptionTable;
    PrrtReceptionTable* redundancyReceptionTable;

77
    PrrtApplicationConstraints *applicationConstraints;
78

79 80
    PrrtCodingConfiguration *codingParameters;
    PrrtCoder *coder;
81

Andreas Schmidt's avatar
Andreas Schmidt committed
82 83 84 85 86 87 88 89 90
    // Pacing
    PrrtPace* appSendPace;
    PrrtPace* prrtTransmitPace;
    PrrtPace* prrtReceivePace;
    PrrtPace* appDeliverPace;

    prrtTimedelta_t send_peer_btl_pace;
    prrtTimedelta_t recv_peer_btl_pace;

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

Andreas Schmidt's avatar
Andreas Schmidt committed
93 94
    pthread_attr_t *sendDataThreadAttr;
    pthread_attr_t *receiveDataThreadAttr;
95

96
    atomic_bool isHardwareTimestamping;
97
    char *interfaceName;
98

99 100
    PrrtChannelStateInformation* senderChannelStateInformation;

101
    atomic_bool isThreadPinning;
102
    prrtByteCount_t maximum_payload_size;
103
    PrrtTimer *retransmissionTimer;
104
} PrrtSocket;
105

106

107
PrrtSocket *PrrtSocket_create(prrtByteCount_t maximum_payload_size, prrtTimedelta_t target_delay_us);
108 109

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

111 112
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

113
int PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
114

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

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

rna's avatar
rna committed
119
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
120

121 122 123
PrrtCodingConfiguration *PrrtSocket_get_coding_parameters(PrrtSocket *s);

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

125
int PrrtSocket_interrupt(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
126

127
int PrrtSocket_close(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
128

129
bool PrrtSocket_connect(PrrtSocket *s, const char *host, const uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
130

131 132
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);
Andreas Schmidt's avatar
Andreas Schmidt committed
133 134
int PrrtSocket_try_send_async(PrrtSocket *s, const uint8_t *data, const size_t data_len);

Andreas Schmidt's avatar
Andreas Schmidt committed
135
bool PrrtSocket_pace(PrrtSocket *sock_ptr, bool prepace);
Andreas Schmidt's avatar
Andreas Schmidt committed
136

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

139 140 141
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);
142

143 144 145
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);
146

147
bool PrrtSocket_cleanup(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
148

149
bool PrrtSocket_closing(PrrtSocket *s);
150

151
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
152

Andreas Schmidt's avatar
Andreas Schmidt committed
153 154 155
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);
Andreas Schmidt's avatar
Andreas Schmidt committed
156 157 158
prrtDeliveryRate_t PrrtSocket_get_btldatarate_fwd(PrrtSocket *s);
prrtDeliveryRate_t PrrtSocket_get_btldatarate_back(PrrtSocket *s);
uint64_t PrrtSocket_get_full_datarate(PrrtSocket *s);
159 160 161 162 163 164 165 166 167 168 169 170 171
bool PrrtSocket_get_filled_pipe(PrrtSocket *s);
uint32_t PrrtSocket_get_bbr_state(PrrtSocket *s);
uint32_t PrrtSocket_get_bbr_app_limited(PrrtSocket *s);
bool PrrtSocket_get_bbr_is_app_limited(PrrtSocket *s);
uint32_t PrrtSocket_get_cycle_index(PrrtSocket *s);
float PrrtSocket_get_pacing_gain(PrrtSocket *s);
uint32_t PrrtSocket_get_cwnd(PrrtSocket *s);
uint32_t PrrtSocket_get_inflight(PrrtSocket *s);
uint32_t PrrtSocket_get_pacing_rate(PrrtSocket *s);
prrtByteCount_t PrrtSocket_get_send_quantum(PrrtSocket *s);
prrtByteCount_t PrrtSocket_get_pipe(PrrtSocket *s);
prrtByteCount_t PrrtSocket_get_delivered(PrrtSocket *s);
bool PrrtSocket_get_bbr_round_start(PrrtSocket *s);
172

173
#endif // PRRT_SOCKET_H