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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include "epc-ue-nas.h"
10
11#include "lte-as-sap.h"
12
13#include <ns3/epc-helper.h>
14#include <ns3/fatal-error.h>
15#include <ns3/log.h>
16#include <ns3/simulator.h>
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("EpcUeNas");
22
23/// Map each of UE NAS states to its string representation.
24static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES] = {
25 "OFF",
26 "ATTACHING",
27 "IDLE_REGISTERED",
28 "CONNECTING_TO_EPC",
29 "ACTIVE",
30};
31
32/**
33 * \param s The UE NAS state.
34 * \return The string representation of the given state.
35 */
36static inline const std::string&
38{
39 return g_ueNasStateName[s];
40}
41
43
45 : m_state(OFF),
46 m_csgId(0),
47 m_asSapProvider(nullptr),
48 m_bidCounter(0)
49{
50 NS_LOG_FUNCTION(this);
52}
53
58
59void
61{
62 NS_LOG_FUNCTION(this);
63 delete m_asSapUser;
64}
65
68{
69 static TypeId tid =
70 TypeId("ns3::EpcUeNas")
72 .SetGroupName("Lte")
73 .AddConstructor<EpcUeNas>()
74 .AddTraceSource("StateTransition",
75 "fired upon every UE NAS state transition",
77 "ns3::EpcUeNas::StateTracedCallback");
78 return tid;
79}
80
81void
83{
84 NS_LOG_FUNCTION(this << dev);
85 m_device = dev;
86}
87
88void
89EpcUeNas::SetImsi(uint64_t imsi)
90{
91 NS_LOG_FUNCTION(this << imsi);
92 m_imsi = imsi;
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << csgId);
99 m_csgId = csgId;
101}
102
105{
106 NS_LOG_FUNCTION(this);
107 return m_csgId;
108}
109
110void
116
119{
120 NS_LOG_FUNCTION(this);
121 return m_asSapUser;
122}
123
124void
130
131void
133{
134 NS_LOG_FUNCTION(this << dlEarfcn);
136}
137
138void
140{
141 NS_LOG_FUNCTION(this);
142
143 // tell RRC to go into connected mode
145}
146
147void
148EpcUeNas::Connect(uint16_t cellId, uint32_t dlEarfcn)
149{
150 NS_LOG_FUNCTION(this << cellId << dlEarfcn);
151
152 // force the UE RRC to be camped on a specific eNB
153 m_asSapProvider->ForceCampedOnEnb(cellId, dlEarfcn);
154
155 // tell RRC to go into connected mode
157}
158
159void
166
167void
169{
170 NS_LOG_FUNCTION(this);
171 switch (m_state)
172 {
173 case ACTIVE:
174 NS_FATAL_ERROR("the necessary NAS signaling to activate a bearer after the initial context "
175 "has already been setup is not implemented");
176 break;
177
178 default:
180 btba.bearer = bearer;
181 btba.tft = tft;
182 m_bearersToBeActivatedList.push_back(btba);
184 break;
185 }
186}
187
188bool
189EpcUeNas::Send(Ptr<Packet> packet, uint16_t protocolNumber)
190{
191 NS_LOG_FUNCTION(this << packet << protocolNumber);
192
193 switch (m_state)
194 {
195 case ACTIVE: {
196 uint32_t id = m_tftClassifier.Classify(packet, EpcTft::UPLINK, protocolNumber);
197 NS_ASSERT((id & 0xFFFFFF00) == 0);
198 auto bid = (uint8_t)(id & 0x000000FF);
199 if (bid == 0)
200 {
201 return false;
202 }
203 else
204 {
205 m_asSapProvider->SendData(packet, bid);
206 return true;
207 }
208 }
209 break;
210
211 default:
212 NS_LOG_WARN(this << " NAS OFF, discarding packet");
213 return false;
214 }
215}
216
217void
219{
220 NS_LOG_FUNCTION(this);
221
222 SwitchToState(ACTIVE); // will eventually activate dedicated bearers
223}
224
225void
227{
228 NS_LOG_FUNCTION(this);
229
230 // immediately retry the connection
232}
233
234void
236{
237 NS_LOG_FUNCTION(this << packet);
238 m_forwardUpCallback(packet);
239}
240
241void
243{
244 NS_LOG_FUNCTION(this);
245 // remove tfts
246 while (m_bidCounter > 0)
247 {
249 m_bidCounter--;
250 }
251 // restore the bearer list to be activated for the next RRC connection
253
254 Disconnect();
255}
256
257void
259{
260 NS_LOG_FUNCTION(this);
261 NS_ASSERT_MSG(m_bidCounter < 11, "cannot have more than 11 EPS bearers");
262 uint8_t bid = ++m_bidCounter;
263 m_tftClassifier.Add(tft, bid);
264}
265
268{
269 NS_LOG_FUNCTION(this);
270 return m_state;
271}
272
273void
275{
276 NS_LOG_FUNCTION(this << ToString(newState));
277 State oldState = m_state;
278 m_state = newState;
279 NS_LOG_INFO("IMSI " << m_imsi << " NAS " << ToString(oldState) << " --> "
280 << ToString(newState));
281 m_stateTransitionCallback(oldState, newState);
282
283 // actions to be done when entering a new state:
284 switch (m_state)
285 {
286 case ACTIVE:
287 for (auto it = m_bearersToBeActivatedList.begin(); it != m_bearersToBeActivatedList.end();
288 m_bearersToBeActivatedList.erase(it++))
289 {
290 DoActivateEpsBearer(it->bearer, it->tft);
291 }
292 break;
293
294 default:
295 break;
296 }
297}
298
299} // namespace ns3
Callback template class.
Definition callback.h:422
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.
friend class MemberLteAsSapUser< EpcUeNas >
allow MemberLteAsSapUser<EpcUeNas> class friend access
Definition epc-ue-nas.h:28
uint64_t m_imsi
The unique UE identifier.
Definition epc-ue-nas.h:214
State m_state
The current UE NAS state.
Definition epc-ue-nas.h:201
~EpcUeNas() override
Destructor.
Definition epc-ue-nas.cc:54
void DoNotifyConnectionSuccessful()
Notify successful connection.
Callback< void, Ptr< Packet > > m_forwardUpCallback
upward callback
Definition epc-ue-nas.h:227
LteAsSapUser * m_asSapUser
LTE SAP user.
Definition epc-ue-nas.h:222
void SetDevice(Ptr< NetDevice > dev)
Definition epc-ue-nas.cc:82
uint8_t m_bidCounter
bid counter
Definition epc-ue-nas.h:224
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:243
TracedCallback< State, State > m_stateTransitionCallback
The StateTransition trace source.
Definition epc-ue-nas.h:208
void StartCellSelection(uint32_t dlEarfcn)
Causes NAS to tell AS to find a suitable cell and camp to it.
State GetState() const
uint32_t m_csgId
Closed Subscriber Group identity.
Definition epc-ue-nas.h:217
EpcUeNas()
Constructor.
Definition epc-ue-nas.cc:44
LteAsSapUser * GetAsSapUser()
void DoActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate EPS Bearer.
State
Definition of NAS states as per "LTE - From theory to practice", Section 3.2.3.2 "Connection Establis...
Definition epc-ue-nas.h:151
void DoNotifyConnectionFailed()
Notify connection failed.
LteAsSapProvider * m_asSapProvider
LTE SAP provider.
Definition epc-ue-nas.h:220
static TypeId GetTypeId()
Get the type ID.
Definition epc-ue-nas.cc:67
void Disconnect()
instruct the NAS to disconnect
EpcTftClassifier m_tftClassifier
tft classifier
Definition epc-ue-nas.h:225
void DoDispose() override
Destructor implementation.
Definition epc-ue-nas.cc:60
void DoNotifyConnectionReleased()
Notify connection released.
void Connect()
Causes NAS to tell AS to go to ACTIVE state.
void SetImsi(uint64_t imsi)
Definition epc-ue-nas.cc:89
Ptr< NetDevice > m_device
The UE NetDevice.
Definition epc-ue-nas.h:211
void SetAsSapProvider(LteAsSapProvider *s)
Set the AS SAP provider to interact with the NAS entity.
void SetCsgId(uint32_t csgId)
Definition epc-ue-nas.cc:96
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
set the callback used to forward data packets up the stack
std::list< BearerToBeActivated > m_bearersToBeActivatedList
bearers to be activated list
Definition epc-ue-nas.h:236
void DoRecvData(Ptr< Packet > packet)
Receive data.
bool Send(Ptr< Packet > p, uint16_t protocolNumber)
Enqueue an IP packet on the proper bearer for uplink transmission.
uint32_t GetCsgId() const
This class contains the specification of EPS Bearers.
Definition eps-bearer.h:80
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition lte-as-sap.h:28
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:87
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:594
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:250
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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:24
@ OFF
The PHY layer is switched off.
static const std::string & ToString(EpcUeNas::State s)
Definition epc-ue-nas.cc:37
BearerToBeActivated structure.
Definition epc-ue-nas.h:231