A Discrete-Event Network Simulator
API
epc-mme.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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/fatal-error.h>
22 #include <ns3/log.h>
23 
24 #include "epc-s1ap-sap.h"
25 #include "epc-s11-sap.h"
26 
27 #include "epc-mme.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("EpcMme");
32 
34 
36  : m_s11SapSgw (0)
37 {
38  NS_LOG_FUNCTION (this);
41 }
42 
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
49 void
51 {
52  NS_LOG_FUNCTION (this);
53  delete m_s1apSapMme;
54  delete m_s11SapMme;
55 }
56 
57 TypeId
59 {
60  static TypeId tid = TypeId ("ns3::EpcMme")
61  .SetParent<Object> ()
62  .SetGroupName("Lte")
63  .AddConstructor<EpcMme> ()
64  ;
65  return tid;
66 }
67 
70 {
71  return m_s1apSapMme;
72 }
73 
74 void
76 {
77  m_s11SapSgw = s;
78 }
79 
82 {
83  return m_s11SapMme;
84 }
85 
86 void
87 EpcMme::AddEnb (uint16_t gci, Ipv4Address enbS1uAddr, EpcS1apSapEnb* enbS1apSap)
88 {
89  NS_LOG_FUNCTION (this << gci << enbS1uAddr);
90  Ptr<EnbInfo> enbInfo = Create<EnbInfo> ();
91  enbInfo->gci = gci;
92  enbInfo->s1uAddr = enbS1uAddr;
93  enbInfo->s1apSapEnb = enbS1apSap;
94  m_enbInfoMap[gci] = enbInfo;
95 }
96 
97 void
98 EpcMme::AddUe (uint64_t imsi)
99 {
100  NS_LOG_FUNCTION (this << imsi);
101  Ptr<UeInfo> ueInfo = Create<UeInfo> ();
102  ueInfo->imsi = imsi;
103  ueInfo->mmeUeS1Id = imsi;
104  m_ueInfoMap[imsi] = ueInfo;
105  ueInfo->bearerCounter = 0;
106 }
107 
108 uint8_t
109 EpcMme::AddBearer (uint64_t imsi, Ptr<EpcTft> tft, EpsBearer bearer)
110 {
111  NS_LOG_FUNCTION (this << imsi);
112  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
113  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
114  NS_ASSERT_MSG (it->second->bearerCounter < 11, "too many bearers already! " << it->second->bearerCounter);
115  BearerInfo bearerInfo;
116  bearerInfo.bearerId = ++(it->second->bearerCounter);
117  bearerInfo.tft = tft;
118  bearerInfo.bearer = bearer;
119  it->second->bearersToBeActivated.push_back (bearerInfo);
120  return bearerInfo.bearerId;
121 }
122 
123 
124 // S1-AP SAP MME forwarded methods
125 
126 void
127 EpcMme::DoInitialUeMessage (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, uint64_t imsi, uint16_t gci)
128 {
129  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << imsi << gci);
130  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
131  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
132  it->second->cellId = gci;
134  msg.imsi = imsi;
135  msg. uli.gci = gci;
136  for (std::list<BearerInfo>::iterator bit = it->second->bearersToBeActivated.begin ();
137  bit != it->second->bearersToBeActivated.end ();
138  ++bit)
139  {
141  bearerContext.epsBearerId = bit->bearerId;
142  bearerContext.bearerLevelQos = bit->bearer;
143  bearerContext.tft = bit->tft;
144  msg.bearerContextsToBeCreated.push_back (bearerContext);
145  }
147 }
148 
149 void
150 EpcMme::DoInitialContextSetupResponse (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabSetupItem> erabSetupList)
151 {
152  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
153  NS_FATAL_ERROR ("unimplemented");
154 }
155 
156 void
157 EpcMme::DoPathSwitchRequest (uint64_t enbUeS1Id, uint64_t mmeUeS1Id, uint16_t gci, std::list<EpcS1apSapMme::ErabSwitchedInDownlinkItem> erabToBeSwitchedInDownlinkList)
158 {
159  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << gci);
160 
161  uint64_t imsi = mmeUeS1Id;
162  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
163  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
164  NS_LOG_INFO ("IMSI " << imsi << " old eNB: " << it->second->cellId << ", new eNB: " << gci);
165  it->second->cellId = gci;
166  it->second->enbUeS1Id = enbUeS1Id;
167 
169  msg.teid = imsi; // trick to avoid the need for allocating TEIDs on the S11 interface
170  msg.uli.gci = gci;
171  // bearer modification is not supported for now
173 }
174 
175 
176 // S11 SAP MME forwarded methods
177 
178 void
180 {
181  NS_LOG_FUNCTION (this << msg.teid);
182  uint64_t imsi = msg.teid;
183  std::list<EpcS1apSapEnb::ErabToBeSetupItem> erabToBeSetupList;
184  for (std::list<EpcS11SapMme::BearerContextCreated>::iterator bit = msg.bearerContextsCreated.begin ();
185  bit != msg.bearerContextsCreated.end ();
186  ++bit)
187  {
189  erab.erabId = bit->epsBearerId;
190  erab.erabLevelQosParameters = bit->bearerLevelQos;
191  erab.transportLayerAddress = bit->sgwFteid.address;
192  erab.sgwTeid = bit->sgwFteid.teid;
193  erabToBeSetupList.push_back (erab);
194  }
195  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
196  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
197  uint16_t cellId = it->second->cellId;
198  uint16_t enbUeS1Id = it->second->enbUeS1Id;
199  uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
200  std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (cellId);
201  NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << cellId);
202  jt->second->s1apSapEnb->InitialContextSetupRequest (mmeUeS1Id, enbUeS1Id, erabToBeSetupList);
203 }
204 
205 
206 void
208 {
209  NS_LOG_FUNCTION (this << msg.teid);
211  uint64_t imsi = msg.teid;
212  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
213  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
214  uint64_t enbUeS1Id = it->second->enbUeS1Id;
215  uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
216  uint16_t cgi = it->second->cellId;
217  std::list<EpcS1apSapEnb::ErabSwitchedInUplinkItem> erabToBeSwitchedInUplinkList; // unused for now
218  std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (it->second->cellId);
219  NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << it->second->cellId);
220  jt->second->s1apSapEnb->PathSwitchRequestAcknowledge (enbUeS1Id, mmeUeS1Id, cgi, erabToBeSwitchedInUplinkList);
221 }
222 
223 void
224 EpcMme::DoErabReleaseIndication (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabToBeReleasedIndication> erabToBeReleaseIndication)
225 {
226  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
227  uint64_t imsi = mmeUeS1Id;
228  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
229  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
230 
232  // trick to avoid the need for allocating TEIDs on the S11 interface
233  msg.teid = imsi;
234 
235  for (std::list<EpcS1apSapMme::ErabToBeReleasedIndication>::iterator bit = erabToBeReleaseIndication.begin (); bit != erabToBeReleaseIndication.end (); ++bit)
236  {
238  bearerContext.epsBearerId = bit->erabId;
239  msg.bearerContextsToBeRemoved.push_back (bearerContext);
240  }
241  //Delete Bearer command towards epc-sgw-pgw-application
243 }
244 
245 void
247 {
248  NS_LOG_FUNCTION (this);
249  uint64_t imsi = msg.teid;
250  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
251  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
253 
254  res.teid = imsi;
255 
256  for (std::list<EpcS11SapMme::BearerContextRemoved>::iterator bit = msg.bearerContextsRemoved.begin ();
257  bit != msg.bearerContextsRemoved.end ();
258  ++bit)
259  {
261  bearerContext.epsBearerId = bit->epsBearerId;
262  res.bearerContextsRemoved.push_back (bearerContext);
263 
264  RemoveBearer (it->second, bearerContext.epsBearerId); //schedules function to erase, context of de-activated bearer
265  }
266  //schedules Delete Bearer Response towards epc-sgw-pgw-application
268 }
269 
270 void EpcMme::RemoveBearer (Ptr<UeInfo> ueInfo, uint8_t epsBearerId)
271 {
272  NS_LOG_FUNCTION (this << epsBearerId);
273  for (std::list<BearerInfo>::iterator bit = ueInfo->bearersToBeActivated.begin ();
274  bit != ueInfo->bearersToBeActivated.end ();
275  ++bit)
276  {
277  if (bit->bearerId == epsBearerId)
278  {
279  ueInfo->bearersToBeActivated.erase (bit);
280  break;
281  }
282  }
283 }
284 
285 } // namespace ns3
std::list< BearerContextRemoved > bearerContextsRemoved
Definition: epc-s11-sap.h:116
void DoDeleteBearerRequest(EpcS11SapMme::DeleteBearerRequestMessage msg)
Definition: epc-mme.cc:246
void AddUe(uint64_t imsi)
Add a new UE to the MME.
Definition: epc-mme.cc:98
enum ns3::EpcS11SapMme::ModifyBearerResponseMessage::Cause cause
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Delete Bearer Command message, see 3GPP TS 29.274 Release 9 V9.3.0 section 7.2.17.1.
Definition: epc-s11-sap.h:194
MME side of the S1-AP Service Access Point (SAP), provides the MME methods to be called when an S1-AP...
Definition: epc-s1ap-sap.h:48
MME side of the S11 Service Access Point (SAP), provides the MME methods to be called when an S11 mes...
Definition: epc-s11-sap.h:72
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void DoModifyBearerResponse(EpcS11SapMme::ModifyBearerResponseMessage msg)
Definition: epc-mme.cc:207
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
Delete Bearer Request message, see 3GPP TS 29.274 Release 9 V9.3.0 section 7.2.9.2.
Definition: epc-s11-sap.h:114
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
std::map< uint16_t, Ptr< EnbInfo > > m_enbInfoMap
EnbInfo stored by EGCI.
Definition: epc-mme.h:179
EpcS1apSapMme * GetS1apSapMme()
Definition: epc-mme.cc:69
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
This object implements the MME functionality.
Definition: epc-mme.h:40
void DoErabReleaseIndication(uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list< EpcS1apSapMme::ErabToBeReleasedIndication > erabToBeReleaseIndication)
Definition: epc-mme.cc:224
EpcS11SapSgw * m_s11SapSgw
Definition: epc-mme.h:187
Delete Bearer Response message, see 3GPP TS 29.274 Release 9 V9.3.0 section 7.2.10.2.
Definition: epc-s11-sap.h:213
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
eNB side of the S1-AP Service Access Point (SAP), provides the eNB methods to be called when an S1-AP...
Definition: epc-s1ap-sap.h:132
EpcS11SapMme * GetS11SapMme()
Definition: epc-mme.cc:81
uint8_t AddBearer(uint64_t imsi, Ptr< EpcTft > tft, EpsBearer bearer)
Add an EPS bearer to the list of bearers to be activated for this UE.
Definition: epc-mme.cc:109
uint64_t mmeUeS1Id
Definition: epc-mme.h:143
virtual void ModifyBearerRequest(ModifyBearerRequestMessage msg)=0
send a Modify Bearer Request message
virtual ~EpcMme()
Destructor.
Definition: epc-mme.cc:44
Modify Bearer Request message, see 3GPP TS 29.274 7.2.7.
Definition: epc-s11-sap.h:227
Ptr< EpcTft > tft
Definition: epc-mme.h:132
std::list< BearerInfo > bearersToBeActivated
Definition: epc-mme.h:147
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::list< BearerContextCreated > bearerContextsCreated
Definition: epc-s11-sap.h:95
virtual void CreateSessionRequest(CreateSessionRequestMessage msg)=0
send a Create Session Request message
virtual void DoDispose()
Destructor implementation.
Definition: epc-mme.cc:50
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
void DoInitialUeMessage(uint64_t mmeUeS1Id, uint16_t enbUeS1Id, uint64_t imsi, uint16_t ecgi)
Definition: epc-mme.cc:127
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
SGW side of the S11 Service Access Point (SAP), provides the SGW methods to be called when an S11 mes...
Definition: epc-s11-sap.h:156
std::list< BearerContextToBeCreated > bearerContextsToBeCreated
Definition: epc-s11-sap.h:176
std::map< uint64_t, Ptr< UeInfo > > m_ueInfoMap
UeInfo stored by IMSI.
Definition: epc-mme.h:155
void DoInitialContextSetupResponse(uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list< EpcS1apSapMme::ErabSetupItem > erabSetupList)
Definition: epc-mme.cc:150
void AddEnb(uint16_t ecgi, Ipv4Address enbS1UAddr, EpcS1apSapEnb *enbS1apSap)
Add a new ENB to the MME.
Definition: epc-mme.cc:87
void DoPathSwitchRequest(uint64_t enbUeS1Id, uint64_t mmeUeS1Id, uint16_t cgi, std::list< EpcS1apSapMme::ErabSwitchedInDownlinkItem > erabToBeSwitchedInDownlinkList)
Definition: epc-mme.cc:157
Template for the implementation of the EpcS1apSapMme as a member of an owner class of type C to which...
Definition: epc-s1ap-sap.h:189
A base class which provides memory management and object aggregation.
Definition: object.h:87
Modify Bearer Response message, see 3GPP TS 29.274 7.2.7.
Definition: epc-s11-sap.h:131
EpcMme()
Constructor.
Definition: epc-mme.cc:35
EpcS1apSapMme * m_s1apSapMme
Definition: epc-mme.h:184
void RemoveBearer(Ptr< UeInfo > ueInfo, uint8_t epsBearerId)
This Function erases all contexts of bearer from MME side.
Definition: epc-mme.cc:270
void SetS11SapSgw(EpcS11SapSgw *s)
Set the SGW side of the S11 SAP.
Definition: epc-mme.cc:75
a unique identifier for an interface.
Definition: type-id.h:58
Template for the implementation of the EpcS11SapMme as a member of an owner class of type C to which ...
Definition: epc-s11-sap.h:253
virtual void DeleteBearerCommand(DeleteBearerCommandMessage msg)=0
As per 3GPP TS 29.274 Release 9 V9.3.0, a Delete Bearer Command message shall be sent on the S11 inte...
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
EpcS11SapMme * m_s11SapMme
Definition: epc-mme.h:186
uint16_t bearerCounter
Definition: epc-mme.h:148
Ipv4Address s1uAddr
Definition: epc-mme.h:171
void DoCreateSessionResponse(EpcS11SapMme::CreateSessionResponseMessage msg)
Definition: epc-mme.cc:179
virtual void DeleteBearerResponse(DeleteBearerResponseMessage msg)=0
As per 3GPP TS 29.274 Release 9 V9.3.0, a Delete Bearer Command message shall be sent on the S11 inte...
static TypeId GetTypeId(void)
Definition: epc-mme.cc:58
Hold info on an EPS bearer to be activated.
Definition: epc-mme.h:130
Create Session Request message, see 3GPP TS 29.274 7.2.1.
Definition: epc-s11-sap.h:172
EpcS1apSapEnb * s1apSapEnb
Definition: epc-mme.h:172
Create Session Response message, see 3GPP TS 29.274 7.2.2.
Definition: epc-s11-sap.h:93