Merge pull request #24 from eboasson/fix

More sensible domain id handling; stopping throughput publisher
This commit is contained in:
eboasson 2018-10-18 21:59:00 +08:00 committed by GitHub
commit 2cee550f6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 89 additions and 55 deletions

View file

@ -32,7 +32,7 @@ dds__check_domain(
*-# Returns 0 on success or a non-zero error status
**/
dds_return_t
dds_init(void);
dds_init(dds_domainid_t domain);
/* Finalization function, called from main */

View file

@ -137,8 +137,8 @@ dds__create_builtin_participant(
}
pp->m_entity.m_guid = guid;
pp->m_entity.m_domain = dds_domain_create (config.domainId);
pp->m_entity.m_domainid = config.domainId;
pp->m_entity.m_domain = dds_domain_create (config.domainId.value);
pp->m_entity.m_domainid = config.domainId.value;
pp->m_entity.m_deriver.delete = dds__delete_builtin_participant;
fail:

View file

@ -41,7 +41,7 @@ dds_globals dds_global = { .m_default_domain = DDS_DOMAIN_DEFAULT };
static struct cfgst * dds_cfgst = NULL;
dds_return_t
dds_init(void)
dds_init(dds_domainid_t domain)
{
dds_return_t ret = DDS_RETCODE_OK;
const char * uri;
@ -86,9 +86,29 @@ dds_init(void)
ret = DDS_ERRNO(DDS_RETCODE_ERROR, "Failed to parse configuration XML file %s", uri);
goto fail_config;
}
/* if a domain id was explicitly given, check & fix up the configuration */
if (domain != DDS_DOMAIN_DEFAULT)
{
if (domain < 0 || domain > 230)
{
ret = DDS_ERRNO(DDS_RETCODE_ERROR, "requested domain id %d is out of range", domain);
goto fail_config;
}
else if (config.domainId.isdefault)
{
config.domainId.value = domain;
}
else if (domain != config.domainId.value)
{
ret = DDS_ERRNO(DDS_RETCODE_ERROR, "requested domain id %d is inconsistent with configured value %d", domain, config.domainId.value);
goto fail_config;
}
}
/* The config.domainId can change internally in DDSI. So, remember what the
* main configured domain id is. */
dds_global.m_default_domain = config.domainId;
dds_global.m_default_domain = config.domainId.value;
dds__builtin_init();

View file

@ -148,7 +148,7 @@ dds_create_participant(
bool asleep;
/* Make sure DDS instance is initialized. */
ret = dds_init();
ret = dds_init(domain);
if (ret != DDS_RETCODE_OK) {
e = (dds_entity_t)ret;
goto fail_dds_init;

View file

@ -45,13 +45,13 @@ Test(ddsc_participant, create_with_no_conf_no_env) {
dds_entity_t participant, participant2, participant3;
dds_return_t status;
dds_domainid_t domain_id;
dds_domainid_t valid_domain=0;
dds_domainid_t valid_domain=3;
const char * env_uri = os_getenv(DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI");
cr_assert_eq(env_uri, NULL, DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI must be NULL");
//invalid domain
participant = dds_create_participant (1, NULL, NULL);
participant = dds_create_participant (-2, NULL, NULL);
cr_assert_lt(participant, 0, "Error must be received for invalid domain value");
//valid specific domain value

View file

@ -235,11 +235,10 @@ struct config
enum boolean_default compat_tcp_enable;
int dontRoute;
int enableMulticastLoopback;
int domainId;
struct config_maybe_int32 domainId;
int participantIndex;
int maxAutoParticipantIndex;
int port_base;
struct config_maybe_int32 discoveryDomainId;
char *spdpMulticastAddressString;
char *defaultMulticastAddressString;
char *assumeMulticastCapable;

View file

@ -101,7 +101,7 @@ static int add_addresses_to_addrset_1 (struct addrset *as, const char *ip, int p
int i;
for (i = 0; i <= config.maxAutoParticipantIndex; i++)
{
int port = config.port_base + config.port_dg * config.domainId + i * config.port_pg + config.port_d1;
int port = config.port_base + config.port_dg * config.domainId.value + i * config.port_pg + config.port_d1;
loc.port = (unsigned) port;
if (i == 0)
nn_log (LC_CONFIG, "%s", ddsi_locator_to_string(buf, sizeof(buf), &loc));
@ -114,7 +114,7 @@ static int add_addresses_to_addrset_1 (struct addrset *as, const char *ip, int p
{
int port = port_mode;
if (port == -1)
port = config.port_base + config.port_dg * config.domainId + config.port_d0;
port = config.port_base + config.port_dg * config.domainId.value + config.port_d0;
loc.port = (unsigned) port;
nn_log (LC_CONFIG, "%s", ddsi_locator_to_string(buf, sizeof(buf), &loc));
add_to_addrset (as, &loc);

View file

@ -161,7 +161,7 @@ DUPF(cipher);
#ifdef DDSI_INCLUDE_BANDWIDTH_LIMITING
DUPF(bandwidth);
#endif
DU(domainId);
DUPF(domainId);
DUPF(durability_cdr);
DUPF(transport_selector);
DUPF(many_sockets_mode);
@ -727,8 +727,6 @@ static const struct cfgelem discovery_peers_cfgelems[] = {
};
static const struct cfgelem discovery_cfgelems[] = {
{ LEAF("DomainId"), 1, "default", ABSOFF(discoveryDomainId), 0, uf_maybe_int32, 0, pf_maybe_int32,
"<p>This element allows overriding of the DDS Domain Id that is used for DDSI2E.</p>" },
{ LEAF("AdvertiseBuiltinTopicWriters"), 1, "true", ABSOFF(advertise_builtin_topic_writers), 0, uf_boolean, 0, pf_boolean,
"<p>This element controls whether or not DDSI2E advertises writers for the built-in topics from its discovery for backwards compatibility with older OpenSplice versions.</p>" },
{ LEAF("DSGracePeriod"), 1, "30 s", ABSOFF(ds_grace_period), 0, uf_duration_inf, 0, pf_duration,
@ -873,7 +871,7 @@ static const struct cfgelem lease_cfgelems[] = {
static const struct cfgelem domain_cfgelems[] = {
{ GROUP("Lease", lease_cfgelems), NULL },
{ LEAF("Id"), 1, "0", ABSOFF(domainId), 0, uf_domainId, 0, pf_int, NULL },
{ LEAF("Id"), 1, "any", ABSOFF(domainId), 0, uf_domainId, 0, pf_domainId, NULL },
WILDCARD,
END_MARKER
};
@ -1904,9 +1902,20 @@ static int uf_int_min_max(struct cfgst *cfgst, void *parent, struct cfgelem cons
return 1;
}
static int uf_domainId(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int first, const char *value)
static int uf_domainId(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value)
{
return uf_int_min_max(cfgst, parent, cfgelem, first, value, 0, 230);
struct config_maybe_int32 *elem = cfg_address(cfgst, parent, cfgelem);
int pos;
if (os_strcasecmp(value, "any") == 0) {
elem->isdefault = 1;
elem->value = 0;
return 1;
} else if (sscanf(value, "%d%n", &elem->value, &pos) == 1 && value[pos] == 0 && elem->value >= 0 && elem->value <= 230) {
elem->isdefault = 0;
return 1;
} else {
return cfg_error(cfgst, "'%s': neither 'any' nor a decimal integer in 0 .. 230\n", value);
}
}
static int uf_participantIndex(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int first, const char *value)
@ -2229,6 +2238,14 @@ static void pf_maybe_memsize(struct cfgst *cfgst, void *parent, struct cfgelem c
pf_int64_unit(cfgst, p->value, is_default, unittab_memsize, "B");
}
static void pf_domainId(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int is_default)
{
struct config_maybe_int32 *p = cfg_address(cfgst, parent, cfgelem);
if ( p->isdefault )
cfg_log(cfgst, "any (%d)%s", p->value, is_default ? " [def]" : "");
else
cfg_log(cfgst, "%d%s", p->value, is_default ? " [def]" : "");
}
static void pf_float(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int is_default)
{
@ -2707,6 +2724,12 @@ struct cfgst * config_init
config.tracingOutputFile = stderr;
config.enabled_logcats = LC_ERROR | LC_WARNING;
/* eventually, we domainId.value will be the real domain id selected, even if it was configured
to the default of "any" and has "isdefault" set; initializing it to the default-default
value of 0 means "any" in the config & DDS_DOMAIN_DEFAULT in create participant automatically
ends up on the right value */
config.domainId.value = 0;
cfgst = os_malloc(sizeof(*cfgst));
memset(cfgst, 0, sizeof(*cfgst));

View file

@ -74,7 +74,7 @@ static int make_uc_sockets (uint32_t * pdisc, uint32_t * pdata, int ppid)
if (config.many_sockets_mode == MSM_NO_UNICAST)
{
assert (ppid == PARTICIPANT_INDEX_NONE);
*pdata = *pdisc = (uint32_t) (config.port_base + config.port_dg * config.domainId);
*pdata = *pdisc = (uint32_t) (config.port_base + config.port_dg * config.domainId.value);
if (config.allowMulticast)
{
/* FIXME: ugly hack - but we'll fix up after creating the multicast sockets */
@ -85,7 +85,7 @@ static int make_uc_sockets (uint32_t * pdisc, uint32_t * pdata, int ppid)
if (ppid >= 0)
{
/* FIXME: verify port numbers are in range instead of truncating them like this */
int base = config.port_base + (config.port_dg * config.domainId) + (ppid * config.port_pg);
int base = config.port_base + (config.port_dg * config.domainId.value) + (ppid * config.port_pg);
*pdisc = (uint32_t) (base + config.port_d1);
*pdata = (uint32_t) (base + config.port_d3);
}
@ -284,7 +284,7 @@ static int string_to_default_locator (nn_locator_t *loc, const char *string, uin
static int set_spdp_address (void)
{
const uint32_t port = (uint32_t) (config.port_base + config.port_dg * config.domainId + config.port_d0);
const uint32_t port = (uint32_t) (config.port_base + config.port_dg * config.domainId.value + config.port_d0);
int rc = 0;
/* FIXME: FIXME: FIXME: */
gv.loc_spdp_mc.kind = NN_LOCATOR_KIND_INVALID;
@ -321,7 +321,7 @@ static int set_spdp_address (void)
static int set_default_mc_address (void)
{
const uint32_t port = (uint32_t) (config.port_base + config.port_dg * config.domainId + config.port_d2);
const uint32_t port = (uint32_t) (config.port_base + config.port_dg * config.domainId.value + config.port_d2);
int rc;
if (!config.defaultMulticastAddressString)
gv.loc_default_mc = gv.loc_spdp_mc;
@ -464,15 +464,7 @@ int rtps_config_prep (struct cfgst *cfgst)
unsigned num_channel_threads = 0;
#endif
/* if the discovery domain id was explicitly set, override the default here */
if (!config.discoveryDomainId.isdefault)
{
config.domainId = config.discoveryDomainId.value;
}
/* retry_on_reject_duration default is dependent on late_ack_mode and responsiveness timeout, so fix up */
if (config.whc_init_highwater_mark.isdefault)
config.whc_init_highwater_mark.value = config.whc_lowwater_mark;
if (config.whc_highwater_mark < config.whc_lowwater_mark ||
@ -662,7 +654,7 @@ int joinleave_spdp_defmcip (int dojoin)
unref_addrset (as);
if (arg.errcount)
{
NN_ERROR ("rtps_init: failed to join multicast groups for domain %d participant %d\n", config.domainId, config.participantIndex);
NN_ERROR ("rtps_init: failed to join multicast groups for domain %d participant %d\n", config.domainId.value, config.participantIndex);
return -1;
}
return 0;
@ -676,7 +668,7 @@ int create_multicast_sockets(void)
qos->m_multicast = 1;
/* FIXME: should check for overflow */
port = (uint32_t) (config.port_base + config.port_dg * config.domainId + config.port_d0);
port = (uint32_t) (config.port_base + config.port_dg * config.domainId.value + config.port_d0);
if ((disc = ddsi_factory_create_conn (gv.m_factory, port, qos)) == NULL)
goto err_disc;
if (config.many_sockets_mode == MSM_NO_UNICAST)
@ -686,7 +678,7 @@ int create_multicast_sockets(void)
}
else
{
port = (uint32_t) (config.port_base + config.port_dg * config.domainId + config.port_d2);
port = (uint32_t) (config.port_base + config.port_dg * config.domainId.value + config.port_d2);
if ((data = ddsi_factory_create_conn (gv.m_factory, port, qos)) == NULL)
goto err_data;
}
@ -960,7 +952,7 @@ int rtps_init (void)
#ifdef DDSI_INCLUDE_NETWORK_PARTITIONS
/* Convert address sets in partition mappings from string to address sets */
{
const int port = config.port_base + config.port_dg * config.domainId + config.port_d2;
const int port = config.port_base + config.port_dg * config.domainId.value + config.port_d2;
struct config_networkpartition_listelem *np;
for (np = config.networkPartitions; np; np = np->next)
{
@ -1034,7 +1026,7 @@ int rtps_init (void)
{
if (make_uc_sockets (&port_disc_uc, &port_data_uc, config.participantIndex) < 0)
{
NN_ERROR ("rtps_init: failed to create unicast sockets for domain %d participant %d\n", config.domainId, config.participantIndex);
NN_ERROR ("rtps_init: failed to create unicast sockets for domain %d participant %d\n", config.domainId.value, config.participantIndex);
goto err_unicast_sockets;
}
}
@ -1052,13 +1044,13 @@ int rtps_init (void)
continue;
else /* Oops! */
{
NN_ERROR ("rtps_init: failed to create unicast sockets for domain %d participant %d\n", config.domainId, ppid);
NN_ERROR ("rtps_init: failed to create unicast sockets for domain %d participant %d\n", config.domainId.value, ppid);
goto err_unicast_sockets;
}
}
if (ppid > config.maxAutoParticipantIndex)
{
NN_ERROR ("rtps_init: failed to find a free participant index for domain %d\n", config.domainId);
NN_ERROR ("rtps_init: failed to find a free participant index for domain %d\n", config.domainId.value);
goto err_unicast_sockets;
}
config.participantIndex = ppid;
@ -1069,7 +1061,7 @@ int rtps_init (void)
}
nn_log (LC_CONFIG, "rtps_init: uc ports: disc %u data %u\n", port_disc_uc, port_data_uc);
}
nn_log (LC_CONFIG, "rtps_init: domainid %d participantid %d\n", config.domainId, config.participantIndex);
nn_log (LC_CONFIG, "rtps_init: domainid %d participantid %d\n", config.domainId.value, config.participantIndex);
if (config.pcap_file && *config.pcap_file)
{

View file

@ -11,7 +11,7 @@
-->
<@CMAKE_PROJECT_NAME@>
<Domain>
<Id>0</Id>
<Id>any</Id>
</Domain>
<DDSI2E>
<General>

View file

@ -57,17 +57,6 @@ int main (int argc, char **argv)
dds_entity_t writer;
ThroughputModule_DataType sample;
/* Register handler for Ctrl-C */
#ifdef _WIN32
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) CtrlHandler, true);
#else
struct sigaction sat;
sat.sa_handler = CtrlHandler;
sigemptyset (&sat.sa_mask);
sat.sa_flags = 0;
sigaction (SIGINT, &sat, &oldAction);
#endif
if (parse_args(argc, argv, &payloadSize, &burstInterval, &burstSize, &timeOut, &partitionName) == EXIT_FAILURE) {
return EXIT_FAILURE;
}
@ -90,6 +79,17 @@ int main (int argc, char **argv)
sample.payload._buffer[i] = 'a';
}
/* Register handler for Ctrl-C */
#ifdef _WIN32
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) CtrlHandler, true);
#else
struct sigaction sat;
sat.sa_handler = CtrlHandler;
sigemptyset (&sat.sa_mask);
sat.sa_flags = 0;
sigaction (SIGINT, &sat, &oldAction);
#endif
/* Register the sample instance and write samples repeatedly or until time out */
start_writing(writer, &sample, burstInterval, burstSize, timeOut);