Skip to content

Commit 2ffe127

Browse files
committed
Added GetParam for Network Statistics
Signed-off-by: HHN <harihara.sn@gmail.com>
1 parent 0298f93 commit 2ffe127

File tree

10 files changed

+134
-16
lines changed

10 files changed

+134
-16
lines changed

docs/Settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ These parameters are accessed by calling [GetParam](./api/GetParam.md) or [SetPa
182182
| `QUIC_PARAM_CONN_STATISTICS_V2_PLAT`<br> 23 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics with platform-specific time format, version 2. |
183183
| `QUIC_PARAM_CONN_ORIG_DEST_CID` <br> 24 | uint8_t[] | Get-only | The original destination connection ID used by the client to connect to the server. |
184184
| `QUIC_PARAM_CONN_SEND_DSCP` <br> 25 | uint8_t | Both | The DiffServ Code Point put in the DiffServ field (formerly TypeOfService/TrafficClass) on packets sent from this connection. |
185+
| `QUIC_PARAM_CONN_NETWORK_STATISTICS` <br> 20 | NETWORK_STATISTICS | Get-only | Returns Connection level network statistics |
185186

186187
### QUIC_PARAM_CONN_STATISTICS_V2
187188

src/core/bbr.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,36 @@ QuicConnLogBbr(
299299
BbrCongestionControlIsAppLimited(Cc));
300300
}
301301

