Program Listing for File PortParameters.hpp
↰ Return to documentation for file (include/fastdds/rtps/common/PortParameters.hpp)
// Copyright 2016 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.
#ifndef FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
#define FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP
#include <fastdds/rtps/common/Types.hpp>
#include <fastdds/dds/log/Log.hpp>
namespace eprosima {
namespace fastdds {
namespace rtps {
class PortParameters
{
public:
PortParameters()
: portBase(7400)
, domainIDGain(250)
, participantIDGain(2)
, offsetd0(0)
, offsetd1(10)
, offsetd2(1)
, offsetd3(11)
, offsetd4(2)
{
}
virtual ~PortParameters()
{
}
bool operator ==(
const PortParameters& b) const
{
return (this->portBase == b.portBase) &&
(this->domainIDGain == b.domainIDGain) &&
(this->participantIDGain == b.participantIDGain) &&
(this->offsetd0 == b.offsetd0) &&
(this->offsetd1 == b.offsetd1) &&
(this->offsetd2 == b.offsetd2) &&
(this->offsetd3 == b.offsetd3) &&
(this->offsetd4 == b.offsetd4);
}
inline uint32_t getMulticastPort(
uint32_t domainId) const
{
uint32_t port = portBase + domainIDGain * domainId + offsetd0;
if (port > 65535)
{
EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
<< "or portBase is too high.");
std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
<< "or portBase is too high." << std::endl;
std::cout.flush();
exit(EXIT_FAILURE);
}
return port;
}
inline uint32_t getUnicastPort(
uint32_t domainId,
uint32_t RTPSParticipantID) const
{
uint32_t port = portBase + domainIDGain * domainId + offsetd1 + participantIDGain * RTPSParticipantID;
if (port > 65535)
{
EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232, there are "
<< "too much participants created or portBase is too high.");
std::cout << "Calculated port number is too high. Probably the domainId is over 232, there are "
<< "too much participants created or portBase is too high." << std::endl;
std::cout.flush();
exit(EXIT_FAILURE);
}
return port;
}
inline uint16_t get_discovery_server_port(
uint32_t domainId) const
{
uint32_t port = portBase + domainIDGain * domainId + offsetd4;
if (port > 65535)
{
EPROSIMA_LOG_ERROR(RTPS, "Calculated port number is too high. Probably the domainId is over 232 "
<< "or portBase is too high.");
std::cout << "Calculated port number is too high. Probably the domainId is over 232 "
<< "or portBase is too high." << std::endl;
std::cout.flush();
exit(EXIT_FAILURE);
}
return static_cast<uint16_t>(port);
}
public:
uint16_t portBase;
uint16_t domainIDGain;
uint16_t participantIDGain;
uint16_t offsetd0;
uint16_t offsetd1;
uint16_t offsetd2;
uint16_t offsetd3;
uint16_t offsetd4;
};
} // namespace rtps
} // namespace rtps
} // namespace eprosima
#endif // FASTDDS_RTPS_COMMON__PORTPARAMETERS_HPP