src/lte/model/epc-sgw-pgw-application.cc
author Nicola Baldo <nbaldo@cttc.es>
Mon, 05 Dec 2011 21:27:44 +0100
changeset 8463 cc818aa536a5
parent 8387 2c745ee2d92c
child 8568 fc43230a29f5
permissions -rw-r--r--
renamed LteTft --> EpcTft
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     2
/*
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     3
 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     4
 *
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     7
 * published by the Free Software Foundation;
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     8
 *
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    12
 * GNU General Public License for more details.
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    13
 *
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    17
 *
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    18
 * Author: Jaume Nin <jnin@cttc.cat>
8366
a3af0a5ed1e9 draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents: 8357
diff changeset
    19
 *         Nicola Baldo <nbaldo@cttc.cat>
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    20
 */
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    21
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    22
8366
a3af0a5ed1e9 draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents: 8357
diff changeset
    23
#include "epc-sgw-pgw-application.h"
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    24
#include "ns3/log.h"
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    25
#include "ns3/mac48-address.h"
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    26
#include "ns3/ipv4.h"
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    27
#include "ns3/inet-socket-address.h"
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    28
#include "ns3/epc-gtpu-header.h"
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    29
#include "ns3/abort.h"
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    30
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    31
namespace ns3 {
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    32
8366
a3af0a5ed1e9 draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents: 8357
diff changeset
    33
NS_LOG_COMPONENT_DEFINE ("EpcSgwPgwApplication");
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    34
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    35
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    36
/////////////////////////
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    37
// UeInfo
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    38
/////////////////////////
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    39
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    40
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    41
EpcSgwPgwApplication::UeInfo::UeInfo ()
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    42
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    43
  NS_LOG_FUNCTION (this);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    44
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    45
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    46
void
8463
cc818aa536a5 renamed LteTft --> EpcTft
Nicola Baldo <nbaldo@cttc.es>
parents: 8387
diff changeset
    47
EpcSgwPgwApplication::UeInfo::AddBearer (Ptr<EpcTft> tft, uint32_t teid)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    48
{
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    49
  NS_LOG_FUNCTION (this << tft << teid);
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    50
  return m_tftClassifier.Add (tft, teid);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    51
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    52
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    53
uint32_t
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    54
EpcSgwPgwApplication::UeInfo::Classify (Ptr<Packet> p)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    55
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    56
  NS_LOG_FUNCTION (this << p);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    57
  // we hardcode DOWNLINK direction since the PGW is espected to
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    58
  // classify only downlink packets (uplink packets will go to the
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    59
  // internet without any classification). 
8463
cc818aa536a5 renamed LteTft --> EpcTft
Nicola Baldo <nbaldo@cttc.es>
parents: 8387
diff changeset
    60
  return m_tftClassifier.Classify (p, EpcTft::DOWNLINK);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    61
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    62
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    63
Ipv4Address 
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    64
EpcSgwPgwApplication::UeInfo::GetEnbAddr ()
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    65
{
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    66
  return m_enbAddr;
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    67
}
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    68
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    69
void
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    70
EpcSgwPgwApplication::UeInfo::SetEnbAddr (Ipv4Address enbAddr)
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    71
{
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    72
  m_enbAddr = enbAddr;
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    73
}
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    74
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    75
/////////////////////////
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    76
// EpcSgwPgwApplication
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    77
/////////////////////////
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    78
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    79
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    80
TypeId
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    81
EpcSgwPgwApplication::GetTypeId (void)
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    82
{
8366
a3af0a5ed1e9 draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents: 8357
diff changeset
    83
  static TypeId tid = TypeId ("ns3::EpcSgwPgwApplication")
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    84
    .SetParent<Object> ();
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    85
  return tid;
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    86
}
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    87
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    88
  
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    89
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
    90
EpcSgwPgwApplication::EpcSgwPgwApplication (const Ptr<VirtualNetDevice> tunDevice, const Ptr<Socket> s1uSocket)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    91
  : m_s1uSocket (s1uSocket),
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
    92
    m_tunDevice (tunDevice),
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    93
    m_gtpuUdpPort (2152), // fixed by the standard
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    94
    m_teidCount (0)
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    95
{
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
    96
  NS_LOG_FUNCTION (this << tunDevice << s1uSocket);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    97
  m_s1uSocket->SetRecvCallback (MakeCallback (&EpcSgwPgwApplication::RecvFromS1uSocket, this));
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    98
}
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    99
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   100
  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   101
EpcSgwPgwApplication::~EpcSgwPgwApplication ()
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   102
{
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   103
  NS_LOG_FUNCTION_NOARGS ();
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   104
}
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   105
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   106
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   107
uint32_t 
8463
cc818aa536a5 renamed LteTft --> EpcTft
Nicola Baldo <nbaldo@cttc.es>
parents: 8387
diff changeset
   108
EpcSgwPgwApplication::ActivateS1Bearer (Ipv4Address ueAddr, Ipv4Address enbAddr, Ptr<EpcTft> tft)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   109
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   110
  NS_LOG_FUNCTION (this << ueAddr << enbAddr << tft);
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   111
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   112
  // simple sanity check. If you ever need more than 4M teids
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   113
  // throughout your simulation, you'll need to implement a smarter teid
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   114
  // management algorithm. 
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   115
  NS_ABORT_IF (m_teidCount == 0xFFFFFFFF);
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   116
  uint32_t teid = ++m_teidCount;  
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   117
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   118
  std::map<Ipv4Address, UeInfo>::iterator it = m_ueInfoMap.find (ueAddr);
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   119
  if (it == m_ueInfoMap.end ())
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   120
    {
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   121
      // UE unknown, creating new entry
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   122
      std::pair<std::map<Ipv4Address, UeInfo>::iterator, bool> ret;
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   123
      ret = m_ueInfoMap.insert (std::pair <Ipv4Address, UeInfo> (ueAddr, UeInfo ()));
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   124
      it = ret.first;
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   125
      it->second.SetEnbAddr (enbAddr);
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   126
    }
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   127
        
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   128
  it->second.AddBearer (tft, teid);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   129
  return teid;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   130
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   131
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   132
bool
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   133
EpcSgwPgwApplication::RecvFromTunDevice (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   134
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   135
  NS_LOG_FUNCTION (this << source << dest << packet << packet->GetSize ());
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   136
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   137
  // get IP address of UE
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   138
  Ptr<Packet> pCopy = packet->Copy ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   139
  Ipv4Header ipv4Header;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   140
  pCopy->RemoveHeader (ipv4Header);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   141
  Ipv4Address ueAddr =  ipv4Header.GetDestination ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   142
  NS_LOG_LOGIC ("packet addressed to UE " << ueAddr);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   143
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   144
  // find corresponding UeInfo address
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   145
  std::map<Ipv4Address, UeInfo>::iterator it = m_ueInfoMap.find (ueAddr);
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   146
  if (it == m_ueInfoMap.end ())
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   147
    {        
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   148
      NS_LOG_WARN ("unknown UE address " << ueAddr) ;
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   149
    }
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   150
  else
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   151
    {
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   152
      Ipv4Address enbAddr = it->second.GetEnbAddr ();      
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   153
      uint32_t teid = it->second.Classify (packet);   
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   154
      if (teid == 0)
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   155
        {
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   156
          NS_LOG_WARN ("no matching bearer for this packet");                   
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   157
        }
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   158
      else
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   159
        {
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   160
          SendToS1uSocket (packet, enbAddr, teid);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   161
        }
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   162
    }
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   163
  // there is no reason why we should notify the TUN
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   164
  // VirtualNetDevice that he failed to send the packet: if we receive
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   165
  // any bogus packet, it will just be silently discarded.
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   166
  const bool succeeded = true;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   167
  return succeeded;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   168
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   169
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   170
void 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   171
EpcSgwPgwApplication::RecvFromS1uSocket (Ptr<Socket> socket)
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   172
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   173
  NS_LOG_FUNCTION (this << socket);  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   174
  NS_ASSERT (socket == m_s1uSocket);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   175
  Ptr<Packet> packet = socket->Recv ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   176
  GtpuHeader gtpu;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   177
  packet->RemoveHeader (gtpu);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   178
  uint32_t teid = gtpu.GetTeid ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   179
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   180
  // workaround for bug 231 https://www.nsnam.org/bugzilla/show_bug.cgi?id=231
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   181
  SocketAddressTag tag;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   182
  packet->RemovePacketTag (tag);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   183
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   184
  SendToTunDevice (packet, teid);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   185
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   186
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   187
void 
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   188
EpcSgwPgwApplication::SendToTunDevice (Ptr<Packet> packet, uint32_t teid)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   189
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   190
  NS_LOG_FUNCTION (this << packet << teid);
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   191
  m_tunDevice->Receive (packet, 0x0800, m_tunDevice->GetAddress (), m_tunDevice->GetAddress (), NetDevice::PACKET_HOST);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   192
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   193
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   194
void 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   195
EpcSgwPgwApplication::SendToS1uSocket (Ptr<Packet> packet, Ipv4Address enbAddr, uint32_t teid)
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   196
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   197
  NS_LOG_FUNCTION (this << packet << enbAddr << teid);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   198
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   199
  GtpuHeader gtpu;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   200
  gtpu.SetTeid (teid);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   201
  // From 3GPP TS 29.281 v10.0.0 Section 5.1
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   202
  // Length of the payload + the non obligatory GTP-U header
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   203
  gtpu.SetLength (packet->GetSize () + gtpu.GetSerializedSize () - 8);  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   204
  packet->AddHeader (gtpu);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   205
  uint32_t flags = 0;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   206
  m_s1uSocket->SendTo (packet, flags, InetSocketAddress(enbAddr, m_gtpuUdpPort));
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   207
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   208
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   209
}; // namespace ns3