A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
epc-enb-application.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Jaume Nin <jnin@cttc.cat>
19  * Nicola Baldo <nbaldo@cttc.cat>
20  */
21 
22 
23 #include "epc-enb-application.h"
24 #include "ns3/log.h"
25 #include "ns3/mac48-address.h"
26 #include "ns3/ipv4.h"
27 #include "ns3/inet-socket-address.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/epc-gtpu-header.h"
30 #include "ns3/lte-radio-bearer-tag.h"
31 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("EpcEnbApplication");
35 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::EpcEnbApplication")
41  .SetParent<Object> ();
42  return tid;
43 }
44 
46  : m_lteSocket (lteSocket),
47  m_s1uSocket (s1uSocket),
48  m_sgwAddress (sgwAddress),
49  m_gtpuUdpPort (2152) // fixed by the standard
50 {
51  NS_LOG_FUNCTION (this << lteSocket << s1uSocket << sgwAddress);
54 }
55 
56 
58 {
59  NS_LOG_FUNCTION (this);
60 }
61 
62 void
63 EpcEnbApplication::ErabSetupRequest (uint32_t teid, uint16_t rnti, uint8_t lcid)
64 {
65  NS_LOG_FUNCTION (this << teid << rnti << (uint16_t) lcid);
66  LteFlowId_t rbid (rnti, lcid);
67  // side effect: create entries if not exist
68  m_rbidTeidMap[rbid] = teid;
69  m_teidRbidMap[teid] = rbid;
70 }
71 
72 void
74 {
75  NS_LOG_FUNCTION (this);
76  NS_ASSERT (socket == m_lteSocket);
77  Ptr<Packet> packet = socket->Recv ();
78 
79  // workaround for bug 231 https://www.nsnam.org/bugzilla/show_bug.cgi?id=231
80  SocketAddressTag satag;
81  packet->RemovePacketTag (satag);
82 
84  bool found = packet->RemovePacketTag (tag);
85  NS_ASSERT (found);
86  LteFlowId_t flowId;
87  flowId.m_rnti = tag.GetRnti ();
88  flowId.m_lcId = tag.GetLcid ();
89  NS_LOG_LOGIC ("received packet with RNTI=" << flowId.m_rnti << ", LCID=" << (uint16_t) flowId.m_lcId);
90  std::map<LteFlowId_t, uint32_t>::iterator it = m_rbidTeidMap.find (flowId);
91  NS_ASSERT (it != m_rbidTeidMap.end ());
92  uint32_t teid = it->second;
93  SendToS1uSocket (packet, teid);
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION (this << socket);
100  NS_ASSERT (socket == m_s1uSocket);
101  Ptr<Packet> packet = socket->Recv ();
102  GtpuHeader gtpu;
103  packet->RemoveHeader (gtpu);
104  uint32_t teid = gtpu.GetTeid ();
105  std::map<uint32_t, LteFlowId_t>::iterator it = m_teidRbidMap.find (teid);
106  NS_ASSERT (it != m_teidRbidMap.end ());
107 
108  // workaround for bug 231 https://www.nsnam.org/bugzilla/show_bug.cgi?id=231
109  SocketAddressTag tag;
110  packet->RemovePacketTag (tag);
111 
112  SendToLteSocket (packet, it->second.m_rnti, it->second.m_lcId);
113 }
114 
115 void
116 EpcEnbApplication::SendToLteSocket (Ptr<Packet> packet, uint16_t rnti, uint8_t lcid)
117 {
118  NS_LOG_FUNCTION (this << packet << rnti << (uint16_t) lcid);
119  LteRadioBearerTag tag (rnti, lcid);
120  packet->AddPacketTag (tag);
121  int sentBytes = m_lteSocket->Send (packet);
122  NS_ASSERT (sentBytes > 0);
123 }
124 
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << packet << teid);
130  GtpuHeader gtpu;
131  gtpu.SetTeid (teid);
132  // From 3GPP TS 29.281 v10.0.0 Section 5.1
133  // Length of the payload + the non obligatory GTP-U header
134  gtpu.SetLength (packet->GetSize () + gtpu.GetSerializedSize () - 8);
135  packet->AddHeader (gtpu);
136  uint32_t flags = 0;
138 }
139 
140 
141 }; // namespace ns3