Beispiel #1
0
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;
}
Beispiel #2
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams)
{
    OptionParser parser;
    OptionBool loopback("-l", "--loopback", "Use the loopback adapter only");
    parser.AddOption(&loopback);
    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }
    if (loopback.Value()) {
        aInitParams->SetUseLoopbackNetworkInterface();
    }
    UpnpLibrary::Initialise(aInitParams);
    UpnpLibrary::StartCombined();
    //Debug::SetLevel(Debug::kDevice/*Debug::kXmlFetch | Debug::kHttp*/);

    Print("TestDviDeviceList - starting\n");

    DvDevices* devices = new DvDevices;
    CpDevices* deviceList = new CpDevices;
    FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed);

    Print("Count devices implementing service1\n");
    Brn domainName("a.b.c");
    Brn serviceType("service1");
    TUint ver = 1;
    CpDeviceListUpnpServiceType* list =
                new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed);
    Blocker* blocker = new Blocker;
    blocker->Wait(aInitParams->MsearchTimeSecs());
    std::vector<const char*> udns;
    udns.push_back((const char*)gNameDevice1.Ptr());
    udns.push_back((const char*)gNameDevice2.Ptr());
    deviceList->Validate(udns);
    udns.clear();
    delete list;
    deviceList->Clear();

    Print("Count devices implementing service2\n");
    serviceType.Set("service2");
    list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed);
    blocker->Wait(aInitParams->MsearchTimeSecs());
    udns.push_back((const char*)gNameDevice1_1.Ptr());
    udns.push_back((const char*)gNameDevice2.Ptr());
    deviceList->Validate(udns);
    udns.clear();
    delete list;

    delete blocker;
    delete deviceList;
    delete devices;

    Print("TestDviDeviceList - completed\n");
    UpnpLibrary::Close();
}
Beispiel #3
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams)
{
    OptionParser parser;
    OptionBool loopback("-l", "--loopback", "Use the loopback adapter only");
    parser.AddOption(&loopback);
    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }
    if (loopback.Value()) {
        aInitParams->SetUseLoopbackNetworkAdapter();
    }
    aInitParams->SetMsearchTime(1);
    aInitParams->SetDvUpnpServerPort(0);
    UpnpLibrary::Initialise(aInitParams);
    std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList();
    TIpAddress subnet = (*subnetList)[0]->Subnet();
    UpnpLibrary::DestroySubnetList(subnetList);
    UpnpLibrary::StartCombined(subnet);
    //Debug::SetLevel(Debug::kEvent | Debug::kDvEvent);

    Print("TestDvDeviceStd - starting\n");

    Semaphore* sem = new Semaphore("SEM1", 0);
    DeviceBasic* device = new DeviceBasic(DeviceBasic::eProtocolUpnp);
    CpDevices* deviceList = new CpDevices(device->Device().Udn(), *sem);
    FunctorCpDeviceCpp added = MakeFunctorCpDeviceCpp(*deviceList, &CpDevices::Added);
    FunctorCpDeviceCpp removed = MakeFunctorCpDeviceCpp(*deviceList, &CpDevices::Removed);
    std::string domainName("openhome.org");
    std::string serviceType("TestBasic");
    TUint ver = 1;
    CpDeviceListCppUpnpServiceType* list =
                new CpDeviceListCppUpnpServiceType(domainName, serviceType, ver, added, removed);
    sem->Wait(30*1000); // allow up to 30s to find our one device
    try {
        deviceList->TestActions();
        Functor cb = MakeFunctor(sem, &DeviceDisabled);
        device->Device().SetDisabled(cb);
        sem->Wait();
        deviceList->TestThrows();
        device->Device().SetEnabled();
        deviceList->TestSubscriptions();
    }
    catch (Exception& e) {
        Print("Exception %s from %s:%u\n", e.Message(), e.File(), e.Line());
        ASSERTS();
    }
    delete sem;
    delete list;
    delete deviceList;
    delete device;

    Print("TestDvDeviceStd - completed\n");
    UpnpLibrary::Close();
}
Beispiel #4
0
void TestSsdpMListen(const std::vector<Brn>& aArgs)
{
    OptionParser parser;
    OptionUint duration("-d", "--duration", 30, "Number of seconds to listen for.  Defaults to 30");
    parser.AddOption(&duration);
    OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");
    parser.AddOption(&adapter);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }

    Runner runner("SSDP multicast listener\n");
    runner.Add(new SuiteListen(duration.Value(), adapter.Value()));
    runner.Run();
}
void TestTopology2(Environment& aEnv, const std::vector<Brn>& aArgs)
{
    if( find(aArgs.begin(), aArgs.end(), Brn("--path")) == aArgs.end() )
    {
        Log::Print("No path supplied!\n");
        ASSERTS();
    }

    OptionParser parser;
    OptionString optionServer("-s", "--server", Brn("eng"), "address of server to connect to");
    parser.AddOption(&optionServer);
    OptionUint optionPort("-p", "--port", 80, "server port to connect on");
    parser.AddOption(&optionPort);
    OptionString optionPath("", "--path", Brn(""), "path to use on server");
    parser.AddOption(&optionPath);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }

    TUint port = optionPort.Value();
    ASSERT(port <= 65535);

    Bwh uriBuf(100);
    Endpoint endptServer = Endpoint(port, optionServer.Value());
    uriBuf.Replace(Brn("http://"));
    endptServer.AppendEndpoint(uriBuf);
    uriBuf.Append(Brn("/"));
    uriBuf.Append(optionPath.Value());
    Uri uri(uriBuf);

    auto reader = new HttpReader(aEnv);
    TUint code = reader->Connect(uri);

    if ((code < HttpStatus::kSuccessCodes) || (code >= HttpStatus::kRedirectionCodes))
    {
        Log::Print("Failed to connect \n");
        ASSERTS();
    }

    ReaderUntilS<1024>* readerUntil = new ReaderUntilS<1024>(*reader);

    Runner runner("Topology2 tests\n");
    runner.Add(new SuiteTopology2(*readerUntil));
    runner.Run();

    delete readerUntil;
    delete reader;
}
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();

}
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams)
{
    OptionParser parser;
    OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    OptionBool refresh("-f", "--refresh", "Wait mx secs then refresh list");
    parser.AddOption(&refresh);
    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }

    if (mx.Value() != 0) {
        aInitParams->SetMsearchTime(mx.Value());
    }
    
    UpnpLibrary::Initialise(aInitParams);
    std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList();
    TIpAddress subnet = (*subnetList)[0]->Subnet();
    UpnpLibrary::DestroySubnetList(subnetList);
    UpnpLibrary::StartCp(subnet);

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

    TopologyLogger logger;

    CpTopology1* topology = new CpTopology1(logger);

    if (topology != NULL) {
        Blocker* blocker = new Blocker;
        blocker->Wait(aInitParams->MsearchTimeSecs());
        delete blocker;
    }
    if (refresh.Value()) {
        Blocker* blocker = new Blocker;
        blocker->Wait(mx.Value());
        Print("\nRefreshing...\n\n");
        topology->Refresh();
        blocker->Wait(mx.Value());
        delete blocker;
    }
    
    delete topology;

    UpnpLibrary::Close();
}
Beispiel #8
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams)
{
    std::vector<Brn> args = OptionParser::ConvertArgs(aArgc, aArgv);

    OptionParser parser;
    OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    if (!parser.Parse(args, true) || parser.HelpDisplayed()) {
        return;
    }

    if (mx.Value() != 0) {
        aInitParams->SetMsearchTime(mx.Value());
    }
    Library* lib = new Net::Library(aInitParams);

    TestSsdpUListen(lib->Env(), args);

    delete lib;
}
Beispiel #9
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams)
{
    std::vector<Brn> args = OptionParser::ConvertArgs(aArgc, aArgv);

    OptionParser parser;
    OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    if (!parser.Parse(args, true) || parser.HelpDisplayed()) {
        return;
    }

    if (mx.Value() != 0) {
        aInitParams->SetMsearchTime(mx.Value());
    }
    UpnpLibrary::Initialise(aInitParams);
    std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList();
    TIpAddress subnet = (*subnetList)[0]->Subnet();
    UpnpLibrary::DestroySubnetList(subnetList);
    UpnpLibrary::StartCp(subnet);

    TestSsdpUListen(args);

    UpnpLibrary::Close();
}
Beispiel #10
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams)
{
    OptionParser parser;
    OptionBool loopback("-l", "--loopback", "Use the loopback adapter only");
    parser.AddOption(&loopback);
    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }
    if (loopback.Value()) {
        aInitParams->SetUseLoopbackNetworkAdapter();
    }
    aInitParams->SetDvUpnpServerPort(0);
    Library* lib = new Library(aInitParams);
    std::vector<NetworkAdapter*>* subnetList = lib->CreateSubnetList();
    TIpAddress subnet = (*subnetList)[0]->Subnet();
    Library::DestroySubnetList(subnetList);
    CpStack* cpStack = NULL;
    DvStack* dvStack = NULL;
    lib->StartCombined(subnet, cpStack, dvStack);

    TestDvSubscription(*cpStack, *dvStack);

    delete lib;
}
Beispiel #11
0
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams)
{
    OptionParser parser;
    Brn emptyString("");
    OptionString config("-c", "--config", emptyString, "[full dir path] to folder containing web UI");
    parser.AddOption(&config);
    OptionBool loopback("-l", "--loopback", "Use the loopback adapter only");
    parser.AddOption(&loopback);
    if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) {
        return;
    }
    if (config.Value().Bytes() == 0) {
        parser.DisplayHelp();
        return;
    }

    if (loopback.Value()) {
        aInitParams->SetUseLoopbackNetworkAdapter();
    }
    aInitParams->SetDvNumWebSocketThreads(5);
    aInitParams->SetDvWebSocketPort(54320);
    aInitParams->SetDvUpnpServerPort(0);
    UpnpLibrary::Initialise(aInitParams);
    Debug::SetLevel(Debug::kDvWebSocket | Debug::kError | Debug::kDvInvocation | Debug::kDvEvent | Debug::kDvDevice);
    UpnpLibrary::StartDv();

    Print("TestDvTestBasic - starting ('q' to quit)\n");
    DeviceBasic* device = new DeviceBasic(config.Value());
    while (getchar() != 'q') {
        ;
    }
    delete device;
    Print("TestDvTestBasic - exiting\n");

    UpnpLibrary::Close();
}
Beispiel #12
0
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();
}
Beispiel #13
0
void TestDeviceList(const std::vector<Brn>& aArgs)
{
    OptionParser parser;
    OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    OptionBool all("-a", "--all", "Search for all devices and services");
    parser.AddOption(&all);
    OptionBool root("-r", "--root", "Search for root devices only");
    parser.AddOption(&root);
    Brn emptyString("");
    OptionString uuid("-u", "--uuid", emptyString, "[uuid string] search for a particular device");
    parser.AddOption(&uuid);
    OptionString urn("-t", "--urn", emptyString, "Search for a device or service of the form [domain:[device|service]:type:ver]");
    parser.AddOption(&urn);
    OptionBool refresh("-f", "--refresh", "Wait mx secs then refresh list");
    parser.AddOption(&refresh);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }

