Commit 1d083c76 authored by Simon Morlat's avatar Simon Morlat Committed by Simon Morlat

Add a test API to force the use of a specific port for outgoing client connections.

parent 7191ee1d
......@@ -68,29 +68,6 @@ BELLESIP_EXPORT void belle_sip_provider_clean_channels(belle_sip_provider_t *p);
**/
BELLESIP_EXPORT int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_request_t* request,belle_sip_response_t *resp, belle_sip_uri_t *from_uri, belle_sip_list_t** auth_infos, const char* realm);
/**
* Can be used to simulate network recv error, for tests.
* @param prov
* @param recv_error if <=0, will cause channel error to be reported
**/
BELLESIP_EXPORT void belle_sip_provider_set_recv_error(belle_sip_provider_t *prov, int recv_error);
/**
* Can be used to unconditionally answer to incoming sip messages. By default 480 is answered.
* Can be enhanced by a new method belle_sip_provider_set_unconditional_answer to allows user to provide answer code
* @param prov
* @param enable 0 to disable
**/
BELLESIP_EXPORT void belle_sip_provider_enable_unconditional_answer(belle_sip_provider_t *prov, int enable);
/**
* Can be used to choose unconditionally answer to incoming sip messages.
* use belle_sip_provider_enable_unconditional_answer to enable/disable
* @param prov
* @param code 0 to sip response code
**/
BELLESIP_EXPORT void belle_sip_provider_set_unconditional_answer(belle_sip_provider_t *prov, unsigned short code);
/**
* Provides access to a specific dialog
* @param prov object
......@@ -131,6 +108,39 @@ BELLESIP_EXPORT void belle_sip_provider_enable_nat_helper(belle_sip_provider_t *
**/
BELLESIP_EXPORT int belle_sip_provider_nat_helper_enabled(const belle_sip_provider_t *prov);
/*
* Following functions are used for tests ONLY
*/
/**
* Can be used to simulate network recv error, for tests.
* @param prov
* @param recv_error if <=0, will cause channel error to be reported
**/
BELLESIP_EXPORT void belle_sip_provider_set_recv_error(belle_sip_provider_t *prov, int recv_error);
/**
* Can be used to unconditionally answer to incoming sip messages. By default 480 is answered.
* Can be enhanced by a new method belle_sip_provider_set_unconditional_answer to allows user to provide answer code
* @param prov
* @param enable 0 to disable
**/
BELLESIP_EXPORT void belle_sip_provider_enable_unconditional_answer(belle_sip_provider_t *prov, int enable);
/**
* Can be used to choose unconditionally answer to incoming sip messages.
* use belle_sip_provider_enable_unconditional_answer to enable/disable
* @param prov
* @param code 0 to sip response code
**/
BELLESIP_EXPORT void belle_sip_provider_set_unconditional_answer(belle_sip_provider_t *prov, unsigned short code);
/*
* End of test features.
*/
BELLE_SIP_END_DECLS
#define BELLE_SIP_PROVIDER(obj) BELLE_SIP_CAST(obj,belle_sip_provider_t)
......
......@@ -70,29 +70,6 @@ BELLESIP_EXPORT void belle_sip_stack_enable_dns_search(belle_sip_stack_t *stack,
**/
BELLESIP_EXPORT void belle_sip_stack_set_dns_servers(belle_sip_stack_t *stack, const belle_sip_list_t *servers);
/**
* Can be used to simulate network transmission delays, for tests.
**/
BELLESIP_EXPORT void belle_sip_stack_set_tx_delay(belle_sip_stack_t *stack, int delay_ms);
/**
* Can be used to simulate network sending error, for tests.
* @param stack
* @param send_error if <0, will cause channel error to be reported
**/
BELLESIP_EXPORT void belle_sip_stack_set_send_error(belle_sip_stack_t *stack, int send_error);
/**
* Can be used to simulate network transmission delays, for tests.
**/
BELLESIP_EXPORT void belle_sip_stack_set_resolver_tx_delay(belle_sip_stack_t *stack, int delay_ms);
/**
* Can be used to simulate network sending error, for tests.
* @param stack
* @param send_error if <0, will cause the resolver to fail with this error code.
**/
BELLESIP_EXPORT void belle_sip_stack_set_resolver_send_error(belle_sip_stack_t *stack, int send_error);
/**
* Get the additional DNS hosts file.
......@@ -187,6 +164,47 @@ BELLESIP_EXPORT void belle_sip_stack_enable_reconnect_to_primary_asap(belle_sip_
**/
BELLESIP_EXPORT int belle_sip_stack_reconnect_to_primary_asap_enabled(const belle_sip_stack_t *stack);
/*
* The following functions are for testing (non regression tests) ONLY
*/
/**
* Can be used to simulate network transmission delays, for tests.
**/
BELLESIP_EXPORT void belle_sip_stack_set_tx_delay(belle_sip_stack_t *stack, int delay_ms);
/**
* Can be used to simulate network sending error, for tests.
* @param stack
* @param send_error if <0, will cause channel error to be reported
**/
BELLESIP_EXPORT void belle_sip_stack_set_send_error(belle_sip_stack_t *stack, int send_error);
/**
* Can be used to simulate network transmission delays, for tests.
**/
BELLESIP_EXPORT void belle_sip_stack_set_resolver_tx_delay(belle_sip_stack_t *stack, int delay_ms);
/**
* Can be used to simulate network sending error, for tests.
* @param stack
* @param send_error if <0, will cause the resolver to fail with this error code.
**/
BELLESIP_EXPORT void belle_sip_stack_set_resolver_send_error(belle_sip_stack_t *stack, int send_error);
/**
* Requests TCP/TLS client connection to bind a on specific port. This is for test ONLY.
**/
BELLESIP_EXPORT void belle_sip_stack_set_client_bind_port(belle_sip_stack_t *stack, int port);
/*
* End of test functions.
*/
BELLE_SIP_END_DECLS
#endif
......@@ -540,6 +540,7 @@ struct belle_sip_stack{
int send_error; /* used to simulate network error. if <0, channel_send will return this value*/
int resolver_tx_delay; /*used to simulate network transmission delay, for tests*/
int resolver_send_error; /* used to simulate network error*/
int test_bind_port;
int dscp;
char *dns_user_hosts_file; /* used to load additional hosts file for tests */
char *dns_resolv_conf; /*used to load custom resolv.conf, for tests*/
......@@ -575,10 +576,10 @@ struct belle_sip_provider{
belle_sip_list_t *server_transactions;
belle_sip_list_t *dialogs;
belle_sip_list_t *auth_contexts;
unsigned short unconditional_answer;
unsigned char rport_enabled; /*0 if rport should not be set in via header*/
unsigned char nat_helper;
unsigned char unconditional_answer_enabled;
unsigned short unconditional_answer;
};
BELLESIP_EXPORT belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
......
......@@ -1357,9 +1357,12 @@ void belle_sip_provider_enable_nat_helper(belle_sip_provider_t *prov, int enable
int belle_sip_provider_nat_helper_enabled(const belle_sip_provider_t *prov){
return prov->nat_helper;
}
void belle_sip_provider_enable_unconditional_answer(belle_sip_provider_t *prov, int enable) {
prov->unconditional_answer_enabled=enable;
}
void belle_sip_provider_set_unconditional_answer(belle_sip_provider_t *prov, unsigned short code) {
prov->unconditional_answer=code;
}
......@@ -332,3 +332,8 @@ void belle_sip_stack_enable_reconnect_to_primary_asap(belle_sip_stack_t *stack,
int belle_sip_stack_reconnect_to_primary_asap_enabled(const belle_sip_stack_t *stack) {
return stack->reconnect_to_primary_asap;
}
void belle_sip_stack_set_client_bind_port(belle_sip_stack_t *stack, int port){
stack->test_bind_port = port;
}
......@@ -121,6 +121,7 @@ int stream_channel_connect(belle_sip_stream_channel_t *obj, const struct addrinf
int err;
int tmp;
belle_sip_socket_t sock;
belle_sip_stack_t *stack = obj->base.stack;
tmp=1;
obj->base.ai_family=ai->ai_family;
......@@ -130,13 +131,31 @@ int stream_channel_connect(belle_sip_stream_channel_t *obj, const struct addrinf
belle_sip_error("Could not create socket: %s",belle_sip_get_socket_error_string());
return -1;
}
tmp = 1;
err=bctbx_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,(char*)&tmp,sizeof(tmp));
if (err!=0){
belle_sip_error("bctbx_setsockopt SO_REUSEADDR failed: [%s]",belle_sip_get_socket_error_string());
}
if (stack->test_bind_port != 0){
struct addrinfo *bind_ai = bctbx_ip_address_to_addrinfo(ai->ai_family, SOCK_STREAM, ai->ai_family == AF_INET6 ? "::0" : "0.0.0.0", stack->test_bind_port);
err = bctbx_bind(sock, bind_ai->ai_addr, bind_ai->ai_addrlen);
if (err != 0){
belle_sip_error("bctbx_bind failed: [%s]",belle_sip_get_socket_error_string());
belle_sip_close_socket(sock);
return -1;
}else bctbx_message("bind() on port [%i] successful", stack->test_bind_port);
bctbx_freeaddrinfo(bind_ai);
}
tmp = 1;
err=bctbx_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,(char*)&tmp,sizeof(tmp));
if (err!=0){
belle_sip_error("bctbx_setsockopt TCP_NODELAY failed: [%s]",belle_sip_get_socket_error_string());
}
belle_sip_socket_set_nonblocking(sock);
if (ai->ai_family==AF_INET6){
if (ai->ai_family==AF_INET6 && stack->test_bind_port == 0){
belle_sip_socket_enable_dual_stack(sock);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment