src/lte/model/epc-sgw-pgw-application.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 26 Sep 2014 15:51:00 -0700
changeset 10968 2d29fee2b7b8
parent 10967 597a9ec89e60
child 11169 5101180376fd
permissions -rw-r--r--
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
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
10967
597a9ec89e60 [Bug 1551] NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    31
namespace ns3 {
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    32
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10967
diff changeset
    33
NS_LOG_COMPONENT_DEFINE ("EpcSgwPgwApplication");
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    34
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    35
/////////////////////////
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    36
// UeInfo
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    37
/////////////////////////
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
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    40
EpcSgwPgwApplication::UeInfo::UeInfo ()
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    41
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    42
  NS_LOG_FUNCTION (this);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    43
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    44
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    45
void
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
    46
EpcSgwPgwApplication::UeInfo::AddBearer (Ptr<EpcTft> tft, uint8_t bearerId, uint32_t teid)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    47
{
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
    48
  NS_LOG_FUNCTION (this << tft << teid);
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
    49
  m_teidByBearerIdMap[bearerId] = teid;
8387
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
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    75
Ipv4Address 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    76
EpcSgwPgwApplication::UeInfo::GetUeAddr ()
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    77
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    78
  return m_ueAddr;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    79
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    80
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    81
void
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    82
EpcSgwPgwApplication::UeInfo::SetUeAddr (Ipv4Address ueAddr)
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    83
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    84
  m_ueAddr = ueAddr;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    85
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
    86
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    87
/////////////////////////
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    88
// EpcSgwPgwApplication
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    89
/////////////////////////
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    90
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    91
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    92
TypeId
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
    93
EpcSgwPgwApplication::GetTypeId (void)
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    94
{
8366
a3af0a5ed1e9 draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents: 8357
diff changeset
    95
  static TypeId tid = TypeId ("ns3::EpcSgwPgwApplication")
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    96
    .SetParent<Object> ();
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    97
  return tid;
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    98
}
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
    99
8568
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   100
void
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   101
EpcSgwPgwApplication::DoDispose ()
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   102
{
9609
13aed388469a Fix some memory leaks
Manuel Requena <manuel.requena@cttc.es>
parents: 9439
diff changeset
   103
  NS_LOG_FUNCTION (this);
8568
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   104
  m_s1uSocket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ());
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   105
  m_s1uSocket = 0;
9609
13aed388469a Fix some memory leaks
Manuel Requena <manuel.requena@cttc.es>
parents: 9439
diff changeset
   106
  delete (m_s11SapSgw);
8568
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   107
}
fc43230a29f5 fixed valgrind errors of epc-s1u tests
Nicola Baldo <nbaldo@cttc.es>
parents: 8463
diff changeset
   108
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   109
  
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   110
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   111
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
   112
  : m_s1uSocket (s1uSocket),
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   113
    m_tunDevice (tunDevice),
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   114
    m_gtpuUdpPort (2152), // fixed by the standard
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   115
    m_teidCount (0),
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   116
    m_s11SapMme (0)
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   117
{
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   118
  NS_LOG_FUNCTION (this << tunDevice << s1uSocket);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   119
  m_s1uSocket->SetRecvCallback (MakeCallback (&EpcSgwPgwApplication::RecvFromS1uSocket, this));
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   120
  m_s11SapSgw = new MemberEpcS11SapSgw<EpcSgwPgwApplication> (this);
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   121
}
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   122
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   123
  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   124
EpcSgwPgwApplication::~EpcSgwPgwApplication ()
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   125
{
9609
13aed388469a Fix some memory leaks
Manuel Requena <manuel.requena@cttc.es>
parents: 9439
diff changeset
   126
  NS_LOG_FUNCTION (this);
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   127
}
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   128
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   129
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   130
bool
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   131
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
   132
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   133
  NS_LOG_FUNCTION (this << source << dest << packet << packet->GetSize ());
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
  // get IP address of UE
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   136
  Ptr<Packet> pCopy = packet->Copy ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   137
  Ipv4Header ipv4Header;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   138
  pCopy->RemoveHeader (ipv4Header);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   139
  Ipv4Address ueAddr =  ipv4Header.GetDestination ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   140
  NS_LOG_LOGIC ("packet addressed to UE " << ueAddr);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   141
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   142
  // find corresponding UeInfo address
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   143
  std::map<Ipv4Address, Ptr<UeInfo> >::iterator it = m_ueInfoByAddrMap.find (ueAddr);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   144
  if (it == m_ueInfoByAddrMap.end ())
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   145
    {        
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   146
      NS_LOG_WARN ("unknown UE address " << ueAddr) ;
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   147
    }
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   148
  else
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   149
    {
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   150
      Ipv4Address enbAddr = it->second->GetEnbAddr ();      
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   151
      uint32_t teid = it->second->Classify (packet);   
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   152
      if (teid == 0)
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   153
        {
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   154
          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
   155
        }
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   156
      else
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
          SendToS1uSocket (packet, enbAddr, teid);
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
    }
8387
2c745ee2d92c revised TEID generation and TFT classification at SGW
Nicola Baldo <nbaldo@cttc.es>
parents: 8386
diff changeset
   161
  // 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
   162
  // 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
   163
  // 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
   164
  const bool succeeded = true;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   165
  return succeeded;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   166
}
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   167
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   168
void 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   169
EpcSgwPgwApplication::RecvFromS1uSocket (Ptr<Socket> socket)
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   170
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   171
  NS_LOG_FUNCTION (this << socket);  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   172
  NS_ASSERT (socket == m_s1uSocket);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   173
  Ptr<Packet> packet = socket->Recv ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   174
  GtpuHeader gtpu;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   175
  packet->RemoveHeader (gtpu);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   176
  uint32_t teid = gtpu.GetTeid ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   177
