Ignore:
Timestamp:
Jun 19, 2013, 11:05:49 AM (11 years ago)
Author:
hock@…
Message:

Reintegrate branch: 20130111-hock-message_classes

improvements:

  • new message classes (reboost, zero-copy)
  • "fast path" for direct links (skip overlay layer)
  • link-properties accessible from the application
  • SystemQueue can call boost::bind functions
  • protlib compatibility removed (32bit overhead saved in every message)
  • addressing2
  • AddressDiscovery discoveres only addresses on which we're actually listening
  • ariba serialization usage reduced (sill used in OverlayMsg)
  • Node::connect, easier and cleaner interface to start-up ariba from the application
  • ariba configs via JSON, XML, etc (boost::property_tree)
  • keep-alive overhead greatly reduced
  • (relayed) overlay links can actually be closed now
  • lost messages are detected in most cases
  • notification to the application when link is transformed into direct-link
  • overlay routing: send message to second best hop if it would be dropped otherwise
  • SequenceNumbers (only mechanisms, so for: upward compatibility)
  • various small fixes


regressions:

  • bluetooth is not yet working again
  • bootstrap modules deactivated
  • liblog4xx is not working (use cout-logging)

This patch brings great performance and stability improvements at cost of backward compatibility.
Also bluetooth and the bootstrap modules have not been ported to the new interfaces, yet.

