Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Fix: UPF send multiple buffered packet by 1 GTP packet when paging (#37)
Browse files Browse the repository at this point in the history
When buffered data is stored, information of length for each packet is held.
When sending data, the stored contents are taken out by length, added with a header, and transmitted.
  • Loading branch information
matsumu-y committed Sep 8, 2021
1 parent 818009b commit b688934
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/utlt/include/utlt_buff.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Status BufblkFmt(Bufblk *bufblk, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
Status BufblkBytes(Bufblk *bufblk, const char *str, uint32_t size);
Status BufblkAppend(Bufblk *bufblk, uint32_t num, uint32_t size);
int BufIsNotEnough(Bufblk *bufblk, uint32_t num, uint32_t size);

void *UTLT_Malloc(uint32_t size);
void *UTLT_Calloc(uint32_t num, uint32_t size);
Expand Down
1 change: 0 additions & 1 deletion lib/utlt/src/utlt_buff.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Status SelectBufblkOption(Bufblk *bufblk, int opt);
Status BufAlloc(Bufblk *bufblk, uint32_t num, uint32_t size);
Status BufFree(Bufblk *bufblk);

int BufIsNotEnough(Bufblk *bufblk, uint32_t num, uint32_t size);

#define BUF_ALLOC 1
#define BUF_FREE 2
Expand Down
6 changes: 6 additions & 0 deletions src/up/up_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,13 @@ static int PacketInBufferHandle(uint8_t *pkt, uint16_t pktlen, UPDK_PDR *matched
UTLT_Assert(packetStorage->packetBuffer, goto unlockErrorReturn, "UpfBufPacket alloc failed");
}

if (BufIsNotEnough(packetStorage->packetBuffer, 1, sizeof(pktlen) + pktlen)) {
UTLT_Level_Assert(LOG_DEBUG, BufblkResize(packetStorage->packetBuffer, 1, packetStorage->packetBuffer->size + sizeof(pktlen) + pktlen) == STATUS_OK,
goto unlockErrorReturn, "block add behind old buffer error");
}

// if packetBuffer not null, just add packet followed
BufblkBytes(packetStorage->packetBuffer, (const char *)&pktlen, sizeof(pktlen));
status = BufblkBytes(packetStorage->packetBuffer, (const char *) pkt, pktlen);
UTLT_Level_Assert(LOG_DEBUG, status == STATUS_OK, goto unlockErrorReturn,
"block add behand old buffer error");
Expand Down
27 changes: 18 additions & 9 deletions src/up/up_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,30 @@ Status UpSendPacketByPdrFar(UpfPDR *pdr, UpfFAR *far, Sock *sock) {
return STATUS_ERROR, "spin lock buffLock error");

Bufblk *sendBuf = BufblkAlloc(1, 0x40);
gtpHdr._length = htons(bufStorage->packetBuffer->len);
BufblkBytes(sendBuf, (void*)&gtpHdr, GTPV1_HEADER_LEN);
BufblkBuf(sendBuf, bufStorage->packetBuffer);
Bufblk *pktBuf = bufStorage->packetBuffer;
uint16_t pktlen;
for (void *pktDataPtr = pktBuf->buf; pktDataPtr < pktBuf->buf + pktBuf->len; pktDataPtr += pktlen) {
pktlen = *(uint16_t *)pktDataPtr;
pktDataPtr += sizeof(pktlen);
gtpHdr._length = htons(pktlen);
BufblkBytes(sendBuf, (void *)&gtpHdr, GTPV1_HEADER_LEN);
BufblkBytes(sendBuf, pktDataPtr, pktlen);
UTLT_Level_Assert(LOG_DEBUG, UdpSendTo(sock, sendBuf->buf, sendBuf->len) == STATUS_OK, , "UdpSendTo failed");
BufblkClear(sendBuf);
}

BufblkFree(sendBuf);

status = UdpSendTo(sock, sendBuf->buf, sendBuf->len);
UTLT_Assert(status == STATUS_OK,
pthread_spin_unlock(&Self()->buffLock); return status,
"UdpSendTo failed");
BufblkClear(sendBuf);
status = BufblkFree(bufStorage->packetBuffer);
if (status == STATUS_OK)
bufStorage->packetBuffer = NULL;
else
UTLT_Error("Free packet buffer failed");

while (pthread_spin_unlock(&Self()->buffLock)) {
// if unlock failed, keep trying
UTLT_Error("spin unlock error");
}
status = BufblkFree(bufStorage->packetBuffer);
} else {
UTLT_Debug("bufStorage is NULL");
}
Expand Down

0 comments on commit b688934

Please sign in to comment.