Changeset 2473


Ignore:
Timestamp:
Feb 23, 2009, 2:21:49 PM (16 years ago)
Author:
Christoph Mayer
Message:

-einige fixes im ablauf des neuen interface
-einige fehlende funktionalität implementiert

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • sample/pingpong/PingPong.cpp

    r2432 r2473  
    1 
    21#include "PingPong.h"
    32#include "ariba/utility/configuration/Configuration.h"
     
    1110
    1211// logging
    13 use_logging_cpp( PingPong);
     12use_logging_cpp( PingPong );
    1413
    1514// the service id of the ping pong service
    16 ServiceID PingPong::PINGPONG_ID = ServiceID(111);
     15ServiceID PingPong::PINGPONG_ID = ServiceID( 111 );
    1716
    1817// construction
     
    2726void PingPong::startup() {
    2827
     28        logging_info( "starting up PingPong service ... " );
     29
    2930        // create ariba module
    30         logging_info("Creating ariba underlay module ... ");
     31        logging_debug( "creating ariba underlay module ... " );
    3132        ariba = new AribaModule();
    3233
    33         logging_info("Starting up PingPong service ... ");
    34 
    35         // --- get config ---
     34        // get the configuration object
    3635        Configuration& config = Configuration::instance();
    3736
     
    6665        node->start();
    6766
    68         if (!isInitiator) {
    69                 node->join(spovnetName);
    70         } else {
    71                 node->initiate(spovnetName);
    72         }
     67        // initiate or join the spovnet
     68        if (!isInitiator) node->join(spovnetName);
     69        else node->initiate(spovnetName);
    7370
    7471        // bind communication and node listener
    7572        node->bind(this);
    7673        node->bind(this, PingPong::PINGPONG_ID);
    77 
     74       
    7875        // ping pong started up...
    79         logging_info("PingPong started up");
     76        logging_info( "pingpong started up ");
    8077}
    8178
    8279// implementation of the startup interface
    8380void PingPong::shutdown() {
    84         logging_info("PingPong service starting shutdown sequence ...");
     81
     82        logging_info( "pingpong service starting shutdown sequence ..." );
    8583
    8684        // stop timer
    8785        Timer::stop();
    88 
    89         // leave spovnet
    90         node->leave();
    9186
    9287        // unbind listeners
     
    9489        node->unbind( this, PingPong::PINGPONG_ID );
    9590
     91        // leave spovnet
     92        node->leave();
     93
     94        // stop the ariba module
    9695        ariba->stop();
     96
     97        // delete node and ariba module
    9798        delete node;
    9899        delete ariba;
    99100
    100         logging_info("PingPong service shut down!");
     101        // now we are completely shut down
     102        logging_info( "pingpong service shut down" );
    101103}
    102104
    103105// node listener interface
    104106void PingPong::onJoinCompleted( const SpoVNetID& vid ) {
    105         logging_info("PingPong node join completed, spovnetid=" << vid.toString() );
     107        logging_info( "pingpong node join completed, spovnetid=" << vid.toString() );
     108
     109        // start the timer to ping every second
     110        Timer::setInterval( 1000 );
     111        Timer::start();
    106112}
    107113
    108114void PingPong::onJoinFailed( const SpoVNetID& vid ) {
    109         logging_info("PingPong node join failed, spovnetid=" << vid.toString() );
     115        logging_error(" pingpong node join failed, spovnetid=" << vid.toString() );
    110116}
    111117
     
    115121}
    116122
    117 void PingPong::onMessage(Message* msg, const NodeID& remote, const LinkID& lnk =
    118                 LinkID::UNSPECIFIED) {
    119         PingPongMessage* incoming = msg->decapsulate<PingPongMessage> ();
     123void PingPong::onMessage(Message* msg, const NodeID& remote,
     124                const LinkID& lnk = LinkID::UNSPECIFIED) {
    120125
    121         logging_info("received ping message on link " << lnk.toString()
    122                         << " from node with id " << (int) incoming->getid());
     126        PingPongMessage* pingmsg = msg->decapsulate<PingPongMessage> ();
     127
     128        logging_info( "received ping message on link " << lnk.toString()
     129                        << " from node " << remote.toString()
     130                        << ": " << pingmsg->toString() );
    123131}
    124132
    125133// timer event
    126134void PingPong::eventFunction() {
     135       
     136        // we ping all nodes that are known in the overlay structure
     137        // this can be all nodes (OneHop) overlay or just some neighbors
     138        // in case of a Chord or Kademlia structure
     139       
     140        logging_info( "pinging overlay neighbors with ping id " << ++pingId );
     141
     142        PingPongMessage pingmsg( pingId );
     143        node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_ID );
     144
    127145}
    128146
  • sample/pingpong/PingPong.h

    r2413 r2473  
    44#include "ariba/ariba.h"
    55#include "PingPongMessage.h"
     6#include "ariba/utility/system/StartupInterface.h"
     7#include "ariba/utility/system/Timer.h"
    68
    79using namespace ariba;
    8 
    9 #include "ariba/utility/system/StartupInterface.h"
    10 #include "ariba/utility/system/Timer.h"
    1110using ariba::utility::StartupInterface;
    1211using ariba::utility::Timer;
     
    5554        Node* node;
    5655
    57         // flag, wheter this node is the initiator of this spovnet
     56        // flag, wheter this node initiates or just joins the spovnet
    5857        bool isInitiator;
    5958
     
    6564};
    6665
    67 //ARIBA_SIMULATION_SERVICE(PingPong);
     66// needed for simulation support
     67ARIBA_SIMULATION_SERVICE(PingPong);
    6868
    6969}}} // namespace ariba, application, pingpong
  • source/ariba/DataMessage.h

    r2435 r2473  
    5454        }
    5555
     56        inline DataMessage( const Message& message ) {
     57                this->data = (void*)const_cast<Message*>(&message);
     58                this->size = ~0;
     59        }
     60
    5661        inline Message* getMessage() const {
    5762                return (Message*)data;
  • source/ariba/Node.cpp

    r2455 r2473  
    3737// [License]
    3838
    39 
    4039#include "Node.h"
    4140
     
    6160
    6261        }
     62
    6363        ServiceInterfaceWrapper(CommunicationListener* listener) :
    6464                nodeListener(NULL), commListener(listener) {
    6565        }
     66       
     67        ~ServiceInterfaceWrapper() {
     68        }
    6669
    6770protected:
     
    6972
    7073        }
     74
    7175        void onOverlayDestroy(const SpoVNetID& id) {
    7276
     
    120124                        const NodeID& node) {
    121125                if (commListener != NULL) commListener->onMessage(
    122                                 const_cast<Message*> (message), node, link);
     126                                const_cast<Message*>(message), node, link);
    123127        }
    124128};
    125129
    126 const ServiceID Node::anonymousService = 0xFF00;
     130ServiceID Node::anonymousService = ServiceID(0xFF00);
    127131
    128132Node::Node(AribaModule& ariba_mod, const Name& node_name) :
     
    142146//TODO: Implement error handling: no bootstrap node available
    143147void Node::initiate(const Name& vnetname, const SpoVNetProperties& parm) {
    144         utility::OverlayParameterSet
    145                         ovrpset =
    146                                         (utility::OverlayParameterSet::_OverlayStructure) parm.getBaseOverlayType();
     148        utility::OverlayParameterSet ovrpset =
     149                        (utility::OverlayParameterSet::_OverlayStructure) parm.getBaseOverlayType();
     150
    147151        spovnetId = vnetname.toSpoVNetId();
    148152        nodeId = generateNodeId(name);
     153
    149154        this->context = ariba_mod.underlay_abs->createSpoVNet(spovnetId, nodeId,
    150                         ariba_mod.ip_addr, ariba_mod.tcp_port);
     155                                                        ariba_mod.ip_addr, ariba_mod.tcp_port);
    151156        ariba_mod.addBootstrapNode(vnetname,
    152                         new EndpointDescriptor(this->context->getBaseCommunication().getEndpointDescriptor()));
     157                new EndpointDescriptor(this->context->getBaseCommunication().getEndpointDescriptor()));
    153158}
    154159
    155160void Node::leave() {
    156         // not implemeted yet.
    157 }
    158 
    159 void Node::bind(NodeListener* listener) {
    160         this->context->getOverlay().bind(new ServiceInterfaceWrapper(listener),
    161                         Node::anonymousService);
    162 }
    163 
    164 void Node::unbind(NodeListener* listener) {
    165         // TODO: allow unbinding
     161        ariba_mod.underlay_abs->leaveSpoVNet( context );
     162        context = NULL;
    166163}
    167164
     
    171168
    172169const SpoVNetID& Node::getSpoVNetId() const {
    173         return SpoVNetID::UNSPECIFIED;
     170        return spovnetId;
    174171}
    175172
    176173const NodeID& Node::getNodeId(const LinkID& lid) const {
    177         return NodeID::UNSPECIFIED;
     174        return nodeId;
    178175}
    179176
     
    201198}
    202199
     200void Node::sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid) {
     201        return context->getOverlay().broadcastMessage((Message*)msg, sid);
     202}
     203
     204void Node::bind(NodeListener* listener) {
     205        context->getOverlay().bind(new ServiceInterfaceWrapper(listener),
     206                        Node::anonymousService);
     207}
     208
     209void Node::unbind(NodeListener* listener) {
     210        delete context->getOverlay().unbind(Node::anonymousService);
     211}
     212
    203213void Node::bind(CommunicationListener* listener, const ServiceID& sid) {
    204         this->context->getOverlay().bind(new ServiceInterfaceWrapper(listener), sid);
     214        context->getOverlay().bind(new ServiceInterfaceWrapper(listener), sid);
    205215}
    206216
    207217void Node::unbind(CommunicationListener* listener, const ServiceID& sid) {
    208         // TODO
     218        delete context->getOverlay().unbind(sid);
    209219}
    210220
  • source/ariba/Node.h

    r2460 r2473  
    3737// [License]
    3838
    39 
    4039#ifndef NODE_H_
    4140#define NODE_H_
     
    236235        seqnum_t sendMessage(const DataMessage& msg, const LinkID& lnk);
    237236
     237        /**
     238         * Sends a message to all known hosts in the overlay structure
     239         * the nodes that are reached here depend on the overlay structure.
     240         *
     241         * @param msg The message to be send
     242         * @param sid The id of the service that should receive the message
     243         */
     244        void sendBroadcastMessage(const DataMessage& msg, const ServiceID& sid);
     245
    238246        // --- communication listeners ---
    239247
     
    316324        // delegates
    317325        interface::AribaContext* context;
    318         static const ServiceID anonymousService;
     326        static ServiceID anonymousService;
    319327};
    320328
  • source/ariba/interface/ServiceInterface.cpp

    r2472 r2473  
    3838
    3939#include "ServiceInterface.h"
    40 #include "ariba/interface/AribaContext.h"
    4140
    4241namespace ariba {
    4342namespace interface {
    4443
    45 ServiceInterface::ServiceInterface() : overlay( NULL ){
     44ServiceInterface::ServiceInterface() {
    4645}
    4746
    4847ServiceInterface::~ServiceInterface(){
    49         if( overlay != NULL )
    50                 overlay->unbind( this, serviceid );
    51 }
    52 
    53 bool ServiceInterface::initialize( AribaContext* _ctx, const ServiceID& _serviceid ){
    54         return initialize( &_ctx->getOverlay(), _serviceid );
    55 }
    56 
    57 bool ServiceInterface::initialize( BaseOverlay* _overlay, const ServiceID& _serviceid ){
    58         if( _overlay == NULL ) return false;
    59 
    60         overlay = _overlay;
    61         serviceid = _serviceid;
    62 
    63         return overlay->bind( this, serviceid);
    6448}
    6549
  • source/ariba/interface/ServiceInterface.h

    r2472 r2473  
    6767namespace interface {
    6868
    69 class AribaContext;
    70 
    7169class ServiceInterface : public OverlayEvents, MessageReceiver {
    7270        friend class ariba::overlay::BaseOverlay;
     
    7472        ServiceInterface();
    7573        virtual ~ServiceInterface();
    76 
    77         bool initialize( AribaContext* _ctx, const ServiceID& _serviceid );
    78         bool initialize( BaseOverlay* _overlay, const ServiceID& _serviceid );
    7974
    8075protected:
     
    9691
    9792        virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
    98 
    99 private:
    100         BaseOverlay* overlay;
    101         ServiceID serviceid;
    10293};
    10394
  • source/ariba/interface/UnderlayAbstraction.cpp

    r2472 r2473  
    8686}
    8787
    88 void UnderlayAbstraction::destroySpoVNet(AribaContext* ctx) {
    89         ctx->getOverlay().leaveSpoVNet();
    90         delete &ctx->getOverlay();
    91         delete &ctx->getBaseCommunication();
    92         delete ctx;
    93 }
    94 
    9588AribaContext* UnderlayAbstraction::joinSpoVNet(const SpoVNetID& spovnetid, const EndpointDescriptor& bootstrapnode, const NodeID& nodeid, const NetworkLocator* locallocator, const uint16_t localport) {
    9689
     
    107100
    108101void UnderlayAbstraction::leaveSpoVNet(AribaContext* ctx) {
    109         destroySpoVNet( ctx );
     102        ctx->getOverlay().leaveSpoVNet();
     103        delete &ctx->getOverlay();
     104        delete &ctx->getBaseCommunication();
     105        delete ctx;
    110106}
    111107
  • source/ariba/interface/UnderlayAbstraction.h

    r2472 r2473  
    7979        );
    8080
    81         void destroySpoVNet( AribaContext* ctx );
    82 
    8381        AribaContext* joinSpoVNet(
    8482                const SpoVNetID& spovnetid,
  • source/ariba/overlay/BaseOverlay.cpp

    r2472 r2473  
    273273bool BaseOverlay::bind(ServiceInterface* service, const ServiceID& sid) {
    274274
    275         logging_debug( "binding service on serviceid " << sid.toString() );
     275        logging_debug( "binding service " << service << " on serviceid " << sid.toString() );
    276276
    277277        if( listenerMux.contains( sid ) ){
     
    284284}
    285285
    286 bool BaseOverlay::unbind(ServiceInterface* service, const ServiceID& sid){
    287 
    288         logging_debug( "unbinding service on serviceid " << sid.toString() );
     286ServiceInterface* BaseOverlay::unbind(const ServiceID& sid){
     287
     288        logging_debug( "unbinding service from serviceid " << sid.toString() );
    289289
    290290        if( !listenerMux.contains( sid ) ){
    291291                logging_warn( "cannot unbind service. no service registered on service id " << sid.toString() );
    292                 return false;
    293         }
    294 
    295         listenerMux.unregisterItem( service );
    296         return true;
     292                return NULL;
     293        }
     294
     295        ServiceInterface* iface = listenerMux.get( sid );
     296        listenerMux.unregisterItem( sid );
     297       
     298        return NULL; //iface;
    297299}
    298300
  • source/ariba/overlay/BaseOverlay.h

    r2472 r2473  
    185185         * Unregister a receiver.
    186186         *
    187          * @param receiver An implementation of the receiver interface
    188          */
    189         bool unbind( ServiceInterface* service, const ServiceID& sid );
     187         * @param sid The service id to unregister
     188         */
     189        ServiceInterface* unbind( const ServiceID& sid );
    190190
    191191        /**
     
    271271         * to deliver upcoming messages to the correct service.
    272272         */
    273         Demultiplexer<ServiceInterface*, const ServiceID> listenerMux;
     273        Demultiplexer<ServiceInterface*, ServiceID> listenerMux;
    274274
    275275        /**
  • source/ariba/overlay/modules/OverlayInterface.cpp

    r2472 r2473  
    5353                eventsReceiver( _eventsReceiver ) {
    5454
    55         ServiceInterface::initialize( &_baseoverlay, OVERLAY_SERVICE_ID );
     55        _baseoverlay.bind( this, OVERLAY_SERVICE_ID );
    5656}
    5757
    5858OverlayInterface::~OverlayInterface(){
     59        baseoverlay.unbind( OVERLAY_SERVICE_ID );
    5960}
    6061
  • source/ariba/utility/misc/Demultiplexer.hpp

    r2472 r2473  
    4141
    4242#include <list>
     43#include <iostream>
    4344#include <map>
    4445#include <boost/thread/mutex.hpp>
     
    4647#include "ariba/utility/messages/Message.h"
    4748
     49using std::cout;
    4850using std::list;
    4951using std::map;
     
    7375        boost::mutex                                            mapMutex;
    7476
     77        void debugprint() {
     78                cout << "-------------start--------" << std::endl;
     79                {
     80                        LISTENER_SERVICE_MAP_CITERATOR i = mapListenerService.begin();
     81                        LISTENER_SERVICE_MAP_CITERATOR iend = mapListenerService.end();
     82                       
     83                        for( ; i != iend; i++ )
     84                                cout << "xxx" << i->first.toString() << " -> " << i->second << std::endl;
     85                }
     86                cout << "-----------------------" << std::endl;
     87                {
     88                        SERVICE_LISTENER_MAP_CITERATOR i = mapServiceListener.begin();
     89                        SERVICE_LISTENER_MAP_CITERATOR iend = mapServiceListener.end();
     90                       
     91                        for( ; i != iend; i++ )
     92                                cout << "xxx" << i->first << " -> " << i->second.toString() << std::endl;
     93                }
     94                cout << "-------------end---------" << std::endl;
     95        }
     96
    7597public:
    7698
     
    83105        void registerItem( S id, T listener ) {
    84106                boost::mutex::scoped_lock lock( mapMutex );
    85                 {
    86                         mapServiceListener.insert( SERVICE_LISTENER_PAIR( id, listener ) );
    87                         mapListenerService.insert( LISTENER_SERVICE_PAIR( listener, id ) );
    88                 }
     107
     108                mapServiceListener.insert( SERVICE_LISTENER_PAIR( id, listener ) );
     109                mapListenerService.insert( LISTENER_SERVICE_PAIR( listener, id ) );
    89110        }
    90111
    91         void unregisterItem( S id) {
     112        void unregisterItem( S id ) {
    92113                T listener = get( id );
    93 
    94                 boost::mutex::scoped_lock lock( mapMutex );
     114               
    95115                {
     116                        boost::mutex::scoped_lock lock( mapMutex );
    96117                        mapServiceListener.erase( id );
    97118                        mapListenerService.erase( listener );
     
    100121
    101122        void unregisterItem( T listener ) {
    102                 S id = get (listener);
     123                S id = get( listener );
    103124                unregisterItem( id );
    104125        }
     
    106127        S get( T listener ) {
    107128                boost::mutex::scoped_lock lock( mapMutex );
    108                 {
    109                         LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener );
    110                         return it->second;
    111                 }
     129
     130                LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener );
     131                return it->second;
    112132        }
    113133
    114134        T get( S id ) {
    115135                boost::mutex::scoped_lock lock( mapMutex );
    116                 {
    117                         SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id );
    118136
    119                         if( it == mapServiceListener.end() )    return NULL;
    120                         else                                    return it->second;
    121                 }
     137                SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id );
     138                if( it == mapServiceListener.end() )    return NULL;
     139                else                                    return it->second;
    122140        }
    123141
    124142        bool contains( T listener ) {
    125143                boost::mutex::scoped_lock lock( mapMutex );
    126                 {
    127                         LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener );
    128                         return ( it != mapListenerService.end() );
    129                 }
     144
     145                LISTENER_SERVICE_MAP_CITERATOR it = mapListenerService.find( listener );
     146                return ( it != mapListenerService.end() );
    130147        }
    131148
    132149        bool contains( S id ) {
    133150                boost::mutex::scoped_lock lock( mapMutex );
    134                 {
    135                         SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id );
    136                         return ( it != mapServiceListener.end() );
    137                 }
     151
     152                SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id );
     153                return ( it != mapServiceListener.end() );
    138154        }
    139155
     
    141157        typedef list<T> TwoList;
    142158
    143         OneList getOneList() const {
     159        OneList getOneList() {
     160                boost::mutex::scoped_lock lock( mapMutex );
    144161                OneList ret;
    145162
     
    151168        }
    152169
    153         TwoList getTwoList() const {
     170        TwoList getTwoList() {
     171                boost::mutex::scoped_lock lock( mapMutex );
    154172                TwoList ret;
    155173
  • source/ariba/utility/types/ServiceID.cpp

    r2472 r2473  
    2424// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
    2525// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26// EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    2727// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    2828// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     
    5050}
    5151
    52 ServiceID::ServiceID(unsigned int _id) : id( _id ){
     52ServiceID::ServiceID(uint32_t _id) : id( _id ){
    5353}
    5454
     
    5757
    5858ServiceID::~ServiceID() {
     59}
     60
     61ServiceID& ServiceID::operator=(const ServiceID &rh) {
     62        id = rh.id;
     63        return *this;
    5964}
    6065
  • source/ariba/utility/types/ServiceID.h

    r2472 r2473  
    7272        bool operator<(const ServiceID& rh) const;
    7373        bool operator!=(const ServiceID& rh) const;
     74        ServiceID& operator=(const ServiceID &rh);
    7475
    7576        inline bool isUnspecified() const {
Note: See TracChangeset for help on using the changeset viewer.