10157
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9609
diff changeset
   178
  /// \internal
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9609
diff changeset
   179
  /// Workaround for \bugid{231}
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   180
  SocketAddressTag tag;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   181
  packet->RemovePacketTag (tag);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   182
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   183
  SendToTunDevice (packet, teid);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   184
}
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
void 
8386
419cbd9e357f S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents: 8380
diff changeset
   187
EpcSgwPgwApplication::SendToTunDevice (Ptr<Packet> packet, uint32_t teid)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   188
{
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8366
diff changeset
   189
  NS_LOG_FUNCTION (this << packet << teid);
8583
7bf7b877aa98 log packet size in uplink EPC data flow
Nicola Baldo <nbaldo@cttc.es>
parents: 8568
diff changeset
   190
  NS_LOG_LOGIC (" packet size: " << packet->GetSize () << " bytes");
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
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   209
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   210
void 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   211
EpcSgwPgwApplication::SetS11SapMme (EpcS11SapMme * s)
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   212
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   213
  m_s11SapMme = s;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   214
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   215
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   216
EpcS11SapSgw* 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   217
EpcSgwPgwApplication::GetS11SapSgw ()
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   218
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   219
  return m_s11SapSgw;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   220
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   221
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   222
void 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   223
EpcSgwPgwApplication::AddEnb (uint16_t cellId, Ipv4Address enbAddr, Ipv4Address sgwAddr)
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   224
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   225
  NS_LOG_FUNCTION (this << cellId << enbAddr << sgwAddr);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   226
  EnbInfo enbInfo;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   227
  enbInfo.enbAddr = enbAddr;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   228
  enbInfo.sgwAddr = sgwAddr;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   229
  m_enbInfoByCellId[cellId] = enbInfo;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   230
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   231
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   232
void 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   233
EpcSgwPgwApplication::AddUe (uint64_t imsi)
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   234
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   235
  NS_LOG_FUNCTION (this << imsi);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   236
  Ptr<UeInfo> ueInfo = Create<UeInfo> ();
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   237
  m_ueInfoByImsiMap[imsi] = ueInfo;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   238
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   239
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   240
void 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   241
EpcSgwPgwApplication::SetUeAddress (uint64_t imsi, Ipv4Address ueAddr)
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   242
{
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   243
  NS_LOG_FUNCTION (this << imsi << ueAddr);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   244
  std::map<uint64_t, Ptr<UeInfo> >::iterator ueit = m_ueInfoByImsiMap.find (imsi);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   245
  NS_ASSERT_MSG (ueit != m_ueInfoByImsiMap.end (), "unknown IMSI " << imsi); 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   246
  m_ueInfoByAddrMap[ueAddr] = ueit->second;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   247
  ueit->second->SetUeAddr (ueAddr);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   248
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   249
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   250
void 
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   251
EpcSgwPgwApplication::DoCreateSessionRequest (EpcS11SapSgw::CreateSessionRequestMessage req)
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   252
{
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   253
  NS_LOG_FUNCTION (this << req.imsi);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   254
  std::map<uint64_t, Ptr<UeInfo> >::iterator ueit = m_ueInfoByImsiMap.find (req.imsi);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   255
  NS_ASSERT_MSG (ueit != m_ueInfoByImsiMap.end (), "unknown IMSI " << req.imsi); 
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   256
  uint16_t cellId = req.uli.gci;
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   257
  std::map<uint16_t, EnbInfo>::iterator enbit = m_enbInfoByCellId.find (cellId);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   258
  NS_ASSERT_MSG (enbit != m_enbInfoByCellId.end (), "unknown CellId " << cellId); 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   259
  Ipv4Address enbAddr = enbit->second.enbAddr;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   260
  ueit->second->SetEnbAddr (enbAddr);
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   261
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   262
  EpcS11SapMme::CreateSessionResponseMessage res;
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   263
  res.teid = req.imsi; // trick to avoid the need for allocating TEIDs on the S11 interface
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   264
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   265
  for (std::list<EpcS11SapSgw::BearerContextToBeCreated>::iterator bit = req.bearerContextsToBeCreated.begin ();
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   266
       bit != req.bearerContextsToBeCreated.end ();
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   267
       ++bit)
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   268
    {
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   269
      // simple sanity check. If you ever need more than 4M teids
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   270
      // throughout your simulation, you'll need to implement a smarter teid
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   271
      // management algorithm. 
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   272
      NS_ABORT_IF (m_teidCount == 0xFFFFFFFF);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   273
      uint32_t teid = ++m_teidCount;  
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   274
      ueit->second->AddBearer (bit->tft, bit->epsBearerId, teid);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   275
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   276
      EpcS11SapMme::BearerContextCreated bearerContext;
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   277
      bearerContext.sgwFteid.teid = teid;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   278
      bearerContext.sgwFteid.address = enbit->second.sgwAddr;
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   279
      bearerContext.epsBearerId =  bit->epsBearerId; 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   280
      bearerContext.bearerLevelQos = bit->bearerLevelQos; 
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   281
      bearerContext.tft = bit->tft;
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   282
      res.bearerContextsCreated.push_back (bearerContext);
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   283
    }
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   284
  m_s11SapMme->CreateSessionResponse (res);
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   285
  
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   286
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   287
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   288
void 
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   289
EpcSgwPgwApplication::DoModifyBearerRequest (EpcS11SapSgw::ModifyBearerRequestMessage req)
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   290
{
9439
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   291
  NS_LOG_FUNCTION (this << req.teid);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   292
  uint64_t imsi = req.teid; // trick to avoid the need for allocating TEIDs on the S11 interface
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   293
  std::map<uint64_t, Ptr<UeInfo> >::iterator ueit = m_ueInfoByImsiMap.find (imsi);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   294
  NS_ASSERT_MSG (ueit != m_ueInfoByImsiMap.end (), "unknown IMSI " << imsi); 
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   295
  uint16_t cellId = req.uli.gci;
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   296
  std::map<uint16_t, EnbInfo>::iterator enbit = m_enbInfoByCellId.find (cellId);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   297
  NS_ASSERT_MSG (enbit != m_enbInfoByCellId.end (), "unknown CellId " << cellId); 
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   298
  Ipv4Address enbAddr = enbit->second.enbAddr;
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   299
  ueit->second->SetEnbAddr (enbAddr);
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   300
  // no actual bearer modification: for now we just support the minimum needed for path switch request (handover)
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   301
  EpcS11SapMme::ModifyBearerResponseMessage res;
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   302
  res.teid = imsi; // trick to avoid the need for allocating TEIDs on the S11 interface
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   303
  res.cause = EpcS11SapMme::ModifyBearerResponseMessage::REQUEST_ACCEPTED;
5107601b7a75 added S1 path switch + S11 modify bearer for X2 handover
Nicola Baldo <nbaldo@cttc.es>
parents: 9430
diff changeset
   304
  m_s11SapMme->ModifyBearerResponse (res);
9430
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   305
}
e8b87593ee5b added MME with simulated S1AP and S11 interfaces
Nicola Baldo <nbaldo@cttc.es>
parents: 8583
diff changeset
   306
 
8357
7bb52f00c205 Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff changeset
   307
}; // namespace ns3