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  .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 
98 void
100 {
101  NS_LOG_FUNCTION (this << dev);
102  m_device = dev;
103 }
104 
105 void
106 EpcUeNas::SetImsi (uint64_t imsi)
107 {
108  NS_LOG_FUNCTION (this << imsi);
109  m_imsi = imsi;
110 }
111 
112 void
113 EpcUeNas::SetCsgId (uint32_t csgId)
114 {
115  NS_LOG_FUNCTION (this << csgId);
116  m_csgId = csgId;
118 }
119 
120 uint32_t
122 {
123  NS_LOG_FUNCTION (this);
124  return m_csgId;
125 }
126 
127 void
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 
141 void
143 {
144  NS_LOG_FUNCTION (this);
145  m_forwardUpCallback = cb;
146 }
147 
148 void
149 EpcUeNas::StartCellSelection (uint32_t dlEarfcn)
150 {
151  NS_LOG_FUNCTION (this << dlEarfcn);
153 }
154 
155 void
157 {
158  NS_LOG_FUNCTION (this);
159 
160  // tell RRC to go into connected mode
162 }
163 
164 void
165 EpcUeNas::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 
177 void
179 {
180  NS_LOG_FUNCTION (this);
182  SwitchToState (OFF);
183 }
184 
185 
186 void
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:
197  BearerToBeActivated btba;
198  btba.bearer = bearer;
199  btba.tft = tft;
200  m_bearersToBeActivatedList.push_back (btba);
201  break;
202  }
203 }
204 
205 bool
207 {
208  NS_LOG_FUNCTION (this << packet);
209 
210  switch (m_state)
211  {
212  case ACTIVE:
213  {
214  uint32_t id = m_tftClassifier.Classify (packet, EpcTft::UPLINK);
215  NS_ASSERT ((id & 0xFFFFFF00) == 0);
216  uint8_t bid = (uint8_t) (id & 0x000000FF);
217  if (bid == 0)
218  {
219  return false;
220  }
221  else
222  {
223  m_asSapProvider->SendData (packet, bid);
224  return true;
225  }
226  }
227  break;
228 
229  default:
230  NS_LOG_WARN (this << " NAS OFF, discarding packet");
231  return false;
232  break;
233  }
234 }
235 
236 void
238 {
239  NS_LOG_FUNCTION (this);
240 
241  SwitchToState (ACTIVE); // will eventually activate dedicated bearers
242 }
243 
244 void
246 {
247  NS_LOG_FUNCTION (this);
248 
249  // immediately retry the connection
251 }
252 
253 void
255 {
256  NS_LOG_FUNCTION (this << packet);
257  m_forwardUpCallback (packet);
258 }
259 
260 void
262 {
263  NS_LOG_FUNCTION (this);
264  SwitchToState (OFF);
265 }
266 
267 void
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 
283 void
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) << " --> " << ToString (newState));
290  m_stateTransitionCallback (oldState, newState);
291 
292  // actions to be done when entering a new state:
293  switch (m_state)
294  {
295  case ACTIVE:
296  for (std::list<BearerToBeActivated>::iterator it = m_bearersToBeActivatedList.begin ();
297  it != m_bearersToBeActivatedList.end ();
298  m_bearersToBeActivatedList.erase (it++))
299  {
300  DoActivateEpsBearer (it->bearer, it->tft);
301  }
302  break;
303 
304  default:
305  break;
306  }
307 
308 }
309 
310 
311 } // namespace ns3
312 
void SwitchToState(State s)
Switch the UE RRC to the given state.
Definition: epc-ue-nas.cc:284
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
Definition: epc-ue-nas.cc:187
Callback< void, Ptr< Packet > > m_forwardUpCallback
upward callback
Definition: epc-ue-nas.h:240
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
LTE SAP provider.
Definition: epc-ue-nas.h:233
Callback template class.
Definition: callback.h:1176
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void Add(Ptr< EpcTft > tft, uint32_t id)
add a TFT to the Classifier
#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
void DoNotifyConnectionSuccessful()
Notify successful connection.
Definition: epc-ue-nas.cc:237
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
uint32_t GetCsgId() const
Definition: epc-ue-nas.cc:121
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
State GetState() const
Definition: epc-ue-nas.cc:277
Ptr< NetDevice > m_device
The UE NetDevice.
Definition: epc-ue-nas.h:224
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()
Notify connection released.
Definition: epc-ue-nas.cc:261
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.
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
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
LteAsSapUser * GetAsSapUser()
Definition: epc-ue-nas.cc:135
void SetCsgId(uint32_t csgId)
Definition: epc-ue-nas.cc:113
void SetDevice(Ptr< NetDevice > dev)
Definition: epc-ue-nas.cc:99
Template for the implementation of the LteAsSapUser as a member of an owner class of type C to which ...
Definition: lte-as-sap.h:230
virtual void StartCellSelection(uint32_t dlEarfcn)=0
Initiate Idle mode cell selection procedure.
uint64_t m_imsi
The unique UE identifier.
Definition: epc-ue-nas.h:227
EpcTftClassifier m_tftClassifier
tft classifier
Definition: epc-ue-nas.h:238
TracedCallback< State, State > m_stateTransitionCallback
The StateTransition trace source.
Definition: epc-ue-nas.h:221
virtual void ForceCampedOnEnb(uint16_t cellId, uint32_t dlEarfcn)=0
Force the RRC entity to stay camped on a certain eNodeB.
State m_state
The current UE NAS state.
Definition: epc-ue-nas.h:214
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DoNotifyConnectionFailed()
Notify connection failed.
Definition: epc-ue-nas.cc:245
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:1570
BearerToBeActivated structure.
Definition: epc-ue-nas.h:243
bool Send(Ptr< Packet > p)
Enqueue an IP packet on the proper bearer for uplink transmission.
Definition: epc-ue-nas.cc:206
void Disconnect()
instruct the NAS to disconnect
Definition: epc-ue-nas.cc:178
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:142
LteAsSapUser * m_asSapUser
LTE SAP user.
Definition: epc-ue-nas.h:235
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:161
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:262
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:128
static TypeId GetTypeId(void)
Get the type ID.
Definition: epc-ue-nas.cc:84
The PHY layer is switched off.
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:156
A base class which provides memory management and object aggregation.
Definition: object.h:87
void SetImsi(uint64_t imsi)
Definition: epc-ue-nas.cc:106
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:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void DoRecvData(Ptr< Packet > packet)
Receive data.
Definition: epc-ue-nas.cc:254
std::list< BearerToBeActivated > m_bearersToBeActivatedList
bearers to be activated list
Definition: epc-ue-nas.h:249
EpsBearer bearer
EPS bearer.
Definition: epc-ue-nas.h:245
uint8_t m_bidCounter
bid counter
Definition: epc-ue-nas.h:237
uint32_t m_csgId
Closed Subscriber Group identity.
Definition: epc-ue-nas.h:230
virtual void DoDispose(void)
Destructor implementation.
Definition: epc-ue-nas.cc:77