Click
Loading...
Searching...
No Matches
bytestreammaintainer.hh
1/*
2 * bytestreammaintainer.hh - Class used to manage a flow. Stores the modifications in the flow
3 * (bytes removed or inserted) as well as information such as the MSS, ports, ips, last
4 * ack received, last ack sent, ...
5 *
6 * This file also contains the declaration and definition of RBTManager
7 * which is the RBTManager used by ByteStreamMaintainer to store the modifications in the flow.
8 *
9 * Romain Gaillard.
10 */
11
12
13#ifndef MIDDLEBOX_BYTESTREAMMAINTAINER_HH
14#define MIDDLEBOX_BYTESTREAMMAINTAINER_HH
15
16#include <click/config.h>
17#include <click/glue.hh>
18#include <clicknet/tcp.h>
19#include "rbt.hh"
20
21CLICK_DECLS
22
31{
32 // ModificationList is the only one allowed to add nodes in the trees
33 friend class ModificationList;
34
35 public:
43
44 inline void reinit() {
46 new (this) ByteStreamMaintainer();
47 }
48
53 uint32_t mapAck(uint32_t position);
54
59 uint32_t mapSeq(uint32_t position);
60
65
68 void printTrees();
69
74 void initialize(RBTManager *rbtManager, uint32_t flowStart);
75
79 void prune(uint32_t position);
80
84 inline void setLastAckSent(uint32_t ackNumber);
85
89 inline uint32_t getLastAckSent();
90
94 inline bool isLastAckSentSet();
95
99 inline void setLastSeqSent(uint32_t seqNumber);
100
103 inline void setLastPayloadLength(uint16_t payload);
104
108 inline uint32_t getLastSeqSent();
109
110 inline uint16_t getLastPayloadLength();
111
115 inline bool isLastSeqSentSet();
116
120 inline uint8_t getDupAcks();
121
125 inline void setDupAcks(uint8_t dupAcks);
126
131 inline void setWindowSize(uint16_t windowSize);
132
137 inline uint16_t getWindowSize();
138
142 inline void setWindowScale(uint16_t windowScale);
143
147 inline uint16_t getWindowScale();
148
153 inline void setUseWindowScale(bool useWindowScale);
154
158 inline bool getUseWindowScale();
159
163 inline uint16_t getMSS();
164
168 inline void setMSS(uint16_t mss);
169
173 inline uint64_t getCongestionWindowSize();
174
178 inline void setCongestionWindowSize(uint64_t congestionWindow);
179
183 inline void setSsthresh(uint64_t ssthresh);
184
188 inline uint64_t getSsthresh();
189
193 inline void setIpSrc(uint32_t ipSrc);
194
198 inline uint32_t getIpSrc();
199
203 inline void setIpDst(uint32_t ipDst);
204
208 inline uint32_t getIpDst();
209
213 inline void setPortSrc(uint16_t portSrc);
214
218 inline uint16_t getPortSrc();
219
223 inline void setPortDst(uint16_t portDst);
224
228 inline uint16_t getPortDst();
229
230 private:
235 void insertInAckTree(uint32_t position, int offset);
236
241 void insertInSeqTree(uint32_t position, int offset);
242
248 void insertInTree(rb_red_blk_tree* tree, uint32_t position, int offset);
249
250 rb_red_blk_tree* treeAck; // Tree used to map the ack numbers
251 rb_red_blk_tree* treeSeq; // Tree used to map the sequence numbers
252 RBTManager* rbtManager; // Manager of the trees (used to allocate memory among others)
253 uint32_t pruneCounter; // Used to avoid pruning for each ack received
254 bool initialized;
255 bool lastAckSentSet; // Indicates whether the value lastAckSent is meaningful
256 bool lastSeqSentSet; // Indicates whether the value lastSeqSent is meaningful
257 bool lastAckReceivedSet; // Indicates whether the value lastAckReceived is meaningful
258
259 uint32_t lastAckSent; // /!\ mapped value (as sent)
260 uint32_t lastSeqSent; // /!\ mapped value (as sent)
261 uint32_t lastAckReceived; // /!\ Unamapped value (as received)
262 uint16_t windowSize; // Window size of the source
263 uint16_t windowScale; // Window scale factor of the source
264 uint8_t dupAcks; // Number of consecutive duplicate acks currently observed
265 bool useWindowScale; // Indicates if the Window Scale option is used
266 uint64_t congestionWindow; // Congestion window for this side of the connection
267 uint64_t ssthresh; // Slow start threshold
268 uint16_t mss; // MSS of the source
269 uint16_t lastPayloadLength;
270 uint32_t ipSrc;
271 uint32_t ipDst;
272 uint16_t portSrc;
273 uint16_t portDst;
274};
275
277{
278 // As the sequence and ack numbers may wrap, we cannot just set a default value (for instance
279 // 0) for them and check that the given one is greater as we could have false negatives
280 if(!lastAckSentSet || SEQ_GT(ackNumber, lastAckSent))
281 lastAckSent = ackNumber;
282
283 lastAckSentSet = true;
284}
285
287{
288 if(!lastAckSentSet)
289 click_chatter("Error: Last ack sent not defined");
290
291 return lastAckSent;
292}
293
295{
296 // As the sequence and ack numbers may wrap, we cannot just set a default value (for instance
297 // 0) for them and check that the given one is greater as we could have false negatives
298 if(!lastSeqSentSet || SEQ_GT(seqNumber, lastSeqSent))
299 lastSeqSent = seqNumber;
300
301 lastSeqSentSet = true;
302}
303
305{
306 lastPayloadLength = payload;
307}
308
310{
311 if(!lastSeqSentSet)
312 click_chatter("Error: Last sequence sent not defined");
313
314 return lastSeqSent;
315}
316
317uint16_t ByteStreamMaintainer::getLastPayloadLength()
318{
319 return lastPayloadLength;
320}
321
323{
324 return lastAckSentSet;
325}
326
328{
329 return lastSeqSentSet;
330}
331
332void ByteStreamMaintainer::setWindowSize(uint16_t windowSize)
333{
334 this->windowSize = windowSize;
335}
336
338{
339 return windowSize;
340}
341
343{
344 this->ipSrc = ipSrc;
345}
346
348{
349 return ipSrc;
350}
351
353{
354 this->ipDst = ipDst;
355}
356
358{
359 return ipDst;
360}
361
363{
364 this->portSrc = portSrc;
365}
366
368{
369 return portSrc;
370}
371
373{
374 this->portDst = portDst;
375}
376
378{
379 return portDst;
380}
381
382void ByteStreamMaintainer::setWindowScale(uint16_t windowScale)
383{
384 this->windowScale = windowScale;
385}
386
388{
389 return windowScale;
390}
391
393{
394 this->useWindowScale = useWindowScale;
395}
396
398{
399 return useWindowScale;
400}
401
403{
404 return mss;
405}
406
408{
409 this->mss = mss;
410}
411
413{
414 return dupAcks;
415}
416
418{
419 this->dupAcks = dupAcks;
420}
421
423{
424 return congestionWindow;
425}
426
428{
429 this->congestionWindow = congestionWindow;
430}
431
433{
434 return ssthresh;
435}
436
438{
439 this->ssthresh = ssthresh;
440}
441
442
443CLICK_ENDDECLS
444#endif
Class used to manage a flow. Stores the modifications in the flow (bytes removed or inserted) as well...
Definition bytestreammaintainer.hh:31
uint32_t getIpDst()
Return the IP address of the destination.
Definition bytestreammaintainer.hh:357
bool getUseWindowScale()
Return a boolean indicating whether the connection uses the window scale option.
Definition bytestreammaintainer.hh:397
void setIpDst(uint32_t ipDst)
Set the IP address of the destination.
Definition bytestreammaintainer.hh:352
uint32_t mapSeq(uint32_t position)
Map a sequence number.
Definition bytestreammaintainer.cc:109
void setWindowScale(uint16_t windowScale)
Set the window scale factor of the source.
Definition bytestreammaintainer.hh:382
uint16_t getWindowSize()
Return the window size of the source (will be used as the receiver's windows size by the other side o...
Definition bytestreammaintainer.hh:337
void setCongestionWindowSize(uint64_t congestionWindow)
Set the size of the congestion window for this side of the connection.
Definition bytestreammaintainer.hh:427
uint32_t getLastSeqSent()
Return the value of the "last seq sent" by this side of the connection.
Definition bytestreammaintainer.hh:309
void setLastSeqSent(uint32_t seqNumber)
Set the value of the "last seq sent" by this side of the connection.
Definition bytestreammaintainer.hh:294
uint16_t getPortSrc()
Return the port number of the source.
Definition bytestreammaintainer.hh:367
bool isLastAckSentSet()
Indicate whether the "last ack sent" value has been set.
Definition bytestreammaintainer.hh:322
uint32_t mapAck(uint32_t position)
Map an ack number.
Definition bytestreammaintainer.cc:61
uint16_t getPortDst()
Return the port number of the destination.
Definition bytestreammaintainer.hh:377
void initialize(RBTManager *rbtManager, uint32_t flowStart)
Initialize the ByteStreamMaintainer (required before beging use)
Definition bytestreammaintainer.cc:41
uint32_t getLastAckSent()
Return the value of the last ack sent by this side of the connection.
Definition bytestreammaintainer.hh:286
bool isLastSeqSentSet()
Indicate whether the "last seq sent" value has been set.
Definition bytestreammaintainer.hh:327
void prune(uint32_t position)
Prune the trees.
Definition bytestreammaintainer.cc:180
uint64_t getSsthresh()
Return the ssthreshold (slow start threshold) for this side of the connection.
Definition bytestreammaintainer.hh:432
void setLastPayloadLength(uint16_t payload)
Set the size of the last packet payload, allows to compute next seq.
Definition bytestreammaintainer.hh:304
uint32_t getIpSrc()
Return the IP address of the source.
Definition bytestreammaintainer.hh:347
void setUseWindowScale(bool useWindowScale)
Indicate whether the connection uses the window scale option.
Definition bytestreammaintainer.hh:392
uint64_t getCongestionWindowSize()
Return the size of the congestion window for this side of the connection.
Definition bytestreammaintainer.hh:422
~ByteStreamMaintainer()
Destruct a ByteStreamMaintainer.
Definition bytestreammaintainer.cc:255
int lastOffsetInAckTree()
Return the offset corresponding to the last modification in the ack tree.
Definition bytestreammaintainer.cc:244
void setWindowSize(uint16_t windowSize)
Set the window size of the source (will be used as the receiver's windows size by the other side of t...
Definition bytestreammaintainer.hh:332
void setIpSrc(uint32_t ipSrc)
Set the IP address of the source.
Definition bytestreammaintainer.hh:342
void setPortSrc(uint16_t portSrc)
Set the port number of the source.
Definition bytestreammaintainer.hh:362
ByteStreamMaintainer()
Construct a ByteStreamMaintainer ByteStreamMaintainer must be initialized before being used.
Definition bytestreammaintainer.cc:18
void setDupAcks(uint8_t dupAcks)
Set the number of consecutive duplicate ACKs currently observed.
Definition bytestreammaintainer.hh:417
void printTrees()
Print the ACK and SEQ trees in the console.
Definition bytestreammaintainer.cc:171
uint8_t getDupAcks()
Return the number of consecutive duplicate ACKs currently observed.
Definition bytestreammaintainer.hh:412
void setLastAckSent(uint32_t ackNumber)
Sets the value of the last ack sent by this side of the connection.
Definition bytestreammaintainer.hh:276
void setPortDst(uint16_t portDst)
Set the port number of the destination.
Definition bytestreammaintainer.hh:372
uint16_t getMSS()
Return the MSS of the source.
Definition bytestreammaintainer.hh:402
void setMSS(uint16_t mss)
Set the MSS of the source.
Definition bytestreammaintainer.hh:407
void setSsthresh(uint64_t ssthresh)
Set the ssthreshold (slow start threshold) for this side of the connection.
Definition bytestreammaintainer.hh:437
uint16_t getWindowScale()
Return the window scale factor of the source.
Definition bytestreammaintainer.hh:387
Class used to store the modifications performed in a packet's structure.
Definition modificationlist.hh:41
RBTManager that uses memory pools to allocate memory and compares the keys as sequence numbers.
Definition rbt.hh:173
Definition rbt.hh:42