2017-05-20 14:46:29 +02:00
|
|
|
package meshviewerFFRGB
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTransform(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2018-01-07 21:00:56 +01:00
|
|
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
2017-05-20 14:46:29 +02:00
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 20:29:00 +01:00
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "node_a",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:a:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Wireless: []string{"node:a:mac:wifi"},
|
|
|
|
Tunnel: []string{"node:a:mac:vpn"},
|
|
|
|
Other: []string{"node:a:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_a",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:a:mac:wifi": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:b:mac:wifi": {TQ: 153},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:a:mac:lan": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:b:mac:lan": {TQ: 51},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 20:29:00 +01:00
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "node_c",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:c:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Other: []string{"node:c:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
2019-02-27 02:29:39 +01:00
|
|
|
NodeID: "node_c",
|
2017-05-20 14:46:29 +02:00
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:c:mac:lan": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:b:mac:lan": {TQ: 102},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
nodes.AddNode(&runtime.Node{
|
2017-11-01 20:29:00 +01:00
|
|
|
Online: true,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-05-20 14:46:29 +02:00
|
|
|
NodeID: "node_b",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:b:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
|
|
|
Wireless: []string{"node:b:mac:wifi"},
|
|
|
|
Other: []string{"node:b:mac:lan"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_b",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:lan": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:c:mac:lan": {TQ: 204},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:b:mac:wifi": {
|
2017-05-20 14:46:29 +02:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:a:mac:wifi": {TQ: 204},
|
2017-05-20 14:46:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-11-01 20:29:00 +01:00
|
|
|
nodes.AddNode(&runtime.Node{
|
|
|
|
Online: false,
|
2019-01-24 02:56:13 +01:00
|
|
|
Nodeinfo: &data.Nodeinfo{
|
2017-11-01 20:29:00 +01:00
|
|
|
NodeID: "node_d",
|
|
|
|
Network: data.Network{
|
|
|
|
Mac: "node:d:mac",
|
2017-12-05 23:17:49 +01:00
|
|
|
Mesh: map[string]*data.NetworkInterface{
|
2018-01-13 16:40:23 +01:00
|
|
|
"bat0": {
|
2017-11-01 20:29:00 +01:00
|
|
|
Interfaces: struct {
|
|
|
|
Wireless []string `json:"wireless,omitempty"`
|
|
|
|
Other []string `json:"other,omitempty"`
|
|
|
|
Tunnel []string `json:"tunnel,omitempty"`
|
|
|
|
}{
|
2024-07-20 00:31:16 +02:00
|
|
|
Wireless: []string{"node:d:mac:wifi"},
|
|
|
|
Other: []string{"node:d:mac:lan"},
|
2017-11-01 20:29:00 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Neighbours: &data.Neighbours{
|
|
|
|
NodeID: "node_d",
|
|
|
|
Batadv: map[string]data.BatadvNeighbours{
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:d:mac:lan": {
|
2017-11-01 20:29:00 +01:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:c:mac:lan": {TQ: 204},
|
2017-11-01 20:29:00 +01:00
|
|
|
},
|
|
|
|
},
|
2018-01-13 16:40:23 +01:00
|
|
|
"node:d:mac:wifi": {
|
2017-11-01 20:29:00 +01:00
|
|
|
Neighbours: map[string]data.BatmanLink{
|
2023-09-18 19:56:18 +02:00
|
|
|
"node:a:mac:wifi": {TQ: 204},
|
2017-11-01 20:29:00 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2017-05-20 14:46:29 +02:00
|
|
|
|
|
|
|
meshviewer := transform(nodes)
|
|
|
|
assert.NotNil(meshviewer)
|
2017-11-01 20:29:00 +01:00
|
|
|
assert.Len(meshviewer.Nodes, 4)
|
2024-07-20 00:31:16 +02:00
|
|
|
/*
|
|
|
|
links:
|
|
|
|
a:wifi <-> b:wifi 153 / 204
|
|
|
|
a:lan -> b:lan 51
|
|
|
|
c:lan <-> b:lan 102 / 204
|
|
|
|
d:lan -> c:lan 204 (but offline)
|
|
|
|
d:wifi -> a:wifi 204 (but offline)
|
|
|
|
*/
|
2017-05-20 14:46:29 +02:00
|
|
|
links := meshviewer.Links
|
|
|
|
assert.Len(links, 3)
|
|
|
|
|
2024-07-20 00:31:16 +02:00
|
|
|
counter := 0
|
2017-05-20 14:46:29 +02:00
|
|
|
for _, link := range links {
|
2017-12-05 23:17:49 +01:00
|
|
|
switch link.SourceAddress {
|
2017-05-20 14:46:29 +02:00
|
|
|
case "node:a:mac:lan":
|
2024-07-20 00:31:16 +02:00
|
|
|
assert.Equal("node:b:mac:lan", link.TargetAddress, "a:lan -> b:lan")
|
|
|
|
assert.Equal("other", link.Type, "a:lan -> b:lan")
|
|
|
|
assert.Equal(float32(0.2), link.SourceTQ, "a:lan -> b:lan")
|
|
|
|
assert.Equal(float32(0), link.TargetTQ, "a:lan -> b:lan")
|
|
|
|
counter++
|
2017-05-20 14:46:29 +02:00
|
|
|
case "node:a:mac:wifi":
|
2024-07-20 00:31:16 +02:00
|
|
|
assert.Equal("node:b:mac:wifi", link.TargetAddress, "a:wifi <-> b:wifi")
|
|
|
|
assert.Equal("wifi", link.Type, "a:wifi <-> b:wifi")
|
|
|
|
assert.Equal(float32(0.6), link.SourceTQ, "a:wifi <-> b:wifi")
|
|
|
|
assert.Equal(float32(0.8), link.TargetTQ, "a:wifi <-> b:wifi")
|
|
|
|
counter++
|
2017-12-31 05:26:17 +01:00
|
|
|
case "node:b:mac:lan":
|
2024-07-20 00:31:16 +02:00
|
|
|
assert.Equal("other", link.Type, "b:lan <-> c:lan")
|
|
|
|
assert.Equal("node:c:mac:lan", link.TargetAddress, "b:lan <-> c:lan")
|
|
|
|
assert.Equal(float32(0.8), link.SourceTQ, "b:lan <-> c:lan")
|
|
|
|
assert.Equal(float32(0.4), link.TargetTQ, "b:lan <-> c:lan")
|
|
|
|
counter++
|
2017-12-31 05:26:17 +01:00
|
|
|
default:
|
2017-12-05 23:17:49 +01:00
|
|
|
assert.False(true, "invalid link.SourceAddress found")
|
2017-05-20 14:46:29 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-20 00:31:16 +02:00
|
|
|
assert.Equal(3, counter, "not found every link")
|
2017-05-20 14:46:29 +02:00
|
|
|
}
|