예제 #1
0
/*
 * Called when we receive a new url list.
 */
void DiscoveryDone(bool ok, const URLEntries &urls) {
  if (!ok) {
    OLA_WARN << "SLP discovery failed";
  } else if (urls.empty()) {
    OLA_INFO << "No services found";
  } else {
    URLEntries::const_iterator iter;
    for (iter = urls.begin(); iter != urls.end(); ++iter) {
      std::cout << "  " << iter->url() << std::endl;
    }
  }
}
예제 #2
0
/**
 * Called when FindService completes.
 */
void SLPDaemon::SLPServiceImpl::FindServiceHandler(
    ola::slp::proto::ServiceReply* response,
    ::google::protobuf::Closure* done,
    const URLEntries &urls) {
  for (URLEntries::const_iterator iter = urls.begin();
       iter != urls.end(); ++iter) {
    ola::slp::proto::URLEntry *url_entry = response->add_url_entry();
    url_entry->set_url(iter->url());
    url_entry->set_lifetime(iter->lifetime());
  }
  done->Run();
}
예제 #3
0
파일: e133-monitor.cpp 프로젝트: Tuckie/ola
/**
 * Called when SLP completes discovery.
 */
void SimpleE133Monitor::DiscoveryCallback(bool ok, const URLEntries &urls) {
  if (ok) {
    URLEntries::const_iterator iter;
    UID uid(0, 0);
    IPV4Address ip;
    for (iter = urls.begin(); iter != urls.end(); ++iter) {
      OLA_INFO << "Located " << *iter;
      if (!ola::e133::ParseE133URL(iter->url(), &uid, &ip))
        continue;

      if (uid.IsBroadcast()) {
        OLA_WARN << "UID " << uid << "@" << ip << " is broadcast";
        continue;
      }
      AddIP(ip);
    }
  } else {
    OLA_INFO << "SLP discovery failed";
  }
}
예제 #4
0
/**
 * Called when SLP discovery completes.
 */
void SimpleE133Controller::DiscoveryCallback(bool ok, const URLEntries &urls) {
  if (ok) {
    URLEntries::const_iterator iter;
    UID uid(0, 0);
    IPV4Address ip;
    for (iter = urls.begin(); iter != urls.end(); ++iter) {
      OLA_INFO << "Located " << *iter;
      if (!ola::e133::ParseE133URL(iter->url(), &uid, &ip))
        continue;

      if (uid.IsBroadcast()) {
        OLA_WARN << "UID " << uid << "@" << ip << " is broadcast";
        continue;
      }
      AddUID(uid, ip);
    }
  }
  m_uid_list_updated = true;
  m_ss.Terminate();
}
예제 #5
0
/**
 * Confirm that we respond to SrvRqst for registered services.
 */
void SLPServerDATest::testSrvRqstForRemoteService() {
  auto_ptr<SLPServer> server(m_helper.CreateDAAndHandleStartup(DA_SCOPES));

  ServiceEntry service("one", FOO_LOCALHOST_URL, 300);
  xid_t xid = 10;

  {
    SocketVerifier verifier(&m_udp_socket);
    m_helper.ExpectServiceAck(UA1, xid, SLP_OK);
    m_helper.InjectServiceRegistration(UA1, xid, true, DA_SCOPES, service);
  }

  // send a unicast SrvRqst, expect a SrvRply
  {
    SocketVerifier verifier(&m_udp_socket);

    URLEntries urls;
    urls.push_back(service.url());
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid++, false, pr_list, FOO_SERVICE,
                                  DA_SCOPES);
  }

  // send a multicast SrvRqst, expect a SrvRply
  {
    SocketVerifier verifier(&m_udp_socket);

    URLEntries urls;
    urls.push_back(service.url());
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid++, true, pr_list, FOO_SERVICE,
                                  DA_SCOPES);
  }

  m_helper.ExpectMulticastDAAdvert(0, 0, DA_SCOPES);
}
예제 #6
0
/**
 * test the SrvDeReg handling
 */
