From 7c8722d9d4d2db13d889be1e5e37bc062f069396 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Mon, 3 Oct 2022 11:43:34 +0900 Subject: [PATCH] [SBI] Client Request timeout TS29.500 Ch 6.11 Detection and handling of late arriving requests In Open5GS, this part was hard-corded. HTTP2 Client sends a request and waits for 10 seconds. If no response is received from the HTTP2 Server, HTTP2 Client performs the exception handling. In this commit, HTTP2 client sends Header with setting Max-Rsp-Time to 10 seconds. However, HTTP2 server has not yet been implemented to process this value. The server is still processing using hard-corded values (10 seconds). --- lib/sbi/conv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ lib/sbi/conv.h | 3 +++ lib/sbi/message.c | 14 ++++++++++ lib/sbi/message.h | 4 +++ 4 files changed, 87 insertions(+) diff --git a/lib/sbi/conv.c b/lib/sbi/conv.c index f7a071235..64fac328a 100644 --- a/lib/sbi/conv.c +++ b/lib/sbi/conv.c @@ -451,6 +451,72 @@ bool ogs_sbi_time_from_string(ogs_time_t *timestamp, char *str) return true; } +int ogs_sbi_rfc7231_string(char *date_str, ogs_time_t time) +{ + const char ogs_month_snames[12][4] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", + "Aug", "Sep", "Oct", "Nov", "Dec" + }; + const char ogs_day_snames[7][4] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + + struct tm gmt; + const char *s; + int real_year; + + ogs_time_t sec = ogs_time_sec(time); + ogs_time_t msec = ogs_time_msec(time); + + ogs_assert(date_str); + + ogs_gmtime(sec, &gmt); + + /* example: "Sun, 04 Aug 2019 08:49:37.845 GMT" */ + /* 123456789012345678901234567890123 */ + + s = &ogs_day_snames[gmt.tm_wday][0]; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = ','; + *date_str++ = ' '; + *date_str++ = gmt.tm_mday / 10 + '0'; + *date_str++ = gmt.tm_mday % 10 + '0'; + *date_str++ = ' '; + s = &ogs_month_snames[gmt.tm_mon][0]; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = *s++; + *date_str++ = ' '; + real_year = 1900 + gmt.tm_year; + /* This routine isn't y10k ready. */ + *date_str++ = real_year / 1000 + '0'; + *date_str++ = real_year % 1000 / 100 + '0'; + *date_str++ = real_year % 100 / 10 + '0'; + *date_str++ = real_year % 10 + '0'; + *date_str++ = ' '; + *date_str++ = gmt.tm_hour / 10 + '0'; + *date_str++ = gmt.tm_hour % 10 + '0'; + *date_str++ = ':'; + *date_str++ = gmt.tm_min / 10 + '0'; + *date_str++ = gmt.tm_min % 10 + '0'; + *date_str++ = ':'; + *date_str++ = gmt.tm_sec / 10 + '0'; + *date_str++ = gmt.tm_sec % 10 + '0'; + *date_str++ = '.'; + *date_str++ = msec / 100 + '0'; + *date_str++ = msec % 100 / 10 + '0'; + *date_str++ = msec % 10 + '0'; + *date_str++ = ' '; + *date_str++ = 'G'; + *date_str++ = 'M'; + *date_str++ = 'T'; + *date_str++ = 0; + + return OGS_OK; +} + char *ogs_sbi_s_nssai_to_string(ogs_s_nssai_t *s_nssai) { cJSON *item = NULL; diff --git a/lib/sbi/conv.h b/lib/sbi/conv.h index 523a499c9..4c0542338 100644 --- a/lib/sbi/conv.h +++ b/lib/sbi/conv.h @@ -56,6 +56,9 @@ char *ogs_sbi_gmtime_string(ogs_time_t time); char *ogs_sbi_timezone_string(int tm_gmtoff); bool ogs_sbi_time_from_string(ogs_time_t *time, char *str); +#define OGS_SBI_RFC7231_DATE_LEN (34) +int ogs_sbi_rfc7231_string(char *date_str, ogs_time_t time); + char *ogs_sbi_s_nssai_to_string(ogs_s_nssai_t *s_nssai); bool ogs_sbi_s_nssai_from_string(ogs_s_nssai_t *s_nssai, char *str); diff --git a/lib/sbi/message.c b/lib/sbi/message.c index 57bf65c1c..a3aabde1e 100644 --- a/lib/sbi/message.c +++ b/lib/sbi/message.c @@ -249,6 +249,8 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) { int i; ogs_sbi_request_t *request = NULL; + char sender_timestamp[OGS_SBI_RFC7231_DATE_LEN]; + char *max_rsp_time = NULL; ogs_assert(message); @@ -443,6 +445,18 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) END } + ogs_assert(OGS_OK == + ogs_sbi_rfc7231_string(sender_timestamp, ogs_time_now())); + ogs_sbi_header_set(request->http.headers, + OGS_SBI_OPTIONAL_CUSTOM_SENDER_TIMESTAMP, sender_timestamp); + + ogs_assert(ogs_time_to_msec(ogs_app()->time.message.duration)); + max_rsp_time = ogs_msprintf("%d", + (int)ogs_time_to_msec(ogs_app()->time.message.duration)); + ogs_sbi_header_set(request->http.headers, + OGS_SBI_OPTIONAL_CUSTOM_MAX_RSP_TIME, max_rsp_time); + ogs_free(max_rsp_time); + if (message->http.content_encoding) ogs_sbi_header_set(request->http.headers, OGS_SBI_ACCEPT_ENCODING, message->http.content_encoding); diff --git a/lib/sbi/message.h b/lib/sbi/message.h index 124ae341b..c713b5576 100644 --- a/lib/sbi/message.h +++ b/lib/sbi/message.h @@ -280,6 +280,10 @@ extern "C" { OGS_SBI_CUSTOM_3GPP_COMMON "Access-Scope" #define OGS_SBI_CUSTOM_ACCESS_TOKEN \ OGS_SBI_CUSTOM_3GPP_COMMON "Access-Token" +#define OGS_SBI_OPTIONAL_CUSTOM_SENDER_TIMESTAMP \ + OGS_SBI_CUSTOM_3GPP_COMMON "Sender-Timestamp" +#define OGS_SBI_OPTIONAL_CUSTOM_MAX_RSP_TIME \ + OGS_SBI_CUSTOM_3GPP_COMMON "Max-Rsp-Time" #define OGS_SBI_PARAM_TARGET_NF_TYPE "target-nf-type" #define OGS_SBI_PARAM_REQUESTER_NF_TYPE "requester-nf-type"