Newer
Older
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
package server
import (
"testing"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route"
"github.com/stretchr/testify/assert"
)
func TestProcessAttribues(t *testing.T) {
unknown3 := &packet.PathAttribute{
Transitive: true,
TypeCode: 100,
Value: []byte{1, 2, 3, 4},
Next: nil,
}
unknown2 := &packet.PathAttribute{
Transitive: false,
TypeCode: 150,
Value: []byte{20},
Next: unknown3,
}
unknown1 := &packet.PathAttribute{
Transitive: true,
TypeCode: 200,
Value: []byte{5, 6},
Next: unknown2,
}
asPath := &packet.PathAttribute{
Transitive: true,
TypeCode: packet.ASPathAttr,
Value: packet.ASPath{
packet.ASPathSegment{
Count: 0,
Type: packet.ASSequence,
ASNs: []uint32{},
},
},
Next: unknown1,
}
e := &establishedState{}
p := &route.Path{
BGPPath: &route.BGPPath{},
}
e.processAttributes(asPath, p)
expectedCodes := []uint8{200, 100}
expectedValues := [][]byte{[]byte{5, 6}, []byte{1, 2, 3, 4}}
i := 0
for attr := p.BGPPath.UnknownAttributes; attr != nil; attr = attr.Next {
assert.Equal(t, true, attr.Transitive, "Transitive")
assert.Equal(t, expectedCodes[i], attr.TypeCode, "Code")
assert.Equal(t, expectedValues[i], attr.Value, "Value")
i++
}
assert.Equal(t, i, 2, "Count")
}