OpenDDS  Snapshot(2023/04/28-20:55)
MulticastInst.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "MulticastInst.h"
9 #include "MulticastLoader.h"
10 #include "MulticastTransport.h"
11 
12 #include <dds/DCPS/LogAddr.h>
15 
16 #include <ace/Configuration.h>
17 
18 #include <iostream>
19 #include <sstream>
20 
21 namespace {
22 
23 const bool DEFAULT_TO_IPV6(false);
24 
25 const u_short DEFAULT_PORT_OFFSET(49152);
26 
27 const char* DEFAULT_IPV4_GROUP_ADDRESS("224.0.0.128");
28 const char* DEFAULT_IPV6_GROUP_ADDRESS("FF01::80");
29 
30 const bool DEFAULT_RELIABLE(true);
31 
32 const double DEFAULT_SYN_BACKOFF(2.0);
33 const long DEFAULT_SYN_INTERVAL(250);
34 const long DEFAULT_SYN_TIMEOUT(30000);
35 
36 const unsigned char DEFAULT_TTL(1);
37 const bool DEFAULT_ASYNC_SEND(false);
38 
39 } // namespace
40 
42 
43 namespace OpenDDS {
44 namespace DCPS {
45 
46 MulticastInst::MulticastInst(const std::string& name)
47  : TransportInst("multicast", name),
48  default_to_ipv6_(DEFAULT_TO_IPV6),
49  port_offset_(DEFAULT_PORT_OFFSET),
50  reliable_(DEFAULT_RELIABLE),
51  syn_backoff_(DEFAULT_SYN_BACKOFF),
52  nak_depth_(DEFAULT_NAK_DEPTH),
53  nak_delay_intervals_(DEFAULT_NAK_DELAY_INTERVALS),
54  nak_max_(DEFAULT_NAK_MAX),
55  ttl_(DEFAULT_TTL),
57  rcv_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ),
58 #else
59  // Use system default values.
60  rcv_buffer_size_(0),
61 #endif
62  async_send_(DEFAULT_ASYNC_SEND)
63 {
65 
66  syn_interval_ = TimeDuration::from_msec(DEFAULT_SYN_INTERVAL);
67  syn_timeout_ = TimeDuration::from_msec(DEFAULT_SYN_TIMEOUT);
68 
71 }
72 
73 int
76 {
77  TransportInst::load(cf, sect); // delegate to parent
78 
79  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("default_to_ipv6"),
80  this->default_to_ipv6_, bool)
81 
82  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("port_offset"),
83  this->port_offset_, u_short)
84 
85  // Explicitly initialize this string to stop gcc 11 from issuing a warning.
86  ACE_TString group_address_s(ACE_TEXT(""));
87  GET_CONFIG_TSTRING_VALUE(cf, sect, ACE_TEXT("group_address"),
88  group_address_s)
89  if (group_address_s.is_empty()) {
90  // TODO: Passing 0 instead of transport id. Does this cause complications?
92  } else {
93  this->group_address_.set(group_address_s.c_str());
94  }
95 
96  GET_CONFIG_STRING_VALUE(cf, sect, ACE_TEXT("local_address"),
97  this->local_address_);
98 
99  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("reliable"), this->reliable_, bool)
100 
101  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("syn_backoff"),
102  this->syn_backoff_, double)
103 
104  GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("syn_interval"), this->syn_interval_)
105 
106  GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("syn_timeout"), this->syn_timeout_)
107 
108  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_depth"),
109  this->nak_depth_, size_t)
110 
111  GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_interval"), this->nak_interval_)
112 
113  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_delay_intervals"),
114  this->nak_delay_intervals_, size_t)
115 
116  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_max"), this->nak_max_, size_t)
117 
118  GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_timeout"), this->nak_timeout_)
119 
120  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("ttl"), this->ttl_, unsigned char)
121 
122  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("rcv_buffer_size"),
123  this->rcv_buffer_size_, size_t)
124 
125 #if defined (ACE_WIN32) && defined (ACE_HAS_WIN32_OVERLAPPED_IO)
126  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("async_send"), this->async_send_, bool)
127 #endif
128 
129  return 0;
130 }
131 
132 void
134 {
135  if (this->default_to_ipv6_) {
136  group_address.set(this->port_offset_, DEFAULT_IPV6_GROUP_ADDRESS);
137  } else {
138  group_address.set(this->port_offset_, DEFAULT_IPV4_GROUP_ADDRESS);
139  }
140 }
141 
144 {
145  return make_rch<MulticastTransport>(rchandle_from(this));
146 }
147 
150 {
151  std::ostringstream os;
153 
154  os << formatNameForDump("group_address") << LogAddr(group_address_).str() << std::endl;
155  os << formatNameForDump("local_address") << this->local_address_ << std::endl;
156  os << formatNameForDump("default_to_ipv6") << (this->default_to_ipv6_ ? "true" : "false") << std::endl;
157  os << formatNameForDump("port_offset") << this->port_offset_ << std::endl;
158  os << formatNameForDump("reliable") << (this->reliable_ ? "true" : "false") << std::endl;
159  os << formatNameForDump("syn_backoff") << this->syn_backoff_ << std::endl;
160  os << formatNameForDump("syn_interval") << this->syn_interval_.str() << std::endl;
161  os << formatNameForDump("syn_timeout") << this->syn_timeout_.str() << std::endl;
162  os << formatNameForDump("nak_depth") << this->nak_depth_ << std::endl;
163  os << formatNameForDump("nak_interval") << this->nak_interval_.str() << std::endl;
164  os << formatNameForDump("nak_delay_intervals") << this->nak_delay_intervals_ << std::endl;
165  os << formatNameForDump("nak_max") << this->nak_max_ << std::endl;
166  os << formatNameForDump("nak_timeout") << this->nak_timeout_.str() << std::endl;
167  os << formatNameForDump("ttl") << int(this->ttl_) << std::endl;
168  os << formatNameForDump("rcv_buffer_size");
169 
170  if (this->rcv_buffer_size_ == 0) {
171  os << "System Default Value" << std::endl;
172  } else {
173  os << this->rcv_buffer_size_ << std::endl;
174  }
175 
176  os << formatNameForDump("async_send");
177 
178 #if defined (ACE_WIN32) && defined (ACE_HAS_WIN32_OVERLAPPED_IO)
179  os << (this->async_send_ ? "true" : "false") << std::endl;
180 #else
181  os << "Not Supported on this Platform" << std::endl;
182 #endif
183  return OPENDDS_STRING(os.str());
184 }
185 
186 size_t
188 {
189  if (group_address_ != ACE_INET_Addr()) {
190  NetworkResource network_resource(group_address_);
191 
192  ACE_OutputCDR cdr;
193  cdr << network_resource;
195 
196  const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length());
197  char* buffer = const_cast<char*>(cdr.buffer()); // safe
198 
199  info.transport_type = "multicast";
200  info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer));
201  return 1;
202  } else {
203  return 0;
204  }
205 }
206 
207 } // namespace DCPS
208 } // namespace OpenDDS
209 
RcHandle< T > rchandle_from(T *pointer)
Definition: RcHandle_T.h:310
const char * c_str(void) const
Base class to hold configuration settings for TransportImpls.
Definition: TransportInst.h:64
if(!(yy_init))
virtual OPENDDS_STRING dump_to_str() const
Diagnostic aid.
#define GET_CONFIG_STRING_VALUE(CF, SECT, KEY, VALUE)
Definition: TransportDefs.h:76
bool is_reliable() const
Does the transport as configured support RELIABLE_RELIABILITY_QOS?
static const long DEFAULT_NAK_TIMEOUT
Definition: MulticastInst.h:34
static const long DEFAULT_NAK_INTERVAL
Definition: MulticastInst.h:31
size_t total_length(void) const
void default_group_address(ACE_INET_Addr &group_address)
#define OPENDDS_STRING
ACE_CDR::ULong ULong
static TimeDuration from_msec(const ACE_UINT64 &ms)
bool is_empty(void) const
#define GET_CONFIG_VALUE(CF, SECT, KEY, VALUE, TYPE)
Definition: TransportDefs.h:45
#define GET_CONFIG_TSTRING_VALUE(CF, SECT, KEY, VALUE)
TransportImpl_rch new_impl()
Defines a wrapper around address info which is used for advertise.
const char * buffer(void) const
#define ACE_DEFAULT_MAX_SOCKET_BUFSIZ
const char *const name
Definition: debug.cpp:60
int set(const ACE_INET_Addr &)
#define GET_CONFIG_TIME_VALUE(CF, SECT, KEY, VALUE)
ACE_TEXT("TCP_Factory")
virtual int load(ACE_Configuration_Heap &cf, ACE_Configuration_Section_Key &sect)
virtual int load(ACE_Configuration_Heap &cf, ACE_Configuration_Section_Key &sect)
String str(unsigned decimal_places=3, bool just_sec=false) const
const String & str() const
Definition: LogAddr.h:31
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
string transport_type
The transport type (e.g. tcp or udp)
static OPENDDS_STRING formatNameForDump(const char *name)
virtual size_t populate_locator(OpenDDS::DCPS::TransportLocator &trans_info, ConnectionInfoFlags flags) const
Populate a transport locator sequence. Return the number of "locators.".
DDS::OctetSeq TransportBLOB
bool Boolean
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
virtual OPENDDS_STRING dump_to_str() const
size_t ConnectionInfoFlags