-
Notifications
You must be signed in to change notification settings - Fork 0
/
epc-mme.cc
285 lines (247 loc) · 9.37 KB
/
epc-mme.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#include <ns3/fatal-error.h>
#include <ns3/log.h>
#include "epc-s1ap-sap.h"
#include "epc-s11-sap.h"
#include "epc-mme.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("EpcMme");
NS_OBJECT_ENSURE_REGISTERED (EpcMme);
EpcMme::EpcMme ()
: m_s11SapSgw (0)
{
NS_LOG_FUNCTION (this);
m_s1apSapMme = new MemberEpcS1apSapMme<EpcMme> (this);
m_s11SapMme = new MemberEpcS11SapMme<EpcMme> (this);
}
EpcMme::~EpcMme ()
{
NS_LOG_FUNCTION (this);
}
void
EpcMme::DoDispose ()
{
NS_LOG_FUNCTION (this);
delete m_s1apSapMme;
delete m_s11SapMme;
}
TypeId
EpcMme::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::EpcMme")
.SetParent<Object> ()
.SetGroupName("Lte")
.AddConstructor<EpcMme> ()
;
return tid;
}
EpcS1apSapMme*
EpcMme::GetS1apSapMme ()
{
return m_s1apSapMme;
}
void
EpcMme::SetS11SapSgw (EpcS11SapSgw * s)
{
m_s11SapSgw = s;
}
EpcS11SapMme*
EpcMme::GetS11SapMme ()
{
return m_s11SapMme;
}
void
EpcMme::AddEnb (uint16_t gci, Ipv4Address enbS1uAddr, EpcS1apSapEnb* enbS1apSap)
{
NS_LOG_FUNCTION (this << gci << enbS1uAddr);
Ptr<EnbInfo> enbInfo = Create<EnbInfo> ();
enbInfo->gci = gci;
enbInfo->s1uAddr = enbS1uAddr;
enbInfo->s1apSapEnb = enbS1apSap;
m_enbInfoMap[gci] = enbInfo;
}
void
EpcMme::AddUe (uint64_t imsi)
{
NS_LOG_FUNCTION (this << imsi);
Ptr<UeInfo> ueInfo = Create<UeInfo> ();
ueInfo->imsi = imsi;
ueInfo->mmeUeS1Id = imsi;
m_ueInfoMap[imsi] = ueInfo;
ueInfo->bearerCounter = 0;
}
uint8_t
EpcMme::AddBearer (uint64_t imsi, Ptr<EpcTft> tft, EpsBearer bearer)
{
NS_LOG_FUNCTION (this << imsi);
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
NS_ASSERT_MSG (it->second->bearerCounter < 11, "too many bearers already! " << it->second->bearerCounter);
BearerInfo bearerInfo;
bearerInfo.bearerId = ++(it->second->bearerCounter);
bearerInfo.tft = tft;
bearerInfo.bearer = bearer;
it->second->bearersToBeActivated.push_back (bearerInfo);
return bearerInfo.bearerId;
}
// S1-AP SAP MME forwarded methods
void
EpcMme::DoInitialUeMessage (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, uint64_t imsi, uint16_t gci)
{
NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << imsi << gci);
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
it->second->cellId = gci;
EpcS11SapSgw::CreateSessionRequestMessage msg;
msg.imsi = imsi;
msg. uli.gci = gci;
for (std::list<BearerInfo>::iterator bit = it->second->bearersToBeActivated.begin ();
bit != it->second->bearersToBeActivated.end ();
++bit)
{
EpcS11SapSgw::BearerContextToBeCreated bearerContext;
bearerContext.epsBearerId = bit->bearerId;
bearerContext.bearerLevelQos = bit->bearer;
bearerContext.tft = bit->tft;
msg.bearerContextsToBeCreated.push_back (bearerContext);
}
m_s11SapSgw->CreateSessionRequest (msg);
}
void
EpcMme::DoInitialContextSetupResponse (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabSetupItem> erabSetupList)
{
NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
NS_FATAL_ERROR ("unimplemented");
}
void
EpcMme::DoPathSwitchRequest (uint64_t enbUeS1Id, uint64_t mmeUeS1Id, uint16_t gci, std::list<EpcS1apSapMme::ErabSwitchedInDownlinkItem> erabToBeSwitchedInDownlinkList)
{
NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id << gci);
uint64_t imsi = mmeUeS1Id;
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
NS_LOG_INFO ("IMSI " << imsi << " old eNB: " << it->second->cellId << ", new eNB: " << gci);
it->second->cellId = gci;
it->second->enbUeS1Id = enbUeS1Id;
EpcS11SapSgw::ModifyBearerRequestMessage msg;
msg.teid = imsi; // trick to avoid the need for allocating TEIDs on the S11 interface
msg.uli.gci = gci;
// bearer modification is not supported for now
m_s11SapSgw->ModifyBearerRequest (msg);
}
// S11 SAP MME forwarded methods
void
EpcMme::DoCreateSessionResponse (EpcS11SapMme::CreateSessionResponseMessage msg)
{
NS_LOG_FUNCTION (this << msg.teid);
uint64_t imsi = msg.teid;
std::list<EpcS1apSapEnb::ErabToBeSetupItem> erabToBeSetupList;
for (std::list<EpcS11SapMme::BearerContextCreated>::iterator bit = msg.bearerContextsCreated.begin ();
bit != msg.bearerContextsCreated.end ();
++bit)
{
EpcS1apSapEnb::ErabToBeSetupItem erab;
erab.erabId = bit->epsBearerId;
erab.erabLevelQosParameters = bit->bearerLevelQos;
erab.transportLayerAddress = bit->sgwFteid.address;
erab.sgwTeid = bit->sgwFteid.teid;
erabToBeSetupList.push_back (erab);
}
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
uint16_t cellId = it->second->cellId;
uint16_t enbUeS1Id = it->second->enbUeS1Id;
uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (cellId);
NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << cellId);
jt->second->s1apSapEnb->InitialContextSetupRequest (mmeUeS1Id, enbUeS1Id, erabToBeSetupList);
}
void
EpcMme::DoModifyBearerResponse (EpcS11SapMme::ModifyBearerResponseMessage msg)
{
NS_LOG_FUNCTION (this << msg.teid);
NS_ASSERT (msg.cause == EpcS11SapMme::ModifyBearerResponseMessage::REQUEST_ACCEPTED);
uint64_t imsi = msg.teid;
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
uint64_t enbUeS1Id = it->second->enbUeS1Id;
uint64_t mmeUeS1Id = it->second->mmeUeS1Id;
uint16_t cgi = it->second->cellId;
std::list<EpcS1apSapEnb::ErabSwitchedInUplinkItem> erabToBeSwitchedInUplinkList; // unused for now
std::map<uint16_t, Ptr<EnbInfo> >::iterator jt = m_enbInfoMap.find (it->second->cellId);
NS_ASSERT_MSG (jt != m_enbInfoMap.end (), "could not find any eNB with CellId " << it->second->cellId);
jt->second->s1apSapEnb->PathSwitchRequestAcknowledge (enbUeS1Id, mmeUeS1Id, cgi, erabToBeSwitchedInUplinkList);
}
void
EpcMme::DoErabReleaseIndication (uint64_t mmeUeS1Id, uint16_t enbUeS1Id, std::list<EpcS1apSapMme::ErabToBeReleasedIndication> erabToBeReleaseIndication)
{
NS_LOG_FUNCTION (this << mmeUeS1Id << enbUeS1Id);
uint64_t imsi = mmeUeS1Id;
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
EpcS11SapSgw::DeleteBearerCommandMessage msg;
// trick to avoid the need for allocating TEIDs on the S11 interface
msg.teid = imsi;
for (std::list<EpcS1apSapMme::ErabToBeReleasedIndication>::iterator bit = erabToBeReleaseIndication.begin (); bit != erabToBeReleaseIndication.end (); ++bit)
{
EpcS11SapSgw::BearerContextToBeRemoved bearerContext;
bearerContext.epsBearerId = bit->erabId;
msg.bearerContextsToBeRemoved.push_back (bearerContext);
}
//Delete Bearer command towards epc-sgw-pgw-application
m_s11SapSgw->DeleteBearerCommand (msg);
}
void
EpcMme::DoDeleteBearerRequest (EpcS11SapMme::DeleteBearerRequestMessage msg)
{
NS_LOG_FUNCTION (this);
uint64_t imsi = msg.teid;
std::map<uint64_t, Ptr<UeInfo> >::iterator it = m_ueInfoMap.find (imsi);
NS_ASSERT_MSG (it != m_ueInfoMap.end (), "could not find any UE with IMSI " << imsi);
EpcS11SapSgw::DeleteBearerResponseMessage res;
res.teid = imsi;
for (std::list<EpcS11SapMme::BearerContextRemoved>::iterator bit = msg.bearerContextsRemoved.begin ();
bit != msg.bearerContextsRemoved.end ();
++bit)
{
EpcS11SapSgw::BearerContextRemovedSgwPgw bearerContext;
bearerContext.epsBearerId = bit->epsBearerId;
res.bearerContextsRemoved.push_back (bearerContext);
RemoveBearer (it->second, bearerContext.epsBearerId); //schedules function to erase, context of de-activated bearer
}
//schedules Delete Bearer Response towards epc-sgw-pgw-application
m_s11SapSgw->DeleteBearerResponse (res);
}
void EpcMme::RemoveBearer (Ptr<UeInfo> ueInfo, uint8_t epsBearerId)
{
NS_LOG_FUNCTION (this << epsBearerId);
for (std::list<BearerInfo>::iterator bit = ueInfo->bearersToBeActivated.begin ();
bit != ueInfo->bearersToBeActivated.end ();
++bit)
{
if (bit->bearerId == epsBearerId)
{
ueInfo->bearersToBeActivated.erase (bit);
break;
}
}
}
} // namespace ns3