Location:
source/ariba/communication/networkinfo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/communication/networkinfo/AddressDiscovery.cpp

    r10700 r12060  
    4949#include <ifaddrs.h>
    5050
     51#include <string>
     52#include <boost/asio/ip/address.hpp>
     53#include <boost/foreach.hpp>
     54
     55#include "ariba/utility/addressing2/tcpip_endpoint.hpp"
     56#include "ariba/utility/addressing/mac_address.hpp"
     57
    5158#ifdef HAVE_LIBBLUETOOTH
    5259  #include <bluetooth/bluetooth.h>
     
    5865namespace communication {
    5966
    60 mac_address AddressDiscovery::getMacFromIF( const char* name ) {
     67
     68using namespace std;
     69using namespace addressing2;
     70using namespace boost::asio::ip;
     71
     72using ariba::addressing::mac_address;
     73
     74mac_address getMacFromIF( const char* name )
     75{
    6176        mac_address addr;
    6277#ifdef HAVE_LIBBLUETOOTH
     
    7388}
    7489
    75 int AddressDiscovery::dev_info(int s, int dev_id, long arg) {
    76 #ifdef HAVE_LIBBLUETOOTH
    77         endpoint_set* set = (endpoint_set*)arg;
    78         struct hci_dev_info di;
    79         memset(&di, 0, sizeof(struct hci_dev_info));
    80         di.dev_id = dev_id;
    81         if (ioctl(s, HCIGETDEVINFO, (void *) &di)) return 0;
    82         mac_address mac;
    83         mac.bluetooth( di.bdaddr );
    84         address_vf vf = mac;
    85         set->add(vf);
     90int dev_info(int s, int dev_id, long arg)
     91{
     92#ifdef HAVE_LIBBLUETOOTH
     93//      endpoint_set* set = (endpoint_set*)arg;
     94//      struct hci_dev_info di;
     95//      memset(&di, 0, sizeof(struct hci_dev_info));
     96//      di.dev_id = dev_id;
     97//      if (ioctl(s, HCIGETDEVINFO, (void *) &di)) return 0;
     98//      mac_address mac;
     99//      mac.bluetooth( di.bdaddr );
     100//      address_vf vf = mac;
     101//      set->add(vf);
    86102#endif
    87103        return 0;
    88104}
    89105
    90 void AddressDiscovery::discover_bluetooth( endpoint_set& endpoints ) {
    91 #ifdef HAVE_LIBBLUETOOTH
    92         hci_for_each_dev(HCI_UP, &AddressDiscovery::dev_info, (long)&endpoints );
    93 #endif
    94 }
    95 
    96 void AddressDiscovery::discover_ip_addresses( endpoint_set& endpoints ) {
    97         struct ifaddrs* ifaceBuffer = NULL;
    98         void*           tmpAddrPtr  = NULL;
    99 
    100         int ret = getifaddrs( &ifaceBuffer );
    101         if( ret != 0 ) return;
    102 
    103         for( struct ifaddrs* i=ifaceBuffer; i != NULL; i=i->ifa_next ) {
    104 
    105                 // ignore devices that are disabled or have no ip
    106                 if(i == NULL) continue;
    107                 struct sockaddr* addr = i->ifa_addr;
    108                 if (addr==NULL) continue;
    109 
    110                 // ignore tun devices
    111                 string device = string(i->ifa_name);
    112                 if(device.find_first_of("tun") == 0) continue;
    113 
    114                 if (addr->sa_family == AF_INET) {
    115                         // look for ipv4
    116                         char straddr[INET_ADDRSTRLEN];
    117                         tmpAddrPtr= &((struct sockaddr_in*)addr)->sin_addr;
    118                         inet_ntop( i->ifa_addr->sa_family, tmpAddrPtr, straddr, sizeof(straddr) );
    119                         ip_address ip = straddr;
    120                         if (ip.is_loopback()) continue;
    121                         address_vf vf = ip;
    122                         endpoints.add( vf );
    123                 } else
    124                 if (addr->sa_family == AF_INET6) {
    125                         // look for ipv6
    126                         char straddr[INET6_ADDRSTRLEN];
    127                         tmpAddrPtr= &((struct sockaddr_in6*)addr)->sin6_addr;
    128                         inet_ntop( i->ifa_addr->sa_family, tmpAddrPtr, straddr, sizeof(straddr) );
    129                         ip_address ip = straddr;
    130                         if (ip.is_loopback()) continue;
    131 //                      if (ip.is_link_local()) continue;
    132                         address_vf vf = ip;
    133                         endpoints.add( vf );
    134                 }
    135         }
    136 
    137         freeifaddrs(ifaceBuffer);
    138 }
    139 
    140 void AddressDiscovery::discover_endpoints( endpoint_set& endpoints ) {
    141         discover_ip_addresses( endpoints );
    142         discover_bluetooth( endpoints );
     106void discover_bluetooth(
     107        EndpointSetPtr listenOn_endpoints,
     108        EndpointSetPtr discovered_endpoints )
     109{
     110#ifdef HAVE_LIBBLUETOOTH
     111    // FIXME aktuell bluetooth
     112//      hci_for_each_dev(HCI_UP, &AddressDiscovery::dev_info, (long)&endpoints );
     113#endif
     114}
     115
     116void discover_ip_addresses(
     117        EndpointSetPtr listenOn_endpoints,
     118        EndpointSetPtr discovered_endpoints )
     119{
     120    bool discover_ipv4 = false;
     121    bool discover_ipv6 = false;
     122    vector<uint16_t> ipv4_ports;
     123    vector<uint16_t> ipv6_ports;
     124   
     125    /* analyze listenOn_endpoints */
     126    BOOST_FOREACH( TcpIP_EndpointPtr endp, listenOn_endpoints->get_tcpip_endpoints() )
     127    {
     128        // BRANCH: IPv4 any [0.0.0.0]
     129        if ( endp->to_asio().address() == address_v4::any() )
     130        {
     131            // add port
     132            ipv4_ports.push_back(endp->to_asio().port());
     133           
     134            discover_ipv4 = true;
     135        }
     136
     137        // BRANCH: IPv6 any [::]
     138        else if ( endp->to_asio().address() == address_v6::any() )
     139        {
     140            // add port
     141            ipv6_ports.push_back(endp->to_asio().port());
     142           
     143            discover_ipv6 = true;
     144
     145           
     146            // NOTE: on linux the ipv6-any address [::] catches ipv4 as well
     147            ipv4_ports.push_back(endp->to_asio().port());
     148            discover_ipv4 = true;
     149        }
     150       
     151        // BRANCH: explicit ip address
     152        else
     153        {
     154            // ---> don't discover anything, just add it directly
     155            discovered_endpoints->add_endpoint(endp);
     156        }
     157    }
     158   
     159   
     160    /* discover addresses */
     161    if ( discover_ipv4 || discover_ipv6 )
     162    {
     163        struct ifaddrs* ifaceBuffer = NULL;
     164        void*           tmpAddrPtr  = NULL;
     165   
     166        int ret = getifaddrs( &ifaceBuffer );
     167        if( ret != 0 ) return;
     168   
     169        for( struct ifaddrs* i=ifaceBuffer; i != NULL; i=i->ifa_next )
     170        {
     171            // ignore devices that are disabled or have no ip
     172            if(i == NULL) continue;
     173            struct sockaddr* addr = i->ifa_addr;
     174            if (addr==NULL) continue;
     175   
     176    //          // ignore tun devices  // XXX why?
     177    //          string device = string(i->ifa_name);
     178    //          if(device.find_first_of("tun") == 0) continue;
     179
     180            // IPv4
     181            if ( discover_ipv4 && addr->sa_family == AF_INET )
     182            {
     183                char straddr[INET_ADDRSTRLEN];
     184                tmpAddrPtr= &((struct sockaddr_in*)addr)->sin_addr;
     185                inet_ntop( i->ifa_addr->sa_family, tmpAddrPtr, straddr, sizeof(straddr) );
     186               
     187                address ip_addr = address::from_string(straddr);
     188   
     189                // skip loopback address
     190                if ( ip_addr.to_v4() == address_v4::loopback() )
     191                    continue;
     192
     193                // add endpoint for this address and every given ipv4 port
     194                BOOST_FOREACH( uint16_t port, ipv4_ports )
     195                {
     196                    tcp::endpoint tcpip_endp(ip_addr, port);
     197                    TcpIP_EndpointPtr endp(new tcpip_endpoint(tcpip_endp));
     198                   
     199                    discovered_endpoints->add_endpoint(endp);
     200                }
     201            }
     202           
     203            // IPv6
     204            else if ( discover_ipv6 && addr->sa_family == AF_INET6 )
     205            {
     206                // look for ipv6
     207                char straddr[INET6_ADDRSTRLEN];
     208                tmpAddrPtr= &((struct sockaddr_in6*)addr)->sin6_addr;
     209                inet_ntop( i->ifa_addr->sa_family, tmpAddrPtr, straddr, sizeof(straddr) );
     210               
     211                address ip_addr = address::from_string(straddr);
     212               
     213                // skip loopback address
     214                if ( ip_addr.to_v6() == address_v6::loopback() )
     215                    continue;
     216
     217                // add endpoint for this address and every given ipv4 port
     218                BOOST_FOREACH( uint16_t port, ipv6_ports )
     219                {
     220                    tcp::endpoint tcpip_endp(ip_addr, port);
     221                    TcpIP_EndpointPtr endp(new tcpip_endpoint(tcpip_endp));
     222                   
     223                    discovered_endpoints->add_endpoint(endp);
     224                }
     225            }
     226        }
     227   
     228        freeifaddrs(ifaceBuffer);
     229    }
     230}
     231
     232
     233
     234EndpointSetPtr AddressDiscovery::discover_endpoints(EndpointSetPtr listenOn_endpoints)
     235{
     236    EndpointSetPtr discovered_endpoints(new addressing2::endpoint_set());
     237   
     238        discover_ip_addresses( listenOn_endpoints, discovered_endpoints );
     239        discover_bluetooth( listenOn_endpoints, discovered_endpoints );
     240       
     241        return discovered_endpoints;
    143242}
    144243
  • source/ariba/communication/networkinfo/AddressDiscovery.h

    r5639 r12060  
    4040#define __ADDRESS_DISCOVERY_H
    4141
    42 #include "ariba/utility/addressing/addressing.hpp"
    43 
    44 using namespace ariba::addressing;
     42#include "ariba/utility/addressing2/endpoint_set.hpp"
    4543
    4644namespace ariba {
    4745namespace communication {
    4846
     47using addressing2::EndpointSetPtr;
     48
    4949class AddressDiscovery {
    5050public:
    51         static void discover_endpoints( endpoint_set& endpoints );
     51        static EndpointSetPtr discover_endpoints(EndpointSetPtr listenOn_endpoints);
    5252
    5353private:
    54         static mac_address getMacFromIF( const char* name );
    55         static int dev_info(int s, int dev_id, long arg);
    56         static void discover_bluetooth( endpoint_set& endpoints );
    57         static void discover_ip_addresses( endpoint_set& endpoints );
     54        // TODO aktuell weg damit..
     55//      static mac_address getMacFromIF( const char* name );
     56//      static int dev_info(int s, int dev_id, long arg);
     57//      static void discover_bluetooth( EndpointSetPtr listenOn_endpoints, EndpointSetPtr discovered_endpoints );
     58//      static void discover_ip_addresses( EndpointSetPtr listenOn_endpoints, EndpointSetPtr discovered_endpoints );
    5859};
    5960
Note: See TracChangeset for help on using the changeset viewer.