FREEDM DGI
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
freedm::broker::CClockSynchronizer Class Reference

#include <CClockSynchronizer.hpp>

Inheritance diagram for freedm::broker::CClockSynchronizer:
freedm::broker::IDGIModule

Public Member Functions

 CClockSynchronizer (boost::asio::io_service &ios)
 Initialize module. More...
 
boost::posix_time::ptime GetSynchronizedTime () const
 Returns the synchronized time. More...
 
void HandleIncomingMessage (boost::shared_ptr< const ModuleMessage > msg, CPeerNode peer)
 Processes incoming messages from other modules. More...
 
void Run ()
 Starts the synchronization algorithm. More...
 
void Stop ()
 Stops the syncrhonization algorithm. More...
 

Protected Member Functions

CPeerNode GetMe ()
 Gets a CPeerNode representing this process. More...
 
std::string GetUUID () const
 Gets the UUID of this process. More...
 

Private Types

typedef std::pair< double, boost::posix_time::ptime > DecayingWeight
 Container for decaying weights. More...
 
typedef std::map< MapIndex, unsigned int > LastResponseMap
 Last responses type. More...
 
typedef std::pair< std::string, std::string > MapIndex
 Does the i,j referencing. More...
 
typedef std::map< MapIndex, boost::posix_time::time_duration > OffsetMap
 Stores the relative offsets. More...
 
typedef std::map< MapIndex, QueryRecordQueryMap
 Stores the outstanding clock queries. More...
 
typedef std::pair< unsigned int, boost::posix_time::ptime > QueryRecord
 Query Tuple. More...
 
typedef std::list< TimeTupleResponseList
 Stores the response pairs. More...
 
typedef std::map< MapIndex, ResponseListResponseMap
 Stores the challenge responses. More...
 
typedef std::map< MapIndex, double > SkewMap
 Type used by skews. More...
 
typedef std::pair< boost::posix_time::ptime, boost::posix_time::ptime > TimeTuple
 Tuples of challenge query/response stuff. More...
 
typedef std::map< MapIndex, DecayingWeightWeightMap
 Type used by the weights. More...
 

Private Member Functions

ModuleMessage CreateExchangeMessage (unsigned int k)
 Generate the exchange message. More...
 
ModuleMessage CreateExchangeResponse (unsigned int k)
 Generate the exchange response message. More...
 
void Exchange (const boost::system::error_code &err)
 Sends clock exchange requests to other processes. More...
 
double GetWeight (MapIndex i) const
 Gets the weight with a decay. More...
 
void HandleExchange (const ExchangeMessage &msg, CPeerNode peer)
 Receiver for clock exchange requests. More...
 
void HandleExchangeResponse (const ExchangeResponseMessage &msg, CPeerNode peer)
 Handler for clock exchange responses. More...
 
void SetWeight (MapIndex i, double w)
 Sets the weight for a process. More...
 

Static Private Member Functions

static boost::posix_time::time_duration DoubleToTD (double td)
 Turn a double into a time duration. More...
 
static ModuleMessage PrepareForSending (const ClockSynchronizerMessage &message)
 Wraps a clock synchronizer message in a ModuleMessage. More...
 
static double TDToDouble (boost::posix_time::time_duration td)
 Turn a time duration into a double. More...
 

Private Attributes

boost::asio::deadline_timer m_exchangetimer
 Time for the exchange. More...
 
unsigned int m_kcounter
 The current k for identifying the freshness. More...
 
boost::posix_time::ptime m_lastinteraction
 Time between interactions. More...
 
LastResponseMap m_lastresponse
 The last time a node responded. More...
 
boost::posix_time::time_duration m_myoffset
 My offset. More...
 
double m_myskew
 My skew. More...
 
OffsetMap m_offsets
 Relative offsets. More...
 
QueryMap m_queries
 Outstanding Clock Queries. More...
 
ResponseMap m_responses
 Old responses. More...
 
SkewMap m_skews
 Relative skews. More...
 
