Interface Diagram:

 

There are three levels and two interfaces that I need to support and program for in this project.  The first level is the simulation of a internet like transport device that the communication takes place over.  Within my simulation the transport layer of the software is handled by my networkInterface.cs file which handles links between the various simulated hardware.  There is then a interface that represents the interface between a computer and the internet and how they communicate back and forth.  The second layer that exists in this project is the physical hardware layer which is handled by my networkNode.cs file which represents the actual communication that a system must take part in.  The second interface is the one that stands between the physical device and the software that is run on it.  The third layer in my project is the layer that is taking part in the actually supporting the time synchronization algorithms and it is done in the BerkelyAlgorithm.cs and clocksampling.cs files respectively for each of the algorithms.


Activity Diagram:



 

This algorithm starts to run at its first viable opportunity once it has joined the network.  The first thing that the node does is sends its personal fitness to be the master system to the network and waits to hear back if it is in fact a master or slave system.  If this is a slave system it waits for a request for its local time on the network.  Once the request has been received it responds with the current time.  At this point it goes back to sleep waiting to find out what the offset is that it should apply to its current clock.  When this offset is provided back to the slave it updates its time and then goes back to waiting for new time requests to come in.

However if the node finds that it is a master node it immediately sends a request off on the network for all of the known nodes to respond with their current system time.  Once the master node receives the current time it then computes what the actual time is and then computes what the adjustment for each of the known nodes is and sends the adjustments to the nodes.  After it provides this update to the slaves the master goes to sleep until it is supposed to wake up and resynchronize the times on the network.

 

 

Much like the Berkley algorithm this algorithm starts at the first opportunity after the node joins a network.  Once the node is connected it immediately starts off by sending its local time to all of the nodes on the network.  Once this has happened the node then goes into a standby mode where it listens for broadcast times from other nodes on the network.  When it receives one the node wakes up and computes what it believes the correct current time is based on all of the reported times from other nodes on the network and then updates its local time.  In addition to this each node knows how often they need to publish their time and wakes up based on that schedule and sends their local time as long as they are still attached to the network.

Algorithm Description:


The most important algorithm is that of the Berkley Algorithm for my project.  That is because the way that the Berkley algorithm computes the actual time is the way that both the full Berkley algorithm computes the time as well as the way that the clock sampling algorithm computes the actual time.

For the Berkley algorithm this starts by requesting the current time from all of its known nodes and then each of these nodes then responds with its current time.  In the clock sampling algorithm each of these nodes would broadcast their time on a given schedule which results in all of the nodes collecting the current time.  From here the algorithm computes the actual time by taking an average of all of the nodes time including itself and it assumes that must be the actual time.  At this point the algorithm updates its time and for the clock sampling algorithm it is done were as for the Berkley algorithm it computes the adjustment that must be made for each of its slave nodes and sends this offset back to the slave.  When the slave receives this offset it then updates the clock as told to bring all of the known nodes clocks into alignment.