natfw/natfwstunturnclient/src/natfwbindingimplementationbase.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "natfwbindingimplementationbase.h"
       
    21 #include "mstunbindingobserver.h"
       
    22 #include "stunturnclientlogs.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 const TReal KAlpha = 0.125;   // alpha = 1/8   RFC 2988
       
    27 const TReal KBeta = 0.25;     // beta = 1/4    RFC 2988
       
    28 
       
    29 const TReal KAlphaRemainder = 1 - KAlpha;  // 1 - alpha = 7/8 (0.875)   RFC 2988 2.3
       
    30 const TReal KBetaRemainder = 1 - KBeta;     // 1 - beta = 3/4 (0.75)  RFC 2988 2.3
       
    31 
       
    32 const TInt KRTTVARFactor = 4;  // RFC 2988 2.3
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Default constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CBindingImplementation::CBindingImplementation( MSTUNBindingObserver& aClient,
       
    40                                                 CBinding& aBinding, 
       
    41                                                 RSocket& aSocket ) :
       
    42     CSTUNTimerUser( aClient.TimerProvider() ),
       
    43     iClient( &aClient ),    
       
    44     iBinding( aBinding ),
       
    45     iSocket( &aSocket ),
       
    46     iDummyIP( KAFUnspec )
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Default constructor - overloaded
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CBindingImplementation::CBindingImplementation( MSTUNBindingObserver& aClient,
       
    55                                         CBinding& aBinding,
       
    56                                         TUint aStreamId,
       
    57                                         TUint aConnectionId,
       
    58                                         MNcmConnectionMultiplexer* aMux ) :
       
    59     CSTUNTimerUser( aClient.TimerProvider() ),
       
    60     iClient( &aClient ),
       
    61     iBinding( aBinding ),
       
    62     iStreamId( aStreamId ),
       
    63     iConnectionId( aConnectionId ),
       
    64     iMux( aMux ),
       
    65     iDummyIP( KAFUnspec )
       
    66     {
       
    67     }
       
    68     
       
    69 // ---------------------------------------------------------------------------
       
    70 // CBindingImplementation::SendRequestL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CBindingImplementation::SendRequestL()
       
    74     {
       
    75     User::Leave( KErrNotSupported );
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CBindingImplementation::SendRequestL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void CBindingImplementation::SendRequestL( const TInetAddr& /*aDestAddr*/,
       
    83                                            TBool /*aAddFingerprint*/,
       
    84                                            TUint /*aRTvalue*/  )
       
    85     {
       
    86     User::Leave( KErrNotSupported );
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CBindingImplementation::AllocateRequestL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CBindingImplementation::AllocateRequestL( TUint /*aRtoValue*/ )
       
    94     {
       
    95     User::Leave( KErrNotSupported );
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CBindingImplementation::StoreAddressL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CBindingImplementation::StoreAddressL( 
       
   103     const TInetAddr& /*ReflexiveAddr*/, const TInetAddr& /*aRelayAddr*/ )
       
   104     {
       
   105     User::Leave( KErrNotSupported );
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CBindingImplementation::RelayAddr
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 const TInetAddr& CBindingImplementation::RelayAddr() const
       
   113     {
       
   114     return iDummyIP;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CBindingImplementation::SetActiveDestinationRequestL
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CBindingImplementation::SetActiveDestinationRequestL( 
       
   122     const TInetAddr& /*aRemoteAddr*/, TUint32& /*aTimerValue*/ )
       
   123     {
       
   124     User::Leave( KErrNotSupported );
       
   125     }
       
   126     
       
   127 // ---------------------------------------------------------------------------
       
   128 // CBindingImplementation::ConnectRequestL
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CBindingImplementation::ConnectRequestL( const TInetAddr& /*aRemoteAddr*/ )
       
   132     {
       
   133     User::Leave( KErrNotSupported );
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CBindingImplementation::NewRTTSampleMeasured
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CBindingImplementation::NewRTTSampleMeasured( TInt64& aRTTSample,
       
   141         TBool aRetransmitted )
       
   142     {
       
   143     __STUNTURNCLIENT( "CBindingImplementation::NewRTTSampleMeasured" )
       
   144 
       
   145     if ( aRetransmitted )
       
   146         {
       
   147         // If segment was retransmitted use backed off RTO for next segment
       
   148         iRetransmitInterval = I64INT( aRTTSample );
       
   149         }
       
   150     else
       
   151         {
       
   152         CalculateNewRTO( aRTTSample );
       
   153         iRetransmitInterval = I64INT( iRTO );
       
   154         }
       
   155         
       
   156     __STUNTURNCLIENT_INT1( "CBindingImplementation::NewRTTSampleMeasured - iRetransmitInterval:", iRetransmitInterval )                  
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CBindingImplementation::CalculateNewRTO
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CBindingImplementation::CalculateNewRTO( TInt64& aRTTSample )
       
   164     {
       
   165     __STUNTURNCLIENT( "CBindingImplementation::RemoveAddress" )
       
   166 
       
   167     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - New RTT Sample:", aRTTSample )
       
   168     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - current iRTTVAR:", iRTTVAR )
       
   169     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - current iSRTT:", iSRTT )
       
   170     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - current iRTO:", iRTO ) 
       
   171     
       
   172     if ( iFirstRTOCalculated )
       
   173         {
       
   174         /* 
       
   175         RTTVAR <- (1 - beta) * RTTVAR + beta * |SRTT - R'|
       
   176         SRTT <- (1 - alpha) * SRTT + alpha * R'
       
   177         RTO <- SRTT + max (G, K*RTTVAR) 
       
   178         */
       
   179               
       
   180         TInt64 diff = Abs( iSRTT - aRTTSample );
       
   181         
       
   182         iRTTVAR = TInt64( ( KBetaRemainder * iRTTVAR ) + ( KBeta * diff ) );
       
   183         
       
   184         iSRTT = TInt64( ( KAlphaRemainder * iSRTT ) + ( KAlpha * aRTTSample ) );
       
   185         
       
   186         // rfc2988 if the K*RTTVAR term in the RTO calculation equals zero,
       
   187         // the variance term MUST be rounded to G seconds
       
   188         TInt64 rttvar( 0 );
       
   189         rttvar = ( 0 == iRTTVAR ) ? 1 : iRTTVAR;
       
   190                 
       
   191         iRTO = iSRTT + ( KRTTVARFactor * rttvar );        
       
   192         }
       
   193     else
       
   194         {       
       
   195         /*    
       
   196         (2.2) When the first RTT measurement R is made
       
   197         SRTT <- R
       
   198         RTTVAR <- R/2
       
   199         RTO <- SRTT + max (G, K*RTTVAR)     
       
   200         */
       
   201         
       
   202         iSRTT = aRTTSample;     
       
   203         iRTTVAR = aRTTSample / TInt64( 2 );      
       
   204         iRTO = iSRTT + ( TInt64( 4 ) * iRTTVAR );
       
   205         
       
   206         iFirstRTOCalculated = ETrue;
       
   207         }
       
   208     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - new iRTTVAR:", iRTTVAR )
       
   209     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - new iSRTT:", iSRTT )
       
   210     __STUNTURNCLIENT_INT1( "CBindingImplementation::CalculateNewRTO - new iRTO:", iRTO ) 
       
   211     }
       
   212 
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CBindingImplementation::CancelRetransmission
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CBindingImplementation::CancelRetransmission()
       
   219     {
       
   220     return;
       
   221     }
       
   222 
       
   223 
       
   224 // End of file
       
   225