src/lte/helper/epc-helper.cc
author Nicola Baldo <nbaldo@cttc.es>
Wed, 19 Oct 2011 19:01:50 +0200
changeset 8380 f615b30c26e1
parent 8378 0d8107d1548b
child 8385 1c778218d880
permissions -rw-r--r--
S1-U working in downlink
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     2
/*
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     3
 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     4
 *
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     8
 *
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    13
 *
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    17
 *
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    18
 * Author: Jaume Nin <jnin@cttc.es>
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    19
 *         Nicola Baldo <nbaldo@cttc.es>
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    20
 */
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    21
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    22
#include <ns3/epc-helper.h>
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    23
#include <ns3/log.h>
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    24
#include <ns3/inet-socket-address.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    25
#include <ns3/mac48-address.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    26
#include <ns3/epc-gtpu-tunnel-endpoint.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    27
#include <ns3/eps-bearer.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    28
#include <ns3/ipv4-address.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    29
#include <ns3/internet-stack-helper.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    30
#include <ns3/point-to-point-helper.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    31
#include <ns3/packet-socket-helper.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    32
#include <ns3/packet-socket-address.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    33
#include <ns3/epc-enb-application.h>
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    34
#include <ns3/epc-sgw-pgw-application.h>
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    35
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    36
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    37
namespace ns3 {
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    38
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    39
NS_LOG_COMPONENT_DEFINE ("EpcHelper");
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    40
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    41
NS_OBJECT_ENSURE_REGISTERED (EpcHelper);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    42
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    43
EpcHelper::EpcHelper () 
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    44
  : m_gtpuUdpPort (2152) // fixed by the standard
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    45
{
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    46
  NS_LOG_FUNCTION (this);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    47
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    48
  // since we use point-to-point links for all S1-U links, 
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    49
  // we use a /30 subnet which can hold exactly two addresses 
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    50
  // (remember that net broadcast and null address are not valid)
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    51
  m_s1uIpv4AddressHelper.SetBase ("10.0.0.0", "255.255.255.252");
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    52
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    53
  // we use a /8 net for all UEs
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    54
  m_ueAddressHelper.SetBase ("7.0.0.0", "255.0.0.0");
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    55
  
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    56
  // create SgwPgwNode
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    57
  m_sgwPgw = CreateObject<Node> ();
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    58
  InternetStackHelper internet;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    59
  internet.Install (m_sgwPgw);
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    60
  
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    61
  // create S1-U socket
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    62
  Ptr<Socket> sgwPgwS1uSocket = Socket::CreateSocket (m_sgwPgw, TypeId::LookupByName ("ns3::UdpSocketFactory"));
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    63
  int retval = sgwPgwS1uSocket->Bind (InetSocketAddress (Ipv4Address::GetAny (), m_gtpuUdpPort));
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    64
  NS_ASSERT (retval == 0);
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    65
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    66
  // create TUN device implementing tunneling of user data over GTP-U/UDP/IP 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    67
  Ptr<VirtualNetDevice> giTunDevice = CreateObject<VirtualNetDevice> ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    68
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    69
  // yes we need this
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    70
  giTunDevice->SetAddress (Mac48Address::Allocate ()); 
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    71
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    72
  m_sgwPgw->AddDevice (giTunDevice);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    73
  NetDeviceContainer giTunDeviceContainer;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    74
  giTunDeviceContainer.Add (giTunDevice);
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    75
  
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    76
  // the TUN device is on the same subnet as the UEs, so when a packet
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    77
  // addressed to an UE arrives at the intenet to the WAN interface of
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    78
  // the PGW it will be forwarded to the TUN device. 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    79
  Ipv4InterfaceContainer giTunDeviceIpv4IfContainer = m_ueAddressHelper.Assign (giTunDeviceContainer);  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    80
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    81
  // create EpcSgwPgwApplication
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    82
  m_sgwPgwApp = CreateObject<EpcSgwPgwApplication> (giTunDevice, sgwPgwS1uSocket);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    83
  m_sgwPgw->AddApplication (m_sgwPgwApp);
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    84
  
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    85
  // connect SgwPgwApplication and virtual net device for tunneling
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
    86
  giTunDevice->SetSendCallback (MakeCallback (&EpcSgwPgwApplication::RecvFromGiTunDevice, m_sgwPgwApp));
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    87
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    88
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    89
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    90
EpcHelper::~EpcHelper ()
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    91
{
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    92
  NS_LOG_FUNCTION (this);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    93
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    94
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    95
TypeId
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    96
EpcHelper::GetTypeId (void)
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    97
{
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    98
  static TypeId tid = TypeId ("ns3::EpcHelper")
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
    99
    .SetParent<Object> ()
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   100
    .AddConstructor<EpcHelper> ()
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   101
    .AddAttribute ("S1uLinkDataRate", 
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   102
                   "The data rate to be used for the next S1-U link to be created",
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   103
                   DataRateValue (DataRate ("10Gb/s")),
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   104
                   MakeDataRateAccessor (&EpcHelper::m_s1uLinkDataRate),
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   105
                   MakeDataRateChecker ())
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   106
    .AddAttribute ("S1uLinkDelay", 
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   107
                   "The delay to be used for the next S1-U link to be created",
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   108
                   TimeValue (Seconds (0)),
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   109
                   MakeTimeAccessor (&EpcHelper::m_s1uLinkDelay),
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   110
                   MakeTimeChecker ())
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   111
  ;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   112
  return tid;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   113
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   114
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   115
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   116
void
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   117
EpcHelper::AddEnb (Ptr<Node> enb, Ptr<NetDevice> lteEnbNetDevice)
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   118
{
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   119
  NS_LOG_FUNCTION (this << enb << lteEnbNetDevice);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   120
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   121
  NS_ASSERT (enb == lteEnbNetDevice->GetNode ());
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   122
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   123
  // add an IPv4 stack to the previously created eNB
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   124
  InternetStackHelper internet;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   125
  internet.Install (enb);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   126
  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after node creation: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   127
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   128
  // create a point to point link between the new eNB and the SGW with
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   129
  // the corresponding new NetDevices on each side  
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   130
  NodeContainer enbSgwNodes;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   131
  enbSgwNodes.Add (m_sgwPgw);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   132
  enbSgwNodes.Add (enb);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   133
  PointToPointHelper p2ph;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   134
  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (m_s1uLinkDataRate));
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   135
  p2ph.SetChannelAttribute ("Delay", TimeValue (m_s1uLinkDelay));  
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   136
  NetDeviceContainer enbSgwDevices = p2ph.Install (enb, m_sgwPgw);
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   137
  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after installing p2p dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   138
  Ptr<NetDevice> enbDev = enbSgwDevices.Get (0);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   139
  Ptr<NetDevice> sgwDev = enbSgwDevices.Get (1);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   140
  m_s1uIpv4AddressHelper.NewNetwork ();
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   141
  Ipv4InterfaceContainer enbSgwIpIfaces = m_s1uIpv4AddressHelper.Assign (enbSgwDevices);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   142
  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after assigning Ipv4 addr to S1 dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   143
  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   144
  Ipv4Address enbAddress = enbSgwIpIfaces.GetAddress (0);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   145
  Ipv4Address sgwAddress = enbSgwIpIfaces.GetAddress (1);
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   146
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   147
  // create S1-U socket for the ENB
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   148
  Ptr<Socket> enbS1uSocket = Socket::CreateSocket (enb, TypeId::LookupByName ("ns3::UdpSocketFactory"));
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   149
  int retval = enbS1uSocket->Bind (InetSocketAddress (enbAddress, m_gtpuUdpPort));
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   150
  NS_ASSERT (retval == 0);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   151
  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   152
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   153
  // give PacketSocket powers to the eNB
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   154
  //PacketSocketHelper packetSocket;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   155
  //packetSocket.Install (enb); 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   156
  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   157
  // create LTE socket for the ENB 
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   158
  Ptr<Socket> enbLteSocket = Socket::CreateSocket (enb, TypeId::LookupByName ("ns3::PacketSocketFactory"));
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   159
  PacketSocketAddress enbLteSocketBindAddress;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   160
  enbLteSocketBindAddress.SetSingleDevice (lteEnbNetDevice->GetIfIndex ());
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   161
  retval = enbLteSocket->Bind (enbLteSocketBindAddress);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   162
  NS_ASSERT (retval == 0);  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   163
  PacketSocketAddress enbLteSocketConnectAddress;
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   164
  enbLteSocketConnectAddress.SetPhysicalAddress (Mac48Address::GetBroadcast ());
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   165
  enbLteSocketConnectAddress.SetProtocol (Ipv4L3Protocol::PROT_NUMBER);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   166
  retval = enbLteSocket->Connect (enbLteSocketConnectAddress);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   167
  NS_ASSERT (retval == 0);  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   168
  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   169
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   170
  NS_LOG_INFO ("create EpcEnbApplication");
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   171
  Ptr<EpcEnbApplication> enbApp = CreateObject<EpcEnbApplication> (enbLteSocket, enbS1uSocket, sgwAddress);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   172
  enb->AddApplication (enbApp);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   173
  NS_ASSERT (enb->GetNApplications () == 1);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   174
  NS_ASSERT_MSG (enb->GetApplication (0)->GetObject<EpcEnbApplication> () != 0, "cannot retrieve EpcEnbApplication");
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   175
  NS_LOG_LOGIC ("enb: " << enb << ", enb->GetApplication (0): " << enb->GetApplication (0));
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   176
  
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   177
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   178
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   179
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   180
void
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   181
EpcHelper::ActivateEpsBearer (Ptr<NetDevice> ueLteDevice, Ptr<NetDevice> enbLteDevice, Ptr<LteTft> tft, uint16_t rnti, uint8_t lcid)
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   182
{
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   183
  Ptr<Node> ueNode = ueLteDevice->GetNode (); 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   184
  Ptr<Ipv4> ueIpv4 = ueNode->GetObject<Ipv4> ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   185
  int32_t interface =  ueIpv4->GetInterfaceForDevice (ueLteDevice);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   186
  NS_ASSERT (interface >= 0);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   187
  NS_ASSERT (ueIpv4->GetNAddresses (interface) == 1);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   188
  Ipv4Address ueAddr = ueIpv4->GetAddress (interface, 0).GetLocal ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   189
  NS_LOG_LOGIC (" UE IP address: " << ueAddr);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   190
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   191
  // NOTE: unlike ueLteDevice, enbLteDevice is NOT an Ipv4 enabled
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   192
  // device. In fact we are interested in the S1 device of the eNB.
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   193
  // We find it by relying on the assumption that the S1 device is the
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   194
  // only Ipv4 enabled device of the eNB besides the localhost interface.
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   195
  Ptr<Node> enbNode = enbLteDevice->GetNode (); 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   196
  NS_ASSERT (enbNode != 0);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   197
  Ptr<Ipv4> enbIpv4 = enbNode->GetObject<Ipv4> ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   198
  NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB: " << enbIpv4->GetNInterfaces ());
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   199
  // two ifaces total: loopback + the S1-U interface
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   200
  NS_ASSERT (enbIpv4->GetNInterfaces () == 2); 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   201
  NS_ASSERT (ueIpv4->GetNAddresses (1) == 1);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   202
  // iface index 0 is loopback, index 1 is the S1-U interface
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   203
  Ipv4Address enbAddr = enbIpv4->GetAddress (1, 0).GetLocal (); 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   204
  NS_LOG_LOGIC (" ENB IP address: " << enbAddr);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   205
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   206
  // setup S1 bearer at EpcSgwPgwApplication
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   207
  uint32_t teid = m_sgwPgwApp->ActivateS1Bearer (ueAddr, enbAddr, tft);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   208
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   209
  // setup S1 bearer at EpcEnbApplication
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   210
  NS_LOG_LOGIC ("enb: " << enbNode << ", enb->GetApplication (0): " << enbNode->GetApplication (0));
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   211
  NS_ASSERT (enbNode->GetNApplications () == 1);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   212
  Ptr<Application> app =  enbNode->GetApplication (0);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   213
  NS_ASSERT (app != 0);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   214
  Ptr<EpcEnbApplication> epcEnbApp = app->GetObject<EpcEnbApplication> ();
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   215
  NS_ASSERT (epcEnbApp != 0);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   216
  epcEnbApp->ErabSetupRequest (teid, rnti, lcid);
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   217
  
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   218
  
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   219
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   220
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   221
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   222
Ptr<Node>
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   223
EpcHelper::GetPgwNode ()
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   224
{
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   225
  return m_sgwPgw;
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   226
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   227
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   228
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   229
Ipv4InterfaceContainer 
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   230
EpcHelper::AssignUeIpv4Address (NetDeviceContainer ueDevices)
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   231
{
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   232
  return m_ueAddressHelper.Assign (ueDevices);
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   233
}
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   234
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   235
8380
f615b30c26e1 S1-U working in downlink
Nicola Baldo <nbaldo@cttc.es>
parents: 8378
diff changeset
   236
8378
0d8107d1548b save changes before merge
Nicola Baldo <nbaldo@cttc.es>
parents:
diff changeset
   237
} // namespace ns3