GiaNeighbors.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #ifndef __GIANEIGHBORS_H_
00025 #define __GIANEIGHBORS_H_
00026 
00027 #include <vector>
00028 
00029 #include <omnetpp.h>
00030 
00031 #include <OverlayKey.h>
00032 #include <InitStages.h>
00033 
00034 #include "GiaNode.h"
00035 #include "GiaKeyList.h"
00036 
00037 
00038 struct GiaNeighborInfo
00039 {
00040     unsigned int connectionDegree;
00041     unsigned int receivedTokens;
00042     unsigned int sentTokens;
00043     simtime_t timestamp;
00044     GiaKeyList keyList;
00045 };
00046 
00047 struct FullGiaNodeInfo
00048 {
00049     GiaNode node;
00050     GiaNeighborInfo* info;
00051 };
00052 
00053 
00054 std::ostream& operator<<(std::ostream& os, const GiaNeighborInfo& info);
00055 
00059 class GiaNeighbors : public cSimpleModule
00060 {
00061   public:
00062     // OMNeT++ methodes
00066     virtual int numInitStages() const
00067     {
00068         return MAX_STAGE_OVERLAY + 1;
00069     }
00070 
00075     virtual void initialize( int stage );
00076 
00081     virtual void handleMessages( cMessage* msg );
00082 
00083     // class methodes
00087     virtual unsigned int getSize() const;
00088 
00093     virtual bool contains(const GiaNode& node) const;
00094     //virtual bool contains(const NodeHandle& node) const;
00095 
00100     virtual bool contains(const OverlayKey& key) const;
00101 
00107     virtual void add(const GiaNode& node, unsigned int degree);
00108     //virtual void add(const NodeHandle& node);
00109 
00114     virtual void remove(const GiaNode& node);
00115 
00121     virtual const GiaNode& get(unsigned int position);
00122 
00128     virtual const GiaNode& get(const OverlayKey& key);
00129     
00130     //bullshit
00131     GiaNeighborInfo* get(const GiaNode& node);
00132 
00136     void updateTimestamp(const GiaNode& node);
00137 
00141     void removeTimedoutNodes();
00142 
00148     void setNeighborKeyList(const GiaNode& node, const GiaKeyList& keyList);
00149     GiaKeyList* getNeighborKeyList(const GiaNode& node);
00150 
00151     double getCapacity(const GiaNode& node) const;
00152     //void setCapacity(const GiaNode& node, double capacity);
00153 
00154     void setConnectionDegree(const GiaNode& node, unsigned int degree);
00155     unsigned int getConnectionDegree(const GiaNode& node) const;
00156 
00157     void setReceivedTokens(const GiaNode& node, unsigned int tokens);
00158     void increaseReceivedTokens(const GiaNode& node);
00159     void decreaseReceivedTokens(const GiaNode& node);
00160     unsigned int getReceivedTokens(const GiaNode& node) const;
00161 
00162     void setSentTokens(const GiaNode& node, unsigned int tokens);
00163     void increaseSentTokens(const GiaNode& node);
00164     unsigned int getSentTokens(const GiaNode& node) const;
00165 
00166     const GiaNode& getDropCandidate(double capacity,
00167                                        unsigned int degree) const;
00168 
00169   protected:
00170     std::map<GiaNode, GiaNeighborInfo> neighbors; 
00171     typedef std::map<GiaNode, GiaNeighborInfo>::iterator NeighborsIterator;
00172     typedef std::map<GiaNode, GiaNeighborInfo>::const_iterator NeighborsConstIterator;
00173     GiaNode thisNode; 
00174     simtime_t timeout; 
00175 };
00176 
00177 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3