Skip to content

Commit

Permalink
Add support for Listener statistics. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
anrossi authored and nibanks committed Nov 5, 2019
1 parent 5eb2690 commit 41c63b3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
8 changes: 8 additions & 0 deletions core/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ typedef struct _QUIC_BINDING {
QUIC_POOL StatelessOperCtxPool;
uint32_t StatelessOperCount;

struct {

struct {
uint64_t DroppedPackets;
} Recv;

} Stats;

} QUIC_BINDING, *PQUIC_BINDING;

//
Expand Down
15 changes: 9 additions & 6 deletions core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,20 @@ QuicConnInitialize(
goto Error;
}
}
InitStep++; // Step 2

//
// N.B. Initializing packet space can fail part-way through, so it must be
// cleaned up even if it doesn't complete. Do not separate it from
// allocation.
//
Status =
QuicRangeInitialize(
QUIC_MAX_RANGE_DECODE_ACKS,
&Connection->DecodedAckRanges);
if (QUIC_FAILED(Status)) {
goto Error;
}
InitStep++; // Step 3
InitStep++; // Step 2

if (Datagram == NULL) {
Connection->State.Initialized = TRUE;
Expand All @@ -226,17 +230,16 @@ QuicConnInitialize(
Error:

switch (InitStep) {
case 3:
case 2:
QuicRangeUninitialize(&Connection->DecodedAckRanges);
__fallthrough;
case 2:
case 1:
for (uint32_t i = 0; i < ARRAYSIZE(Connection->Packets); i++) {
if (Connection->Packets[i] != NULL) {
QuicPacketSpaceUninitialize(Connection->Packets[i]);
}
}
__fallthrough;
case 1:

Connection->State.HandleClosed = TRUE;
Connection->State.Uninitialized = TRUE;
if (Datagram != NULL) {
Expand Down
41 changes: 34 additions & 7 deletions core/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ QuicListenerAcceptConnection(
Connection);
if (AcceptResult != QUIC_CONNECTION_ACCEPT) {
QuicRundownRelease(&Listener->Rundown);
Listener->TotalRejectedConnections++;
goto Error;
}

Expand All @@ -409,14 +410,14 @@ QuicListenerAcceptConnection(
&SecConfig);
QuicRundownRelease(&Listener->Rundown);

if (QUIC_FAILED(Status) && Status != QUIC_STATUS_PENDING) {
QUIC_TEL_ASSERTMSG(SecConfig == NULL, "App failed AND provided a sec config?");
goto Error;
}

if (SecConfig == NULL) {
if (Status != QUIC_STATUS_PENDING) {
if (Status != QUIC_STATUS_PENDING) {
if (QUIC_FAILED(Status)) {
QUIC_TEL_ASSERTMSG(SecConfig == NULL, "App failed AND provided a sec config?");
Listener->TotalRejectedConnections++;
goto Error;
} else if (SecConfig == NULL) {
LogVerbose("[conn][%p] No security config was provided by the app.", Connection);
Listener->TotalRejectedConnections++;
goto Error;
}
}
Expand All @@ -427,10 +428,12 @@ QuicListenerAcceptConnection(
if (Status != QUIC_STATUS_PENDING) {
Status = QuicConnHandshakeConfigure(Connection, SecConfig);
if (QUIC_FAILED(Status)) {
Listener->TotalRejectedConnections++;
goto Error;
}
}

Listener->TotalAcceptedConnections++;
AcceptResult = QUIC_CONNECTION_ACCEPT;

Error:
Expand Down Expand Up @@ -497,6 +500,30 @@ QuicListenerParamGet(
Status = QUIC_STATUS_SUCCESS;
break;

case QUIC_PARAM_LISTENER_STATS:

if (*BufferLength < sizeof(QUIC_LISTENER_STATISTICS)) {
*BufferLength = sizeof(QUIC_LISTENER_STATISTICS);
Status = QUIC_STATUS_BUFFER_TOO_SMALL;
break;
}

if (Buffer == NULL) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}

*BufferLength = sizeof(QUIC_LISTENER_STATISTICS);
QUIC_LISTENER_STATISTICS* Stats = (QUIC_LISTENER_STATISTICS*)Buffer;

Stats->TotalAcceptedConnections = Listener->TotalAcceptedConnections;
Stats->TotalRejectedConnections = Listener->TotalRejectedConnections;

Stats->Binding.Recv.DroppedPackets = Listener->Binding->Stats.Recv.DroppedPackets;

Status = QUIC_STATUS_SUCCESS;
break;

default:
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
Expand Down
6 changes: 6 additions & 0 deletions core/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ typedef struct _QUIC_LISTENER {
//
QUIC_LISTENER_CALLBACK_HANDLER ClientCallbackHandler;

//
// Stats for the Listener.
//
uint64_t TotalAcceptedConnections;
uint64_t TotalRejectedConnections;

} QUIC_LISTENER, *PQUIC_LISTENER;

//
Expand Down
4 changes: 4 additions & 0 deletions core/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ QuicPacketLogDrop(
QuicDataPathRecvPacketToRecvDatagram(Packet);

if (Packet->AssignedToConnection) {
InterlockedIncrement64((LONG64*) &((QUIC_CONNECTION*)Owner)->Stats.Recv.DroppedPackets);
EventWriteQuicConnDropPacket(
Owner,
Packet->PacketNumberSet ? UINT64_MAX : Packet->PacketNumber,
Expand All @@ -595,6 +596,7 @@ QuicPacketLogDrop(
(uint8_t*)&Datagram->Tuple->RemoteAddress,
Reason);
} else {
InterlockedIncrement64((LONG64*) &((QUIC_BINDING*)Owner)->Stats.Recv.DroppedPackets);
EventWriteQuicBindingDropPacket(
Owner,
Packet->PacketNumberSet ? UINT64_MAX : Packet->PacketNumber,
Expand All @@ -619,6 +621,7 @@ QuicPacketLogDropWithValue(
QuicDataPathRecvPacketToRecvDatagram(Packet);

if (Packet->AssignedToConnection) {
InterlockedIncrement64((LONG64*) & ((QUIC_CONNECTION*)Owner)->Stats.Recv.DroppedPackets);
EventWriteQuicConnDropPacketEx(
Owner,
Packet->PacketNumberSet ? UINT64_MAX : Packet->PacketNumber,
Expand All @@ -629,6 +632,7 @@ QuicPacketLogDropWithValue(
(uint8_t*)&Datagram->Tuple->RemoteAddress,
Reason);
} else {
InterlockedIncrement64((LONG64*) &((QUIC_BINDING*)Owner)->Stats.Recv.DroppedPackets);
EventWriteQuicBindingDropPacketEx(
Owner,
Packet->PacketNumberSet ? UINT64_MAX : Packet->PacketNumber,
Expand Down
17 changes: 15 additions & 2 deletions inc/msquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,19 @@ typedef struct _QUIC_STATISTICS {
struct {
uint32_t KeyUpdateCount;
} Misc;
} QUIC_STATISTICS;
} QUIC_STATISTICS;

typedef struct _QUIC_LISTENER_STATISTICS {

uint64_t TotalAcceptedConnections;
uint64_t TotalRejectedConnections;

struct {
struct {
uint64_t DroppedPackets;
} Recv;
} Binding;
} QUIC_LISTENER_STATISTICS;

//
// Functions for associating application contexts with QUIC handles.
Expand Down Expand Up @@ -477,7 +489,8 @@ typedef enum QUIC_PARAM_LEVEL {
//
// Parameters for QUIC_PARAM_LEVEL_LISTENER.
//
#define QUIC_PARAM_LISTENER_LOCAL_ADDRESS 0 // QUIC_ADDR
#define QUIC_PARAM_LISTENER_LOCAL_ADDRESS 0 // QUIC_ADDR
#define QUIC_PARAM_LISTENER_STATS 1 // QUIC_LISTENER_STATISTICS

//
// Parameters for QUIC_PARAM_LEVEL_CONNECTION.
Expand Down

0 comments on commit 41c63b3

Please sign in to comment.