-
Notifications
You must be signed in to change notification settings - Fork 106
/
simulation.go
70 lines (62 loc) · 1.58 KB
/
simulation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package manage
import (
"errors"
"strconv"
"github.com/BurntSushi/toml"
"gopkg.in/dedis/cothority.v0/lib/dbg"
"gopkg.in/dedis/cothority.v0/lib/monitor"
"gopkg.in/dedis/cothority.v0/lib/sda"
)
/*
Defines the simulation for the count-protocol
*/
func init() {
sda.SimulationRegister("Count", NewSimulation)
}
// Simulation only holds the BFTree simulation
type simulation struct {
sda.SimulationBFTree
}
// NewSimulation returns the new simulation, where all fields are
// initialised using the config-file
func NewSimulation(config string) (sda.Simulation, error) {
es := &simulation{}
_, err := toml.Decode(config, es)
if err != nil {
return nil, err
}
return es, nil
}
// Setup creates the tree used for that simulation
func (e *simulation) Setup(dir string, hosts []string) (
*sda.SimulationConfig, error) {
sc := &sda.SimulationConfig{}
e.CreateEntityList(sc, hosts, 2000)
err := e.CreateTree(sc)
if err != nil {
return nil, err
}
return sc, nil
}
// Run is used on the destination machines and runs a number of
// rounds
func (e *simulation) Run(config *sda.SimulationConfig) error {
size := config.Tree.Size()
dbg.Lvl2("Size is:", size, "rounds:", e.Rounds)
for round := 0; round < e.Rounds; round++ {
dbg.Lvl1("Starting round", round)
round := monitor.NewTimeMeasure("round")
p, err := config.Overlay.CreateProtocol(config.Tree, "Count")
if err != nil {
return err
}
go p.Start()
children := <-p.(*ProtocolCount).Count
round.Record()
if children != size {
return errors.New("Didn't get " + strconv.Itoa(size) +
" children")
}
}
return nil
}