コード例 #1
0
ファイル: TestNetwork.cpp プロジェクト: chinshou/ohNet
void TestNetwork(const std::vector<Brn>& aArgs)
{
    OptionParser parser;
    OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");
    parser.AddOption(&adapter);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }

    std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(Net::InitialisationParams::ELoopbackUse, "TestNetwork");
    ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size());
    TIpAddress addr = (*ifs)[adapter.Value()]->Address();
    for (TUint i=0; i<ifs->size(); i++) {
        (*ifs)[i]->RemoveRef("TestNetwork");
    }
    delete ifs;
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Using network interface %s\n\n", buf.Ptr());
    Thread* th = new MainNetworkTestThread(addr);
    th->Start();
    th->Wait();
    delete th;
}
コード例 #2
0
static void LogSubnet(const TChar* aPrefix, TIpAddress aSubnet)
{
    Endpoint endpt(0, aSubnet);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("%s: subnet=%s\n", aPrefix, buf.Ptr());
}
コード例 #3
0
ファイル: TestShell.cpp プロジェクト: DoomHammer/ohNet
void OpenHome::TestFramework::Runner::Main(TInt /*aArgc*/, TChar* /*aArgv*/[], Net::InitialisationParams* aInitParams)
{
    Library* lib = new Library(aInitParams);
    std::vector<NetworkAdapter*>* subnetList = lib->CreateSubnetList();
    TIpAddress subnet = (*subnetList)[0]->Subnet();
    TIpAddress addr = (*subnetList)[0]->Address();
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Connect to %s:%u then 'help' for options\n\n", buf.Ptr(), Shell::kServerPortDefault);
    Library::DestroySubnetList(subnetList);
    CpStack* cpStack = NULL;
    DvStack* dvStack = NULL;
    lib->StartCombined(subnet, cpStack, dvStack);

    Shell* shell = new Shell(cpStack->Env());
    Semaphore* blocker = new Semaphore("BLCK", 0);

    std::vector<ShellTest> shellTests;
    shellTests.push_back(ShellTest("TestBuffer", RunTestBuffer));
    shellTests.push_back(ShellTest("TestThread", RunTestThread));
    shellTests.push_back(ShellTest("TestFifo", RunTestFifo));
    shellTests.push_back(ShellTest("TestQueue", RunTestQueue));
    shellTests.push_back(ShellTest("TestTextUtils", RunTestTextUtils));
    shellTests.push_back(ShellTest("TestNetwork", RunTestNetwork, true));
    shellTests.push_back(ShellTest("TestTimer", RunTestTimer));
    shellTests.push_back(ShellTest("TestSsdpMListen", RunTestSsdpMListen, true));
    shellTests.push_back(ShellTest("TestSsdpUListen", RunTestSsdpUListen, true));
    shellTests.push_back(ShellTest("TestDeviceList", RunTestDeviceList, true));
    shellTests.push_back(ShellTest("TestInvocation", RunTestInvocation));
    shellTests.push_back(ShellTest("TestSubscription", RunTestSubscription));
    shellTests.push_back(ShellTest("TestCpDeviceDv", RunTestCpDeviceDv));
    shellTests.push_back(ShellTest("TestDviDiscovery", RunTestDviDiscovery));
    shellTests.push_back(ShellTest("TestDviDeviceList", RunTestDviDeviceList));
    shellTests.push_back(ShellTest("TestDvInvocation", RunTestDvInvocation));
    shellTests.push_back(ShellTest("TestDvSubscription", RunTestDvSubscription));
    shellTests.push_back(ShellTest("TestDvLpec", RunTestDvLpec));
    shellTests.push_back(ShellTest("TestException", RunTestException));
    shellTests.push_back(ShellTest("TestFunctorGeneric", RunTestFunctorGeneric));
    shellTests.push_back(ShellTest("TestXmlParser", RunTestXmlParser));

    ShellCommandRun* cmdRun = new ShellCommandRun(*cpStack, *dvStack, *shell, shellTests);
    ShellCommandDebug* cmdDebug = new ShellCommandDebug(*shell);
    ShellCommandQuit* cmdQuit = new ShellCommandQuit(*shell, *blocker);
    ShellCommandWatchDog* cmdWatchDog = new ShellCommandWatchDog(*shell, 60); // default to 60s watchdog. This can be changed at runtime by client.
    blocker->Wait();
    // control never reaches here
    delete blocker;
    delete cmdWatchDog;
    delete cmdQuit;
    delete cmdDebug;
    delete cmdRun;
    delete shell;
    delete lib;
}
コード例 #4
0
ファイル: TestSsdpMListen.cpp プロジェクト: astaykov/ohNet
TIpAddress SuiteListen::NetworkIf(TUint aIndex)
{
    const std::vector<NetworkAdapter*>& ifs = Stack::NetworkAdapterList().List();
    ASSERT(ifs.size() > 0 && aIndex < ifs.size());
    TIpAddress addr = ifs[aIndex]->Address();
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Using network interface %s\n\n", buf.Ptr());
    return ifs[aIndex]->Address();
}
コード例 #5
0
static TIpAddress NetworkIf(Environment& aEnv, TUint aIndex)
{
    const std::vector<NetworkAdapter*>& ifs = aEnv.NetworkAdapterList().List();
    ASSERT(ifs.size() > 0 && aIndex < ifs.size());
    TIpAddress addr = ifs[aIndex]->Address();
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Using network interface %s\n\n", buf.Ptr());
    return ifs[aIndex]->Address();
}
コード例 #6
0
ファイル: OhNet.cpp プロジェクト: cedric-andrieu/ohNet
void NetworkAdapter::ListObjectDetails() const
{
    Endpoint ep(0, iAddress);
    Endpoint::AddressBuf buf;
    ep.AppendAddress(buf);
    Log::Print("  NetworkAdapter: addr=%p, ip=%s", this, buf.Ptr());
    ep.SetAddress(iNetMask);
    buf.SetBytes(0);
    ep.AppendAddress(buf);
    Log::Print(", netmask=%s, name=%s, cookies={", buf.Ptr(), iName.Ptr());
    for (TUint i=0; (TUint)i<iCookies.size(); i++) {
        const char* cookie = ((iCookies[i] == NULL || strlen(iCookies[i]) == 0) ? "[none]" : iCookies[i]);
        Log::Print(" %s", cookie);
    }
    Log::Print(" }\n");
}
コード例 #7
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams)
{
    OptionParser parser;

    OptionUint duration("-d", "--duration", 30, "Number of seconds to run the test");
    OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");

    parser.AddOption(&duration);
    parser.AddOption(&adapter);

    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }

    UpnpLibrary::Initialise(aInitParams);
    std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(false, "TestTopology3");
    ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size());
    TIpAddress subnet = (*ifs)[adapter.Value()]->Subnet();
    for (TUint i=0; i<ifs->size(); i++) {
        (*ifs)[i]->RemoveRef("TestTopology3");
    }
    delete ifs;
    UpnpLibrary::StartCp(subnet);

    Endpoint endpt(0, subnet);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Using network interface %s\n\n", buf.Ptr());

    // Debug::SetLevel(Debug::kTopology);
    // Debug::SetLevel(Debug::kAll);

    TopologyLogger logger;

    CpTopology3* topology = new CpTopology3(logger);

    if (topology != NULL) {
        Blocker* blocker = new Blocker;
        blocker->Wait(duration.Value());
        delete blocker;
    }

    delete topology;

    UpnpLibrary::Close();

}
コード例 #8
0
ファイル: TestEcho.cpp プロジェクト: astaykov/ohNet
void OpenHome::TestFramework::Runner::Main(TInt /*aArgc*/, TChar* /*aArgv*/[], Net::InitialisationParams* aInitParams)
{
    Net::UpnpLibrary::Initialise(aInitParams);
//    Debug::SetLevel(Debug::kNetwork);

    std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(false, "TestEcho");
    ASSERT(ifs->size() > 0);
    TIpAddress addr = (*ifs)[0]->Address();
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    for (TUint i=0; i<ifs->size(); i++) {
        (*ifs)[i]->RemoveRef("TestEcho");
    }
    Print("Using network interface %s\n\n", buf.Ptr());
    Semaphore sem("", 0);
    SocketTcpServer* server = new SocketTcpServer("ECHO", 1025, addr);
    server->Add("ECHO", new EchoSession(sem));

    sem.Wait();
    delete ifs;

    Net::UpnpLibrary::Close();
}
コード例 #9
0
ファイル: TestMulticast.cpp プロジェクト: tata-/ohNet-1
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams)
{
    OptionParser parser;    

    OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");
    parser.AddOption(&adapter);

    OptionBool send("-s", "--send", "Send");
    parser.AddOption(&send);

    OptionString endpoint("-a", "--address", Brn("239.255.255.250"), "Multicast address");
    parser.AddOption(&endpoint);

    OptionUint port("-p", "--port", 1968, "Multicast port");
    parser.AddOption(&port);

    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }

    Net::UpnpLibrary::InitialiseMinimal(aInitParams);

    std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(*Net::gStack, Net::InitialisationParams::ELoopbackExclude, "TestMulticast");
    ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size());
    TIpAddress addr = (*ifs)[adapter.Value()]->Address();
    for (TUint i=0; i<ifs->size(); i++) {
        (*ifs)[i]->RemoveRef("TestMulticast");
    }
    delete ifs;
    Endpoint endpt(0, addr);
    Endpoint::AddressBuf buf;
    endpt.AppendAddress(buf);
    Print("Using network interface %s\n\n", buf.Ptr());
    
    Endpoint multicast(port.Value(), endpoint.Value());
    
    if (send.Value() == false) {
        SocketUdpMulticast socket(addr, multicast);

        Endpoint actual(socket.Port(), multicast.Address());
        Bws<100> buf2;
        actual.AppendEndpoint(buf2);
        Print("Receiving from multicast endpoint %s\n", buf2.Ptr());
    
        Bwh message(10000);
        Endpoint sender = socket.Receive(message);
        Bws<100> buf3;
        sender.AppendEndpoint(buf3);
        
        if (message == Brn("Test message")) {
            Print("Received test messsge from %s\n", buf3.Ptr());
        }
        else {
            Print("Received unrecognised messsge from %s\n", buf3.Ptr());
        }
    }
    else {
        if (multicast.Port() == 0) {
            Print("Cannot send to port 0\n");
        }
        else {
            Bws<100> buf2;
            multicast.AppendEndpoint(buf2);
            Print("Sending test message to %s\n", buf2.Ptr());
        
            //SocketUdpMulticast socket(addr, multicast);
            SocketUdp socket(0, addr);
            
            socket.Send(Brn("Test message"), multicast);
        }
    } 

    Net::UpnpLibrary::Close();
}