-
Notifications
You must be signed in to change notification settings - Fork 86
/
tcp-rl-env.h
150 lines (125 loc) · 4.45 KB
/
tcp-rl-env.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2018 Technische Universität Berlin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Piotr Gawlowicz <[email protected]>
* Modify: Pengyu Liu <[email protected]>
* Hao Yin <[email protected]>
* Muyuan Shen <[email protected]>
*/
#ifndef TCP_RL_ENV_H_MSG
#define TCP_RL_ENV_H_MSG
#include "agent.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/tcp-header.h"
#include "ns3/tcp-socket-base.h"
namespace ns3
{
struct TcpRlEnv
{
uint32_t nodeId;
uint32_t socketUid;
uint8_t envType;
int64_t simTime_us;
uint32_t ssThresh;
uint32_t cWnd;
uint32_t segmentSize;
uint32_t segmentsAcked;
uint32_t bytesInFlight;
};
struct TcpRlAct
{
uint32_t new_ssThresh;
uint32_t new_cWnd;
};
class TcpTimeStepEnv : public Object
{
public:
TcpTimeStepEnv();
~TcpTimeStepEnv() override;
static TypeId GetTypeId();
void SetNodeId(uint32_t id);
void SetSocketUuid(uint32_t id);
void TxPktTrace(Ptr<const Packet>, const TcpHeader&, Ptr<const TcpSocketBase>);
void RxPktTrace(Ptr<const Packet>, const TcpHeader&, Ptr<const TcpSocketBase>);
// TCP congestion control interface
uint32_t GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight);
void IncreaseWindow(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
// optional functions used to collect obs
void PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt);
void CongestionStateSet(Ptr<TcpSocketState> tcb, const TcpSocketState::TcpCongState_t newState);
void CwndEvent(Ptr<TcpSocketState> tcb, const TcpSocketState::TcpCAEvent_t event);
private:
uint32_t m_nodeId;
uint32_t m_socketUuid;
Time m_lastPktTxTime{MicroSeconds(0.0)};
Time m_lastPktRxTime{MicroSeconds(0.0)};
uint64_t m_interTxTimeNum{0};
Time m_interTxTimeSum{MicroSeconds(0.0)};
uint64_t m_interRxTimeNum{0};
Time m_interRxTimeSum{MicroSeconds(0.0)};
uint32_t m_new_ssThresh;
uint32_t m_new_cWnd;
void ScheduleNotify();
bool m_started{false};
Time m_timeStep;
// state
Ptr<const TcpSocketState> m_tcb;
std::vector<uint32_t> m_bytesInFlight;
std::vector<uint32_t> m_segmentsAcked;
uint64_t m_rttSampleNum{0};
Time m_rttSum{MicroSeconds(0.0)};
TcpDeepQAgent m_agent;
};
class TcpEventBasedEnv : public Object
{
public:
TcpEventBasedEnv();
~TcpEventBasedEnv() override;
static TypeId GetTypeId();
void SetNodeId(uint32_t id);
void SetSocketUuid(uint32_t id);
void TxPktTrace(Ptr<const Packet>, const TcpHeader&, Ptr<const TcpSocketBase>);
void RxPktTrace(Ptr<const Packet>, const TcpHeader&, Ptr<const TcpSocketBase>);
// TCP congestion control interface
uint32_t GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight);
void IncreaseWindow(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
// optional functions used to collect obs
void PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt);
void CongestionStateSet(Ptr<TcpSocketState> tcb, const TcpSocketState::TcpCongState_t newState);
void CwndEvent(Ptr<TcpSocketState> tcb, const TcpSocketState::TcpCAEvent_t event);
private:
uint32_t m_nodeId;
uint32_t m_socketUuid;
Time m_lastPktTxTime{MicroSeconds(0.0)};
Time m_lastPktRxTime{MicroSeconds(0.0)};
uint64_t m_interTxTimeNum{0};
Time m_interTxTimeSum{MicroSeconds(0.0)};
uint64_t m_interRxTimeNum{0};
Time m_interRxTimeSum{MicroSeconds(0.0)};
uint32_t m_new_ssThresh;
uint32_t m_new_cWnd;
void Notify();
// state
Ptr<const TcpSocketState> m_tcb;
std::vector<uint32_t> m_bytesInFlight;
std::vector<uint32_t> m_segmentsAcked;
uint64_t m_rttSampleNum{0};
Time m_rttSum{MicroSeconds(0.0)};
TcpDeepQAgent m_agent;
};
} // namespace ns3
#endif /* TCP_RL_ENV_H_MSG */