//    Debug::SetLevel(Debug::kDevice);
    DeviceListLogger logger;
    CpDeviceList* deviceList = NULL;
    FunctorCpDevice added = MakeFunctorCpDevice(logger, &DeviceListLogger::Added);
    FunctorCpDevice removed = MakeFunctorCpDevice(logger, &DeviceListLogger::Removed);
    if (all.Value()) {
        deviceList = new CpDeviceListUpnpAll(added, removed);
    }
    else if (root.Value()) {
        Print("Search root...\n");
        deviceList = new CpDeviceListUpnpRoot(added, removed);
    }
    else if (uuid.Value().Bytes() > 0) {
        Print("Search uuid...\n");
        deviceList = new CpDeviceListUpnpUuid(uuid.Value(), added, removed);
    }
    else if (urn.Value().Bytes() > 0) {
        Print("Search device/service...\n");
        Brn domainName;
        Brn type;
        TUint ver;
        if (OpenHome::Net::Ssdp::ParseUrnDevice(urn.Value(), domainName, type, ver)) {
            deviceList = new CpDeviceListUpnpDeviceType(domainName, type, ver, added, removed);
        }
        else if (OpenHome::Net::Ssdp::ParseUrnService(urn.Value(), domainName, type, ver)) {
            deviceList = new CpDeviceListUpnpServiceType(domainName, type, ver, added, removed);
        }
        else {
            parser.DisplayHelp();
        }
    }
    else {
        parser.DisplayHelp();
    }

    Blocker* blocker = new Blocker;
    if (deviceList != NULL) {
        blocker->Wait(Stack::InitParams().MsearchTimeSecs());
    }
    if (refresh.Value()) {
        Print("\nRefreshing...\n\n");
        deviceList->Refresh();
        blocker->Wait(Stack::InitParams().MsearchTimeSecs());
    }
    delete blocker;
    delete deviceList;
}
void TestSsdpUListen(Environment& aEnv, const std::vector<Brn>& aArgs)
{
    OptionParser parser;
    OptionUint mx("-mx", "--mx", 0, "[1..5] number of second to spread response over");
    parser.AddOption(&mx);
    OptionUint adapter("-i", "--interface", 0, "index of network adapter to use");
    parser.AddOption(&adapter);
    OptionBool all("-a", "--all", "Search for all devices and services");
    parser.AddOption(&all);
    OptionBool root("-r", "--root", "Search for root devices only");
    parser.AddOption(&root);
    Brn emptyString("");
    OptionString uuid("-u", "--uuid", emptyString, "[uuid string] search for a particular device");
    parser.AddOption(&uuid);
    OptionString urn("-t", "--urn", emptyString, "Search for a device or service of the form [domain:[device|service]:type:ver]");
    parser.AddOption(&urn);
    if (!parser.Parse(aArgs) || parser.HelpDisplayed()) {
        return;
    }

    //Debug::SetLevel(Debug::kSsdpMulticast);
    TBool block = true;
    SsdpNotifyLoggerU logger;
    SsdpListenerUnicast* uListener = new SsdpListenerUnicast(aEnv, logger, NetworkIf(aEnv, adapter.Value()));
    uListener->Start();
    if (all.Value()) {
        Print("Search all...\n");
        uListener->MsearchAll();
    }
    else if (root.Value()) {
        Print("Search root...\n");
        uListener->MsearchRoot();
    }
    else if (uuid.Value().Bytes() > 0) {
        Print("Search uuid...\n");
        uListener->MsearchUuid(uuid.Value());
    }
    else if (urn.Value().Bytes() > 0) {
        Print("Search device/service...\n");
        Brn domainName;
        Brn deviceType;
        TUint ver;
        if (OpenHome::Net::Ssdp::ParseUrnDevice(urn.Value(), domainName, deviceType, ver)) {
            uListener->MsearchDeviceType(domainName, deviceType, ver);
        }
        else if (OpenHome::Net::Ssdp::ParseUrnService(urn.Value(), domainName, deviceType, ver)) {
            uListener->MsearchServiceType(domainName, deviceType, ver);
        }
        else {
            parser.DisplayHelp();
            block = false;
        }
    }
    else {
        parser.DisplayHelp();
        block = false;
    }

    if (block) {
        Blocker* blocker = new Blocker(aEnv);
        blocker->Wait(aEnv.InitParams()->MsearchTimeSecs());
        delete blocker;
    }
    delete uListener;
}