OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2014 Universitat Autònoma de Barcelona |
| 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: Rubén Martínez <rmartinez@deic.uab.cat> |
| 19 */ |
| 20 |
| 21 #include "ltp-session-state-record.h" |
| 22 #include "ns3/log.h" |
| 23 |
| 24 |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("SessionStateRecord"); |
| 27 |
| 28 namespace ns3 { |
| 29 namespace ltp { |
| 30 |
| 31 LtpEngineConfigParameters::LtpEngineConfigParameters () |
| 32 : m_localEngineId (0), |
| 33 m_cpRtxLimit (0), |
| 34 m_rpRtxLimit (0), |
| 35 m_rxProblemLimit (0), |
| 36 m_cxRtxLimit (0), |
| 37 m_rtxCycleLimit (0) |
| 38 { |
| 39 NS_LOG_FUNCTION (this); |
| 40 } |
| 41 |
| 42 LtpEngineConfigParameters::LtpEngineConfigParameters |
| 43 (uint64_t engineId,uint32_t cpLimit,uint32_t rpLimi
t,uint32_t problemLimit, |
| 44 uint32_t cancelLimit,uint32_t cycleLimit) |
| 45 : m_localEngineId (engineId), |
| 46 m_cpRtxLimit (cpLimit), |
| 47 m_rpRtxLimit (rpLimit), |
| 48 m_rxProblemLimit (problemLimit), |
| 49 m_cxRtxLimit (cancelLimit), |
| 50 m_rtxCycleLimit (cycleLimit) |
| 51 { |
| 52 NS_LOG_FUNCTION (this); |
| 53 } |
| 54 |
| 55 LtpEngineConfigParameters::~LtpEngineConfigParameters () |
| 56 { |
| 57 NS_LOG_FUNCTION (this); |
| 58 } |
| 59 |
| 60 uint64_t |
| 61 LtpEngineConfigParameters::GetLocalEngineId () const |
| 62 { |
| 63 NS_LOG_FUNCTION (this); |
| 64 return m_localEngineId; |
| 65 } |
| 66 |
| 67 uint32_t LtpEngineConfigParameters::GetCheckPointRetransLimit () const |
| 68 { |
| 69 NS_LOG_FUNCTION (this); |
| 70 return m_cpRtxLimit; |
| 71 } |
| 72 uint32_t LtpEngineConfigParameters::GetReportRetransLimit () const |
| 73 { |
| 74 NS_LOG_FUNCTION (this); |
| 75 return m_rpRtxLimit; |
| 76 } |
| 77 |
| 78 uint32_t LtpEngineConfigParameters::GetReceptionProblemLimit () const |
| 79 { |
| 80 NS_LOG_FUNCTION (this); |
| 81 return m_rxProblemLimit; |
| 82 } |
| 83 |
| 84 uint32_t LtpEngineConfigParameters::GetCancellationRetransLimit () const |
| 85 { |
| 86 NS_LOG_FUNCTION (this); |
| 87 return m_cxRtxLimit; |
| 88 } |
| 89 |
| 90 uint32_t LtpEngineConfigParameters::GetRetransCycleLimit () const |
| 91 { |
| 92 NS_LOG_FUNCTION (this); |
| 93 return m_rtxCycleLimit; |
| 94 } |
| 95 |
| 96 |
| 97 SessionStateRecord::SessionStateRecord () |
| 98 : m_config (), |
| 99 m_sessionId (), |
| 100 m_txQueue (), |
| 101 m_peerLtpEngine (), |
| 102 m_CpTimer (Timer::CANCEL_ON_DESTROY), |
| 103 m_RsTimer (Timer::CANCEL_ON_DESTROY), |
| 104 m_CxTimer (Timer::CANCEL_ON_DESTROY), |
| 105 m_rcvSegments (), |
| 106 m_redpartSucces (false), |
| 107 m_redpartAckSuccess (false), |
| 108 m_blockSuccess (false), |
| 109 m_rTxCnt (0), |
| 110 m_canceled (NOT_CANCELED), |
| 111 m_canceledReason (RESERVED), |
| 112 m_suspended (false) |
| 113 { |
| 114 NS_LOG_FUNCTION (this); |
| 115 } |
| 116 |
| 117 |
| 118 SessionStateRecord::SessionStateRecord (LtpEngineConfigParameters config, |
| 119 uint64_t localClientServiceId, |
| 120 uint64_t peerLtpEngineId) |
| 121 : m_config (config), |
| 122 m_sessionId (), |
| 123 m_txQueue (), |
| 124 m_peerLtpEngine (peerLtpEngineId), |
| 125 m_localClientService (localClientServiceId), |
| 126 m_CpTimer (Timer::CANCEL_ON_DESTROY), |
| 127 m_RsTimer (Timer::CANCEL_ON_DESTROY), |
| 128 m_CxTimer (Timer::CANCEL_ON_DESTROY), |
| 129 m_rcvSegments (), |
| 130 m_redpartSucces (false), |
| 131 m_redpartAckSuccess (false), |
| 132 m_blockSuccess (false), |
| 133 m_rTxCnt (0), |
| 134 m_canceled (NOT_CANCELED), |
| 135 m_canceledReason (RESERVED), |
| 136 m_suspended (false) |
| 137 |
| 138 { |
| 139 NS_LOG_FUNCTION (this); |
| 140 } |
| 141 |
| 142 |
| 143 SenderSessionStateRecord::SenderSessionStateRecord () |
| 144 : SessionStateRecord (), |
| 145 m_destinationClientServiceId (0) |
| 146 { |
| 147 NS_LOG_FUNCTION (this); |
| 148 } |
| 149 |
| 150 SenderSessionStateRecord::SenderSessionStateRecord ( LtpEngineConfigParameters c
onfig, |
| 151 uint64_t localClientService
Id, |
| 152 uint64_t destinationClientS
ervice, |
| 153 uint64_t destinationLtpEngi
ne, |
| 154 Ptr<UniformRandomVariable>
number) |
| 155 : SessionStateRecord (config,localClientServiceId,destinationLtpEngine), |
| 156 m_destinationClientServiceId (destinationClientService) |
| 157 { |
| 158 NS_LOG_FUNCTION (this); |
| 159 m_sessionId = SessionId (m_config.GetLocalEngineId (), |
| 160 number->GetInteger (SessionId::MIN_SESSION_NUMBER,Ses
sionId::MAX_SESSION_NUMBER)) ; |
| 161 |
| 162 m_firstCpSerialNumber = number->GetInteger (MIN_INITIAL_SERIAL_NUMBER,MAX_INIT
IAL_SERIAL_NUMBER); |
| 163 m_currentCpSerialNumber = m_firstCpSerialNumber; |
| 164 m_firstRpSerialNumber = 0; |
| 165 m_currentRpSerialNumber = 0; |
| 166 } |
| 167 ReceiverSessionStateRecord::ReceiverSessionStateRecord () |
| 168 : SessionStateRecord (), |
| 169 m_rcvCheckpoints () |
| 170 { |
| 171 NS_LOG_FUNCTION (this); |
| 172 } |
| 173 |
| 174 ReceiverSessionStateRecord::ReceiverSessionStateRecord (LtpEngineConfigParameter
s config, uint64_t localClientServiceId, SessionId id, Ptr<UniformRandomVariable
> number ) |
| 175 : SessionStateRecord (config,localClientServiceId,id.GetSessionOriginator ()), |
| 176 m_rcvCheckpoints () |
| 177 { |
| 178 NS_LOG_FUNCTION (this); |
| 179 |
| 180 m_sessionId = id; |
| 181 |
| 182 m_firstCpSerialNumber = 0; |
| 183 m_currentCpSerialNumber = 0; |
| 184 m_firstRpSerialNumber = number->GetInteger (MIN_INITIAL_SERIAL_NUMBER,MAX_INIT
IAL_SERIAL_NUMBER); |
| 185 m_currentRpSerialNumber = m_firstRpSerialNumber; |
| 186 } |
| 187 |
| 188 |
| 189 SessionStateRecord::~SessionStateRecord () |
| 190 { |
| 191 NS_LOG_FUNCTION (this); |
| 192 } |
| 193 ReceiverSessionStateRecord::~ReceiverSessionStateRecord () |
| 194 { |
| 195 NS_LOG_FUNCTION (this); |
| 196 } |
| 197 SenderSessionStateRecord::~SenderSessionStateRecord () |
| 198 { |
| 199 NS_LOG_FUNCTION (this); |
| 200 } |
| 201 |
| 202 TypeId |
| 203 SessionStateRecord::GetTypeId () |
| 204 { |
| 205 static TypeId tid = TypeId ("ns3::SessionStateRecord") |
| 206 .SetParent<Object> () |
| 207 .AddConstructor<SessionStateRecord> () |
| 208 ; |
| 209 return tid; |
| 210 } |
| 211 |
| 212 TypeId |
| 213 SessionStateRecord::GetInstanceTypeId (void) const |
| 214 { |
| 215 NS_LOG_FUNCTION (this); |
| 216 return GetTypeId (); |
| 217 } |
| 218 |
| 219 TypeId |
| 220 SenderSessionStateRecord::GetTypeId () |
| 221 { |
| 222 static TypeId tid = TypeId ("ns3::SenderSessionStateRecord") |
| 223 .SetParent<SessionStateRecord> () |
| 224 .AddConstructor<SenderSessionStateRecord> () |
| 225 ; |
| 226 return tid; |
| 227 } |
| 228 |
| 229 TypeId |
| 230 SenderSessionStateRecord::GetInstanceTypeId (void) const |
| 231 { |
| 232 NS_LOG_FUNCTION (this); |
| 233 return GetTypeId (); |
| 234 } |
| 235 |
| 236 TypeId |
| 237 ReceiverSessionStateRecord::GetTypeId () |
| 238 { |
| 239 static TypeId tid = TypeId ("ns3::ReceiverSessionStateRecord") |
| 240 .SetParent<SessionStateRecord> () |
| 241 .AddConstructor<ReceiverSessionStateRecord> () |
| 242 ; |
| 243 return tid; |
| 244 } |
| 245 |
| 246 TypeId |
| 247 ReceiverSessionStateRecord::GetInstanceTypeId (void) const |
| 248 { |
| 249 NS_LOG_FUNCTION (this); |
| 250 return GetTypeId (); |
| 251 } |
| 252 |
| 253 |
| 254 SessionId |
| 255 SessionStateRecord::GetSessionId () const |
| 256 { |
| 257 NS_LOG_FUNCTION (this); |
| 258 return m_sessionId; |
| 259 } |
| 260 |
| 261 void |
| 262 SessionStateRecord::SuspendTimer (TimerCode type) |
| 263 { |
| 264 NS_LOG_FUNCTION (this << type); |
| 265 switch (type) |
| 266 { |
| 267 case CHECKPOINT: |
| 268 m_CpTimer.Suspend (); |
| 269 break; |
| 270 case REPORT: |
| 271 m_RsTimer.Suspend (); |
| 272 break; |
| 273 case CANCEL: |
| 274 m_CxTimer.Suspend (); |
| 275 break; |
| 276 default: |
| 277 break; |
| 278 } |
| 279 } |
| 280 void |
| 281 SessionStateRecord::ResumeTimer (TimerCode type) |
| 282 { |
| 283 NS_LOG_FUNCTION (this << type); |
| 284 switch (type) |
| 285 { |
| 286 case CHECKPOINT: |
| 287 m_CpTimer.Resume (); |
| 288 break; |
| 289 case REPORT: |
| 290 m_RsTimer.Resume (); |
| 291 break; |
| 292 case CANCEL: |
| 293 m_CxTimer.Resume (); |
| 294 break; |
| 295 default: |
| 296 break; |
| 297 } |
| 298 } |
| 299 |
| 300 uint64_t |
| 301 SessionStateRecord::GetCpStartSerialNumber () const |
| 302 { |
| 303 NS_LOG_FUNCTION (this); |
| 304 return m_firstCpSerialNumber; |
| 305 } |
| 306 |
| 307 uint64_t |
| 308 SessionStateRecord::GetRpStartSerialNumber () const |
| 309 { |
| 310 NS_LOG_FUNCTION (this); |
| 311 return m_firstRpSerialNumber; |
| 312 } |
| 313 |
| 314 uint64_t |
| 315 SessionStateRecord::GetCpCurrentSerialNumber () const |
| 316 { |
| 317 NS_LOG_FUNCTION (this); |
| 318 return m_currentCpSerialNumber; |
| 319 } |
| 320 |
| 321 uint64_t |
| 322 SessionStateRecord::GetRpCurrentSerialNumber () const |
| 323 { |
| 324 NS_LOG_FUNCTION (this); |
| 325 return m_currentRpSerialNumber; |
| 326 } |
| 327 |
| 328 |
| 329 uint64_t |
| 330 SessionStateRecord::GetPeerLtpEngineId () const |
| 331 { |
| 332 NS_LOG_FUNCTION (this); |
| 333 return m_peerLtpEngine; |
| 334 } |
| 335 |
| 336 uint64_t |
| 337 SessionStateRecord::GetLocalClientServiceId () const |
| 338 { |
| 339 NS_LOG_FUNCTION (this); |
| 340 return m_localClientService; |
| 341 } |
| 342 |
| 343 uint64_t |
| 344 SessionStateRecord::IncrementCpCurrentSerialNumber () |
| 345 { |
| 346 NS_LOG_FUNCTION (this); |
| 347 return m_currentCpSerialNumber++; |
| 348 } |
| 349 |
| 350 uint64_t |
| 351 SessionStateRecord::IncrementRpCurrentSerialNumber () |
| 352 { |
| 353 NS_LOG_FUNCTION (this); |
| 354 return m_currentRpSerialNumber++; |
| 355 } |
| 356 |
| 357 bool |
| 358 SessionStateRecord::Enqueue (Ptr<Packet> p) |
| 359 { |
| 360 NS_LOG_FUNCTION (this << p); |
| 361 return m_txQueue.Enqueue (p); |
| 362 } |
| 363 |
| 364 Ptr<Packet> |
| 365 SessionStateRecord::Dequeue (void) |
| 366 { |
| 367 NS_LOG_FUNCTION (this); |
| 368 return m_txQueue.Dequeue (); |
| 369 } |
| 370 uint32_t |
| 371 SessionStateRecord::GetNPackets () const |
| 372 { |
| 373 NS_LOG_FUNCTION (this); |
| 374 return m_txQueue.GetNPackets (); |
| 375 } |
| 376 uint64_t |
| 377 SenderSessionStateRecord::GetDestination () const |
| 378 { |
| 379 NS_LOG_FUNCTION (this); |
| 380 return m_destinationClientServiceId; |
| 381 } |
| 382 |
| 383 bool |
| 384 SessionStateRecord::IsRedPartFinished () const |
| 385 { |
| 386 NS_LOG_FUNCTION (this); |
| 387 return m_redpartSucces; |
| 388 } |
| 389 |
| 390 void |
| 391 SessionStateRecord::SetRedPartFinished () |
| 392 { |
| 393 NS_LOG_FUNCTION (this); |
| 394 m_redpartSucces = true; |
| 395 } |
| 396 |
| 397 bool |
| 398 SessionStateRecord::IsRedPartAck () const |
| 399 { |
| 400 NS_LOG_FUNCTION (this); |
| 401 return m_redpartAckSuccess; |
| 402 } |
| 403 |
| 404 void |
| 405 SessionStateRecord::SetRedPartAck () |
| 406 { |
| 407 NS_LOG_FUNCTION (this); |
| 408 m_redpartAckSuccess = true; |
| 409 } |
| 410 |
| 411 bool |
| 412 SessionStateRecord::IsBlockFinished () const |
| 413 { |
| 414 NS_LOG_FUNCTION (this); |
| 415 return m_blockSuccess; |
| 416 } |
| 417 |
| 418 void |
| 419 SessionStateRecord::SetBlockFinished () |
| 420 { |
| 421 NS_LOG_FUNCTION (this); |
| 422 m_blockSuccess = true; |
| 423 } |
| 424 |
| 425 uint64_t |
| 426 SessionStateRecord::GetRTxNumber () const |
| 427 { |
| 428 NS_LOG_FUNCTION (this); |
| 429 return m_rTxCnt; |
| 430 } |
| 431 |
| 432 void |
| 433 SessionStateRecord::IncrementRtxNumber () |
| 434 { |
| 435 NS_LOG_FUNCTION (this); |
| 436 m_rTxCnt++; |
| 437 } |
| 438 |
| 439 bool |
| 440 SessionStateRecord::IsCanceled () const |
| 441 { |
| 442 NS_LOG_FUNCTION (this); |
| 443 return ((m_canceled == NOT_CANCELED) ? false : true); |
| 444 } |
| 445 |
| 446 void |
| 447 SessionStateRecord::Cancel (CancellationState s, CxReasonCode r) |
| 448 { |
| 449 NS_LOG_FUNCTION (this << r << s); |
| 450 m_canceled = s; |
| 451 m_canceledReason = r; |
| 452 } |
| 453 |
| 454 CxReasonCode |
| 455 SessionStateRecord::GetCancellationReason () const |
| 456 { |
| 457 NS_LOG_FUNCTION (this); |
| 458 return m_canceledReason; |
| 459 } |
| 460 |
| 461 bool |
| 462 SessionStateRecord::IsSuspended () const |
| 463 { |
| 464 NS_LOG_FUNCTION (this); |
| 465 return m_suspended; |
| 466 } |
| 467 void |
| 468 SessionStateRecord::Suspend () |
| 469 { |
| 470 NS_LOG_FUNCTION (this); |
| 471 m_suspended = true; |
| 472 } |
| 473 |
| 474 void |
| 475 SessionStateRecord::Resume () |
| 476 { |
| 477 NS_LOG_FUNCTION (this); |
| 478 m_suspended = false; |
| 479 } |
| 480 |
| 481 bool |
| 482 SessionStateRecord::InsertClaim (LtpContentHeader::ReceptionClaim claim) |
| 483 { |
| 484 NS_LOG_FUNCTION (this << claim.offset << " " << claim.length); |
| 485 |
| 486 std::pair<uint64_t,uint64_t> key; |
| 487 std::pair<std::pair<uint64_t,uint64_t>,LtpContentHeader::ReceptionClaim> ack; |
| 488 |
| 489 key = std::make_pair (m_currentRpSerialNumber,claim.offset); |
| 490 ack = std::make_pair (key,claim); |
| 491 return m_rcvSegments.insert (ack).second; |
| 492 } |
| 493 |
| 494 bool |
| 495 ReceiverSessionStateRecord::InsertCheckpoint () |
| 496 { |
| 497 NS_LOG_FUNCTION (this); |
| 498 return m_rcvCheckpoints.insert (m_currentCpSerialNumber).second; |
| 499 |
| 500 } |
| 501 |
| 502 } // namespace ltp |
| 503 } // namespace ns3 |
OLD | NEW |