void SLPServerDATest::testDeRegistration() {
  auto_ptr<SLPServer> server(m_helper.CreateDAAndHandleStartup(DA_SCOPES));

  ServiceEntry service("one", FOO_LOCALHOST_URL, 300);
  xid_t xid = 10;

  // try to de-reg a service that isn't registered
  // The RFC isn't clear what to return here, none of the error codes really
  // match so we return SLP_OK.
  {
    SocketVerifier verifier(&m_udp_socket);
    m_helper.ExpectServiceAck(UA1, xid, SLP_OK);

    m_helper.InjectServiceDeRegistration(UA1, xid, DA_SCOPES, service);
  }

  // register a service
  {
    SocketVerifier verifier(&m_udp_socket);
    m_helper.ExpectServiceAck(UA1, xid, SLP_OK);

    m_helper.InjectServiceRegistration(UA1, xid++, true, DA_SCOPES, service);
  }

  // try to de-register the service without any scopes
  {
    SocketVerifier verifier(&m_udp_socket);
    m_helper.ExpectServiceAck(UA1, xid, SCOPE_NOT_SUPPORTED);

    m_helper.InjectServiceDeRegistration(UA1, xid++, EMPTY_SCOPES, service);
  }

  // try to de-register the service with a subset of the scopes
  {
    SocketVerifier verifier(&m_udp_socket);
    m_helper.ExpectServiceAck(UA1, xid, SCOPE_NOT_SUPPORTED);

    m_helper.InjectServiceDeRegistration(UA1, xid++, SCOPE1, service);
  }

  // confirm we still reply to a SrvRqst
  {
    SocketVerifier verifier(&m_udp_socket);
    URLEntries urls;
    urls.push_back(service.url());
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, true, pr_list, FOO_SERVICE,
                                  DA_SCOPES);
  }

  // now actually de-register the service
  {
    SocketVerifier verifier(&m_udp_socket);
    m_helper.ExpectServiceAck(UA1, xid, SLP_OK);

    m_helper.InjectServiceDeRegistration(UA1, xid++, DA_SCOPES, service);
  }

  // confirm we no longer reply to a SrvRqst
  {
    SocketVerifier verifier(&m_udp_socket);
    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, true, pr_list, FOO_SERVICE,
                                  DA_SCOPES);
  }

  m_helper.ExpectMulticastDAAdvert(0, 0, DA_SCOPES);
}
예제 #7
0
/**
 * Test the we respond correctly to SrvRqsts for locally registered services
 */
void SLPServerDATest::testSrvRqstForLocalService() {
  auto_ptr<SLPServer> server(m_helper.CreateDAAndHandleStartup(DA_SCOPES));

  // register a service
  ServiceEntry service("one", FOO_LOCALHOST_URL, 300);
  OLA_ASSERT_EQ((uint16_t) SLP_OK, server->RegisterService(service));
  m_helper.AdvanceTime(0);

  // now perform various SrvRqsts
  xid_t xid = 10;

  // send a unicast SrvRqst, expect a SrvRply
  {
    SocketVerifier verifier(&m_udp_socket);

    URLEntries urls;
    urls.push_back(service.url());
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, false, pr_list, FOO_SERVICE,
                                  SCOPE1);
  }

  // send a multicast SrvRqst, expect a SrvRply
  {
    SocketVerifier verifier(&m_udp_socket);

    URLEntries urls;
    urls.push_back(service.url());
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, true, pr_list, FOO_SERVICE,
                                  SCOPE1);
  }

  // Try a multicast request but with the SA's IP in the PR list
  {
    SocketVerifier verifier(&m_udp_socket);
    PRList pr_list;
    pr_list.insert(
        IPV4Address::FromStringOrDie(SLPServerTestHelper::SERVER_IP));
    m_helper.InjectServiceRequest(UA1, ++xid, true, pr_list, FOO_SERVICE,
                                  SCOPE1);
  }

  // test a multicast request for a scope that the DA doesn't support
  {
    SocketVerifier verifier(&m_udp_socket);
    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, ++xid, true, pr_list, FOO_SERVICE,
                                  SCOPE3);
  }

  // test a unicast request for a scope that the DA doesn't support
  {
    SocketVerifier verifier(&m_udp_socket);
    URLEntries urls;
    m_helper.ExpectError(UA1, SERVICE_REPLY, ++xid, SCOPE_NOT_SUPPORTED);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, false, pr_list, FOO_SERVICE,
                                  SCOPE3);
  }

  // test a multicast request for a scope that the DA supports, but the service
  // wasn't registered with
  {
    SocketVerifier verifier(&m_udp_socket);
    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, ++xid, true, pr_list, FOO_SERVICE,
                                  SCOPE2);
  }

  // test a unicast request for a scope that the DA supports, but the service
  // wasn't registered with
  {
    SocketVerifier verifier(&m_udp_socket);
    URLEntries urls;
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, false, pr_list, FOO_SERVICE,
                                  SCOPE2);
  }

  // test a unicast request with no scope list
  {
    SocketVerifier verifier(&m_udp_socket);
    URLEntries urls;
    m_helper.ExpectError(UA1, SERVICE_REPLY, ++xid, SCOPE_NOT_SUPPORTED);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, false, pr_list, FOO_SERVICE,
                                  EMPTY_SCOPES);
  }

  // test a multicast request with no scope list
  {
    SocketVerifier verifier(&m_udp_socket);
    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, ++xid, true, pr_list, FOO_SERVICE,
                                  EMPTY_SCOPES);
  }

  // de-register the service
  OLA_ASSERT_EQ((uint16_t) SLP_OK, server->DeRegisterService(service));
  m_helper.AdvanceTime(0);

  // send a unicast SrvRqst, expect an empty SrvRply
  {
    SocketVerifier verifier(&m_udp_socket);
    URLEntries urls;
    m_helper.ExpectServiceReply(UA1, xid, SLP_OK, urls);

    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, false, pr_list, FOO_SERVICE,
                                  SCOPE1);
  }

  // send a multicast SrvRqst, expect no response
  {
    SocketVerifier verifier(&m_udp_socket);
    PRList pr_list;
    m_helper.InjectServiceRequest(UA1, xid, true, pr_list, FOO_SERVICE,
                                  SCOPE1);
  }

  m_helper.ExpectMulticastDAAdvert(0, 0, DA_SCOPES);
}