Exemplo n.º 1
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);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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);
}