WeightMap m_weights
 Relative weights. More...
 

Member Typedef Documentation

typedef std::pair< double, boost::posix_time::ptime > freedm::broker::CClockSynchronizer::DecayingWeight
private
typedef std::map< MapIndex, unsigned int > freedm::broker::CClockSynchronizer::LastResponseMap
private
typedef std::pair<std::string,std::string> freedm::broker::CClockSynchronizer::MapIndex
private
typedef std::map< MapIndex, boost::posix_time::time_duration > freedm::broker::CClockSynchronizer::OffsetMap
private
typedef std::pair<unsigned int, boost::posix_time::ptime> freedm::broker::CClockSynchronizer::QueryRecord
private
typedef std::map< MapIndex, double > freedm::broker::CClockSynchronizer::SkewMap
private
typedef std::pair<boost::posix_time::ptime, boost::posix_time::ptime> freedm::broker::CClockSynchronizer::TimeTuple
private

Constructor & Destructor Documentation

freedm::broker::CClockSynchronizer::CClockSynchronizer ( boost::asio::io_service &  ios)
explicit

CClockSynchronizer::CClockSynchronizer

Description:
Constructs the synchronizer object
Limitations:
none
Precondition:
None
Postcondition:
Read handlers are registered and the synchronizer is ready to begin
Parameters
iosthe broker's ioservice

Member Function Documentation

ModuleMessage freedm::broker::CClockSynchronizer::CreateExchangeMessage ( unsigned int  k)
private

CClockSynchronizer::ExchangeMessage

Description:
Generates the challenge message, which requests a clock reading from another process.
Limitations:
none
Precondition:
None
Postcondition:
None
Parameters
kA sequence number to use for this request, which is a monotonically increasing value for each receiver
Returns
A prepared exchange message.
ModuleMessage freedm::broker::CClockSynchronizer::CreateExchangeResponse ( unsigned int  k)
private

CClockSynchronizer::ExchangeResponse

Description:
Generates the response message. Embeds the current clock reading and the offset table for this process in a message.
Limitations:
none
Precondition:
None
Postcondition:
None
Parameters
kA sequence number to use for this request, which is a monotonically increasing value for each receiver
Returns
A prepared response message.
boost::posix_time::time_duration freedm::broker::CClockSynchronizer::DoubleToTD ( double  td)
staticprivate

CClockSynchronizer::DoubleToTD

