- Timestamp:
- Jul 21, 2009, 1:54:55 PM (15 years ago)
- Location:
- sample/pingpong
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/pingpong/PingPong.cpp
r4948 r5151 17 17 // construction 18 18 PingPong::PingPong() : pingId( 0 ) { 19 Timer::setInterval( 5000 );19 Timer::setInterval( 1000 ); 20 20 } 21 21 … … 41 41 // get initiator flag 42 42 this->isInitiator = Configuration::instance().read<bool>("node.initiator"); 43 44 this->name = string("<ping>"); 43 45 44 46 // get node name … … 55 57 if (config.exists("ariba.bootstrap.hints")) ariba->setProperty("bootstrap.hints", 56 58 config.read<string>("ariba.bootstrap.hints")); 59 if (config.exists("pingpong.name")) name = 60 config.read<string>("pingpong.name"); 57 61 58 62 // start ariba module … … 71 75 // when initiating, you can define the overlay type, default is Chord [CHORD_OVERLAY] 72 76 SpoVNetProperties params; 73 params.setBaseOverlayType( SpoVNetProperties::ONE_HOP_OVERLAY ); // alternative: OneHop77 //params.setBaseOverlayType( SpoVNetProperties::ONE_HOP_OVERLAY ); // alternative: OneHop 74 78 75 79 // initiate or join the spovnet … … 122 126 // function that is implemented further down in PingPong::onLinkUp 123 127 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 ); 127 131 128 132 //----------------------------------------------------------------------- 129 133 // Option 1: get all neighboring nodes and send the message to each 130 134 //----------------------------------------------------------------------- 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 } 131 146 vector<NodeID> nodes = node->getNeighborNodes(); 132 147 BOOST_FOREACH( NodeID nid, nodes ){ … … 162 177 void PingPong::onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk) { 163 178 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() ); 168 185 } 169 186 -
sample/pingpong/PingPong.h
r3071 r5151 6 6 #include "ariba/utility/system/StartupInterface.h" 7 7 #include "ariba/utility/system/Timer.h" 8 9 #include <vector> 8 10 9 11 using namespace ariba; … … 15 17 namespace pingpong { 16 18 19 using namespace std; 20 17 21 /** 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 **/ 27 class PingPong: public NodeListener, 25 28 public CommunicationListener, 26 29 public StartupInterface, … … 35 38 protected: 36 39 // 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); 39 44 virtual void onLinkUp(const LinkID& lnk, const NodeID& remote); 40 45 virtual void onLinkDown(const LinkID& lnk, const NodeID& remote); … … 43 48 44 49 // 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); 49 54 50 55 // startup wrapper interface … … 53 58 54 59 // timer events 55 60 virtual void eventFunction(); 56 61 57 62 private: 58 63 // the ariba module and a node 59 64 AribaModule* ariba; 60 Node* node; 65 Node* node; 66 string name; 67 int counter; 68 vector<string> names; 61 69 62 70 // flag, whether this node initiates or just joins the spovnet 63 71 bool isInitiator; 64 72 65 66 73 // the ping pong service id 74 static ServiceID PINGPONG_SERVICEID; 67 75 68 69 76 // the current ping id 77 unsigned long pingId; 70 78 71 79 }; -
sample/pingpong/PingPongMessage.cpp
r4626 r5151 10 10 } 11 11 12 PingPongMessage::PingPongMessage(uint8_t _id ) : id(_id) {12 PingPongMessage::PingPongMessage(uint8_t _id, string name) : id(_id),name(name) { 13 13 } 14 14 -
sample/pingpong/PingPongMessage.h
r4625 r5151 18 18 public: 19 19 PingPongMessage(); 20 PingPongMessage( uint8_t _id );20 PingPongMessage( uint8_t _id, string name = string("<ping>") ); 21 21 virtual ~PingPongMessage(); 22 22 23 23 string info(); 24 24 uint8_t getid(); 25 26 inline string getName() const { 27 return name; 28 } 25 29 private: 26 30 uint8_t id; 31 string name; 27 32 }; 28 33 … … 30 35 31 36 sznBeginDefault( ariba::application::pingpong::PingPongMessage, X ) { 32 X && id ;37 X && id && T(name); 33 38 } sznEnd(); 34 39 -
sample/pingpong/main.cpp
r4925 r5151 7 7 using ariba::application::pingpong::PingPong; 8 8 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 30 9 int main( int argc, char** argv ) { 31 32 //debug();33 //return 0;34 10 35 11 // get config file
Note:
See TracChangeset
for help on using the changeset viewer.