forked from tkn-tub/ns3-gym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcp_base.py
138 lines (122 loc) · 3.68 KB
/
tcp_base.py
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
__author__ = "Piotr Gawlowicz"
__copyright__ = "Copyright (c) 2018, Technische Universität Berlin"
__version__ = "0.1.0"
__email__ = "[email protected]"
class Tcp(object):
"""docstring for Tcp"""
def __init__(self):
super(Tcp, self).__init__()
def set_spaces(self, obs, act):
self.obsSpace = obs
self.actSpace = act
def get_action(self, obs, reward, done, info):
pass
class TcpEventBased(Tcp):
"""docstring for TcpEventBased"""
def __init__(self):
super(TcpEventBased, self).__init__()
def get_action(self, obs, reward, done, info):
# unique socket ID
socketUuid = obs[0]
# TCP env type: event-based = 0 / time-based = 1
envType = obs[1]
# sim time in us
simTime_us = obs[2]
# unique node ID
nodeId = obs[3]
# current ssThreshold
ssThresh = obs[4]
# current contention window size
cWnd = obs[5]
# segment size
segmentSize = obs[6]
# number of acked segments
segmentsAcked = obs[7]
# estimated bytes in flight
bytesInFlight = obs[8]
# last estimation of RTT
lastRtt_us = obs[9]
# min value of RTT
minRtt_us = obs[10]
# function from Congestion Algorithm (CA) interface:
# GET_SS_THRESH = 0 (packet loss),
# INCREASE_WINDOW (packet acked),
# PKTS_ACKED (unused),
# CONGESTION_STATE_SET (unused),
# CWND_EVENT (unused),
calledFunc = obs[11]
# Congetsion Algorithm (CA) state:
# CA_OPEN = 0,
# CA_DISORDER,
# CA_CWR,
# CA_RECOVERY,
# CA_LOSS,
# CA_LAST_STATE
caState = obs[12]
# Congetsion Algorithm (CA) event:
# CA_EVENT_TX_START = 0,
# CA_EVENT_CWND_RESTART,
# CA_EVENT_COMPLETE_CWR,
# CA_EVENT_LOSS,
# CA_EVENT_ECN_NO_CE,
# CA_EVENT_ECN_IS_CE,
# CA_EVENT_DELAYED_ACK,
# CA_EVENT_NON_DELAYED_ACK,
caEvent = obs[13]
# ECN state:
# ECN_DISABLED = 0,
# ECN_IDLE,
# ECN_CE_RCVD,
# ECN_SENDING_ECE,
# ECN_ECE_RCVD,
# ECN_CWR_SENT
ecnState = obs[14]
# compute new values
new_cWnd = 10 * segmentSize
new_ssThresh = 5 * segmentSize
# return actions
actions = [new_ssThresh, new_cWnd]
return actions
class TcpTimeBased(Tcp):
"""docstring for TcpTimeBased"""
def __init__(self):
super(TcpTimeBased, self).__init__()
def get_action(self, obs, reward, done, info):
# unique socket ID
socketUuid = obs[0]
# TCP env type: event-based = 0 / time-based = 1
envType = obs[1]
# sim time in us
simTime_us = obs[2]
# unique node ID
nodeId = obs[3]
# current ssThreshold
ssThresh = obs[4]
# current contention window size
cWnd = obs[5]
# segment size
segmentSize = obs[6]
# bytesInFlightSum
bytesInFlightSum = obs[7]
# bytesInFlightAvg
bytesInFlightAvg = obs[8]
# segmentsAckedSum
segmentsAckedSum = obs[9]
# segmentsAckedAvg
segmentsAckedAvg = obs[10]
# avgRtt
avgRtt = obs[11]
# minRtt
minRtt = obs[12]
# avgInterTx
avgInterTx = obs[13]
# avgInterRx
avgInterRx = obs[14]
# throughput
throughput = obs[15]
# compute new values
new_cWnd = 10 * segmentSize
new_ssThresh = 5 * segmentSize
# return actions
actions = [new_ssThresh, new_cWnd]
return actions