A Discrete-Event Network Simulator
API
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#include "lte-enb-net-device.h"
24
25#include <ns3/epc-helper.h>
26#include <ns3/fatal-error.h>
27#include <ns3/log.h>
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("EpcUeNas");
33
35static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES] = {"OFF",
36 "ATTACHING",
37 "IDLE_REGISTERED",
38 "CONNECTING_TO_EPC",
39 "ACTIVE"};
40
45static inline const std::string&
47{
48 return g_ueNasStateName[s];
49}
50
52
54 : m_state(OFF),
55 m_csgId(0),
56 m_asSapProvider(nullptr),
57 m_bidCounter(0)
58{
59 NS_LOG_FUNCTION(this);
61}
62
64{
65 NS_LOG_FUNCTION(this);
66}
67
68void
70{
71 NS_LOG_FUNCTION(this);
72 delete m_asSapUser;
73}
74
77{
78 static TypeId tid =
79 TypeId("ns3::EpcUeNas")
81 .SetGroupName("Lte")
82 .AddConstructor<EpcUeNas>()
83 .AddTraceSource("StateTransition",
84 "fired upon every UE NAS state transition",
86 "ns3::EpcUeNas::StateTracedCallback");
87 return tid;
88}
89
90void
92{
93 NS_LOG_FUNCTION(this << dev);
94 m_device = dev;
95}
96
97void
98EpcUeNas::SetImsi(uint64_t imsi)
99{
100 NS_LOG_FUNCTION(this << imsi);
101 m_imsi = imsi;
102}
103
104void
106{
107 NS_LOG_FUNCTION(this << csgId);
108 m_csgId = csgId;
110}
111
114{
115 NS_LOG_FUNCTION(this);
116 return m_csgId;
117}
118
119void
121{
122 NS_LOG_FUNCTION(this << s);
123 m_asSapProvider = s;
124}
125
128{
129 NS_LOG_FUNCTION(this);
130 return m_asSapUser;
131}
132
133void
135{
136 NS_LOG_FUNCTION(this);
138}
139
140void
142{
143 NS_LOG_FUNCTION(this << dlEarfcn);
145}
146
147void
149{
150 NS_LOG_FUNCTION(this);
151
152 // tell RRC to go into connected mode
154}
155
156void
157EpcUeNas::Connect(uint16_t cellId, uint32_t dlEarfcn)
158{
159 NS_LOG_FUNCTION(this << cellId << dlEarfcn);
160
161 // force the UE RRC to be camped on a specific eNB
162 m_asSapProvider->ForceCampedOnEnb(cellId, dlEarfcn);
163
164 // tell RRC to go into connected mode
166}
167
168void
170{
171 NS_LOG_FUNCTION(this);
174}
175
176void
178{
179 NS_LOG_FUNCTION(this);
180 switch (m_state)
181 {
182 case ACTIVE:
183 NS_FATAL_ERROR("the necessary NAS signaling to activate a bearer after the initial context "
184 "has already been setup is not implemented");
185 break;
186
187 default:
189 btba.bearer = bearer;
190 btba.tft = tft;
191 m_bearersToBeActivatedList.push_back(btba);
193 break;
194 }
195}
196
197bool
198EpcUeNas::Send(Ptr<Packet> packet, uint16_t protocolNumber)
199{
200 NS_LOG_FUNCTION(this << packet << protocolNumber);
201
202 switch (m_state)
203 {
204 case ACTIVE: {
205 uint32_t id = m_tftClassifier.Classify(packet, EpcTft::UPLINK, protocolNumber);
206 NS_ASSERT((id & 0xFFFFFF00) == 0);
207 uint8_t bid = (uint8_t)(id & 0x000000FF);
208 if (bid == 0)
209 {
210 return false;
211 }
212 else
213 {
214 m_asSapProvider->SendData(packet, bid);
215 return true;
216 }
217 }
218 break;
219
220 default:
221 NS_LOG_WARN(this << " NAS OFF, discarding packet");
222 return false;
223 break;
224 }
225}
226
227void
229{
230 NS_LOG_FUNCTION(this);
231
232 SwitchToState(ACTIVE); // will eventually activate dedicated bearers
233}
234
235void
237{
238 NS_LOG_FUNCTION(this);
239
240 // immediately retry the connection
242}
243
244void
246{
247 NS_LOG_FUNCTION(this << packet);
248 m_forwardUpCallback(packet);
249}
250
251void
253{
254 NS_LOG_FUNCTION(this);
255 // remove tfts
256 while (m_bidCounter > 0)
257 {
259 m_bidCounter--;
260 }
261 // restore the bearer list to be activated for the next RRC connection
263
264 Disconnect();
265}
266
267void
269{
270 NS_LOG_FUNCTION(this);
271 NS_ASSERT_MSG(m_bidCounter < 11, "cannot have more than 11 EPS bearers");
272 uint8_t bid = ++m_bidCounter;
273 m_tftClassifier.Add(tft, bid);
274}
275
278{
279 NS_LOG_FUNCTION(this);
280 return m_state;
281}
282
283void
285{
286 NS_LOG_FUNCTION(this << ToString(newState));
287 State oldState = m_state;
288 m_state = newState;
289 NS_LOG_INFO("IMSI " << m_imsi << " NAS " << ToString(oldState) << " --> "
290 << ToString(newState));
291 m_stateTransitionCallback(oldState, newState);
292
293 // actions to be done when entering a new state:
294 switch (m_state)
295 {
296 case ACTIVE:
297 for (std::list<BearerToBeActivated>::iterator it = m_bearersToBeActivatedList.begin();
298 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:443
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:284
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:63
void DoNotifyConnectionSuccessful()
Notify successful connection.
Definition: epc-ue-nas.cc:228
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:91
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:141
State GetState() const
Definition: epc-ue-nas.cc:277
uint32_t m_csgId
Closed Subscriber Group identity.
Definition: epc-ue-nas.h:228
EpcUeNas()
Constructor.
Definition: epc-ue-nas.cc:53
LteAsSapUser * GetAsSapUser()
Definition: epc-ue-nas.cc:127
void DoActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate EPS Bearer.
Definition: epc-ue-nas.cc:268
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:236
LteAsSapProvider * m_asSapProvider
LTE SAP provider.
Definition: epc-ue-nas.h:231
static TypeId GetTypeId()
Get the type ID.
Definition: epc-ue-nas.cc:76
void Disconnect()
instruct the NAS to disconnect
Definition: epc-ue-nas.cc:169
EpcTftClassifier m_tftClassifier
tft classifier
Definition: epc-ue-nas.h:236
void DoDispose() override
Destructor implementation.
Definition: epc-ue-nas.cc:69
void DoNotifyConnectionReleased()
Notify connection released.
Definition: epc-ue-nas.cc:252
void Connect()
Causes NAS to tell AS to go to ACTIVE state.
Definition: epc-ue-nas.cc:148
void SetImsi(uint64_t imsi)
Definition: epc-ue-nas.cc:98
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:120
void SetCsgId(uint32_t csgId)
Definition: epc-ue-nas.cc:105
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
Definition: epc-ue-nas.cc:177
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
set the callback used to forward data packets up the stack
Definition: epc-ue-nas.cc:134
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:245
bool Send(Ptr< Packet > p, uint16_t protocolNumber)
Enqueue an IP packet on the proper bearer for uplink transmission.
Definition: epc-ue-nas.cc:198
uint32_t GetCsgId() const
Definition: epc-ue-nas.cc:113
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:78
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:606
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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:160
#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:45
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
static const std::string & ToString(EpcUeNas::State s)
Definition: epc-ue-nas.cc:46
BearerToBeActivated structure.
Definition: epc-ue-nas.h:242
EpsBearer bearer
EPS bearer.
Definition: epc-ue-nas.h:243
@ OFF
The PHY layer is switched off.