natfw/tsrc/natfwtestconsoles/natfwtestconsole/src/icetests.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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 
       
    21 // INCLUDES
       
    22 #include <e32debug.h>
       
    23 #include "natfwconnectivityapidefs.h"
       
    24 #include "natfwconnectivityapi.h"
       
    25 #include "natfwcandidate.h"
       
    26 #include "natfwcandidatepair.h"
       
    27 #include <badesca.h>
       
    28 
       
    29 #include "icetests.h"
       
    30 #include "iceteststubs.h"
       
    31 #include "testdefinitions.hrh"
       
    32 #include "mnatfwsocketmediaconnwrapper.h"
       
    33 #include "natfwcredentials.h"
       
    34 
       
    35 const TInt KDefaultQos = 46;
       
    36 const TInt KStreamCollectionId = 1;
       
    37 const TInt KMediaComponentId = 1;
       
    38 //_LIT8( KUsername, "username" );
       
    39 //_LIT8( KPassword, "password" );
       
    40 //const TUint32 KDestAddr = INET_ADDR( 0,0,0,0 );
       
    41 //const TUint KDestPort = 33000;
       
    42 //_LIT8( KUDPMessage, "UDP_Message" );
       
    43 //_LIT8( KIncomingAddress, "10.10.10.10" );
       
    44 
       
    45 const TInt KFetchingTime = 10000000; // 10 sec.
       
    46 
       
    47 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS =================================================
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CICETests::CICETests
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CICETests::CICETests(
       
    58     CConsoleBase& aConsole,
       
    59     CNATFWConnectivityApi& aNat,
       
    60     CICETestStubs& aIFStub,
       
    61     TUint aIapId,
       
    62     TUint32 aDestAddress, 
       
    63     TUint aDestPort,
       
    64     TUint aProtocol ) :
       
    65     iConsole( aConsole ), iNat( aNat ), iIfStub( aIFStub ), iTestIapId( aIapId ),
       
    66     iDestAddress( aDestAddress ), iDestPort( aDestPort ), iProtocol( aProtocol )
       
    67     {
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CICETests::ConstructL
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CICETests::ConstructL( const TDesC8& aDomain )
       
    77     {
       
    78     iTestDomain = aDomain.AllocL();
       
    79     iIfStub.SetObserver( this );
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CICETests::NewL
       
    85 // Static constructor.
       
    86 // ---------------------------------------------------------------------------
       
    87 //   
       
    88 CICETests* CICETests::NewL( CConsoleBase& aConsole,
       
    89     CNATFWConnectivityApi& aNat, CICETestStubs& aIFStub,
       
    90     const TDesC8& aDomain, TUint aIapId, TUint32 aDestAddress,
       
    91     TUint aDestPort, TUint aProtocol )
       
    92     {
       
    93     CICETests* self 
       
    94         = new ( ELeave ) CICETests( aConsole, aNat, aIFStub, aIapId,
       
    95         aDestAddress, aDestPort, aProtocol );
       
    96 
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL( aDomain );
       
    99     CleanupStack::Pop( self );
       
   100     return self;
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CICETests::~CICETests
       
   106 // Destructor.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CICETests::~CICETests()
       
   110     {
       
   111     delete iTestDomain;
       
   112     TInt count = iCandidateArray.Count();
       
   113     for ( TInt i( 0 ); i < count; i++  )
       
   114         {
       
   115         delete iCandidateArray[i] ;
       
   116         }
       
   117     iCandidateArray.Reset();
       
   118     delete iCandidatePair;
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CICETests::LocalCandidateFound
       
   124 // From MTestConsoleStubsObserver
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CICETests::LocalCandidateFound( CNATFWCandidate& aLocalCandidate/*,
       
   128     TBool aLastCandidate*/ )
       
   129     {
       
   130     //iReceiveMediaAddress = aLocalCandidate.TransportAddr();
       
   131     //iLocalCandidate = &aLocalCandidate;
       
   132     iCandidateArray.AppendL( &aLocalCandidate );
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CICETests::NewCandidatePairFound
       
   138 // From MICETestStubsObserver
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CICETests::NewCandidatePairFound( CNATFWCandidatePair* aCandidatePair )
       
   142     {
       
   143     RDebug::Print( _L( "TEST PRINT: CICETests::NewCandidatePairFound" ) );
       
   144     TBuf<40> buffer;
       
   145     iCandidatePair = aCandidatePair;
       
   146     
       
   147     TInetAddr localAddr = iCandidatePair->LocalCandidate().TransportAddr();
       
   148     localAddr.Output( buffer );
       
   149     RDebug::Print( _L( "Local candidate: %S" ), &buffer );
       
   150 
       
   151     localAddr = iCandidatePair->RemoteCandidate().TransportAddr();
       
   152     buffer.Zero();
       
   153     localAddr.Output( buffer );
       
   154     RDebug::Print( _L( "Remote candidate: %S" ), &buffer );
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CICETests::DoRunNatTestsL
       
   160 // 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CICETests::DoRunIceTestsL()
       
   164     {
       
   165     TInt err( KErrNone );
       
   166 
       
   167     err = KErrNone;
       
   168     RDebug::Print( _L("\n\nNAT_ICE_TEST_START: TestFetchCandidatesL") );
       
   169     iConsole.Printf( _L("Fetch Canditates test") );
       
   170     //__UHEAP_MARK;
       
   171     TRAP( err, TestFetchCandidatesL() );
       
   172     RDebug::Print( _L("\nNAT_ICE_UDP_TEST_STOP: TestFetchCandidatesL, ERR: %d"), err );
       
   173     PrintTestResult( err );
       
   174     //__UHEAP_MARKEND;
       
   175     
       
   176     err = KErrNone;
       
   177     RDebug::Print( _L( "\n\nNAT_ICE_TEST_START: Set role" ) );
       
   178     iConsole.Printf( _L( "Set role test" ) );
       
   179     __UHEAP_MARK;
       
   180     TRAP( err, TestSetOperationModeL() );
       
   181     RDebug::Print( _L( "\nNAT_ICE_UDP_TEST_STOP: Set role, ERR: %d" ), err );
       
   182     PrintTestResult( err );
       
   183     __UHEAP_MARKEND;
       
   184     /*
       
   185     err = KErrNone;
       
   186     RDebug::Print( _L( "\n\nNAT_ICE_TEST_START: Set credential" ) );
       
   187     iConsole.Printf( _L( "Set Identification test" ) );
       
   188     __UHEAP_MARK;
       
   189     TRAP( err, TestSetIdentificationL() );
       
   190     RDebug::Print( _L( "\nNAT_ICE_UDP_TEST_STOP: Set credential, ERR: %d" ), err );
       
   191     PrintTestResult( err );
       
   192     __UHEAP_MARKEND;
       
   193     
       
   194     err = KErrNone;
       
   195     RDebug::Print( _L("\n\nNAT_STUN_TEST_START: Perform Connectivity Checks") );
       
   196     iConsole.Printf( _L("Perform Candidate Checks test") );
       
   197     __UHEAP_MARK;
       
   198     TRAP( err, TestPerformConnectivityChecksL() );
       
   199     RDebug::Print( _L("\nNAT_STUN_TEST_STOP: Perform Connectivity Checks, ERR: %d"), err );
       
   200     PrintTestResult( err );
       
   201     __UHEAP_MARKEND;
       
   202     */
       
   203     }
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CICETests::TestFetchCandidatesL
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CICETests::TestFetchCandidatesL()
       
   211     {
       
   212     const TInt KDefaultGranularity = 1;
       
   213     
       
   214     TUint sessionId( 0 );
       
   215     TUint streamId( 0 );
       
   216     TInt loadedPluginInd( 0 );
       
   217     
       
   218     CDesC8Array* plugins =
       
   219         new ( ELeave ) CDesC8ArrayFlat( KDefaultGranularity );
       
   220     CleanupStack::PushL( plugins );
       
   221     
       
   222     plugins->AppendL( _L8( "nokia.ice" ) );
       
   223     
       
   224     sessionId = iNat.CreateSessionL( iTestIapId, *iTestDomain );
       
   225     iIfStub.StartActiveSchedulerL();
       
   226     
       
   227     iNat.LoadPluginL( sessionId, *plugins, loadedPluginInd );
       
   228     
       
   229     streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos );
       
   230     
       
   231     iNat.FetchCandidatesL( sessionId, streamId, KStreamCollectionId,
       
   232     	KMediaComponentId, KAfInet );
       
   233     iIfStub.StartActiveSchedulerL( KFetchingTime );
       
   234     
       
   235     iNat.CloseStreamL( sessionId, streamId );
       
   236     iNat.CloseSessionL( sessionId );
       
   237     
       
   238     for( TInt i( 0 ); i < iCandidateArray.Count(); i++ )
       
   239         {
       
   240         RDebug::Print( _L( "\nTEST PRINT: Contents of Candidate %d" ), i + 1 );
       
   241         PrintContents( iCandidateArray[i] );
       
   242         }
       
   243     iCandidateArray.ResetAndDestroy();
       
   244     CleanupStack::PopAndDestroy( plugins );
       
   245     }
       
   246 
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CICETests::PrintContent  
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CICETests::PrintContents( CNATFWCandidate* aCandidate )
       
   253     {
       
   254     TInetAddr address;
       
   255     TBuf16<160> buffer;
       
   256     
       
   257     buffer.AppendFormat( _L( "Candidate type = %d\n"), aCandidate->Type() );
       
   258 
       
   259     address = aCandidate->TransportAddr();
       
   260     address.Output( buffer );
       
   261     
       
   262     buffer.AppendFormat( _L( "Transport address = %S:%d\n" ), &buffer, address.Port() );
       
   263     
       
   264     buffer.AppendFormat( _L( "Transport protocol = %d\n" ),
       
   265         aCandidate->TransportProtocol() );
       
   266         
       
   267     address = aCandidate->Base();
       
   268     address.Output( buffer );
       
   269     
       
   270     buffer.AppendFormat( _L( "Candidate base = %S:%d\n" ), &buffer, address.Port() );
       
   271 
       
   272     RDebug::Print( buffer );
       
   273     }
       
   274     
       
   275     
       
   276 // ---------------------------------------------------------------------------
       
   277 // CICETests::TestSetOperationModeL
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CICETests::TestSetOperationModeL()
       
   281     {
       
   282     TUint sessionId( 0 );
       
   283     
       
   284     sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() );
       
   285     iIfStub.StartActiveSchedulerL();
       
   286     
       
   287     iNat.SetRoleL( sessionId, EIceRoleControlling );
       
   288     
       
   289     iNat.SetRoleL( sessionId, EIceRoleControlled );
       
   290     
       
   291     iNat.CloseSessionL( sessionId );
       
   292     iCandidateArray.ResetAndDestroy();
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // CICETests::TestSetIdentificationL
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 /*
       
   301 void CICETests::TestSetIdentificationL()
       
   302     {
       
   303     TUint sessionId( 0 );
       
   304     TUint streamId( 0 );
       
   305     CNATFWCredentials* natIdIn = CNATFWCredentials::NewL();
       
   306     CNATFWCredentials* natIdOut = CNATFWCredentials::NewL();
       
   307     
       
   308     natIdIn->SetDirection( CNATFWCredentials::EInbound );
       
   309     natIdIn->SetUsernameL( KUsername );
       
   310     natIdIn->SetPasswordL( KPassword );
       
   311     natIdIn->SetStreamCollectionId( KStreamCollectionId );
       
   312     
       
   313     natIdOut->SetDirection( CNATFWCredentials::EOutbound );
       
   314     natIdOut->SetUsernameL( KUsername );
       
   315     natIdOut->SetPasswordL( KPassword );
       
   316     natIdOut->SetStreamCollectionId( KStreamCollectionId );
       
   317     
       
   318     sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() );
       
   319     iIfStub.StartActiveSchedulerL();
       
   320     
       
   321     streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos );
       
   322 
       
   323     iNat.SetCredentialsL( sessionId, streamId, *natIdIn );
       
   324     
       
   325     iNat.SetCredentialsL( sessionId, streamId, *natIdOut );
       
   326     
       
   327     iNat.CloseStreamL( sessionId, streamId );
       
   328     iNat.CloseSessionL( sessionId );
       
   329     delete natIdIn;
       
   330     delete natIdOut;
       
   331     }
       
   332 */
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CICETests::TestPerformConnectivityChecksL
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 /*
       
   339 void CICETests::TestPerformConnectivityChecksL()
       
   340     {
       
   341     TUint sessionId( 0 );
       
   342     TUint streamId( 0 );
       
   343     CNATFWCredentials* natId = CNATFWCredentials::NewL();
       
   344     
       
   345     natId->SetDirection( CNATFWCredentials::EOutbound );
       
   346     natId->SetUsernameL( KUsername );
       
   347     natId->SetPasswordL( KPassword );
       
   348     natId->SetStreamCollectionId( KStreamCollectionId );
       
   349     
       
   350     sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() );
       
   351     iIfStub.StartActiveSchedulerL();
       
   352     
       
   353     streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos );
       
   354     iNat.SetCredentialsL( sessionId, streamId, *natId );
       
   355     
       
   356     iNat.FetchCandidatesL( sessionId, streamId, KStreamCollectionId,
       
   357     	KMediaComponentId );
       
   358     iIfStub.StartActiveSchedulerL( KFetchingTime );
       
   359     
       
   360     // role ICE Controlled
       
   361     iNat.SetRoleL( sessionId, EIceRoleControlled );
       
   362     iNat.PerformConnectivityChecksL( sessionId, iCandidateArray );
       
   363     
       
   364     // role ICE Controlling
       
   365     iNat.SetRoleL( sessionId, EIceRoleControlling );
       
   366     iNat.PerformConnectivityChecksL( sessionId, iCandidateArray );
       
   367     
       
   368     iNat.CloseStreamL( sessionId, streamId );
       
   369     iNat.CloseSessionL( sessionId );
       
   370     delete natId;
       
   371     iCandidateArray.ResetAndDestroy();
       
   372     }
       
   373 */
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CICETests::PrintResult
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CICETests::PrintTestResult( TInt aError )
       
   380     {
       
   381     if ( KErrNone == aError )
       
   382         {
       
   383         iConsole.Printf( _L("...Ready \n") );
       
   384         }
       
   385     else
       
   386         {
       
   387         iConsole.Printf( _L("...Error: %d\n"), aError );
       
   388         }
       
   389     }