Address( address ),
Port( 0 ),
ProtocolList(),
+ ProtocolFallbackCount( 0 ),
IntervalInSec( 0 )
{
}
}
/**
+ * @return The amount of pings to perform before change the protocol.
+ */
+int Host::get_ping_protocol_fallback_count() const
+{
+ return ProtocolFallbackCount;
+}
+
+/**
+ * @param protocol_fallback_count The amount of pings to perform before change the protocol.
+ */
+void Host::set_ping_protocol_fallback_count( const int protocol_fallback_count )
+{
+ BOOST_ASSERT( ( 0 <= protocol_fallback_count ) && ( protocol_fallback_count < numeric_limits<int>::max() ) );
+
+ this->ProtocolFallbackCount = protocol_fallback_count;
+}
+
+/**
* @return The interval between each ping to the host.
*/
int Host::get_interval_in_sec() const
PingProtocolList get_ping_protocol_list() const;
void set_ping_protocol_list( const PingProtocolList &ping_protocol );
+ int get_ping_protocol_fallback_count() const;
+ void set_ping_protocol_fallback_count( const int protocol_fallback_count );
+
int get_interval_in_sec() const;
void set_interval_in_sec( const int interval_in_sec );
uint16_t Port;
/// The list of protocols used to ping
PingProtocolList ProtocolList;
+ /// The amount of pings to perform before change the protocol.
+ int ProtocolFallbackCount;
/// The interval between each ping to the host
int IntervalInSec;
#include <boost/assert.hpp>
#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
#include <logfunc.hpp>
HostConfigurationOption(
"host.ping-protocol",
value< vector<string> >(),
- "Defines which protocol will be used to ping the destination."
+ "Defines which protocols will be used to ping the destination."
)
{
}
BOOST_ASSERT( !protocols_string.empty() );
HostItem host_item = *hosts_list_iterator;
- PingProtocolList host_protocols = parse_protocol_list( protocols_string );
+ PingProtocolList host_protocols;
+ int protocol_fallback_count = 0;
+ parse_protocol_list( protocols_string, &host_protocols, &protocol_fallback_count );
host_item->set_ping_protocol_list( host_protocols );
+ host_item->set_ping_protocol_fallback_count( protocol_fallback_count );
++hosts_list_iterator;
GlobalLogger.info() << get_command_string() << "="
return parsed_success;
}
-PingProtocolList HostPingProtocolOption::parse_protocol_list(
- const std::string &protocol_list_string
+void HostPingProtocolOption::parse_protocol_list(
+ const std::string &protocol_list_string,
+ PingProtocolList *protocol_list,
+ int *protocol_fallback_count
+
) const
{
BOOST_ASSERT( !protocol_list_string.empty() );
- PingProtocolList protocol_list;
+ size_t protocol_index = 0;
string protocol_string;
istringstream iss( protocol_list_string );
{
BOOST_ASSERT( !protocol_string.empty());
- PingProtocol protocol = get_ping_protocol_from_string( protocol_string );
- protocol_list.push_back( protocol );
+ // The second item in the list is the amount of pings to perform before change from the
+ // first protocol to the second (e.g. ICMP,10,ICMPv6).
+ if ( protocol_index == 1 )
+ {
+ try
+ {
+ *protocol_fallback_count = boost::lexical_cast< int >( protocol_string );
+ }
+ catch ( boost::bad_lexical_cast const &ex )
+ {
+ GlobalLogger.error() << "Error: input string was not valid" << endl;
+ }
+ }
+ else
+ {
+ PingProtocol protocol = get_ping_protocol_from_string( protocol_string );
+ protocol_list->push_back( protocol );
- GlobalLogger.debug() << "- " << protocol_string;
+ GlobalLogger.debug() << "- " << protocol_string;
- BOOST_ASSERT( ( PingProtocol_First <= protocol ) && ( protocol <= PingProtocol_Last ) );
- }
+ BOOST_ASSERT( ( PingProtocol_First <= protocol ) && ( protocol <= PingProtocol_Last ) );
+ }
- BOOST_ASSERT( 0 < protocol_list.size() );
+ protocol_index++;
+ }
- return protocol_list;
+ BOOST_ASSERT( 0 < protocol_list->size() );
}