- Timestamp:
- Jun 19, 2013, 11:05:49 AM (11 years ago)
- Location:
- sample
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/CMakeLists.txt
r10700 r12060 38 38 39 39 add_subdirectory(pingpong) 40 #add_subdirectory(debugging) 41 -
sample/pingpong/PingPong.cpp
r9990 r12060 3 3 #include "ariba/utility/visual/DddVis.h" 4 4 5 #include <boost/property_tree/ptree.hpp> 6 #include <boost/property_tree/json_parser.hpp> 7 8 5 9 using ariba::utility::Configuration; 6 10 using namespace ariba; … … 17 21 18 22 // construction 19 PingPong::PingPong() : pingId( 0 ) { 20 Timer::setInterval( 1000 ); 23 PingPong::PingPong( string config) : 24 node(), 25 pingId( 0 ), 26 config_file(config) 27 { 28 Timer::setInterval( 3000 ); 21 29 } 22 30 … … 26 34 27 35 // implementation of the startup interface 28 void PingPong::startup() { 29 36 void PingPong::startup() 37 { 38 using boost::property_tree::ptree; 39 using boost::property_tree::json_parser::read_json; 40 30 41 // set up logging 31 logging_rootlevel_ info();42 logging_rootlevel_debug(); 32 43 logging_classlevel_debug(PingPong); 33 44 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 77 64 // 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")); 95 72 96 73 // 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() << "]" ); 100 77 } 101 78 … … 103 80 void PingPong::shutdown() { 104 81 105 logging_info( " pingpong service starting shutdown sequence ..." );82 logging_info( "[PINGPONG]\t pingpong service starting shutdown sequence ..." ); 106 83 107 84 // stop timer … … 109 86 110 87 // leave spovnet 111 node ->leave();88 node.leave(); 112 89 113 90 // 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*/ 123 93 124 94 // now we are completely shut down … … 129 99 void PingPong::eventFunction() { 130 100 101 if ( node.getNeighborNodes().size() == 0) 102 { 103 logging_info( "[PINGPONG]\t +++ no neighbors +++" ); 104 return; 105 } 106 131 107 // we ping all nodes that are known in the overlay structure 132 108 // this can be all nodes (OneHop) overlay or just some neighbors … … 140 116 141 117 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 ); 143 121 PingPongMessage pingmsg( pingId, name ); 144 122 145 123 //----------------------------------------------------------------------- 146 124 // Option 1: get all neighboring nodes and send the message to each … … 154 132 s = s+names[i]; 155 133 } 156 logging_info(" ----> I am " << name << " and I know " << s);134 logging_info("[PINGPONG]\t ----> I am " << name << " and I know " << s); 157 135 names.clear(); 158 136 } 159 137 160 vector<NodeID> nodes = node ->getNeighborNodes();138 vector<NodeID> nodes = node.getNeighborNodes(); 161 139 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 ); 164 142 } 165 143 … … 195 173 for (int i=0;i<names.size(); i++) if (names[i]==pingmsg->getName()) found=true; 196 174 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) 198 181 << " from node " << remote.toString() 182 << " (" << pingmsg->getName() << ")" 199 183 << ": " << pingmsg->info() ); 200 184 delete pingmsg; -
sample/pingpong/PingPong.h
r10570 r12060 33 33 34 34 public: 35 PingPong( );35 PingPong( string config ); 36 36 virtual ~PingPong(); 37 37 … … 61 61 private: 62 62 // the ariba module and a node 63 AribaModule* ariba;64 Node *node;63 // AribaModule* ariba; 64 Node node; 65 65 string name; 66 66 int counter; … … 73 73 unsigned long pingId; 74 74 75 string config_file; 75 76 }; 76 77 -
sample/pingpong/main.cpp
r5151 r12060 10 10 11 11 // get config file 12 string config = "../etc/settings.cnf";12 string config; 13 13 if (argc >= 2) config = argv[1]; 14 14 15 StartupWrapper::initConfig( config );15 // StartupWrapper::initConfig( config ); 16 16 StartupWrapper::startSystem(); 17 17 18 18 // this will do the main functionality and block 19 PingPong ping ;19 PingPong ping(config); 20 20 StartupWrapper::startup(&ping); 21 21
Note:
See TracChangeset
for help on using the changeset viewer.