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
24
26 : m_state(OFF),
27 m_csgId(0),
28 m_asSapProvider(nullptr),
29 m_bidCounter(0)
30{
31 NS_LOG_FUNCTION(this);
33}
34
39
40void
42{
43 NS_LOG_FUNCTION(this);
44 delete m_asSapUser;
45}
46
49{
50 static TypeId tid =
51 TypeId("ns3::EpcUeNas")
53 .SetGroupName("Lte")
54 .AddConstructor<EpcUeNas>()
55 .AddTraceSource("StateTransition",
56 "fired upon every UE NAS state transition",
58 "ns3::EpcUeNas::StateTracedCallback");
59 return tid;
60}
61
62void
64{
65 NS_LOG_FUNCTION(this << dev);
66 m_device = dev;
67}
68
69void
70EpcUeNas::SetImsi(uint64_t imsi)
71{
72 NS_LOG_FUNCTION(this << imsi);
73 m_imsi = imsi;
74}
75
76void
78{
79 NS_LOG_FUNCTION(this << csgId);
80 m_csgId = csgId;
82}
83
86{
87 NS_LOG_FUNCTION(this);
88 return m_csgId;
89}
90
91void
97
100{
101 NS_LOG_FUNCTION(this);
102 return m_asSapUser;
103}
104
105void
111
112void
114{
115 NS_LOG_FUNCTION(this << dlEarfcn);
117}
118
119void
121{
122 NS_LOG_FUNCTION(this);
123
124 // tell RRC to go into connected mode
126}
127
128void
129EpcUeNas::Connect(uint16_t cellId, uint32_t dlEarfcn)
130{
131 NS_LOG_FUNCTION(this << cellId << dlEarfcn);
132
133 // force the UE RRC to be camped on a specific eNB
134 m_asSapProvider->ForceCampedOnEnb(cellId, dlEarfcn);
135
136 // tell RRC to go into connected mode
138}
139
140void
147
148void
150{
151 NS_LOG_FUNCTION(this);
152 switch (m_state)
153 {
154 case ACTIVE:
155 NS_FATAL_ERROR("the necessary NAS signaling to activate a bearer after the initial context "
156 "has already been setup is not implemented");
157 break;
158
159 default:
161 btba.bearer = bearer;
162 btba.tft = tft;
163 m_bearersToBeActivatedList.push_back(btba);
165 break;
166 }
167}
168
169bool
170EpcUeNas::Send(Ptr<Packet> packet, uint16_t protocolNumber)
171{
172 NS_LOG_FUNCTION(this << packet << protocolNumber);
173
174 switch (m_state)
175 {
176 case ACTIVE: {
177 uint32_t id = m_tftClassifier.Classify(packet, EpcTft::UPLINK, protocolNumber);
178 NS_ASSERT((id & 0xFFFFFF00) == 0);
179 auto bid = (uint8_t)(id & 0x000000FF);
180 if (bid == 0)
181 {
182 return false;
183 }
184 else
185 {
186 m_asSapProvider->SendData(packet, bid);
187 return true;
188 }
189 }
190 break;
191
192 default:
193 NS_LOG_WARN(this << " NAS OFF, discarding packet");
194 return false;
195 }
196}
197
198void
200{
201 NS_LOG_FUNCTION(this);
202
203 SwitchToState(ACTIVE); // will eventually activate dedicated bearers
204}
205
206void
208{
209 NS_LOG_FUNCTION(this);
210
211 // immediately retry the connection
213}
214
215void
217{
218 NS_LOG_FUNCTION(this << packet);
219 m_forwardUpCallback(packet);
220}
221
222void
224{
225 NS_LOG_FUNCTION(this);
226 // remove tfts
227 while (m_bidCounter > 0)
228 {
230 m_bidCounter--;
231 }
232 // restore the bearer list to be activated for the next RRC connection
234
235 Disconnect();
236}
237
238void
240{
241 NS_LOG_FUNCTION(this);
242 NS_ASSERT_MSG(m_bidCounter < 11, "cannot have more than 11 EPS bearers");
243 uint8_t bid = ++m_bidCounter;
244 m_tftClassifier.Add(tft, bid);
245}
246
249{
250 NS_LOG_FUNCTION(this);
251 return m_state;
252}
253
254void
256{
257 NS_LOG_FUNCTION(this << newState);
258 State oldState = m_state;
259 m_state = newState;
260 NS_LOG_INFO("IMSI " << m_imsi << " NAS " << oldState << " --> " << newState);
261 m_stateTransitionCallback(oldState, newState);
262
263 // actions to be done when entering a new state:
264 switch (m_state)
265 {
266 case ACTIVE:
267 for (auto it = m_bearersToBeActivatedList.begin(); it != m_bearersToBeActivatedList.end();
268 m_bearersToBeActivatedList.erase(it++))
269 {
270 DoActivateEpsBearer(it->bearer, it->tft);
271 }
272 break;
273
274 default:
275 break;
276 }
277}
278
279std::ostream&
280operator<<(std::ostream& os, EpcUeNas::State state)
281{
282 switch (state)
283 {
285 return os << "OFF";
287 return os << "ATTACHING";
289 return os << "IDLE_REGISTERED";
291 return os << "CONNECTING_TO_EPC";
293 return os << "ACTIVE";
295 return os << "NUM_STATES";
296 };
297 return os << "UNKNOWN(" << static_cast<uint32_t>(state) << ")";
298}
299
300} // 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:35
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:63
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:25
LteAsSapUser * GetAsSapUser()
Definition epc-ue-nas.cc:99
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:48
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:41
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:70
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.
Definition epc-ue-nas.cc:92
void SetCsgId(uint32_t csgId)
Definition epc-ue-nas.cc:77
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
Definition epc-ue-nas.cc:85
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.
@ OFF
The PHY layer is switched off.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
BearerToBeActivated structure.
Definition epc-ue-nas.h:231