manage

package
v0.0.0-...-53feb6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2016 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package manage implements protocols used when setting up and testing a tree.

The count-protocol returns the number of nodes in the tree that are reachable. It also sets up all necessary connections, so if you want to do time-measurements without including the setup-time, you can ran a count-protocol first.

The broadcast-protocol connects every node of the tree to every other node and waits for all connections to be set up.

The close_all-protocol sends a 'terminate'-message to all nodes which will close down everything.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBroadcastProtocol

func NewBroadcastProtocol(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error)

NewBroadcastProtocol returns a new Broadcast protocol

func NewCloseAll

func NewCloseAll(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error)

NewCloseAll will create a new protocol

func NewCount

NewCount returns a new protocolInstance

func NewSimulation

func NewSimulation(config string) (sda.Simulation, error)

NewSimulation returns the new simulation, where all fields are initialised using the config-file

Types

type Broadcast

type Broadcast struct {
	*sda.TreeNodeInstance
	// contains filtered or unexported fields
}

Broadcast ensures that all nodes are connected to each other. If you need a confirmation once everything is set up, you can register a callback-function using RegisterOnDone()

func (*Broadcast) RegisterOnDone

func (b *Broadcast) RegisterOnDone(fn func())

RegisterOnDone takes a function that will be called once all connections are set up.

func (*Broadcast) Start

func (b *Broadcast) Start() error

Start will contact everyone and makes the connections

type Close

type Close struct{}

Close is sent to the parent just before the node shuts down

type CloseMsg

type CloseMsg struct {
	*sda.TreeNode
	Close
}

CloseMsg is the wrapper for the Close message

type ContactNodes

type ContactNodes struct{}

ContactNodes is sent from the root to ALL other nodes

type Count

type Count struct {
	Children int
}

Count sends the number of children to the parent node.

type CountMsg

type CountMsg struct {
	*sda.TreeNode
	Count
}

CountMsg is wrapper around the Count-structure

type Done

type Done struct{}

Done is sent back to root once everybody has been contacted

type NodeIsUp

type NodeIsUp struct{}

NodeIsUp - if it is received by the root it will reset the counter.

type PrepareClose

type PrepareClose struct{}

PrepareClose is sent down the tree until the nodes

type PrepareCloseMsg

type PrepareCloseMsg struct {
	*sda.TreeNode
	PrepareClose
}

PrepareCloseMsg is the wrapper for the PrepareClose message

type PrepareCount

type PrepareCount struct {
	Timeout int
}

PrepareCount is sent so that every node can contact the root to say the counting is still going on.

type ProtocolCloseAll

type ProtocolCloseAll struct {
	*sda.TreeNodeInstance
	// Done receives a 'true' once the protocol is done.
	Done chan bool
}

ProtocolCloseAll is the structure used to hold the Done-channel

func (*ProtocolCloseAll) FuncClose

func (p *ProtocolCloseAll) FuncClose(c []CloseMsg)

FuncClose is called from the leafs to the parents and up the tree. Everybody receiving all `Close`-messages from all children will close down all network communication.

func (*ProtocolCloseAll) FuncPrepareClose

func (p *ProtocolCloseAll) FuncPrepareClose(pc PrepareCloseMsg)

FuncPrepareClose sends a `PrepareClose`-message down the tree.

func (*ProtocolCloseAll) Start

func (p *ProtocolCloseAll) Start() error

Start the protocol and waits for the `Close`-message to arrive back at the root-node.

type ProtocolCount

type ProtocolCount struct {
	*sda.TreeNodeInstance
	Replies int
	Count   chan int
	Quit    chan bool

	PrepareCountChan chan struct {
		*sda.TreeNode
		PrepareCount
	}
	CountChan    chan []CountMsg
	NodeIsUpChan chan struct {
		*sda.TreeNode
		NodeIsUp
	}
	// contains filtered or unexported fields
}

ProtocolCount holds all channels. If a timeout occurs or the counting is done, the Count-channel receives the number of nodes reachable in the tree.

func (*ProtocolCount) Dispatch

func (p *ProtocolCount) Dispatch() error

Dispatch listens for all channels and waits for a timeout in case nothing happens for a certain duration

func (*ProtocolCount) FuncC

func (p *ProtocolCount) FuncC(cc []CountMsg)

FuncC creates a Count-message that will be received by all parents and count the total number of children

func (*ProtocolCount) FuncPC

func (p *ProtocolCount) FuncPC()

FuncPC handles PrepareCount messages. These messages go down the tree and every node that receives one will reply with a 'NodeIsUp'-message

func (*ProtocolCount) SetTimeout

func (p *ProtocolCount) SetTimeout(t int)

SetTimeout sets the new timeout

func (*ProtocolCount) Start

func (p *ProtocolCount) Start() error

Start the protocol

func (*ProtocolCount) Timeout

func (p *ProtocolCount) Timeout() int

Timeout returns the current timeout

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL