Skip to content

Commit b3302bc

Browse files
committed
Merge pull request #76 from AutoRoute/bandwidth_estimation
Bandwidth estimation
2 parents ece3da0 + 4b14b12 commit b3302bc

24 files changed

Lines changed: 973 additions & 100 deletions

integration_tests/autoroute_binary.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type BinaryOptions struct {
2727
BTCHost string
2828
BTCUser string
2929
BTCPass string
30+
// Whether to enable race condition checker.
31+
Race bool
3032
}
3133

3234
// Transforms a BinaryOptions into a valid AutoRoute command line.
@@ -70,11 +72,18 @@ func ProduceCommandLine(b BinaryOptions) []string {
7072

7173
// Produces a AutoRoute Binary which can be run. Must call Start in order to
7274
// make it start running.
75+
// Args:
76+
// b: Options for the binary.
77+
// Returns:
78+
// The new autoroute binary.
7379
func NewNodeBinary(b BinaryOptions) AutoRouteBinary {
7480
port := GetUnusedPort()
7581
args := ProduceCommandLine(b)
7682
args = append(args, "--status=[::1]:"+fmt.Sprint(port))
77-
binary := NewWrappedBinary(GetAutoRoutePath(), args...)
83+
84+
path := GetAutoRoutePath(b.Race)
85+
binary := NewWrappedBinary(path, args...)
86+
7887
return AutoRouteBinary{binary, port}
7988
}
8089

integration_tests/bitcoin_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func TestBitcoin(t *testing.T) {
7373
BTCHost: "[::1]:19001",
7474
BTCUser: "admin1",
7575
BTCPass: "123",
76+
Race: true,
7677
})
7778
listen.Start()
7879
defer listen.KillAndPrint(t)

integration_tests/build.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,23 @@ import (
77
)
88

99
func BuildBinary(path string) (string, error) {
10-
cmd := exec.Command("go", "install", "-race", path)
10+
// Install a version with race condition checking enabled and one without.
11+
cmd := exec.Command("go", "install", path)
12+
race_cmd := exec.Command("go", "install", "-race", path)
1113
cmd.Env = os.Environ()
1214
cmd.Env = append(cmd.Env, "GOBIN=/tmp")
15+
race_cmd.Env = cmd.Env
16+
race_out, race_err := race_cmd.CombinedOutput()
17+
// Rename the race binary.
18+
os.Rename(GetAutoRoutePath(false), GetAutoRoutePath(true))
1319
out, err := cmd.CombinedOutput()
14-
return string(out), err
20+
ret_err := race_err
21+
ret_out := race_out
22+
if err != nil {
23+
ret_err = err
24+
ret_out = out
25+
}
26+
return string(ret_out), ret_err
1527
}
1628

1729
func init() {
@@ -21,6 +33,16 @@ func init() {
2133
}
2234
}
2335

24-
func GetAutoRoutePath() string {
25-
return "/tmp/autoroute"
36+
// Gets the path for the version of the autoroute binary.
37+
// Args:
38+
// race: Whether to use the version with race checking.
39+
// Returns:
40+
// The path requested.
41+
func GetAutoRoutePath(race bool) string {
42+
path := "/tmp/autoroute"
43+
if race {
44+
path += "_race"
45+
}
46+
47+
return path
2648
}

integration_tests/connection_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
)
66

77
func TestConnection(t *testing.T) {
8-
listen := NewNodeBinary(BinaryOptions{Listen: "[::1]:9999", Fake_money: true})
8+
listen := NewNodeBinary(BinaryOptions{Listen: "[::1]:9999",
9+
Fake_money: true})
910
listen.Start()
1011
defer listen.KillAndPrint(t)
1112
listen_id, err := WaitForID(listen)
@@ -21,7 +22,7 @@ func TestConnection(t *testing.T) {
2122
defer connect.KillAndPrint(t)
2223
connect_id, err := WaitForID(connect)
2324
if err != nil {
24-
t.Fatal(err)
25+
t.Fatal(err)
2526
}
2627

2728
err = WaitForConnection(listen, connect_id)

integration_tests/loopback2/loopback2.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func waitForOffline(devices map[string]l2.FrameReadWriteCloser) {
8383

8484
// Check for timeout.
8585
select {
86-
case <-timeout:
87-
log.Fatal("Waiting for devices to go offline took too long.\n")
88-
default:
89-
continue
86+
case <-timeout:
87+
log.Fatal("Waiting for devices to go offline took too long.\n")
88+
default:
89+
continue
9090
}
9191
}
9292
}
@@ -244,8 +244,9 @@ func (t *TapNetwork) doCreateNetwork() {
244244
}
245245
waitForOffline(devices)
246246

247-
t.waiter.Done()
248247
log.Print("Loopback2: Exiting...\n")
248+
// Tell the caller we're done quitting.
249+
t.waiter.Done()
249250
}
250251

251252
// Stops a running network simulation.

integration_tests/packet_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TestPacket(t *testing.T) {
4141
connect.Start()
4242
defer connect.KillAndPrint(t)
4343
connect_id, err := WaitForID(connect)
44+
if err != nil {
45+
t.Fatal(err)
46+
}
4447

4548
err = WaitForConnection(listen, connect_id)
4649
if err != nil {

integration_tests/ports.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var l *sync.Mutex = &sync.Mutex{}
1010
func GetUnusedPort() int {
1111
l.Lock()
1212
defer l.Unlock()
13+
ret := port
1314
port = port + 1
14-
return port - 1
15+
return ret
1516
}

integration_tests/root/autodiscovery_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func TestConnection(t *testing.T) {
122122
Fake_money: true,
123123
Autodiscover: true,
124124
Autodiscover_devices: []string{listen_dev.Name},
125+
Race: true,
125126
})
126127
listen.Start()
127128
defer listen.KillAndPrint(t)
@@ -132,6 +133,7 @@ func TestConnection(t *testing.T) {
132133
Fake_money: true,
133134
Autodiscover: true,
134135
Autodiscover_devices: []string{connect_dev.Name},
136+
Race: true,
135137
})
136138
connect.Start()
137139
defer connect.KillAndPrint(t)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"connections": [
3+
{
4+
"source": "A",
5+
"destination": "C"
6+
},
7+
{
8+
"source": "C",
9+
"destination": "D"
10+
},
11+
{
12+
"source": "D",
13+
"destination": "B"
14+
},
15+
{
16+
"source": "A",
17+
"destination": "E"
18+
},
19+
{
20+
"source": "E",
21+
"destination": "B"
22+
},
23+
{
24+
"source": "A",
25+
"destination": "F"
26+
},
27+
{
28+
"source": "F",
29+
"destination": "B"
30+
}
31+
],
32+
"devices": [
33+
{
34+
"name": "C",
35+
"bandwidth": "25000"
36+
},
37+
{
38+
"name": "D",
39+
"bandwidth": "15000"
40+
},
41+
{
42+
"name": "E",
43+
"bandwidth": "5000"
44+
},
45+
{
46+
"name": "F",
47+
"bandwidth": "25000"
48+
}
49+
]
50+
}

0 commit comments

Comments
 (0)