A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("EpcUeNas");
31 
32 namespace ns3 {
33 
34 
35 
36 
37 
38 static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES] =
39 {
40  "OFF",
41  "ATTACHING",
42  "IDLE_REGISTERED",
43  "CONNECTING_TO_EPC",
44  "ACTIVE"
45 };
46 
47 static inline const std::string & ToString (EpcUeNas::State s)
48 {
49  return g_ueNasStateName[s];
50 }
51 
52 
53 
54 
56 
58  : m_state (OFF),
59  m_csgId (0),
60  m_asSapProvider (0),
61  m_bidCounter (0)
62 {
63  NS_LOG_FUNCTION (this);
65 }
66 
67 
69 {
70  NS_LOG_FUNCTION (this);
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION (this);
77  delete m_asSapUser;
78 }
79 
80 TypeId
82 {
83  static TypeId tid = TypeId ("ns3::EpcUeNas")
84  .SetParent<Object> ()
85  .AddConstructor<EpcUeNas> ()
86  .AddTraceSource ("StateTransition",
87  "fired upon every UE NAS state transition",
89  ;
90  return tid;
91 }
92 
93 void
95 {
96  NS_LOG_FUNCTION (this << dev);
97  m_device = dev;
98 }
99 
100 void
101 EpcUeNas::SetImsi (uint64_t imsi)
102 {
103  NS_LOG_FUNCTION (this << imsi);
104  m_imsi = imsi;
105 }
106 
107 void
108 EpcUeNas::SetCsgId (uint32_t csgId)
109 {
110  NS_LOG_FUNCTION (this << csgId);
111  m_csgId = csgId;
113 }
114 
115 uint32_t
117 {
118  NS_LOG_FUNCTION (this);
119  return m_csgId;
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this << s);
126  m_asSapProvider = s;
127 }
128 
131 {
132  NS_LOG_FUNCTION (this);
133  return m_asSapUser;
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION (this);
140  m_forwardUpCallback = cb;
141 }
142 
143 void
144 EpcUeNas::StartCellSelection (uint16_t dlEarfcn)
145 {
146  NS_LOG_FUNCTION (this << dlEarfcn);
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION (this);
154 
155  // tell RRC to go into connected mode
157 }
158 
159 void
160 EpcUeNas::Connect (uint16_t cellId, uint16_t dlEarfcn)
161 {
162  NS_LOG_FUNCTION (this << cellId << dlEarfcn);
163 
164  // force the UE RRC to be camped on a specific eNB
165  m_asSapProvider->ForceCampedOnEnb (cellId, dlEarfcn);
166 
167  // tell RRC to go into connected mode
169 }
170 
171 
172 void
174 {
175  NS_LOG_FUNCTION (this);
177  SwitchToState (OFF);
178 }
179 
180 
181 void
183 {
184  NS_LOG_FUNCTION (this);
185  switch (m_state)
186  {
187  case ACTIVE:
188  NS_FATAL_ERROR ("the necessary NAS signaling to activate a bearer after the initial context has already been setup is not implemented");
189  break;
190 
191  default:
192  BearerToBeActivated btba;
193  btba.bearer = bearer;
194  btba.tft = tft;
195  m_bearersToBeActivatedList.push_back (btba);
196  break;
197  }
198 }
199 
200 bool
202 {
203  NS_LOG_FUNCTION (this << packet);
204 
205  switch (m_state)
206  {
207  case ACTIVE:
208  {
209  uint32_t id = m_tftClassifier.Classify (packet, EpcTft::UPLINK);
210  NS_ASSERT ((id & 0xFFFFFF00) == 0);
211  uint8_t bid = (uint8_t) (id & 0x000000FF);
212  if (bid == 0)
213  {
214  return false;
215  }
216  else
217  {
218  m_asSapProvider->SendData (packet, bid);
219  return true;
220  }
221  }
222  break;
223 
224  default:
225  NS_LOG_WARN (this << " NAS OFF, discarding packet");
226  return false;
227  break;
228  }
229 }
230 
231 void
233 {
234  NS_LOG_FUNCTION (this);
235 
236  SwitchToState (ACTIVE); // will eventually activate dedicated bearers
237 }
238 
239 void
241 {
242  NS_LOG_FUNCTION (this);
243 
244  // immediately retry the connection
246 }
247 
248 void
250 {
251  NS_LOG_FUNCTION (this << packet);
252  m_forwardUpCallback (packet);
253 }
254 
255 void
257 {
258  NS_LOG_FUNCTION (this);
259  SwitchToState (OFF);
260 }
261 
262 void
264 {
265  NS_LOG_FUNCTION (this);
266  NS_ASSERT_MSG (m_bidCounter < 11, "cannot have more than 11 EPS bearers");
267  uint8_t bid = ++m_bidCounter;
268  m_tftClassifier.Add (tft, bid);
269 }
270 
273 {
274  NS_LOG_FUNCTION (this);
275  return m_state;
276 }
277 
278 void
280 {
281  NS_LOG_FUNCTION (this << ToString (newState));
282  State oldState = m_state;
283  m_state = newState;
284  NS_LOG_INFO ("IMSI " << m_imsi << " NAS " << ToString (oldState) << " --> " << ToString (newState));
285  m_stateTransitionCallback (oldState, newState);
286 
287  // actions to be done when entering a new state:
288  switch (m_state)
289  {
290  case ACTIVE:
291  for (std::list<BearerToBeActivated>::iterator it = m_bearersToBeActivatedList.begin ();
292  it != m_bearersToBeActivatedList.end ();
293  m_bearersToBeActivatedList.erase (it++))
294  {
295  DoActivateEpsBearer (it->bearer, it->tft);
296  }
297  break;
298 
299  default:
300  break;
301  }
302 
303 }
304 
305 
306 } // namespace ns3
307 
void SwitchToState(State s)
Definition: epc-ue-nas.cc:279
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
Definition: epc-ue-nas.cc:182
Callback< void, Ptr< Packet > > m_forwardUpCallback
Definition: epc-ue-nas.h:200
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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:194
virtual void StartCellSelection(uint16_t dlEarfcn)=0
Initiate Idle mode cell selection procedure.
Callback template class.
Definition: callback.h:972
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
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:232
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
void StartCellSelection(uint16_t dlEarfcn)
Causes NAS to tell AS to find a suitable cell and camp to it.
Definition: epc-ue-nas.cc:144
EpcUeNas()
Constructor.
Definition: epc-ue-nas.cc:57
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
Definition: epc-ue-nas.h:188
uint32_t Classify(Ptr< Packet > p, EpcTft::Direction direction)
classify an IP packet
static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES]
Definition: epc-ue-nas.cc:38
void DoNotifyConnectionReleased()
Definition: epc-ue-nas.cc:256
virtual void SendData(Ptr< Packet > packet, uint8_t bid)=0
Send a data packet.
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
State GetState() const
Definition: epc-ue-nas.cc:272
LteAsSapUser * GetAsSapUser()
Definition: epc-ue-nas.cc:130
void SetCsgId(uint32_t csgId)
Definition: epc-ue-nas.cc:108
void SetDevice(Ptr< NetDevice > dev)
Definition: epc-ue-nas.cc:94
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
Definition: epc-ue-nas.h:190
EpcTftClassifier m_tftClassifier
Definition: epc-ue-nas.h:198
TracedCallback< State, State > m_stateTransitionCallback
Definition: epc-ue-nas.h:186
uint32_t GetCsgId() const
Definition: epc-ue-nas.cc:116
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void DoNotifyConnectionFailed()
Definition: epc-ue-nas.cc:240
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:986
bool Send(Ptr< Packet > p)
Enqueue an IP packet on the proper bearer for uplink transmission.
Definition: epc-ue-nas.cc:201
void Disconnect()
instruct the NAS to disconnect
Definition: epc-ue-nas.cc:173
#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:68
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
set the callback used to forward data packets up the stack
Definition: epc-ue-nas.cc:137
LteAsSapUser * m_asSapUser
Definition: epc-ue-nas.h:195
void DoActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Definition: epc-ue-nas.cc:263
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:47
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:203
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:123
static TypeId GetTypeId(void)
Definition: epc-ue-nas.cc:81
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:151
a base class which provides memory management and object aggregation
Definition: object.h:64
void SetImsi(uint64_t imsi)
Definition: epc-ue-nas.cc:101
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:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void DoRecvData(Ptr< Packet > packet)
Definition: epc-ue-nas.cc:249
std::list< BearerToBeActivated > m_bearersToBeActivatedList
Definition: epc-ue-nas.h:208
uint8_t m_bidCounter
Definition: epc-ue-nas.h:197
uint32_t m_csgId
Definition: epc-ue-nas.h:192
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: epc-ue-nas.cc:74