Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags

build/
install/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -10,29 +10,25 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License\.

#pragma once

#include <string>

#include <yaml-cpp/yaml.h>

namespace eprosima {
namespace ddspipe {
namespace core {
namespace testing {

/**
* Configuration is in dictionary format
*
* YAML spec: https://yaml.org/spec/1.2.2/
*
* @note It is not legal to repeat keys in a YAML
*
* @note this object contains a reference to the actual yaml object. Thus passing it by value or by reference
* makes no different.
*/
using Yaml = YAML::Node;
template <typename T>
T arbitrary(
unsigned int seed = 0);

//! Type of tag in the yaml
using TagType = std::string;
template <typename T, typename ... Args>
T arbitrary(
unsigned int seed,
Args... args);

} /* namespace testing */
} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */
180 changes: 180 additions & 0 deletions ddspipe_core/src/cpp/testing/arbitrary_values.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#include <cpp_utils/exception/InitializationException.hpp>

#include <ddspipe_core/testing/arbitrary_values.hpp>
#include <ddspipe_core/types/dds/DomainId.hpp>
#include <ddspipe_core/types/dds/Endpoint.hpp>
#include <ddspipe_core/types/dds/Guid.hpp>
#include <ddspipe_core/types/dds/GuidPrefix.hpp>
#include <ddspipe_core/types/participant/ParticipantId.hpp>
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
#include <ddspipe_core/types/topic/filter/WildcardDdsFilterTopic.hpp>

namespace eprosima {
namespace ddspipe {
namespace core {
namespace testing {

using namespace eprosima::ddspipe::core::types;

////////////////////////////////////////////////
// DEFAULT ARBITRARY
////////////////////////////////////////////////

template <>
TopicQoS arbitrary(
unsigned int seed /* = 0 */)
{
TopicQoS object;

if (seed % 2)
{
object.reliability_qos = ReliabilityKind::BEST_EFFORT;
}
else
{
object.reliability_qos = ReliabilityKind::RELIABLE;
}

seed /= 2;

switch ((seed / 2) % 4)
{
case 0:
object.durability_qos = DurabilityKind::VOLATILE;
break;

case 1:
object.durability_qos = DurabilityKind::TRANSIENT_LOCAL;
break;

case 2:
object.durability_qos = DurabilityKind::TRANSIENT;
break;

case 3:
object.durability_qos = DurabilityKind::PERSISTENT;
break;

default:
break;
}

seed /= 4;

if (seed % 2)
{
object.ownership_qos = OwnershipQosPolicyKind::SHARED_OWNERSHIP_QOS;
}
else
{
object.ownership_qos = OwnershipQosPolicyKind::EXCLUSIVE_OWNERSHIP_QOS;
}

seed /= 2;

object.use_partitions = ((seed % 2) == 0);

seed /= 2;

object.keyed = ((seed % 2) == 0);

seed /= 2;

object.downsampling = (seed % 2) + 1;

seed /= 2;

object.max_reception_rate = seed % 2;

seed /= 2;

object.history_depth = seed + 1;

return object;
}

template <>
DdsTopic arbitrary(
unsigned int seed /* = 0 */)
{
DdsTopic object;
object.m_topic_name = "TopicName_" + std::to_string(seed);
object.type_name = "TopicType_" + std::to_string(seed);
object.topic_qos = arbitrary<TopicQoS>(seed);
return object;
}

template <>
WildcardDdsFilterTopic arbitrary(
unsigned int seed /* = 0 */)
{
WildcardDdsFilterTopic object;

if (seed % 2)
{
object.topic_name.set_value("TopicName_" + std::to_string(seed));
}

seed /= 2;

if (seed % 2)
{
object.type_name.set_value("TopicName_" + std::to_string(seed));
}

return object;
}

template <>
GuidPrefix arbitrary(
unsigned int seed /* = 0 */)
{
// TODO do it more generic and arbitrary
return GuidPrefix(static_cast<uint32_t>(seed));
}

////////////////////////////////////////////////
// SPECIFIC ARBITRARY
////////////////////////////////////////////////

template <>
TopicQoS arbitrary(
unsigned int seed,
bool limit_durability)
{
TopicQoS object = arbitrary<TopicQoS>(seed);

// Reliability
seed /= 2;

if (seed % 2)
{
object.durability_qos = DurabilityKind::VOLATILE;
}
else
{
object.durability_qos = DurabilityKind::TRANSIENT_LOCAL;
}

return object;
}

} /* namespace testing */
} /* namespace core */
} /* namespace ddspipe */
} /* namespace eprosima */
2 changes: 1 addition & 1 deletion ddspipe_core/src/cpp/types/topic/dds/DdsTopic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::ostream& operator <<(
std::ostream& os,
const DdsTopic& t)
{
os << "DdsTopic{" << t.topic_name() << ";" << t.type_name << t.topic_qos << "}";
os << "DdsTopic{" << t.topic_name() << ";" << t.type_name << ";" << t.topic_qos << "}";
return os;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <fastdds/rtps/common/Locator.h>

#include <cpp_utils/macros/custom_enumeration.hpp>

#include <ddspipe_participants/library/library_dll.h>

namespace eprosima {
Expand All @@ -35,18 +37,18 @@ using DomainType = std::string;
using PortType = uint16_t;

//! Different versions allowed for IP
enum class IpVersion : int
{
v4 = 4,
v6 = 6,
};
ENUMERATION_BUILDER(
IpVersion,
v4,
v6
);

//! Different Transport Protocols allowed
enum class TransportProtocol
{
ENUMERATION_BUILDER(
TransportProtocol,
udp,
tcp
};
);

/**
* @brief Address that works as a collection of data defining a network address.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,10 @@ namespace types {
* This class has several address associated with one \c GuidPrefix in order to connect with
* a remote Discovery Server.
*/
class DiscoveryServerConnectionAddress
struct DiscoveryServerConnectionAddress
{
public:

/**
* @brief Construct a new \c DiscoveryServerConnectionAddress object with all the parameters
*
* @param discovery_server_guid_ : Guid Prefix of the remote Discovery Server
* @param addresses_ collection of addresses
*/
DDSPIPE_PARTICIPANTS_DllAPI
DiscoveryServerConnectionAddress(
core::types::GuidPrefix discovery_server_guid,
std::set<Address> addresses);

//! Discovery Server \c GuidPrefix Port getter
DDSPIPE_PARTICIPANTS_DllAPI
core::types::GuidPrefix discovery_server_guid_prefix() const noexcept;

//! Addresses getter
DDSPIPE_PARTICIPANTS_DllAPI
std::set<Address> addresses() const noexcept;

/**
* @brief Whether the address is correct
*
Expand All @@ -75,13 +56,11 @@ class DiscoveryServerConnectionAddress
bool operator ==(
const DiscoveryServerConnectionAddress& other) const noexcept;

protected:

//! Internal Discovery Server Guid Prefix object
core::types::GuidPrefix discovery_server_guid_prefix_;
core::types::GuidPrefix discovery_server_guid_prefix;

//! Internal Addresses object
std::set<Address> addresses_;
std::set<Address> addresses;
};

//! \c DiscoveryServerConnectionAddress to stream serializator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,22 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
// Invalid connection address, continue with next one
logWarning(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Discard connection address with remote server: " <<
connection_address.discovery_server_guid_prefix() <<
connection_address.discovery_server_guid_prefix <<
" in Participant " << configuration->id << " initialization.");
continue;
}

// Set Server GUID
core::types::GuidPrefix server_prefix = connection_address.discovery_server_guid_prefix();
core::types::GuidPrefix server_prefix = connection_address.discovery_server_guid_prefix;

for (types::Address address : connection_address.addresses())
for (types::Address address : connection_address.addresses)
{
if (!address.is_valid())
{
// Invalid ip address, continue with next one
logWarning(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Discard connection address with remote server: " <<
connection_address.discovery_server_guid_prefix() <<
connection_address.discovery_server_guid_prefix <<
" due to invalid ip address " << address.ip() << " in Participant " << configuration->id <<
" initialization.");
continue;
Expand Down
Loading