302+
_IRQL_requires_max_(DISPATCH_LEVEL)
303+
void
304+
BbrCongestionControlGetNetworkStatistics(
305+
_In_ const QUIC_CONNECTION* const Connection,
306+
_In_ const QUIC_CONGESTION_CONTROL* const Cc,
307+
_Out_ NETWORK_STATISTICS* NetworkStatistics
308+
)
309+
{
310+
const QUIC_CONGESTION_CONTROL_BBR* Bbr = &Cc->Bbr;
311+
const QUIC_PATH* Path = &Connection->Paths[0];
312+
313+
NetworkStatistics->BytesInFlight = Bbr->BytesInFlight;
314+
NetworkStatistics->PostedBytes = Connection->SendBuffer.PostedBytes;
315+
NetworkStatistics->IdealBytes = Connection->SendBuffer.IdealBytes;
316+
NetworkStatistics->SmoothedRTT = Path->SmoothedRtt;
317+
NetworkStatistics->CongestionWindow = BbrCongestionControlGetCongestionWindow(Cc);
318+
NetworkStatistics->Bandwidth = BbrCongestionControlGetBandwidth(Cc) / BW_UNIT;
319+
}
320+
302321
_IRQL_requires_max_(DISPATCH_LEVEL)
303322
void
304323
BbrCongestionControlIndicateConnectionEvent(
305324
_In_ QUIC_CONNECTION* const Connection,
306325
_In_ const QUIC_CONGESTION_CONTROL* Cc
307326
)
308327
{
309-
const QUIC_CONGESTION_CONTROL_BBR* Bbr = &Cc->Bbr;
310-
const QUIC_PATH* Path = &Connection->Paths[0];
311328
QUIC_CONNECTION_EVENT Event;
312329
Event.Type = QUIC_CONNECTION_EVENT_NETWORK_STATISTICS;
313-
Event.NETWORK_STATISTICS.BytesInFlight = Bbr->BytesInFlight;
314-
Event.NETWORK_STATISTICS.PostedBytes = Connection->SendBuffer.PostedBytes;
315-
Event.NETWORK_STATISTICS.IdealBytes = Connection->SendBuffer.IdealBytes;
316-
Event.NETWORK_STATISTICS.SmoothedRTT = Path->SmoothedRtt;
317-
Event.NETWORK_STATISTICS.CongestionWindow = BbrCongestionControlGetCongestionWindow(Cc);
318-
Event.NETWORK_STATISTICS.Bandwidth = BbrCongestionControlGetBandwidth(Cc) / BW_UNIT;
330+
331+
BbrCongestionControlGetNetworkStatistics(Connection, Cc, &Event.NETWORK_STATISTICS);
319332

320333
QuicTraceLogConnVerbose(
321334
IndicateDataAcked,
@@ -1068,6 +1081,7 @@ static const QUIC_CONGESTION_CONTROL QuicCongestionControlBbr = {
10681081
.QuicCongestionControlGetBytesInFlightMax = BbrCongestionControlGetBytesInFlightMax,
10691082
.QuicCongestionControlIsAppLimited = BbrCongestionControlIsAppLimited,
10701083
.QuicCongestionControlSetAppLimited = BbrCongestionControlSetAppLimited,
1084+
.QuicCongestionControlGetNetworkStatistics = BbrCongestionControlGetNetworkStatistics
10711085
};
10721086

10731087
_IRQL_requires_max_(DISPATCH_LEVEL)

src/core/congestion_control.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ typedef struct QUIC_CONGESTION_CONTROL {
155155
_In_ struct QUIC_CONGESTION_CONTROL* Cc
156156
);
157157

158+
void (*QuicCongestionControlGetNetworkStatistics)(
159+
_In_ const QUIC_CONNECTION* const Connection,
160+
_In_ const struct QUIC_CONGESTION_CONTROL* const Cc,
161+
_Out_ struct NETWORK_STATISTICS* NetworkStatistics
162+
);
163+
158164
//
159165
// Algorithm specific state.
160166
//

src/core/connection.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6902,6 +6902,40 @@ QuicConnGetV2Statistics(
69026902
return QUIC_STATUS_SUCCESS;
69036903
}
69046904

6905+
_IRQL_requires_max_(PASSIVE_LEVEL)
6906+
static
6907+
QUIC_STATUS
6908+
QuicConnGetNetworkStatistics(
6909+
_In_ const QUIC_CONNECTION* Connection,
6910+
_Inout_ uint32_t* StatsLength,
6911+
_Out_writes_bytes_opt_(*StatsLength)
6912+
NETWORK_STATISTICS* Stats
6913+
)
6914+
{
6915+
const uint32_t MinimumStatsSize = sizeof(NETWORK_STATISTICS);
6916+
6917+
if (*StatsLength == 0) {
6918+
*StatsLength = sizeof(NETWORK_STATISTICS);
6919+
return QUIC_STATUS_BUFFER_TOO_SMALL;
6920+
}
6921+
6922+
if (*StatsLength < MinimumStatsSize) {
6923+
*StatsLength = MinimumStatsSize;
6924+
return QUIC_STATUS_BUFFER_TOO_SMALL;
6925+
}
6926+
6927+
if (Stats == NULL) {
6928+
return QUIC_STATUS_INVALID_PARAMETER;
6929+
}
6930+
6931+
memset(Stats, 0, MinimumStatsSize);
6932+
6933+
Connection->CongestionControl.QuicCongestionControlGetNetworkStatistics(
6934+
Connection, &Connection->CongestionControl, Stats);
6935+
6936+
return QUIC_STATUS_SUCCESS;
6937+
}
6938+
69056939
_IRQL_requires_max_(PASSIVE_LEVEL)
69066940
QUIC_STATUS
69076941
QuicConnParamGet(
@@ -7320,6 +7354,11 @@ QuicConnParamGet(
73207354
Status = QUIC_STATUS_SUCCESS;
73217355
break;
73227356

7357+
case QUIC_PARAM_CONN_NETWORK_STATISTICS:
7358+
Status =
7359+
QuicConnGetNetworkStatistics(Connection, BufferLength, (NETWORK_STATISTICS *)Buffer);
7360+
break;
7361+
73237362
default:
73247363
Status = QUIC_STATUS_INVALID_PARAMETER;
73257364
break;

src/core/cubic.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,25 @@ CubicCongestionControlOnDataInvalidated(
414414
return CubicCongestionControlUpdateBlockedState(Cc, PreviousCanSendState);
415415
}
416416

417+
_IRQL_requires_max_(DISPATCH_LEVEL)
418+
void
419+
CubicCongestionControlGetNetworkStatistics(
420+
_In_ const QUIC_CONNECTION* const Connection,
421+
_In_ const QUIC_CONGESTION_CONTROL* const Cc,
422+
_Out_ NETWORK_STATISTICS* NetworkStatistics
423+
)
424+
{
425+
const QUIC_CONGESTION_CONTROL_CUBIC* Cubic = &Cc->Cubic;
426+
const QUIC_PATH* Path = &Connection->Paths[0];
427+
428+
NetworkStatistics->BytesInFlight = Cubic->BytesInFlight;
429+
NetworkStatistics->PostedBytes = Connection->SendBuffer.PostedBytes;
430+
NetworkStatistics->IdealBytes = Connection->SendBuffer.IdealBytes;
431+
NetworkStatistics->SmoothedRTT = Path->SmoothedRtt;
432+
NetworkStatistics->CongestionWindow = Cubic->CongestionWindow;
433+
NetworkStatistics->Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt;
434+
}
435+
417436
_IRQL_requires_max_(DISPATCH_LEVEL)
418437
BOOLEAN
419438
CubicCongestionControlOnDataAcknowledged(
@@ -888,6 +907,7 @@ static const QUIC_CONGESTION_CONTROL QuicCongestionControlCubic = {
888907
.QuicCongestionControlIsAppLimited = CubicCongestionControlIsAppLimited,
889908
.QuicCongestionControlSetAppLimited = CubicCongestionControlSetAppLimited,
890909
.QuicCongestionControlGetCongestionWindow = CubicCongestionControlGetCongestionWindow,
910+
.QuicCongestionControlGetNetworkStatistics = CubicCongestionControlGetNetworkStatistics
891911
};
892912

893913
_IRQL_requires_max_(DISPATCH_LEVEL)

src/cs/lib/msquic_generated.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,6 +3714,9 @@ internal static unsafe partial class MsQuic
37143714
[NativeTypeName("#define QUIC_PARAM_CONN_SEND_DSCP 0x05000019")]
37153715
internal const uint QUIC_PARAM_CONN_SEND_DSCP = 0x05000019;
37163716

3717+
[NativeTypeName("#define QUIC_PARAM_CONN_NETWORK_STATISTICS 0x05000019")]
3718+
internal const uint QUIC_PARAM_CONN_NETWORK_STATISTICS = 0x05000019;
3719+
37173720
[NativeTypeName("#define QUIC_PARAM_TLS_HANDSHAKE_INFO 0x06000000")]
37183721
internal const uint QUIC_PARAM_TLS_HANDSHAKE_INFO = 0x06000000;
37193722

src/inc/msquic.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,17 @@ typedef struct QUIC_STATISTICS_V2 {
641641

642642
} QUIC_STATISTICS_V2;
643643

644+
typedef struct NETWORK_STATISTICS
645+
{
646+
uint64_t BytesInFlight; // Bytes that were sent on the wire, but not yet acked
647+
uint64_t PostedBytes; // Total bytes queued, but not yet acked. These may contain sent bytes that may have potentially lost too.
648+
uint64_t IdealBytes; // Ideal number of bytes required to be available to avoid limiting throughput
649+
uint64_t SmoothedRTT; // Smoothed RTT value
650+
uint64_t CongestionWindow; // Congestion Window
651+
uint64_t Bandwidth; // Estimated bandwidth
652+
653+
} NETWORK_STATISTICS;
654+
644655
#define QUIC_STRUCT_SIZE_THRU_FIELD(Struct, Field) \
645656
(FIELD_OFFSET(Struct, Field) + sizeof(((Struct*)0)->Field))
646657

@@ -1011,6 +1022,10 @@ typedef struct QUIC_SCHANNEL_CREDENTIAL_ATTRIBUTE_W {
10111022
#define QUIC_PARAM_CONN_ORIG_DEST_CID 0x05000018 // uint8_t[]
10121023
#define QUIC_PARAM_CONN_SEND_DSCP 0x05000019 // uint8_t
10131024

1025+
#ifdef QUIC_API_ENABLE_PREVIEW_FEATURES
1026+
#define QUIC_PARAM_CONN_NETWORK_STATISTICS 0x05000020 // struct NETWORK_STATISTICS
1027+
#endif
1028+
10141029
//
10151030
// Parameters for TLS.
10161031
//
@@ -1359,14 +1374,7 @@ typedef struct QUIC_CONNECTION_EVENT {
13591374
BOOLEAN SendNegotiated; // TRUE if sending one-way delay timestamps is negotiated.
13601375
BOOLEAN ReceiveNegotiated; // TRUE if receiving one-way delay timestamps is negotiated.
13611376
} ONE_WAY_DELAY_NEGOTIATED;
1362-
struct {
1363-
uint32_t BytesInFlight; // Bytes that were sent on the wire, but not yet acked
1364-
uint64_t PostedBytes; // Total bytes queued, but not yet acked. These may contain sent bytes that may have potentially lost too.
1365-
uint64_t IdealBytes; // Ideal number of bytes required to be available to avoid limiting throughput
1366-
uint64_t SmoothedRTT; // Smoothed RTT value
1367-
uint32_t CongestionWindow; // Congestion Window
1368-
uint64_t Bandwidth; // Estimated bandwidth
1369-
} NETWORK_STATISTICS;
1377+
NETWORK_STATISTICS NETWORK_STATISTICS;
13701378
#endif
13711379
};
13721380
} QUIC_CONNECTION_EVENT;

src/rs/ffi/linux_bindings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub const QUIC_PARAM_CONN_STATISTICS_V2: u32 = 83886102;
207207
pub const QUIC_PARAM_CONN_STATISTICS_V2_PLAT: u32 = 83886103;
208208
pub const QUIC_PARAM_CONN_ORIG_DEST_CID: u32 = 83886104;
209209
pub const QUIC_PARAM_CONN_SEND_DSCP: u32 = 83886105;
210+
pub const QUIC_PARAM_CONN_NETWORK_STATISTICS: u32 = 83886106;
210211
pub const QUIC_PARAM_TLS_HANDSHAKE_INFO: u32 = 100663296;
211212
pub const QUIC_PARAM_TLS_NEGOTIATED_ALPN: u32 = 100663297;
212213
pub const QUIC_PARAM_STREAM_ID: u32 = 134217728;

src/rs/ffi/win_bindings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub const QUIC_PARAM_CONN_STATISTICS_V2: u32 = 83886102;
201201
pub const QUIC_PARAM_CONN_STATISTICS_V2_PLAT: u32 = 83886103;
202202
pub const QUIC_PARAM_CONN_ORIG_DEST_CID: u32 = 83886104;
203203
pub const QUIC_PARAM_CONN_SEND_DSCP: u32 = 83886105;
204+
pub const QUIC_PARAM_CONN_NETWORK_STATISTICS: u32 = 83886106;
204205
pub const QUIC_PARAM_TLS_HANDSHAKE_INFO: u32 = 100663296;
205206
pub const QUIC_PARAM_TLS_NEGOTIATED_ALPN: u32 = 100663297;
206207
pub const QUIC_PARAM_TLS_SCHANNEL_CONTEXT_ATTRIBUTE_W: u32 = 117440512;

src/test/lib/ApiTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,6 +4721,30 @@ void QuicTest_QUIC_PARAM_CONN_SEND_DSCP(MsQuicRegistration& Registration)
47214721
}
47224722
}
47234723

4724+
void QuicTest_QUIC_PARAM_CONN_NETWORK_STATISTICS(MsQuicRegistration& Registration)
4725+
{
4726+
TestScopeLogger LogScope0("QUIC_PARAM_CONN_NETWORK_STATISTICS");
4727+
{
4728+
TestScopeLogger LogScope1("SetParam");
4729+
MsQuicConnection Connection(Registration);
4730+
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
4731+
uint16_t Dummy = 0;
4732+
TEST_QUIC_STATUS(
4733+
QUIC_STATUS_INVALID_PARAMETER,
4734+
Connection.SetParam(
4735+
QUIC_PARAM_CONN_NETWORK_STATISTICS,
4736+
sizeof(Dummy),
4737+
&Dummy));
4738+
}
4739+
4740+
{
4741+
TestScopeLogger LogScope1("GetParam");
4742+
MsQuicConnection Connection(Registration);
4743+
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
4744+
SimpleGetParamTest(Connection.Handle, QUIC_PARAM_CONN_NETWORK_STATISTICS, sizeof(NETWORK_STATISTICS), nullptr, true);
4745+
}
4746+
}
4747+
47244748
void QuicTestConnectionParam()
47254749
{
47264750
MsQuicAlpn Alpn("MsQuicTest");
@@ -4755,6 +4779,7 @@ void QuicTestConnectionParam()
47554779
QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(Registration);
47564780
QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(Registration, ClientConfiguration);
47574781
QuicTest_QUIC_PARAM_CONN_SEND_DSCP(Registration);
4782+
QuicTest_QUIC_PARAM_CONN_NETWORK_STATISTICS(Registration);
47584783
}
47594784

47604785
//

0 commit comments

Comments
 (0)