A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
epc-mme.cc
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 NS_LOG_COMPONENT_DEFINE ("EpcMme");
30 
31 namespace ns3 {
32 
33 
34 
35 
36 NS_OBJECT_ENSURE_REGISTERED (EpcMme);
37 
39  : m_s11SapSgw (0)
40 {
41  NS_LOG_FUNCTION (this);
42  m_s1apSapMme = new MemberEpcS1apSapMme<EpcMme> (this);
43  m_s11SapMme = new MemberEpcS11SapMme<EpcMme> (this);
44 }
45 
46 
48 {
49  NS_LOG_FUNCTION (this);
50 }
51 
52 void
54 {
55  NS_LOG_FUNCTION (this);
56  delete m_s1apSapMme;
57  delete m_s11SapMme;
58 }
59 
60 TypeId
61 EpcMme::GetTypeId (void)
62 {
63  static TypeId tid = TypeId ("ns3::EpcMme")
64  .SetParent<Object> ()
65  .AddConstructor<EpcMme> ()
66  ;
67  return tid;
68 }
69 
70 EpcS1apSapMme*
72 {
73  return m_s1apSapMme;
74 }
75 
76 void
78 {
79  m_s11SapSgw = s;
80 }
81 
84 {
85  return m_s11SapMme;
86 }
87 
88 void
89 EpcMme::AddEnb (uint16_t gci, Ipv4Address enbS1uAddr, EpcS1apSapEnb* enbS1apSap)
90 {
91  NS_LOG_FUNCTION (this << gci << enbS1uAddr);
92  Ptr<EnbInfo> enbInfo = Create<EnbInfo> ();
93  enbInfo->gci = gci;
94  enbInfo->s1uAddr = enbS1uAddr;
95  enbInfo->s1apSapEnb = enbS1apSap;
96  m_enbInfoMap[gci] = enbInfo;
97 }
98 
99 void
100 EpcMme::AddUe (uint64_t imsi)
101 {
102  NS_LOG_FUNCTION (this << imsi);
103  Ptr<UeInfo> ueInfo = Create<UeInfo> ();
104  ueInfo->imsi = imsi;
105  ueInfo->mmeUeS1Id = imsi;
106  m_ueInfoMap[imsi] = ueInfo;
107  ueInfo->bearerCounter = 0;
108 }
109 
110 void
111 EpcMme::AddBearer (uint64_t imsi, Ptr<EpcTft> tft, EpsBearer bearer)
112 {
113  NS_LOG_FUNCTION (this << imsi);
114  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
115  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
116  NS_ASSERT_MSG (it->second->bearerCounter < 11, "too many bearers already! " << it->second->bearerCounter);
117  BearerInfo bearerInfo;
118  bearerInfo.bearerId = ++(it->second->bearerCounter);
119  bearerInfo.tft = tft;
120  bearerInfo.bearer = bearer;
121  it->second->bearersToBeActivated.push_back (bearerInfo);
122 }
123 
124 
125 // S1-AP SAP MME forwarded methods
126 
127 void
128 EpcMme::DoInitialUeMessage (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, uint64_t imsi, uint16_t gci)
129 {
130  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << imsi << gci);
131  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
132  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
133  it->second->cellId = gci;
135  msg.imsi = imsi;
136  msg. uli.gci = gci;
137  for (std::list<BearerInfo>::iterator bit = it->second->bearersToBeActivated.begin ();
138  bit != it->second->bearersToBeActivated.end ();
139  ++bit)
140  {
142  bearerContext.epsBearerId = bit->bearerId;
143  bearerContext.bearerLevelQos = bit->bearer;
144  bearerContext.tft = bit->tft;
145  msg.bearerContextsToBeCreated.push_back (bearerContext);
146  }
147  m_s11SapSgw->CreateSessionRequest (msg);
148 }
149 
150 void
151 EpcMme::DoInitialContextSetupResponse (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabSetupItem> erabSetupList)
152 {
153  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
154  NS_FATAL_ERROR ("unimplemented");
155 }
156 
157 void
158 EpcMme::DoPathSwitchRequest (uint64_t enbUeS1Id, uint64_t mmeUeS1Id, uint16_t gci, std::list<EpcS1apSapMme::ErabSwitchedInDownlinkItem> erabToBeSwitchedInDownlinkList)
159 {
160  NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << gci);
161 
162  uint64_t imsi = mmeUeS1Id;
163  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
164  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
165  NS_LOG_INFO ("IMSI " << imsi << " old eNB: " << it->second->cellId << ", new eNB: " << gci);
166  it->second->cellId = gci;
167  it->second->enbUeS1Id = enbUeS1Id;
168 
169  EpcS11SapSgw::ModifyBearerRequestMessage msg;
170  msg.teid = imsi; // trick to avoid the need for allocating TEIDs on the S11 interface
171  msg.uli.gci = gci;
172  // bearer modification is not supported for now
173  m_s11SapSgw->ModifyBearerRequest (msg);
174 }
175 
176 
177 // S11 SAP MME forwarded methods
178 
179 void
180 EpcMme::DoCreateSessionResponse (EpcS11SapMme::CreateSessionResponseMessage msg)
181 {
182  NS_LOG_FUNCTION (this << msg.teid);
183  uint64_t imsi = msg.teid;
184  std::list<EpcS1apSapEnb::ErabToBeSetupItem> erabToBeSetupList;
185  for (std::list<EpcS11SapMme::BearerContextCreated>::iterator bit = msg.bearerContextsCreated.begin ();
186  bit != msg.bearerContextsCreated.end ();
187  ++bit)
188  {
189  EpcS1apSapEnb::ErabToBeSetupItem erab;
190  erab.erabId = bit->epsBearerId;
191  erab.erabLevelQosParameters = bit->bearerLevelQos;
192  erab.transportLayerAddress = bit->sgwFteid.address;
193  erab.sgwTeid = bit->sgwFteid.teid;
194  erabToBeSetupList.push_back (erab);
195  }
196  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
197  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
198  uint16_t cellId = it->second->cellId;
199  uint16_t enbUeS1Id = it->second->enbUeS1Id;
200  uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
201  std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (cellId);
202  NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << cellId);
203  jt->second->s1apSapEnb->InitialContextSetupRequest (mmeUeS1Id, enbUeS1Id, erabToBeSetupList);
204 }
205 
206 
207 void
208 EpcMme::DoModifyBearerResponse (EpcS11SapMme::ModifyBearerResponseMessage msg)
209 {
210  NS_LOG_FUNCTION (this << msg.teid);
211  NS_ASSERT (msg.cause == EpcS11SapMme::ModifyBearerResponseMessage::REQUEST_ACCEPTED);
212  uint64_t imsi = msg.teid;
213  std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
214  NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
215  uint64_t enbUeS1Id = it->second->enbUeS1Id;
216  uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
217  uint16_t cgi = it->second->cellId;
218  std::list<EpcS1apSapEnb::ErabSwitchedInUplinkItem> erabToBeSwitchedInUplinkList; // unused for now
219  std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (it->second->cellId);
220  NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << it->second->cellId);
221  jt->second->s1apSapEnb->PathSwitchRequestAcknowledge (enbUeS1Id, mmeUeS1Id, cgi, erabToBeSwitchedInUplinkList);
222 }
223 
224 } // namespace ns3
void AddUe(uint64_t imsi)
Definition: epc-mme.cc:100
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
std::map< uint16_t, Ptr< EnbInfo > > m_enbInfoMap
Definition: epc-mme.h:170
EpcS1apSapMme * GetS1apSapMme()
Definition: epc-mme.cc:71
#define NS_LOG_INFO(msg)
Definition: log.h:264
void AddBearer(uint64_t imsi, Ptr< EpcTft > tft, EpsBearer bearer)
Definition: epc-mme.cc:111
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
EpcS11SapMme * GetS11SapMme()
Definition: epc-mme.cc:83
virtual void ModifyBearerRequest(ModifyBearerRequestMessage msg)=0
virtual ~EpcMme()
Definition: epc-mme.cc:47
void AddEnb(uint16_t egci, Ipv4Address enbS1UAddr, EpcS1apSapEnb *enbS1apSap)
Definition: epc-mme.cc:89
virtual void CreateSessionRequest(CreateSessionRequestMessage msg)=0
virtual void DoDispose()
Definition: epc-mme.cc:53
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
std::map< uint64_t, Ptr< UeInfo > > m_ueInfoMap
Definition: epc-mme.h:153
a base class which provides memory management and object aggregation
Definition: object.h:63
void SetS11SapSgw(EpcS11SapSgw *s)
Definition: epc-mme.cc:77
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471