config/option/hostpingprotocoloption.cpp
config/option/hostportoption.cpp
config/option/hostnameoption.cpp
+ config/option/hostsourcenetworkinterfaceoption.cpp
config/option/hostsdownlimitoption.cpp
config/option/linkdownintervaloption.cpp
config/option/linkupintervaloption.cpp
#include "config/option/hostportoption.h"
#include "config/option/hostpingprotocoloption.h"
#include "config/option/hostpingintervaloption.h"
+#include "config/option/hostsourcenetworkinterfaceoption.h"
#include "config/option/linkdownintervaloption.h"
#include "config/option/linkupintervaloption.h"
#include "config/option/logleveloption.h"
HostConfigurationOptionItem host_port( new HostPortOption );
HostOptions.push_back( host_port );
+ HostConfigurationOptionItem host_source_network_interface( new HostSourceNetworkInterfaceOption );
+ HostOptions.push_back( host_source_network_interface );
+
HostConfigurationOptionItem host_protocol( new HostPingProtocolOption );
HostOptions.push_back( host_protocol );
Host::Host( string address ) :
Address( address ),
Port( 0 ),
+ SourceNetworkInterface( "" ),
Protocol( PingProtocol_ICMP ),
IntervalInSec( 0 )
{
}
/**
+ * @return The network interface from where the pings will depart.
+ */
+string Host::get_source_network_interface() const
+{
+ return SourceNetworkInterface;
+}
+
+/**
+ * @param source_network_interface The network interface from where the pings will depart.
+ */
+void Host::set_source_network_interface(
+ const string &source_network_interface
+)
+{
+ SourceNetworkInterface = source_network_interface;
+}
+
+/**
* @return The protocol used to ping this host.
*/
PingProtocol Host::get_ping_protocol() const
uint16_t get_port() const;
void set_port( const uint16_t port );
+ std::string get_source_network_interface() const;
+ void set_source_network_interface(
+ const std::string &source_network_interface
+ );
+
PingProtocol get_ping_protocol() const;
void set_ping_protocol( const PingProtocol ping_protocol );
std::string Address;
/// The port of the host
uint16_t Port;
+ /// The network interface from where the pings will depart
+ std::string SourceNetworkInterface;
/// The protocol to ping
PingProtocol Protocol;
/// The interval between each ping to the host
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#include "config/option/hostsourcenetworkinterfaceoption.h"
+
+#include <string>
+
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp>
+
+#include <logfunc.hpp>
+
+using namespace std;
+using boost::program_options::value;
+using boost::program_options::variables_map;
+using I2n::Logger::GlobalLogger;
+
+//-----------------------------------------------------------------------------
+// HostSourceNetworkInterfaceOption
+//-----------------------------------------------------------------------------
+
+HostSourceNetworkInterfaceOption::HostSourceNetworkInterfaceOption() :
+ HostConfigurationOption(
+ "host.source-network-interface",
+ value< vector<string> >(),
+ "The network interface from where the packets will be received and originated"
+ )
+{
+}
+
+HostSourceNetworkInterfaceOption::~HostSourceNetworkInterfaceOption()
+{
+}
+
+bool HostSourceNetworkInterfaceOption::parse(
+ const variables_map& vm,
+ Configuration *configuration
+)
+{
+ size_t hosts_count = 0;
+ size_t hosts_source_interface_count = 0;
+ bool parsed_success = false;
+
+ // [host] source-network-interface
+ if ( 1 <= vm.count( get_command_string() ) )
+ {
+ HostList hosts_list = configuration->get_hosts();
+ HostList::iterator hosts_list_iterator = hosts_list.begin();
+ hosts_count = hosts_list.size();
+
+ vector<string> host_source_interface_list = vm[ get_command_string() ].as< vector<string> >();
+ hosts_source_interface_count = host_source_interface_list.size();
+
+ BOOST_ASSERT( hosts_count >= hosts_source_interface_count );
+
+ BOOST_FOREACH( string host_source_interface, host_source_interface_list )
+ {
+ BOOST_ASSERT( !host_source_interface.empty() );
+
+ HostItem host_item = *hosts_list_iterator;
+ host_item->set_source_network_interface( host_source_interface );
+ ++hosts_list_iterator;
+
+ GlobalLogger.info() << get_command_string() << "=" << host_source_interface << endl;
+ }
+
+ parsed_success = true;
+ }
+
+ set_hosts_count( hosts_source_interface_count );
+
+ BOOST_ASSERT( hosts_count == hosts_source_interface_count );
+
+ return parsed_success;
+}
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#ifndef HOST_SOURCE_NETWORK_INTERFACE_OPTION_H
+#define HOST_SOURCE_NETWORK_INTERFACE_OPTION_H
+
+#include <boost/program_options.hpp>
+
+#include "config/option/hostconfigurationoption.h"
+
+//-----------------------------------------------------------------------------
+// HostSourceNetworkInterfaceOption
+//-----------------------------------------------------------------------------
+
+/**
+ * @brief This class represents the "[host] source-network-interface" configuration
+ * option.
+ */
+class HostSourceNetworkInterfaceOption : public HostConfigurationOption
+{
+public:
+ HostSourceNetworkInterfaceOption();
+ virtual ~HostSourceNetworkInterfaceOption();
+
+ virtual bool parse(
+ const boost::program_options::variables_map &vm,
+ Configuration *configuration
+ );
+
+};
+
+#endif // HOST_SOURCE_NETWORK_INTERFACE_OPTION_H