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  .AddConstructor<EpcMme> ()
63  ;
64  return tid;
65 }
66 
69 {
70  return m_s1apSapMme;
71 }
72 
73 void
75 {
76  m_s11SapSgw = s;
77 }
78 
81 {
82  return m_s11SapMme;
83 }
84 
85 void
86 EpcMme::AddEnb (uint16_t gci, Ipv4Address enbS1uAddr, EpcS1apSapEnb* enbS1apSap)
87 {
88  NS_LOG_FUNCTION (this << gci << enbS1uAddr);
89  Ptr<EnbInfo> enbInfo = Create<EnbInfo> ();
90  enbInfo->gci = gci;
91  enbInfo->s1uAddr = enbS1uAddr;
92  enbInfo->s1apSapEnb = enbS1apSap;
93  m_enbInfoMap[gci] = enbInfo;
94 }
95 
96 void
97 EpcMme::AddUe (uint64_t imsi)
98 {
99  NS_LOG_FUNCTION (this << imsi);
100  Ptr<UeInfo> ueInfo = Create<UeInfo> ();
101  ueInfo->imsi = imsi;
102  ueInfo->mmeUeS1Id = imsi;
103  m_ueInfoMap[imsi] = ueInfo;
104  ueInfo->bearerCounter = 0;
105 }
106 
107 uint8_t
108 EpcMme::AddBearer (uint64_t imsi, Ptr<EpcTft> tft, EpsBearer bearer)
109 {
110  NS_LOG_FUNCTION (this << imsi);
111  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
112  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
113  NS_ASSERT_MSG (it->second->bearerCounter < 11, "too many bearers already! " << it->second->bearerCounter);
114  BearerInfo bearerInfo;
115  bearerInfo.bearerId = ++(it->second->bearerCounter);
116  bearerInfo.tft = tft;
117  bearerInfo.bearer = bearer;
118  it->second->bearersToBeActivated.push_back (bearerInfo);
119  return bearerInfo.bearerId;
120 }
121 
122 
123 // S1-AP SAP MME forwarded methods
124 
125 void
126 EpcMme::DoInitialUeMessage (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, uint64_t imsi, uint16_t gci)
127 {
128  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << imsi << gci);
129  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
130  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
131  it->second->cellId = gci;
133  msg.imsi = imsi;
134  msg. uli.gci = gci;
135  for (std::list<BearerInfo>::iterator bit = it->second->bearersToBeActivated.begin ();
136  bit != it->second->bearersToBeActivated.end ();
137  ++bit)
138  {
140  bearerContext.epsBearerId = bit->bearerId;
141  bearerContext.bearerLevelQos = bit->bearer;
142  bearerContext.tft = bit->tft;
143  msg.bearerContextsToBeCreated.push_back (bearerContext);
144  }
146 }
147 
148 void
149 EpcMme::DoInitialContextSetupResponse (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabSetupItem> erabSetupList)
150 {
151  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
152  NS_FATAL_ERROR ("unimplemented");
153 }
154 
155 void
156 EpcMme::DoPathSwitchRequest (uint64_t enbUeS1Id, uint64_t mmeUeS1Id, uint16_t gci, std::list<EpcS1apSapMme::ErabSwitchedInDownlinkItem> erabToBeSwitchedInDownlinkList)
157 {
158  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << gci);
159 
160  uint64_t imsi = mmeUeS1Id;
161  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
162  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
163  NS_LOG_INFO ("IMSI " << imsi << " old eNB: " << it->second->cellId << ", new eNB: " << gci);
164  it->second->cellId = gci;
165  it->second->enbUeS1Id = enbUeS1Id;
166 
168  msg.teid = imsi; // trick to avoid the need for allocating TEIDs on the S11 interface
169  msg.uli.gci = gci;
170  // bearer modification is not supported for now
172 }
173 
174 
175 // S11 SAP MME forwarded methods
176 
177 void
179 {
180  NS_LOG_FUNCTION (this << msg.teid);
181  uint64_t imsi = msg.teid;
182  std::list<EpcS1apSapEnb::ErabToBeSetupItem> erabToBeSetupList;
183  for (std::list<EpcS11SapMme::BearerContextCreated>::iterator bit = msg.bearerContextsCreated.begin ();
184  bit != msg.bearerContextsCreated.end ();
185  ++bit)
186  {
188  erab.erabId = bit->epsBearerId;
189  erab.erabLevelQosParameters = bit->bearerLevelQos;
190  erab.transportLayerAddress = bit->sgwFteid.address;
191  erab.sgwTeid = bit->sgwFteid.teid;
192  erabToBeSetupList.push_back (erab);
193  }
194  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
195  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
196  uint16_t cellId = it->second->cellId;
197  uint16_t enbUeS1Id = it->second->enbUeS1Id;
198  uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
199  std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (cellId);
200  NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << cellId);
201  jt->second->s1apSapEnb->InitialContextSetupRequest (mmeUeS1Id, enbUeS1Id, erabToBeSetupList);
202 }
203 
204 
205 void
207 {
208  NS_LOG_FUNCTION (this << msg.teid);
210  uint64_t imsi = msg.teid;
211  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
212  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
213  uint64_t enbUeS1Id = it->second->enbUeS1Id;
214  uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
215  uint16_t cgi = it->second->cellId;
216  std::list<EpcS1apSapEnb::ErabSwitchedInUplinkItem> erabToBeSwitchedInUplinkList; // unused for now
217  std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (it->second->cellId);
218  NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << it->second->cellId);
219  jt->second->s1apSapEnb->PathSwitchRequestAcknowledge (enbUeS1Id, mmeUeS1Id, cgi, erabToBeSwitchedInUplinkList);
220 }
221 
222 void
223 EpcMme::DoErabReleaseIndication (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabToBeReleasedIndication> erabToBeReleaseIndication)
224 {
225  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
226  uint64_t imsi = mmeUeS1Id;
227  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
228  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
229 
231  // trick to avoid the need for allocating TEIDs on the S11 interface
232  msg.teid = imsi;
233 
234  for (std::list<EpcS1apSapMme::ErabToBeReleasedIndication>::iterator bit = erabToBeReleaseIndication.begin (); bit != erabToBeReleaseIndication.end (); ++bit)
235  {
237  bearerContext.epsBearerId = bit->erabId;
238  msg.bearerContextsToBeRemoved.push_back (bearerContext);
239  }
240  //Delete Bearer command towards epc-sgw-pgw-application
242 }
243 
244 void
246 {
247  NS_LOG_FUNCTION (this);
248  uint64_t imsi = msg.teid;
249  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
250  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
252 
253  res.teid = imsi;
254 
255  for (std::list<EpcS11SapMme::BearerContextRemoved>::iterator bit = msg.bearerContextsRemoved.begin ();
256  bit != msg.bearerContextsRemoved.end ();
257  ++bit)
258  {
260  bearerContext.epsBearerId = bit->epsBearerId;
261  res.bearerContextsRemoved.push_back (bearerContext);
262 
263  RemoveBearer (it->second, bearerContext.epsBearerId); //schedules function to erase, context of de-activated bearer
264  }
265  //schedules Delete Bearer Response towards epc-sgw-pgw-application
267 }
268 
269 void EpcMme::RemoveBearer (Ptr<UeInfo> ueInfo, uint8_t epsBearerId)
270 {
271  NS_LOG_FUNCTION (this << epsBearerId);
272  for (std::list<BearerInfo>::iterator bit = ueInfo->bearersToBeActivated.begin ();
273  bit != ueInfo->bearersToBeActivated.end ();
274  ++bit)
275  {
276  if (bit->bearerId == epsBearerId)
277  {
278  ueInfo->bearersToBeActivated.erase (bit);
279  break;
280  }
281  }
282 }
283 
284 } // namespace ns3
std::list< BearerContextRemoved > bearerContextsRemoved
Definition: epc-s11-sap.h:116
void DoDeleteBearerRequest(EpcS11SapMme::DeleteBearerRequestMessage msg)
Definition: epc-mme.cc:245
void AddUe(uint64_t imsi)
Add a new UE to the MME.
Definition: epc-mme.cc:97
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:206
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
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:68
#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)
Fatal error handling.
Definition: fatal-error.h:100
void DoErabReleaseIndication(uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list< EpcS1apSapMme::ErabToBeReleasedIndication > erabToBeReleaseIndication)
Definition: epc-mme.cc:223
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:80
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:108
uint64_t mmeUeS1Id
Definition: epc-mme.h:143
Ptr< SampleEmitter > s
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:84
void DoInitialUeMessage(uint64_t mmeUeS1Id, uint16_t enbUeS1Id, uint64_t imsi, uint16_t ecgi)
Definition: epc-mme.cc:126
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:149
void AddEnb(uint16_t ecgi, Ipv4Address enbS1UAddr, EpcS1apSapEnb *enbS1apSap)
Add a new ENB to the MME.
Definition: epc-mme.cc:86
void DoPathSwitchRequest(uint64_t enbUeS1Id, uint64_t mmeUeS1Id, uint16_t cgi, std::list< EpcS1apSapMme::ErabSwitchedInDownlinkItem > erabToBeSwitchedInDownlinkList)
Definition: epc-mme.cc:156
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:269
void SetS11SapSgw(EpcS11SapSgw *s)
Set the SGW side of the S11 SAP.
Definition: epc-mme.cc:74
a unique identifier for an interface.
Definition: type-id.h:51
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)
Definition: type-id.cc:631
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:178
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