From 569a7cbc949a415773454abf1ae647bcf393a784 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Tue, 25 Sep 2018 15:17:39 +0100 Subject: [PATCH 01/10] GTPU cleanup, adding support for GTPU echo response --- lib/include/srslte/upper/gtpu.h | 4 +- srsenb/hdr/upper/gtpu.h | 7 +- srsenb/src/upper/gtpu.cc | 128 ++++++++++++++++++-------------- 3 files changed, 77 insertions(+), 62 deletions(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 24b9c5c41..55c8189cc 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -52,8 +52,8 @@ namespace srslte { #define GTPU_HEADER_LEN 8 typedef struct{ - uint8_t flags; // Only support 0x30 - v1, PT1 (GTP), no other flags - uint8_t message_type; // Only support 0xFF - T-PDU type + uint8_t flags; + uint8_t message_type; uint16_t length; uint32_t teid; }gtpu_header_t; diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index 4dc05585d..519b831d9 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -124,12 +124,11 @@ private: }bearer_map; std::map rnti_bearers; - // Socket file descriptors - int snk_fd; - int src_fd; + // Socket file descriptor + int fd; - //Threading void run_thread(); + void echo_response(in_addr_t addr, in_port_t port, uint16_t seq); pthread_mutex_t mutex; diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 1d90fd388..777943125 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -52,35 +52,19 @@ bool gtpu::init(std::string gtp_bind_addr_, std::string mme_addr_, srsenb::pdcp_ pool = byte_buffer_pool::get_instance(); - // Set up sink socket - snk_fd = socket(AF_INET, SOCK_DGRAM, 0); - if (snk_fd < 0) { - gtpu_log->error("Failed to create sink socket\n"); + // Set up socket + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + gtpu_log->error("Failed to create socket\n"); return false; } int enable = 1; #if defined (SO_REUSEADDR) - if (setsockopt(snk_fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) gtpu_log->error("setsockopt(SO_REUSEADDR) failed\n"); #endif #if defined (SO_REUSEPORT) - if (setsockopt(snk_fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) - gtpu_log->error("setsockopt(SO_REUSEPORT) failed\n"); -#endif - - - // Set up source socket - src_fd = socket(AF_INET, SOCK_DGRAM, 0); - if (src_fd < 0) { - gtpu_log->error("Failed to create source socket\n"); - return false; - } -#if defined (SO_REUSEADDR) - if (setsockopt(src_fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) - gtpu_log->error("setsockopt(SO_REUSEADDR) failed\n"); -#endif -#if defined (SO_REUSEPORT) - if (setsockopt(src_fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(int)) < 0) gtpu_log->error("setsockopt(SO_REUSEPORT) failed\n"); #endif @@ -90,7 +74,7 @@ bool gtpu::init(std::string gtp_bind_addr_, std::string mme_addr_, srsenb::pdcp_ bindaddr.sin_addr.s_addr = inet_addr(gtp_bind_addr.c_str()); bindaddr.sin_port = htons(GTPU_PORT); - if (bind(src_fd, (struct sockaddr *)&bindaddr, sizeof(struct sockaddr_in))) { + if (bind(fd, (struct sockaddr *)&bindaddr, sizeof(struct sockaddr_in))) { gtpu_log->error("Failed to bind on address %s, port %d\n", gtp_bind_addr.c_str(), GTPU_PORT); gtpu_log->console("Failed to bind on address %s, port %d\n", gtp_bind_addr.c_str(), GTPU_PORT); return false; @@ -128,11 +112,8 @@ void gtpu::stop() wait_thread_finish(); } - if (snk_fd) { - close(snk_fd); - } - if (src_fd) { - close(src_fd); + if (fd) { + close(fd); } } @@ -152,7 +133,7 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu) servaddr.sin_port = htons(GTPU_PORT); gtpu_write_header(&header, pdu, gtpu_log); - if (sendto(snk_fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in))<0) { + if (sendto(fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in))<0) { perror("sendto"); } @@ -223,6 +204,10 @@ void gtpu::run_thread() } run_enable = true; + sockaddr_in client; + socklen_t client_len = sizeof(client); + size_t buflen = SRSENB_MAX_BUFFER_SIZE_BYTES - SRSENB_BUFFER_HEADER_OFFSET; + running=true; while(run_enable) { @@ -230,7 +215,7 @@ void gtpu::run_thread() gtpu_log->debug("Waiting for read...\n"); int n = 0; do{ - n = recv(src_fd, pdu->msg, SRSENB_MAX_BUFFER_SIZE_BYTES - SRSENB_BUFFER_HEADER_OFFSET, 0); + n = recvfrom(fd, pdu->msg, buflen, 0, (struct sockaddr *)&client, &client_len); } while (n == -1 && errno == EAGAIN); if (n < 0) { @@ -239,40 +224,71 @@ void gtpu::run_thread() pdu->N_bytes = (uint32_t) n; - gtpu_header_t header; - gtpu_read_header(pdu, &header,gtpu_log); + if(pdu->msg[1] == 0x01) { + if(n<10) { + continue; + } + // Echo request - send response + uint16_t seq = 0; + uint8_to_uint16(&pdu->msg[8], &seq); + echo_response(client.sin_addr.s_addr, client.sin_port, seq); + + }else{ + gtpu_header_t header; + gtpu_read_header(pdu, &header,gtpu_log); + + uint16_t rnti = 0; + uint16_t lcid = 0; + teidin_to_rntilcid(header.teid, &rnti, &lcid); + + pthread_mutex_lock(&mutex); + bool user_exists = (rnti_bearers.count(rnti) > 0); + pthread_mutex_unlock(&mutex); + + if(!user_exists) { + gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti); + continue; + } + + if(lcid < SRSENB_N_SRB || lcid >= SRSENB_N_RADIO_BEARERS) { + gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid); + continue; + } - uint16_t rnti = 0; - uint16_t lcid = 0; - teidin_to_rntilcid(header.teid, &rnti, &lcid); + gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes); - pthread_mutex_lock(&mutex); - bool user_exists = (rnti_bearers.count(rnti) > 0); - pthread_mutex_unlock(&mutex); + pdcp->write_sdu(rnti, lcid, pdu); - if(!user_exists) { - gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti); - continue; + do { + pdu = pool_allocate; + if (!pdu) { + gtpu_log->console("GTPU Buffer pool empty. Trying again...\n"); + usleep(10000); + } + } while(!pdu); } + } + running = false; +} - if(lcid < SRSENB_N_SRB || lcid >= SRSENB_N_RADIO_BEARERS) { - gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid); - continue; - } +void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq) +{ + gtpu_log->info("TX GTPU Echo Response, Seq: %d\n", seq); - gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes); + uint8_t resp[12]; + bzero(resp, 12); + resp[0] = 0x32; //flags + resp[1] = 0x02; //type + uint16_to_uint8(4, &resp[2]); //length + uint32_to_uint8(0, &resp[4]); //TEID + uint16_to_uint8(seq, &resp[8]); //seq - pdcp->write_sdu(rnti, lcid, pdu); + struct sockaddr_in servaddr; + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = addr; + servaddr.sin_port = port; - do { - pdu = pool_allocate; - if (!pdu) { - gtpu_log->console("GTPU Buffer pool empty. Trying again...\n"); - usleep(10000); - } - } while(!pdu); - } - running = false; + sendto(fd, resp, 12, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in)); } /**************************************************************************** From ee04639337b2a29bd241eb555fc36990ab615395 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 28 Sep 2018 13:46:13 +0100 Subject: [PATCH 02/10] Changed gtpu header flags to use a bitfield. Fixing compilation issues. --- lib/include/srslte/upper/gtpu.h | 50 ++++++++++++++---- lib/src/upper/gtpu.cc | 65 +++++++++++++++++++----- srsenb/src/upper/gtpu.cc | 90 +++++++++++++++++++-------------- srsepc/src/mbms-gw/mbms-gw.cc | 15 +++--- srsepc/src/spgw/spgw.cc | 9 ++-- 5 files changed, 155 insertions(+), 74 deletions(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 55c8189cc..5cb0ed8ce 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -40,22 +40,54 @@ namespace srslte { * | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | * * 1 | Version |PT | * | E | S |PN | - * 2 | Message Type | - * 3 | Length (1st Octet) | - * 4 | Length (2nd Octet) | - * 5 | TEID (1st Octet) | - * 6 | TEID (2nd Octet) | - * 7 | TEID (3rd Octet) | - * 8 | TEID (4th Octet) | + * 2 | Message Type | + * 3 | Length (1st Octet) | + * 4 | Length (2nd Octet) | + * 5 | TEID (1st Octet) | + * 6 | TEID (2nd Octet) | + * 7 | TEID (3rd Octet) | + * 8 | TEID (4th Octet) | + * 9 | Seq Number (1st Octet) | + * 10 | Seq Number (2st Octet) | + * 11 | N-PDU | + * 12 | Next Extension Header Type | ***************************************************************************/ -#define GTPU_HEADER_LEN 8 +#define GTPU_BASE_HEADER_LEN 8 +#define GTPU_EXTENDED_HEADER_LEN 12 + +#define GTPU_VERSION_V1 1 + +#define GTP_PRIME_PROTO 0 +#define GTP_PROTO 1 + +#define GTPU_MSG_ECHO_REQUEST 0 +#define GTPU_MSG_ECHO_RESPONSE 1 +#define GTPU_MSG_ERROR_INDICATION 26 +#define GTPU_MSG_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION 31 +#define GTPU_MSG_END_MARKER 254 +#define GTPU_MSG_DATA_PDU 255 + +typedef struct{ + uint8_t version : 3; + uint8_t protocol_type : 1; + uint8_t star : 1; + uint8_t ext_header :1; + uint8_t sequence :1; + uint8_t pkt_number :1; +}gtpu_flags_t; typedef struct{ - uint8_t flags; + union{ + gtpu_flags_t flag_bits; + uint8_t flags; + } gtpu_flags; uint8_t message_type; uint16_t length; uint32_t teid; + uint16_t seq_number; + uint8_t n_pdu; + uint8_t next_ext_hdr_type; }gtpu_header_t; diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index a8046aa4d..54ecdf6fc 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -37,21 +37,30 @@ namespace srslte { bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log) { - if(header->flags != 0x30) { - gtpu_log->error("gtpu_write_header - Unhandled header flags: 0x%x\n", header->flags); + + if(header->flags.version != GTPU_VERSION_V1) { + gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n"); + return false; + } + if(header->flags.protocol_type != GTP_PROTO) { + gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n"); + return false; + } + if(header->flags.ext_header) { + gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n"); return false; } - if(header->message_type != 0xFF) { + if(header->message_type != GTPU_MSG_DATA_PDU) { gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type); return false; } - if(pdu->get_headroom() < GTPU_HEADER_LEN) { + if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); return false; } - pdu->msg -= GTPU_HEADER_LEN; - pdu->N_bytes += GTPU_HEADER_LEN; + pdu->msg -= GTPU_BASE_HEADER_LEN; + pdu->N_bytes += GTPU_BASE_HEADER_LEN; uint8_t *ptr = pdu->msg; @@ -70,22 +79,50 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: { uint8_t *ptr = pdu->msg; - pdu->msg += GTPU_HEADER_LEN; - pdu->N_bytes -= GTPU_HEADER_LEN; - - header->flags = *ptr; + header->flags = *ptr; ptr++; - header->message_type = *ptr; + header->message_type = *ptr; ptr++; uint8_to_uint16(ptr, &header->length); ptr += 2; uint8_to_uint32(ptr, &header->teid); - if(header->flags != 0x30) { - gtpu_log->error("gtpu_read_header - Unhandled header flags: 0x%x\n", header->flags); + if(header->gtpu_flags.flag_bits.version != GTPU_VERSION_V1) { + gtpu_log->error("gtpu_read_header - Unhandled GTP-U version. Flags: 0x%x\n", header->gtpu_flags.flags); + return false; + } + if(header->gtpu_flags.flag_bits.protocol_type != GTP_PROTO) { + gtpu_log->error("gtpu_read_header - Unhandled GTP Protocol. Flags: 0x%x\n", header->gtpu_flags.flags); + return false; + } + if(header->gtpu_flags.flag_bits.ext_header) { + gtpu_log->error("gtpu_read_header - Unhandled GTP-U Header Extensions. Flags: 0x%x\n", header->gtpu_flags.flags); return false; } - if(header->message_type != 0xFF) { + + //If E, S or PN are set, header is longer + if(header->gtpu_flags.flag_bits.sequence || header->gtpu_flags.flag_bits.ext_header || header->gtpu_flags.flag_bits.ext_header) { + pdu->msg += GTPU_EXTENDED_HEADER_LEN; + pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN; + + uint8_to_uint16(ptr, &header->seq_number); + ptr+=2; + + header->n_pdu = *ptr; + ptr++; + + header->next_ext_hdr_type = *ptr; + ptr++; + } else { + pdu->msg += GTPU_BASE_HEADER_LEN; + pdu->N_bytes -= GTPU_BASE_HEADER_LEN; + } + + if(header->gtpu_flags.flag_bits.sequence){ + ptr+=2; + } + + if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) { gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type); return false; } diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 777943125..62855ff5f 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -122,8 +122,10 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu) { gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes); gtpu_header_t header; - header.flags = 0x30; - header.message_type = 0xFF; + bzero(&header,sizeof(header)); + header.flags.version = GTPU_VERSION_V1; + header.flags.protocol_type = GTP_PROTO; + header.message_type = GTPU_MSG_DATA_PDU; header.length = pdu->N_bytes; header.teid = rnti_bearers[rnti].teids_out[lcid]; @@ -224,48 +226,50 @@ void gtpu::run_thread() pdu->N_bytes = (uint32_t) n; - if(pdu->msg[1] == 0x01) { - if(n<10) { - continue; - } - // Echo request - send response - uint16_t seq = 0; - uint8_to_uint16(&pdu->msg[8], &seq); - echo_response(client.sin_addr.s_addr, client.sin_port, seq); - - }else{ - gtpu_header_t header; - gtpu_read_header(pdu, &header,gtpu_log); - - uint16_t rnti = 0; - uint16_t lcid = 0; - teidin_to_rntilcid(header.teid, &rnti, &lcid); - - pthread_mutex_lock(&mutex); - bool user_exists = (rnti_bearers.count(rnti) > 0); - pthread_mutex_unlock(&mutex); - - if(!user_exists) { - gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti); - continue; - } + gtpu_header_t header; + if(!gtpu_read_header(pdu, &header,gtpu_log)){ + continue; + } - if(lcid < SRSENB_N_SRB || lcid >= SRSENB_N_RADIO_BEARERS) { - gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid); - continue; - } + switch(header.message_type) { + + case GTPU_MSG_ECHO_REQUEST: + // Echo request - send response + echo_response(client.sin_addr.s_addr, client.sin_port, header.seq_number); + break; - gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes); + case GTPU_MSG_DATA_PDU: - pdcp->write_sdu(rnti, lcid, pdu); + uint16_t rnti = 0; + uint16_t lcid = 0; + teidin_to_rntilcid(header.teid, &rnti, &lcid); - do { - pdu = pool_allocate; - if (!pdu) { - gtpu_log->console("GTPU Buffer pool empty. Trying again...\n"); - usleep(10000); + pthread_mutex_lock(&mutex); + bool user_exists = (rnti_bearers.count(rnti) > 0); + pthread_mutex_unlock(&mutex); + + if(!user_exists) { + gtpu_log->error("Unrecognized RNTI for DL PDU: 0x%x - dropping packet\n", rnti); + continue; } - } while(!pdu); + + if(lcid < SRSENB_N_SRB || lcid >= SRSENB_N_RADIO_BEARERS) { + gtpu_log->error("Invalid LCID for DL PDU: %d - dropping packet\n", lcid); + continue; + } + + gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes); + + pdcp->write_sdu(rnti, lcid, pdu); + + do { + pdu = pool_allocate; + if (!pdu) { + gtpu_log->console("GTPU Buffer pool empty. Trying again...\n"); + usleep(10000); + } + } while(!pdu); + break; } } running = false; @@ -275,6 +279,14 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq) { gtpu_log->info("TX GTPU Echo Response, Seq: %d\n", seq); + gtpu_header_t header; + bzero(&header, sizeof(header)); + + //flags + header.flags.version = GTPU_VERSION_V1; + header.flags.protocol_type = GTP_PROTO; + header.flags.sequence = 1; + uint8_t resp[12]; bzero(resp, 12); resp[0] = 0x32; //flags diff --git a/srsepc/src/mbms-gw/mbms-gw.cc b/srsepc/src/mbms-gw/mbms-gw.cc index b373df4e7..03f08bcc6 100644 --- a/srsepc/src/mbms-gw/mbms-gw.cc +++ b/srsepc/src/mbms-gw/mbms-gw.cc @@ -285,31 +285,30 @@ mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t *msg) { uint8_t version; srslte::gtpu_header_t header; + bzero(&header, sizeof(srslte::gtpu_header_t)); //Setup GTP-U header - header.flags = 0x30; - header.message_type = 0xFF; + header.flags.version = GTPU_VERSION_V1; + header.flags.protocol_type = GTP_PROTO; + header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; header.teid = 0xAAAA; //FIXME Harcoded TEID for now //Sanity Check IP packet - if(msg->N_bytes < 20) - { + if (msg->N_bytes < 20) { m_mbms_gw_log->error("IPv4 min len: %d, drop msg len %d\n", 20, msg->N_bytes); return; } //IP Headers struct iphdr *iph = (struct iphdr *) msg->msg; - if(iph->version != 4) - { + if(iph->version != 4) { m_mbms_gw_log->warning("IPv6 not supported yet.\n"); return; } //Write GTP-U header into packet - if(!srslte::gtpu_write_header(&header, msg, m_mbms_gw_log)) - { + if (!srslte::gtpu_write_header(&header, msg, m_mbms_gw_log)) { m_mbms_gw_log->console("Error writing GTP-U header on PDU\n"); } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 20311cc16..2c34e5da8 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -363,14 +363,15 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) //Setup GTP-U header srslte::gtpu_header_t header; - header.flags = 0x30; - header.message_type = 0xFF; + bzero(&header,sizeof(srslte::gtpu_header_t)); + header.flags.version = GTPU_VERSION_V1; + header.flags.protocol_type = GTP_PROTO; + header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; header.teid = enb_fteid.teid; //Write header into packet - if(!srslte::gtpu_write_header(&header, msg, m_spgw_log)) - { + if (!srslte::gtpu_write_header(&header, msg, m_spgw_log)) { m_spgw_log->console("Error writing GTP-U header on PDU\n"); } From e320c33aefad68008b41a80c31f750b5e3ed4f9a Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 28 Sep 2018 15:42:28 +0100 Subject: [PATCH 03/10] Fixed last compilation issues. --- lib/src/upper/gtpu.cc | 10 +++++----- srsenb/src/upper/gtpu.cc | 30 ++++++++++++++++-------------- srsepc/src/mbms-gw/mbms-gw.cc | 4 ++-- srsepc/src/spgw/spgw.cc | 18 +++++++----------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 54ecdf6fc..b01f834fb 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -38,15 +38,15 @@ namespace srslte { bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log) { - if(header->flags.version != GTPU_VERSION_V1) { + if(header->gtpu_flags.flag_bits.version != GTPU_VERSION_V1) { gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n"); return false; } - if(header->flags.protocol_type != GTP_PROTO) { + if(header->gtpu_flags.flag_bits.protocol_type != GTP_PROTO) { gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n"); return false; } - if(header->flags.ext_header) { + if(header->gtpu_flags.flag_bits.ext_header) { gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n"); return false; } @@ -64,7 +64,7 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte uint8_t *ptr = pdu->msg; - *ptr = header->flags; + *ptr = header->gtpu_flags.flags; ptr++; *ptr = header->message_type; ptr++; @@ -79,7 +79,7 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: { uint8_t *ptr = pdu->msg; - header->flags = *ptr; + header->gtpu_flags.flags = *ptr; ptr++; header->message_type = *ptr; ptr++; diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 62855ff5f..99bcd7e25 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -123,8 +123,8 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu) gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes); gtpu_header_t header; bzero(&header,sizeof(header)); - header.flags.version = GTPU_VERSION_V1; - header.flags.protocol_type = GTP_PROTO; + header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; + header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; header.message_type = GTPU_MSG_DATA_PDU; header.length = pdu->N_bytes; header.teid = rnti_bearers[rnti].teids_out[lcid]; @@ -282,25 +282,27 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq) gtpu_header_t header; bzero(&header, sizeof(header)); + srslte::byte_buffer_t *pdu = pool_allocate; + //flags - header.flags.version = GTPU_VERSION_V1; - header.flags.protocol_type = GTP_PROTO; - header.flags.sequence = 1; - - uint8_t resp[12]; - bzero(resp, 12); - resp[0] = 0x32; //flags - resp[1] = 0x02; //type - uint16_to_uint8(4, &resp[2]); //length - uint32_to_uint8(0, &resp[4]); //TEID - uint16_to_uint8(seq, &resp[8]); //seq + header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; + header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; + header.gtpu_flags.flag_bits.sequence = 1; + + header.message_type = GTPU_MSG_ECHO_RESPONSE; + header.teid = 0; + header.length = 4; + header.seq_number = seq; + + gtpu_write_header(&header,pdu,gtpu_log); struct sockaddr_in servaddr; servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = addr; servaddr.sin_port = port; - sendto(fd, resp, 12, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in)); + sendto(fd, pdu->msg, 12, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in)); + pool->deallocate(pdu); } /**************************************************************************** diff --git a/srsepc/src/mbms-gw/mbms-gw.cc b/srsepc/src/mbms-gw/mbms-gw.cc index 03f08bcc6..e9d828451 100644 --- a/srsepc/src/mbms-gw/mbms-gw.cc +++ b/srsepc/src/mbms-gw/mbms-gw.cc @@ -288,8 +288,8 @@ mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t *msg) bzero(&header, sizeof(srslte::gtpu_header_t)); //Setup GTP-U header - header.flags.version = GTPU_VERSION_V1; - header.flags.protocol_type = GTP_PROTO; + header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; + header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; header.teid = 0xAAAA; //FIXME Harcoded TEID for now diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 2c34e5da8..da36fdaac 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -330,28 +330,24 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) srslte::gtpc_f_teid_ie enb_fteid; struct iphdr *iph = (struct iphdr *) msg->msg; - if(iph->version != 4) - { + if (iph->version != 4) { m_spgw_log->warning("IPv6 not supported yet.\n"); return; } - if(iph->tot_len < 20) - { + if (iph->tot_len < 20) { m_spgw_log->warning("Invalid IP header length.\n"); return; } pthread_mutex_lock(&m_mutex); gtp_fteid_it = m_ip_to_teid.find(iph->daddr); - if(gtp_fteid_it != m_ip_to_teid.end()) - { + if (gtp_fteid_it != m_ip_to_teid.end()) { ip_found = true; enb_fteid = gtp_fteid_it->second; } pthread_mutex_unlock(&m_mutex); - if(ip_found == false) - { + if (ip_found == false) { //m_spgw_log->console("IP Packet is not for any UE\n"); return; } @@ -364,9 +360,9 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) //Setup GTP-U header srslte::gtpu_header_t header; bzero(&header,sizeof(srslte::gtpu_header_t)); - header.flags.version = GTPU_VERSION_V1; - header.flags.protocol_type = GTP_PROTO; - header.message_type = GTPU_MSG_DATA_PDU; + header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; + header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; + header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; header.teid = enb_fteid.teid; From c1f633c5c7bcf81ae9d612a6da8bfd893477dba9 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 15:17:26 +0100 Subject: [PATCH 04/10] Dropping bitfields for now. Using #defines and uint8_t for the flags. --- lib/include/srslte/upper/gtpu.h | 74 +++++++++++++++------------------ lib/src/upper/gtpu.cc | 73 +++++++++++++++----------------- srsenb/src/upper/gtpu.cc | 15 +++---- srsepc/src/mbms-gw/mbms-gw.cc | 4 +- srsepc/src/spgw/spgw.cc | 6 +-- 5 files changed, 75 insertions(+), 97 deletions(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 5cb0ed8ce..41e9dc2e9 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -56,10 +56,13 @@ namespace srslte { #define GTPU_BASE_HEADER_LEN 8 #define GTPU_EXTENDED_HEADER_LEN 12 -#define GTPU_VERSION_V1 1 - -#define GTP_PRIME_PROTO 0 -#define GTP_PROTO 1 +#define GTPU_FLAGS_VERSION_MASK 0xE0 +#define GTPU_FLAGS_VERSION_V1 0x20 +#define GTPU_FLAGS_GTP_PRIME_PROTOCOL 0x00 +#define GTPU_FLAGS_GTP_PROTOCOL 0x10 +#define GTPU_FLAGS_EXTENDED_HDR 0x04 +#define GTPU_FLAGS_SEQUENCE 0x02 +#define GTPU_FLAGS_PACKET_NUM 0x01 #define GTPU_MSG_ECHO_REQUEST 0 #define GTPU_MSG_ECHO_RESPONSE 1 @@ -69,19 +72,7 @@ namespace srslte { #define GTPU_MSG_DATA_PDU 255 typedef struct{ - uint8_t version : 3; - uint8_t protocol_type : 1; - uint8_t star : 1; - uint8_t ext_header :1; - uint8_t sequence :1; - uint8_t pkt_number :1; -}gtpu_flags_t; - -typedef struct{ - union{ - gtpu_flags_t flag_bits; - uint8_t flags; - } gtpu_flags; + uint8_t flags; uint8_t message_type; uint16_t length; uint32_t teid; @@ -94,35 +85,38 @@ typedef struct{ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte::log *gtpu_log); bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log); -inline void uint8_to_uint32(uint8_t *buf, uint32_t *i) -{ - *i = (uint32_t)buf[0] << 24 | - (uint32_t)buf[1] << 16 | - (uint32_t)buf[2] << 8 | - (uint32_t)buf[3]; -} - -inline void uint32_to_uint8(uint32_t i, uint8_t *buf) +inline bool gtpu_supported_flags_check(gtpu_header_t *header, srslte::log *gtpu_log) { - buf[0] = (i >> 24) & 0xFF; - buf[1] = (i >> 16) & 0xFF; - buf[2] = (i >> 8) & 0xFF; - buf[3] = i & 0xFF; + //flags + if( (header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1 ) { + gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n"); + return false; + } + if( !(header->flags & GTPU_FLAGS_GTP_PROTOCOL) ) { + gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n"); + return false; + } + if( !(header->flags & GTPU_FLAGS_EXTENDED_HDR) ) { + gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n"); + return false; + } + if( !(header->flags & GTPU_FLAGS_PACKET_NUM) ) { + gtpu_log->error("gtpu_write_header - Unhandled Packet Number.\n"); + return false; + } + return true; } -inline void uint8_to_uint16(uint8_t *buf, uint16_t *i) +inline bool gtpu_supported_msg_type_check(gtpu_header_t *header, srslte::log *gtpu_log) { - *i = (uint32_t)buf[0] << 8 | - (uint32_t)buf[1]; + //msg_tpye + if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) { + gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type); + return false; + } + return true; } -inline void uint16_to_uint8(uint16_t i, uint8_t *buf) -{ - buf[0] = (i >> 8) & 0xFF; - buf[1] = i & 0xFF; -} - - }//namespace #endif diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index b01f834fb..b373cc546 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -26,7 +26,7 @@ #include "srslte/upper/gtpu.h" - +#include "srslte/common/int_helpers.h" namespace srslte { @@ -37,40 +37,45 @@ namespace srslte { bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte::log *gtpu_log) { - - if(header->gtpu_flags.flag_bits.version != GTPU_VERSION_V1) { - gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n"); - return false; - } - if(header->gtpu_flags.flag_bits.protocol_type != GTP_PROTO) { - gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n"); - return false; - } - if(header->gtpu_flags.flag_bits.ext_header) { - gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n"); + //flags + if(!gtpu_supported_flags_check(header,gtpu_log)){ return false; } - if(header->message_type != GTPU_MSG_DATA_PDU) { + + //msg type + if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) { gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type); return false; } - if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { - gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); - return false; - } - pdu->msg -= GTPU_BASE_HEADER_LEN; - pdu->N_bytes += GTPU_BASE_HEADER_LEN; + //If E, S or PN are set, the header is longer + if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { + if(pdu->get_headroom() < GTPU_EXTENDED_HEADER_LEN) { + gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); + return false; + } + pdu->msg -= GTPU_EXTENDED_HEADER_LEN; + pdu->N_bytes += GTPU_EXTENDED_HEADER_LEN; + } else { + if(pdu->get_headroom() < GTPU_BASE_HEADER_LEN) { + gtpu_log->error("gtpu_write_header - No room in PDU for header\n"); + return false; + } + pdu->msg -= GTPU_BASE_HEADER_LEN; + pdu->N_bytes += GTPU_BASE_HEADER_LEN; + } + //write mandatory fields uint8_t *ptr = pdu->msg; - - *ptr = header->gtpu_flags.flags; + *ptr = header->flags; ptr++; *ptr = header->message_type; ptr++; uint16_to_uint8(header->length, ptr); ptr += 2; uint32_to_uint8(header->teid, ptr); + //write optional fields + return true; } @@ -79,7 +84,7 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: { uint8_t *ptr = pdu->msg; - header->gtpu_flags.flags = *ptr; + header->flags = *ptr; ptr++; header->message_type = *ptr; ptr++; @@ -87,21 +92,18 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: ptr += 2; uint8_to_uint32(ptr, &header->teid); - if(header->gtpu_flags.flag_bits.version != GTPU_VERSION_V1) { - gtpu_log->error("gtpu_read_header - Unhandled GTP-U version. Flags: 0x%x\n", header->gtpu_flags.flags); - return false; - } - if(header->gtpu_flags.flag_bits.protocol_type != GTP_PROTO) { - gtpu_log->error("gtpu_read_header - Unhandled GTP Protocol. Flags: 0x%x\n", header->gtpu_flags.flags); + //flags + if(!gtpu_supported_flags_check(header,gtpu_log)){ return false; } - if(header->gtpu_flags.flag_bits.ext_header) { - gtpu_log->error("gtpu_read_header - Unhandled GTP-U Header Extensions. Flags: 0x%x\n", header->gtpu_flags.flags); + + //message_type + if(!gtpu_supported_msg_type_check(header,gtpu_log)){ return false; } //If E, S or PN are set, header is longer - if(header->gtpu_flags.flag_bits.sequence || header->gtpu_flags.flag_bits.ext_header || header->gtpu_flags.flag_bits.ext_header) { + if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { pdu->msg += GTPU_EXTENDED_HEADER_LEN; pdu->N_bytes -= GTPU_EXTENDED_HEADER_LEN; @@ -118,15 +120,6 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: pdu->N_bytes -= GTPU_BASE_HEADER_LEN; } - if(header->gtpu_flags.flag_bits.sequence){ - ptr+=2; - } - - if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) { - gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type); - return false; - } - return true; } diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 99bcd7e25..acce49eb6 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -122,9 +122,7 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu) { gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes); gtpu_header_t header; - bzero(&header,sizeof(header)); - header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; - header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; + header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL; header.message_type = GTPU_MSG_DATA_PDU; header.length = pdu->N_bytes; header.teid = rnti_bearers[rnti].teids_out[lcid]; @@ -280,19 +278,16 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq) gtpu_log->info("TX GTPU Echo Response, Seq: %d\n", seq); gtpu_header_t header; - bzero(&header, sizeof(header)); - srslte::byte_buffer_t *pdu = pool_allocate; - //flags - header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; - header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; - header.gtpu_flags.flag_bits.sequence = 1; - + //header + header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL | GTPU_FLAGS_SEQUENCE; header.message_type = GTPU_MSG_ECHO_RESPONSE; header.teid = 0; header.length = 4; header.seq_number = seq; + header.n_pdu = 0; + header.next_ext_hdr_type = 0; gtpu_write_header(&header,pdu,gtpu_log); diff --git a/srsepc/src/mbms-gw/mbms-gw.cc b/srsepc/src/mbms-gw/mbms-gw.cc index e9d828451..dc8199e27 100644 --- a/srsepc/src/mbms-gw/mbms-gw.cc +++ b/srsepc/src/mbms-gw/mbms-gw.cc @@ -285,11 +285,9 @@ mbms_gw::handle_sgi_md_pdu(srslte::byte_buffer_t *msg) { uint8_t version; srslte::gtpu_header_t header; - bzero(&header, sizeof(srslte::gtpu_header_t)); //Setup GTP-U header - header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; - header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; + header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL; header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; header.teid = 0xAAAA; //FIXME Harcoded TEID for now diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index da36fdaac..0a867d51c 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -359,10 +359,8 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg) //Setup GTP-U header srslte::gtpu_header_t header; - bzero(&header,sizeof(srslte::gtpu_header_t)); - header.gtpu_flags.flag_bits.version = GTPU_VERSION_V1; - header.gtpu_flags.flag_bits.protocol_type = GTP_PROTO; - header.message_type = GTPU_MSG_DATA_PDU; + header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL; + header.message_type = GTPU_MSG_DATA_PDU; header.length = msg->N_bytes; header.teid = enb_fteid.teid; From c9cd355cdb891b1335edd3dc585b43ee8d2426a6 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 15:46:14 +0100 Subject: [PATCH 05/10] Forgot to use supported_msg_type_check in gtpu_write_header. --- lib/src/upper/gtpu.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index b373cc546..38a8cd572 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -43,8 +43,7 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte } //msg type - if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) { - gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type); + if(!gtpu_supported_msg_type_check(header,gtpu_log)){ return false; } From 2ff900d971b39201a7c75606b5b5feceadd9e3dd Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 16:02:00 +0100 Subject: [PATCH 06/10] Making sure that GTPU optional fields get written --- lib/src/upper/gtpu.cc | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 38a8cd572..25e6fea75 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -73,9 +73,30 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte uint16_to_uint8(header->length, ptr); ptr += 2; uint32_to_uint8(header->teid, ptr); - //write optional fields - - + //write optional fields, if E, S or PN are set. + if (header->flags & (GTPU_FLAGS_EXTENDED_HDR | GTPU_FLAGS_SEQUENCE | GTPU_FLAGS_PACKET_NUM)) { + //S + if (header->flags & GTPU_FLAGS_SEQUENCE ) { + uint16_to_uint8(header->seq_number, ptr); + } else { + uint16_to_uint8(0, ptr); + } + ptr+=2; + //PN + if (header->flags & GTPU_FLAGS_PACKET_NUM ) { + *ptr = header->n_pdu; + } else { + header=>n_pdu = 0; + } + ptr++; + //E + if (header->flags & GTPU_FLAGS_EXTENDED_HDR ) { + *ptr = header->next_ext_hdr_type; + } else { + *ptr = 0; + } + ptr++; + } return true; } From efffd3dec971be54e75c611b23c9c8a261d81d28 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 16:05:26 +0100 Subject: [PATCH 07/10] Fix compilation mistake. --- lib/src/upper/gtpu.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 25e6fea75..283270f0b 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -86,7 +86,7 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte if (header->flags & GTPU_FLAGS_PACKET_NUM ) { *ptr = header->n_pdu; } else { - header=>n_pdu = 0; + header->n_pdu = 0; } ptr++; //E From e925ef0a42324c1247f0ef01765c5e509ef9ab5d Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 17:34:02 +0100 Subject: [PATCH 08/10] Added some more debug infor to error prints. Making sure that packet is not sent from the eNB if there is an error in the GTP-U header packing. Fixed error in checking msg_type. --- lib/include/srslte/upper/gtpu.h | 16 ++++++++-------- lib/src/upper/gtpu.cc | 4 ++++ srsenb/hdr/upper/gtpu.h | 18 ------------------ srsenb/src/upper/gtpu.cc | 5 ++++- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 41e9dc2e9..df388ba02 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -89,19 +89,19 @@ inline bool gtpu_supported_flags_check(gtpu_header_t *header, srslte::log *gtpu_ { //flags if( (header->flags & GTPU_FLAGS_VERSION_MASK) != GTPU_FLAGS_VERSION_V1 ) { - gtpu_log->error("gtpu_write_header - Unhandled GTP-U Version.\n"); + gtpu_log->error("gtpu_header - Unhandled GTP-U Version. Flags: 0x%x\n", header->flags); return false; } if( !(header->flags & GTPU_FLAGS_GTP_PROTOCOL) ) { - gtpu_log->error("gtpu_write_header - Unhandled Protocol Type.\n"); + gtpu_log->error("gtpu_header - Unhandled Protocol Type. Flags: 0x%x\n\n", header->flags); return false; } - if( !(header->flags & GTPU_FLAGS_EXTENDED_HDR) ) { - gtpu_log->error("gtpu_write_header - Unhandled Header Extensions.\n"); + if( header->flags & GTPU_FLAGS_EXTENDED_HDR ) { + gtpu_log->error("gtpu_header - Unhandled Header Extensions. Flags: 0x%x\n\n", header->flags); return false; } - if( !(header->flags & GTPU_FLAGS_PACKET_NUM) ) { - gtpu_log->error("gtpu_write_header - Unhandled Packet Number.\n"); + if( header->flags & GTPU_FLAGS_PACKET_NUM ) { + gtpu_log->error("gtpu_header - Unhandled Packet Number. Flags: 0x%x\n\n", header->flags); return false; } return true; @@ -110,8 +110,8 @@ inline bool gtpu_supported_flags_check(gtpu_header_t *header, srslte::log *gtpu_ inline bool gtpu_supported_msg_type_check(gtpu_header_t *header, srslte::log *gtpu_log) { //msg_tpye - if(header->message_type != GTPU_MSG_DATA_PDU || header->message_type != GTPU_MSG_ECHO_REQUEST) { - gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type); + if( header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST ) { + gtpu_log->error("gtpu_header - Unhandled message type: 0x%x\n", header->message_type); return false; } return true; diff --git a/lib/src/upper/gtpu.cc b/lib/src/upper/gtpu.cc index 283270f0b..537b1043c 100644 --- a/lib/src/upper/gtpu.cc +++ b/lib/src/upper/gtpu.cc @@ -39,11 +39,13 @@ bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu, srslte { //flags if(!gtpu_supported_flags_check(header,gtpu_log)){ + gtpu_log->error("gtpu_write_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags); return false; } //msg type if(!gtpu_supported_msg_type_check(header,gtpu_log)){ + gtpu_log->error("gtpu_write_header - Unhandled GTP-U Message Type. Message Type: 0x%x\n", header->message_type); return false; } @@ -114,11 +116,13 @@ bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header, srslte: //flags if(!gtpu_supported_flags_check(header,gtpu_log)){ + gtpu_log->error("gtpu_read_header - Unhandled GTP-U Flags. Flags: 0x%x\n", header->flags); return false; } //message_type if(!gtpu_supported_msg_type_check(header,gtpu_log)){ + gtpu_log->error("gtpu_read_header - Unhandled GTP-U Message Type. Flags: 0x%x\n", header->message_type); return false; } diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index 519b831d9..3771ec402 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -40,24 +40,6 @@ namespace srsenb { -/**************************************************************************** - * GTPU Header - * Ref: 3GPP TS 29.281 v10.1.0 Section 5 - * - * | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | - * - * 1 | Version |PT | * | E | S |PN | - * 2 | Message Type | - * 3 | Length (1st Octet) | - * 4 | Length (2nd Octet) | - * 5 | TEID (1st Octet) | - * 6 | TEID (2nd Octet) | - * 7 | TEID (3rd Octet) | - * 8 | TEID (4th Octet) | - ***************************************************************************/ - -#define GTPU_HEADER_LEN 8 - class gtpu :public gtpu_interface_rrc ,public gtpu_interface_pdcp diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index acce49eb6..d6cc3fc89 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -132,7 +132,10 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu) servaddr.sin_addr.s_addr = htonl(rnti_bearers[rnti].spgw_addrs[lcid]); servaddr.sin_port = htons(GTPU_PORT); - gtpu_write_header(&header, pdu, gtpu_log); + if(!gtpu_write_header(&header, pdu, gtpu_log)){ + gtpu_log->error("Error writing GTP-U Header. Flags 0x%x, Message Type 0x%x\n", header.flags, header.message_type); + return; + } if (sendto(fd, pdu->msg, pdu->N_bytes, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in))<0) { perror("sendto"); } From a2befbd949118adb35ec3908282616ccf10324aa Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 18:07:30 +0100 Subject: [PATCH 09/10] Fix mistake in echo reply/response message type. --- lib/include/srslte/upper/gtpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index df388ba02..2756bc0ab 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -64,8 +64,8 @@ namespace srslte { #define GTPU_FLAGS_SEQUENCE 0x02 #define GTPU_FLAGS_PACKET_NUM 0x01 -#define GTPU_MSG_ECHO_REQUEST 0 -#define GTPU_MSG_ECHO_RESPONSE 1 +#define GTPU_MSG_ECHO_REQUEST 1 +#define GTPU_MSG_ECHO_RESPONSE 2 #define GTPU_MSG_ERROR_INDICATION 26 #define GTPU_MSG_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION 31 #define GTPU_MSG_END_MARKER 254 From 28f377128b1e9a1ca0fc2c4b107aae709d4975b5 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 1 Oct 2018 18:23:04 +0100 Subject: [PATCH 10/10] Making sure both Echo request and echo response are supported types. Echo response/request is working again. --- lib/include/srslte/upper/gtpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/include/srslte/upper/gtpu.h b/lib/include/srslte/upper/gtpu.h index 2756bc0ab..2230d76b7 100644 --- a/lib/include/srslte/upper/gtpu.h +++ b/lib/include/srslte/upper/gtpu.h @@ -110,7 +110,7 @@ inline bool gtpu_supported_flags_check(gtpu_header_t *header, srslte::log *gtpu_ inline bool gtpu_supported_msg_type_check(gtpu_header_t *header, srslte::log *gtpu_log) { //msg_tpye - if( header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST ) { + if( header->message_type != GTPU_MSG_DATA_PDU && header->message_type != GTPU_MSG_ECHO_REQUEST && header->message_type != GTPU_MSG_ECHO_RESPONSE) { gtpu_log->error("gtpu_header - Unhandled message type: 0x%x\n", header->message_type); return false; }