Description:
given a double td, convert it to a boost time_duration of roughly the same value (some losses for the accuracy of posix_time
Precondition:
None
Postcondition:
None
Parameters
tdthe time duration (in seconds) to convert
Returns
a time duration that is roughly the same as td.
void freedm::broker::CClockSynchronizer::Exchange ( const boost::system::error_code &  err)
private

CClockSynchronizer::Exchange

Description:
Makes clock reading requests to the other processes in the system.
Limitations:
none
Precondition:
None
Postcondition:
The query table is updated and the clock offset / skew is adjusted
Parameters
errThe reason this function was called.
CPeerNode IDGIModule::GetMe ( )
protectedinherited

GetMe

Description:
Gets a CPeerNode that refers to this process.
Returns
A CPeerNode referring to this process.
boost::posix_time::ptime freedm::broker::CClockSynchronizer::GetSynchronizedTime ( ) const

CClockSynchronizer::GetSynchronizedTime

Description:
Returns the time adjusted by the set offset
Limitations:
none
Precondition:
None
Postcondition:
None
Returns
The current time as decided by the synchronization algorithm
std::string IDGIModule::GetUUID ( ) const
protectedinherited

GetUUID

Description:
Gets this process's UUID.
Returns
This process's UUID
double freedm::broker::CClockSynchronizer::GetWeight ( MapIndex  i) const
private

CClockSynchronizer::GetWeight

Description:
Returns the confidence in the relative offset between 2 nodes
Limitations:
none
Precondition:
None
Postcondition:
None
Returns
The weight of a processes clock measurement.
void freedm::broker::CClockSynchronizer::HandleExchange ( const ExchangeMessage &  msg,
CPeerNode  peer 
)
private

CClockSynchronizer::HandleExchange

Description:
Responds to a clock reading request issued by a remote node.
Limitations:
none
Precondition:
None
Postcondition:
An exchange response is sent to the original sender.
Parameters
msgThe message from the remote node
peerThe peer sending the message.
void freedm::broker::CClockSynchronizer::HandleExchangeResponse ( const ExchangeResponseMessage &  msg,
CPeerNode  peer 
)
private

CClockSynchronizer::HandleExchangeResponse

Description:
Handles the clock reading response from the remote node
Limitations:
none
Precondition:
None
Postcondition:
Internal tables and state are updated, based on a linear regression created from this response and previous responses.
Parameters
msgThe message from the remote node
peerThe remote node.
void freedm::broker::CClockSynchronizer::HandleIncomingMessage ( boost::shared_ptr< const ModuleMessage >  msg,
CPeerNode  peer 
)
virtual

CClockSyncronizer::HandleIncoming Message

Description:
: Takes an incoming message, determines its type and passes it to the appropriate message handler.
Parameters
msgthe incoming message
peerthe node that sent this message (could be this DGI)

Implements freedm::broker::IDGIModule.

ModuleMessage freedm::broker::CClockSynchronizer::PrepareForSending ( const ClockSynchronizerMessage &  message)
staticprivate

CClockSynchronizer::PrepareForSending

Description:
Wraps a ClockSynchronizerMessage in a ModuleMessage.
Parameters
messagethe message to prepare. If any required field is unset, an exception will be thrown.
Precondition:
None
Postcondition:
None
Returns
a ModuleMessage containing a copy of the ClockSynchronizerMessage
void freedm::broker::CClockSynchronizer::Run ( )

CClockSynchronizer::Run()

Description:
Schedule's the synchronizer's behavior and starts the synchronization algorithm.
Limitations:
none
Precondition:
None
Postcondition:
The exchange timer is set and the first round will run in QUERY_INTERVAL milliseconds
void freedm::broker::CClockSynchronizer::SetWeight ( MapIndex  i,
double  w 
)
private

CClockSynchronizer::setWeight

Description:
Updates the weights table
Limitations:
none
Precondition:
None
Postcondition:
None
Parameters
iThe weight to update
wThe amount of weight
void freedm::broker::CClockSynchronizer::Stop ( )

CClockSynchronizer::Stop()

Description:
Stops the clock synchronizer.
Limitations:
none
Precondition:
None
Postcondition:
The timer is canceled.
double freedm::broker::CClockSynchronizer::TDToDouble ( boost::posix_time::time_duration  td)
staticprivate

CClockSynchronizer::TDToDouble

Description:
give a time duration td, convert it to a double which represents the number of seconds the time duration represents
Precondition:
None
Postcondition:
None
Parameters
tdthe time duration to convert
Returns
a double of the time duration, in seconds.

Member Data Documentation

boost::asio::deadline_timer freedm::broker::CClockSynchronizer::m_exchangetimer
private
unsigned int freedm::broker::CClockSynchronizer::m_kcounter
private
boost::posix_time::ptime freedm::broker::CClockSynchronizer::m_lastinteraction
private
LastResponseMap freedm::broker::CClockSynchronizer::m_lastresponse
private
boost::posix_time::time_duration freedm::broker::CClockSynchronizer::m_myoffset
private
double freedm::broker::CClockSynchronizer::m_myskew
private
OffsetMap freedm::broker::CClockSynchronizer::m_offsets
private
QueryMap freedm::broker::CClockSynchronizer::m_queries
private
ResponseMap freedm::broker::CClockSynchronizer::m_responses
private
SkewMap freedm::broker::CClockSynchronizer::m_skews
private
WeightMap freedm::broker::CClockSynchronizer::m_weights
private

The documentation for this class was generated from the following files: