natfw/natfwconnectionmultiplexer/tsrc/muxtestconsole/src/multiplexerudptests.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 <in_sock.h>
       
    24 #include "cncmconnectionmultiplexer.h"
       
    25 #include <mmccinterface.h>
       
    26 #include <mmcccodecinformation.h>
       
    27 
       
    28 #include "multiplexerudptests.h"
       
    29 #include "muxtestconsolestubs.h"
       
    30 #include "testdefinitions.hrh"
       
    31 #include "ncmconnectionmultiplexerlogs.h"
       
    32 #include "cncmportstore.h"
       
    33 #include "natfwsocketmediaconnwrapper.h"
       
    34 
       
    35 #ifndef __WINSCW__
       
    36 const TInt KTestIapId = 1;
       
    37 #else
       
    38 const TInt KTestIapId = 6;
       
    39 #endif
       
    40 
       
    41 const TInt KAudioPrefVoipAudioUplink           = 0x05220001;
       
    42 const TInt KAudioPrefVoipAudioUplinkNonSignal  = 0x05230001;
       
    43 const TInt KAudioPrefVoipAudioDownlink         = 0x05210001;
       
    44 const TInt KAudioDTMFString                    = 0x00150001;
       
    45 const TInt KAudioPriorityDTMFString            = 45;
       
    46 
       
    47 const TInt KDefaultQos = 46;
       
    48 _LIT8(KUDPMessage,"UDP_Message"); 
       
    49 
       
    50 const TUint KMediaConnection = 1;
       
    51 
       
    52 // ======== MEMBER FUNCTIONS =================================================
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CMultiplexerUdpTestsInterface::CMultiplexerUdpTestsInterface
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CMultiplexerUdpTests::CMultiplexerUdpTests( CConsoleBase& aConsole,
       
    61     CNcmConnectionMultiplexer& aMux, CMuxTestConsoleStubs& aIFStub ) :
       
    62     iConsole( aConsole ), iMux( aMux ), iIfStub( aIFStub )
       
    63     {
       
    64     }
       
    65     
       
    66 // ---------------------------------------------------------------------------
       
    67 // CMultiplexerUdpTests::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CMultiplexerUdpTests::ConstructL()
       
    72     {
       
    73     RDebug::Print( _L("CMultiplexerUdpTests::ConstructL IAP: %d"), KTestIapId );
       
    74     
       
    75     // Dummy 'cause first uheap marking  
       
    76     TUint sessionId( 0 );
       
    77     TUint streamId( 0 );
       
    78 
       
    79     sessionId = iMux.CreateSessionL( KTestIapId, 5090, 5500 );
       
    80     CActiveScheduler::Start();
       
    81     
       
    82     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
    83 
       
    84     iMux.RegisterIncomingConnectionObserverL( streamId, iIfStub );
       
    85     TUint sub = iMux.CreateConnectionL( streamId, KAfInet );
       
    86     iMux.UnregisterIncomingConnectionObserverL( streamId, iIfStub );
       
    87     iMux.RemoveSessionL( sessionId );    
       
    88     }
       
    89     
       
    90 // ---------------------------------------------------------------------------
       
    91 // CMultiplexerUdpTests::NewL
       
    92 // Static constructor.
       
    93 // ---------------------------------------------------------------------------
       
    94 //   
       
    95 CMultiplexerUdpTests* CMultiplexerUdpTests::NewL( CConsoleBase& aConsole,
       
    96     CNcmConnectionMultiplexer& aMux, CMuxTestConsoleStubs& aIFStub )
       
    97     {
       
    98     CMultiplexerUdpTests* self 
       
    99         = new ( ELeave ) CMultiplexerUdpTests( aConsole, aMux, aIFStub );
       
   100 
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();
       
   103     CleanupStack::Pop( self );
       
   104     return self;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CMultiplexerUdpTests::~CMultiplexerUdpTests
       
   109 // Destructor.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CMultiplexerUdpTests::~CMultiplexerUdpTests()
       
   113     {
       
   114     delete iMccInterface;
       
   115     TRAP_IGNORE( iMux.RemoveSessionL( iSessionId ) );
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CMultiplexerUdpTests::DoRunUdpMuxtTests
       
   120 // 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CMultiplexerUdpTests::DoRunUdpMuxtTests()
       
   124     {
       
   125     iConsole.ClearScreen();
       
   126     iConsole.Printf( _L("\n*** MUX TESTS ***\n") );
       
   127     
       
   128     TInt err( KErrNone );
       
   129     
       
   130     iConsole.Printf( _L("Create session test\n") );
       
   131     RDebug::Print( _L("MUX_TEST_START: TestCreateSessionL") );
       
   132     //__UHEAP_MARK;
       
   133     TRAP( err, TestCreateSessionL() );
       
   134     //__UHEAP_MARKEND;
       
   135     RDebug::Print( _L("MUX_TEST_STOP: TestCreateSessionL, ERR: %d"), err );
       
   136 
       
   137     iConsole.Printf( _L("Create session test\n") );
       
   138     RDebug::Print( _L("MUX_TEST_START: TestCreateSessionL") );
       
   139     __UHEAP_MARK;
       
   140     TRAP( err, TestCreateSessionL() );
       
   141     __UHEAP_MARKEND;
       
   142     RDebug::Print( _L("MUX_TEST_STOP: TestCreateSessionL, ERR: %d"), err );
       
   143     
       
   144     err = KErrNone;
       
   145     RDebug::Print( _L("MUX_TEST_START: TestCreateStreamL") );
       
   146     iConsole.Printf( _L("Create stream test\n") );
       
   147     __UHEAP_MARK;
       
   148     TRAP( err, TestCreateStreamL() );
       
   149     __UHEAP_MARKEND;
       
   150     RDebug::Print( _L("MUX_TEST_STOP: TestCreateStreamL, ERR: %d"), err );
       
   151 
       
   152     err = KErrNone;
       
   153     RDebug::Print( _L("MUX_TEST_START: TestCreateConnectionL") );
       
   154     iConsole.Printf( _L("Create connection test\n") );
       
   155     __UHEAP_MARK;
       
   156     TRAP( err, TestCreateConnectionL() );
       
   157     __UHEAP_MARKEND;
       
   158     RDebug::Print( _L("MUX_TEST_STOP: TestCreateConnectionL, ERR: %d"), err );
       
   159      
       
   160     // After this test again with memory leak check
       
   161     err = KErrNone;
       
   162     RDebug::Print( _L("MUX_TEST_START: TestActivateUdpConnectionsL") );
       
   163     iConsole.Printf( _L("(De)Activate UDP connections test\n") );
       
   164     //__UHEAP_MARK;
       
   165     TRAP( err, TestActivateUdpConnectionsL() );
       
   166     //__UHEAP_MARKEND;
       
   167     RDebug::Print( _L("MUX_TEST_STOP: TestActivateUdpConnectionsL, ERR: %d"), err );
       
   168 
       
   169     // DO same as before... Now check memory leak
       
   170     err = KErrNone;
       
   171     RDebug::Print( _L("MUX_TEST_START: TestActivateUdpConnectionsL") );
       
   172     iConsole.Printf( _L("(De)Activate UDP connections test\n") );
       
   173     __UHEAP_MARK;
       
   174     TRAP( err, TestActivateUdpConnectionsL() );
       
   175     __UHEAP_MARKEND;
       
   176     RDebug::Print( _L("MUX_TEST_STOP: TestActivateUdpConnectionsL, ERR: %d"), err );
       
   177     
       
   178     err = KErrNone;
       
   179     RDebug::Print( _L("MUX_TEST_START: TestActivateStunUdpMediaConnectionsL") );
       
   180     iConsole.Printf( _L("(De)Activate STUN UDP media connections test\n") );
       
   181     __UHEAP_MARK;
       
   182     TRAP( err, TestActivateStunUdpMediaConnectionsL() );
       
   183     __UHEAP_MARKEND;
       
   184     RDebug::Print( _L("MUX_TEST_STOP: TestActivateStunUdpMediaConnectionsL, ERR: %d"), err );  
       
   185     }
       
   186 
       
   187       
       
   188 // ---------------------------------------------------------------------------
       
   189 // CMultiplexerUdpTests::TestCreateSessionL
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CMultiplexerUdpTests::TestCreateSessionL()
       
   193     {
       
   194     TUint sessionId( 0 );
       
   195     TUint sessionId2( 0 );
       
   196     
       
   197     sessionId = iMux.CreateSessionL( 0,5000, 5100 );
       
   198     CActiveScheduler::Start();
       
   199     
       
   200     iMux.RemoveSessionL( sessionId );
       
   201     
       
   202     sessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 );
       
   203     iMux.RemoveSessionL( sessionId );
       
   204     
       
   205     sessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 );
       
   206     iMux.RemoveSessionL( sessionId );
       
   207     
       
   208     sessionId = iMux.CreateSessionL( 0,5000, 5100 );
       
   209     sessionId2 = iMux.CreateSessionL( 0,5000, 5100 );
       
   210     CActiveScheduler::Start();
       
   211     
       
   212     iMux.RemoveSessionL( sessionId );
       
   213     iMux.RemoveSessionL( sessionId2 );
       
   214     
       
   215     
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CMultiplexerUdpTests::TestCreateStreamL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CMultiplexerUdpTests::TestCreateStreamL()
       
   223     {
       
   224     TUint sessionId( 0 );
       
   225     TUint sessionId2( 0 );
       
   226     TUint streamId( 0 );
       
   227     TUint streamId2( 0 );  
       
   228     
       
   229     sessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 ); 
       
   230     CActiveScheduler::Start();
       
   231 
       
   232         
       
   233     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   234     streamId2 = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   235       
       
   236     iMux.RemoveStreamL( streamId ); 
       
   237     iMux.RemoveStreamL( streamId2 );
       
   238 
       
   239     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   240     
       
   241     iMux.RegisterIncomingConnectionObserverL( streamId, iIfStub );
       
   242     iMux.RegisterIncomingConnectionObserverL( streamId, iIfStub );
       
   243     
       
   244     streamId2 = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   245     
       
   246     iMux.RemoveStreamL( streamId );
       
   247     iMux.RemoveSessionL( sessionId );
       
   248     iMux.RemoveSessionL( sessionId2 );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CMultiplexerUdpTests::TestCreateConnectionL
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CMultiplexerUdpTests::TestCreateConnectionL()
       
   256     {
       
   257     TUint sessionId( 0 );
       
   258     
       
   259     TUint streamId( 0 );
       
   260     TUint streamId2( 0 );
       
   261       
       
   262     TUint connectionId( 0 );
       
   263     TUint connectionId2( 0 );
       
   264     TUint connectionId3( 0 );
       
   265     TUint connectionId4( 0 );
       
   266     TUint connectionId5( 0 );
       
   267     
       
   268     sessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 );
       
   269     CActiveScheduler::Start();
       
   270     
       
   271     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   272     streamId2 = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   273     
       
   274     iMux.RegisterIncomingConnectionObserverL(streamId, iIfStub );
       
   275   
       
   276     connectionId = iMux.CreateConnectionL( streamId, KAfInet );
       
   277     connectionId2 = iMux.CreateConnectionL( streamId, KAfInet );  
       
   278     connectionId3 = iMux.CreateConnectionL( streamId2, KAfInet );
       
   279     
       
   280     // New connection, Reuse local address
       
   281     TInetAddr connectionAddr = iMux.LocalIPAddressL( streamId, connectionId2 );
       
   282     connectionId4 = iMux.CreateConnectionL( streamId2, connectionAddr );  
       
   283     // Check success of address reuse
       
   284     TInetAddr connectionAddr2 = iMux.LocalIPAddressL( streamId, connectionId4 );
       
   285     ASSERT( connectionAddr.CmpAddr( connectionAddr2 ) );
       
   286     
       
   287     
       
   288     // New connection, Reuse local address
       
   289     TInetAddr connectionAddr3 = iMux.LocalIPAddressL( streamId, connectionId3 );
       
   290     connectionId5 = iMux.CreateConnectionL( streamId2, connectionAddr3 );
       
   291     // Check success of address reuse
       
   292     TInetAddr connectionAddr5 = iMux.LocalIPAddressL( streamId2, connectionId5 );    
       
   293     ASSERT( connectionAddr3.CmpAddr( connectionAddr5 ) );    
       
   294     
       
   295     // New connection, Reuse local address
       
   296     connectionAddr3 = iMux.LocalIPAddressL( streamId, connectionId3 );
       
   297     connectionId5 = iMux.CreateConnectionL( streamId2, connectionAddr3 );
       
   298     // Check success of address reuse
       
   299     connectionAddr5 = iMux.LocalIPAddressL( streamId2, connectionId5 );    
       
   300     ASSERT( connectionAddr3.CmpAddr( connectionAddr5 ) );  
       
   301         
       
   302     iMux.RemoveConnectionL( streamId2, connectionId5 );
       
   303     iMux.RemoveConnectionL( streamId, connectionId3 );
       
   304     iMux.RemoveStreamL( streamId );
       
   305     iMux.RemoveSessionL( sessionId );    
       
   306     }
       
   307     
       
   308 // ---------------------------------------------------------------------------
       
   309 // CMultiplexerUdpTests::TestActivateUdpConnectionsL
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CMultiplexerUdpTests::TestActivateUdpConnectionsL()
       
   313     {
       
   314     TUint sessionId( 0 );
       
   315     
       
   316     TUint streamId( 0 );
       
   317     TUint streamId2( 0 );
       
   318       
       
   319     TUint connectionId( 0 );
       
   320     TUint connectionId2( 0 );
       
   321     TUint connectionId3( 0 );
       
   322     
       
   323     TInetAddr connectionAddr;
       
   324     TInetAddr connectionAddr2;
       
   325       
       
   326     // Create 1 session, 1 stream, 1 connection
       
   327     sessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 );
       
   328     CActiveScheduler::Start();
       
   329           
       
   330     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   331     connectionId = iMux.CreateConnectionL( streamId, KAfInet );
       
   332     connectionAddr = iMux.LocalIPAddressL( streamId, connectionId );
       
   333 
       
   334     // Test connection
       
   335     streamId2 = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   336     connectionId2 = iMux.CreateConnectionL( streamId2, KAfInet );
       
   337     connectionAddr2 = iMux.LocalIPAddressL( streamId2, connectionId2 );
       
   338     
       
   339     iMux.RegisterIncomingConnectionObserverL( streamId, iIfStub );
       
   340     iMux.RegisterOutgoingConnectionObserverL( streamId, iIfStub );
       
   341     iMux.RegisterConnectionObserverL( streamId, iIfStub );
       
   342     iMux.RegisterMessageObserverL( streamId, iIfStub );
       
   343     
       
   344     // Activate receiving -> passivate receiving    
       
   345     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStateActive );
       
   346     CActiveScheduler::Start();   
       
   347     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStatePassive );
       
   348     CActiveScheduler::Start();
       
   349     
       
   350     // Activate sending -> passivate sending    
       
   351     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStateActive ); 
       
   352     CActiveScheduler::Start();    
       
   353     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStatePassive ); 
       
   354     CActiveScheduler::Start();    
       
   355   
       
   356      // Activate receiving/sending -> passivate receiving/sending    
       
   357     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStateActive );
       
   358     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStateActive );    
       
   359     CActiveScheduler::Start();    
       
   360     CActiveScheduler::Start(); 
       
   361     
       
   362     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStatePassive );   
       
   363     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStatePassive );;  
       
   364     CActiveScheduler::Start();   
       
   365     CActiveScheduler::Start();
       
   366 
       
   367      // Activate receiving/sending -> activate sending again with different destination address 
       
   368     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStateActive );
       
   369     iMux.SetSendingStateL( streamId, connectionId, connectionAddr, EStreamingStateActive );
       
   370     CActiveScheduler::Start();    
       
   371     CActiveScheduler::Start();    
       
   372     
       
   373     // Set sending again
       
   374     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStateActive );
       
   375     CActiveScheduler::Start(); 
       
   376     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStateActive );
       
   377     CActiveScheduler::Start(); 
       
   378            
       
   379     // Set receiving again
       
   380     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStateActive );
       
   381     CActiveScheduler::Start();
       
   382     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStateActive );
       
   383     CActiveScheduler::Start(); 
       
   384      
       
   385     iMux.SetSendingStateL( streamId, connectionId, connectionAddr2, EStreamingStatePassive );  
       
   386     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStatePassive );
       
   387     CActiveScheduler::Start();  
       
   388     CActiveScheduler::Start();
       
   389              
       
   390     iMux.RemoveSessionL( sessionId );    
       
   391 
       
   392     }
       
   393 
       
   394   
       
   395 // ---------------------------------------------------------------------------
       
   396 // CMultiplexerUdpTests::TestActivateStunUdpMediaConnectionsL
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 void CMultiplexerUdpTests::TestActivateStunUdpMediaConnectionsL()
       
   400     {
       
   401     TUint sessionId( 0 );
       
   402     
       
   403     TUint streamId( 0 );
       
   404     TUint streamId2( 0 );
       
   405       
       
   406     TUint connectionId( 0 );
       
   407     TUint connectionId2( 0 );
       
   408     TUint connectionId3( 0 );
       
   409     
       
   410     sessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 );
       
   411     CActiveScheduler::Start();
       
   412     
       
   413     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   414     streamId2 = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   415     
       
   416     // Simulate UDP fetch candidate    
       
   417     iMux.RegisterIncomingConnectionObserverL( streamId, iIfStub );
       
   418     iMux.RegisterConnectionObserverL( streamId, iIfStub );
       
   419     
       
   420     connectionId = iMux.CreateConnectionL( streamId, KAfInet );
       
   421     
       
   422     // Test connection
       
   423     connectionId2 = iMux.CreateConnectionL( streamId, KAfInet );  
       
   424     TInetAddr connectionAddress2( iMux.LocalIPAddressL( streamId, connectionId2 ) );
       
   425 
       
   426     /**** setup wrapper *****/
       
   427     CNATFWSocketMediaConnWrapper* mediaWrapper = CNATFWSocketMediaConnWrapper::NewL(
       
   428              iMux.PortStoreL( sessionId ).Port(), KProtocolInetUdp, streamId );
       
   429        
       
   430     iMux.RegisterMediaWrapperL( mediaWrapper );
       
   431             
       
   432     TInetAddr destinationAddress;    
       
   433     mediaWrapper->OutgoingAddr( destinationAddress );    
       
   434     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- Wrapper LOCAL ADDRESS: ", destinationAddress )
       
   435 
       
   436     
       
   437     mediaWrapper->SetIncomingAddrL( destinationAddress );
       
   438 
       
   439     TInetAddr stunServerAddress;
       
   440     stunServerAddress.SetAddress( INET_ADDR( 10,36,7,6 ) );
       
   441     stunServerAddress.SetPort( 3478 );
       
   442     
       
   443     iMux.SetReceivingStateL( streamId, connectionId, EStreamingStateActive );
       
   444     iMux.SetSendingStateL( streamId, connectionId, stunServerAddress, EStreamingStateActive );
       
   445     CActiveScheduler::Start();    
       
   446     CActiveScheduler::Start();
       
   447     
       
   448     // Binding request
       
   449     _LIT8(KUDPMessage,"UDP_Binding_Request");
       
   450     iMux.SendL( streamId, connectionId, KUDPMessage, NULL );
       
   451     
       
   452     // Setup media flow to peer
       
   453     // NATFW client
       
   454     iMux.SetReceivingStateForMediaL( streamId, connectionId, EStreamingStateActive );
       
   455     CActiveScheduler::Start();
       
   456    
       
   457     // STUN plugin, reuse connection.. connect to peer address
       
   458     iMux.SetSendingStateL( streamId, connectionId, connectionAddress2, EStreamingStateActive );
       
   459 
       
   460     // NATFW client
       
   461     iMux.SetSendingStateForMediaL( streamId, connectionId, EStreamingStateActive );
       
   462     CActiveScheduler::Start(); 
       
   463     CActiveScheduler::Start(); 
       
   464 
       
   465     iMux.SendL( streamId, connectionId, KUDPMessage, &iIfStub );
       
   466     iMux.SendL( streamId, connectionId, KUDPMessage, connectionAddress2, &iIfStub );
       
   467     CActiveScheduler::Start(); 
       
   468     CActiveScheduler::Start();   
       
   469     
       
   470     iMux.RemoveSessionL( sessionId );    
       
   471     }
       
   472   
       
   473   
       
   474   
       
   475 // ---------------------------------------------------------------------------
       
   476 // CMultiplexerUdpTests::TestUdpAudioL
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 void CMultiplexerUdpTests::TestUdpAudioStreamingL()
       
   480     {
       
   481     TUint sessionId( 0 );  
       
   482     TUint streamId( 0 );
       
   483     TUint streamId2( 0 );
       
   484     // UDP SESSIO
       
   485     RDebug::Print( _L("CMultiplexerUdpTests::TestUdpAudioL - start") );
       
   486     
       
   487     iSessionId = iMux.CreateSessionL( KTestIapId, 5000, 5100 );
       
   488     sessionId = iSessionId;
       
   489     CActiveScheduler::Start();
       
   490     
       
   491         
       
   492     // STREAM
       
   493     streamId = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   494     TUint connectionId2 = iMux.CreateConnectionL( streamId, KAfInet );
       
   495     
       
   496     // STREAM 2
       
   497     streamId2 = iMux.CreateStreamL( sessionId, KDefaultQos, KProtocolInetUdp );
       
   498     TUint connectionId = iMux.CreateConnectionL( streamId2, KAfInet );
       
   499     
       
   500     // Get local IP that receives media
       
   501     TInetAddr receiveMediaAddress;
       
   502     receiveMediaAddress = iMux.LocalIPAddressL( streamId, connectionId2 );
       
   503     
       
   504     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- LOCAL ADDRESS: ", receiveMediaAddress )
       
   505 
       
   506     // WRAPPER
       
   507     CNATFWSocketMediaConnWrapper* mediaWrapper = CNATFWSocketMediaConnWrapper::NewL(
       
   508             iMux.PortStoreL( sessionId ).Port(), KProtocolInetUdp, streamId );          
       
   509             
       
   510     iMux.RegisterMediaWrapperL( mediaWrapper );
       
   511 
       
   512     TInetAddr destinationAddress;
       
   513     //destinationAddress = receiveMediaAddress;
       
   514     //destinationAddress.SetPort( port);
       
   515     mediaWrapper->OutgoingAddr( destinationAddress );
       
   516         
       
   517     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- Wrapper LOCAL ADDRESS: ", destinationAddress )
       
   518 
       
   519 
       
   520 
       
   521     // NET settings value
       
   522     iNetsettings.iRemoteAddress.SetAddress( destinationAddress.Address() );
       
   523     iNetsettings.iRemoteAddress.SetPort( destinationAddress.Port() );
       
   524     iNetsettings.iRemoteRtcpPort = KDefaultRtcpPort;
       
   525     
       
   526     iNetsettings.iLocalAddress.SetAddress( KInetAddrAny );
       
   527     iNetsettings.iLocalAddress.SetPort( KDefaultRtpPort );
       
   528   
       
   529     iNetsettings.iLocalPublicAddress.SetAddress( KInetAddrAny );
       
   530     iNetsettings.iLocalRtcpPort = KDefaultRtcpPort;
       
   531     iNetsettings.iLocalPublicRtcpPort = KDefaultRtcpPort;
       
   532     iNetsettings.iMediaQosValue = KDefaultMediaQos;
       
   533     iNetsettings.iIapId = KTestIapId;
       
   534     
       
   535     TUint32 sessionId1;
       
   536     iMccInterface = CMccInterface::NewL( iIfStub );     
       
   537     User::LeaveIfError( iMccInterface->CreateSession( sessionId1 ) );
       
   538     
       
   539 
       
   540     // Create MCC LINK
       
   541     TUint32 linkId;
       
   542     User::LeaveIfError( iMccInterface->CreateLink( sessionId1, KMccLinkGeneral, linkId, iNetsettings ) ); 
       
   543       
       
   544     CActiveScheduler::Start();
       
   545     
       
   546 
       
   547     iNetsettings.iRemoteAddress.SetAddress( destinationAddress.Address() );
       
   548     iNetsettings.iRemoteAddress.SetPort( destinationAddress.Port() );
       
   549     
       
   550         
       
   551     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- iNetsettings.iRemoteAddress: ", iIfStub.NetSettings().iRemoteAddress )
       
   552     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- iNetsettings.iLocalAddress: ", iIfStub.NetSettings().iLocalAddress )
       
   553 
       
   554     User::LeaveIfError( iMccInterface->SetRemoteAddress( sessionId1, linkId, iNetsettings.iRemoteAddress ) );
       
   555     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- iNetsettings.iLocalAddress: ", iIfStub.NetSettings().iLocalAddress)
       
   556 
       
   557 
       
   558     RPointerArray<CMccCodecInformation> codecArray;
       
   559     CleanupResetAndDestroy< RPointerArray<CMccCodecInformation> >::PushL( codecArray );
       
   560     User::LeaveIfError( iMccInterface->GetCapabilities( codecArray ) );
       
   561 
       
   562     
       
   563     
       
   564     // Create upstream
       
   565     TUint32 upStream;
       
   566     TUint32 dataSinkId1;
       
   567     TUint32 dataSourceId1;
       
   568     User::LeaveIfError( iMccInterface->AddDataSink( KMccRtpSinkUid, KNullDesC8, dataSinkId1 ) );
       
   569     User::LeaveIfError( iMccInterface->AddDataSource( KUidMmfAudioInput, KNullDesC8, dataSourceId1 ) );
       
   570     codecArray[0]->SetPriorityPreference( KAudioPrefVoipAudioUplink );
       
   571     User::LeaveIfError( iMccInterface->CreateStream( sessionId1, linkId, upStream, 
       
   572         KMccAudioUplinkStream, *codecArray[0] ) );
       
   573 
       
   574     // Create downstream
       
   575     TUint32 downStream;
       
   576     TUint32 dataSinkId2;
       
   577     TUint32 dataSourceId2;
       
   578     User::LeaveIfError( iMccInterface->AddDataSink( KUidMmfAudioOutput, KNullDesC8, dataSinkId2 ) );
       
   579     User::LeaveIfError( iMccInterface->AddDataSource( KMccRtpSourceUid, KNullDesC8, dataSourceId2 ) );
       
   580     codecArray[0]->SetPriorityPreference( KAudioPrefVoipAudioDownlink );
       
   581     User::LeaveIfError( iMccInterface->CreateStream( sessionId1, linkId, downStream,
       
   582         KMccAudioDownlinkStream, *codecArray[0] ) );
       
   583 
       
   584 
       
   585     // Set destination address to wrapper
       
   586      __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- iNetsettings.iLocalAddress: ", iIfStub.NetSettings().iLocalAddress )
       
   587     mediaWrapper->SetIncomingAddrL( iIfStub.NetSettings().iLocalAddress);
       
   588 
       
   589     mediaWrapper->SetReceivingStateL( EStreamingStateActive );
       
   590     mediaWrapper->SetSendingStateL( EStreamingStateActive );
       
   591 
       
   592     // Address resolving
       
   593     TInetAddr streamAddr;
       
   594     TInetAddr streamAddr2;
       
   595     
       
   596     streamAddr = iMux.LocalIPAddressL( streamId, 1 );
       
   597     streamAddr2 = iMux.LocalIPAddressL( streamId2, 1 );
       
   598     
       
   599     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL - receiver - streamAddr: ", streamAddr )
       
   600     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- sender - streamAddr2: ", streamAddr2 )
       
   601     __CONNECTIONMULTIPLEXER_ADDRLOG( "CMultiplexerUdpTests::TestUdpAudioL- iNetsettings.iLocalAddress: ", iIfStub.NetSettings().iLocalAddress )
       
   602     
       
   603     // Connect internal two streams
       
   604     //iMux.SetReceivingStateL( streamId2, connectionId, EStreamingStateActive );  
       
   605     //iMux.SetSendingStateL( streamId2, connectionId, streamAddr, EStreamingStateActive );
       
   606 
       
   607     iMux.SetReceivingStateL( streamId, KMediaConnection, EStreamingStateActive );  
       
   608     iMux.SetSendingStateL( streamId, KMediaConnection, streamAddr/*2*/, EStreamingStateActive );
       
   609 
       
   610     
       
   611     iMux.RegisterIncomingConnectionObserverL( streamId/*2*/, iIfStub );
       
   612     iMux.RegisterOutgoingConnectionObserverL( streamId/*2*/, iIfStub );
       
   613 
       
   614 
       
   615     RDebug::Print( _L("CMultiplexerUdpTests::TestUdpAudioL - after prepare stream1") );
       
   616          
       
   617     User::LeaveIfError( iMccInterface->PrepareStream( sessionId1, linkId, upStream ) );
       
   618     CActiveScheduler::Start();
       
   619    CActiveScheduler::Start();    
       
   620 
       
   621     RDebug::Print( _L("CMultiplexerUdpTests::TestUdpAudioL - before prepare stream2") );
       
   622     // Prepare and start up and downstream  
       
   623     User::LeaveIfError( iMccInterface->PrepareStream( sessionId1, linkId, downStream ) );
       
   624     CActiveScheduler::Start();
       
   625     CActiveScheduler::Start();
       
   626         
       
   627     RDebug::Print( _L("CMultiplexerUdpTests::TestUdpAudioL - after start stream1") );
       
   628        
       
   629     User::LeaveIfError( iMccInterface->StartStream( sessionId1, linkId, upStream ) );
       
   630     CActiveScheduler::Start();
       
   631     CActiveScheduler::Start();
       
   632     
       
   633 
       
   634     
       
   635     RDebug::Print( _L("CMultiplexerUdpTests::TestUdpAudioL - after prepare stream2") );
       
   636    
       
   637     User::LeaveIfError( iMccInterface->StartStream( sessionId1, linkId, downStream ) );
       
   638     CActiveScheduler::Start();
       
   639     CActiveScheduler::Start();
       
   640 
       
   641     RDebug::Print( _L("CMultiplexerUdpTests::TestUdpAudioL - end") );   
       
   642     CleanupStack::PopAndDestroy( &codecArray );
       
   643     //iMux.RemoveStreamL( streamId );
       
   644     }