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 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("EpcUeNas");
33 
34 
35 
37 static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES] =
38 {
39  "OFF",
40  "ATTACHING",
41  "IDLE_REGISTERED",
42  "CONNECTING_TO_EPC",
43  "ACTIVE"
44 };
45 
50 static 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 
76 void
78 {
79  NS_LOG_FUNCTION (this);
80  delete m_asSapUser;
81 }
82 
83 TypeId
85 {
86  static TypeId tid = TypeId ("ns3::EpcUeNas")
87  .SetParent<Object> ()
88  .AddConstructor<EpcUeNas> ()
89  .AddTraceSource ("StateTransition",
90  "fired upon every UE NAS state transition",
92  "ns3::EpcUeNas::StateTracedCallback")
93  ;
94  return tid;
95 }
96 
97 void
99 {
100  NS_LOG_FUNCTION (this << dev);
101  m_device = dev;
102 }
103 
104 void
105 EpcUeNas::SetImsi (uint64_t imsi)
106 {
107  NS_LOG_FUNCTION (this << imsi);
108  m_imsi = imsi;
109 }
110 
111 void
112 EpcUeNas::SetCsgId (uint32_t csgId)
113 {
114  NS_LOG_FUNCTION (this << csgId);
115  m_csgId = csgId;
117 }
118 
119 uint32_t
121 {
122  NS_LOG_FUNCTION (this);
123  return m_csgId;
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << s);
130  m_asSapProvider = s;
131 }
132 
135 {
136  NS_LOG_FUNCTION (this);
137  return m_asSapUser;
138 }
139 
140 void
142 {
143  NS_LOG_FUNCTION (this);
144  m_forwardUpCallback = cb;
145 }
146 
147 void
148 EpcUeNas::StartCellSelection (uint16_t dlEarfcn)
149 {
150  NS_LOG_FUNCTION (this << dlEarfcn);
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION (this);
158 
159  // tell RRC to go into connected mode
161 }
162 
163 void
164 EpcUeNas::Connect (uint16_t cellId, uint16_t dlEarfcn)
165 {
166  NS_LOG_FUNCTION (this << cellId << dlEarfcn);
167 
168  // force the UE RRC to be camped on a specific eNB
169  m_asSapProvider->ForceCampedOnEnb (cellId, dlEarfcn);
170 
171  // tell RRC to go into connected mode
173 }
174 
175 
176 void
178 {
179  NS_LOG_FUNCTION (this);
181  SwitchToState (OFF);
182 }
183 
184 
185 void
187 {
188  NS_LOG_FUNCTION (this);
189  switch (m_state)
190  {
191  case ACTIVE:
192  NS_FATAL_ERROR ("the necessary NAS signaling to activate a bearer after the initial context has already been setup is not implemented");
193  break;
194 
195  default:
196  BearerToBeActivated btba;
197  btba.bearer = bearer;
198  btba.tft = tft;
199  m_bearersToBeActivatedList.push_back (btba);
200  break;
201  }
202 }
203 
204 bool
206 {
207  NS_LOG_FUNCTION (this << packet);
208 
209  switch (m_state)
210  {
211  case ACTIVE:
212  {
213  uint32_t id = m_tftClassifier.Classify (packet, EpcTft::UPLINK);
214  NS_ASSERT ((id & 0xFFFFFF00) == 0);
215  uint8_t bid = (uint8_t) (id & 0x000000FF);
216  if (bid == 0)
217  {
218  return false;
219  }
220  else
221  {
222  m_asSapProvider->SendData (packet, bid);
223  return true;
224  }
225  }
226  break;
227 
228  default:
229  NS_LOG_WARN (this << " NAS OFF, discarding packet");
230  return false;
231  break;
232  }
233 }
234 
235 void
237 {
238  NS_LOG_FUNCTION (this);
239 
240  SwitchToState (ACTIVE); // will eventually activate dedicated bearers
241 }
242 
243 void
245 {
246  NS_LOG_FUNCTION (this);
247 
248  // immediately retry the connection
250 }
251 
252 void
254 {
255  NS_LOG_FUNCTION (this << packet);
256  m_forwardUpCallback (packet);
257 }
258 
259 void
261 {
262  NS_LOG_FUNCTION (this);
263  SwitchToState (OFF);
264 }
265 
266 void
268 {
269  NS_LOG_FUNCTION (this);
270  NS_ASSERT_MSG (m_bidCounter < 11, "cannot have more than 11 EPS bearers");
271  uint8_t bid = ++m_bidCounter;
272  m_tftClassifier.Add (tft, bid);
273 }
274 
277 {
278  NS_LOG_FUNCTION (this);
279  return m_state;
280 }
281 
282 void
284 {
285  NS_LOG_FUNCTION (this << ToString (newState));
286  State oldState = m_state;
287  m_state = newState;
288  NS_LOG_INFO ("IMSI " << m_imsi << " NAS " << ToString (oldState) << " --> " << ToString (newState));
289  m_stateTransitionCallback (oldState, newState);
290 
291  // actions to be done when entering a new state:
292  switch (m_state)
293  {
294  case ACTIVE:
295  for (std::list<BearerToBeActivated>::iterator it = m_bearersToBeActivatedList.begin ();
296  it != m_bearersToBeActivatedList.end ();
297  m_bearersToBeActivatedList.erase (it++))
298  {
299  DoActivateEpsBearer (it->bearer, it->tft);
300  }
301  break;
302 
303  default:
304  break;
305  }
306 
307 }
308 
309 
310 } // namespace ns3
311 
void SwitchToState(State s)
Switch the UE RRC to the given state.
Definition: epc-ue-nas.cc:283
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
Definition: epc-ue-nas.cc:186
Callback< void, Ptr< Packet > > m_forwardUpCallback
Definition: epc-ue-nas.h:221
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
LteAsSapProvider * m_asSapProvider
Definition: epc-ue-nas.h:215
virtual void StartCellSelection(uint16_t dlEarfcn)=0
Initiate Idle mode cell selection procedure.
Callback template class.
Definition: callback.h:978
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void Add(Ptr< EpcTft > tft, uint32_t id)
add a TFT to the Classifier
virtual void ForceCampedOnEnb(uint16_t cellId, uint16_t dlEarfcn)=0
Force the RRC entity to stay camped on a certain eNodeB.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
void DoNotifyConnectionSuccessful()
Definition: epc-ue-nas.cc:236
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
void StartCellSelection(uint16_t dlEarfcn)
Causes NAS to tell AS to find a suitable cell and camp to it.
Definition: epc-ue-nas.cc:148
EpcUeNas()
Constructor.
Definition: epc-ue-nas.cc:60
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition: lte-as-sap.h:41
Ptr< NetDevice > m_device
The UE NetDevice.
Definition: epc-ue-nas.h:207
uint32_t Classify(Ptr< Packet > p, EpcTft::Direction direction)
classify an IP packet
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
void DoNotifyConnectionReleased()
Definition: epc-ue-nas.cc:260
virtual void SendData(Ptr< Packet > packet, uint8_t bid)=0
Send a data packet.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
State GetState() const
Definition: epc-ue-nas.cc:276
LteAsSapUser * GetAsSapUser()
Definition: epc-ue-nas.cc:134
void SetCsgId(uint32_t csgId)
Definition: epc-ue-nas.cc:112
void SetDevice(Ptr< NetDevice > dev)
Definition: epc-ue-nas.cc:98
Template for the implementation of the LteAsSapUser as a member of an owner class of type C to which ...
Definition: lte-as-sap.h:225
Ptr< SampleEmitter > s
uint64_t m_imsi
The unique UE identifier.
Definition: epc-ue-nas.h:210
EpcTftClassifier m_tftClassifier
Definition: epc-ue-nas.h:219
TracedCallback< State, State > m_stateTransitionCallback
The StateTransition trace source.
Definition: epc-ue-nas.h:204
uint32_t GetCsgId() const
Definition: epc-ue-nas.cc:120
State m_state
The current UE NAS state.
Definition: epc-ue-nas.h:197
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DoNotifyConnectionFailed()
Definition: epc-ue-nas.cc:244
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition: lte-as-sap.h:105
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:980
bool Send(Ptr< Packet > p)
Enqueue an IP packet on the proper bearer for uplink transmission.
Definition: epc-ue-nas.cc:205
void Disconnect()
instruct the NAS to disconnect
Definition: epc-ue-nas.cc:177
#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:84
virtual ~EpcUeNas()
Destructor.
Definition: epc-ue-nas.cc:71
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
set the callback used to forward data packets up the stack
Definition: epc-ue-nas.cc:141
LteAsSapUser * m_asSapUser
Definition: epc-ue-nas.h:216
void DoActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Definition: epc-ue-nas.cc:267
State
Definition of NAS states as per "LTE - From theory to practice", Section 3.2.3.2 "Connection Establis...
Definition: epc-ue-nas.h:156
static const std::string & ToString(EpcUeNas::State s)
Definition: epc-ue-nas.cc:50
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
virtual void Disconnect()=0
Tell the RRC entity to release the connection.
void SetAsSapProvider(LteAsSapProvider *s)
Set the AS SAP provider to interact with the NAS entity.
Definition: epc-ue-nas.cc:127
static TypeId GetTypeId(void)
Definition: epc-ue-nas.cc:84
virtual void Connect(void)=0
Tell the RRC entity to enter Connected mode.
void Connect()
Causes NAS to tell AS to go to ACTIVE state.
Definition: epc-ue-nas.cc:155
A base class which provides memory management and object aggregation.
Definition: object.h:87
void SetImsi(uint64_t imsi)
Definition: epc-ue-nas.cc:105
virtual void SetCsgWhiteList(uint32_t csgId)=0
Set the selected Closed Subscriber Group subscription list to be used for cell selection.
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
void DoRecvData(Ptr< Packet > packet)
Definition: epc-ue-nas.cc:253
std::list< BearerToBeActivated > m_bearersToBeActivatedList
Definition: epc-ue-nas.h:229
uint8_t m_bidCounter
Definition: epc-ue-nas.h:218
uint32_t m_csgId
Closed Subscriber Group identity.
Definition: epc-ue-nas.h:213
virtual void DoDispose(void)
Destructor implementation.
Definition: epc-ue-nas.cc:77