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: Manuel Requena <manuel.requena@cttc.es> 19 */ 20 21 #ifndef LTE_TEST_ENTITIES_H 22 #define LTE_TEST_ENTITIES_H 23 24 #include "ns3/simulator.h" 25 #include "ns3/test.h" 26 27 #include "ns3/lte-mac-sap.h" 28 #include "ns3/lte-rlc-sap.h" 29 #include "ns3/lte-pdcp-sap.h" 30 31 #include "ns3/net-device.h" 32 #include <ns3/epc-enb-s1-sap.h> 33 34 namespace ns3 { 35 36 /** 37 * \ingroup lte-test 38 * \ingroup tests 39 * 40 * \brief This class implements a testing RRC entity 41 */ 42 class LteTestRrc : public Object 43 { 44 /// allow LtePdcpSpecificLtePdcpSapUser<LteTestRrc> class friend access 45 friend class LtePdcpSpecificLtePdcpSapUser<LteTestRrc>; 46 // friend class EnbMacMemberLteEnbCmacSapProvider; 47 // friend class EnbMacMemberLteMacSapProvider<LteTestMac>; 48 // friend class EnbMacMemberFfMacSchedSapUser; 49 // friend class EnbMacMemberFfMacCschedSapUser; 50 // friend class EnbMacMemberLteEnbPhySapUser; 51 52 public: 53 /** 54 * \brief Get the type ID. 55 * \return the object TypeId 56 */ 57 static TypeId GetTypeId (void); 58 59 LteTestRrc (void); 60 virtual ~LteTestRrc (void); 61 virtual void DoDispose (void); 62 63 64 /** 65 * \brief Set the PDCP SAP provider 66 * \param s a pointer to the PDCP SAP provider 67 */ 68 void SetLtePdcpSapProvider (LtePdcpSapProvider* s); 69 /** 70 * \brief Get the PDCP SAP user 71 * \return a pointer to the SAP user of the RLC 72 */ 73 LtePdcpSapUser* GetLtePdcpSapUser (void); 74 75 /// Start function 76 void Start (); 77 /// Stop function 78 void Stop (); 79 80 /** 81 * \brief Send data function 82 * \param at the time to send 83 * \param dataToSend the data to send 84 */ 85 void SendData (Time at, std::string dataToSend); 86 /** 87 * \brief Get data received function 88 * \returns the received data string 89 */ 90 std::string GetDataReceived (void); 91 92 // Stats 93 /** 94 * \brief Get the transmit PDUs 95 * \return the number of transmit PDUS 96 */ 97 uint32_t GetTxPdus (void); 98 /** 99 * \brief Get the transmit bytes 100 * \return the number of bytes transmitted 101 */ 102 uint32_t GetTxBytes (void); 103 /** 104 * \brief Get the receive PDUs 105 * \return the number of receive PDUS 106 */ 107 uint32_t GetRxPdus (void); 108 /** 109 * \brief Get the receive bytes 110 * \return the number of bytes received 111 */ 112 uint32_t GetRxBytes (void); 113 114 /** 115 * \brief Get the last transmit time 116 * \return the time of the last transmit 117 */ 118 Time GetTxLastTime (void); 119 /** 120 * \brief Get the last receive time 121 * \return the time of the last receive 122 */ 123 Time GetRxLastTime (void); 124 125 /** 126 * \brief Set the arrival time 127 * \param arrivalTime the arrival time 128 */ 129 void SetArrivalTime (Time arrivalTime); 130 /** 131 * \brief Set the PDU size 132 * \param pduSize the PDU size 133 */ 134 void SetPduSize (uint32_t pduSize); 135 136 /** 137 * \brief Set the device 138 * \param device the device 139 */ 140 void SetDevice (Ptr<NetDevice> device); 141 142 private: 143 /** 144 * Interface forwarded by LtePdcpSapUser 145 * \param params the LtePdcpSapUser::ReceivePdcpSduParameters 146 */ 147 virtual void DoReceivePdcpSdu (LtePdcpSapUser::ReceivePdcpSduParameters params); 148 149 LtePdcpSapUser* m_pdcpSapUser; ///< PDCP SAP user 150 LtePdcpSapProvider* m_pdcpSapProvider; ///< PDCP SAP provider 151 152 std::string m_receivedData; ///< the received data 153 154 uint32_t m_txPdus; ///< number of transmit PDUs 155 uint32_t m_txBytes; ///< number of transmit bytes 156 uint32_t m_rxPdus; ///< number of receive PDUs 157 uint32_t m_rxBytes; ///< number of receive bytes 158 Time m_txLastTime; ///< last transmit time 159 Time m_rxLastTime; ///< last reeive time 160 161 EventId m_nextPdu; ///< next PDU event 162 Time m_arrivalTime; ///< next arrival time 163 uint32_t m_pduSize; ///< PDU size 164 165 Ptr<NetDevice> m_device; ///< the device 166 }; 167 168 ///////////////////////////////////////////////////////////////////// 169 170 /** 171 * \ingroup lte-test 172 * \ingroup tests 173 * 174 * \brief This class implements a testing PDCP entity 175 */ 176 class LteTestPdcp : public Object 177 { 178 /// allow LteRlcSpecificLteRlcSapUser<LteTestPdcp> class friend access 179 friend class LteRlcSpecificLteRlcSapUser<LteTestPdcp>; 180 181 public: 182 /** 183 * \brief Get the type ID. 184 * \return the object TypeId 185 */ 186 static TypeId GetTypeId (void); 187 188 LteTestPdcp (void); 189 virtual ~LteTestPdcp (void); 190 virtual void DoDispose (void); 191 192 193 /** 194 * \brief Set the RLC SAP provider 195 * \param s a pointer to the RLC SAP provider 196 */ 197 void SetLteRlcSapProvider (LteRlcSapProvider* s); 198 /** 199 * \brief Get the RLC SAP user 200 * \return a pointer to the SAP user of the RLC 201 */ 202 LteRlcSapUser* GetLteRlcSapUser (void); 203 204 /// Start function 205 void Start (); 206 207 /** 208 * \brief Send data function 209 * \param time the time to send 210 * \param dataToSend the data to send 211 */ 212 void SendData (Time time, std::string dataToSend); 213 /** 214 * \brief Get data received function 215 * \returns the received data string 216 */ 217 std::string GetDataReceived (void); 218 219 private: 220 /** 221 * Interface forwarded by LteRlcSapUser 222 * \param p the PDCP PDU packet received 223 */ 224 virtual void DoReceivePdcpPdu (Ptr<Packet> p); 225 226 LteRlcSapUser* m_rlcSapUser; ///< RLC SAP user 227 LteRlcSapProvider* m_rlcSapProvider; ///< RLC SAP provider 228 229 std::string m_receivedData; ///< the received data 230 }; 231 232 ///////////////////////////////////////////////////////////////////// 233 234 /** 235 * \ingroup lte-test 236 * \ingroup tests 237 * 238 * \brief This class implements a testing loopback MAC layer 239 */ 240 class LteTestMac : public Object 241 { 242 // friend class EnbMacMemberLteEnbCmacSapProvider; 243 /// allow EnbMacMemberLteMacSapProvider<LteTestMac> class friend access 244 friend class EnbMacMemberLteMacSapProvider<LteTestMac>; 245 // friend class EnbMacMemberFfMacSchedSapUser; 246 // friend class EnbMacMemberFfMacCschedSapUser; 247 // friend class EnbMacMemberLteEnbPhySapUser; 248 249 public: 250 /** 251 * \brief Get the type ID. 252 * \return the object TypeId 253 */ 254 static TypeId GetTypeId (void); 255 256 LteTestMac (void); 257 virtual ~LteTestMac (void); 258 virtual void DoDispose (void); 259 260 /** 261 * \brief Set the device function 262 * \param device the device 263 */ 264 void SetDevice (Ptr<NetDevice> device); 265 266 /** 267 * \brief Send transmit opportunity function 268 * \param time the time 269 * \param bytes the number of bytes 270 */ 271 void SendTxOpportunity (Time time, uint32_t bytes); 272 /** 273 * \brief Get data received function 274 * \returns the received data string 275 */ 276 std::string GetDataReceived (void); 277 278 /** 279 * \brief the Receive function 280 * \param nd the device 281 * \param p the packet 282 * \param protocol the protocol 283 * \param addr the address 284 * \returns true if successful 285 */ 286 bool Receive (Ptr<NetDevice> nd, Ptr<const Packet> p, uint16_t protocol, const Address& addr); 287 288 /** 289 * \brief Set the MAC SAP user 290 * \param s a pointer to the MAC SAP user 291 */ 292 void SetLteMacSapUser (LteMacSapUser* s); 293 /** 294 * \brief Get the MAC SAP provider 295 * \return a pointer to the SAP provider of the MAC 296 */ 297 LteMacSapProvider* GetLteMacSapProvider (void); 298 299 /** 300 * \brief Set the other side of the MAC Loopback 301 * \param s a pointer to the other side of the MAC loopback 302 */ 303 void SetLteMacLoopback (Ptr<LteTestMac> s); 304 305 /** 306 * \brief Set PDCP header present function 307 * \param present true iif PDCP header present 308 */ 309 void SetPdcpHeaderPresent (bool present); 310 311 /** 312 * \brief Set RLC header type 313 * \param rlcHeaderType the RLC header type 314 */ 315 void SetRlcHeaderType (uint8_t rlcHeaderType); 316 317 /// RCL Header Type enumeration 318 typedef enum { 319 UM_RLC_HEADER = 0, 320 AM_RLC_HEADER = 1, 321 } RlcHeaderType_t; ///< the RLC header type 322 323 /** 324 * Set transmit opportunity mode 325 * \param mode the transmit opportunity mode 326 */ 327 void SetTxOpportunityMode (uint8_t mode); 328 329 /// Transmit opportunity mode enumeration 330 typedef enum { 331 MANUAL_MODE = 0, 332 AUTOMATIC_MODE = 1, 333 RANDOM_MODE = 2 334 } TxOpportunityMode_t; ///< transmit opportunity mode 335 336 /** 337 * Set transmit opportunity time 338 * \param txOppTime the transmit opportunity time 339 */ 340 void SetTxOppTime (Time txOppTime); 341 /** 342 * Set transmit opportunity time 343 * \param txOppSize the transmit opportunity size 344 */ 345 void SetTxOppSize (uint32_t txOppSize); 346 347 // Stats 348 /** 349 * \brief Get the transmit PDUs 350 * \return the number of transmit PDUS 351 */ 352 uint32_t GetTxPdus (void); 353 /** 354 * \brief Get the transmit bytes 355 * \return the number of bytes transmitted 356 */ 357 uint32_t GetTxBytes (void); 358 /** 359 * \brief Get the receive PDUs 360 * \return the number of receive PDUS 361 */ 362 uint32_t GetRxPdus (void); 363 /** 364 * \brief Get the receive bytes 365 * \return the number of bytes received 366 */ 367 uint32_t GetRxBytes (void); 368 369 private: 370 // forwarded from LteMacSapProvider 371 /** 372 * Transmit PDU 373 * \param params LteMacSapProvider::TransmitPduParameters 374 */ 375 void DoTransmitPdu (LteMacSapProvider::TransmitPduParameters params); 376 /** 377 * Report buffer status function 378 * \param params LteMacSapProvider::ReportBufferStatusParameters 379 */ 380 void DoReportBufferStatus (LteMacSapProvider::ReportBufferStatusParameters params); 381 382 LteMacSapProvider* m_macSapProvider; ///< MAC SAP provider 383 LteMacSapUser* m_macSapUser; ///< MAC SAP user 384 Ptr<LteTestMac> m_macLoopback; ///< MAC loopback 385 386 std::string m_receivedData; ///< the received data string 387 388 uint8_t m_rlcHeaderType; ///< RLC header type 389 bool m_pdcpHeaderPresent; ///< PDCP header present? 390 uint8_t m_txOpportunityMode; ///< transmit opportunity mode 391 392 Ptr<NetDevice> m_device; ///< the device 393 394 // TxOpportunity configuration 395 EventId m_nextTxOpp; ///< next transmit opportunity event 396 Time m_txOppTime; ///< transmit opportunity time 397 uint32_t m_txOppSize; ///< transmit opportunity size 398 std::list<EventId> m_nextTxOppList; ///< next transmit opportunity list 399 400 // Stats 401 uint32_t m_txPdus; ///< the number of transmit PDUs 402 uint32_t m_txBytes; ///< the number of transmit bytes 403 uint32_t m_rxPdus; ///< the number of receive PDUs 404 uint32_t m_rxBytes; ///< the number of receive bytes 405 406 }; 407 408 409 410 /** 411 * \ingroup lte-test 412 * \ingroup tests 413 * 414 * \brief RRC stub providing a testing S1 SAP user to be used with the EpcEnbApplication 415 */ 416 class EpcTestRrc : public Object 417 { 418 /// allow MemberEpcEnbS1SapUser<EpcTestRrc> class friend access 419 friend class MemberEpcEnbS1SapUser<EpcTestRrc>; 420 421 public: 422 EpcTestRrc (); 423 virtual ~EpcTestRrc (); 424 425 // inherited from Object 426 virtual void DoDispose (void); 427 /** 428 * \brief Get the type ID. 429 * \return the object TypeId 430 */ 431 static TypeId GetTypeId (void); 432 433 /** 434 * Set the S1 SAP Provider 435 * 436 * \param s the S1 SAP Provider 437 */ 438 void SetS1SapProvider (EpcEnbS1SapProvider* s); 439 440 /** 441 * 442 * \return the S1 SAP user 443 */ 444 EpcEnbS1SapUser* GetS1SapUser (); 445 446 private: 447 448 // S1 SAP methods 449 /** 450 * Initial context setup request 451 * \param params EpcEnbS1SapUser::InitialContextSetupRequestParameters 452 */ 453 void DoInitialContextSetupRequest (EpcEnbS1SapUser::InitialContextSetupRequestParameters params); 454 /** 455 * Data radio bearer setup request 456 * \param params EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters 457 */ 458 void DoDataRadioBearerSetupRequest (EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters params); 459 /** 460 * Path switch request acknowledge function 461 * \param params EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters 462 */ 463 void DoPathSwitchRequestAcknowledge (EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters params); 464 465 EpcEnbS1SapProvider* m_s1SapProvider; ///< S1 SAP provider 466 EpcEnbS1SapUser* m_s1SapUser; ///< S1 SAP user 467 468 469 }; 470 471 472 } // namespace ns3 473 474 #endif /* LTE_TEST_MAC_H */ 475