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