-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatapacket.h
83 lines (66 loc) · 2.26 KB
/
datapacket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Datapacket header
*/
#ifndef DATAPACKET_H
#define DATAPACKET_H
#include "network.h"
// DataPacket and DataAck are subclasses of Packet used by TcpSrc and other flow control protocols.
// They incorporate a packet database, to reuse packet objects that are no longer needed.
// Note: you never construct a new DataPacket or DataAck directly;
// rather you use the static method newpkt() which knows to reuse old packets from the database.
class DataPacket : public Packet
{
public:
typedef uint64_t seq_t;
virtual ~DataPacket() {}
inline static DataPacket* newpkt(PacketFlow &flow, route_t &route, seq_t seqno, int size)
{
DataPacket *p = _packetdb.allocPacket();
// The sequence number is the first byte of the packet.
// This will ID the packet by its last byte.
p->set(flow, route, size, seqno);
p->_seqno = seqno;
flow._nPackets++;
return p;
}
void free() {
flow()._nPackets--;
_packetdb.freePacket(this);
}
inline seq_t seqno() const {return _seqno;}
inline simtime_picosec ts() const {return _ts;}
inline void set_ts(simtime_picosec ts) {_ts = ts;}
protected:
seq_t _seqno;
simtime_picosec _ts;
static PacketDB<DataPacket> _packetdb;
};
class DataAck : public Packet
{
public:
typedef DataPacket::seq_t seq_t;
virtual ~DataAck(){}
inline static DataAck* newpkt(PacketFlow &flow, route_t &route, seq_t seqno, seq_t ackno)
{
DataAck *p = _packetdb.allocPacket();
p->set(flow, route, ACK_SIZE, ackno);
p->_seqno = seqno;
p->_ackno = ackno;
flow._nPackets++;
return p;
}
void free() {
flow()._nPackets--;
_packetdb.freePacket(this);
}
inline seq_t seqno() const {return _seqno;}
inline seq_t ackno() const {return _ackno;}
inline simtime_picosec ts() const {return _ts;}
inline void set_ts(simtime_picosec ts) {_ts = ts;}
protected:
seq_t _seqno;
seq_t _ackno;
simtime_picosec _ts;
static PacketDB<DataAck> _packetdb;
};
#endif /* DATAPACKET_H */