Files
scandocs/uni/masterarbeit/source/moversight/Moversight.h
2014-06-30 13:58:10 +02:00

180 lines
5.8 KiB
C++

#pragma once
#ifndef MOVERSIGHT_H
#define MOVERSIGHT_H
/*
* File: Moversight.h
* Author: jgaebler
*
* Created on September 20, 2010, 1:30 PM
*/
#include "BaseMoversight.h"
#include "mrs/metric/MaintanceMomentMetricTypes.h"
#include "ms/placingstrategy/PeerPlacingStrategyType.h"
#include "common/transport/msg/MoversightMessage.h"
#include "fd/NetworkFailureDetectorType.h"
#if UBEEME
#include "Dispatcher.h"
#include "mt/msg/GroupData.h"
#include "app/MoversightCallback.h"
#include "common/transport/MoversightMessageFactory.h"
#include "common/Defines.h"
#include "core/network/networking_nodes/datagram_input.h"
#include "core/network/networking_nodes/datagram_output.h"
#include "core/network/udp_endpoint.h"
#include "core/network/udp_node_event_receiver.h"
#include "core/network/udp_info_object.h"
#include "common/byte_array.h"
#include <QSharedPointer>
#else
#include "simutils/MoversightSimulationPeerStateVisualization.h"
//omnet
#include "UDPSocket.h"
#include "NotificationBoard.h"
#include "INotifiable.h"
#endif
namespace ubeeme {
namespace moversight {
class MulticastMessage;
class ExteriorMessage;
class Dispatcher;
class MoversightCallback;
class Application;
#if UBEEME
class MOV_EXPORT Moversight : public BaseMoversight, public DatagramInput<PeerID>, public DatagramOutput<TransportAddress>, public UDPNodeEventReceiver {
public:
Moversight(MoversightCallback & callBack);
~Moversight();
#else
/**
* @brief Base OMNeT++ Module for Moversight.
* @author Jan Gäbler
* @ingroup Moversight
* @class Moversight
*/
class Moversight : public BaseMoversight, public INotifiable, public cSimpleModule {
public:
void scheduleTestCase(simtime_t time);
void updateSimUI();
void bubble(const char* msg);
void receiveChangeNotification(int category, const cPolymorphic *details);
#endif
void sendToPeer( const MoversightMessage& msg, const TransportAddress& toPeerTA);
void connectionLost();
void connectionEstablished();
size_t getMaxClusterCount();
size_t getMaxPeerCount();
const PeerPlacingStrategyType & getPeerPlacingStrategyType() const;
const PeerPlacingStrategyMetricType & getPeerPlacingStrategyMetricType() const;
const MaintanceMomentMetricType & getMaintanceMomentMetricType() const;
const NetworkFailureDetectorType & getFailureDetectorType() const;
const PeerResources & getPeerResources() const;
Moversight & operator=(Moversight const & other);
virtual TransportAddress & getLocalAddress();
virtual void initialize(int stage);
#if UBEEME
//call backs
bool hasInputNodeInChain(DatagramInput<PeerID> const *input) const;
virtual void delegateReceive(ByteArray const &buffer, PeerID const &from);
/**
* @brief Chains the given DatagramInput to this DatagramOutput. So it can be used for delegating.
* @param input Input to chain.
*/
virtual void chainDown(DatagramInput<TransportAddress> *input);
/**
* @brief Unchains the given input from this DatagramOutput.
* @param input Input to unchain.
*/
virtual void unchainDown(DatagramInput<TransportAddress> *input);
virtual void stateChanged(EventContainer e);
bool handleSend(const ByteArray & buffer, PeerID const &to = 0, DatagramOutput<PeerID> const *fromOutput = 0);
void handleReceive(ByteArray const & buffer, TransportAddress const & from, DatagramInput<TransportAddress> const *fromInput);
void invitePeer(TransportAddress & ta, PeerDescription & pDesc);
void cancelInvitation(TransportAddress & ta, std::string reason);
void acceptInvitation(Invitation & inv, std::string comment, PeerDescription & pDesc);
void rejectInvitation(Invitation & inv, std::string reason);
void leaveGroup();
void splitGroup(unsigned char options, PeerIDList splitPeers);
void mergeGroup(TransportAddress & destTa);
void acceptGroupMerge();
void rejectGroupMerge(std::string & reason);
#endif
protected:
void sendToUDP( const MoversightMessage& msg, const TransportAddress & destAddr);
virtual int numInitStages() const { return 4; }
#if OMNETPP
virtual void handleMessage(cMessage *msg);
#endif
virtual void finish();
private:
void handleSimulationTriggerTimer();
void setLocalAddress();
PeerPlacingStrategyType peerPlacingStrategyType;
PeerPlacingStrategyMetricType peerPlacingStrategyMetricType;
PeerResources peerResourcesValue;
MaintanceMomentMetricType maintanceMomentMetricType;
NetworkFailureDetectorType failureDetectorType;
TransportAddress localTA;
#if UBEEME
bool initNetworkInfos();
MoversightMessageFactory factory;
QSharedPointer<UDPInfoObject> infoObject;
Dispatcher dispatcher;
#else
MoversightSimulationPeerStateVisualization * visu;
UDPSocket socket;
cMessage * simulationTrigger;
Application * app;
Dispatcher * dispatcher;
// NotificationBoard * notificationBoard;
size_t numMessagesReceived;
size_t numMessagesSent;
#endif
size_t maxClusterCount;
size_t maxPeerCount;
bool enableRecordStats;
}; //End class
}//End namespace
}//End namespace
#endif // MOVERSIGHT_H