A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
epc-ue-nas.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#include "epc-ue-nas.h"
21
22#include "lte-as-sap.h"
23
24#include <ns3/epc-helper.h>
25#include <ns3/fatal-error.h>
26#include <ns3/log.h>
27#include <ns3/simulator.h>
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("EpcUeNas");
33
34/// Map each of UE NAS states to its string representation.
35static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES] = {
36 "OFF",
37 "ATTACHING",
38 "IDLE_REGISTERED",
39 "CONNECTING_TO_EPC",
40 "ACTIVE",
41};
42
43/**
44 * \param s The UE NAS state.
45 * \return The string representation of the given state.
46 */
47static inline const std::string&
49{
50 return g_ueNasStateName[s];
51}
52
54
56 : m_state(OFF),
57 m_csgId(0),
58 m_asSapProvider(nullptr),
59 m_bidCounter(0)
60{
61 NS_LOG_FUNCTION(this);
63}
64
66{
67 NS_LOG_FUNCTION(this);
68}
69
70void
72{
73 NS_LOG_FUNCTION(this);
74 delete m_asSapUser;
75}
76
79{
80 static TypeId tid =
81 TypeId("ns3::EpcUeNas")
83 .SetGroupName("Lte")
84 .AddConstructor<EpcUeNas>()
85 .AddTraceSource("StateTransition",
86 "fired upon every UE NAS state transition",
88 "ns3::EpcUeNas::StateTracedCallback");
89 return tid;
90}
91
92void
94{
95 NS_LOG_FUNCTION(this << dev);
96 m_device = dev;
97}
98
99void
100EpcUeNas::SetImsi(uint64_t imsi)
101{
102 NS_LOG_FUNCTION(this << imsi);
103 m_imsi = imsi;
104}
105
106void
108{
109 NS_LOG_FUNCTION(this << csgId);
110 m_csgId = csgId;
112}
113
116{
117 NS_LOG_FUNCTION(this);
118 return m_csgId;
119}
120
121void
123{
124 NS_LOG_FUNCTION(this << s);
125 m_asSapProvider = s;
126}
127
130{
131 NS_LOG_FUNCTION(this);
132 return m_asSapUser;
133}
134
135void
137{
138 NS_LOG_FUNCTION(this);
140}
141
142void
144{
145 NS_LOG_FUNCTION(this << dlEarfcn);
147}
148
149void
151{
152 NS_LOG_FUNCTION(this);
153
154 // tell RRC to go into connected mode
156}
157
158void
159EpcUeNas::Connect(uint16_t cellId, uint32_t dlEarfcn)
160{
161 NS_LOG_FUNCTION(this << cellId << dlEarfcn);
162
163 // force the UE RRC to be camped on a specific eNB
164 m_asSapProvider->ForceCampedOnEnb(cellId, dlEarfcn);
165
166 // tell RRC to go into connected mode
168}
169
170void
172{
173 NS_LOG_FUNCTION(this);
176}
177
178void
180{
181 NS_LOG_FUNCTION(this);
182 switch (m_state)
183 {
184 case ACTIVE:
185 NS_FATAL_ERROR("the necessary NAS signaling to activate a bearer after the initial context "
186 "has already been setup is not implemented");
187 break;
188
189 default:
191 btba.bearer = bearer;
192 btba.tft = tft;
193 m_bearersToBeActivatedList.push_back(btba);
195 break;
196 }
197}
198
199bool
200EpcUeNas::Send(Ptr<Packet> packet, uint16_t protocolNumber)
201{
202 NS_LOG_FUNCTION(this << packet << protocolNumber);
203
204 switch (m_state)
205 {
206 case ACTIVE: {
207 uint32_t id = m_tftClassifier.Classify(packet, EpcTft::UPLINK, protocolNumber);
208 NS_ASSERT((id & 0xFFFFFF00) == 0);
209 auto bid = (uint8_t)(id & 0x000000FF);
210 if (bid == 0)
211 {
212 return false;
213 }
214 else
215 {
216 m_asSapProvider->SendData(packet, bid);
217 return true;
218 }
219 }
220 break;
221
222 default:
223 NS_LOG_WARN(this << " NAS OFF, discarding packet");
224 return false;
225 }
226}
227
228void
230{
231 NS_LOG_FUNCTION(this);
232
233 SwitchToState(ACTIVE); // will eventually activate dedicated bearers
234}
235
236void
238{
239 NS_LOG_FUNCTION(this);
240
241 // immediately retry the connection
243}
244
245void
247{
248 NS_LOG_FUNCTION(this << packet);
249 m_forwardUpCallback(packet);
250}
251
252void
254{
255 NS_LOG_FUNCTION(this);
256 // remove tfts
257 while (m_bidCounter > 0)
258 {
260 m_bidCounter--;
261 }
262 // restore the bearer list to be activated for the next RRC connection
264
265 Disconnect();
266}
267
268void
270{
271 NS_LOG_FUNCTION(this);
272 NS_ASSERT_MSG(m_bidCounter < 11, "cannot have more than 11 EPS bearers");
273 uint8_t bid = ++m_bidCounter;
274 m_tftClassifier.Add(tft, bid);
275}
276
279{
280 NS_LOG_FUNCTION(this);
281 return m_state;
282}
283
284void
286{
287 NS_LOG_FUNCTION(this << ToString(newState));
288 State oldState = m_state;
289 m_state = newState;
290 NS_LOG_INFO("IMSI " << m_imsi << " NAS " << ToString(oldState) << " --> "
291 << ToString(newState));
292 m_stateTransitionCallback(oldState, newState);
293
294 // actions to be done when entering a new state:
295 switch (m_state)
296 {
297 case ACTIVE:
298 for (auto it = m_bearersToBeActivatedList.begin(); it != m_bearersToBeActivatedList.end();
299 m_bearersToBeActivatedList.erase(it++))
300 {
301 DoActivateEpsBearer(it->bearer, it->tft);
302 }
303 break;
304
305 default:
306 break;
307 }
308}
309
310} // namespace ns3
Callback template class.
Definition: callback.h:438
uint32_t Classify(Ptr< Packet > p, EpcTft::Direction direction, uint16_t protocolNumber)
classify an IP packet
void Add(Ptr< EpcTft > tft, uint32_t id)
add a TFT to the Classifier
void Delete(uint32_t id)
delete an existing TFT from the classifier
void SwitchToState(State s)
Switch the UE RRC to the given state.
Definition: epc-ue-nas.cc:285
friend class MemberLteAsSapUser< EpcUeNas >
allow MemberLteAsSapUser<EpcUeNas> class friend access
Definition: epc-ue-nas.h:39
uint64_t m_imsi
The unique UE identifier.
Definition: epc-ue-nas.h:225
State m_state
The current UE NAS state.
Definition: epc-ue-nas.h:212
~EpcUeNas() override
Destructor.
Definition: epc-ue-nas.cc:65
void DoNotifyConnectionSuccessful()
Notify successful connection.
Definition: epc-ue-nas.cc:229
Callback< void, Ptr< Packet > > m_forwardUpCallback
upward callback
Definition: epc-ue-nas.h:238
LteAsSapUser * m_asSapUser
LTE SAP user.
Definition: epc-ue-nas.h:233
void SetDevice(Ptr< NetDevice > dev)
Definition: epc-ue-nas.cc:93
uint8_t m_bidCounter
bid counter
Definition: epc-ue-nas.h:235
std::list< BearerToBeActivated > m_bearersToBeActivatedListForReconnection
bearers to be activated list maintained and to be used for reconnecting an out-of-sync UE
Definition: epc-ue-nas.h:254
TracedCallback< State, State > m_stateTransitionCallback
The StateTransition trace source.
Definition: epc-ue-nas.h:219
void StartCellSelection(uint32_t dlEarfcn)
Causes NAS to tell AS to find a suitable cell and camp to it.
Definition: epc-ue-nas.cc:143
State GetState() const
Definition: epc-ue-nas.cc:278
uint32_t m_csgId
Closed Subscriber Group identity.
Definition: epc-ue-nas.h:228
EpcUeNas()
Constructor.
Definition: epc-ue-nas.cc:55
LteAsSapUser * GetAsSapUser()
Definition: epc-ue-nas.cc:129
void DoActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate EPS Bearer.
Definition: epc-ue-nas.cc:269
State
Definition of NAS states as per "LTE - From theory to practice", Section 3.2.3.2 "Connection Establis...
Definition: epc-ue-nas.h:162
void DoNotifyConnectionFailed()
Notify connection failed.
Definition: epc-ue-nas.cc:237
LteAsSapProvider * m_asSapProvider
LTE SAP provider.
Definition: epc-ue-nas.h:231
static TypeId GetTypeId()
Get the type ID.
Definition: epc-ue-nas.cc:78
void Disconnect()
instruct the NAS to disconnect
Definition: epc-ue-nas.cc:171
EpcTftClassifier m_tftClassifier
tft classifier
Definition: epc-ue-nas.h:236
void DoDispose() override
Destructor implementation.
Definition: epc-ue-nas.cc:71
void DoNotifyConnectionReleased()
Notify connection released.
Definition: epc-ue-nas.cc:253
void Connect()
Causes NAS to tell AS to go to ACTIVE state.
Definition: epc-ue-nas.cc:150
void SetImsi(uint64_t imsi)
Definition: epc-ue-nas.cc:100
Ptr< NetDevice > m_device
The UE NetDevice.
Definition: epc-ue-nas.h:222
void SetAsSapProvider(LteAsSapProvider *s)
Set the AS SAP provider to interact with the NAS entity.
Definition: epc-ue-nas.cc:122
void SetCsgId(uint32_t csgId)
Definition: epc-ue-nas.cc:107
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
Definition: epc-ue-nas.cc:179
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
set the callback used to forward data packets up the stack
Definition: epc-ue-nas.cc:136
std::list< BearerToBeActivated > m_bearersToBeActivatedList
bearers to be activated list
Definition: epc-ue-nas.h:247
void DoRecvData(Ptr< Packet > packet)
Receive data.
Definition: epc-ue-nas.cc:246
bool Send(Ptr< Packet > p, uint16_t protocolNumber)
Enqueue an IP packet on the proper bearer for uplink transmission.
Definition: epc-ue-nas.cc:200
uint32_t GetCsgId() const
Definition: epc-ue-nas.cc:115
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition: lte-as-sap.h:39
virtual void SetCsgWhiteList(uint32_t csgId)=0
Set the selected Closed Subscriber Group subscription list to be used for cell selection.
virtual void Connect()=0
Tell the RRC entity to enter Connected mode.
virtual void StartCellSelection(uint32_t dlEarfcn)=0
Initiate Idle mode cell selection procedure.
virtual void Disconnect()=0
Tell the RRC entity to release the connection.
virtual void SendData(Ptr< Packet > packet, uint8_t bid)=0
Send a data packet.
virtual void ForceCampedOnEnb(uint16_t cellId, uint32_t dlEarfcn)=0
Force the RRC entity to stay camped on a certain eNodeB.
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition: lte-as-sap.h:98
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:605
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES]
Map each of UE NAS states to its string representation.
Definition: epc-ue-nas.cc:35
@ OFF
The PHY layer is switched off.
static const std::string & ToString(EpcUeNas::State s)
Definition: epc-ue-nas.cc:48
BearerToBeActivated structure.
Definition: epc-ue-nas.h:242
EpsBearer bearer
EPS bearer.
Definition: epc-ue-nas.h:243