mirror of https://github.com/PentHertz/srsLTE.git
Added downlink IP tunnel. Downlink user plane packets reach the UE.
This commit is contained in:
parent
2b7bd546bc
commit
c838758db2
|
@ -0,0 +1,95 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2017 Software Radio Systems Limited
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsLTE library.
|
||||||
|
*
|
||||||
|
* srsUE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsUE is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Affero General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRSLTE_GTPU_H
|
||||||
|
#define SRSLTE_GTPU_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "srslte/common/common.h"
|
||||||
|
|
||||||
|
namespace srslte {
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* 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
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
uint8_t flags; // Only support 0x30 - v1, PT1 (GTP), no other flags
|
||||||
|
uint8_t message_type; // Only support 0xFF - T-PDU type
|
||||||
|
uint16_t length;
|
||||||
|
uint32_t teid;
|
||||||
|
}gtpu_header_t;
|
||||||
|
|
||||||
|
|
||||||
|
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header);
|
||||||
|
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
buf[0] = (i >> 24) & 0xFF;
|
||||||
|
buf[1] = (i >> 16) & 0xFF;
|
||||||
|
buf[2] = (i >> 8) & 0xFF;
|
||||||
|
buf[3] = i & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void uint8_to_uint16(uint8_t *buf, uint16_t *i)
|
||||||
|
{
|
||||||
|
*i = (uint32_t)buf[0] << 8 |
|
||||||
|
(uint32_t)buf[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void uint16_to_uint8(uint16_t i, uint8_t *buf)
|
||||||
|
{
|
||||||
|
buf[0] = (i >> 8) & 0xFF;
|
||||||
|
buf[1] = i & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,96 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* \section COPYRIGHT
|
||||||
|
*
|
||||||
|
* Copyright 2013-2017 Software Radio Systems Limited
|
||||||
|
*
|
||||||
|
* \section LICENSE
|
||||||
|
*
|
||||||
|
* This file is part of the srsLTE library.
|
||||||
|
*
|
||||||
|
* srsUE is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* srsUE is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* A copy of the GNU Affero General Public License can be found in
|
||||||
|
* the LICENSE file in the top-level directory of this distribution
|
||||||
|
* and at http://www.gnu.org/licenses/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "srslte/upper/gtpu.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace srslte {
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Header pack/unpack helper functions
|
||||||
|
* Ref: 3GPP TS 29.281 v10.1.0 Section 5
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
bool gtpu_write_header(gtpu_header_t *header, srslte::byte_buffer_t *pdu)
|
||||||
|
{
|
||||||
|
if(header->flags != 0x30) {
|
||||||
|
//gtpu_log->error("gtpu_write_header - Unhandled header flags: 0x%x\n", header->flags);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(header->message_type != 0xFF) {
|
||||||
|
//gtpu_log->error("gtpu_write_header - Unhandled message type: 0x%x\n", header->message_type);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(pdu->get_headroom() < GTPU_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;
|
||||||
|
|
||||||
|
uint8_t *ptr = pdu->msg;
|
||||||
|
|
||||||
|
*ptr = header->flags;
|
||||||
|
ptr++;
|
||||||
|
*ptr = header->message_type;
|
||||||
|
ptr++;
|
||||||
|
uint16_to_uint8(header->length, ptr);
|
||||||
|
ptr += 2;
|
||||||
|
uint32_to_uint8(header->teid, ptr);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gtpu_read_header(srslte::byte_buffer_t *pdu, gtpu_header_t *header)
|
||||||
|
{
|
||||||
|
uint8_t *ptr = pdu->msg;
|
||||||
|
|
||||||
|
pdu->msg += GTPU_HEADER_LEN;
|
||||||
|
pdu->N_bytes -= GTPU_HEADER_LEN;
|
||||||
|
|
||||||
|
header->flags = *ptr;
|
||||||
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(header->message_type != 0xFF) {
|
||||||
|
//gtpu_log->error("gtpu_read_header - Unhandled message type: 0x%x\n", header->message_type);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace srslte
|
|
@ -698,7 +698,7 @@ s1ap::handle_initial_context_setup_response(LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSE
|
||||||
m_s1ap_log->error("Could not find UE's context in active UE's map\n");
|
m_s1ap_log->error("Could not find UE's context in active UE's map\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(uint32_t i; i<in_ctxt_resp->E_RABSetupListCtxtSURes.len;i++)
|
for(uint32_t i=0; i<in_ctxt_resp->E_RABSetupListCtxtSURes.len;i++)
|
||||||
{
|
{
|
||||||
uint8_t erab_id = in_ctxt_resp->E_RABSetupListCtxtSURes.buffer[i].e_RAB_ID.E_RAB_ID;
|
uint8_t erab_id = in_ctxt_resp->E_RABSetupListCtxtSURes.buffer[i].e_RAB_ID.E_RAB_ID;
|
||||||
erab_ctx_t *erab_ctx = &ue_ctx_it->second->erabs_ctx[erab_id];
|
erab_ctx_t *erab_ctx = &ue_ctx_it->second->erabs_ctx[erab_id];
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include <linux/if_tun.h>
|
#include <linux/if_tun.h>
|
||||||
#include "spgw/spgw.h"
|
#include "spgw/spgw.h"
|
||||||
#include "mme/mme_gtpc.h"
|
#include "mme/mme_gtpc.h"
|
||||||
|
#include "srslte/upper/gtpu.h"
|
||||||
|
|
||||||
namespace srsepc{
|
namespace srsepc{
|
||||||
|
|
||||||
|
@ -328,11 +328,34 @@ spgw::handle_sgi_pdu(srslte::byte_buffer_t *msg)
|
||||||
m_spgw_log->console("IP Packet is not for any UE\n");
|
m_spgw_log->console("IP Packet is not for any UE\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct in_addr enb_addr;
|
struct sockaddr_in enb_addr;
|
||||||
enb_addr.s_addr = enb_fteid.ipv4;
|
enb_addr.sin_family = AF_INET;
|
||||||
m_spgw_log->console("UE F-TEID found, TEID 0x%x, eNB IP %s\n", enb_fteid.teid, inet_ntoa(enb_addr));
|
enb_addr.sin_port = htons(GTPU_RX_PORT);
|
||||||
|
enb_addr.sin_addr.s_addr = enb_fteid.ipv4;
|
||||||
|
m_spgw_log->console("UE F-TEID found, TEID 0x%x, eNB IP %s\n", enb_fteid.teid, inet_ntoa(enb_addr.sin_addr));
|
||||||
|
|
||||||
|
//Setup GTP-U header
|
||||||
|
srslte::gtpu_header_t header;
|
||||||
|
header.flags = 0x30;
|
||||||
|
header.message_type = 0xFF;
|
||||||
|
header.length = msg->N_bytes;
|
||||||
|
header.teid = enb_fteid.teid;
|
||||||
|
|
||||||
|
//Write header into packet
|
||||||
|
if(!srslte::gtpu_write_header(&header, msg))
|
||||||
|
{
|
||||||
|
m_spgw_log->console("Error writing GTP-U header on PDU\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Send packet to destination
|
||||||
|
int n = sendto(m_s1u,msg->msg,msg->N_bytes,0,(struct sockaddr*) &enb_addr,sizeof(enb_addr));
|
||||||
|
if(n<0)
|
||||||
|
{
|
||||||
|
m_spgw_log->console("Error sending packet to eNB\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_spgw_log->console("Sent packet to %s:%d. Bytes=%d\n",inet_ntoa(enb_addr.sin_addr), GTPU_RX_PORT,n);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue