Changeset 5151 for sample


Ignore:
Timestamp:
Jul 21, 2009, 1:54:55 PM (15 years ago)
Author:
Christoph Mayer
Message:

begin merge back from relay branch

Location:
sample/pingpong
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sample/pingpong/PingPong.cpp

    r4948 r5151  
    1717// construction
    1818PingPong::PingPong() : pingId( 0 ) {
    19         Timer::setInterval( 5000 );
     19        Timer::setInterval( 1000 );
    2020}
    2121
     
    4141        // get initiator flag
    4242        this->isInitiator = Configuration::instance().read<bool>("node.initiator");
     43
     44        this->name = string("<ping>");
    4345
    4446        // get node name
     
    5557        if (config.exists("ariba.bootstrap.hints")) ariba->setProperty("bootstrap.hints",
    5658                        config.read<string>("ariba.bootstrap.hints"));
     59        if (config.exists("pingpong.name")) name =
     60                        config.read<string>("pingpong.name");
    5761
    5862        // start ariba module
     
    7175        // when initiating, you can define the overlay type, default is Chord [CHORD_OVERLAY]
    7276        SpoVNetProperties params;
    73         params.setBaseOverlayType( SpoVNetProperties::ONE_HOP_OVERLAY ); // alternative: OneHop
     77        //params.setBaseOverlayType( SpoVNetProperties::ONE_HOP_OVERLAY ); // alternative: OneHop
    7478
    7579        // initiate or join the spovnet
     
    122126        // function that is implemented further down in PingPong::onLinkUp
    123127
    124         logging_info( "pinging overlay neighbors with ping id " << ++pingId );
    125 
    126         PingPongMessage pingmsg( pingId );
     128//      logging_info( "pinging overlay neighbors with ping id " << ++pingId );
     129
     130        PingPongMessage pingmsg( pingId, name );
    127131
    128132        //-----------------------------------------------------------------------
    129133        // Option 1: get all neighboring nodes and send the message to each
    130134        //-----------------------------------------------------------------------
     135        counter++;
     136        if (counter<0 || counter>4) {
     137                counter = 0;
     138                string s;
     139                for (int i=0; i<names.size();i++) {
     140                        if (i!=0) s+= ", ";
     141                        s = s+names[i];
     142                }
     143                logging_info("----> I am " << name << " and I know " << s);
     144                names.clear();
     145        }
    131146        vector<NodeID> nodes = node->getNeighborNodes();
    132147        BOOST_FOREACH( NodeID nid, nodes ){
     
    162177void PingPong::onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk) {
    163178        PingPongMessage* pingmsg = msg.getMessage()->convert<PingPongMessage> ();
    164 
    165         logging_info( "received ping message on link " << lnk.toString()
    166                         << " from node " << remote.toString()
    167                         << ": " << pingmsg->info() );
     179        bool found=false;
     180        for (int i=0;i<names.size(); i++) if (names[i]==pingmsg->getName()) found=true;
     181        if (!found) names.push_back(pingmsg->getName());
     182//      logging_info( "received ping message on link " << lnk.toString()
     183//                      << " from node " << remote.toString()
     184//                      << ": " << pingmsg->info() );
    168185}
    169186
  • sample/pingpong/PingPong.h

    r3071 r5151  
    66#include "ariba/utility/system/StartupInterface.h"
    77#include "ariba/utility/system/Timer.h"
     8
     9#include <vector>
    810
    911using namespace ariba;
     
    1517namespace pingpong {
    1618
     19using namespace std;
     20
    1721/**
    18 /* The PingPong main class
    19 /* This class implements an example service for demonstration purposes
    20 /* The pingpong class sends and receives messages between two SpoVNet
    21 /* instances
    22 **/
    23 class PingPong :
    24         public NodeListener,
     22 /* The PingPong main class
     23 /* This class implements an example service for demonstration purposes
     24 /* The pingpong class sends and receives messages between two SpoVNet
     25 /* instances
     26 **/
     27class PingPong: public NodeListener,
    2528        public CommunicationListener,
    2629        public StartupInterface,
     
    3538protected:
    3639        // communication listener interface
    37         virtual bool onLinkRequest(const NodeID& remote, const DataMessage& msg = DataMessage::UNSPECIFIED);
    38         virtual void onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk= LinkID::UNSPECIFIED);
     40        virtual bool onLinkRequest(const NodeID& remote, const DataMessage& msg =
     41                        DataMessage::UNSPECIFIED);
     42        virtual void onMessage(const DataMessage& msg, const NodeID& remote,
     43                const LinkID& lnk = LinkID::UNSPECIFIED);
    3944        virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
    4045        virtual void onLinkDown(const LinkID& lnk, const NodeID& remote);
     
    4348
    4449        // node listener interface
    45         virtual void onJoinCompleted( const SpoVNetID& vid );
    46         virtual void onJoinFailed( const SpoVNetID& vid );
    47         virtual void onLeaveCompleted( const SpoVNetID& vid );
    48         virtual void onLeaveFailed( const SpoVNetID& vid );
     50        virtual void onJoinCompleted(const SpoVNetID& vid);
     51        virtual void onJoinFailed(const SpoVNetID& vid);
     52        virtual void onLeaveCompleted(const SpoVNetID& vid);
     53        virtual void onLeaveFailed(const SpoVNetID& vid);
    4954
    5055        // startup wrapper interface
     
    5358
    5459        // timer events
    55         virtual void eventFunction();
     60        virtual void eventFunction();
    5661
    5762private:
    5863        // the ariba module and a node
    5964        AribaModule* ariba;
    60         Node*        node;
     65        Node* node;
     66        string name;
     67        int counter;
     68        vector<string> names;
    6169
    6270        // flag, whether this node initiates or just joins the spovnet
    6371        bool isInitiator;
    6472
    65         // the ping pong service id
    66         static ServiceID PINGPONG_SERVICEID;
     73        // the ping pong service id
     74        static ServiceID PINGPONG_SERVICEID;
    6775
    68         // the current ping id
    69         unsigned long pingId;
     76        // the current ping id
     77        unsigned long pingId;
    7078
    7179};
  • sample/pingpong/PingPongMessage.cpp

    r4626 r5151  
    1010}
    1111
    12 PingPongMessage::PingPongMessage(uint8_t _id) : id(_id) {
     12PingPongMessage::PingPongMessage(uint8_t _id, string name) : id(_id),name(name) {
    1313}
    1414
  • sample/pingpong/PingPongMessage.h

    r4625 r5151  
    1818public:
    1919        PingPongMessage();
    20         PingPongMessage( uint8_t _id );
     20        PingPongMessage( uint8_t _id, string name = string("<ping>") );
    2121        virtual ~PingPongMessage();
    2222
    2323        string info();
    2424        uint8_t getid();
     25
     26        inline string getName() const {
     27                return name;
     28        }
    2529private:
    2630        uint8_t id;
     31        string name;
    2732};
    2833
     
    3035
    3136sznBeginDefault( ariba::application::pingpong::PingPongMessage, X ) {
    32         X && id;
     37        X && id && T(name);
    3338} sznEnd();
    3439
  • sample/pingpong/main.cpp

    r4925 r5151  
    77using ariba::application::pingpong::PingPong;
    88
    9 //*************************************************
    10 /*
    11 #include "ariba/utility/bootstrap/BootstrapManager.h"
    12 using ariba::utility::BootstrapManager;
    13 
    14 void debug(){
    15         StartupWrapper::startSystem();
    16 
    17         BootstrapManager& manager = BootstrapManager::instance();
    18         manager.registerModule( BootstrapManager::BootstrapTypePeriodicBroadcast );
    19 
    20         manager.publish("testname", "testinfo1", "testinfo2", "testinfo3");
    21         getchar();
    22         manager.revoke("testname");
    23 
    24         manager.unregisterModule( BootstrapManager::BootstrapTypePeriodicBroadcast );
    25         StartupWrapper::stopSystem();
    26 }
    27 */
    28 //*************************************************
    29 
    309int main( int argc, char** argv ) {
    31 
    32         //debug();
    33         //return 0;
    3410
    3511        // get config file
Note: See TracChangeset for help on using the changeset viewer.