socket.h 5.57 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"
Stefan Reif's avatar
Stefan Reif committed
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"
13
#include "stores/pace.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
14
#include "stores/paceFilter.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
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"
Andreas Schmidt's avatar
Andreas Schmidt committed
20
#include "types/lossStatistics.h"
21
#include "types/packet.h"
22
#include "clock.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
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 {
34
    int socketFd;
35

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

Andreas Schmidt's avatar
Andreas Schmidt committed
40 41
    bool pacingEnabled;

Stefan Reif's avatar
Stefan Reif committed
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

Andreas Schmidt's avatar
Andreas Schmidt committed
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

Andreas Schmidt's avatar
Andreas Schmidt committed
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;
rna's avatar
rna committed
102
    prrtByteCount_t maximum_payload_size;
Andreas Schmidt's avatar
Andreas Schmidt committed
103 104

    PrrtTimer *retransmissionTimer;
105
} PrrtSocket;
106

107

rna's avatar
rna committed
108
PrrtSocket *PrrtSocket_create(prrtByteCount_t maximum_payload_size, prrtTimedelta_t target_delay_us);
109 110

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

112 113
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

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

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

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

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

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

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

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

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

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

Andreas Schmidt's avatar
Andreas Schmidt committed
132 133
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);
134
bool PrrtSocket_pace(PrrtSocket *sock_ptr, bool prepace);
Andreas Schmidt's avatar
Andreas Schmidt committed
135

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

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

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

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

148
bool PrrtSocket_closing(PrrtSocket *s);
149

150
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
151

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

172
#endif // PRRT_SOCKET_H