Merge branch 'ip-version-drop'
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Wed, 21 Mar 2012 00:42:14 +0000 (21:42 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Wed, 21 Mar 2012 22:42:37 +0000 (19:42 -0300)
Conflicts:
src/config/host.cpp
src/config/host.h
src/host/pingscheduler.h
src/main.cpp
test/test_configurationcommandline.cpp
test/test_configurationoptions.cpp

12 files changed:
1  2 
Readme
src/CMakeLists.txt
src/config/host.cpp
src/config/host.h
src/host/pinger.h
src/host/pingscheduler.cpp
src/host/pingscheduler.h
src/icmp/icmppinger.cpp
src/main.cpp
test/test_configurationcommandline.cpp
test/test_configurationfile.cpp
test/test_configurationoptions.cpp

diff --cc Readme
--- 1/Readme
--- 2/Readme
+++ b/Readme
@@@ -83,12 -81,9 +83,12 @@@ This configurations are shared among an
    IP is provide, it is the only which will be pinged.
  - port: when using a port based protocol, like TCP, this field specifies in
    which port to ping the host.
 +- source-network-interface: the local network interface from where the ping
 +  packages for a given host will originate. This setting is used only if the
 +  global network interface was not provided.
  - interval: the host will be pinged every "interval" seconds.
  - ping-protocol: indicates which protocol to use to ping the destination host,
-   the currently supported protocols are TCP and ICMP.
+   the currently supported protocols are TCP (tcp, tcp_ipv6) and ICMP (icmp, icmpv6).
  
  
  
Simple merge
@@@ -37,8 -37,7 +37,8 @@@ using namespace std
  Host::Host( string address ) :
      Address( address ),
      Port( 0 ),
 +    SourceNetworkInterface( "" ),
-     Protocol( PingProtocol_ICMP ),
+     ProtocolList(),
      IntervalInSec( 0 )
  {
  }
@@@ -87,29 -86,11 +87,29 @@@ void Host::set_port( const uint16_t por
  }
  
  /**
 + * @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.
+  * @return The list of protocols used to ping this host.
   */
- PingProtocol Host::get_ping_protocol() const
+ PingProtocolList Host::get_ping_protocol_list() const
  {
-     return Protocol;
+     return ProtocolList;
  }
  
  /**
@@@ -48,13 -48,8 +48,13 @@@ public
      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 );
+     PingProtocolList get_ping_protocol_list() const;
+     void set_ping_protocol_list( const PingProtocolList &ping_protocol );
  
      int get_interval_in_sec() const;
      void set_interval_in_sec( const int interval_in_sec );
@@@ -64,10 -59,8 +64,10 @@@ private
      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 list of protocols used to ping
+     PingProtocolList ProtocolList;
      /// The interval between each ping to the host
      int IntervalInSec;
  
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc src/main.cpp
@@@ -122,18 -122,14 +122,18 @@@ void init_pingers
      {
          string destination_address = host->get_address();
          uint16_t destination_port = host->get_port();
 +        string host_network_interface = host->get_source_network_interface();
 +        string network_interface = ( default_network_interface.empty() ) ?
 +                host_network_interface :
 +                default_network_interface;
-         PingProtocol protocol = host->get_ping_protocol();
+         PingProtocolList protocol_list = host->get_ping_protocol_list();
          int ping_interval_in_sec = host->get_interval_in_sec();
          PingSchedulerItem scheduler(
                  new PingScheduler(
 -                        local_interface,
 +                        network_interface,
                          destination_address,
                          destination_port,
-                         protocol,
+                         protocol_list,
                          ping_interval_in_sec,
                          ping_fail_limit,
                          nameserver,
@@@ -32,7 -32,7 +32,7 @@@ BOOST_AUTO_TEST_SUITE( TestConfiguratio
  
  BOOST_AUTO_TEST_CASE( normal_options )
  {
-     const int argc = 20;
 -    const int argc = 22;
++    const int argc = 25;
      const char *argv[argc] = {
          "./pingcheck",
          "--daemon",
          // 2nd host
          "--host.name=www.ufsc.br",
          "--host.port=25",
 +        "--host.source-network-interface=lo",
          "--host.interval=1000",
          "--host.ping-protocol=ICMP",
+         // 3rd host
+         "--host.name=www.kernel.org",
+         "--host.port=80",
++        "--host.source-network-interface=eth1",
+         "--host.interval=1000",
+         "--host.ping-protocol=ICMP,ICMPv6",
      };
      boost::program_options::variables_map vm;
      Configuration config;
      HostItem host1 = config.get_hosts().at(0);
      BOOST_CHECK_EQUAL( host1->get_address(), "www.intra2net.com" );
      BOOST_CHECK_EQUAL( host1->get_port(), 80 );
 +    BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "eth0" );
      BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 4000 );
-     BOOST_CHECK_EQUAL( host1->get_ping_protocol(), PingProtocol_TCP );
+     BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().size(), 1 );
+     BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().front(), PingProtocol_TCP );
      HostItem host2 = config.get_hosts().at(1);
      BOOST_CHECK_EQUAL( host2->get_address(), "www.ufsc.br" );
      BOOST_CHECK_EQUAL( host2->get_port(), 25 );
 +    BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "lo" );
      BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 1000 );
-     BOOST_CHECK_EQUAL( host2->get_ping_protocol(), PingProtocol_ICMP );
+     BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().size(), 1 );
+     BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().front(), PingProtocol_ICMP );
+     HostItem host3 = config.get_hosts().at(2);
+     BOOST_CHECK_EQUAL( host3->get_address(), "www.kernel.org" );
+     BOOST_CHECK_EQUAL( host3->get_port(), 80 );
++    BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth1" );
+     BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 1000 );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().size(), 2 );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().front(), PingProtocol_ICMP );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().back(), PingProtocol_ICMPv6 );
  }
  
  BOOST_AUTO_TEST_CASE( version_option )
@@@ -60,9 -59,14 +60,16 @@@ BOOST_AUTO_TEST_CASE( normal_options 
      file << "[host]\n";
      file << "name=www.ufsc.br\n";
      file << "port=25\n";
-     file << "source-network-interface=eth3\n";
++    file << "source-network-interface=eth2\n";
      file << "interval=1000\n";
      file << "ping-protocol=ICMP\n";
+     // 3rd host
+     file << "[host]\n";
+     file << "name=www.kernel.org\n";
+     file << "port=80\n";
++    file << "source-network-interface=eth3\n";
+     file << "interval=1000\n";
+     file << "ping-protocol=TCP,TCP_IPv6\n";
      file.close();
  
      ConfigurationFile configuration_file( file_name );
      HostItem host1 = config.get_hosts().at(0);
      BOOST_CHECK_EQUAL( host1->get_address(), "www.intra2net.com" );
      BOOST_CHECK_EQUAL( host1->get_port(), 80 );
 +    BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "wlan1" );
      BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 4000 );
-     BOOST_CHECK_EQUAL( host1->get_ping_protocol(), PingProtocol_TCP );
+     BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().size(), 1 );
+     BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().front(), PingProtocol_TCP );
      HostItem host2 = config.get_hosts().at(1);
      BOOST_CHECK_EQUAL( host2->get_address(), "www.ufsc.br" );
      BOOST_CHECK_EQUAL( host2->get_port(), 25 );
-     BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "eth3" );
++    BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "eth2" );
      BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 1000 );
-     BOOST_CHECK_EQUAL( host2->get_ping_protocol(), PingProtocol_ICMP );
+     BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().size(), 1 );
+     BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().front(), PingProtocol_ICMP );
+     HostItem host3 = config.get_hosts().at(2);
+     BOOST_CHECK_EQUAL( host3->get_address(), "www.kernel.org" );
+     BOOST_CHECK_EQUAL( host3->get_port(), 80 );
++    BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth3" );
+     BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 1000 );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().size(), 2 );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().front(), PingProtocol_TCP );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().back(), PingProtocol_TCP_IPv6 );
  }
  
  BOOST_AUTO_TEST_SUITE_END()
@@@ -205,9 -200,18 +205,21 @@@ BOOST_AUTO_TEST_CASE( parse_hosts_optio
      // host 4
      hosts_names.push_back( "www.google.com" );
      hosts_ports.push_back( 64 );
 +    hosts_source_interfaces.push_back( "eth4" );
      hosts_ping_protocols.push_back( "TCP_IPv6" );
      hosts_intervals.push_back( 74 );
+     // host 5
+     hosts_names.push_back( "www.kernel.org" );
+     hosts_ports.push_back( 64 );
++    hosts_source_interfaces.push_back( "eth5" );
+     hosts_ping_protocols.push_back( "TCP,ICMP" );
+     hosts_intervals.push_back( 75 );
+     // host 6
+     hosts_names.push_back( "www.linux.com" );
+     hosts_ports.push_back( 64 );
++    hosts_source_interfaces.push_back( "eth6" );
+     hosts_ping_protocols.push_back( "ICMPv6,TCP_IPv6" );
+     hosts_intervals.push_back( 76 );
  
      ConfigurationOptions config_options;
      Configuration configuration;
       HostItem host1 = configuration.get_hosts().at(0);
      BOOST_CHECK_EQUAL( host1->get_address(), "www.fazenda.gov.br" );
      BOOST_CHECK_EQUAL( host1->get_port(), 61 );
 +    BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "eth1" );
-     BOOST_CHECK_EQUAL( host1->get_ping_protocol(), PingProtocol_TCP );
+     BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().front(), PingProtocol_TCP );
      BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 71 );
      // host 2
       HostItem host2 = configuration.get_hosts().at(1);
      BOOST_CHECK_EQUAL( host2->get_address(), "www.intra2net.de" );
      BOOST_CHECK_EQUAL( host2->get_port(), 62 );
 +    BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "eth2" );
-     BOOST_CHECK_EQUAL( host2->get_ping_protocol(), PingProtocol_ICMP );
+     BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().front(), PingProtocol_ICMP );
      BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 72 );
      // host 3
       HostItem host3 = configuration.get_hosts().at(2);
      BOOST_CHECK_EQUAL( host3->get_address(), "www.ufsc.br" );
      BOOST_CHECK_EQUAL( host3->get_port(), 63 );
 +    BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth3" );
-     BOOST_CHECK_EQUAL( host3->get_ping_protocol(), PingProtocol_ICMPv6 );
+     BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().front(), PingProtocol_ICMPv6 );
      BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 73 );
      // host 4
-      HostItem host4 = configuration.get_hosts().at(3);
+     HostItem host4 = configuration.get_hosts().at(3);
      BOOST_CHECK_EQUAL( host4->get_address(), "www.google.com" );
      BOOST_CHECK_EQUAL( host4->get_port(), 64 );
 +    BOOST_CHECK_EQUAL( host4->get_source_network_interface(), "eth4" );
-     BOOST_CHECK_EQUAL( host4->get_ping_protocol(), PingProtocol_TCP_IPv6 );
+     BOOST_CHECK_EQUAL( host4->get_ping_protocol_list().front(), PingProtocol_TCP_IPv6 );
      BOOST_CHECK_EQUAL( host4->get_interval_in_sec(), 74 );
+     // host 5
+     HostItem host5 = configuration.get_hosts().at(4);
+     BOOST_CHECK_EQUAL( host5->get_address(), "www.kernel.org" );
+     BOOST_CHECK_EQUAL( host5->get_port(), 64 );
++    BOOST_CHECK_EQUAL( host5->get_source_network_interface(), "eth5" );
+     BOOST_CHECK_EQUAL( host5->get_ping_protocol_list().size(), 2 );
+     BOOST_CHECK_EQUAL( host5->get_ping_protocol_list().front(), PingProtocol_TCP );
+     BOOST_CHECK_EQUAL( host5->get_ping_protocol_list().back(), PingProtocol_ICMP );
+     BOOST_CHECK_EQUAL( host5->get_interval_in_sec(), 75 );
+     // host 6
+     HostItem host6 = configuration.get_hosts().at(5);
+     BOOST_CHECK_EQUAL( host6->get_address(), "www.linux.com" );
+     BOOST_CHECK_EQUAL( host6->get_port(), 64 );
++    BOOST_CHECK_EQUAL( host6->get_source_network_interface(), "eth6" );
+     BOOST_CHECK_EQUAL( host6->get_ping_protocol_list().size(), 2 );
+     BOOST_CHECK_EQUAL( host6->get_ping_protocol_list().front(), PingProtocol_ICMPv6 );
+     BOOST_CHECK_EQUAL( host6->get_ping_protocol_list().back(), PingProtocol_TCP_IPv6 );
+     BOOST_CHECK_EQUAL( host6->get_interval_in_sec(), 76 );
  }
  
  BOOST_AUTO_TEST_CASE( halt_on_generic_options )