close Warning: Can't use blame annotator:
No changeset 1891 in the repository

source: trash/pingpong/PingPong.cpp@ 5860

Last change on this file since 5860 was 5860, checked in by Christoph Mayer, 15 years ago

networkinfo fix wenn socket kaputt geht, erfolgreich verwendete bootstrap infos speichern und wenn overlay verbindungen alle weg sind diese infos ausprobieren

File size: 4.6 KB
RevLine 
1#include "PingPong.h"
2
3#include "ariba/interface/UnderlayAbstraction.h"
4
5namespace ariba {
6namespace appplication {
7namespace pingpong {
8
9use_logging_cpp(PingPong);
10ServiceID PingPong::PINGPONG_ID = ServiceID(111);
11
12PingPong::PingPong() : pingid( 0 ) {
13}
14
15PingPong::~PingPong(){
16}
17
18void PingPong::setMode(bool startingNode){
19 startping = startingNode;
20}
21
22void PingPong::startup(){
23 abstraction = new UnderlayAbstraction();
24
25 logging_info( "starting up PingPong service ... " );
26
27 SpoVNetID spovnetid (Identifier(5000));
28
29 setMode( !Configuration::instance().read<bool>("GENERAL_Initiator") );
30
31 NodeID nodeid = (Configuration::instance().exists("BASE_nodeid") ?
32 NodeID(Identifier(Configuration::instance().read<unsigned long>("BASE_nodeid"))) :
33 NodeID::UNSPECIFIED);
34
35 IPv4Locator* locallocator = (Configuration::instance().exists("BASE_localLocator") ?
36 &(IPv4Locator::fromString(Configuration::instance().read<string>("BASE_localLocator"))) :
37 NULL);
38
39 uint16_t localport = Configuration::instance().exists("BASE_port") ?
40 Configuration::instance().read<uint16_t>("BASE_port") :
41 ARIBA_DEFAULT_PORT;
42
43 if( !startping ){
44
45 context = abstraction->createSpoVNet(
46 spovnetid, nodeid, locallocator, localport );
47
48 } else {
49
50 if( !Configuration::instance().exists("BASE_bootstrapIP")){
51 logging_fatal( "no bootstrap address found" );
52 return;
53 }
54
55 logging_info( "using bootstrap point " <<
56 Configuration::instance().read<string>("BASE_bootstrapIP") );
57
58 EndpointDescriptor bootstrap(
59 new IPv4Locator(IPv4Locator::fromString(
60 Configuration::instance().read<string>("BASE_bootstrapIP"))));
61
62 context = abstraction->joinSpoVNet(
63 spovnetid, bootstrap, nodeid, locallocator, localport );
64
65 }
66
67 overlay = &context->getOverlay();
68 overlay->bind( this, PingPong::PINGPONG_ID );
69
70 logging_info( "PingPong started up" );
71
72 // trigger the creation of the pathload measurement module
73 //PathloadMeasurement::instance( overlay );
74}
75
76void PingPong::shutdown(){
77 logging_info( "shutting down PingPong service ..." );
78
79 overlay->unbind( this, PingPong::PINGPONG_ID );
80 Timer::stop();
81
82 if( !startping ) abstraction->destroySpoVNet( context );
83 else abstraction->leaveSpoVNet( context );
84
85 delete abstraction;
86
87 logging_info( "PingPong service shut down" );
88}
89
90bool PingPong::receiveMessage(const Message* message, const LinkID& link, const NodeID& node){
91
92 PingPongMessage* incoming = ((Message*)message)->decapsulate<PingPongMessage>();
93
94 logging_info( "received ping message on link " << link.toString() <<
95 " from node with id " << (int)incoming->getid());
96
97// if( ((int)incoming->getid() % 5) == 0 )
98// PathloadMeasurement::instance().measure( node, this );
99}
100
101void PingPong::eventFunction(){
102
103 logging_info( "pinging our remote nodes" );
104
105 RemoteNodes::iterator i = remoteNodes.begin();
106 RemoteNodes::iterator iend = remoteNodes.end();
107
108 pingid++;
109
110 for( ; i != iend; i++ ){
111 logging_info( " -> pinging " << i->first );
112
113 PingPongMessage pingmsg( pingid );
114 overlay->sendMessage( &pingmsg, i->second );
115 }
116}
117
118void PingPong::onMeasurement(NodeID node, double mbps){
119 logging_info( "pingpong received measurement for node " << node.toString() << " with result " << mbps );
120}
121
122void PingPong::onJoinSuccess( const SpoVNetID& spovnetid ){
123}
124
125void PingPong::onOverlayCreate( const SpoVNetID& id ){
126}
127
128void PingPong::onOverlayDestroy( const SpoVNetID& id ){
129}
130
131bool PingPong::isJoinAllowed( const NodeID& nodeid, const SpoVNetID& spovnetid ){
132 return true;
133}
134
135void PingPong::onNodeJoin( const NodeID& nodeid, const SpoVNetID& spovnetid ){
136
137 if( !startping ){
138
139 logging_info( "establishing link to node " << nodeid.toString() );
140 const LinkID link = overlay->establishLink( nodeid, PingPong::PINGPONG_ID );
141
142 logging_info( "adding node to registered nodes in pingpong: " << nodeid.toString() );
143 remoteNodes.insert( make_pair(nodeid,link) );
144
145 Timer::setInterval( 2000 );
146 Timer::start();
147 }
148}
149
150void PingPong::onNodeLeave( const NodeID& id, const SpoVNetID& spovnetid ){
151 RemoteNodes::iterator i = remoteNodes.find( id );
152 if( i != remoteNodes.end() ) remoteNodes.erase( i );
153}
154
155void PingPong::onJoinFail( const SpoVNetID& spovnetid ){
156}
157
158void PingPong::onLinkUp( const LinkID& link, const NodeID& local, const NodeID& remote ){
159}
160
161void PingPong::onLinkDown( const LinkID& link, const NodeID& local, const NodeID& remote ){
162}
163
164void PingPong::onLinkChanged( const LinkID& link, const NodeID& local, const NodeID& remote ){
165}
166
167void PingPong::onLinkFail(const LinkID& id, const NodeID& local, const NodeID& remote){
168}
169
170void PingPong::onLinkQoSChanged(const LinkID& id, const NodeID& local, const NodeID& remote , const QoSParameterSet& qos){
171}
172
173}}} // namespace ariba, appplication, pingpong
Note: See TracBrowser for help on using the repository browser.