Changeset 12060 for sample/pingpong


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:
sample/pingpong
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sample/pingpong/PingPong.cpp

    r9990 r12060  
    33#include "ariba/utility/visual/DddVis.h"
    44
     5#include <boost/property_tree/ptree.hpp>
     6#include <boost/property_tree/json_parser.hpp>
     7
     8
    59using ariba::utility::Configuration;
    610using namespace ariba;
     
    1721
    1822// construction
    19 PingPong::PingPong() : pingId( 0 ) {
    20         Timer::setInterval( 1000 );
     23PingPong::PingPong( string config)  :
     24        node(),
     25        pingId( 0 ),
     26        config_file(config)
     27{
     28        Timer::setInterval( 3000 );
    2129}
    2230
     
    2634
    2735// implementation of the startup interface
    28 void PingPong::startup() {
    29 
     36void PingPong::startup()
     37{
     38    using boost::property_tree::ptree;
     39    using boost::property_tree::json_parser::read_json;
     40   
    3041        // set up logging
    31         logging_rootlevel_info();
     42        logging_rootlevel_debug();
    3243        logging_classlevel_debug(PingPong);
    3344
    34         logging_info( "starting up PingPong service ... " );
    35 
    36         // create ariba module
    37         logging_debug( "creating ariba underlay module ... " );
    38         ariba = new AribaModule();
    39 
    40         Name spovnetName("pingpong");
    41         Name nodeName = Name::UNSPECIFIED;
    42         this->name = string("<ping>");
    43 
    44         // get settings from configuration object
    45         if( Configuration::haveConfig() ){
    46                 Configuration& config = Configuration::instance();
    47 
    48                 // get node name
    49                 if (config.exists("node.name"))
    50                         nodeName = config.read<string> ("node.name");
    51 
    52                 // configure ariba module
    53                 if (config.exists("ariba.endpoints"))
    54                         ariba->setProperty("endpoints", config.read<string>("ariba.endpoints"));
    55                 if (config.exists("ariba.bootstrap.hints"))
    56                         ariba->setProperty("bootstrap.hints", config.read<string>("ariba.bootstrap.hints"));
    57                 if (config.exists("pingpong.name"))
    58                         name = config.read<string>("pingpong.name");
    59 
    60                 // get visualization
    61                 if( config.exists("ariba.visual3d.ip") && config.exists("ariba.visual3d.port")){
    62                         string ip = config.read<string>("ariba.visual3d.ip");
    63                         unsigned int port = config.read<unsigned int>("ariba.visual3d.port");
    64                         unsigned int color = config.exists("node.color") ?
    65                                         config.read<unsigned int>("node.color") : 0;
    66                         ariba::utility::DddVis::instance().configure(ip, port, color);
    67                 }
    68 
    69         } // if( Configuration::haveConfig() )
    70 
    71         // start ariba module
    72         ariba->start();
    73 
    74         // create node and join
    75         node = new Node( *ariba, nodeName );
    76 
     45        logging_info( "[PINGPONG]\t starting up PingPong service ... " );
     46
     47    // read config
     48    ptree config;
     49    try
     50    {
     51        read_json(config_file, config);
     52    }
     53    catch ( exception& e )
     54    {
     55        logging_warn("ERROR: Failed to read config file »" << config_file << "«: ");
     56        logging_warn(e.what());
     57        logging_warn("---> Using fallback config.");
     58       
     59        config.put("ariba.spovnet_name", "pingpong");
     60    }
     61   
     62    name = "TODO";
     63   
    7764        // bind communication and node listener
    78         node->bind( this );                              /*NodeListener*/
    79         node->bind( this, PingPong::PINGPONG_SERVICEID); /*CommunicationListener*/
    80 
    81         // start node module
    82         node->start();
    83 
    84         // when initiating, you can define the overlay type, default is Chord [CHORD_OVERLAY]
    85         SpoVNetProperties params;
    86         //params.setBaseOverlayType( SpoVNetProperties::ONE_HOP_OVERLAY ); // alternative: OneHop
    87 
    88         // initiate the spovnet
    89         logging_info("initiating spovnet");
    90         node->initiate(spovnetName, params);
    91 
    92         // join the spovnet
    93         logging_info("joining spovnet");
    94         node->join(spovnetName);
     65        node.bind( this );                              /*NodeListener*/
     66        node.bind( this, PingPong::PINGPONG_SERVICEID); /*CommunicationListener*/
     67
     68    // connecting
     69    logging_debug( "connecting ... " );
     70
     71        node.connect(config.get_child("ariba"));
    9572
    9673        // ping pong started up...
    97         logging_info( "pingpong starting up with"
    98                         << " [spovnetid " << node->getSpoVNetId().toString() << "]"
    99                         << " and [nodeid " << node->getNodeId().toString() << "]" );
     74        logging_info( "[PINGPONG]\t pingpong starting up with"
     75                        << " [spovnetid " << node.getSpoVNetId().toString() << "]"
     76                        << " and [nodeid " << node.getNodeId().toString() << "]" );
    10077}
    10178
     
    10380void PingPong::shutdown() {
    10481
    105         logging_info( "pingpong service starting shutdown sequence ..." );
     82        logging_info( "[PINGPONG]\t pingpong service starting shutdown sequence ..." );
    10683
    10784        // stop timer
     
    10986
    11087        // leave spovnet
    111         node->leave();
     88        node.leave();
    11289
    11390        // unbind communication and node listener
    114         node->unbind( this );                               /*NodeListener*/
    115         node->unbind( this, PingPong::PINGPONG_SERVICEID ); /*CommunicationListener*/
    116 
    117         // stop the ariba module
    118         ariba->stop();
    119 
    120         // delete node and ariba module
    121         delete node;
    122         delete ariba;
     91        node.unbind( this );                               /*NodeListener*/
     92        node.unbind( this, PingPong::PINGPONG_SERVICEID ); /*CommunicationListener*/
    12393
    12494        // now we are completely shut down
     
    12999void PingPong::eventFunction() {
    130100
     101    if ( node.getNeighborNodes().size() == 0)
     102    {
     103        logging_info( "[PINGPONG]\t +++ no neighbors +++" );
     104        return;
     105    }
     106   
    131107        // we ping all nodes that are known in the overlay structure
    132108        // this can be all nodes (OneHop) overlay or just some neighbors
     
    140116
    141117        pingId++;
    142         logging_info( "pinging overlay neighbors with ping id " << pingId );
     118//      logging_info( endl << "#################" << endl
     119    logging_info( endl << "|||||||||| >>>>>>>>>>" << endl
     120                << "[PINGPONG]\t PINGING overlay neighbors with ping id " << pingId );
    143121        PingPongMessage pingmsg( pingId, name );
    144 
     122       
    145123        //-----------------------------------------------------------------------
    146124        // Option 1: get all neighboring nodes and send the message to each
     
    154132                        s = s+names[i];
    155133                }
    156                 logging_info("----> I am " << name << " and I know " << s);
     134                logging_info("[PINGPONG]\t ----> I am " << name << " and I know " << s);
    157135                names.clear();
    158136        }
    159137
    160         vector<NodeID> nodes = node->getNeighborNodes();
     138        vector<NodeID> nodes = node.getNeighborNodes();
    161139        BOOST_FOREACH( NodeID nid, nodes ){
    162                 logging_info( "sending ping message to " << nid.toString() );
    163                 node->sendMessage( pingmsg, nid, PingPong::PINGPONG_SERVICEID );
     140                logging_info( "[PINGPONG]\t sending ping message to " << nid.toString() );
     141                node.sendMessage( pingmsg, nid, PingPong::PINGPONG_SERVICEID );
    164142        }
    165143
     
    195173        for (int i=0;i<names.size(); i++) if (names[i]==pingmsg->getName()) found=true;
    196174        if (!found) names.push_back(pingmsg->getName());
    197         logging_info( "received ping message on link " << lnk.toString()
     175//      logging_info( endl << "#################" << endl
     176        logging_info( endl << "<<<<<<<<<< ||||||||||" << endl
     177                << "[PINGPONG]\t RECEIVED ping message on link "
     178                << lnk.toString()
     179                << " " << (node.isLinkDirect(lnk) ? "[DIRECT-LINK]" : "[INDIRECT-LINK]")
     180                << " HopCount: " << node.getHopCount(lnk)
    198181                        << " from node " << remote.toString()
     182                        << " (" << pingmsg->getName() << ")"
    199183                        << ": " << pingmsg->info() );
    200184        delete pingmsg;
  • sample/pingpong/PingPong.h

    r10570 r12060  
    3333
    3434public:
    35         PingPong();
     35        PingPong( string config );
    3636        virtual ~PingPong();
    3737
     
    6161private:
    6262        // the ariba module and a node
    63         AribaModule* ariba;
    64         Node* node;
     63//      AribaModule* ariba;
     64        Node node;
    6565        string name;
    6666        int counter;
     
    7373        unsigned long pingId;
    7474
     75        string config_file;
    7576};
    7677
  • sample/pingpong/main.cpp

    r5151 r12060  
    1010
    1111        // get config file
    12         string config = "../etc/settings.cnf";
     12        string config;
    1313        if (argc >= 2) config = argv[1];
    1414
    15         StartupWrapper::initConfig( config );
     15//      StartupWrapper::initConfig( config );
    1616        StartupWrapper::startSystem();
    1717
    1818        // this will do the main functionality and block
    19         PingPong ping;
     19        PingPong ping(config);
    2020        StartupWrapper::startup(&ping);
    2121
Note: See TracChangeset for help on using the changeset viewer.